<?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>
	Ol&aacute;: <?php include('logado.php');?>
</section>
<?php
	include ("conexao.php");

	$sql = mysqli_query($mysqli,"SELECT * FROM pagtonresgistado WHERE id = (SELECT MAX(id) FROM pagtonresgistado where agente = '$Nome')");
	$result = mysqli_fetch_array($sql);
	
    $id_pag = $result['id'];
	$d = $result['dia'];
    $m = $result['mes'];
    $ano = $result['ano'];
    $pago = $result['pago'];
    
	$sql3 = mysqli_query($mysqli,"SELECT * FROM receitas WHERE referencia = '$id_pag' and origem = 'amb'");
	$result3 = mysqli_fetch_array($sql3);
	if($result3['referencia']<1) { 
	$stmt = $mysqli->prepare("INSERT INTO receitas (referencia,origem, dia, mes, ano, subcod, codigo, valor) VALUES ('$id_pag','amb','$d','$m','$ano','1142','114205','$pago')");
	if(!$stmt->execute())
	{
	}
	else
	{
	}
	} 
	else 
	{
	}
	$sql2 = mysqli_query($mysqli,"SELECT * FROM recibos_impressos WHERE id_pagamento = '$id_pag'");
	$result2 = mysqli_fetch_array($sql2);
	
	if($result2['id_pagamento']>0) { 
	 echo ("<script>alert('Este recibo ja foi impresso por ". $result2['agente']." !');window.location.href='index.php?link=1';</script>");?>
	    <meta http-equiv="refresh" content="1;url=inicio.php"/>
	    
	<?php  // header("Location: index.php?link=14"); 
	} else {
?> 
<div class="container">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="chapter">Recibo de pagamento</span>Do dia <?php print $result['dia'].'/'.$result['mes'].'/'.$result['ano']?></p>
<div class="bloc">
<div class="bloc--content">
 
<p>
	<div>
	<center>
	<a href="my.bluetoothprint.scheme://http://mobile.cacm.co.mz/response.php?cod=<?php echo $result['id'];?>" target="_self" > 
	<i class="fa fa-print" style="font-size:48px;color:blue"></i><br>Imprimir<br><br></a>
	</center>	
	</div>
	<br>
	
<center><a href="cobranca.php"><i class="fa fa-refresh" style="font-size:48px;color:blue"></i><br>Novo pagamento</a></center>

<?php } ?>
</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>

