<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
include("edc22_funciones.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_dh_fun.php");
//
$USU=vbval(V($_SESSION['SYS_USER_ID']));
$HWN="EDC_".V($_SESSION['SYS_HW']);
$DEX=val_dex($Dex);
$HAX=val_hax($Hax);
//
$LStrTR=mysqli_num_rows($RS);
$LStrPag=V($_POST['TxtPag']);
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=10;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
$TI=0;
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Proformas - Estado de cuenta (Formato2)</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();   
});
</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_dh.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 (FORMATO 2)</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="s1" style="left:35px; top: 132px; width: 141px; height: 18px;">
CLIENTE</div>
<input name="Cli"  type="text" 
class="lt"  id="Cli" 
style="left:35px; top: 149px; width: 223px;"
maxlength="150" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Cli;?>"   />

<div class="s1" style="left:271px; top: 132px; width: 94px; height: 18px;"> RUC
</div>
<input name="Ruc"  type="text" 
class="lt"  id="Ruc" 
style="left:269px; top: 149px; width: 123px;"
maxlength="150" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Ruc;?>"   />

<div class="s1" style="left:402px; top: 132px; width: 64px; height: 18px;"> DNI
</div>
<input name="Dni"  type="text" 
class="lt"  id="Dni" 
style="left:402px; top: 149px; width: 123px;"
maxlength="150" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Dni;?>"   />


<div class="ad" style="left:548px; top:100px; width: 148px; height: 18px;">
FECHA DE PROFORMA</div>
<div class="ad" style="left:548px; top:118px; width: 82px; height: 18px;">
DESDE</div>
<div class="EV" style="left: 548px; 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:548px; top: 149px; width:90px;" 
value="<?php echo $Dex;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="ad" style="left:653px; top:118px; width: 82px; height: 18px;">HASTA</div>
<div class="EV" style="left: 653px; 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:651px; top: 149px; width: 90px;" 
value="<?php echo $Hax;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="ad" style="left:754px; top:132px; width: 78px; height: 18px;">
ESTADO</div>
<select name="Est" id="Est" 
class="lty" style="left:754px; top:149px; width: 219px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBOO_("au_item","auxiliar","au_tab='EDC'",$Est,"N","N","au_orden");
?>
</select>
<input name="CmdF" type="button" id="CmdF"  style="position:absolute; top:149px; left:1131px; width: 105px;"
value="Filtrar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />

<!--INI_TABLA----->

<div class="s1"
style="position:absolute; left: 35px; top: 180px; width: 1195px; overflow:auto;">
    <table width="100%">
    <tr>
    <td  height="18" align="center">
    <?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
    </td>
    </tr> 
    </table>
</div>

<div class="s1"
style="position:absolute; left: 35px; top: 213px; width: 1262px; height: 607px; overflow:auto;">
<div class="s1" style="left: 0px; top: 0px; width: 1240px; 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=$SQL;
		$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
		$rs = grs($s);
		while ($r = $rs->fetch_assoc()){
			$KLI=$r['IDCLI'];
			GEN_EDC($USU,$HWN,$KLI,$DEX,$HAX);
			$SAL_INI=GET_SAL_INI($KLI,$DEX);			
	?>
        <tr style="background-color:#CCC">
        <td width="115" ><b>CLIENTE</b></td>
        <td width="3">:</td>
        <td colspan="6"><?php echo $r['CLI'];?></td>
        <td width="151" ></td> 
        <td width="15"></td>
        </tr>
        <tr style="background-color:#CCC">
          <td><b>SALDO INICIAL</b></td>
          <td>:</td>
          <td colspan="2" align="left"><?php echo NF2($SAL_INI,1)?></td>
          <td width="153">&nbsp;</td>
          <td width="153">&nbsp;</td>
          <td width="153" align="right" style="padding-right:0.2rem">&nbsp;</td>
          <td width="153" align="right">&nbsp;</td>
          <td align="right">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        
       
        
        
        <tr >
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td colspan="7">
          
                <table width="100%" border="0" style="font-size:11px;border-collapse: collapse">
                <tr style="background-color:#CCC">
                <td width="10%"><b>FECHA</b></td>
                <td width="13%"><b>DOCUMENTO</b></td>
                <td width="15%"><b>NUMERO</b></td>
                <td width="12%"><b>TIPO DE PAGO</b></td>
                <td width="33%"><b>&nbsp;</b></td>
                <td width="9%" align="right"><b>DEBE</b></td>
                <td width="8%" align="right"><b>HABER</b></td>
                </tr>
                <?php
				$TOT_DEB=0;
				$TOT_HAB=0;
				$w="SELECT * FROM vis_edc22 
					WHERE USU=$USU AND HW='$HWN' ORDER BY FEC,GI";
				$rw=grs($w);
    			while($w=$rw->fetch_assoc()){
					$X_FEC=$w['FEC_'];
					$X_DOC_TIP=$w['DOC_TIP'];
					$X_DOC_NUM=$w['DOC_NUM'];
					$X_DOC_TDP=$w['DOC_TDP'];
				
					$X_DEB=$w['DEB'];
					$X_HAB=$w['HAB'];
					//
					$TOT_DEB=$TOT_DEB + $X_DEB;
					$TOT_HAB=$TOT_HAB + $X_HAB;
				?>
                <tr>
                <td><?php echo $X_FEC;?></td>
                <td><?php echo $X_DOC_TIP;?></td>
                <td><?php echo $X_DOC_NUM;?></td>
                <td><?php echo $X_DOC_TDP;?></td>
                <td>&nbsp;</td>
                <td align="right"><?php echo $X_DEB;?></td>
                <td align="right"><?php echo $X_HAB;?></td>
                </tr>
                
                <tr>
                <td>&nbsp;</td>
                <td colspan="4">
                	<?php
					if($w['PHP']=="PROFORMA"){
					?>
                    <table width="100%" border="0" style="font-size:11px;border-collapse: collapse">
                    <tr >
                    <td colspan="6"><b>COMPROBANTES EMITIDOS</b></td>
                    </tr>
                    <tr style="background-color:#CCC">
                    <td width="13%"><b>EMPRESA</b></td>
                    <td width="14%"><b>FECHA</b></td>
                    <td width="18%"><b>COMPROBANTE</b></td>
                    <td width="13%"><b>NUMERO</b></td>
                    <td width="32%" align="right"><b>TOTAL</b></td>
                    <td width="10%" align="center"><b>PAGADO</b></td>
                    </tr>
						<?php
						$z="SELECT * FROM vis_cot_ven_relacionadas 
           				    WHERE REF_ID_COM=-3 AND REF_ID=".$w['PHP_ID']." AND ANU='N' ORDER BY ID ";
						$rz=grs($z);
        				while($z=$rz->fetch_assoc()){
                        ?>
                        <tr>
                        <td><?php echo $z['EMP_NC'];?></td>
                        <td><?php echo $z['FEC_'];?></td>
                        <td><?php echo $z['COM'];?></td>
                        <td><?php echo $z['NUM'];?></td>
                        <td align="right"><?php echo NF2($z['TOT'],1);?></td>
                        <td align="center"><?php echo $z['PAGADO'];?></td>
                        </tr>
                        <?php
							$not="SELECT * FROM vis_cot_notas 
							WHERE REF_VEN_ID=".$z['ID']." AND ANU='N' ORDER BY ID ";
							$rn=grs($not);
							while($not=$rn->fetch_assoc()){
							?>
                                <tr>
                                <td>&nbsp;</td>
                                <td><?php echo $not['FEC_'];?></td>
                                <td><?php echo $not['COM'];?></td>
                                <td><?php echo $not['COM_SER']."-".$not['COM_NUM'];?></td>
                                <td align="right"><?php echo NF2($not['TOT'],1);?></td>
                                <td align="right">&nbsp;</td>
                                </tr>
							<?php
							}
						}
                        ?>
                    </table>
                    <?php
					}
					?>
                    
                    <?php
					if($w['PHP']=="COBRO" &&  $w['DOC_TIP']=="COBRO(R)" && $w['DOC_TIP']=="DEPOSITO"){
					?>
                    <table width="100%" border="0" style="font-size:11px;border-collapse: collapse">
                    <tr style="background-color:#CCC">
                    <td width="68%"><b>CUENTA</b></td>
                    <td width="15%"><b>FECHA</b></td>
                    <td width="17%"><b>N° OPERACION</b></td>
                    </tr>
                    	<?php
						$rx=gr("vis_cot_cobroz","ID=".$r['ID']);
						?>
                        <tr>
                        <td><?php echo $rx['CTA_BAN']." ".$rx['CTA_NRO'];?></td>
                        <td><?php echo $rx['OPE_FEC_'];?></td>
                        <td><?php echo $rx['OPE_NRO'];?></td>
                        </tr>
              
                    </table>
                    <?php
					}
					?>
                    
                </td>
                <td align="right">&nbsp;</td>
                <td align="right">&nbsp;</td>
                </tr>
                
                <tr>
                <td>&nbsp;</td>
                <td colspan="4">
                </td>
                <td align="right">&nbsp;</td>
                <td align="right">&nbsp;</td>
                </tr>           
                <?php
				}
				?>
                <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td align="right"><b>TOTAL</b></td>
                <td align="right"><b><?php echo NF2($TOT_DEB,1);?></b></td>
                <td align="right"><b><?php echo NF2($TOT_HAB,1);?></b></td>
                </tr>
                
                <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td align="right"><b>SALDO FINAL (Inc. SALDO INICIAL)</b></td>
                <td align="right"></td>
                <td align="right"><b><?php echo NF2($SAL_INI + $TOT_DEB - $TOT_HAB,1);?></b></td>
                </tr>
                
                </table>
                
          </td>
          <td>&nbsp;</td>
        </tr>
        <tr >
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td width="109">&nbsp;</td>
          <td width="153">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right" style="padding-right:0.2rem">&nbsp;</td>
          <td align="right">&nbsp;</td>
          <td align="right">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr >
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right" style="padding-right:0.2rem">&nbsp;</td>
          <td align="right">&nbsp;</td>
          <td align="right">&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>
