
<?php require_once('Connections/paivaconex.php'); 
include("FusionCharts_Enterprise/Code/PHP/Includes/FusionCharts.php");
session_start();
?>

<script language="javascript" src="FusionCharts_Enterprise/JSClass/FusionCharts.js"></script>

<?php
$sql = '';

if (count($_POST) >=1) {
	if (isset($_POST['mes'])) {
		$quando[] = "month(datafluxo) IN (".implode( " ,",$_POST['mes']).")";
	}
	if (isset($_POST['ano'])) {
		$quando[] = "year(datafluxo) IN (".implode( " ,",$_POST['ano']).")";
	}
	if (isset($_POST['dia'])) {
		$quando[] = "day(datafluxo) IN (".implode( " ,",$_POST['dia']).")";
	}
	if (isset($_POST['cliente'])) {
		$quando[] = "Cliente IN (".implode( " ,",$_POST['cliente']).")";
	}
	if (isset($_POST['pasta'])) {
		$quando[] = "Pasta IN (".implode( " ,",$_POST['pasta']).")";
	}
	if (isset($_POST['fornecedor'])) {
		$quando[] = "Fornecedor IN (".implode( " ,",$_POST['fornecedor']).")";
	}
	if (isset($_POST['conta'])) {
		$quando[] = "mfin_fornecedores.ContaResultado IN (".implode( " ,",$_POST['conta']).")";
	}
	if (isset($_POST['grupo'])) {
		$quando[] = "mfin_grupocontas.Id IN (".implode( " ,",$_POST['grupo']).")";
	}
	if (isset($_POST['status'])) {
		$quando[] = "status IN (".implode( " ,",$_POST['status']).")";
	}
	if (isset($_POST['detalhe'])) {
		$quando[] = "dashboard.Detalhe IN ('".implode( "' ,'",$_POST['detalhe'])."')";
	}
	$sql = "WHERE ".implode( " AND ", $quando);	
}

mysql_select_db($database_paivaconex, $paivaconex);
$query_clientes = "Select vl_pag+Juros_pag as vl, dashboard.Detalhe as Detalhe, mfin_clientes.NomeFantasia as cliente, mfin_fornecedores.NomeFantasia as fornec, DATE_FORMAT(datafluxo, '%d/%m/%Y') as pagamento, mfin_pastas.Numero as numpasta  from dashboard
Inner Join mfin_clientes ON Cliente = mfin_clientes.Id
Left Join mfin_pastas ON Pasta = mfin_pastas.Id
Inner Join mfin_fornecedores ON Fornecedor = mfin_fornecedores.Id
Inner Join mfin_contas ON mfin_fornecedores.ContaResultado = mfin_contas.Id
Inner Join mfin_grupocontas ON Grupo = mfin_grupocontas.Id
".$sql." Order by datafluxo, mfin_pastas.Numero, vl_pag+Juros_pag,  mfin_fornecedores.NomeFantasia";
$clientes = mysql_query($query_clientes, $paivaconex) or die(mysql_error());
$row_clientes = mysql_fetch_assoc($clientes);
$totalRows_clientes = mysql_num_rows($clientes);
?>
<style type="text/css" media="print">
div.conteudodatabela {overflow: visible;	}
table>tbody	{overflow: visible; }
td {height: 14pt;} /*adds control for test purposes*/
thead td	{font-size: 11pt;	}
tfoot td	{
	text-align: center;
	font-size: 9pt;
	border-bottom: solid 1px slategray;
	}
	
thead	{display: table-header-group;	}
tfoot	{display: table-footer-group;	}
thead th, thead td	{position: static; } 

thead tr	{position: static; } /*prevent problem if print after scrolling table*/ 
table tfoot tr {     position: static;    }


</style>

<style type="text/css">

@page { size: A4 landscape }

</style>
<table width="1100" border="1" style="border-collapse:collapse">
<thead>
  <tr bgcolor="#CCCCCC" style="font-size: 12px">
    
    <th align="center">Pagamento</th>
    <th align="center">Fornecedor</th>
    <th align="center">Pasta</th>
    <th align="center">Cliente</th>
    <th align="center">Descri&ccedil;&atilde;o</th>
    <th align="center">Valor</th>
  </tr>
 </thead> 
 <tfoot>
 </tfoot>
 <tbody>
  <?php do { ?>
  
    <tr style="font-size: 12px" >
      	<td align="center"><?php echo $row_clientes['pagamento']; ?></td>
    	<td align="center"><?php echo htmlentities($row_clientes['fornec'], ENT_COMPAT , "ISO-8859-1"); ?></td>
	    <td align="center"><?php echo $row_clientes['numpasta']; ?></td>
        <td align="center"><?php echo htmlentities($row_clientes['cliente'], ENT_COMPAT , "ISO-8859-1"); ?></td>
    	<td height="26" align="center"><?php echo htmlentities($row_clientes['Detalhe'], ENT_COMPAT , "ISO-8859-1"); ?></td>
      <td align="right"><?php echo number_format($row_clientes['vl'],2,',','.'); ?></td>
    </tr>
   
    <?php } while ($row_clientes = mysql_fetch_assoc($clientes)); ?>
    </tbody>
</table>
<?php mysql_free_result($clientes); 

echo "<script language=javascript> window.print()</script>"; 
?>
