<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


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

$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);


$sql_vtast='select *,
	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(tiva) as ttiva,
	sum(tirbp) as ttirbp,
	sum(total) as ttotal
	from vtas12 where ';



$sql_vtast.='(';

if(isset($_GET['fecha_ini']) && !empty($_GET['fecha_ini']) && isset($_GET['fecha_fin']) && !empty($_GET['fecha_fin']))
{
	$sql_vtast.='fecha BETWEEN "'.$_GET['fecha_ini'].'" and "'.$_GET['fecha_fin'].'"';
	$xfecha1=$_GET['fecha_ini'];
	$xfecha2=$_GET['fecha_fin'];
}
else
{
	$sql_vtast.=' fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"' ;
}

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




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

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


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

switch ($xfgrou)
{
	case 'D':$xgroup='docu,ptoe,numero,idnum1 ';break;
	case 'E':
	$sql_vtast.=' and enti like "'.$_GET['idnum'].'%" ';
	$xgroup='docu,ptoe,numero,idnum1 ';
	break;
	case 'I':
	$sql_vtast.=' and item like "'.$_GET['idnum'].'%" ';
	$xgroup='docu,ptoe,numero,idnum1 ';
	break;

	case 'P':
	$sql_vtast.=' and ptov like "'.$_GET['idnum'].'%" or ptoe like  "'.$_GET['idnum'].'%"';
	$xgroup='docu,ptoe,numero,idnum1 ';
	break;

	case 'V':
	$sql_vtast.=' and vndd like "'.$_GET['idnum'].'"';
	$xgroup='docu,ptoe,numero,idnum1 ';
	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':
	//$sql_vtast.=' and(concat(fanio,fmes)="'.$_GET['idnum'].'") ';
	$xgroup='docu,ptoe,numero,idnum1 ';
	break;
	case 'S':$xgroup='fanio,fsema ';break;
	case 'F':$xgroup='fecha ';break;

	default :$xgroup='';break;
}

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

	default :$xorder=$xgroup;break;
}
// echo $sql_vtast;
$res_vtastt=mysql_query($sql_vtast,$link_vcrx);
$xttdcto=mysql_result($res_vtastt,0,'ttdcto');
$xttice=mysql_result($res_vtastt,0,'ttice');
$xttiva=mysql_result($res_vtastt,0,'ttiva');
$xttirbp=mysql_result($res_vtastt,0,'ttirbp');


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

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

$res_vtast=mysql_query($sql_vtast,$link_vcrx);
?>


<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Ventas Totales (Cliente)</title>
<style type="text/css">
body{ font-family:"Courier New", Courier, monospace;}

</style>

</head>
<body>

<div align="center">
<div align="center" style="width:1100px; font-size:12px;">
<div align="center" style="font-size:18px; border:#000 solid 1px; background: #F7F7F7; margin:2px; font-weight: bold;">VENTAS TOTALES</div>

<table width="100%" cellspacing="0" cellpadding="2">
<tr valign="top">
<td width="50%">

<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse">
<tr>
	<th width="30%" style="background: #F7F7F7;">PARAMETROS</th>
	<th></th>
</tr>

<tr>
    	<td style="font-weight:bolder;">FECHA</td>
	<td><?php echo date_format(date_create($xfecha1),'d/M/Y').' - '.date_format(date_create($xfecha2),'d/M/Y');?></td>
</tr>



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

<tr></tr>

<?php	
	break;
	case 'E':
	$sql_clie='select * from enti00 where enti_codigo like "'.$_GET['idnum'].'%" ';
	$res_clie=mysql_query($sql_clie,$link_vcrx);
?>

<tr>
	<td><b>CLIENTE</td>
	<td><?php echo mysql_result($res_clie,0,'enti_codigo').' - '.mysql_result($res_clie,0,'enti_descri');?></td>
<tr>


<?php	
	break;
	case 'I':
	$sql_clie='select * from item00 where item_codigo like "'.$_GET['idnum'].'%" ';
	$res_clie=mysql_query($sql_clie,$link_vcrx);
?>

<tr>
	<td><b>ITEM</td>
	<td><?php echo mysql_result($res_clie,0,'item_codigo').' - '.mysql_result($res_clie,0,'item_descri');?></td>
<tr>
<?php	
	break;
	case 'M':
?>
<tr>
	<td><b>CLIENTE</td>
	<td><?php echo 'TODOS';?></td>
<tr>
<tr>
	<td><b>AÑO</td>
	<td><?php echo substr($_GET['idnum'],0,4);
		?></td>
<tr>
<tr>
	<td><b>MES</td>
	<td><?php echo substr($_GET['idnum'],4,2);
		?></td>
<tr>
<?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':
	$sql_clie='select * from ptov0 where ptov_codigo like "'.$_GET['idnum'].'%" or ptov_ptoe like "'.$_GET['idnum'].'%"';
	$res_clie=mysql_query($sql_clie,$link_vcrx);
?>

<tr>
	<td><b>PTO.VTA.</td>
	<td><?php echo mysql_result($res_clie,0,'ptov_codigo').' - '.mysql_result($res_clie,0,'ptov_descri');?></td>
<tr>


<?php	
	break;
	case 'V':
	$sql_clie='select * from vndd0 where vndd_codigo like "'.$_GET['idnum'].'" or vndd_descri like "%'.$_GET['idnum'].'%"';
	$res_clie=mysql_query($sql_clie,$link_vcrx);
?>

<tr>
	<td><b>VENDEDOR</td>
	<td><?php echo mysql_result($res_clie,0,'vndd_codigo').' - '.mysql_result($res_clie,0,'vndd_descri');?></td>
<tr>


<?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 } ?>



</table>




<td>
<!----++++++++++------>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse">
<tr>
	<th width="30%"  style="background: #F7F7F7;">I N F O</th>
	<th></th>    
</tr>

<?php
$sql_empr='select * from empr0';
$res_empr=mysql_query($sql_empr,$link_vcrx);
?>
<tr>
	<td align="right">EMPRESA:</td>
	<td><?php echo mysql_result($res_empr,0,'empr_descri');?></td>
</tr>

<tr>
	<td align="right">USUARIO:</td>
	<td><?php echo $_SESSION['user_vcrx_id'].' / '.$_SESSION['user_vcrx_descri'];?></td>
</tr>
<tr>
	<td align="right">FECHA / HORA :</td>
	<td><?php echo date('d/M/Y H:i:s');?></td>
</tr>
</table>
<!----++++++++++------>
</td>




</tr>
</table>
<!----++++++++++------>


<hr/>

<table 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">
<?php
switch ($xfgrou)
{
	case 'D':
?>

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


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

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


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


<?php	
	break;
	case 'M':
?>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</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>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
	<th>NOMBRE</th>
	<th></th>


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

	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
	<th>NOMBRE</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 } ?>

	<th>SUBT</th>

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

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

	<th>ST-IVA 0</th>

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

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

	<th>TOTAL</th>

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

<?php	
	break;
	case 'E':
?>
	<th>PROVINCIA /CIUDAD</th>
	<th>VENDEDOR</th>

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



</tr>

</div>


</tr>

<?php 
$filax=0;
//$urcdd='';
//$res_vtast=mysql_query($sql_vtast,$link_vcrx);

while($r_vtast=mysql_fetch_assoc($res_vtast))
{
$duni=$r_vtast['item_duni'];
?>

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

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

        <td align="center"><?php echo'<span title="'.$r_vtast['docu'].'">'.$r_vtast['docu'].'</span>';?></td>
	<td align="center"><?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>
	<td></td>


<?php	
	break;
	case 'E':
?>
	<td align="center"><?php echo '<span title="'.$r_vtast['docu_descri'].'">'.$r_vtast['docu'].'</span>';?></a> </td>
	<td align="center"><?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>
	<th></th>
	<th></th>


<?php	
	break;
	case 'I':
?>
        <td align="center"><?php echo'<span title="'.$r_vtast['docu'].'">'.$r_vtast['docu'].'</span>';?></td>
	<td align="center"><?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>
   	<td align="right"><?php echo number_format($r_vtast['ttcant'],2);?></td>


<?php	
	break;
	case 'M':
?>
        <td align="center"><?php echo'<span title="'.$r_vtast['docu'].'">'.$r_vtast['docu'].'</span>';?></td>
	<td align="center"><?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>
	<td></td>

<?php	
	break;
	case 'S':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['fanio'].'">'.$r_vtast['fanio'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['fsema'].'">'.$r_vtast['fsema'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'F':
?>
	<td></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"><?php echo '<span title="'.$r_vtast['fechadmy'].'">'.$r_vtast['fdian'].'-'.$r_vtast['fdia'].'</span>';?></a> </td>
	<td></td>

<?php	
	break;
	case 'P':
?>
	<td align="center"><?php echo '<span title="'.$r_vtast['docu_descri'].'">'.$r_vtast['docu'].'</span>';?></a> </td>
	<td align="center"><?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>
	<th></th>


<?php	
	break;
	case 'V':
?>
	<td align="center"><?php echo '<span title="'.$r_vtast['docu_descri'].'">'.$r_vtast['docu'].'</span>';?></a> </td>
	<td align="center"><?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>
	<th></th>

<?php	
	break;
	case 'Z':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['zsub'].'">'.$r_vtast['zsub'].'</span>';?></td>
	<td align="left"><?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></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['item_lsub'].'">'.$r_vtast['item_lsub'].'</span>';?></td>
	<td align="left"><?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></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['item_at10'].'">'.$r_vtast['item_at10'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['at10_descri'].'">'.$r_vtast['at10_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>



<?php }?>



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


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

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

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

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

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

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




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

        <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 '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
switch ($xfgrou)
{
	case 'M':
?>
	<th></th>
	<th></th>
<?php
	break;
	case 'E':
?>
	<th></th>
	<th></th>
<?php
	break;
	case 'P':
?>
	<th></th>
	<th></th>
<?php
	break;
	case 'I':
?>
	<th></th>
	<th></th>
<?php
	break;
}
?>
	
	<th></th>
	<th>TOTALES</th>
	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttcant'),2);?></th>
	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttsubt'),2);?></th>
	
<?php if($xttdcto!=0){ ?>	
	<th align="right">&nbsp;<?php echo '<i>'.number_format(mysql_result($res_vtastt,0,'ttdcto'),2);?></th>
<?php } ?>

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

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

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

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

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

<tr>

</table>



</div>
<br>
<div id="vtastot2"></div>

