<?php
function vratrzl1d($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
switch ($grupo)
{
	case 'D':
	    $sql_enti ='select * from enti00 where idnum1='.$idnum.' and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by item' ;
		$sql_entit='select *,sum(tdcto) as ttdcto, sum(tice) as ttice, sum(tiva) as ttiva, sum(tirbp) as ttirbp from enti00 where idnum1='.$idnum.' ' ;
		break;

	case 'E':
	    $sql_enti ='select * from enti00 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 enti00 where enti like "'.$idnum.'%" group by enti' ;
		break;

	case 'I':
		$xgroup='item_lsub,item_descri ';
	    $sql_enti ='select * from enti00 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 enti00 where item like "'.$idnum.'%" group by enti' ;
		break;

	case 'P':
		$xgroup='ptoe ';
	    $sql_enti ='select * from enti00 where ptoe 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 enti00 where ptoe like "'.$idnum.'%" group by enti' ;
		break;
	case 'V':
		$xgroup='vndd ';
	    $sql_enti ='select * from enti00 where vndd 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 enti00 where vndd like "'.$idnum.'%" group by enti' ;
		break;
	case 'Z':$xgroup='zsub ';break;
	case 'L':$xgroup='item_lsub ';break;
	case 'R':$xgroup='item_at10 ';break;
	case 'C':$xgroup='cdad ';break;

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

	case 'F':
		$xgroup='fecha ';
	    $sql_enti ='select * from enti00 where fecha = "'.$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 enti00 where fecha = "'.$idnum.'" group by enti' ;
		break;

	default :
	$xgroup='';
	break;
}
	
// AJUSTA ADRS DEFAULT
	
$sql_atrd ='select * from atrd0 where atrd_atrz = "'.$idnum.'" and atrd_status!="X" order by atrd_docu ' ;
$res_atrd=mysql_query($sql_atrd,$link_vcrx);
// echo $sql_atrd;	
?>

<div style="overflow-y:scroll; height:250px; font-size:12px;">
<?php 
echo '<b>'.$idnum.' - '.$xdescri.'</b>';
?>
<table id="tabla_atrzl1"  border="0" width="100%" 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></th>
 	<th >DOCU</th>
 	<th >PTOE</th>
 	<th >DESDE</th>
 	<th >HASTA</th>
 	<th align="center"></th>
</tr>
<?php 
$filax=0; 

while($r_atrd=mysql_fetch_assoc($res_atrd))
{ ?>

<tr valign="center" style=" <?php if($filax!=3){$filax++;}else{echo 'border-bottom:dotted 1px #000000;'; $filax=0;}?> ">
  	<td align="center">
<!-- 		<a href="lblatrd0.php?ci=<?php echo $r_atrd['atrd_codigo']; ?>" target="_blank">
		<img src="../img/print2.png" width="20"  title="Imprimir  <?php echo $r_atrd['atrd_enti'];?>"  /></a> -->
    </td>

  <td align="center"><?php echo $r_atrd['atrd_docu']; ?></td>
  <td align="center"><?php echo $r_atrd['atrd_ptoe']; ?></td>
  <td align="center"><?php echo $r_atrd['atrd_desde']; ?></td>
  <td align="center"><?php echo $r_atrd['atrd_hasta']; ?></td>
</tr>

<?php }?>

</table>
<hr/>

<div>

<?php }?>