<?php
function vrcompt1d($grupo,$idnum,$fini,$ffin)
{
	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');
	}

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



?>


<?php
	include('php_gene1.php');
  $sql_empr='select * from empr0';
  $res_empr=mysql_query($sql_empr,$link_vcrx); 
//   $empr_cont=r_fiel('empr',$cfg_empr,'empr_cont');  
  $empr_cont=mysql_result($res_empr,0,'empr_cont');
//   echo '*/*/*'.$empr_cont;
  
switch ($grupo)
{
	case 'D':
// 	        $sql_enti ='select * from comp12 where idnum1='.$idnum.' and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by item' ;
	  $sql_enti ='select * from comp12 where idnum1='.$idnum.'  order by item' ;
		$sql_entit='select *,sum(tdcto) as ttdcto, sum(tice) as ttice, sum(tiva) as ttiva, sum(tirbp) as ttirbp from comp11 where idnum1='.$idnum.' ' ;
		break;

	case 'E':
	  $sql_enti ='select * from comp11 where enti like "'.$idnum.'%" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by fecha desc, docu, ptonumero' ;
		$sql_entit='select *, sum(tdcto) as ttdcto, sum(tice) as ttice, sum(tiva) as ttiva, sum(tirbp) as ttirbp  from comp11 where enti like "'.$idnum.'%" group by enti' ;
		break;

	case 'C':
	  $sql_enti ='select * from comp12 where ctas like "'.$idnum.'%" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" group by idnum1 order by fecha desc, docu, ptonumero ' ;
		$sql_entit='select *, sum(tdcto) as ttdcto, sum(tice) as ttice, sum(tiva) as ttiva, sum(tirbp) as ttirbp  from comp12 where ctas like "'.$idnum.'%" group by idnum1' ;
		break;

	case 'R':
	  $sql_enti ='select * from comp12 where cair like "'.$idnum.'%" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" group by idnum1 order by fecha desc, docu, ptonumero ' ;
		$sql_entit='select *, sum(tdcto) as ttdcto, sum(tice) as ttice, sum(tiva) as ttiva, sum(tirbp) as ttirbp  from comp12 where cair like "'.$idnum.'%" group by idnum1' ;
		break;

	case 'I':
		$xgroup='item_lsub,item_descri ';
	  $sql_enti ='select * from comp12 where item like "'.$idnum.'" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by fecha desc, docu, ptonumero' ;
		$sql_entit='select *, sum(tdcto) as ttdcto, sum(tice) as ttice, sum(tiva) as ttiva, sum(tirbp) as ttirbp  from comp12 where item like "'.$idnum.'%" group by item' ;
		break;

	case 'P':$xgroup='ptoe ';break;
	case 'V':$xgroup='vndd ';break;
	case 'Z':$xgroup='zsub ';break;
	case 'T':$xgroup='tpro ';break;
	case 'L':$xgroup='item_lsub ';break;

	case 'A':$xgroup='fanio ';break;
	case 'M':
		$xgroup='fanio,fmes ';
		$sql_enti ='select * from comp11 where concat(fanio,fmes) = "'.$idnum.'"  order by enti_descri, fecha desc, docu, ptonumero, idnum1 desc' ;
		$sql_entit='select *, sum(tdcto) as ttdcto, sum(tice) as ttice, sum(tiva) as ttiva, sum(tirbp) as ttirbp  from comp11 where concat(fanio,fmes) = "'.$idnum.'" group by enti' ;
		break;
	
	case 'S':	
		$xgroup='fanio,fsema ';
	    $sql_enti ='select * from comp11 where concat(fanio,fsema) = "'.$idnum.'"  order by enti_descri, fecha desc, docu, ptonumero, idnum1 desc' ;
		$sql_entit='select *, sum(tdcto) as ttdcto, sum(tice) as ttice, sum(tiva) as ttiva, sum(tirbp) as ttirbp  from comp11 where  concat(fanio,fsema) = '.$idnum.' group by enti' ;
		break;

	case 'F':
	case 'F':$xgroup='fecha ';break;

	default :
	$xgroup='';
	break;
}

        $res_entit=mysql_query($sql_entit,$link_vcrx);
// 	echo $sql_enti; 
        $res_enti=mysql_query($sql_enti,$link_vcrx);


?>




<?php
$xtdcto=mysql_result($res_entit,0,'ttdcto');
$xtice =mysql_result($res_entit,0,'ttice');
$xtiva =mysql_result($res_entit,0,'ttiva');
$xtirbp=mysql_result($res_entit,0,'ttirbp');
?>



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



<table id="tabla_compt1"  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
switch ($grupo)
{
	case 'D':
?>
	<th>ITEM</th>
	<th>NOMBRE</th>
	<th>CANT.</th>  
	<th>P.UNIT.</th>

<?php	
	break;
	case 'E':
?>
	<th></th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>


<?php	
	break;
	case 'C':
?>
	<th></th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>


<?php	
	break;
	case 'R':
?>
	<th></th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>


<?php	
	break;
	case 'I':
?>
	<th></th>
	<th>NOMBRE</th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
	<th>CANT</th>


<?php	
	break;
	case 'M':
?>
	<th></th>
	<th>NOMBRE</th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
<?php	
	break;
	case 'S':
?>
	<th></th>
	<th>NOMBRE</th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>

<?php	
	break;
	case 'F':
?>
	<th></th>
	<th>ANIO</th>
	<th>MES</th>
	<th>FECHA</th>
	<th></th>

<?php	
	break;
	case 'P':
?>
	<th></th>
	<th>PTO/EMI</th>
	<th></th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'V':
?>
	<th></th>
	<th>VNDD</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'Z':
?>
	<th></th>
	<th>ZONA</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'L':
?>
	<th></th>
	<th>LINEA</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'C':
?>
	<th></th>
	<th>CODIGO</th>
	<th>CUENTA</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'R':
?>
	<th></th>
	<th>COD.RET.</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	default:
?>
	<th></th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
	
<?php }; ?>


  <th>SUBT</th>

  <?php if ($xtdcto<>0){ ?>  
  <th>DSCTO</th>
  <?php } ?>

  <?php if ($xtice<>0){ ?>  
  <th>ICE</th>
  <?php } ?>

  <?php if ($xtiva<>0){ ?>  
  <th>IVA</th>
  <?php } ?>

  <?php if ($xtirbp<>0){ ?>  
  <th>IRBP</th>
  <?php } ?>

  <th>TOTAL</th>
  <th>.</th>
  <th>DETALLE</th>
  <?php if($empr_cont==1){?>
  <th>CAIR</th>
  <th>CUENTA</th>
  <th>CONTABLE</th>
  <?php } ?>
</tr>
<?php 
$filax=0; 

while($r_enti=mysql_fetch_assoc($res_enti))
{ 

$item_codigo=$r_enti['item'];
$item_duni=$r_enti['item_duni'];

if(substr($item_codigo,0,4)=='9999'){$item_duni=2;}
  
?>

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



<?php
switch ($grupo)
{
	case 'D':
?>
  <td align="left"><?php echo $r_enti['item']; ?></td>
  <td align="left"><?php echo $r_enti['item_descri']; ?></td>
  <td align="right" title="<?php echo $r_enti['cant']; ?>"><?php echo number_format($r_enti['cant'],$item_duni) ?></td>
  <td align="right"><?php echo number_format($r_enti['puni'],2) ?></td>

<?php	
	break;
	case 'E':
?>
  <td>
    <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"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>

<?php	
	break;
	case 'C':
?>
  <td>
    <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"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>

<?php	
	break;
	case 'R':
?>
  <td>
    <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"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>

<?php	
	break;
	case 'I':
?>
	<td>
    <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="left"><?php echo $r_enti['enti_descri']; ?></td>
  <td align="center"><?php echo $r_enti['docu']; ?></td>
  <td align="center"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>
  <td align="right"><?php echo number_format($r_enti['tcant'],2) ?></td>

<?php	
	break;
	case 'M':
?>
	<td>
    <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="left"><?php echo $r_enti['enti_descri']; ?></td>
  <td align="center"><?php echo $r_enti['docu']; ?></td>
  <td align="center"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>

<?php	
	break;
	case 'S':
?>
	<td>
    <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="left"><?php echo $r_enti['enti_descri']; ?></td>
  <td align="center"><?php echo $r_enti['docu']; ?></td>
  <td align="center"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>

<?php	
	break;
	default:
?>
  <td>
    <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"><?php echo $r_enti['ptonumero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>

<?php } ?>






  <td align="right"><?php echo number_format($r_enti['tsubt'],2) ?></td>

  <?php if ($xtdcto<>0){ ?>  
  <td align="right" title="<?php echo number_format($r_enti['dcto'],2).'%' ?>"><i><?php echo number_format($r_enti['tdcto'],2) ?></i></td>
  <?php } ?>

  <?php if ($xtice<>0){ ?>  
  <td align="right" title="<?php echo number_format($r_enti['ice'],2).'%' ?>"><?php echo number_format($r_enti['tice'],2) ?></td>
  <?php } ?>

  <?php if ($xtiva<>0){ ?>  
  <td align="right" title="<?php echo number_format($r_enti['iva'],2).'%' ?>"><?php echo number_format($r_enti['tiva'],2) ?></td>
  <?php } ?>

  <?php if ($xtirbp<>0){ ?>  
  <td align="right" title="<?php echo number_format($r_enti['irbp'],4).'' ?>"><?php echo number_format($r_enti['tirbp'],2) ?></td>
  <?php } ?>

  <td align="right"><?php echo '<b>'.number_format($r_enti['total'],2) ?></td>
  <td></td>

  <td align="left"><?php echo $r_enti['detalle']; ?></td>
  <?php if($empr_cont==1){?>
  <td align="center" title="<?php echo $r_enti['cair_descri']; ?>"><?php echo $r_enti['cair']; ?></td>
  <td align="left"><?php echo $r_enti['ctas']; ?></td>
  <td align="left"><?php echo $r_enti['ctas_descri']; ?></td>
  <?php } ?>  
</tr>

<?php }?>

</table>
<hr/>

<div>

<?php }?>