<?php
class impr_list1
{
	function Ximpr_list1($docu,$enti,$fecha1,$fecha2)
	{echo 'Proximamente...' ;}
	
	
	function impr_list1($docu,$enti,$fstat,$fptov,$fzsub,$fenti,$fecha1,$fecha2,$total1,$total2)
	{
		require('../cfg/res.php');


		if (mb_stristr('clie.prov',substr($_SESSION['user_vcrx_tipo'],0,4)))
			{$enti='M';
			if (substr($docu,0,1)=='O')
				{$tabla='clie';
				}
			
			if (substr($docu,0,1)=='F')
				{$tabla='vtas';
				}
			}



		$sql_drtr='select *from drtr0 where left(enti_codigo,10) like "'.$_SESSION['user_vcrx_id'].'%"';
		$res_drtr=mysql_query($sql_drtr,$link_vcrx);
		$drtr=0;

		if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4)))
			{if (mysql_num_rows($res_drtr)!=0)
				{$drtr=1;
				}
			}

// 		$sql_user='select *from user00 where user_cedula like"'.$_SESSION['user_vcrx_id'].'%"';
		$sql_user='select *from user00 where user_cedula like"'.$_SESSION['user_vcrx_id'].'%" or user_codigo like "'.$_SESSION['user_vcrx_id'].'"';
		$res_user=mysql_query($sql_user,$link_vcrx);
		$xuser=@mysql_result($res_user,0,'enti_nom1').' '.@mysql_result($res_user,0,'enti_ape1');
		
		$sql_tabla='select *from docu0 where docu_codigo like "'.$docu.'%"';
		$res_tabla=mysql_query($sql_tabla,$link_vcrx);
		
		$sql_empr='select *from empr1';
		$res_empr=mysql_query($sql_empr,$link_vcrx);
		
		$docu_tabla=mysql_result($res_tabla,0,'docu_tabla');
		$tabla=strtolower($docu_tabla);
		
			
		$sql_tran1='select *from '.$tabla.'11 
			where docu like "'.$docu.'%"';

		if(isset($_GET['fstat']) && !empty($_GET['fstat']))
			{
			$sql_tran1.=' and  (status like "'.$_GET['fstat'].'") ';
			$xfstat=$_GET['fstat'];
			}
		if(isset($_GET['fzsub']) && !empty($_GET['fzsub']))
			{
			$sql_tran1.=' and  (zsub like "'.$_GET['fzsub'].'%") ';
			$xfzsub=$_GET['fzsub'];
			}
		if(isset($_GET['fptov']) && !empty($_GET['fptov']))
			{
			$sql_tran1.=' and  (ptov like "'.$_GET['fptov'].'" or ptov_descri like "%'.$_GET['fptov'].'%" or ptoe like "'.$_GET['fptov'].'%") ';
			$xfptov=$_GET['fptov'];
			}

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



		if(isset($_GET['fnum1']) && !empty($_GET['fnum1']) && isset($_GET['fnum2']) && !empty($_GET['fnum2']))
			{
			$xfnum1=$_GET['fnum1'];
			$xfnum2=$_GET['fnum2'];
			}
		else
			{
			//$sql_tran1.=' and  fecha BETWEEN "'.$xfnum1.'" and "'.$xfnum2.'"';
			}



		if(isset($_GET['fecha_ini']) && !empty($_GET['fecha_ini']) && isset($_GET['fecha_fin']) && !empty($_GET['fecha_fin']))
			{
			$sql_tran1.=' and  fecha BETWEEN "'.$_GET['fecha_ini'].'" and "'.$_GET['fecha_fin'].'"';
			$xfecha1=$_GET['fecha_ini'];
			$xfecha2=$_GET['fecha_fin'];
			}
		else
			{
			$sql_tran1.=' and  fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"';
			}
			
		//if(isset($_GET['total_min']) && !empty($_GET['total_min']) && isset($_GET['total_max']) && !empty($_GET['total_max']))
		if(isset($_GET['total_min']) && isset($_GET['total_max']) && !empty($_GET['total_max']))
			{
// 			$sql_tran1.=' and  abs(total) BETWEEN '.$_GET['total_min'].' and '.$_GET['total_max'].' ';
// 			$xtotal1=$_GET['total_min'];
// 			$xtotal2=$_GET['total_max'];
			}
		else
			{
			$sql_tran1.=' and  abs(total) BETWEEN "'.$xtotal1.'" and "'.$xtotal2.'"';
			}

			$xtotal1=$_GET['total_min'];
			$xtotal2=$_GET['total_max'];
		if(empty($xtotal1)){$xtotal1=0;}
		if(empty($xtotal2)){$xtotal2=9999999.99;}
			$sql_tran1.=' and  abs(total) BETWEEN "'.$xtotal1.'" and "'.$xtotal2.'"';
			
		//echo $sql_tran1;

		if(isset($_GET['fcontra']) && !empty($_GET['fcontra']))
			{
			$sql_tran1.=' and  (contrato like "%'.$_GET['fcontra'].'%")';
			$xfcontra=$_GET['fcontra'];
			}

		if(isset($_GET['fdrtr']) && !empty($_GET['fdrtr']))
			{
			$sql_tran1.=' and  (drtr like "'.$_GET['fdrtr'].'%")';
			$xfdrtr=$_GET['fdrtr'];
			}

		if ($enti=='M')
			{	
			if ($drtr==0)
				{$sql_tran1.=' and (left(enti,10) like "' .$_SESSION['user_vcrx_id'].'%")';
				}
			else
				{$sql_tran1.=' and (left(enti,10) like "'.$_SESSION['user_vcrx_id'].'%" or left(drtr,10) like "'.$_SESSION['user_vcrx_id'].'%")';
				}
			}


		$sql_order=' order by docu, ptoe, numero, fecha, idnum1 ';
		
		if (mb_stristr('tcor',substr($_SESSION['user_vcrx_empr'],0,4))&& mb_stristr('vtas.clie',$tabla) )
			{$sql_order=' order by zsub,contrato,docu ';}

		if (mb_stristr('DK.DB',substr($docu,0,2)))
			{$sql_order=' order by fecha,docu,ptoe,numero,idnum1';}
		
		$sql_tran1.=$sql_order;
		//echo $sql_tran1;
		//$res_tran1=mysql_query($sql_tran1,$link_vcrx);

		
		$sql_tran1t= str_replace('select *','select *, sum(abs(total)) as ttotal ',$sql_tran1);
		$sql_tran1t= str_replace('order by','group by docu order by ',$sql_tran1t);

		if ($tabla=='vtas')
		{$sql_tran1t= str_replace('group by docu','group by docu,ptov ',$sql_tran1t);}

		if ($tabla=='caja')
		{$sql_tran1t= str_replace('group by docu','group by docu,caja ',$sql_tran1t);}

		if ($tabla=='bcos')
		{$sql_tran1t= str_replace('group by docu','group by docu,ctab ',$sql_tran1t);}

		if (mb_stristr('retc.retp',$tabla))
		{
			$sql_tran1t= str_replace('group by docu','group by cair,puni  ',$sql_tran1t);
			$sql_tran1t= str_replace('order by','order by cair,puni, ',$sql_tran1t);
		}

		$sql_tran2='select *from '.$docu_tabla.'12 where idnum1="'.$idnum.'" order by item_codigov, item ';
		$sql_tran2='select *from '.$docu_tabla.'12 where idnum1="'.$idnum.'" order by item_nctlg desc, item_pctlg, item ';
		//$res_tran2=mysql_query($sql_tran2,$link_vcrx);
		
		$sql_tran3='select * from '.$docu_tabla.'12 where idnum1="'.$idnum.'" and item like "%TRAN%"';
		//$res_tran3=mysql_query($sql_tran3,$link_vcrx);
		$xenvioa=1;


		if (mb_stristr('gnya.leie',$_SESSION['user_vcrx_empr']) && 1==0)
		{
		$xdrtr=mysql_result($res_tran2,0,'drtr');
		if (!empty($xdrtr))
		{
		$sql_drtr='select *from enti00 where enti_codigo="'.$xdrtr.'"';
		$res_drtr=mysql_query($sql_drtr,$link_vcrx);
		$xdrtr=mysql_result($res_drtr,0,'enti_descri');
		}
		}		

		//if(mysql_num_rows($res_tran1)!=0 && 1==0)
		if(1==0)
		{
			$xtran=mysql_result($res_tran3,0,'puni');
			if($xtran==1)
			{
				$xenvioa=2;
				$entienvio=mysql_result($res_tran1,0,'enti_referidox');
				
			}
			else
			{
				
				$xenvioa=3;
				$entienvio=mysql_result($res_tran1,0,'enti');

			}
			/*
			if (empty($xentienvio))
			{
				$entienvio=mysql_result($res_tran1,0,'drtr');
			}
			
			$sql_envioa='select *from enti00 where enti_codigo="'.$entienvio.'"';
			$res_envioa=mysql_query($sql_envioa,$link_vcrx);
			
                       
                        if(mysql_num_rows($res_envioa)!=0)
			{
				$envio_descri=mysql_result($res_envioa,0,'enti_descri');
				$envio_ciudad=mysql_result($res_envioa,0,'prvc_descri').' /'.mysql_result($res_envioa,0,'cdad_descri');
				$envio_direcc=trim(mysql_result($res_envioa,0,'enti_direccion')) .' /'.trim(mysql_result($res_envioa,0,'enti_calle1')) .' /'.trim(mysql_result($res_envioa,0,'enti_callen')) .' /'.trim(mysql_result($res_envioa,0,'enti_calle2')) .' /'.trim(mysql_result($res_envioa,0,'enti_calle3'));
				$envio_tlfn=mysql_result($res_envioa,0,'enti_telefono');
			}
			else
			{
				$envio_descri='-';
				$envio_ciudad='-';
				$envio_direcc='-';
				$envio_tlfn='-';
				
			}
*/


		}
		/*
		if (mysql_num_rows($res_tran1)!=0)
		{
		$sql_enti='select *from enti00 where enti_codigo="'.mysql_result($res_tran1,0,'enti').'"';
		$res_enti=mysql_query($sql_enti,$link_vcrx);
		
		//echo $sql_tran1;
		
		$sql_drtr='select *from enti0 where enti_codigo="'.mysql_result($res_enti,0,'enti_referidox').'"';
		$res_drtr=mysql_query($sql_drtr,$link_vcrx);
		}
		*/
		$xcelecl='vtas.comp.guia.retc.retp.cont';
		

?>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Listado de Transacciones</title>


<style type="text/css">
BODY{
	font-family: courier new;
/* 	font-size: 20px; */
	}

@page {
/*    size: 7in 9.25in; */
/* 	 top left bott right */
    size: 215mm 297mm; 
    margin: 0mm 10mm 10mm 0mm; /* 	top right bottom left */
}

@media print
{    
    .no-print, .no-print *
    {
        display: none !important;
    }
}	
	
</style>	
	
	
	
	
</head>
<body>


<div align="center">
<div align="center" style="width:1150px; font-size:18px;">
<div align="center" style="font-size:20px; font-weight: bold;border:#000 solid 1px; background: #F7F7F7; margin:2px;">LISTADO DE TRANSACCIONES</div>

<table width="90%" 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="50%" style="background: #F7F7F7;">PARAMETROS</th>
	<th></th>
</tr>
<tr>
	<td>DOCUMENTO</td>
	<td><?php echo $docu;?></td>
</tr>
<tr>
	<td>FECHA</td>
	<td><?php echo date_format(date_create($fecha1),'d/M/Y').' - '.date_format(date_create($fecha2),'d/M/Y');?></td>
</tr>
<tr>
	<td>Valor</td>
	<td><?php echo number_format($xtotal1,2).' - '.number_format($xtotal2,2);?></td>
</tr>
<tr>
	<td>STATUS</td>
	<td><?php if(empty($fstat)){echo 'TODOS';}else{echo $fstat;}?></td>
</tr>
<tr>
    <?php
    switch($tabla)
    {
    	case "vtas":
    ?>  
	    <td>PTO.VTA:</td> 
	    <td><?php if(empty($fptov)){echo 'TODOS';}else{echo $fptov;}?></td>
	    </tr>
	    <tr>
	    <td>ZONA-SUB</td> 
	    <td><?php if(empty($fzsub)){echo 'TODOS';}else{echo $fzsub;}?></td>
	    </tr>
	    <tr>
	    <td>CLIENTE</td> 
    <?php
	    break;
    	case "clie":
    ?>  
	    <td>ZONA-SUB</td> 
	    <td><?php if(empty($fzsub)){echo 'TODOS';}else{echo $fzsub;}?></td>
	    </tr>
	    <tr>
	    <td>CLIENTE</td> 
    <?php
	    break;
    	case "comp":
    ?>  
	    <td>PROVEEDOR</td> 
    <?php
    	    break;
    	case "prov":
    ?>  
	    <td>PROVEEDOR</td> 
    <?php
    	    break;
    	case "nomi":
    ?>  
	    <td>EMPLEADO</td> 
    <?php
	    break;
    	default;
    ?>  
	    <td>ENTIDAD</td> 

    <?php
    	
    }
    ?>  

	<td><?php if(empty($fenti)){echo 'TODOS';}else{echo $fenti;}?></td>
</tr>

<?php
if(isset($_GET['fdrtr']) && !empty($_GET['fdrtr']))
if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4)))
{{
$sql_drtrn='select *from drtr0 where left(enti_codigo,10) like "'.$_GET['fdrtr'].'%"';
$res_drtrn=mysql_query($sql_drtrn,$link_vcrx);
$drtrn=mysql_result($res_drtrn,0,'enti_descri');
?>
<tr>
<td>DIRECTOR</td>
<td><?php echo $drtrn; ?></td>
</tr>

<?php }} ?>
</table>

<!----++++++++++------>
</td>



<td>
<!----++++++++++------>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse">
<tr>
	<th width="50%"  style="background: #F7F7F7;">I N F O</th>
	<th></th>    
</tr>
<tr>
	<td align="right">USUARIO:</td>
	<td><?php echo $_SESSION['user_vcrx_id'].' / '.$xuser;?></td>
</tr>
<tr>
	<td align="right">FECHA / HORA :</td>
	<td><?php echo date('d/M/Y H:m:s');?></td>
</tr>

<tr>
<td></td>	<td></td>	
</tr>

<tr>
	<th width="50%"  style="background: #F7F7F7;">TOTALES</th>
	<th></th>    
</tr>
<?php
$res_tran1t=mysql_query($sql_tran1t,$link_vcrx);
// 		echo $sql_tran1t;
while($r_tran1t=mysql_fetch_assoc($res_tran1t))
{
?>	
<tr>
	<td align="right" style="font-size:14px;">
		<?php
 		echo $r_tran1t['docu_descri'];
		if ($tabla=='vtas'){echo ' - '.$r_tran1t['ptov_descri'];}
		if ($tabla=='caja'){echo ' - '.$r_tran1t['caja_descri'];}
		if ($tabla=='bcos'){echo ' - '.$r_tran1t['ctab_descri'];}
		if ($tabla=='retc'){echo '-'.$r_tran1t['cair'];}
		if ($tabla=='retp'){echo '-'.$r_tran1t['cair'];}
		?>
	</td>
	<td align="right"><?php echo number_format($r_tran1t['ttotal'],2);?></td>
</tr>
	
<?php } ?>
	
</table>
<!----++++++++++------>
</td>

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


<hr/>



<table 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">
 	<th>DOCUMENTO No</th>	
	<th>FECHA</th>
    <?php
    switch($tabla)
    {
    	case "vtas":
    ?>  
	    <th>C L I E N T E</th> 
    <?php
	    break;
    	case "clie":
    ?>  
	    <th>C L I E N T E</th> 
    <?php
	    break;
    	case "retc":
    ?>  
	    <th>C L I E N T E</th> 
	    <th>BASE</th> 
	    <th>%</th> 
    <?php
	    break;
    	case "comp":
    ?>  
	    <th>P R O V E E D O R</th> 
    <?php
    	    break;
    	case "prov":
    ?>  
	    <th>P R O V E E D O R</th> 
    <?php
    	    break;
    	case "retp":
    ?>  
	    <th>P R O V E E D O R</th> 
	    <th>BASE</th> 
	    <th>%</th> 
    <?php
    	    break;
    	case "nomi":
    ?>  
	    <th>E M P L E A D O</th> 
    <?php
	    break;
    	default;
    ?>  
	    <th>E N T I D A D</th> 

    <?php
    	
    }
    ?>  
	<th>TOTAL</th>
	<th>STAT</th>
	<th>Concepto</th>
	<th align="center">
	<?php
	if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4))&& mb_stristr('vtas.clie',$tabla) )
	{
	if ($drtr==1 ||  (mb_stristr('admi',substr($_SESSION['user_vcrx_tipo'],0,4))))
	{
	?>
	Comi
	<?php
	}
	}
	?>
	
	<?php
	if (mb_stristr('tcor',substr($_SESSION['user_vcrx_empr'],0,4))&& mb_stristr('vtas.clie',$tabla) )
	{
	?>
	Zona / Contrato
	<?php
	}
	?>
	
	</th>
</tr>
<?php
$filax=1;
$tbase=0;
$ttotal = 0;
$ttcomi = 0;
$tdocu = 0;
$res_tran1=mysql_query($sql_tran1,$link_vcrx);
while($r_tran1=mysql_fetch_assoc($res_tran1))
{
$tbase=$tbase+$r_tran1['brta']+$r_tran1['biva'];
$ttotal=$ttotal+abs($r_tran1['total']);
$ttcomi=$ttcomi+$r_tran1['tcomi'];
$tdocu=$tdocu+1;
?>
<tr valign="top" style=" <?php if($filax==3){echo 'border-bottom:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >

	<?php if (mb_stristr('retc.retp',$tabla)) {?>	
	  <td align="center"><?php echo $r_tran1['numero']; ?></td>	
	<?php }else{?>	
  	<td align="center"><?php echo $r_tran1['docu'].'-'.$r_tran1['ptonumero']; ?></td>	
	<?php }?>	
	<td align="center"><?php echo $r_tran1['fechadmy'];?></td>
	<td><?php echo $r_tran1['enti_descri'];?></td>
	<?php if (mb_stristr('retc.retp',$tabla)) {?>	
		<td align="right"><?php echo number_format($r_tran1['brta']+$r_tran1['biva'],2);?></td>
		<td align="right"><?php echo number_format($r_tran1['prta']+$r_tran1['piva'],2);?></td>
	<?php }?>	
	<td align="right"><?php echo number_format(abs($r_tran1['total']),2);?></td>
	<td align="center"><?php echo $r_tran1['status'];?></td>
	<td align="left"><?php echo $r_tran1['concepto'];?></td>
	<td align="right">
	
	<?php
	if (mb_stristr('vtas.clie',$tabla))
		{if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4)))
			{if ($drtr==1 ||  (mb_stristr('admi',substr($_SESSION['user_vcrx_tipo'],0,4)))  )
				{echo number_format($r_tran1['tcomi'],2);
				}
			}
		}
	?>
	
	<?php
	if (mb_stristr('vtas.clie',$tabla)){
			if (mb_stristr('tcor',substr($_SESSION['user_vcrx_empr'],0,4)))
			{echo $r_tran1['zsub'].'/ '.$r_tran1['contrato'];}
		}
	?>
	
	</td>


</tr>
<?php	
}
?>


<tr align="right" style="font-weight:bolder;border-top:solid 1px#000">
	<td><?php echo number_format($tdocu,0);?> Transacciones</td>
	<td></td>
	<td>T O T A L E S : </td>
	<?php	if(mb_stristr('retc.retp',$tabla)){?>
		<td><?php echo number_format($tbase,2);?></td>
		<td></td>
	<?php }?>
	<td><?php echo number_format($ttotal,2);?></td>
	<td></td>
	<td></td>
	<td>
	<?php
	if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4))&& mb_stristr('vtas.clie',$tabla) )
	{
	if ($drtr==1 ||  (mb_stristr('admi',substr($_SESSION['user_vcrx_tipo'],0,4))))
	{
	echo number_format($ttcomi,2);
	}
	}
	?>
	
	</td>
</tr>
</table>
</div>
</div>
<!--
<table border="1" width="50%">
<tr align="center" font bgcolor=#DDDDDD>
<td><b><font size="2">NOTAS</b></td>
</tr>
<tr>
<td><font size="2">ESTA IMPRESION SOLO TIENE FINES INFORMATIVOS Y DE CONSULTA</td>
</tr>
<tr>
<td><font size="2">ESTA IMPRESION NO TIENE VALIDEZ TRIBUTARIA</td>
</tr>
<tr>
<td><font size="2">VALIDADOR : <a href="https://declaraciones.sri.gob.ec/comprobantes-electronicos-internet/publico/validezComprobantes.jsf">https://declaraciones.sri.gob.ec/comprobantes-electronicos-internet/publico/validezComprobantes.jsf</a></td>
</tr>
<tr>
<td><font size="2">Mas informacion en : <a href="http://www.sri.gob.ec/web/10138/145">http://www.sri.gob.ec/web/10138/145 </a></td>
</tr>
</table>
-->





<?php		
		
	}
}
?>
</html>