<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");


if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
if(vbval($_SESSION['SYS_USER_GI'])!=USU_GET_GI($_SESSION['SYS_USER_ID'])){
	JsDir("cerrar.php");	
	return;
}


$HW=$_SESSION['SYS_HW'];
$StrGT="";$LStrMsg="";$LStrFoc="";$LStrMM="";
$LStrPag=V($_POST['TxtPag']);
//
include("lq_ventas_ctas_fun.php");
//
$LStrTR=gn("count(*)","vventas_ctas",$FF);
$LStrPag=V($_POST['TxtPag']);
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=300;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
$TI=0;
?>
<html >
<head>
<style>
    /* Solo aplica a la tabla con id Exportar_a_Excel */
    #Exportar_a_Excel {
      border-collapse: collapse;
      width: 100%;
      max-height: 570px; /* altura máxima visible */
      display: block;
      overflow-y: auto; /* scroll solo en esta tabla */
	  font-size:11px;
	  font-family:Tahoma, Geneva, sans-serif
	 	
    }

    #Exportar_a_Excel th,
    #Exportar_a_Excel td {
      border: 1px solid #ccc;
      padding: 8px;
      text-align: left;
    }

    #Exportar_a_Excel thead th {
      position: sticky;
      top: 0;
      background: #f9f9f9; /* fondo del encabezado */
      z-index: 2;
    }
  </style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reporte de ventas / cobros / cuentas</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="fe/funcionex.js"></script>
<!--FIN_SCRIPT------------------------------------->
<link rel="stylesheet" type="text/css" href="estilox.css"  />
<link rel="stylesheet" type="text/css" href="basix.css"  />
<style type="text/css">
.cF {height:650px;width:1300px;position:relative; <?php echo "top:0px";?>}
</style>
<script>
$(document).ready(function(){  
   Inicializar();   
});
</script>
<script language="javascript">
$(document).ready(function() {
	$(".botonExcel").click(function(event) {
		$("#datos_a_enviar").val( $("<div>").append( $("#Exportar_a_Excel").eq(0).clone()).html());
		$("#FormularioExportacion").submit();
});
});
function _S(O){
	var s=O.value;
	s=s.trim()
	if(jL(s)==1)s="000"+s;
	if(jL(s)==2)s="00"+s;
	if(jL(s)==3)s="0"+s;
	O.value=s;
}
function _N(O){
	var s=O.value;
	s=s.trim()
	if(jL(s)==1)s="00000"+s;
	if(jL(s)==2)s="0000"+s;
	if(jL(s)==3)s="000"+s;
	if(jL(s)==4)s="00"+s;
	if(jL(s)==5)s="0"+s;
	O.value=s;
}

</script>
</head>

<body >
<div align="center">

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF; height:800px" >
<form id="Frm" name="Frm" method="post" action="lq_ventas_ctas.php" autocomplete="off">
<!--INI_TITULO-->
<div id="DivT" class="dT"  style="width:1300px">
<img src="img/unidades.png" class="iT" />
<div class="tT" style="width:1000px">REPORTE DE VENTAS / COBROS / CUENTAS</div>
</div>
<!--FIN_TITULO-->
<div class="s1" style="left:177px; top: 114px; width: 142px; height: 18px;">
  <?php
	if(strlen($_PDF)>0){
		echo "<a href=\"$_PDF\" target=\"_new\">DESCARGAR</a>";	
	}
?>
  
</div>

<div class="ad" style="left:35px; top:132px; width: 78px; height: 18px;">EMPRESA</div>
<select name="Emp" id="Emp" 
class="lty" style="left:35px; top:149px; width: 77px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBO("emp_nomc","empresas","id_emp>0",$Emp,"S","N");
?>
</select>

<div class="ad" style="left:124px; top:118px; width: 72px; height: 28px;">COMPRO-BANTE</div>
<select name="Com" id="Com" 
class="lty" style="left:123px; top:149px; width: 68px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
echo FCBO_("com_nombre","comprobantes",
		  "id_comprobante>0 AND com_nombre IN ('FACTURA','BOLETA','FACT. ELEC.','BOL. ELEC.')",$Com,"S","N");
?>
</select>


<div class="s1" style="left:201px; top: 132px; width: 40px; height: 18px;">
SERIE</div>
<input name="Ser"  type="text" 
class="lt"  id="Ser" onBlur="_S(this);"
style="left:201px; top: 149px; width: 41px;"
maxlength="4" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Ser;?>"   />

<div class="s1" style="left:250px; top: 132px; width: 59px; height: 18px;">
NUMERO</div>
<input name="Num"  type="text" 
class="lt"  id="Num" 
style="left:250px; top: 149px; width: 60px;"
maxlength="6" onBlur="_N(this);"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Num;?>"   />

<div class="s1" style="left:319px; top: 132px; width: 59px; height: 18px;">
CLIENTE</div>
<input name="Cli"  type="text" 
class="lt"  id="Cli" 
style="left:319px; top: 149px; width: 166px;"
maxlength="150" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Cli;?>"   />
<div class="ad" style="left:658px; top:116px; width: 52px; height: 18px;">
  GENE- RADO</div>
<select name="Gen" id="Gen" 
class="lty" style="left:657px; top:149px; width: 55px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
echo FCBO("au_item","auxiliar","au_tab='SI_NO'",$Gen,"S","N");
?>
</select>


<div class="ad" style="left:721px; top:116px; width: 52px; height: 18px;">
ANU- LADO</div>
<select name="Anu" id="Anu" 
class="lty" style="left:721px; top:149px; width: 55px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
echo FCBO("au_item","auxiliar","au_tab='SI_NO'",$Anu,"S","N");
?>
</select>

<div class="ad" style="left:785px; top:116px; width: 52px; height: 18px;">
COB- BRADO</div>
<select name="Cob" id="Cob" 
class="lty" style="left:785px; top:149px; width: 62px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
echo FCBO("au_item","auxiliar","au_tab='SI_NO'",$Cob,"S","N");
?>
</select>

<div class="ad" style="left:854px; top:116px; width: 52px; height: 18px;">
COB. MODALIDAD</div>
<select name="CobMod" id="CobMod" 
class="lty" style="left:854px; top:149px; width: 67px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
echo FCBO("au_item","auxiliar","au_tab='COB_MODA'",$CobMod,"S","N");
?>
</select>
<div class="ad" style="left:934px; top:132px; width: 257px; height: 18px;">CUENTA</div>
<select name="Cue" id="Cue" 
class="lty" style="left:932px; top:149px; width: 291px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
echo FCBO("MI_CUENTA","vis_cuentas_emp","ID_CTA>0",$Cue,"S","N");
?>
</select>





<div class="ad" style="left:497px; top:118px; width: 82px; height: 18px;">DESDE</div>
<div class="EV" style="left: 497px; top: 132px; width: 86px;"><u><a onClick="sh('Dex')">(dd-mm-yy)</a></u></div>
<input name="Dex" type="text" id="Dex" 
class="fe"
style="left:497px; top: 149px; width: 70px;" value="<?php echo $Dex;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="ad" style="left:579px; top:118px; width: 82px; height: 18px;">HASTA</div>
<div class="EV" style="left: 579px; top: 132px; width: 86px;"><u><a onClick="sh('Hax')">(dd-mm-yy)</a></u></div>
<input name="Hax" type="text" id="Hax" 
class="fe"
style="left:577px; top: 149px; width: 70px;" value="<?php echo $Hax;?>"  
tabindex="<?php echo ++$TI;?>" />






<input name="CmdF" type="button" id="CmdF"  style="position:absolute; top:149px; left:1231px; width: 57px;"
value="Filtrar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />

<!--INI_TABLA----->

<div class="s1"
style="background:#ECF9FF; position:absolute; left: 35px; top: 180px; width: 1262px; height: 426px; overflow:auto;">
<div class="s1" style="left: 0px; top: 0px; width: 1257px; z-index:0;">
<table class="f4t" width="1239" border="1" style="border-collapse: collapse">
<tr>
<td  bgcolor="#CCCCCC" height="18" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>
</tr>   
</table>
    
</div>
</div>

<div class="s1"
style="background:#ECF9FF; position:absolute; left: 35px; top: 205px; width: 1262px; height: 580px; overflow:auto;">

    <table id="Exportar_a_Excel" class="f4t" border="1" style="border-collapse: collapse; overflow-y: auto">
    <thead>
    <tr>
    <th style="width:20px" bgcolor="#CCCCCC"><b>#</b></th>
    <th style="width:100px" bgcolor="#CCCCCC"><b>EMPRESA</b></th>
    <th style="width:100px"  bgcolor="#CCCCCC"><b>COMPROBANTE</b></th>
    <th style="width:80px"  bgcolor="#CCCCCC"><b>SERIE</b></th>
    <th style="width:100px"  bgcolor="#CCCCCC"><b>NUMERO</b></th>
    <th style="width:100px" bgcolor="#CCCCCC"><b>FECHA</b></th>
    <th style="width:300px" bgcolor="#CCCCCC"><b>CLIENTE</b></th>
    <th style="width:80px" bgcolor="#CCCCCC"><b>RUC</b></th>
    <th style="width:100px" bgcolor="#CCCCCC"><b>N°DOCUMENTO</b></th>
    <th style="width:100px"" align="right" bgcolor="#CCCCCC"><b>SUBTOTAL</b></th>
    <th style="width:100px" align="right" bgcolor="#CCCCCC"><b>IGV</b></th>
    <th style="width:100px" align="right" bgcolor="#CCCCCC"><b>TOTAL</b></th>
    <th style="width:80px" bgcolor="#CCCCCC"><b>GEN</b></th>
    <th style="width:80px" bgcolor="#CCCCCC"><b>ANU</b></th>
    <th style="width:80px" bgcolor="#CCCCCC"><b>COB</b></th>
    <th style="width:100px" bgcolor="#CCCCCC"><b>C.MODALIDAD</b></th>      
    <th style="width:150px" bgcolor="#CCCCCC"><b>CTA.BANCO</b></th>
    <th style="width:100px" bgcolor="#CCCCCC"><b>CTA.NUMERO</b></th>
    <th style="width:100px" bgcolor="#CCCCCC"><b>CTA.OPE.NRO</b></th>
    <th style="width:100px" bgcolor="#CCCCCC"><b>CTA.OPE.FEC</b></th>
    </tr>
    </thead>   
    <?php
		$ZX=0;
		$CSS="";
		$TOT=0;
		$s="SELECT * FROM vventas_ctas WHERE ".$FF." ORDER BY FEC DESC,ID DESC ";
		$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
		$rs = grs($s);
		while ($r = $rs->fetch_assoc()){
			if($r['CTA_OPE_FEC_']=="01-01-00")$r['CTA_OPE_FEC_']="";
			$ZX++;
			$CSS="";
			if($ZX%2==0)$CSS=' style="background-color:#DADADA" ';
			if($ZX>350)break;
			if($r['COM']=="FACT. ELEC." || $r['COM']=="FACTURA"){
				$r['DNI']="";
			}else{
				$r['RUC']="";
			}
			
	?>
        <tr <?php echo $CSS;?> >
        <td>'<?php echo $ZX;?></td>
        <td style="white-space: nowrap;"><?php echo $r['EMPC'];?></td>
        <td style="white-space: nowrap;"><?php echo $r['COM'];?></td>
        <td style="white-space: nowrap;">'<?php echo $r['SER'];?></td>
        <td style="white-space: nowrap;">'<?php echo $r['NUM'];?></td>
        <td style="white-space: nowrap;"><?php echo $r['FEC_'];?></td>
        <td style="white-space: nowrap;"><?php echo $r['CLI'];?></td>  
        <td style="white-space: nowrap;">'<?php echo $r['RUC'];?></td>        
        <td style="white-space: nowrap;">'<?php echo $r['DNI'];?></td>
        <td align="right" style="padding-right:0.2rem;white-space: nowrap;"><?php echo NF2($r['ST'],2);?></td>
        <td align="right" style="padding-right:0.2rem;white-space: nowrap;"><?php echo NF2($r['IGV'],2);?></td> 
        <td align="right" style="padding-right:0.2rem;white-space: nowrap;"><?php echo NF2($r['TOT'],1);?></td> 
        <td style="white-space: nowrap;"><?php echo $r['GEN'];?></td>    
        <td style="white-space: nowrap;"><?php echo $r['ANU'];?></td> 
        <td style="white-space: nowrap;"><?php echo $r['COB_PAG'];?></td> 
        <td style="white-space: nowrap;"><?php echo $r['COB_MODA'];?></td> 
        <td style="white-space: nowrap;"><?php echo $r['CTA_BAN'];?></td>    
        <td style="white-space: nowrap;"><?php echo $r['CTA_NRO'];?></td>  
        <td style="white-space: nowrap;"><?php echo $r['CTA_OPE_NRO'];?></td>  
        <td style="white-space: nowrap;"><?php echo $r['CTA_OPE_FEC_'];?></td>  
        </tr>			
    <?php
		}
	?>
  </table>

</div>
<!--FIN_TABLA----->
<!--INI_OCULTOS-------------------------------->
<?php include("ocultox.php");?>
<!--FIN_OCULTOS-------------------------------->
<!--INI_BOTONES----->
<div id="DivBtn"  align="left"
style="position:absolute; left: 33px; top: 71px; width: 180px; height: 26px;">
<input name="CmdB" type="button" id="CmdZ" class="btm"
value="Volver" onClick="fBuscar('menu.php');"  
tabindex="<?php echo ++$TI;?>" />
</div>
<!--FIN_BOTONES-->
</form>
<form action="ficheroExcel.php" method="post" target="_blank" id="FormularioExportacion" >
<div style="position:absolute; left: 149px; top: 72px; width: 45px; height: 15px;">  
<input name="" type="button" class="botonExcel" value="Exportar" />
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
</div>
</form>

</div>
</div>
</body>
</html>
