<?php 	
include('conexao.php');
session_start();

if(!isset($_SESSION["login"]) || !isset($_SESSION["senha"])){
header("Location: cuide.php");
exit;	
}

?> 
<!doctype html>
<html lang="fr">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>SiGA</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
  <link rel="stylesheet" href="assets/css/milligram/milligram.min.css">
  <link rel="stylesheet" href="assets/css/omega.css">
  <link rel="stylesheet" href="assets/css/style.css">
  
</head>
<body id="app">
<?php include("menu.php");?>
<main>
    <section>
        <div class="container">
		Ol&aacute;: <?php include('logado.php');?>
        </div>
    </section>
	<?php
	if($_POST)
	{
	$tipotaxa       = $_POST['tipotaxa'];
	//$taxa 			= $_POST['taxa'];
	$multa 			= $_POST['multa'];
	$total 			= $_POST['total'];
	$mercado 		= $_POST['mercado'];
	$dia 			= $_POST['dia'];
	$mes 			= $_POST['mes'];
	$ano 			= $_POST['ano'];
	$agente 		= $_POST['cadastradoPor'];
	$data 	= date('Y-m-d');
	$h 	= date('H');
	$mi 	= date('i');
	$seg 	= date('s');
	$mercado = $_POST['mercado'];
	
	$hora = ($h+2).''.$mi.''.$seg;
	
	$stmt = $mysqli->prepare("INSERT INTO pagtonresgistado (taxa, mercado, multa, pago, datapagto,hora, dia, mes, ano, agente) VALUES ('$tipotaxa','$mercado','$multa','$total','$data','$hora','$dia','$mes','$ano','$agente')");
		
	if(!$stmt->execute())
		{
			echo("<script>alert('Erro!');</script>");
		}
		else
		{
			echo("<script>window.location.href='printnresgistado.php';</script>");
		}
	}
?>
<body>
<script> 
	function taxatotal() 
	{
	form.total.value = (form.tipotaxa.value*1) + (form.multa.value*1);
	}
</script>

<div class="container">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="chapter">Cobrança</span>Vendedores não registados</p>
<div class="bloc">
<div class="bloc--content">
<p>
	<form name="form" method="post" action="">
	<div><input name="cadastradoPor" class="input" type="hidden" size="28"  value="<?php print $Nome?>"></div>	
	<div class="form-group">
	<label for="usr">Mercado:</label>
		<select name="mercado" required class="form-control" >
		    <option value="">- - - -</option>
		<?php
            $sql = "SELECT * FROM mercados ORDER BY nome";
            $res = mysqli_query($mysqli, $sql );
            while ( $row = mysqli_fetch_assoc( $res ) ) {
                    echo '<option value="'.$row['id'].'">'.$row['nome'].'</option>';
            }
        ?>
		</select>
	</div>	
	<div class="form-group">
	<label for="usr">Taxa:</label>
		<select name="tipotaxa" id="cod_provincia" class="form-control" onBlur="taxatotal()" required>
		    <option value="">- - - -</option>
		<?php
            $sql = "SELECT taxa, designacao FROM taxas ORDER BY taxa";
            $res = mysqli_query($mysqli, $sql );
            while ( $row = mysqli_fetch_assoc( $res ) ) {
                    echo '<option value="'.$row['taxa'].'">'.number_format($row['taxa'],2).'MT</option>';
            }
        ?>
		</select>
	</div>

	<div class="form-group">
	<label for="usr">Multa:</label>
	<input name="multa" class="form-control" type="text" onBlur="taxatotal()" value="0" autocomplete="off"></div>
	<div class="form-group">
	<label for="usr">Total a pagar:</label>
	<input name="total" class="form-control" type="text" placeholder=" Total a pagar" readonly></div>
		<input type="hidden" name="dia" value="<?php echo date("d")?>">
        <input type="hidden" name="mes" value="<?php echo date("m")?>">
        <input type="hidden" name="ano" value="<?php echo date("Y")?>">
	<div class="form-group">
	<input name="pgmr" class="btn btn-primary" type="submit" value="Pagamento">
	</div>	
	</form>
	</p>
	</div>
</div>
</div>
</main>
<footer>
  2019 <strong>acliven</strong> - <a href="https://www.acliven.it">www.acliven.it</a>
</footer>
<script defer src="https://use.fontawesome.com/releases/v5.8.1/js/all.js" integrity="sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ" crossorigin="anonymous"></script>
<script src="assets/js/omega.js"></script>
</body>
</html>