<?php
function vrrolpt1d($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 rolp12 where idnum1='.$idnum.' and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by item' ;
		$sql_entit='select *,sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2 from rolp11 where idnum1='.$idnum.' ' ;
		break;

	case 'E':
	    $sql_enti ='select * from rolp12 where enti2 like "'.$idnum.'%" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by fecha desc, docu, ptonumero' ;
		$sql_entit='select *, sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2  from rolp11 where enti like "'.$idnum.'%" group by enti' ;
		break;

	case 'I':
// 		$xgroup='item_lsub,item_descri ';
		$xgroup='nvdd,nvdd_descri ';
	    $sql_enti ='select * from rolp12 where nvdd like "'.$idnum.'" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by fecha desc, docu, ptonumero' ;
		$sql_entit='select *, sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2  from rolp12 where nvdd like "'.$idnum.'%" group by nvdd' ;
		break;

	case 'P':
		$xgroup='ptoe ';
	    $sql_enti ='select * from rolp11 where ptoe like "'.$idnum.'%" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by fecha desc, docu, ptonumero' ;
		$sql_entit='select *, sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2  from rolp11 where ptoe like "'.$idnum.'%" group by enti' ;
		break;
	case 'V':
		$xgroup='vndd ';
	    $sql_enti ='select * from rolp11 where vndd like "'.$idnum.'%" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by fecha desc, docu, ptonumero' ;
		$sql_entit='select *, sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2  from rolp11 where vndd like "'.$idnum.'%" group by enti' ;
		break;
	case 'C':$xgroup='csub ';break;
	case 'L':$xgroup='item_lsub ';break;
	case 'R':
	    $sql_enti ='select * from rolp12 where enti2 like "'.$idnum.'%" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by fecha desc, docu, ptonumero' ;
		$sql_entit='select *, sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2  from rolp11 where enti like "'.$idnum.'%" group by enti' ;
		break;
	case 'C':$xgroup='cdad ';break;

	case 'A':$xgroup='fanio ';break;
	case 'M':
		$xgroup='fanio,fmes ';
		$sql_enti ='select * from rolp11 where concat(fanio,fmes) = "'.$idnum.'"  order by fecha desc, docu, ptonumero desc' ;
		$sql_entit='select *, sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2  from rolp11 where concat(fanio,fmes)= "'.$idnum.'" group by enti' ;
		break;
	case 'S':
		$xgroup='fanio,fsema ';
	    $sql_enti ='select * from rolp11 where concat(fanio,fsema) = "'.$idnum.'"  order by fecha desc, docu, ptonumero desc' ;
		$sql_entit='select *, sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2  from rolp11 where  concat(fanio,fsema) = '.$idnum.' group by enti' ;
		break;

	case 'F':
		$xgroup='fecha ';
	    $sql_enti ='select * from rolp11 where fecha = "'.$idnum.'" and fecha>="'.$fini.'" and fecha<="'.$ffin.'" order by fecha desc, docu, ptonumero' ;
		$sql_entit='select *, sum(tingreso) as ttingreso, sum(tegreso) as ttegreso, sum(tprovi1) as ttprovi1, sum(tprovi2) as ttprovi2  from rolp11 where fecha = "'.$idnum.'" group by enti' ;
		break;

	default :
	$xgroup='';
	break;
}
        $res_entit=mysql_query($sql_entit,$link_vcrx);
        $res_enti=mysql_query($sql_enti,$link_vcrx);

?>




<?php
if(mysql_num_rows($res_entit)!=0)
{
$xtingreso=mysql_result($res_entit,0,'ttingreso');
$xtegreso =mysql_result($res_entit,0,'ttegreso');
$xtprovi1 =mysql_result($res_entit,0,'ttprovi1');
$xtprovi2=mysql_result($res_entit,0,'ttprovi2');
}
// 	echo $sql_enti;
?>



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



<table id="tabla_rolpt1"  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>V.UNIT.</th>

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


<?php	
	break;
	case 'I':
?>
	<th></th>
	<th>NOMBRE</th>
	<th>DOCU</th>
	<th>NUMERO</th>
	<th>FECHA</th>
	<th>CANT</th>
	<th>V.UNIT</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>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
	<th>CLIENTE</th>


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


<?php	
	break;
	case 'C':
?>
	<th></th>
	<th>CENTRO</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 'R':
?>
	<th></th>
	<th>DOCU</th>
	<th>NUMERO</th>
	<th>FECHA</th>
	<th>NOVEDAD</th>

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


  <th>INGRESO</th>
  <th>EGRESO</th>
  <th>PROVI 1</th>
  <th>PROVI 2</th>

  <th>TOTAL</th>
  <th>.</th>
  <th>DETALLE</th>
</tr>
<?php 
$filax=0; 

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

<tr valign="top" 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"><?php echo number_format($r_enti['cant'],$r_enti['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['numero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>
  <td align="left"><?php echo $r_enti['nvdd_descri']; ?></td>

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

<?php	
	break;
	case 'V':
?>
  <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>
  <td align="left"><?php echo $r_enti['enti_descri']; ?></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['numero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>
  <td align="right"><?php echo $r_enti['cant']; ?></td>
  <td align="right"><?php echo $r_enti['puni']; ?></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['numero']; ?></td>
  <td align="center"><?php echo $r_enti['fechadmy']; ?></td>
  <td align="left"><?php echo $r_enti['nvdd_descri']; ?></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></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['tingreso'],2) ?></td>
  <td align="right"><?php echo number_format($r_enti['tegreso'],2) ?></td>
  <td align="right"><?php echo number_format($r_enti['tprovi1'],2) ?></td>
  <td align="right"><?php echo number_format($r_enti['tprovi2'],2) ?></td>
  <td align="right"><?php echo '<b>'.number_format($r_enti['total'],2) ?></td>
  <td></td>

  <td align="left"><?php echo $r_enti['detalle']; ?></td>
</tr>

<?php }?>

</table>
<hr/>

<div>

<?php }?>