<?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_estado_de_cuenta_fun.php");
//
$LStrTR=gn("count(*)","vis_cot_edc",$FF);
$LStrPag=V($_POST['TxtPag']);
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=30;	
//
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
$TI=0;
?>
<html >
<head>
<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:850px;width:1300px;position:relative; <?php echo "top:0px";?>}
</style>
<script>
$(document).ready(function(){  
   Inicializar();   
   jF("Ser");
});
</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;" >
<form id="Frm" name="Frm" method="post" 
action="lq_estado_de_cuenta.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">PROFORMAS - ESTADO DE CUENTA</div>
</div>
<!--FIN_TITULO-->
<div class="s1" style="left:176px; top: 114px; width: 143px; height: 18px;">
  <?php
	if(strlen($_PDF)>0){
		echo "<a href=\"$_PDF\" target=\"_new\">DESCARGAR</a>";	
	}
?>
  
</div>

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

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

<div class="s1" style="left:233px; top: 132px; width: 119px; height: 18px;">
CLIENTE</div>
<input name="Cli"  type="text" 
class="lt"  id="Cli" 
style="left:233px; top: 149px; width: 226px;"
maxlength="150" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Cli;?>"   />


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

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

<div class="ad" style="left:675px; top:132px; width: 78px; height: 18px;">
ESTADO</div>
<select name="Est" id="Est" 
class="lty" style="left:675px; top:149px; width: 219px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBOO_("au_item","auxiliar","au_tab='EDC'",$Est,"N","N","au_orden");
?>
</select>


<div class="ad" style="left:906px; top:132px; width: 78px; height: 18px;">
VENDEDOR</div>
<select name="Ven" id="Ven" 
class="lty" style="left:906px; top:149px; width: 219px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBO_("NOMBRE","vpersonal","ID>0 AND CARGO='VENDEDOR'",$Ven,"S","N");
?>
</select>





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

<!--INI_TABLA----->
<div class="s1" style="position:absolute; left: 35px; top: 178px; width: 1252px; height: 22px; overflow:auto; background-color:#FFF ">
<table class="f4t" width="1200" border="0" style="border-collapse: collapse">
<tr>
<td colspan="10" height="18" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>
</tr> 
</table>
</div>

<div class="s1"
style="background:#FFF; position:absolute; left: 35px; top: 201px; width: 1252px; height: 622px; overflow:auto;">
<div class="s1" style="left: 0px; top: 0px; width: 1229px; z-index:0;">
  <table id="Exportar_a_Excel" class="f4t" width="1200" border="0" style="border-collapse: collapse">
   
    <?php
		$ZX=0;
		$CSS="";
		$TOT=0;
		$s="SELECT * FROM vis_cot_edc WHERE $FF ORDER BY ID ";
		$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
		$rs = grs($s);
		while ($r = $rs->fetch_assoc()){
			$PROFORMA_TOT=$r['TOT_REAL'];
			$PROFORMA_OBS="";
			$PROFORMA_VENTAS_CANT=0;
			for($i=1;$i<=10;$i++){
				$PROFORMA_VENTAS[$i]=0;
			}
			$ZX++;
			$CSS="";
			if($ZX%2==0){
				$CSS=' style="background-color:#A3F8AD " ';
			}
	?>
        <tr>
        <td width="72" bgcolor="#CCCCCC"><b>#<?php echo $ZX;?></b></td>
        <td width="67" bgcolor="#CCCCCC"><b>EMPRESA</b></td>
        <td width="69" bgcolor="#CCCCCC"><b>SERIE</b></td>
        <td width="100" bgcolor="#CCCCCC"><b>NUMERO</b></td>
        <td width="78" bgcolor="#CCCCCC"><b>FECHA</b></td>
        <td width="352" bgcolor="#CCCCCC"><b>CLIENTE</b></td>
        <td width="94" align="right" bgcolor="#CCCCCC"><b>TOTAL</b></td>
        <td width="72" bgcolor="#CCCCCC"><b>A CUENTA</b></td>
        <td width="63" bgcolor="#CCCCCC"><b>SALDO</b></td>
        <td width="103" bgcolor="#CCCCCC"><b>VENDEDOR</b></td>
        </tr> 
        
        <tr <?php echo $CSS; ?> >
        <td><b>PROFORMA:</b></td>
        <td><?php echo $r['EMPC'];?></td>
        <td>'<?php echo $r['SER'];?></td>
        <td>'<?php echo $r['NUM'];?></td>
        <td><?php echo $r['FEC'];?></td>
        <td><?php echo $r['CLI'];?></td>        
        
        <td align="right" style="padding-right:0.2rem">
		<?php echo NF2($r['TOT_REAL'],1);?></td> 
        <td align="right"><?php echo NF2( $r['TOT_COB'],1);?></td>    
        <td align="right"><?php echo NF2($r['SALDO'],1);?></td> 
        <td><?php echo $r['VEN'];?></td>
        </tr>

        <tr  <?php echo $CSS; ?> >
        <td>&nbsp;</td>
        <td colspan="9"><div style="padding-top:0.3rem ; padding-bottom:0.3rem; font-size:10px"><b>COMPROBANTES EMITIDOS</b></div>
        </td>
        </tr>
    
    <tr  <?php echo $CSS; ?>  >
    <td></td>
    <td colspan="6" <?php echo $CSS; ?>  >
    	<table width="100%" border="0" style="font-family:Tahoma, Geneva, sans-serif; font-size:11px;border-collapse: collapse ">
        <tr style="background-color:#CCC">
        <td width="10%"><b>EMPRESA</b></td>
        <td width="10%"><b>COMPROBANTE</b></td>
        <td width="5%"><b>SERIE</b></td>
        <td width="6%"><b>NUMERO</b></td>
        <td width="7%"><b>FECHA</b></td>
        <td width="55%"><b>CLIENTE</b></td>
        <td width="11%"><b>TOTAL</b></td>
        <td width="6%" align="center"><b>PAGADO</b></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        <?php
        $v="SELECT * FROM vis_cot_ven_relacionadas 
            WHERE REF_ID_COM=-3 AND REF_ID=".$r['ID']." AND ANU='N' ORDER BY ID ";
        $rv=grs($v);
        while($v=$rv->fetch_assoc()){
			$PROFORMA_VENTAS_CANT++;
			$PROFORMA_VENTAS[$PROFORMA_VENTAS_CANT]=$v['ID'];
			
        ?>
            <tr  >
            <td><?php echo $v['EMP_NC'];?></td>
            <td>'<?php echo $v['COM'];?></td>
            <td><?php echo $v['SER'];?></td>
            <td><?php echo $v['NUM'];?></td>
            <td><?php echo $v['FEC_'];?></td>
            <td><?php echo $v['CLI'];?></td>
            <td align="right"><?php echo NF2($v['TOT'],1);?></td>
            <td align="center"><?php echo $v['PAGADO'];?></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            </tr>
        <?php
        }
        ?>
        </table>
    </td>      
        
    <td >&nbsp;</td>
    <td >&nbsp;</td>
    <td >&nbsp;</td>
    </tr>

    <tr <?php echo $CSS; ?> >
    <td>&nbsp;</td>
    <td colspan="9">&nbsp;</td>
    </tr>

    <tr  <?php echo $CSS; ?> >
    <td>&nbsp;</td>
    <td colspan="9"><div style="padding-top:0.3rem ; padding-bottom:0.3rem; font-size:10px"><b>COBROS RELACIONADOS</b></div>
    </td>
    </tr>

    <tr <?php echo $CSS; ?> >
    <td>&nbsp;</td>
    <td colspan="6">
    
        <table width="100%" border="0" style="font-family:Tahoma, Geneva, sans-serif; font-size:11px;border-collapse: collapse ">
        <tr style="background-color:#CCC">
        <td width="5%"><b>TIPO</b></td>
        <td width="10%"><b>CODIGO</b></td>
        <td width="8%"><b>FECHA</b></td>
        <td width="5%"><b>TOTAL</b></td>
        <td width="9%"><b>MODALIDAD</b></td>
        <td width="42%"><b>CUENTA</b></td>
        <td width="10%"><b>NªOPERACION</b></td>
        <td width="11%"><b>F.OPERACION</b></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        <?php
		$TOTAL_COBRADO=0;
		
        $c="SELECT * FROM vis_cot_cobroz 
            WHERE ID_COM=-3 AND COT_ISER=".$r['ISER']." AND COT_INUM=".$r['INUM']." 
			ORDER BY ID ";
        $rc=grs($c);
        while($c=$rc->fetch_assoc()){
			if($c['OPE_FEC_']=="01-01-00")$c['OPE_FEC_']="";
			$TOTAL_COBRADO=$TOTAL_COBRADO + $c['TOT'];
        ?>
            <tr>
            <td>R</td>
            <td><?php echo $c['COD'];?></td>
            <td><?php echo $c['FEC_'];?></td>
            <td align="right"><?php echo NF2($c['TOT'],1);?></td>
            <td><?php echo $c['TDP'];?></td>
            <td><?php echo $c['CTA_BAN']." - ".$c['CTA_NRO'];?></td>
            <td><?php echo $c['OPE_NRO'];?></td>
            <td><?php echo $c['OPE_FEC_'];?></td>
            <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
            </tr>
        <?php
        }
        ?>
        
        <?php
        $c="SELECT * FROM vis_cot_devoluciones
            WHERE ID_COM=-3 AND COT_ISER=".$r['ISER']." AND COT_INUM=".$r['INUM']." 
			ORDER BY ID ";
        $rc=grs($c);
        while($c=$rc->fetch_assoc()){
			if($c['TIP']=="D")$c['TIP']="DEVOLUCION";
			if($c['TIP']=="J")$c['TIP']="DEJA";
			$TOTAL_COBRADO=$TOTAL_COBRADO + $c['TOT'];
        ?>
            <tr>
            <td>D</td>
            <td><?php echo $c['NRO'];?></td>
            <td><?php echo $c['FEC_'];?></td>
            <td align="right"><?php echo NF2($c['TOT'],1);?></td>
            <td><?php echo $c['TIP'];?></td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            </tr>
           
        <?php
        }
		
		$SALDO=$PROFORMA_TOT - $TOTAL_COBRADO;
        ?>
        <tr <?php echo $CSS; ?> >
        <td>&nbsp;</td>
        <td colspan="2" >&nbsp;</td>
        <td align="right">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        <tr >
        <td>&nbsp;</td>
        <td colspan="2" ><b>TOTAL COBRADO</b></td>
        <td align="right"><?php echo NF2($TOTAL_COBRADO,1)?></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        <tr >
        <td>&nbsp;</td>
        <td colspan="2" ><b>SALDO PENDIENTE</b></td>
        <td align="right"><?php echo NF2($SALDO,1)?></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        
        
        </table>
    </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>

    <tr  <?php echo $CSS; ?> >
    <td>&nbsp;</td>
    <td colspan="9">&nbsp;</td>
    </tr>
	

    <tr <?php echo $CSS; ?> >
    <td>&nbsp;</td>
    <td colspan="9"><div style="padding-top:0.3rem ; padding-bottom:0.3rem; font-size:10px"><b>NOTAS EMITIDAS</b></div>
    </td>
    </tr>
    
    <tr <?php echo $CSS; ?> >
    <td>&nbsp;</td>
    <td colspan="6">
              
            <table width="100%" border="0" style="font-family:Tahoma, Geneva, sans-serif; font-size:11px;border-collapse: collapse ">
            <tr style="background-color:#CCC">
            <td width="10%"><b>COMPROBANTE</b></td>
            <td width="4%"><b>SERIE</b></td>
            <td width="6%"><b>NUMERO</b></td>
            <td width="9%"><b>FECHA</b></td>
            <td width="28%"><b>CLIENTE</b></td>
            <td width="8%"><b>TOTAL</b></td>
            <td width="4%" >&nbsp;</td>
            <td width="10%" ><b>REFERENCIA</b></td>
            <td width="10%" ><b>SERIE</b></td>
            <td width="11%" ><b>NUMERO</b></td>
            <td>&nbsp;</td>
            </tr>
            <?php
			$NOTAS_CANT=0;
			for($i=1;$i<=$PROFORMA_VENTAS_CANT;$i++){
				$VENTA_KOD=$PROFORMA_VENTAS[$i];
				$v="SELECT * FROM vis_cot_notas 
				WHERE REF_VEN_ID=$VENTA_KOD AND ANU='N' ORDER BY ID ";
				$rv=grs($v);
				while($v=$rv->fetch_assoc()){
					$NOTAS_CANT++;
				?>
					<tr>
					<td>'<?php echo $v['COM'];?></td>
					<td><?php echo $v['COM_SER'];?></td>
					<td><?php echo $v['COM_NUM'];?></td>
					<td><?php echo $v['FEC_'];?></td>
					<td><?php echo substr($v['CLI'],0,25);?></td>
					<td align="right"><?php echo NF2($v['TOT'],1);?></td>
					<td>&nbsp;</td>
                    <td><?php echo $v['REF_COM'];?></td>
					<td><?php echo $v['REF_SER'];?></td>
                    <td><?php echo $v['REF_NUM'];?></td>
                    <td>&nbsp;</td>
					</tr>
				<?php
				}
			}
            ?>
            <?php
			if($NOTAS_CANT==0){
			?>
            <tr >
            <td width="10%"><b>CERO NOTAS</b></td>
            <td width="4%">&nbsp;</td>
            <td width="6%">&nbsp;</td>
            <td width="9%">&nbsp;</td>
            <td width="28%">&nbsp;</td>
            <td width="8%">&nbsp;</td>
            <td width="4%" >&nbsp;</td>
            <td width="10%" >&nbsp;</td>
            <td width="10%" >&nbsp;</td>
            <td width="11%" >&nbsp;</td>
            <td>&nbsp;</td>
            </tr>
            <?php
			}
			?>
            </table>           
          
    </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>    

    <tr <?php echo $CSS; ?> >
    <td>&nbsp;</td>
    <td colspan="6">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
   
       
    <?php
	}
	?>
    
   
    
  </table>
</div>
</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>
