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

$idnum=trim($_GET['idnum']);

$sql_compt='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 comp12 where ';



$sql_compt.='(';

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

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




if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
{$sql_compt.=' 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_compt.=' and(enti="'.$idnum.'") ';
	$xgroup='docu,ptoe,numero,idnum1 ';
	break;
	case 'I':
	$sql_compt.=' and(item="'.$idnum.'") ';
	$xgroup='fecha,docu,ptoe,numero,idnum1 ';
	break;

	case 'P':$xgroup='ptoe ';break;
	case 'V':$xgroup='vndd ';break;
	case 'T':$xgroup='tpro ';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 ';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;
}



$res_comptt=mysql_query($sql_compt,$link_vcrx);
$xttdcto=mysql_result($res_comptt,0,'ttdcto');
$xttice=mysql_result($res_comptt,0,'ttice');
$xttiva=mysql_result($res_comptt,0,'ttiva');
$xttirbp=mysql_result($res_comptt,0,'ttirbp');


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

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

$res_compt=mysql_query($sql_compt,$link_vcrx);
?>


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

<title>Compras Totales (Proveedor)</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;">COMPRAS TOTALES (Detalle)</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':
?>

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


<?php	
	break;
	case 'E':
	$sql_clie='select * from enti00 where enti_codigo like "'.$idnum.'%" ';
	$res_clie=mysql_query($sql_clie,$link_vcrx);
?>
<tr>
	<td><b>PROVEEDOR</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 "'.$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':
?>
	<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 'T':
?>
	<th></th>
	<th>T.PROV.</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></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 'T':
?>
	<th></th>
	<th>T.PROV.</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_compt=mysql_query($sql_compt,$link_vcrx);

while($r_compt=mysql_fetch_assoc($res_compt))
{
$duni=$r_compt['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_compt['docu'].'">'.$r_compt['docu'].'</span>';?></td>
	<td align="center"><?php echo '<span title="'.$r_compt['ptonumero'].'">'.$r_compt['ptonumero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_compt['fechadmy'].'">'.$r_compt['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_compt['enti'].'">'.$r_compt['enti_descri'].'</span>';?></td>
	<td></td>


<?php	
	break;
	case 'E':
?>
	<td align="center"><?php echo '<span title="'.$r_compt['docu_descri'].'">'.$r_compt['docu'].'</span>';?></a> </td>
	<td align="center"><?php echo '<span title="'.$r_compt['ptonumero'].'">'.$r_compt['ptonumero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_compt['fechadmy'].'">'.$r_compt['fechadmy'].'</span>';?></td>
	<td></td>
	<td></td>


<?php	
	break;
	case 'I':
?>
	<td align="center"><?php echo '<span title="'.$r_compt['docu_descri'].'">'.$r_compt['docu'].'</span>';?></a> </td>
	<td align="center"><?php echo '<span title="'.$r_compt['ptonumero'].'">'.$r_compt['ptonumero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_compt['fechadmy'].'">'.$r_compt['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_compt['enti'].'">'.$r_compt['enti_descri'].'</span>';?></td>
   	<td align="right"><?php echo number_format($r_compt['ttcant'],2);?></td>


<?php	
	break;
	case 'M':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_compt['fanio'].'">'.$r_compt['fanio'].'</span>';?></td>
	<td align="center"><?php echo '<span title="'.$r_compt['fmes'].'">'.$r_compt['fmes'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_compt['fmesn'].'">'.$r_compt['fmesn'].'</span>';?></td>
	<td></td>

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

<?php	
	break;
	case 'F':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_compt['fanio'].'">'.$r_compt['fanio'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_compt['fmesn'].'">'.$r_compt['fmesn'].'</span>';?></td>
	<td align="center"><?php echo '<span title="'.$r_compt['fechadmy'].'">'.$r_compt['fdian'].'-'.$r_compt['fdia'].'</span>';?></a> </td>
	<td></td>

<?php	
	break;
	case 'P':
?>
	<td></td>
	<td align="left"><?php echo '<span title="'.$r_compt['ptoe'].'">'.$r_compt['ptoe'].'</span>';?></a> </td>
	<td align="left"></td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'V':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_compt['vndd'].'">'.$r_compt['vndd'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_compt['vndd_descri'].'">'.$r_compt['vndd_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'Z':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_compt['enti_tpro'].'">'.$r_compt['enti_tpro'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_compt['tpro_descri'].'">'.$r_compt['tpro__descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

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



<?php }?>



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


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

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

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

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

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

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




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

        <td align="center"><?php echo'<span title="'.$r_compt['cdad_descri'].'">'.$r_compt['cdad_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_compt['vndd'].'">'.$r_compt['vndd'].'</span>';?></td>

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

	<td align="center"><?php echo'<span title="'.$r_compt['enti_telefono'].'">'.$r_compt['prvc_descri'].' /'.$r_compt['cdad_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_compt['vndd'].'">'.$r_compt['vndd'].'</span>';?></td>

<?php	
	break;
	case 'I':
?>
	<td align="center"><?php echo'<span title="'.$r_compt['item_mrca'].'">'.$r_compt['item_mrca'].' /'.$r_compt['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 'I':
?>
	<th></th>
	<th></th>
<?php
	break;
}
?>

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

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

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

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

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

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

<tr>

</table>



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

