<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//-------------------------	
$StrGT="";
$VP_RegXPag=10;
$LStrMsg="";
$LStrFoc="";
$LStrMM="";
$LStrPag=V($_POST['TxtPag']);
$StrHW=$_SESSION['SYS_HW'];
//$LStrTR=gn("count(*)","marcas","");
include("clientes_edc_fun.php");

$IdUsu=$_SESSION['SYS_USER_ID'];
$AT=gs("at","usuarios","id_usuario=$IdUsu");
?>

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Clientes - Estado de Cuenta</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>
<script type="text/javascript" src="ja/clientes_edc.js"></script>
<!--FIN_SCRIPT------------------------------------->
<link rel="stylesheet" type="text/css" href="css/estiloss.css"  />
<link rel="stylesheet" type="text/css" href="css/basic.css"  />
<link rel="stylesheet" type="text/css" href="css/mnu.css"  />
<style type="text/css">
.cF {height:600px;width:1250px;position:relative;top:0px}
.mM {height:34px;width:1250px;position:relative;top:0px;background-color:#09C; z-index:500;}

</style>
<script>
$(document).ready(function(){  
   Inicializar();
});


function fSelVen(){
	var IdC=document.getElementById("TxtIdPro").value;	
	var Mon=document.getElementById("CboMon").value;
	var Cli=document.getElementById("TxtPro").value;
	if(jLen(Cli)==0){
		alert("Seleccione un cliente");
		jFocus("TxtPro");
		return true;
	}		
	if(jLen(IdC)==0){
		alert("No se puede determinar el id del cliente, seleccione un cliente nuevamente");
		jFocus("TxtPro");
		return true;
	}
	if(jLen(Mon)==0){
		alert("Seleccione la moneda correspondiente");
		jFocus("CboMon");
		return true;
	}
	
	OpenWin('clientes_edc_sel_ventas.php?C='+IdC+"&M="+Mon,600,600);
}

</script>
</head>

<body  <?php echo $LStrMsg;?>>
<div align="center">

<div class="mM" align="left" style="font-size:12px">
<?php
$HTM=file_get_contents("http://inversionessounduniversal.com/ventas/phpmnu.php?USER_ID=$IdUsu");
echo $HTM;
?>
</div>

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;">
<form id="Frm" name="Frm" method="post" action="clientes_edc.php" style="margin:0px; padding:0px; display:inline;" onSubmit="return false;">

<!--INI_TITULO--------------------------------->
<div id="DivT" class="dT" >
<img src="img/pagos.png" class="iT" />
<div class="tT">EST. DE CUENTA CLIENTES</div>
</div>
<!--FIN_TITULO--------------------------------->

<div class="s1" style="position:absolute; left: 430px; top: 170px; width: 377px; font-size:14px">
COMPROBANTES DE VENTA A CANCELAR</div>


<div class="s1" style="left: 30px; top: 126px; width: 79px;">ALMACEN</div>
<select name="CboAlm" id="CboAlm" 
class="lt" style="position: absolute; left: 30px; top: 143px; width: 181px;"
tabindex="<?php echo ++$TI;?>">
<?php echo ListALM($StrAlm); ?>
</select>

<div class="s1" style="left: 223px; top: 126px; width: 67px;">FECHA</div>
<input name="TxtFec" type="text" id="TxtFec" 
class="fe" style="position: absolute; left: 221px; top: 143px; width: 71px;" 
value="<?php echo $StrFec;?>" 
tabindex="<?php echo ++$TI;?>"  maxlength="8" />

<div class="s1" style="position: absolute; left: 302px; top: 126px; width: 199px;">CLIENTE</div>
<input name="TxtPro" type="text" id="TxtPro" 
class="roi" style="position: absolute; left: 299px; top: 143px; width: 382px;"
value="<?php echo $StrPro;?>"  
tabindex="<?php echo ++$TI;?>"/>

<input type="button" name="CmdSel" id="CmdSel" style="position: absolute; left: 688px; top: 143px; width: 30px;"
value="..." onClick="OpenWin('clientes_edc_seleccionar.php',800,600)" 
<?php if(strlen($StrId)>0){echo "disabled=\"disabled\"";}?>
tatabindex="<?php echo ++$TI;?>"/>

<input type="button" name="CmdCls" id="CmdCls" style="position: absolute; left: 723px; top: 143px; width: 29px;"
value="X" onClick="fCls();" 
<?php if(strlen($StrId)>0){echo "disabled=\"disabled\"";}?>
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 760px; top: 126px; width: 65px;">MONEDA</div>
<select name="CboMon" id="CboMon" 
class="lt" style="position: absolute; left: 756px; top: 143px; width: 92px;"
onchange="fGetSaldoDol(document.getElementById('TxtIdPro').value,this.value);"
tabindex="<?php echo ++$TI;?>">
<?php //echo FCBO_("mon_nombre","monedas","mon_nombre IN ('SOLES','DOLARES')",$StrMon,"N","S");?>
<?php echo FCBOO_("mon_nombre","monedas","id_moneda<>'X'",$StrMon,"N","N","mon_nombre DESC")?> 

</select>

<div class="s1" style="left: 854px; top: 126px; width: 63px;">SALDO</div>
<div id="layer25" style="position: absolute; left: 856px; top: 144px; width: 76px; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000; height: 16px;">
<div id="DivSaldo" align="right" class="Est2" style="color:#00F; z-index:2">
<?php echo $StrSaldo;?>
</div>
</div>

<div class="s1" style="left: 947px; top: 126px; width: 54px;">TOTAL</div>
<input name="TxtTot" type="text" id="TxtTot" 
class="lt" style="position: absolute; left: 945px; top: 143px; width: 75px; text-align: right;"
value="<?php echo $StrTot;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 30px; top: 187px; width: 110px;">FORMA DE PAGO</div>
<select name="CboFdp" id="CboFdp"  
class="lt" style="position:absolute; left: 30px; top: 205px; width: 151px;" 
onchange="fFormaDePago();"
tabindex="<?php echo ++$TI;?>">
<?php echo FCBOO("nombre","fpagos","id_fpago>0",$StrFdp,"N","S","id_fpago");?>
</select>

<div class="s1" style="left: 197px; top: 187px; width: 127px;">NUMERO DE PAGO</div>
<input name="TxtNdp" type="text" id="TxtNdp" 
class="lt" style="position:absolute; left: 196px; top: 205px; width: 107px;" 
value="<?php echo $StrNdp;?>"  
tabindex="<?php echo ++$TI;?>"  
<?php
	if(strlen($StrId)==0){
		echo " readonly=\"readonly\" ";
	}else{
		if($StrFdp=="EFECTIVO"){
			echo " readonly=\"readonly\" ";
		}
	}
?>
/>

<div class="s1" style="left: 312px; top: 187px; width: 95px;">FECHA VCTO</div>
<input name="TxtFecVen" type="text" id="TxtFecVen" 
class="lt" style="position:absolute; left: 312px; top: 205px; width: 85px;" 
value="<?php echo  $StrFecVen;?>"  
tabindex="<?php echo ++$TI;?>" 
<?php
	if(strlen($StrId)==0){
		echo " readonly=\"readonly\" ";
	}else{
		if($StrFdp=="EFECTIVO"){
			echo " readonly=\"readonly\" ";
		}
	}
?>
/>

<div class="s1" style="left: 430px; top: 187px; width: 105px; height: 19px;">COMPROBANTE</div>
<select name="CboCom" id="CboCom" 
class="lt" style="position:absolute; left: 430px; top: 205px; width: 121px;"
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("com_nombre","comprobantes","id_comprobante>0",$StrCom,"N","S");?>
</select>

<div class="s1" style="left: 558px; top: 187px; width: 47px;">SERIE</div>
<input name="TxtSer" type="text" id="TxtSer" 
class="lt" style="position:absolute; left: 558px; top: 205px; width: 51px;"
value="<?php echo $StrSer;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 618px; top:187px; width: 66px;">NUMERO +</div>
<input name="TxtNum" type="text" id="TxtNum" 
class="lt" style="position:absolute; left: 617px; top: 205px; width: 99px;"
value="<?php echo $StrNum;?>"  
onkeydown="return GetTOT(event,'CmdAdd');" 
tabindex="13" />

<div class="s1" style="left: 726px; top:187px; width: 66px;">TOTAL</div>
<input name="TxtTOT" type="text" id="TxtTOT" 
class="roi" style="position:absolute; left: 723px; top: 205px; width: 72px; text-align:right;"
value="<?php echo $StrTOT;?>"  
tabindex="<?php echo ++$TI;?>"/>

<input type="button" name="CmdAdd" id="CmdAdd"  style="position:absolute; left: 803px; top: 205px; width: 31px;"
value="+" onClick="fAdd();" 
tabindex="<?php echo ++$TI;?>"
<?php if(strlen($StrId)>0){echo " disabled=\"disabled\"	";}?>
/>

<input type="button" name="CmdSelVen" id="CmdSelVen" style="position:absolute; left: 841px; top: 205px; width: 31px;" 
value="..." onClick="fSelVen();" 
tabindex="<?php echo ++$TI;?>"
<?php if(strlen($StrId)>0){	echo " disabled=\"disabled\"	";}?>
/>

<div class="s1" style="left: 30px; top: 241px; width: 110px;">BANCO</div>
<select name="CboBan" id="CboBan" 
class="lt" style="position:absolute; left: 30px; top: 259px; width: 368px;" 
tabindex="<?php echo ++$TI;?>"
<?php
	if(strlen($StrId)==0 ){
		if($StrFdp=="EFECTIVO"){
			echo " disabled=\"disabled\" ";
		}
	}else{
		if($StrFdp=="EFECTIVO"){
			echo " disabled=\"disabled\" ";
		}
	}
?>

>
<?php
echo FCBOO("ban_nombre","bancos","id_banco>0",$StrBan,"N","S","ban_nombre");
?>
</select>

<!--INI_BOTONES-------------------------------->
<div id="DivBtn" align="left" style="position:absolute; left: 33px; top: 71px; width:1000px; height: 26px;">
<input name="CmdB" type="button" id="CmdG" class="btm" 
<?php GOM($StrId);?>
onclick="fGuardar();"  
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" id="CmdC"  class="btm" 
value="Nuevo" onClick="fCancelar();"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdE" class="btm" 
value="Eliminar" onClick="fEliminar();"
<?php DIS($StrId);?>
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdB" class="btm"
value="Buscar" onClick="fBuscar('clientes_edc_buscar.php');"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdZ" class="btm"
value="Est.Cuenta" onClick="fBuscar('cobros_historial.php');"  
tabindex="<?php echo ++$TI;?>"/>
 
</div>
<!--FIN_BOTONES-------------------------------->

<input type="button" name="CmdLoad" id="CmdLoad" value="Load" 
onclick="fLoad();" 
style="position:absolute; left: 823px; top: 173px; width: 49px;visibility:hidden "
tabindex="3" 
/>



<div class="datagrid" style="position: absolute; left: 430px; top: 237px; width: 590px; height: 302px; overflow: auto">
<table width="100%">
<thead>
<tr>
<td colspan="10" height="18" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>
<tr>
<th width="92">FECHA</th>
<th width="219">COMPROBANTE</th>
<th width="79">SERIE</th>
<th width="89">NUMERO</th>
<th width="68">TOTAL</th>
<th width="26">&nbsp;</th>
</tr>
</thead>
<tbody>


<?php
$cx=0;
$TOT=0;
$s="SELECT IT,DATE_FORMAT(FEC,'%d-%m-%y'),COM,".
"SER,NUM,TOT  ".
"FROM vis_cobros_ventas_temp WHERE HW='$StrHW' ORDER BY IT";
$result = grs($s);
while ($row = $result->fetch_row()){
	$cx=$cx+1;	
	$it=$row[0];
	$fe=$row[1];
	$co=$row[2];
	$se=$row[3];
	$nu=$row[4];
	$to=NF2($row[5],2);
	$TOT=$TOT+$row[5];
?>
<tr>
<td bgcolor="#FFFFFF"><span class="Est5"><?php echo $fe;?></span></td>
<td bgcolor="#FFFFFF"><span class="Est5"><?php echo $co;?></span></td>
<td bgcolor="#FFFFFF"><span class="Est5"><?php echo $se;?></span></td>
<td bgcolor="#FFFFFF"><span class="Est5"><?php echo $nu;?></span></td>
<td bgcolor="#FFFFFF" align="right"><span class="Est5"><?php echo $to;?></span></td>
<td width="26" bgcolor="#FFFFFF" align="center">
<?php
	if(strlen($StrId)==0){
		echo "<a href=\"javascript:void(0)\" ";
		echo "onclick=\"fKiller(".$it.");\" >";
		echo "<img src=\"img/eliminar.png\" />";
		echo "</a>";
	}
?>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" bgcolor="#FFFFFF" align="right"><span class="Est5">TOTAL</span></td>
<td bgcolor="#FFFFFF" align="right"><span class="Est5">
<?php echo NF2($TOT,2);?>
</span></td>
<td bgcolor="#FFFFFF" align="center">&nbsp;</td>
</tr>

</tbody>
</table>
</div>













<div id="layer21" style="position:absolute; left: 149px; top: 369px; width: 152px; height: 25px;">
<div align="left" class="Est2">
<?php
if(strlen($StrId)>0  && $StrFdp!="EFECTIVO"){
if(strlen($StrFecPag)==0){
echo "<input type=\"button\" name=\"CmdPagar\" ";
echo "id=\"CmdPagar\" value=\"Pagar\" onclick=\"fPagar();\"  style=\"width:150px\"/>";
}else{
echo "<input type=\"button\" name=\"CmdPagar\" ";
echo "id=\"CmdPagar\" value=\"Deshacer pago\" ";
echo "onclick=\"fDeshacer();\"  style=\"width:150px\"/>";
}
}
?>
</div>
</div>
<?php
if(strlen($StrId)>0  && $StrFdp!="EFECTIVO"){
echo "<div class=\"Est2\" align=\"left\"";
echo "style=\"position:absolute; left: 37px; top: 241px; width: 108px;\">";
echo "FECHA DE PAGO";
echo "</div>";

}
?>
<div id="layer23" style="position:absolute; left: 37px; top: 368px; width: 101px; height: 25px;">
<?php
if(strlen($StrId)>0 && $StrFdp!="EFECTIVO"){
if(strlen($StrFecPag)==0){
echo "<input name=\"TxtFecPag\" type=\"text\" id=\"TxtFecPag\" ";
echo "style=\"width:100px\" ";
echo "value=\"\"  ";
echo "onkeydown=\"return SoloFec(this,event,'CmdPagar');\" ";
echo "tabindex=\"1\" />";
}else{
echo "<input name=\"TxtFecPag\" type=\"text\" id=\"TxtFecPag\" ";
echo "style=\"width:100px\" ";
echo "value=\"$StrFecPag\"  ";
echo "onkeydown=\"return SoloFec(this,event,'CmdPagar');\" ";
echo "tabindex=\"1\" readonly=\"readonly\" />";

}
}
?>
</div>


<div style="position: absolute; left: 854px; top: 143px; width: 82px; border-style: solid; border-width: 1px; height: 20px; background-color: #FFFFFF; layer-background-color: #FFFFFF">
</div>

<?php
	$StrSaldo="0.00";
	if(strlen($StrId)==0){
		if($StrMon=="SOLES"){			
			$TOT=gn("SUM(tot)","ventas",
					  "id_cliente=$StrIdPro AND 
					  anu='N' AND id_tip_pag='CR' AND mon='S'");
			$PAE=gn("SUM(total)","cobros","id_cliente=$StrIdPro AND anu='N' AND mon='S'");
			$StrSaldo=round($TOT - $PAE,2);			
		}else{
			$TOT=gn("SUM(tot)","ventas",
					  "id_cliente=$StrIdPro AND 
					  anu='N' AND id_tip_pag='CR' AND mon='D'");
			$PAE=gn("SUM(total)","cobros","id_cliente=$StrIdPro AND anu='N' AND mon='D'");
			$StrSaldo=round($TOT - $PAE,2);						
		}
	}
?>



<!--INI_OCULTOS-------------------------------->
<?php include("ocultos.php");?>
<!--FIN_OCULTOS-------------------------------->
<input name="TxtKill" type="hidden" id="TxtKill" value="" />
<input type="hidden" name="TxtIdPro" id="TxtIdPro" value="<?php echo $StrIdPro;?>" />

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