<?php 
session_start();

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

include('php_gene1.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);

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



$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='item';break;
	case '2': $item_codi='item_codigov';break;
	case '3': $item_codi='item_ean';break;
	default : $item_codi='item';break;
}
// echo $item_codi;

$sql_vtast='select *,
	max(dcto) as pdcto,
	max(ice) as pice,
	max(iva) as piva,
	max(irbp) as pirbp,
	sum(tcant) as ttcant,
	sum(tsubt) as ttsubt,
	sum(tdcto*-1) as ttdcto,
	sum(tsubtice) as ttsubtice,
	sum(tice) as ttice,
	sum(tsubtiva0) as ttsubtiva0,
	sum(tsubtiva) as ttsubtiva,
	sum(tsubtiva0) as ttiva0,
	sum(tiva) as ttiva,
	sum(tirbp) as ttirbp,
	sum(total) as ttotal
	from vtas12 where ';


/*
$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_vtast.='(';

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_vtasf='select min(fecha) as fecha from vtas1 where status!="X" and status!="O" and fecha>="'.$xfecha1.'"';
$res_vtasf=mysql_query($sql_vtasf,$link_vcrx);
$xfecha1b=mysql_result($res_vtasf,0,'fecha');

$sql_vtasf='select max(fecha) as fecha from vtas1 where status!="X" and status!="O" and fecha<="'.$xfecha2.'"';
$res_vtasf=mysql_query($sql_vtasf,$link_vcrx);
$xfecha2b=mysql_result($res_vtasf,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_vtast.='fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"';

if(isset($_POST['fvence']) && ($_POST['fvence']=='true'))
{$xfvence=$_POST['fvence'];}
else
{$xfvence='false';}



if($xfvence=='true')
{$sql_vtast=str_replace('fecha BETWEEN','adddate(fecha,plazo) BETWEEN',$sql_vtast);}

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

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

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

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

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

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



if(isset($_POST['fcdad']) && !empty($_POST['fcdad']))
{
	$sql_vtast.=' 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_vtast.=' and  (item_lsub like "'.$_POST['flsub'].'%" or lsub_descri like "%'.$_POST['flsub'].'%" ) ';
	$xflsub=$_POST['flsub'];
}

if(isset($_POST['fzsub']) && !empty($_POST['fzsub']))
{
	$sql_vtast.=' and  (enti_zsub like "'.$_POST['fzsub'].'%" or zsub_descri like "%'.$_POST['fzsub'].'%" ) ';
	$xfzsub=$_POST['fzsub'];
}

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


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


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





	$sql_vtast.=' and(status!="X") ';
if($xfgrou!="D")
{$sql_vtast.=' and(status!="O") ';}

if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
{$sql_vtast.=' and(docu!="NV13") ';}



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

switch ($xfgrou)
{
	case 'D':$xgroup='docu,ptoe,numero,idnum1 ';break;
	case 'C':$xgroup='docu,ptoe,numero desc ';break;
	case 'E':$xgroup='enti_zsub,enti_descri,enti ';break;
	case 'I':$xgroup='item_lsub,item_descri,item ';break;

	case 'P':$xgroup='ptoe ';break;
	case 'V':$xgroup='vndd_descri,vndd ';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 ';break;
	case 'S':$xgroup='fanio,fsema '; $xforde='S'; break;
	case 'F':$xgroup='fecha '; $xforde='M';break;

	default :$xgroup='';break;
}

switch ($xforde)
{
	case 'D':$xorder=$xgroup;break;
	case 'C':$xorder='idnum1 desc ';break;
	case 'C':$xorder=str_replace('_descri','',$xgroup);
			$xorder=str_replace(',item',','.$item_codi.',item_descri,item',$xorder);break;
	case 'T':$xorder='ttotal desc, '.str_replace('_descri','',$xgroup);break;
	case 'S':$xorder='fecha ';break;
	case 'M':$xorder='fecha';break;

	default :$xorder=$xgroup;break;
}

//$xorder=str_replace('_codigo','',$xorder)
// explain_sql($sql_vtast);

$res_vtastt=mysql_query($sql_vtast,$link_vcrx);
if (mysql_result($res_vtastt,0,'ttcant')==0)
{
// 	$sql_vtast=str_replace($xfecha1,'2000-01-01',$sql_vtast);
// 	$res_vtastt=mysql_query($sql_vtast,$link_vcrx);
// 	$xfecha1='2000-01-01';
}

$xttdcto=mysql_result($res_vtastt,0,'ttdcto');
$xttice=mysql_result($res_vtastt,0,'ttice');
$xttiva0=mysql_result($res_vtastt,0,'ttiva0');
$xttiva=mysql_result($res_vtastt,0,'ttiva');
$xttirbp=mysql_result($res_vtastt,0,'ttirbp');

if($xfgrou=='C')
{
$xttdcto=0;
$xttice=0;
$xttiva0=0;
$xttiva=0;
$xttirbp=0;
}


$sql_vtast.=' group by '.$xgroup;

if ($xmodi=='1')
{
	$xfgrou=$xmodi;
}

if ($xmodi=='2')
{
	$sql_vtast=str_replace('sum','',$sql_vtast);
	$sql_vtast.=',iddet';
	$xfgrou=$xmodi;
}




$sql_vtast.=' order by '.$xorder;

//  echo $sql_vtast;

$res_vtast=mysql_query($sql_vtast,$link_vcrx);
$totreg = mysql_num_rows($res_vtast);
// echo str_repeat('-',date('s')*2).'';
// echo mysql_error();

// explain($sql_vtast);

?>
<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 '1':
?>

	<th></th>
	<th>DOCU</th>
	<th>NUMERO</th>
	<th>FECHA</th>
	<th>CLIENTE</th>
	<th>CONCEPTO</th>
	<th>VALOR</th>
	<th>PLAZO</th>
	<th></th>
	<th></th>
	<th></th>
	<th></th>



<?php	
	break;
	case 'D':
?>

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



<?php	
	break;
	case 'C':
?>

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



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



<?php	
	break;
	case 'I':
?>
	<th></th>
	<th>LINEA</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 '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 'R':
?>
	<th></th>
	<th>COD.RET.</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>
<?php } ?>

	
<?php	if ($xmodi=='0')	{	?>
	
	<th>SUBT</th>

<?php if($xttdcto!=0){ ?>	
	<th>DCTO</th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th>ICE</th>
<?php } ?>

<?php if ($xttiva0!=0){ ?>	
	<th>ST-IVA 0</th>
<?php } ?>

<?php if ($xttiva!=0){ ?>	
	<th>ST-IVA</th>
	<th>IVA</th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th>IRBP</th>
<?php } ?>

	<th>TOTAL</th>

<?php } ?>
	
	
	
<?php
switch ($xfgrou)
{
	case 'D':
?>
	<th>CRE</th>
	<th>PROVINCIA /CIUDAD</th>
	<th>VENDEDOR</th>

<?php	
	break;
	case 'C':
?>
	<th></th>
	<th>CLAVE / AUTORIZACION / E-mail</th>
	<th>FECHAS</th>
	<th></th>
	<th>STATUS</th>
	<th></th>
<?php	
	break;
	case 'E':
?>
	<th>PROVINCIA /CIUDAD</th>
	<th>VENDEDOR</th>

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






</tr>

<?php 
$filax=0;
$cregi=0;
//$urcdd='';

while($r_vtast=mysql_fetch_assoc($res_vtast))
{
$cregi++;
$duni=$r_vtast['item_duni'];
?>
<?php
    $enti_descri=$r_vtast['enti_descri'];
    $enti_razsoc=$r_vtast['enti_razsoc'];
    if($enti_descri=='' and $enti_razsoc=='')    
    {
      get_ruc0($r_vtast['enti']);
      get_ced0($r_vtast['enti']);
    }
?>

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

//$prcdd=$urcdd;
//$urcdd=$r_vtast['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 '1':
?>
<td>
		<a href="../print1.php?prnt=1&docu=<?php echo $r_vtas['docu']; ?>&idnum=<?php echo $r_vtas['idnum1']; ?>&formato=3" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_vtast['docu'];?>-<?php echo $r_vtast['numero'];?>"  /></a>
<!--     <a href="../lib/celectop1.php?docu=<?php echo $r_vtast['docu']; ?>&idnum=<?php echo $r_vtast['idnum1']; ?>&formato=1" target="_blank" tabindex="-1"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_vtast['docu'];?>-<?php echo $r_vtast['numero'];?>"  /></a> -->
</td>
  <td align="center"><?php echo'<span title="'.$r_vtast['docu'].'">'.$r_vtast['docu'].'</span>';?></td>
	<td align="center"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['idnum1']; ?>',this);" tabindex="-1"><?php echo '<span title="'.$r_vtast['ptonumero'].'">'.$r_vtast['numero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_vtast['fechadmy'].'">'.$r_vtast['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_vtast['enti'].'">'.$r_vtast['enti_descri'].'</span>';?></td>
		<td align="left"><?php echo'<span title="'.$r_vtast['concepto'].'">'.$r_vtast['concepto'].'</span>';?></td>
   <td align="right"><?php echo number_format($r_vtast['ttotal'],2);?></td>
<td>
		<?php $pcaption=$r_vtast['plazo'];  $pidtxt='plazo_'.$r_vtast['idnum1']; $pdefa=$r_vtast['plazo']; $pobj=1; include('vrgetval.php'); ?>
</td>
<td>
		<?php $pcaption='';   $pidtxt='atrz_'.$r_vtast['idnum1']; $pdefa=$r_vtast['atrz']; $pobj=1; $plong=10; include('vrgetnum.php'); ?>
</td>
		
<td>
</td>
		<td>
		<?php $pcaption='Modif';  $ponclick='_modi1('.$r_vtast['idnum1'].');'; include('vrbutton.php'); ?>
			
		</td>
		<td style="font-size:10px;"><div id="error_<?php echo $r_vtast['idnum1'];?>"></div></td>

		
	<th></th>

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

<?php	
	break;
	case 'C':
?>
<td>
		<a href="../print1.php?prnt=1&docu=<?php echo $r_vtast['docu']; ?>&idnum=<?php echo $r_vtast['idnum1']; ?>&formato=3" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_vtast['docu'];?>-<?php echo $r_vtast['numero'];?>"  /></a>
<!--     <a href="../lib/celectop1.php?docu=<?php echo $r_vtast['docu']; ?>&idnum=<?php echo $r_vtast['idnum1']; ?>&formato=1" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_vtast['docu'];?>-<?php echo $r_vtast['numero'];?>"  /></a> -->
</td>
        <td align="center"><?php echo'<span title="'.$r_vtast['docu'].'">'.$r_vtast['docu'].'</span>';?></td>
	<td align="center"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['idnum1']; ?>',this);"><?php echo '<span title="'.$r_vtast['ptonumero'].'">'.$r_vtast['ptonumero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_vtast['fechadmy'].'">'.$r_vtast['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_vtast['enti'].'">'.$r_vtast['enti_descri'].'</span>';?></td>

<?php	
	break;
	case 'E':
?>
	<td>
    	<a href="../lib/impr_vtast1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_vtast['enti']; ?>&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_vtast['enti'];?>"  /></a>
	</td>
        <td align="center"><?php echo'<span title="'.$r_vtast['enti_zsub'].'">'.$r_vtast['zsub_descri'].'</span>';?></td>
	<td align="left"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['enti']; ?>',this);"><?php echo '<span title="'.$r_vtast['enti'].'">'.$r_vtast['enti'].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_vtast['enti_direccion'].'">'.$r_vtast['enti_descri'].'</span>';?></td>
	<td></td>

<?php	
	break;
	case 'I':
?>
	<td>
    	<a href="../lib/impr_vtast1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_vtast['item']; ?>&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_vtast['item'];?>"  /></a>
	</td>
        <td align="center"><?php echo'<span title="'.$r_vtast['item_lsub'].'">'.$r_vtast['lsub_descri'].'</span>';?></td>
	<td align="left"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['item']; ?>',this);"><?php echo '<span title="'.$r_vtast['item'].'">'.$r_vtast[$item_codi].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_vtast['item_mrca'].'">'.$r_vtast['item_descri'].'</span>';?></td>
   	<td align="right"><?php echo number_format($r_vtast['ttcant'],$duni);?></td>


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

<?php	
	break;
	case 'S':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_vtast['item'];?>','<?php echo $r_vtast['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['fanio'].'">'.$r_vtast['fanio'].'</span>';?></td>
	<td align="center"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['fanio'].$r_vtast['fsema']; ?>',this);"><?php echo '<span title="'.$r_vtast['fsema'].'">'.$r_vtast['fsema'].'</span>';?></a> </td>
	<td align="center">
    <?php 
      $week_start = date('d/M',strtotime(sema_ini($r_vtast['fecha'])));
      $week_end = date('d/M',strtotime(sema_fin($r_vtast['fecha'])));
      echo $week_start.' - '.$week_end;
    ?>
  </td>
	<td></td>

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

<?php	
	break;
	case 'P':
?>
	<td>
    	<a href="../lib/impr_vtast1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_vtast['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_vtast['ptoe'];?>"  /></a>
	</td>
	<td align="left"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['ptoe']; ?>',this);"><?php echo '<span title="'.$r_vtast['ptoe'].'">'.$r_vtast['ptoe'].'</span>';?></a> </td>
	<td align="left"></td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'V':
?>
	<td>
    	<a href="../lib/impr_vtast1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_vtast['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_vtast['vndd'];?>"  /></a>
	</td>
	<td align="center"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['vndd']; ?>',this);"><?php echo '<span title="'.$r_vtast['vndd'].'">'.$r_vtast['vndd'].'</span>';?></a> </td>
  <td align="left"><?php echo'<span title="'.$r_vtast['vndd'].'">'.$r_vtast['vndd_descri'].'</span>';?></td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'Z':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_vtast['item'];?>','<?php echo $r_vtast['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['zsub'].'">'.$r_vtast['zsub'].'</span>';?></td>
	<td align="left"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['zsub']; ?>',this);"><?php echo '<span title="'.$r_vtast['zsub_descri'].'">'.$r_vtast['zsub_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>
<?php	
	break;
	case 'L':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_vtast['item'];?>','<?php echo $r_vtast['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['item_lsub'].'">'.$r_vtast['item_lsub'].'</span>';?></td>
	<td align="left"><a href="#" onClick="vtast1d('<?php echo $xfgrou; ?>','<?php echo $r_vtast['lsub']; ?>',this);"><?php echo '<span title="'.$r_vtast['lsub_descri'].'">'.$r_vtast['lsub_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

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


<?php }?>

<?php
	if ($xmodi=='0')
	{
	?>
		
		
   	<td align="right"><?php echo number_format($r_vtast['ttsubt'],2);?></td>


<?php if($xttdcto!=0){ ?>	
   	<td align="right" title="<?php echo number_format($r_vtas['pdcto'],2).'%';?>"><?php echo '<i>'.number_format($r_vtast['ttdcto'],2);?></td>
<?php } ?>

<?php if($xttice!=0){ ?>	
   	<td align="right" title="<?php echo number_format($r_vtas['pice'],2).'%';?>"><?php echo number_format($r_vtast['ttice'],2);?></td>
<?php } ?>

<?php if($xttiva0!=0){ ?>	
   	<td align="right"><?php echo number_format($r_vtast['ttsubtiva0'],2).'';?></td>
<?php } ?>

<?php if($xttiva!=0){ ?>	
   	<td align="right"><?php echo number_format($r_vtast['ttsubtiva'],2);?></td>
   	<td align="right" title="<?php echo number_format($r_vtas['piva'],2).'%';?>"><?php echo number_format($r_vtast['ttiva'],2);?></td>
<?php } ?>

<?php if($xttirbp!=0){ ?>	
   	<td align="right" title="<?php echo number_format($r_vtas['pirbp'],2);?>"><?php echo number_format($r_vtast['ttirbp'],2);?></td>
<?php } ?>

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

<?php }?>
		
		
<?php	
switch ($xfgrou)
{
	case 'D':
?>
        <td align="center"><?php if($r_vtast['plazo']>0){echo "S";}else{echo "N";};?></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['cdad_descri'].'">'.$r_vtast['cdad_descri'].'</span>';?></td>
				<td align="center"><?php echo'<span title="'.$r_vtast['vndd'].'">'.$r_vtast['vndd'].'</span>';?></td>
<?php	
	break;
	case 'C':
?>
				<td align="center">
				</td>
				<td align="left">
					<?php echo'<span title="'.$r_vtast['statcemsj'].'">'.substr($r_vtast['claveacc'],0,24).''.substr($r_vtast['claveacc'],24).'</span>';?>
					<br>
					<?php if ($r_vtast['autornum']!=""){?>
					<?php echo'<span title="'.$r_vtast['statcemsj'].'">'.substr($r_vtast['autornum'],0).'</span>';?>
					<?php }else{ ?>
					<?php echo'<span title="'.$r_vtast['statcemsj'].'">'.substr($r_vtast['statcemsj'],0).'</span>';?>
					<?php } ?>
					<br>
					<?php if ($r_vtast['emailto']!=""){?>
					<?php echo'<span title="'.$r_vtast['emailfec'].'">'.$r_vtast['emailto'].'</span>';?>
					<?php }else{ ?>
					<?php echo'<span title="'.$r_vtast['emailfec'].'">'.$r_vtast['enti_emailce'].'</span>';?>
					<?php } ?>
				</td>
				<td align="left">
				<?php if ($r_vtast['firmado']!=""){?>
					<?php echo'<span title="'.$r_vtast['firmado'].'">'.date('d/M',strtotime($r_vtast['firmado'])).' '.date('H:i',strtotime($r_vtast['firmado'])).'</span>';?>
				<?php } ?>
					<br>
				<?php if ($r_vtast['autorfec']!=""){?>
					<?php echo'<span title="'.$r_vtast['autornum'].'">'.date('d/M',strtotime($r_vtast['autorfec'])).' '.date('H:i',strtotime($r_vtast['firmado'])).'</span>';?>
				<?php } ?>
					<br>
				<?php if ($r_vtast['emailfec']!=""){?>
					<?php echo'<span title="'.$r_vtast['emailfec'].'">'.date('d/M',strtotime($r_vtast['emailfec'])).' '.date('H:i',strtotime($r_vtast['emailfec'])).'</span>';?>
				<?php } ?>
				</td>
				<td align="center">
				</td>
				<td align="center"><?php echo'<span title="'.$r_vtast['statcemsj'].'">'.$r_vtast['statce'].'</span>';?></td>
		
				<td align="center" valign="top">
				<?php if ($r_vtast['autornum']==""){?>
					<?php $pidtxt='btnfirma'.$r_vtast['idnum1']; $pcaption='Autor'; $psize=8; $ponclick='snd_cel("firma","'.$r_vtast['docu'].'","'.$r_vtast['idnum1'].'");'; include('vrbutton.php'); ?>
				<?php }else{ ?>
				<?php if ($r_vtast['statce']=="FIR" or $r_vtast['statce']=="SRI"){?>
					<?php $pidtxt='btnrecep'.$r_vtast['idnum1']; $pcaption='Autor'; $psize=8; $ponclick='snd_cel("recep","'.$r_vtast['claveacc'].'","'.$r_vtast['idnum1'].'");'; include('vrbutton.php'); ?>
				<?php } ?>
				<?php } ?>
				<?php if ($r_vtast['statce']!="---" or 1==1){?>
					<?php $pidtxt='btnemail'.$r_vtast['idnum1']; $pcaption='E-Mail'; $psize=8; $ponclick='snd_cel("email","'.$r_vtast['claveacc'].'","'.$r_vtast['idnum1'].'");'; include('vrbutton.php'); ?>
				<?php } ?>
				</td>

<?php	
	break;
	case 'E':
?>
	<td align="center"><?php echo'<span title="'.$r_vtast['enti_telefono'].'">'.$r_vtast['prvc_descri'].' /'.$r_vtast['cdad_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_vtast['vndd'].'">'.$r_vtast['vndd'].'</span>';?></td>


<?php	
	break;
	case 'I':
?>
	<td align="center"><?php echo'<span title="'.$r_vtast['item_mrca'].'">'.$r_vtast['item_mrca'].' /'.$r_vtast['item_modelo'].'</span>';?></td>
	<td align="center"></td>


	
<?php }?>







</tr>
<?php }?>


<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000 <?php if($xmodi!='0'){echo 'display:none;';}?>">
	<th></th>
	<th></th>
	<th><?php echo $xfgrou.' : '.$cregi; ?></th>
	<th>TOTALES</th>
	<th></th>
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubt'),2);?></th>

<?php if($xttdcto!=0){ ?>	
	<th align="right"><?php echo '<i>'.number_format(mysql_result($res_vtastt,0,'ttdcto'),2);?></th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttice'),2);?></th>
<?php } ?>

<?php if ($xttiva0!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubtiva0'),2);?></th>
<?php } ?>

<?php if ($xttiva!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubtiva'),2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttiva'),2);?></th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttirbp'),2);?></th>
<?php } ?>

	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttotal'),2);?></th>


	</tr>

<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000 <?php if($xmodi!='0'){echo 'display:none;';}?>">
	<th></th>
	<th></th>
	<th></th>
	<th>PROMEDIOS</th>
	<th></th>
<?php if($totreg!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubt')/$totreg,2);?></th>
<?php } ?>

<?php if($xttdcto!=0){ ?>	
	<th align="right"><?php echo '<i>'.number_format(mysql_result($res_vtastt,0,'ttdcto')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttice')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttiva0!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubtiva0')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttiva!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubtiva')/$totreg,2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttiva')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttirbp')/$totreg,2);?></th>
<?php } ?>

<?php if($totreg!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttotal')/$totreg,2);?></th>
<?php } ?>


	</tr>


</table>
</div>