<?php

//USING
require_once 'controls/verifylogin.php';
require_once '../Class/model/FaturasModel.php';
require_once '../Class/model/FaturasDescricaoModel.php';
require_once '../Class/model/ClientesModel.php';
require_once '../Class/model/PastasModel.php';
require_once '../Class/controller/FaturasControl.php';
include_once('../Database/MySQL.Aux.php');

$control = new FaturasControl();
$model = new FaturasModel();
$modelDescricao = new FaturasDescricaoModel();

$aux = new MySQLAux();

$control->setDel();

$del = $control->getDel();

if ($del > 0)
{
	$model->setId($del);
	$model->delete();
	$modelDescricao->deleteByFatura($del);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Módulo Financeiro</title>

<?php include_once('controls/import.php'); ?>

</head>
<body>

<?php include_once('controls/header.php'); ?>

<div class="content">

<div class="form"><?php include_once('controls/menu.php'); ?>

<div id="conteudo-site">

<div class="titulo-conteudo-site"><img src="images/applications.png"
	title="" alt="" /> Faturas</div>

<div class="pg-botoes" style="float: right;"><a href="cadfaturas.php"
	class="submit"> cadastrar </a></div>
<br clear="all" />
<table border="0" cellpadding="3" cellspacing="0"
	class="gridPesquisa fundoGridPesquisa" width="100%">
	<tr>
		<th>Id</th>
		<th>Cliente</th>
		<th>Pasta</th>
		<th>Nº Fatura</th>
		<th>Emissão</th>
		<th>Valor</th>
		<th>Fatura</th>
		<th></th>
	</tr>
	
		<?php

	foreach ($model->listAll() as $item) {
		
		echo "<tr>";
		echo "<td> <a href='cadfaturas.php?id={$item->getId()}'> {$item->getId()} </a></td>";
		echo "<td> <a href='cadfaturas.php?id={$item->getId()}'> {$control->RetornaCliente($item->getCliente())} </a></td>";
		echo "<td> <a href='cadfaturas.php?id={$item->getId()}'> {$control->RetornaPasta($item->getPasta())} </a></td>";
		echo "<td> <a href='cadfaturas.php?id={$item->getId()}'> {$item->getNumNota()} </a></td>";
		echo "<td> <a href='cadfaturas.php?id={$item->getId()}'> {$aux->getDataBR($item->getDtEmissao())} </a></td>";
		echo "<td> <a href='cadfaturas.php?id={$item->getId()}'> {$aux->getValorBR($control->RetornaValor($item->getId()))} </a></td>";
		echo "<td> <a href='fatura.php?id={$item->getId()}'> Fatura </a></td>";
		echo "<td> <a href='faturas.php?del={$item->getId()}' onclick='return DeleteItem();'> <img src='images/ico-minus.png' /> </a> </td>";
		echo "</tr>";
	}

	?>
</table>
</div>

</div>

</div>

<?php include_once('controls/footer.php'); ?>

</body>
</html>
