<?php require_once('Connections/paivaconex.php'); 
require_once('funcoes.php'); 
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}



mysql_select_db($database_paivaconex, $paivaconex);
$query_receber = "Select (Juros + Multa - Desconto - ir - pis - cofins - csll + Valor) AS vl, NomeFantasia, mfin_pastas.Numero as n_pasta, NumeroNota, mfin_recebimentos.Id as rec_id,  DATE_FORMAT(Emissao, '%d/%m/%Y') AS dta_emissao,  DATE_FORMAT(Recebimento, '%d/%m/%Y') AS dta_recebimento,  if(isnull(phoenix_emi),'Não',DATE_FORMAT(phoenix_emi, '%d/%m/%Y')) AS dta_phoenix From mfin_recebimentos INNER JOIN mfin_clientes ON mfin_recebimentos.Cliente_Id = mfin_clientes.Id  INNER JOIN mfin_pastas ON mfin_recebimentos.Pasta_Id = mfin_pastas.Id  WHERE Emissao >= '".convertdata($_GET['data_ini'])."' AND Emissao <= '".convertdata($_GET['data_fim'])."'";
$receber = mysql_query($query_receber, $paivaconex) or die(mysql_error());
$row_receber = mysql_fetch_assoc($receber);
$totalRows_receber = mysql_num_rows($receber);

mysql_select_db($database_paivaconex, $paivaconex);
$query_pagar = "Select (Valor- Ir- Pis- Cofins- Csll- Inss- Iss+ Juros- Desconto+ Multa) AS vl, mfin_fornecedores.NomeFantasia as nome_fantasia, mfin_pastas.Numero as n_pasta, NumFatura, mfin_pagamentos.Id as pag_id,  DATE_FORMAT(Emissao, '%d/%m/%Y') AS dta_emissao,  DATE_FORMAT(Vencimento, '%d/%m/%Y') AS dta_vencimento,  if(isnull(phoenix_emi),'Não',DATE_FORMAT(phoenix_emi, '%d/%m/%Y')) AS dta_phoenix  From mfin_pagamentos INNER JOIN mfin_fornecedores ON mfin_pagamentos.Fornecedor = mfin_fornecedores.Id  INNER JOIN mfin_clientes ON mfin_pagamentos.Cliente = mfin_clientes.Id  INNER JOIN mfin_pastas ON mfin_pagamentos.Pasta = mfin_pastas.Id  WHERE Emissao >= '".convertdata($_GET['data_ini'])."' AND Emissao <= '".convertdata($_GET['data_fim'])."'";
$pagar = mysql_query($query_pagar, $paivaconex) or die(mysql_error());
$row_pagar = mysql_fetch_assoc($pagar);
$totalRows_pagar = mysql_num_rows($pagar);
?>
<!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"><!-- InstanceBegin template="/Templates/template.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Paiva</title>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript">  
$(document).ready(function() {
	$("#selecionador").click(function(){
		$("input[type=checkbox]").attr("checked", true);
	})
	$("#desmarcador").click(function(){
		$("input[type=checkbox]").attr("checked", false);
	})
});

</script>

<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>

<strong><!-- InstanceBeginEditable name="Conteudo" -->
	<form action="contimatic_arquivo_emi.php" method="post">
    <p><a href="index.php">Voltar</a> </p>
    <p>
      <input type="button" name="selecionador" id="selecionador" value="Marcar Todos" />
      <input type="button" name="desmarcador" id="desmarcador" value="Desmarcar Todos" />
    </p>
    <p>Recebimentos</p>
	  <table border="1">
	    <tr>
	      <td>Cliente</td>
	      <td><strong>Pasta</strong></td>
	      <td><strong>Numero da NF</strong></td>
	      <td><strong>Emiss&atilde;o</strong></td>
	      <td>Valor L&iacute;quido</td>
          <td>Integrado</td>
	      <td>Incluir no Lote</td>
	      </tr>
	    <?php do { ?>
	      <tr>
	        <td><?php echo $row_receber['NomeFantasia']; ?></td>
	        <td><?php echo $row_receber['n_pasta']; ?></td>
	        <td><?php echo $row_receber['NumeroNota']; ?></td>
	        <td><?php echo $row_receber['dta_emissao']; ?></td>
	        <td align="right"><?php echo number_format($row_receber['vl'],2,',','.'); ?></td>
            <td><?php echo $row_receber['dta_phoenix']; ?></td>
	        <td align="center"><input type="checkbox" name="receber[]" id="receber" value="<?php echo $row_receber['rec_id']; ?>"/></td>
	        </tr>
	      <?php } while ($row_receber = mysql_fetch_assoc($receber)); ?>
	    </table>
	  <p>Pagamentos</p>
	  <table border="1">
	    <tr>
	      <td>Fornecedor</td>
	      <td>Numero NF</td>
	      <td>Emiss&atilde;o</td>
	      <td><strong>Vencimento</strong></td>
	      <td>Valor L&iacute;quido</td>
          <td>Integrado</td>
	      <td>Incluir no Lote</td>
	      </tr>
          <?php do { ?>
          
	    <tr>
	      <td><?php echo $row_pagar['nome_fantasia']; ?></td>
	      <td><?php echo $row_pagar['NumFatura']; ?></td>
	      <td><?php echo $row_pagar['dta_emissao']; ?></td>
	      <td><?php echo $row_pagar['dta_vencimento']; ?></td>
	      <td align="right"><?php echo number_format($row_pagar['vl'],2,',','.'); ?></td>
          <td><?php echo $row_pagar['dta_phoenix']; ?></td>
	      <td align="center"><input type="checkbox" name="pagar[]" id="pagar" value="<?php echo $row_pagar['pag_id']; ?>" /></td>
	      </tr>
          <?php } while ($row_pagar = mysql_fetch_assoc($pagar)); ?>
          
	    </table>
	  <p>&nbsp;</p>
	  <p>
	    <input type="submit" name="boto" id="boto" value="Gerar Lote" />
	  </p>
	  <p>&nbsp;</p>
    
    <input type="hidden" name="MM_insert" value="<?php echo substr($_GET['data_ini'],-4); ?>" />
    
    </form>
    
	<!-- InstanceEndEditable --></strong>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($receber);

mysql_free_result($pagar);
?>
