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

<?php

	$fini1= date('2000-01-01');
	if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
	{$fini1=date('2014-11-01');}


	$enti=$_GET['enti'];
	if(isset($_GET['fecha_ini']) && !empty($_GET['fecha_ini']))
	{$fini=$_GET['fecha_ini'];}
	else
	{
		$fini=date('2000-01-01');
		if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
		{$fini=date('2014-11-01');}
	}
	
	if(isset($_GET['fecha_fin']) && !empty($_GET['fecha_fin']))
	{$ffin=$_GET['fecha_fin'];}
	else
	{$ffin=date('Y-m-d');}



	
	require('../cfg/res.php');
	mysql_query("SET NAMES 'utf8'");

        $sql_enti='select * from enti0 where enti_codigo like "'.$enti.'"';
        $res_enti=mysql_query($sql_enti,$link_vcrx);
  
        $sql_cxcc='select idnum1,enti,enti_descri,fecha,fechadmy,docu,ptonumero,total,saldo,concepto
        		from cxco11 
        		where enti like "'.$enti.'" and fecha >= "'.$fini1.'" AND fecha <= "'.$ffin.'"   ';
        $sql_cxcc.=' union ';
        $sql_cxcc.='select idnum1,enti,enti_descri,fecha,fechadmy,docu,ptonumero,tcant as total,0 as saldo,concepto
        		from cxco22
        		where enti like "'.$enti.'" and fecha >= "'.$fini1.'" AND fecha <= "'.$ffin.'" ';
        $sql_cxcc.='ORDER BY fecha, docu, ptonumero ';
        $res_cxcc=mysql_query($sql_cxcc,$link_vcrx);

$tdebito=0;
$tcredito=0;
$tsaldo =0;



?>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cuentas X Cobrar (Cliente)</title>
<style type="text/css">
body{ font-family:"Courier New", Courier, monospace;}

</style>

</head>
<body>

<div align="center">
<div align="center" style="width:1150px; font-size:12px;">
<div align="center" style="font-size:18px;font-weight: bold; border:#000 solid 1px; background: #F7F7F7; margin:2px;">CUENTAS X COBRAR (CLIENTE)</div>

<table width="90%" cellspacing="0" cellpadding="2">
<tr valign="top">
<td width="50%">

<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse">
<tr>
	<th width="30%" style="background: #F7F7F7;">PARAMETROS</th>
	<th></th>
</tr>

	<tr>
    	<td style="font-weight:bolder;">C.I. /RUC :</td>
        <td><?php echo $_GET['enti'];?></td>
    </tr>

	<tr>
    	<td style="font-weight:bolder;">CLIENTE</td>
    	<td><?php echo mysql_result($res_enti,0,'enti_descri');?></td>
    </tr>

<tr>
    	<td style="font-weight:bolder;">FECHA</td>
	<td><?php echo date_format(date_create($fini),'d/M/Y').' - '.date_format(date_create($ffin),'d/M/Y');?></td>
</tr>


</table>




<td>
<!----++++++++++------>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse">
<tr>
	<th width="30%"  style="background: #F7F7F7;">I N F O</th>
	<th></th>    
</tr>
<tr>
	<td align="right">USUARIO:</td>
	<td><?php echo $_SESSION['user_vcrx_id'].' / '.$_SESSION['user_vcrx_descri'];?></td>
</tr>
<tr>
	<td align="right">FECHA / HORA :</td>
	<td><?php echo date('d/M/Y H:i:s');?></td>
</tr>
</table>
<!----++++++++++------>
</td>




</tr>
</table>
<!----++++++++++------>


<hr/>

<table border="0" width="90%" cellpadding="2" cellspacing="0" style="border-collapse:collapse">

<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
  <th>FECHA</th>
  <th>DOC.</th>
  <th>PTO.NUMERO</th>  
  <th>DEBITO</th>
  <th>CREDITO</th>
  <th>SALDO</th>
  <th>CONCEPTO</th>
</tr>


<?php 
$filax=0; 
$xsaldo = 0;

while($r_cxcc=mysql_fetch_assoc($res_cxcc)){?>


  <?php
  	if(mb_stristr('FC.NV.FP',substr($r_cxcc['docu'],0,2)))
  	{
  	$xdebito=$r_cxcc['total'];
  	$xcredito=0;
  	$tdebito=$tdebito+$r_cxcc['total'];
  	$xsaldo=$xsaldo+$r_cxcc['total'];
  	}
  	else
  	{
  	$xdebito=0;
  	$xcredito=$r_cxcc['total'];
  	$tcredito=$tcredito+$r_cxcc['total'];
  	$xsaldo=$xsaldo-$r_cxcc['total'];
  	}
  ?>



<?php
if($r_cxcc['fecha']>=$fini)
{
?>

<tr style=" <?php if($filax!=2){$filax++;}else{echo 'border-bottom:dotted 1px #000000;'; $filax=0;}?> ">
  <td align="center"><?php echo $r_cxcc['fechadmy']; ?></td>
  <td align="center"><?php echo $r_cxcc['docu']; ?></td>
  <td align="left" width="130px"><?php echo $r_cxcc['ptonumero']; ?></td>
  <td align="right"><?php if($xdebito!=0){echo number_format($xdebito,2);} ?></td>
  <td align="right"><?php if($xcredito!=0){echo number_format($xcredito,2);} ?></td>
  <td align="right"><?php echo number_format($xsaldo,2); ?></td>
  <td align="left"><?php echo $r_cxcc['concepto']; ?></td>
</tr>
<?php
}
?>

<?php }?>


<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
<th></th>
<th></th>
<th align="center">T O T A L E S</th>
<th align="right"><?php echo number_format($tdebito,2); ?></th>
<th align="right"><?php echo number_format($tcredito,2); ?></th>
<th align="right"><?php echo number_format($tdebito-$tcredito,2); ?></th>
</tr>

</table>




</div>
</div>

</body>
</html>

<?php //}?>