<?php

session_start();

include_once '../conexao/index.php';
date_default_timezone_set('Africa/Maputo');

$data_hora = date("Y-m-d H:i:s");

$userID = $_SESSION['idUsuario'];

$userNOME = $_SESSION['nomeUsuario'];

$userCATE = $_SESSION['categoriaUsuario'];


$sql = "SELECT MAX(idperiodo) as id FROM periodo";
$rs = mysqli_query($db, $sql);
$dados = mysqli_fetch_array($rs);
$id = $dados['id'];
?>
<html>
<head>
	<title>Fecho de Caixa</title>
	<script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
	<style type="text/css">
		*{
			font-size: 8pt;
		}
	</style>
</head>
<body>
<div class="fatura">
<div class="header" style="text-align: center;">
	<img src="logo_pedaco.png" style="width: 150px;">
	<p>Tete - Cidade de Moatize</p>
	<p>Estrada Nacional NR 7</p>
	<p>Cell:855213692  -  NUIT: 401058303</p>
</div>
<div class="fact" style="text-align: center;">
	<p><span>Fecho</span><span class="pd" style="margin-left: 100px;"><?php echo $id; ?></span></p>
</div>
<div class="body" style="text-align: center;">
	<p class="p"><span>Documento Original</span><span style="margin-left: 10px;"><?php echo $data_hora; ?></span></p>
</div>
<table class="prodFactura" style="width: 95%;margin: 3px auto;text-align:center;">
	<thead class="titulo">
		<th>Data</th>
		<th>Abertura (Mt)</th>
		<th>Fecho (Mt)</th>
	</thead>
	<tbody>
		<?php 
			$q = "SELECT * FROM periodo WHERE idperiodo = '$id'";
			$c = mysqli_query($db, $q);
			while ($a = mysqli_fetch_array($c)) {
			$ab = $a['aberturaperiodo'];
			$fc = $a['fechoperiodo'];
		?>
			<tr>
				<td><?php echo $a['datafechoperiodo']; ?></td>
				<td><?php echo "".number_format($ab,2,".",","); ?></td>
				<td><?php echo "".number_format($fc,2,".",","); ?></td>
			</tr>
		<?php

			}
		?>
	</tbody>
</table>
<div class="processo" style="text-align: center;">
	<p>iVone - Processado por programa</p>
	<p style="margin: 10px 0px;">Operador: <?php echo $_SESSION['nomeUsuario']; ?></p>
</div>

</div>
<script type="text/javascript">

	$(function() {

		window.print();

	});

</script>
</body>
</html>