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

?>
<html lang="fr">
<head>
  <meta 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>
		Ol&aacute;: <?php include('logado.php');?>
</section>
<div class="container">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="chapter">Cobrança</span>Transportadores</p>
<div class="bloc">
<div class="bloc--content">
<p>
<?php

	if($_POST)
	{
	$id     = $_POST['nome'];
	$taxa 	= $_POST['taxa'];
	$multa 	= $_POST['multa'];
	$pago 	= $_POST['pago'];
	$dia 	= $_POST['dia'];
	$mes 	= $_POST['mes'];
	$ano 	= $_POST['ano'];
	$parque = $_POST['parque'];
	$agente = $_POST['agente'];
	$data = date('Y-m-d');
	$h 	= date('H');
	$mi 	= date('i');
	$seg 	= date('s');
	$mercado = $_POST['mercado'];
	
	$hora = ($h+2).''.$mi.''.$seg;
    $parque = strtoupper($parque);
	$stmt = $mysqli->prepare("INSERT INTO pagtodriversnregisted
	                    (veiculo, paragem, taxa, multa, pago,datapagto, hora,dia, mes, ano, agente ) VALUES
	                    ('$id','$parque','$taxa','$multa','$pago','$data','$hora','$dia','$mes','$ano','$agente')");
	 
	if(!$stmt->execute())
		{
			echo("<script>alert('Erro!');</script>");
		}
		else
		{
			echo("<script>window.location.href='printdriversnregisted.php';</script>");
		}
    }
?>
<body>
<script> 
	function taxatotal() 
	{
	form.pago.value = (form.taxa.value*1) + (form.multa.value*1);
	}
</script>
	<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">
	<div><input name="agente" class="input" type="hidden" size="28"  value="<?php print $Nome?>" readonly></div>
	<label for="usr">Veiculo:</label>
	<input name="nome" class="form-control" type="text"  placeholder=" aaa 001 zb" autocomplete="off" autofocus="true">
	</div>
	<div class="form-group">
	<label for="usr">Parque:</label>
		<select name="parque" class="form-control">
		<?php
            $sql2 = "SELECT id, nome
                            FROM paragens
                            ORDER BY nome";
            $res = mysqli_query($mysqli, $sql2 );
            while ($row = mysqli_fetch_assoc( $res ) ) {
                    echo '<option value="'.$row['id'].'">'.$row['nome'].'</option>';
            }
        ?>
		</select>
	</div>	
	<div class="form-group">
	<label for="usr">Tipo taxa:</label>
		<select name="taxa" id="cod_provincia" class="form-control" onBlur="taxatotal()">
		<?php
            $sql2 = "SELECT id, designacao, taxa
                            FROM taxas
                            ORDER BY taxa";
            $res = mysqli_query($mysqli, $sql2 );
            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="number" onBlur="taxatotal()" value="0" autocomplete="off"></div>
	<div class="form-group">
	<label for="usr">Total a pagar:</label>
	<input name="pago" 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>
	</p>
	</div>
		</form>
</div>
</div>
</main>

<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>