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

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

</head>
<body id="app">
<?php include("menu.php");?>
<main>
    <section>
		Ol&aacute;: <?php include('logado.php');?>
    </section>
	<?php
	if($_POST)
	{
	$nome       	= $_POST['nome'];
	$doc	       	= $_POST['doc'];
	$docnum	       	= $_POST['docnum'];
	$codigo 		= $_POST['codigo'];
	$id		 		= $_POST['id'];
	$taxa	 		= $_POST['taxa'];
	$multa 			= $_POST['multa'];
	$total 			= $_POST['total'];
	$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 outras_taxas 
	(nome, documento, numero_doc, tipo_taxa, sub,datapagto, taxafixa, outrataxa, pago, hora, ano, mes, dia, agente) 
	VALUES ('$nome','$doc','$docnum','$codigo','$id','$data','0','$multa','$total','$hora','$ano','$mes','$dia','$agente')");
		
	if(!$stmt->execute())
		{
			echo("<script>alert('Erro!');</script>");
		}
		else
		{
			echo("<script>window.location.href='printtae.php';</script>");
			//header("Location: printtae.php");
		}
	}
?>
<body>
<script type='text/javascript'>
$(document).ready(function(){
  $("select[name='tipotaxa']").blur(function(){
	var $taxa = $("input[name='taxa']");
	var $codigo = $("input[name='codigo']");
	var $id = $("input[name='id']");
	var $total = $("input[name='total']");
	$.getJSON('function.php',{
	  tipotaxa: $( this ).val()
	},function( json ){
	  $taxa.val( json.taxa );
	  $codigo.val( json.codigo );
	  $id.val( json.id );
	  $total.val( json.total );
	});
  });
});
</script>
<script> 
	function taxatotal() 
	{
	form.id.value = (form.tipotaxa.value*1);
	}

	function valor() 
	{
	form.total.value = (form.taxa.value*1) + (form.multa.value*1);
	}
</script>
<div class="container">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="chapter">Cobrança</span>Taxa por Actividade Economica</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">Municipe:</label>
		<input name="nome" placeholder="DIGITE O MOME" class="input" type="text" size="28" autocomplete="off" required>
	</div>
	<div class="form-group">
	<label for="usr">Documento:</label>
	<select name="doc" id="cod_provincia" class="form-control" required>
		<option value=''>ESCOLHA O DOCUMENTO
		<option value="BI">BI
		<option value="Carta de Conducao">Carta de Condução
		<option value="NUIT">NUIT
		<option value="Outro">Outro
	</select>
	</div>
	<div class="form-group">
	<label for="usr">Nº documento:</label>
		<input name="docnum" placeholder="NUMERO DO DOCUMENTO" class="input" type="text" size="28" autocomplete="off">
	</div>
	<div class="form-group">
	<label for="usr">Taxa:</label>
		<select name="tipotaxa" id="cod_provincia" class="form-control"  onBlur="valor()" required>
		<option value=''>ESCOLHA A TAXA
		<?php
            $sql = "SELECT * FROM taxas_contabil order by designacao";
            $res = mysqli_query($mysqli, $sql);
            while ( $row = mysqli_fetch_assoc($res)) {
                    echo '<option value="'.$row['id'].'">'.$row['designacao'].' → '.number_format($row['taxa'],2).'MT</option>';
            }
        ?>
		</select>
	</div>
	<label for="usr">Multa:</label>	
	<input name="taxa" class="form-control" type="hidden" placeholder="VALOR DA TAXA"  autocomplete="off" required>
	<input name="id" class="form-control" type="text">
	<input name="codigo" class="form-control" type="text">

	<input name="multa" class="form-control" type="number" onBlur="valor()" placeholder="MULTA" autocomplete="off" required></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><!--
	Estamos a trabalhar. Ate breve!...<br>
	<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSFZkQDagdrL9GHuTyKeu2BAsS8lGpxY1ARzdyagGwy-sdjcWie-->
	</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>