<?php 
session_start();

require('../cfg/res.php');
require('../cfg/cfg.php');


$xacceso=0;
$sql_acce='select * from usrdoc1 where docu like "FC%" and info="1" and user="'.$_SESSION['user_vcrx_id'].'" ';
$res_acce=mysql_query($sql_acce,$link_vcrx);
if (mysql_num_rows($res_acce)!=0){$xacceso=1;}
if (mb_stristr('sist.supe',$_SESSION['user_vcrx_tipo'])){$xacceso=1;}
if ($xacceso==0){echo '<font size="8" color="red"><b>';die('No tiene acceso a Informe de Ventas ' );}	


$fecha1 = date('Y-m-j');
$nuevafecha = strtotime ( '-1 month' , strtotime ( $fecha1 ) ) ;
$xfecha1 = date ( 'Y/m/j' , $nuevafecha );
$xfecha1= date('Y/m/'.'1');
$xfecha2= date('Y/m/d');

$sql_datesp='SET lc_time_names = "es_UY"';
$res_datesp=mysql_query($sql_datesp,$link_vcrx);



$xfgrou='D';
if(isset($_POST['fgrou']) && !empty($_POST['fgrou']))
{$xfgrou=$_POST['fgrou'];}


if(isset($_POST['fcodi']) && !empty($_POST['fcodi']))
{
	$xfcodi=$_POST['fcodi'];
}
switch ($xfcodi)
{
	case '1': $item_codi='nvdd';break;
	case '2': $item_codi='nvdd_codigo';break;
	case '3': $item_codi='nvdd_codigo';break;
	default : $item_codi='nvdd';break;
}
// echo $item_codi;

$sql_rolpt='select rolp12.*,
	sum(tcant) as ttcant,
	sum(tsubt) as ttsubt,
	sum(tingreso) as ttingreso,
	sum(tegreso) as ttegreso,
	sum(tprovi) as ttprovi,
	sum(tfalta) as ttfalta,
	sum(total) as ttotal
	from rolp12 where ';

$sql_rolpt.='(';

if(isset($_POST['fecha_ini']) && !empty($_POST['fecha_ini']) && isset($_POST['fecha_fin']) && !empty($_POST['fecha_fin']))
{
	$xfecha1=$_POST['fecha_ini'];
	$xfecha2=$_POST['fecha_fin'];
}

$sql_rolpf='select min(fecha) as fecha from rolp1 where status!="X" and status!="O" and fecha>="'.$xfecha1.'"';
$res_rolpf=mysql_query($sql_rolpf,$link_vcrx);
$xfecha1b=mysql_result($res_rolpf,0,'fecha');

$sql_rolpf='select max(fecha) as fecha from rolp1 where status!="X" and status!="O" and fecha<="'.$xfecha2.'"';
$res_rolpf=mysql_query($sql_rolpf,$link_vcrx);
$xfecha2b=mysql_result($res_rolpf,0,'fecha');

	$xanios=date('Y',strtotime($xfecha2b))-date('Y',strtotime($xfecha1b))+1;
	$xanio1=date('Y',strtotime($xfecha1b));
	$xanio2=date('Y',strtotime($xfecha2b));

	$dias=intval(strtotime($xfecha2b) - strtotime($xfecha1b))/60/60/24;
    $anios=date('Y',strtotime($xfecha2))-date('Y',strtotime($xfecha1));

	switch ($xfgrou)
	{
	case 'M':
		$xfecha1=date('Y/m/'.'1',strtotime($xfecha1));

		if($dias<=31)
		{$xfecha1=date('Y/m/'.'1',strtotime('-2 month',strtotime($xfecha1)));}

		//if($dias>360)
		//{$xfecha1=date('Y/'.'1/1',strtotime($xfecha1));}

		//if($anios!=0)
		//{$xfecha1=date('Y/'.'1/1',strtotime($xfecha1));}
		
		$xfecha2=date('Y/m/t',strtotime($xfecha2));
		break;

	case 'S':
		if($dias<=7)
		{$xfecha1=date('Y/m/d',strtotime('-1 month',strtotime($xfecha1)));}
		
		$xfecha1=date('Y/m/d',strtotime('-'.date('w',strtotime($xfecha1)).' day',strtotime($xfecha1)));
		$xfecha2=date('Y/m/d',strtotime('+'.(6-date('w',strtotime($xfecha2))).' day',strtotime($xfecha2)));
		break;
	}

	$sql_rolpt.='fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"';
//}
//else
//{
//	$sql_rolpt.=' fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"' ;
//}

$sql_rolpt.=')';
$sql_rolpt=str_replace(')(',')||(',$sql_rolpt);

if(isset($_POST['docu']) && !empty($_POST['docu']))
{
	//$sql_rolpt.=' and  (docu like "'.$_POST['docu'].'%" or docu_descri like "%'.$_POST['docu'].'%" ) ';
	$sql_rolpt.=' and  (docu like "'.$_POST['docu'].'%"  ) ';
	$xfdocu=$_POST['docu'];
}

if(isset($_POST['enti2']) && !empty($_POST['enti2']))
{
	$sql_rolpt.=' and  (enti2 like "'.$_POST['enti2'].'%" or enti_descri like "%'.$_POST['enti2'].'%" ) ';
	$xfenti=$_POST['enti2'];
}

if(isset($_POST['item']) && !empty($_POST['item']))
{
	$sql_rolpt.=' and  (item like "'.$_POST['item'].'%" or item_descri like "%'.$_POST['item'].'%" ) ';
	$xfitem=$_POST['item'];
}

if(isset($_POST['ptov']) && !empty($_POST['ptov']))
{
	$sql_rolpt.=' and  (ptov like "'.$_POST['ptov'].'%" or ptov_descri like "%'.$_POST['ptov'].'%" ) ';
	$xfitem=$_POST['ptov'];
}



if(isset($_POST['fcdad']) && !empty($_POST['fcdad']))
{
	$sql_rolpt.=' and  (prvc_descri like "%'.$_POST['fcdad'].'%" or enti_cdad like "'.$_POST['fcdad'].'%" or cdad_descri like "%'.$_POST['fcdad'].'%"  ) ';
	$xfcdad=$_POST['fcdad'];
}

if(isset($_POST['flsub']) && !empty($_POST['flsub']))
{
	$sql_rolpt.=' and  (item_lsub like "'.$_POST['flsub'].'%" or lsub_descri like "%'.$_POST['flsub'].'%" ) ';
	$xflsub=$_POST['flsub'];
}

if(isset($_POST['fcsub']) && !empty($_POST['fcsub']))
{
	$sql_rolpt.=' and  (enti_csub like "'.$_POST['fcsub'].'%" or csub_descri like "%'.$_POST['fcsub'].'%" ) ';
	$xfcsub=$_POST['fcsub'];
}

if(isset($_POST['fvndd']) && !empty($_POST['fvndd']))
{
	$sql_rolpt.=' and  (vndd like "'.$_POST['fvndd'].'%" ) ';
	$xfvndd=$_POST['fvndd'];
}


if(isset($_POST['frcdd']) && !empty($_POST['frcdd']))
{
	//$sql_rolpt.=' and  (enti like "%'.$_POST['frcdd'].'%" ) ';
	$xfrcdd=$_POST['frcdd'];
}


if(isset($_POST['fctlg']) && !empty($_POST['fctlg']))
{
	$xfctlg=$_POST['fctlg'];
}


	$sql_rolpt.=' and(status!="X") ';
	$sql_rolpt.=' and(status!="O") ';



$xforde='D';
if(isset($_POST['forde']) && !empty($_POST['forde']))
{$xforde=$_POST['forde'];}

switch ($xfgrou)
{
	case 'D':$xgroup='docu,ptoe,numero,idnum1 ';break;
	case 'E':$xgroup='enti_csub,enti_descri,enti2 ';break;
	case 'G':$xgroup='enti_csub,enti_descri,enti2 ';break;
// 	case 'I':$xgroup='item_lsub,item_descri,item ';break;
	case 'I':$xgroup='nvdd_posi,nvdd,nvdd_descri ';break;

	case 'P':$xgroup='ptoe ';break;
	case 'V':$xgroup='vndd_descri,vndd ';break;
	case 'C':$xgroup='csub ';break;
	case 'L':$xgroup='item_lsub ';break;
	case 'R':$xgroup='enti_csub,enti_descri,enti2 ';break;
	case 'C':$xgroup='cdad ';break;

	case 'A':$xgroup='fanio ';break;
	case 'M':$xgroup='fanio,fmes ';break;
	case 'S':$xgroup='fanio,fsema ';break;
	case 'F':$xgroup='fecha ';break;

	default :$xgroup='enti_csub,enti_descri,enti2 ';break;
}

switch ($xforde)
{
	case 'D':$xorder=$xgroup;break;
	case 'C':$xorder=str_replace('_descri','',$xgroup);
			$xorder=str_replace(',nvdd',','.$item_codi.',nvdd_descri,item',$xorder);break;
	case 'T':$xorder='ttotal desc, '.str_replace('_descri','',$xgroup);break;

	default :$xorder=$xgroup;break;
}

//$xorder=str_replace('_codigo','',$xorder)
// echo $xfgrou;
$xnvdds=0;
$xwidth = 100;
if ($xfgrou=='G')
{
		$xfecha1=date('Y-m-01',strtotime($xfecha1));
		$xfecha2=date('Y-m-t', strtotime($xfecha2));
		$xf2col='false';
		$sql_nvdds='select distinct nvdd,nvdd_abrev from rolp12 where fecha>="'.$xfecha1.'" and fecha<="'.$xfecha2.'" order by nvdd_posi,nvdd';
		$res_nvdds=mysql_query($sql_nvdds,$link_vcrx);
		$xnvdds = mysql_num_rows($res_nvdds);
		$xcnvd=0;
		$sql_pivot='';
		while ($r_nvd0=mysql_fetch_assoc($res_nvdds))	
		{
			$xcnvd++;
			$xnvd=$r_nvd0['nvdd'];
			$sql_pivot.='sum(case when nvdd="'.$xnvd.'" then tsubt end) as st'.$xnvd.',';	
		}

	$sql_rolpt=str_replace($xfecha1,$xfecha1c,$sql_rolpt);
	$sql_rolpt=str_replace('rolp12.*,','rolp12.*,'.$sql_pivot,$sql_rolpt);

	$sql_rolptt=str_replace($xfecha1,$xfecha1c,$sql_rolptt);
	$sql_rolptt=str_replace('rolp12.*,','rolp12.*,'.$sql_pivot,$sql_rolptt);
	// 	echo $sql_rolpt;
	if($xnvdds>6){$xwidth = 100 + ($xnvdds-6)*10;}
	
}
// echo $sql_pivot;

// $res_rolptt=mysql_query($sql_rolpt,$link_vcrx);
// $sql_rolpt.=' group by '.$xgroup;
// $sql_rolpt.=' order by '.$xorder;
// $res_rolpt=mysql_query($sql_rolpt,$link_vcrx);

echo str_repeat('-',date('s')*2).'';


$res_rolptt=mysql_query($sql_rolpt,$link_vcrx);
$xttingreso=mysql_result($res_rolptt,0,'ttingreso');
$xttegreso=mysql_result($res_rolptt,0,'ttegreso');
$xttprovi=mysql_result($res_rolptt,0,'ttprovi');
$sql_rolpt.=' group by '.$xgroup;
$sql_rolpt.=' order by '.$xorder;
// echo $sql_rolpt;
$res_rolpt=mysql_query($sql_rolpt,$link_vcrx);
$totreg = mysql_num_rows($res_rolpt);
echo str_repeat('-',date('s')*2).'';

?>
<table id="tabla_cxccli" width="100%" border="0" cellspacing="0" cellpadding="2" style="border-collapse:collapse;font-size:12px; border:#000000 solid 1px;">

<tr style="border-bottom:#000000 solid 2px; ">
<?php
switch ($xfgrou)
{
	case 'D':
?>

	<th></th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
	<th>NOMBRE</th>



<?php	
	break;
	case 'E':
?>
	<th></th>
	<th>CENTRO</th>
	<th>EMPLEADO</th>
	<th>NOMBRE</th>
	<th>DIAS</th>



<?php	
	break;
	case 'I':
?>
	<th></th>
	<th></th>
	<th>ITEM</th>
	<th>NOMBRE</th>
	<th>CANT</th>


<?php	
	break;
	case 'M':
?>
	<th></th>
	<th>ANIO</th>
	<th>MES</th>
	<th>NOMBRE</th>
	<th></th>
<?php	
	break;
	case 'S':
?>
	<th></th>
	<th>ANIO</th>
	<th>SEMA</th>
	<th></th>
	<th></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 'C':
?>
	<th></th>
	<th>CENTRO</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'G':
?>
	<th></th>
	<th></th>
	<th>CI</th>
	<th>NOMBRE</th>
	<th>DIAS</th>

<?php	

// if ($xfgrou=='G')
if (1==1)
{
		$xf2col='false';
		$res_nvdds=mysql_query($sql_nvdds,$link_vcrx);
		$xnvdds = mysql_num_rows($res_nvdds);
		$xcnvd=0;
		$sql_pivot='';
		while ($r_nvd0=mysql_fetch_assoc($res_nvdds))	
		{
			$xnvd=$r_nvd0['nvdd_abrev'];
			if ($xnvd==""){$xnvd="N---";}
			echo '<th>'.$xnvd.'</th>';
		}
}
?>
	
	
	
<?php	
	break;
	case 'R':
?>
	<th></th>
	<th></th>
	<th>CI</th>
	<th>NOMBRE</th>
	<th></th>
<?php } ?>


	<th>INGRESOS</th>
	<th>EGRESOS</th>
	<th>PROVIS.</th>

	<th>TOTAL</th>

<?php
switch ($xfgrou)
{
	case 'D':
?>
	<th></th>

<?php	
	break;
	case 'E':
?>
	<th>DETALLE</th>

<?php	
	break;
	case 'I':
?>
	<th>DETALLE</th>
<?php } ?>






</tr>

<?php 
$filax=0;

//$urcdd='';

while($r_rolpt=mysql_fetch_assoc($res_rolpt))
{
$duni=2;
?>

<?php	
//if ($r_rolpt['enti_modelo']==$urcdd)
//{if($urcdd==$prcdd){$filax=1;}}
//else
//{if($urcdd!=$prcdd){}else{$filax=4;}}

//$prcdd=$urcdd;
//$urcdd=$r_rolpt['enti_modelo'];

?>
	
	<tr class="filax" id="<?php echo $r_ped['idnum1']; ?>" valign="top" align="center" style=" <?php if($filax>=4){echo 'border-top:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >

<?php
switch ($xfgrou)
{
	case 'D':
?>
<td>
    <a href="../lib/celectop1.php?docu=<?php echo $r_rolpt['docu']; ?>&idnum=<?php echo $r_rolpt['idnum1']; ?>&formato=1" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['docu'];?>-<?php echo $r_rolpt['numero'];?>"  /></a>
</td>
        <td align="center"><?php echo'<span title="'.$r_rolpt['docu'].'">'.$r_rolpt['docu'].'</span>';?></td>
	<td align="center"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['idnum1']; ?>',this);"><?php echo '<span title="'.$r_rolpt['ptonumero'].'">'.$r_rolpt['ptonumero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_rolpt['fechadmy'].'">'.$r_rolpt['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_rolpt['enti2'].'">'.$r_rolpt['enti_descri'].'</span>';?></td>

<?php	
	break;
	case 'E':
?>
	<td>
    	<a href="../lib/impr_rolpt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_rolpt['enti2']; ?>&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['enti2'];?>"  /></a>
	</td>
        <td align="center"><?php echo'<span title="'.$r_rolpt['enti_csub'].'">'.$r_rolpt['csub_descri'].'</span>';?></td>
	<td align="left"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['enti2']; ?>',this);"><?php echo '<span title="'.$r_rolpt['enti2'].'">'.$r_rolpt['enti2'].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_rolpt['enti_direccion'].'">'.$r_rolpt['enti_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="">'.number_format(30-$r_rolpt['ttfalta'],0).'</span>';?></td>

<?php	
	break;
	case 'I':
?>
	<td>
    	<a href="../lib/impr_rolpt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_rolpt['nvdd']; ?>&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['nvdd'];?>"  /></a>
	</td>
<!--         <td align="center"><?php echo'<span title="'.$r_rolpt['nvdd'].'">'.$r_rolpt['nvdd_descri'].'</span>';?></td> -->
        <td align="center"></td>
	<td align="center"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['nvdd']; ?>',this);"><?php echo '<span title="'.$r_rolpt['nvdd'].'">'.$r_rolpt[$item_codi].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_rolpt['nvdd'].'">'.$r_rolpt['nvdd_descri'].'</span>';?></td>
   	<td align="right"><?php echo number_format($r_rolpt['ttcant'],$duni);?></td>


<?php	
	break;
	case 'M':
?>
	<td>
    	<a href="../lib/impr_rolpt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_rolpt['fanio'].$r_rolpt['fmes']; ?>&fecha_ini=<?php echo  $r_rolpt['fanio'].'/'.$r_rolpt['fmes'].'/01';?>&fecha_fin=<?php echo $r_rolpt['fanio'].'/'.$r_rolpt['fmes'].'/'.cal_days_in_month(CAL_GREGORIAN, $r_rolpt['fmes'], $r_rolpt['fanio']);?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['fmesn'];?>"  /></a>
	</td>
		
        <td align="center"><?php echo'<span title="'.$r_rolpt['fanio'].'">'.$r_rolpt['fanio'].'</span>';?></td>
	<td align="center"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['fanio'].$r_rolpt['fmes']; ?>',this);"><?php echo '<span title="'.$r_rolpt['fmes'].'">'.$r_rolpt['fmes'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_rolpt['fmesn'].'">'.$r_rolpt['fmesn'].'</span>';?></td>
	<td></td>

<?php	
	break;
	case 'S':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_rolpt['item'];?>','<?php echo $r_rolpt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_rolpt['fanio'].'">'.$r_rolpt['fanio'].'</span>';?></td>
	<td align="center"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['fanio'].$r_rolpt['fsema']; ?>',this);"><?php echo '<span title="'.$r_rolpt['fsema'].'">'.$r_rolpt['fsema'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'F':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_rolpt['item'];?>','<?php echo $r_rolpt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_rolpt['fanio'].'">'.$r_rolpt['fanio'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_rolpt['fmesn'].'">'.$r_rolpt['fmesn'].'</span>';?></td>
	<td align="center"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['fecha']; ?>',this);?>',this);"><?php echo '<span title="'.$r_rolpt['fechadmy'].'">'.$r_rolpt['fdian'].'-'.$r_rolpt['fdia'].'</span>';?></a> </td>
	<td></td>

<?php	
	break;
	case 'P':
?>
	<td>
    	<a href="../lib/impr_rolpt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_rolpt['ptoe']; ?>&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['ptoe'];?>"  /></a>
	</td>
	<td align="left"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['ptoe']; ?>',this);"><?php echo '<span title="'.$r_rolpt['ptoe'].'">'.$r_rolpt['ptoe'].'</span>';?></a> </td>
	<td align="left"></td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'V':
?>
	<td>
    	<a href="../lib/impr_rolpt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_rolpt['vndd']; ?>&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['vndd'];?>"  /></a>
	</td>
	<td align="center"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['vndd']; ?>',this);"><?php echo '<span title="'.$r_rolpt['vndd'].'">'.$r_rolpt['vndd'].'</span>';?></a> </td>
  <td align="left"><?php echo'<span title="'.$r_rolpt['vndd'].'">'.$r_rolpt['vndd_descri'].'</span>';?></td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'C':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_rolpt['item'];?>','<?php echo $r_rolpt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_rolpt['csub'].'">'.$r_rolpt['csub'].'</span>';?></td>
	<td align="left"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['csub']; ?>',this);"><?php echo '<span title="'.$r_rolpt['csub_descri'].'">'.$r_rolpt['csub_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>
<?php	
	break;
	case 'G':
?>
<!-- 
	<td>
    	<a href="../lib/impr_rolpt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_rolpt['enti2']; ?>&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['enti2'];?>"  /></a>
	</td>
 -->
	<td>
    	<a href="../lib/impr_rolxe0.php?fgrou=R&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>&fenti=<?php echo $r_rolpt['enti2'];?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['enti2'];?>"  /></a>
	</td>
        <td align="center"><?php echo'<span title="'.$r_rolpt['enti_csub'].'">'.$r_rolpt['csub_descri'].'</span>';?></td>
	<td align="left"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['enti2']; ?>',this);"><?php echo '<span title="'.$r_rolpt['enti2'].'">'.$r_rolpt['enti2'].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_rolpt['enti_direccion'].'">'.$r_rolpt['enti_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="">'.number_format(30-$r_rolpt['ttfalta'],0).'</span>';?></td>

	<?php	
// if ($xfgrou=='G')
if (1==1)
{
		$xf2col='false';
		$res_nvdds=mysql_query($sql_nvdds,$link_vcrx);
		$xnvdds = mysql_num_rows($res_nvdds);
		$xcnvd=0;
		$sql_pivot='';
		while ($r_nvd0=mysql_fetch_assoc($res_nvdds))	
		{
			$xnvd=$r_nvd0['nvdd'];
			echo '<td  align="right">'.number_format($r_rolpt['st'.$xnvd],$duni).'</td>';
		}
}
?>
		
		
		
		
		
		
		
<?php	
	break;
	case 'R':
?>
	<td>
    	<a href="../lib/impr_rolxe0.php?fgrou=R&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>&fenti=<?php echo $r_rolpt['enti2'];?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_rolpt['enti2'];?>"  /></a>
	</td>
        <td align="center"><?php echo'<span title="'.$r_rolpt['enti_csub'].'">'.$r_rolpt['csub_descri'].'</span>';?></td>
	<td align="left"><a href="#" onClick="rolpt1d('<?php echo $xfgrou; ?>','<?php echo $r_rolpt['enti2']; ?>',this);"><?php echo '<span title="'.$r_rolpt['enti2'].'">'.$r_rolpt['enti2'].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_rolpt['enti_direccion'].'">'.$r_rolpt['enti_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="">'.number_format(30-$r_rolpt['ttfalta'],0).'</span>';?></td>


<?php }?>
		
<?php
	if ($xfgrou=='R')
	{
?>
<td>
	<?php
		$sql_rolpe=$sql_rolpt;
		$sql_rolpe=str_replace('where ','where nvdd like "1%" and enti2="'.$r_rolpt['enti2'].'" and ',$sql_rolpe);
		$sql_rolpe=str_replace('group by ','group by nvdd,',$sql_rolpe);
		$sql_rolpe=str_replace('order by ','order by nvdd_posi,nvdd,',$sql_rolpe);
		$res_rolpe=mysql_query($sql_rolpe,$link_vcrx);
		echo '<table width="100%">';
		while($r_rolpe=mysql_fetch_assoc($res_rolpe))
		{
			echo '<tr>';
			echo'<td  align="left">'. $r_rolpe['nvdd_descri'].'</td>';
			echo'<td  align="right">'. number_format($r_rolpe['tingreso'],2).'</td>';
			echo '</tr>';
		}
// 		echo'<td  align="right"><b>TOTAL</b></td>';
//    	echo '<td align="right"><b>'. number_format($r_rolpt['ttingreso'],2).'</b></td>';
		echo '</table>';
	?>
</td>		
<td>
	<?php
		$sql_rolpe=$sql_rolpt;
		$sql_rolpe=str_replace('where ','where nvdd like "2%" and enti2="'.$r_rolpt['enti2'].'" and ',$sql_rolpe);
		$sql_rolpe=str_replace('group by ','group by nvdd,',$sql_rolpe);
		$sql_rolpe=str_replace('order by ','order by nvdd_posi,nvdd,',$sql_rolpe);
		$res_rolpe=mysql_query($sql_rolpe,$link_vcrx);
		echo '<table width="100%">';
		while($r_rolpe=mysql_fetch_assoc($res_rolpe))
		{
			echo '<tr>';
			echo'<td  align="left">'. $r_rolpe['nvdd_descri'].'</td>';
			echo'<td  align="right">'. number_format($r_rolpe['tegreso'],2).'</td>';
			echo '</tr>';
		}
// 		echo'<td  align="right"><b>TOTAL</b></td>';
//    	echo '<td align="right"><b>'. number_format($r_rolpt['ttegreso'],2).'</b></td>';
		echo '</table>';
	?>

</td>		
<td>
	<?php
		$sql_rolpe=$sql_rolpt;
		$sql_rolpe=str_replace('where ','where (nvdd like "3%" or nvdd like "4%") and enti2="'.$r_rolpt['enti2'].'" and ',$sql_rolpe);
		$sql_rolpe=str_replace('group by ','group by nvdd,',$sql_rolpe);
		$sql_rolpe=str_replace('order by ','order by nvdd_posi,nvdd,',$sql_rolpe);
		$res_rolpe=mysql_query($sql_rolpe,$link_vcrx);
		echo '<table width="100%">';
		while($r_rolpe=mysql_fetch_assoc($res_rolpe))
		{
			echo '<tr>';
			echo'<td  align="left">'. $r_rolpe['nvdd_descri'].'</td>';
			echo'<td  align="right">'. number_format($r_rolpe['tprovi'],2).'</td>';
			echo '</tr>';
		}
// 		echo'<td  align="right"><b>TOTAL</b></td>';
//    	echo '<td align="right"><b>'. number_format($r_rolpt['ttprovi'],2).'</b></td>';
		echo '</table>';
	?>

</td>		

	</tr>
	<tr style ="border-bottom:dotted 1px">
		<td></td>		
		<td></td>		
		<td></td>		
		<td></td>		
		<td></td>		
   	<td align="right"><b><?php echo number_format($r_rolpt['ttingreso'],2);?></b></td>
   	<td align="right"><b><?php echo number_format($r_rolpt['ttegreso'],2);?></b></td>
   	<td align="right"><b><?php echo number_format($r_rolpt['ttprovi'],2);?></b></td>
   	<td align="right"><b><?php echo number_format($r_rolpt['ttotal'],2);?></b></td>
		
<?php
	}else{
?>
   	<td align="right"><?php echo number_format($r_rolpt['ttingreso'],2);?></td>
   	<td align="right"><?php echo number_format($r_rolpt['ttegreso'],2);?></td>
   	<td align="right"><?php echo number_format($r_rolpt['ttprovi'],2);?></td>

   	<td align="right"><?php echo '<b>'.number_format($r_rolpt['ttotal'],2);?></td>
<?php
	}
?>

		
</tr>
<?php }?>

<!-- 
<?php	
switch ($xfgrou)
{
	case 'D':
?>
        <td align="center"></td>

<?php	
	break;
	case 'E':
?>
	<td align="center"></td>


<?php	
	break;
	case 'G':
?>
	<td align="center"></td>


<?php	
	break;
	case 'I':
?>
	<td align="center"></td>


	
<?php }?>
	 -->
	
	
<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
	<th></th>
	<th></th>
	<th></th>
	<th>TOTALES</th>
	<th></th>
	
	
		<?php	
if ($xfgrou=='G')
{
		$xf2col='false';
		$res_nvdds=mysql_query($sql_nvdds,$link_vcrx);
		$xnvdds = mysql_num_rows($res_nvdds);
		$xcnvd=0;
		$sql_pivot='';
		while ($r_nvd0=mysql_fetch_assoc($res_nvdds))	
		{
			$xnvd=$r_nvd0['nvdd'];
			echo '<th  align="right">'.number_format(mysql_result($res_rolptt,0,'st'.$xnvd),2).'</th>';
		}
}
?>

	
	<th align="right"><?php echo number_format(mysql_result($res_rolptt,0,'ttingreso'),2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_rolptt,0,'ttegreso'),2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_rolptt,0,'ttprovi'),2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_rolptt,0,'ttotal'),2);?></th>
	</tr>

<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
	<th></th>
	<th></th>
	<th></th>
	<th>PROMEDIOS</th>
	<th></th>

	
		<?php	
if ($xfgrou=='G')
{
		$xf2col='false';
		$res_nvdds=mysql_query($sql_nvdds,$link_vcrx);
		$xnvdds = mysql_num_rows($res_nvdds);
		$xcnvd=0;
		$sql_pivot='';
		while ($r_nvd0=mysql_fetch_assoc($res_nvdds))	
		{
			$xnvd=$r_nvd0['nvdd'];
			echo '<th  align="right">'.number_format(mysql_result($res_rolptt,0,'st'.$xnvd)/$totreg,2).'</th>';
		}
}
?>

	<th align="right"><?php echo number_format(mysql_result($res_rolptt,0,'ttingreso')/$totreg,2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_rolptt,0,'ttegreso')/$totreg,2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_rolptt,0,'ttprovi')/$totreg,2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_rolptt,0,'ttotal')/$totreg,2);?></th>
	</tr>


</table>
</div>