<?php
function vrcxppro1d($enti,$frepo)
{
	if(isset($_POST['fini']) && !empty($_POST['fini']))
	{
		$fini=$_POST['fini'];
	}
	else
	{
		$fini=date('2000-01-01');
	}
	
	if(isset($_POST['ffin']) && !empty($_POST['ffin']))
	{
		$ffin=$_POST['ffin'];
	}
	else
	{
		$ffin=date('Y-m-d');
	}

	$enti=$_POST['enti'];
	$frepo=$_POST['frepo'];
	
	require('../cfg/res.php');
	mysql_query("SET NAMES 'utf8'");
        $sql_enti='select *, sum(debito)as tdebito,sum(credito) as tcredito, sum(case when signo=1 then idnum1 end) as idnum0 from cxpa12 ';
				$sql_enti.=' where docuenti2 like "'.$frepo.'"';
				$sql_enti.='group by idnum1,docu,numero,fecha ';
	      $sql_enti.='order by fecha, signo desc, docu, ptonumero ';

				if ($frepo=='S')
				{
        $sql_enti='select *, sum(debito)as tdebito,sum(credito) as tcredito, sum(case when signo=1 then idnum1 end) as idnum0 from cxpa12 ';
				$sql_enti.=' where enti like "'.$enti.'" and fecha >= "'.$fini.'" AND fecha <= "'.$ffin.'" ';
				$sql_enti.='group by idnum1,docu,numero,fecha ';
	      $sql_enti.='order by fecha desc, signo, docu, ptonumero ';
				}

				if ($frepo=='R')
				{
        $sql_enti='select * from adrs0 where enti like "'.$enti.'%" and status !="X" order by defa desc,calle1';
				}


	$res_enti=mysql_query($sql_enti,$link_vcrx);
	$num_rows = mysql_num_rows($res_enti);	

	$sql_enti0='select * from enti0 where enti_codigo like "'.$enti.'"';
  $res_enti0=mysql_query($sql_enti0,$link_vcrx);
	echo '<b>'.mysql_result($res_enti0,0,'enti_descri').'</b>';
	
?>

<div style="overflow-y:scroll; height:250px; font-size:12px;">

<table id="tabla_cxppro"  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">
<?php  if ($frepo=='S'){?>	
	<th></th>
  <th>DOC.</th>
  <th>PTO.NUMERO</th>  
  <th>FECHA</th>
  <th>DEBITO</th>
  <th>CREDITO</th>
  <th>.</th>
  <th>CONCEPTO</th>
  <th>ST</th>
<?php } ?>
<?php  if ($frepo=='R'){?>	
	<th>e-mail</th>
	<th>TELEFONO</th>
	<th>DIRECCION</th>
	<th>PROV/CIUDAD</th>
	<th>CONTACTO</th>
	<th>VENDEDOR</th>
	<th>RECAUDADOR</th>
<?php } ?>
<?php  if ($frepo!='S' &$frepo!="R"){?>	
	<th></th>
  <th>DOC.</th>
  <th>PTO.NUMERO</th>  
  <th>FECHA</th>
  <th>DEBITO</th>
  <th>CREDITO</th>
	<th>.</th>
  <th>CONCEPTO</th>
  <th>ST</th>
<?php } ?>
</tr>
<?php 
$filax=0; 

if ($num_rows>0)
{	
while($r_enti=mysql_fetch_assoc($res_enti)){?>
<tr style=" <?php if($filax!=3){$filax++;}else{echo 'border-bottom:dotted 1px #000000;'; $filax=0;}?> ">

<?php  if ($frepo=='S'){?>	
  <td align="center">
    <a href="../lib/celectop1.php?docu=<?php echo $r_enti['docu']; ?>&idnum=<?php echo $r_enti['idnum1']; ?>&formato=1" target="_blank">
		<img src="../img/print2.png" width="20"  title="Imprimir  <?php echo $r_enti['docu'];?>-<?php echo $r_enti['numero'];?>"  /></a>
	</td>
  <td align="center"><?php echo $r_enti['docu']; ?></td>
  <td align="center" width="130px"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>
  <td align="right"><?php if($r_enti['tdebito']!=0){echo number_format($r_enti['tdebito'],2);} ?></td>
  <td align="right"><?php if($r_enti['tcredito']!=0){echo '<i>'.number_format(abs($r_enti['tcredito']),2);} ?></td>
	<td></td>
	<td align="left"><?php echo $r_enti['concepto']; ?></td>
  <td align="center"><?php echo '<span title="'.$r_enti['stat_descri'].'">'.$r_enti['status']; ?></td>
<?php } ?>
<?php  if ($frepo=='R'){?>	
  <td align="center"><?php echo $r_enti['email']; ?></td>
  <td align="center"><?php echo $r_enti['telefono']; ?></td>
  <td align="center"><?php echo $r_enti['calle1']; ?></td>
  <td align="center"><?php echo $r_enti['cdad_descri']; ?></td>
  <td align="center"><?php echo $r_enti['contacto']; ?></td>
  <td align="center"><?php echo $r_enti['vndd']; ?></td>
  <td align="center"><?php echo $r_enti['rcdd']; ?></td>
<?php } ?>
<?php  if ($frepo!='S' &$frepo!="R"){?>	
  <td align="center">
    <a href="../lib/celectop1.php?docu=<?php echo $r_enti['docu']; ?>&idnum=<?php echo $r_enti['idnum1']; ?>&formato=1" target="_blank">
		<img src="../img/print2.png" width="20"  title="Imprimir  <?php echo $r_enti['docu'];?>-<?php echo $r_enti['numero'];?>"  /></a>
	</td>
  <td align="center"><?php echo $r_enti['docu']; ?></td>
  <td align="center" width="130px"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>
  <td align="right"><?php echo number_format($r_enti['tdebito'],2); ?></td>
  <td align="right"><?php echo number_format($r_enti['tcredito'],2); ?></td>
	<td></td>
	<td align="left"><?php echo $r_enti['concepto']; ?></td>
  <td align="center"><?php echo '<span title="'.$r_enti['stat_descri'].'">'.$r_enti['status']; ?></td>
<?php } ?>
</tr>

<?php }?>
<?php }?>

</table>
<div>

<?php }?>