<?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>
<script type='text/javascript'>
$(document).ready(function(){
  $("select[name='tipotaxa']").blur(function(){
	var $taxa = $("input[name='taxa']");
	var $codigo = $("input[name='codigo']");
	var $total = $("input[name='total']");
	var $id = $("input[name='id']");
	$.getJSON('function.php',{
	  tipotaxa: $( this ).val()
	},function( json ){
	  $taxa.val( json.taxa );
	  $codigo.val( json.codigo );
	  $total.val( json.total );
	  $id.val( json.id );
	});
  });
});
</script>
</head>
<body id="app">
<?php include("menu.php");?>
<main>
    <section>
		Ol&aacute;: <?php include('logado.php');?>
    </section>
	<?php
    if($_POST)
        {
        $matriz 	= $_POST['matriz'];
        $rpred 		= $_POST['rpred'];
        $final 		= $_POST['final'];
        $bairro 	= $_POST["bairro"];
        $desc		= $_POST['desc'];
        $data       = $_POST['datareg'];
        $valor      = $_POST['valor'];
        //$isento		= $_POST['isento'];
        $totalpagar = $_POST['valortotal'];
        $multa 	    = $_POST['multa'];
      	$pago 	    = $_POST['pago'];
      	$dia 	    = $_POST['dia'];
      	$mes 	    = $_POST['mesp'];
      	$ano 	    = $_POST['ano'];
      	$data 	    = date('Y-m-d');
        $dono		= $_POST['dono'];
		$h 			= date('H');
		$mi 		= date('i');
		$seg 		= date('s');
		$hora 		= ($h+2).''.$mi.''.$seg;
    
        $stmt = $mysqli->prepare("INSERT INTO imovel VALUES 
		(NULL,'$matriz','$dono','$rpred','$final','$bairro','$desc','$valor','$totalpagar','$data',
        '$multa','$pago','$hora','$ano','$mes','$dia','$Nome','')") or die (mysqli_error());

        if(!$stmt->execute())
    		{
    			echo("<script>alert('Erro!');</script>");
    		}
    			else
    		{
          echo("<script>window.location.href='printipra.php';</script>");
        }
    }
?>
<body>
<script>
        function checar() {
           campo1 = document.form.final;
           campo2 = document.form.valor;
           if(campo1.value!="") {
           valor1=campo1.value;
           } else {
           valor1="";
           }
           if(campo2.value!="") {
           valor2=campo2.value;
           } else {
           valor2="";
           }
           um = valor1*1;
           dois = valor2*1;
            if(um=="" && dois=="") {
            document.form.valortotal.value="";
            } else {
                if(um == 1){
                    document.form.valortotal.value=0;
                }else if(um == 2){
                    document.form.valortotal.value = (((0.004) * dois).toFixed(2));
                    document.form.pago.value = (((0.004) * dois).toFixed(2));
                }else if(um == 3){
                    document.form.valortotal.value= ((((0.7)/100) * dois).toFixed(2));
                    document.form.pago.value= ((((0.7)/100) * dois).toFixed(2));
                }else if(um == 4){
                    document.form.valortotal.value=0;
                }
            }
            var dia = form.datareg.value;
            var mes = form.datareg.value;
            form.dia.value = dia.substr(8,9);
            form.mes.value = mes.substr(4,4);
            }
            function taxatotal()
            {
              form.pago.value = (((form.valortotal.value*1) + (form.multa.value*1)).toFixed(2));
              var mesx = form.mes.value;
              form.mesp.value = mesx.substr(1,2);
            }
        </script>
<div class="container">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="chapter">Cobrança</span>IPRA</p>
<div class="bloc">
<div class="bloc--content">

<p>
	<form name="form" method="post" action="">
	<input type="hidden" name="ano" value="<?php echo date("Y")?>">
  <input type="hidden" name="dia">
  <input type="hidden" name="mes">
  <input type="hidden" name="mesp">
	<div><input name="cadastradoPor" class="input" type="hidden" size="28"  value="<?php print $Nome?>"></div>	
	<div class="form-group">
	<label for="usr">Proprietario:</label>
		<input name="dono" placeholder="Nome do proprietario" class="input" type="text" size="28" autocomplete="off" required>
	</div>
	<div class="form-group">
	<label for="usr">Matriz predial:</label>
		<input name="matriz" placeholder="Matriz predial" class="input" type="text" size="28" autocomplete="off">
	</div>
	<div class="form-group">
	<label for="usr">Registo predil:</label>
		<input name="rpred" placeholder="Registo predil" class="input" type="text" size="28" autocomplete="off">
	</div>
	<div class="form-group">
	<label for="usr">Bairro:</label>
		<input name="bairro" placeholder="Bairro onde se localiza" class="input" type="text" size="28" autocomplete="off">
	</div>
	<div class="form-group">
	<label for="usr">Finalidade do im&oacute;vel:</label>
		<select name="final"  onchange="checar()" class="input">
              <option value="">Escolha o tipo de imposto</option>
              <option value="1">Imposto Predial Aut&aacute;rquico Antiga Base</option>
              <option value="2">Imposto Predial Aut&aacute;rquico Habita&ccedil;&atilde;o</option>
              <option value="3">Imposto Predial Aut&aacute;rquico Com&eacute;rcio e Ind&uacute;stria</option>
              <option value="4">Imposto Predial Aut&aacute;rquico Terreno para Constru&ccedil;&atilde;o</option>
		</select>
	</div>	
	<div class="form-group">
	<label for="usr">Valor do im&oacute;vel:</label>
	<input class="form-control" type="text" name="valor" type="number" onChange="checar()" placeholder=" Valor do imovel" autocomplete="off">
	</div>
	<div class="form-group">
	<label for="usr">A pagar:</label>
	<input class="form-control" type="text" name="valortotal" type="number" class="select"  style="background: #FFEDBF" readonly>
	<input type="hidden" name="datareg" class="select" size="10" value="<?php echo date('Y-m-d');?>"/>
	</div>
	<div class="form-group">
	<label for="usr">Multa:</label>
	<input name="multa" class="form-control" type="number" onBlur="taxatotal()"  placeholder=" Multa" autocomplete="off" required></div>
	<div class="form-group">
	<label for="usr">Total a pagar:</label>
	<input name="pago" class="form-control" type="text" style="background: #FFEDBF" placeholder=" TOTAL A PAGAR" required></div>
	<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>