<?php
ini_set("session.cookie_lifetime",60*60*10);
ini_set("session.gc_maxlifetime", 60*60*10);
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;
}
$TI=0;
//-------------------------
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
//-------------------------
$StrEmp=V($_POST['CboEmp']);	
$StrCom=V($_POST['CboCom']);		
$StrSer=V($_POST['TxtSer']);		
$StrNum=V($_POST['TxtNum']);		
$StrDex=V($_POST['TxtDex']);		
$StrHax=V($_POST['TxtHax']);			
$StrPro=V($_POST['TxtPro']);	
$StrEst=V($_POST['CboEst']);	
$StrVen=V($_POST['CboVen']);	
//
if(strlen($StrEmp)==0)$StrEmp=GE("N");
//
if(strlen($StrCom)==0)$StrCom="PROFORMA";	
if(strlen($StrEst)==0)$StrEst="PENDIENTES POR COBRAR";	
if(strlen($StrVen)==0)$StrVen="TODOS";
$StrEst_=substr($StrEst,0,1);	
//
$StrSer_="%".$StrSer;
$StrNum_="%".$StrNum;
$StrDex_=val_dex($StrDex);
$StrHax_=val_hax($StrHax);	
$StrPro_=$StrPro."%";
if($StrVen=="TODOS"){
	$StrVen_="%";
}else{
	$StrVen_=$StrVen;
}
//-------------------------
if($StrCom=="PROFORMA"){
	if($StrEst_=="T"){
		$FF="ID>0 AND SER LIKE '$StrSer_' AND 
			 NUM LIKE '$StrNum_' AND FEC>='$StrDex_' AND 
			 FEC<='$StrHax_' AND CLI LIKE '$StrPro_' AND 
			 ANU='N' AND PRI_='1' AND EMPC='$StrEmp' AND VEN LIKE '$StrVen_' ";
	}
	if($StrEst_=="P"){
		$FF="ID>0 AND SER LIKE '$StrSer_' AND 
			 NUM LIKE '$StrNum_' AND FEC>='$StrDex_' AND 
			 FEC<='$StrHax_' AND CLI LIKE '$StrPro_' AND 
			 ANU='N' AND PRI_='1' AND ROUND(SALDO,2)>0 AND EMPC='$StrEmp' AND VEN LIKE '$StrVen_' ";
	}
	if($StrEst_=="C"){
		$FF="ID>0 AND SER LIKE '$StrSer_' AND 
			 NUM LIKE '$StrNum_' AND FEC>='$StrDex_' AND 
			 FEC<='$StrHax_' AND CLI LIKE '$StrPro_' AND 
			 ANU='N' AND PRI_='1' AND ROUND(SALDO,2)=0 AND EMPC='$StrEmp' AND VEN LIKE '$StrVen_' ";
	}
	$TAB="vcot_edc";
}else{
	if($StrEst_=="T"){
		$FF="ID>0 AND SER LIKE '$StrSer_' AND 
			 NUM LIKE '$StrNum_' AND FEC>='$StrDex_' AND 
			 FEC<='$StrHax_' AND CLI LIKE '$StrPro_' AND 
			 ANU='N' AND PRI_=1 AND COM='$StrCom'  AND EMPC='$StrEmp' AND VEN LIKE '$StrVen_' ";
	}
	if($StrEst_=="P"){
		$FF="ID>0 AND SER LIKE '$StrSer_' AND 
			 NUM LIKE '$StrNum_' AND FEC>='$StrDex_' AND 
			 FEC<='$StrHax_' AND CLI LIKE '$StrPro_' AND 
			 ANU='N' AND PRI_=1 AND COM='$StrCom' AND SALDO>0  AND EMPC='$StrEmp' AND VEN LIKE '$StrVen_' ";
	}
	if($StrEst_=="C"){
		$FF="ID>0 AND SER LIKE '$StrSer_' AND 
			 NUM LIKE '$StrNum_' AND FEC>='$StrDex_' AND 
			 FEC<='$StrHax_' AND CLI LIKE '$StrPro_' AND 
			 ANU='N' AND PRI_=1 AND COM='$StrCom' AND SALDO=0  AND EMPC='$StrEmp' AND VEN LIKE '$StrVen_' ";
	}

	$TAB="vven_edc";
}
$LStrTR=gn("count(*)",$TAB,$FF);
$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=1000;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Proformas - Estado de Cuenta</title>
<!--CSS_NEW------------------------------------->
<link rel="stylesheet" type="text/css" href="estiloss.css"  />
<link rel="stylesheet" type="text/css" href="basic.css"  />
<!--CSS_NEW------------------------------------->
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="jquery.maskedinput.min.js" type="text/javascript"></script>
<script type="text/javascript" src="fe/funciones.js"></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();
});
});
</script>
<script>
$(document).ready(function(){
   $("#TxtDex").mask("99-99-99");
   $("#TxtHax").mask("99-99-99");
});
</script>
<style type="text/css">
<!--
body {
	background-color: #CCC;
}
#Layer1 {
	position:absolute;
	left:345px;
	top:115px;
	width:123px;
	height:35px;
	z-index:1;
}
.centrarFrm{
	width:1300px;
	height:600px;
	position:absolute;
	left:<?php echo "50%";?>;
	top:<?php echo "50%";?>;
	background-color:#006699;
	margin:<?php echo "-300px";?> 0 0 <?php echo "-650px";?>;
}
#Layer2 {
	position:absolute;
	left:409px;
	top:205px;
	width:82px;
	height:24px;
	z-index:1;
}
.Estilo1 {
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #FFFFFF;
}
.f2 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #FFFFFF; font-size: 12px; }
.Estilo3 {color: #FFFFFF; font-size: 12px; font-family: Arial, Helvetica, sans-serif;}
.eS4 {color: #000099}
.Estilo5 {color: #000000}

-->
</style>

</head>
<body  <?php echo $StrMsg;?>>
<div Id="DivFRM"  class="centrarFrm" >
<div id="LblTit" style="position:absolute; left: 20px; top: 25px; width: 64px;">
<div align="left" class="Estilo1"><img src="img/buscar.png" width="57" height="60" /></div>
</div>	

<form id="Frm" name="Frm" method="post" action="cotizaciones_saldos.php">
<input name="TxtAc" type="hidden" value="" id="TxtAc" />
<input name="TxtPag" type="hidden" value="<?php echo $LStrPag;?>" id="TxtPag"  />
<input name="FEC_SERVER" type="hidden" id="FEC_SERVER" value="<?php echo date("d-m-y");?>"/>
<div id="layer5" style="position:absolute; left: 79px; top: 50px; width: 85px; height: 28px;">
  <div align="left" class="f2">
<input name="CmdV" type="button" id="CmdV" 
value="Volver" onclick="fVolver('menu.php');" />
</div>
</div>

<div class="s1" style="left:25px; top: 104px; width: 115px;">
EMPRESA
</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:25px; top:122px; width: 113px;" 
onkeydown="return SoloTextoEx(event,'CboAlm');" tabindex="1">
<?php 
	echo LE($StrEmp,"N","N"); 
?>
</select>

<div class="s1" style="left:146px; top: 104px; width: 115px;">
COMPROBANTE
</div>
<select name="CboCom" id="CboCom" style="position:absolute; left: 143px; top: 122px; width: 120px;" 
onkeydown="return SoloTextoEx(event,'TxtSer');" 
tabindex="<?php echo ++$TI;?>">
<?php 
echo FCBOOD_("com_nombre","comprobantes",
"com_nombre IN ('FACTURA','BOLETA','PROFORMA','FACT. ELEC.','BOL. ELEC.')",$StrCom,"N","N","com_nombre");
?>
</select>    

<div class="s1" style="left:271px; top: 104px; width: 52px;">
SERIE
</div>
<input name="TxtSer" type="text" id="TxtSer" 
style="position:absolute; left: 269px; top: 122px; width: 52px;" 
onblur="_S(this);"
value="<?php echo $StrSer;?>"  
onkeydown="return SoloTextoEx(event,'TxtNum');"
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left:335px; top: 104px; width: 70px;">
NUMERO
</div>
<input name="TxtNum" type="text" id="TxtNum" 
style="position:absolute; left: 331px; top: 122px; width: 66px;" 
onblur="_N(this);"
value="<?php echo $StrNum;?>"  
onkeydown="return SoloTextoEx(event,'TxtDex');"
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left:404px; top: 90px; width: 73px;">
DESDE
</div>
<div class="EV" 
style="left: 403px; top: 104px; width: 80px; color:#FF0"><u><a onclick="fFecServer('TxtDex')">(dd-mm-yy) +</a></u></div>
<input name="TxtDex" type="text" id="TxtDex" 
style="position:absolute; left: 403px; top: 122px; width: 80px;" value="<?php echo $StrDex;?>"  
onkeydown="return SoloFec(this,event,'TxtHax');"
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left:491px; top: 90px; width: 73px;">
HASTA
</div>
<div class="EV" style="left: 490px; top: 104px; width: 79px; color:#FF0"><u><a onclick="fFecServer('TxtHax')">(dd-mm-yy) +</a></u></div>
<input name="TxtHax" type="text" id="TxtHax" 
style="position:absolute; left: 489px; top: 122px; width: 80px;" 
value="<?php echo $StrHax;?>"  
onkeydown="return SoloFec(this,event,'TxtPro');"
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left:579px; top: 104px; width: 109px;">
CLIENTE
</div>
<input name="TxtPro" type="text" id="TxtPro" 
style="position:absolute; left: 577px; top: 122px; width: 137px;" value="<?php echo $StrPro;?>"  
onkeydown="return SoloTextoEx(event,'CboEst');" 
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left:727px; top: 104px; width: 148px;">
ESTADO
</div>
<select name="CboEst" id="CboEst" 
style="position:absolute; left: 725px; top: 122px; width: 180px;" 
onkeydown="return SoloTextoEx(event,'CboVen');" 
tabindex="<?php echo ++$TI;?>">
<?php 
echo FCBOO_("au_item","auxiliar",
"au_tab='EDC'",$StrEst,"N","N","au_orden");
?>
</select>  

<div class="s1"  style="left:921px; top:104px; width: 122px;">VENDEDOR</div>
<select name="CboVen" id="CboVen" 
style="position:absolute; left: 919px; top: 122px; width: 145px;"
onkeydown="return SoloTextoEx(event,'CmdB');" tabindex="15" >
<?php
echo FCBO_("NOMBRE","vpersonal","ID>0 AND CARGO='VENDEDOR'",$StrVen,"S","N");
?>
</select>



<input name="CmdB" type="button" id="CmdB" 
style="position:absolute; left: 1068px; top: 121px; width: 85px;"
tabindex="<?php echo ++$TI;?>"
value="Filtrar" onclick="fFiltrar();" />


<div id="layer3" 
style="position:absolute; left: 25px; top: 151px; width: 1255px; height: 400px; overflow:auto">
<div align="left" class="f2">

<table id="Exportar_a_Excel" width="1249" height="57" border="1" cellpadding="0" cellspacing="0">

<tr>
<td height="18" colspan="10" bgcolor="#666666" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>

<tr>
<td width="53" height="20" bgcolor="#999999"><span class="eS4">SERIE</span></td>
<td width="75" bgcolor="#999999"><span class="eS4">NUMERO</span></td>
<td width="79" bgcolor="#999999"><span class="eS4">FECHA</span></td>
<td width="483" bgcolor="#999999"><span class="eS4">CLIENTE</span></td>
<td width="111" bgcolor="#999999"><span class="eS4">RUC</span></td>
<td width="75" bgcolor="#999999" align="right"><span class="eS4">TOTAL</span></td>
<td width="85" bgcolor="#999999" align="right"><span class="eS4">TOT. COB</span></td>
<td width="44" bgcolor="#999999" align="right"><span class="eS4" >SALDO</span></td>
<td width="205" bgcolor="#999999" ><span class="eS4" >VENDEDOR</span></td>
<td width="17" bgcolor="#999999">&nbsp;</td>
</tr>

<?php
$T=0;	  		
$C=0;	  		
$S=0;	  		
$ss="SELECT SER,NUM,DATE_FORMAT(FEC,'%d-%m-%y') as F,
SUBSTRING(CLI,1,40) as KLI,RUC,ROUND(TOT_REAL,2) as T,ROUND(TOT_COB,2) as C, ROUND(SALDO,2) as S ,VEN 
FROM $TAB WHERE $FF ORDER BY ID ";
$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
$X1B="<td bgcolor=\"#FFFFFF\" align=\"right\"><span class=\"Estilo5\">";
$X2="</span></td>";
//echo $ss;
$s=PagSql($ss,$LStrPag,$VP_RegXPag,$LStrTR);
$result = grs($s);				
while ($row = $result->fetch_assoc()){
	echo "<tr >";
	echo $X1."'".$row['SER'].$X2;		
	echo $X1."'".$row['NUM'].$X2;		
	echo $X1.$row['F'].$X2;		
	echo $X1.$row['KLI'].$X2;
	echo $X1.$row['RUC'].$X2;
	echo $X1B.NF3($row['T']).$X2;
	echo $X1B.NF3($row['C']).$X2;
	echo $X1B.NF3($row['S']).$X2;
	echo $X1.$row['VEN'].$X2;
	echo $X1."".$X2;	
	echo "</tr>";
	$T=$T + $row['T'];
	$C=$C + $row['C'];
	$S=$S + $row['S'];
}
?>
<tr>
<td bgcolor="#999999">&nbsp;</td>
<td bgcolor="#999999">&nbsp;</td>
<td bgcolor="#999999">&nbsp;</td>
<td bgcolor="#999999">&nbsp;</td>
<td bgcolor="#999999">&nbsp;</td>
<td bgcolor="#999999" align="right"><span class="eS4"><?php echo NF3($T);?></span></td>
<td bgcolor="#999999" align="right"><span class="eS4"><?php echo NF3($C);?></span></td>
<td bgcolor="#999999" align="right"><span class="eS4"><?php echo NF3($S);?></span></td>
<td bgcolor="#999999" align="right"></td>
<td bgcolor="#999999" align="right"></td>
</tr>	  

</table>
</div>
</div>
<div id="layer" style="position:absolute; left: 79px; top: 30px; width: 412px; height: 24px;">
<div align="left" class="Estilo1">PROFORMAS - ESTADO DE CUENTA</div>
</div>
</form>

<form action="ficheroExcel.php" 
method="post" target="_blank" 
id="FormularioExportacion" >
<div 
style="position:absolute; left: 155px; top: 50px; width: 51px; height: 14px;">  
<input name="" type="button" style="height: 23px;"  class="botonExcel" value="Exportar" />
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
</div>
</form>
</div>
</body>
</html>
