<?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");
include("funciones.php");
$SYS_MSG="";
$SYS_FOC="CboEmp";
$LIS_VENTAS="";
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;
}
//
$M_S=true;
$M_C=true;
//
$ES_CAJERO=0;
$ES_FACTURACION=0;
if(USU_PER_GET_ES_CAJERO()){
	$ES_CAJERO=1;
}
if(USU_PER_GET_ES_FACTURACION()){
	$ES_FACTURACION=1;
}
//-------------------------	++++
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
$LStrPag=V($_POST['TxtPag']);
//
$UZU_KOD=vbval(V($_SESSION['SYS_USER_ID']));
//
$POL_USU_PER_ELI=USU_PER_GET_EX("ELI_COB");
//	
$StrGT="";
$LStrMsg="";
$LStrFoc="";
$LStrMM="";
$REF_COM="";
$REF_KOD=0;
include("cobroz_fun.php");
//-------------------------	
$w="ID>0";
//++
$LStrTR=gn("count(*)","vcobroz",$w);
$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=13;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$LStrFoc="document.getElementById('CboEmp').focus();";
$LStrMsg="onload=\"$LStrFoc;\"";
$TI=1;
?>
<!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>Cobros</title>
<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/funcionez.js"></script>
<script type="text/javascript" src="fe/cobroz6.js"></script>
<script type="text/javascript" src="fe/leo.js"></script>
<script>
$(document).ready(function(){
   $("#TxtFec").mask("99-99-99");
   //
   var pol_usu_per_eli=gv("POL_USU_PER_ELI");
   if(jVal(pol_usu_per_eli)==0){
	   document.getElementById("CmdE").disabled=true;
   }  
   SYS_LOAD(); 
});
function SYS_LOAD(){
	var sys_msg=gv("SYS_MSG");
	var sys_foc=gv("SYS_FOC");
	if(jL(sys_msg)>0){
		alert(sys_msg);
	}
	if(jL(sys_foc)>0){
		jF(sys_foc);
	}
}
function F_PAGAR(cob_id,ven_id){
	var usu_id=jVal(gv("UZU_KOD"));
	var d=AX("COB_VEN_PAGAR",cob_id,ven_id,usu_id);
	var r=d.split("|");
	if(r[1]=="OK"){
		
		return true;
	}else{
		if(r[1]=="MS"){
			alert(r[2]);
		}else{
			alert("Error de conexion");
		}
		return false;
	}
}
</script>
<link rel="stylesheet" type="text/css" href="basic.css"  />
<style type="text/css">
<!--
body {
	background-color: #CCC;
}
#Layer1 {
	position:absolute;
	left:345px;
	top:115px;
	width:123px;
	height:35px;
	z-index:1;
}
.centrarFrm{
     width:1000px;
     height:700px;
     position:absolute;
     left:<?php echo "50%";?>;
     top:<?php echo "50%";?>;
	 background-color:#006699;
	 margin:<?php echo "-350px";?> 0 0 <?php echo "-500px";?>;

}
#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;}
.s4 {color: #000099}
.s5 {color: #000000}
#Frm center #DivFRM #layer .Estilo1 strong {
	color: #900;
}

-->
</style>

</head>
<body >
<form id="Frm" name="Frm" method="post" action="cobroz.php">
<center> 
  <div Id="DivFRM"  class="centrarFrm" >



<div id="layer13" style="position:absolute; left: 30px; top:671px; width: 922px;">
<div align="left" class="f2" >**** SOLO LOS USUARIOS DE CARGO CAJERO PUEDEN REGISTRAR COBROS ****</div>
</div>


<div id="layer" style="position:absolute; left: 116px; top: 21px; width: 412px; height: 45px; z-index: 100;">
<div align="left" class="Estilo1">
<input name="LIS_VENTAS" type="hidden" id="LIS_VENTAS" 
value="<?php echo $LIS_VENTAS;?>"/>

<input name="ES_CAJERO" type="hidden" id="ES_CAJERO" value="<?php echo $ES_CAJERO;?>" />
<input name="ES_FACTURACION" type="hidden" id="ES_FACTURACION" value="<?php echo $ES_FACTURACION;?>" />

<input name="UZU_KOD" type="hidden" id="UZU_KOD" value="<?php echo $UZU_KOD;?>" />
<input name="TxtId" type="hidden" id="TxtId" value="<?php echo $StrId;?>"/>
<input name="POL_USU_PER_ELI" type="hidden" id="POL_USU_PER_ELI" value="<?php echo $POL_USU_PER_ELI;?>"/>
<input name="TxtAc" type="hidden" id="TxtAc" value="" />
<input name="TxtPag" type="hidden" id="TxtPag" value="<?php echo $LStrPag; ?>" />
<input name="FEC_SERVER" type="hidden" id="FEC_SERVER" value="<?php echo date("d-m-y");?>"/> 
<strong>COBROS</strong></div>
</div>
    
    

<div id="LblTit" style="position:absolute; left: 52px; top: 15px; width: 64px; z-index: 100;">
<div align="left" class="Estilo1"><img src="img/marcas.gif" width="48" height="48" /></div>
</div>
<div id="layer8" style="position:absolute; left: 0px; top: 0px; width:1000px; height: 79px; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000; z-index: 0;">
<div align="left" class="Estilo1">        
</div>
</div>


<div id="DivNUM" class="s1" style="left: 30px; top: 114px; width: 266px;">
NUMERO DE COBRO : <?php echo $StrNUM;?>
</div>


<div class="s1" style="left:30px; top: 152px; width: 107px;">
EMPRESA
</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:30px; top:171px; width: 103px;" 
onkeydown="return SoloTextoEx(event,'CboAlm');" 
onchange="EM_OC();" tabindex="<?php echo $TI++;?>">
<?php 
	echo LE($StrEmp,"N","N");
?>
</select>

<div class="s1" style="position:absolute; left: 154px; top: 152px; width: 106px;">
PUNTO EMISION</div>
<select name="CboAlm" id="CboAlm" 
style="left: 149px; top: 171px; width:100px;" 
onkeydown="return SoloTextoEx(event,'TxtFec');" 
tabindex="2" >
<?php
	echo LA($StrEmp,$StrAlm,"N","S");
?>
</select>



<div class="EV" style="left: 266px; top: 152px; width: 88px; color:#FF0">
<u><a onclick="fFecServer('TxtFec')">(dd-mm-yy) +</a></u></div>
<div class="s1" style="left: 266px; top: 136px; width: 87px;">
FECHA</div>
<?php if(strlen($StrFec)==0)$StrFec=date("d-m-y");?>
<input name="TxtFec" type="text" id="TxtFec" 
style="position:absolute; left: 268px; top: 171px; width: 92px; background-color:#CCC" 
value="<?php echo $StrFec;?>"  
onkeydown="return SoloFec(this,event,'CboCom');" 
tabindex="<?php echo $TI++;?>" />


<div class="s1" style="left: 374px; top: 152px; width: 131px;">
COMPROBANTE
</div>
<select name="CboCom" id="CboCom" 
style="position:absolute; left: 376px; top: 171px; width: 126px;" 
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","S","com_nombre");
?>
</select>

<div class="s1" style="left: 517px; top: 152px; width: 75px;">
SERIE
</div>
<input name="TxtSer" type="text" id="TxtSer" 
style="left: 515px; top: 171px; width: 65px;" 
tabindex="<?php echo $TI++;?>" onblur="_S(this);" 
onkeydown="return SoloEnterosEx(this,event,'TxtNum');" 
value="<?php echo $StrSer;?>" maxlength="4" />

<div class="s1" style="left: 595px; top: 152px; width: 110px;">
NUMERO +
</div>
<input name="TxtNum" type="text" id="TxtNum" 
style="left: 598px; top: 171px; width:90px;" 
tabindex="<?php echo $TI++;?>"   onblur="_N(this);" 
onkeydown="return snNum(this,event,'TxtTot');" 
value="<?php echo $StrNum;?>" maxlength="6" />

<div class="s1" style="left: 715px; top: 152px; width: 158px;"> CLIENTE
</div>
<input name="Cli" type="text" id="Cli" 
style="left:715px; top: 171px; width:251px; background-color:#CCC " 
tabindex="<?php echo $TI++;?>"  readonly="readonly"
value="<?php echo $Cli;?>" />



<div class="s1" style="left: 30px; top: 200px; width: 127px;">
TOT. VENTA (S/.)
</div>
<input name="TxtTve" type="text" id="TxtTve" 
style="left:30px; top:219px; width:103px; background-color:#CCCCCC; text-align:right" 
value="<?php echo $StrTve;?>"  
onkeydown="return SoloEnterosEx(this,event,'TxtTot');"
readonly="readonly" 
tabindex="<?php echo $TI++;?>" />

<div class="s1" style="left: 154px; top: 200px; width: 96px;">
TOT. A CUENTA
</div>
<input name="TxtAcu" type="text" id="TxtAcu" 
style="left: 154px; top: 219px; width: 98px; background-color:#CCCCCC; text-align:right" 
value="<?php echo $StrAcu;?>"  
onkeydown="return SoloEnterosEx(this,event,'TxtTot');"
readonly="readonly" 
tabindex="<?php echo $TI++;?>" />

<div class="s1" style="left: 268px; top: 200px; width: 83px;">
TOT. COB.</div>
<input name="TxtTot" type="text" id="TxtTot" 
style="position:absolute; left: 268px; top: 219px; width: 92px; text-align:right" 
value="<?php echo $StrTot;?>"  
onkeydown="return SoloNum(this,event,'CboMod');" 
onkeyup="CalSaldo();"
tabindex="<?php echo $TI++;?>" 
onfocus="selecciona_value(this);"
/>

<div class="s1" style="left: 376px; top: 200px; width: 87px;"> MODALIDAD
</div>
<select name="CboMod" id="CboMod" 
style="width:126px; position:absolute; left: 376px; top: 219px;" 
onkeydown="return SoloTextoEx(event,'TxtObs');" 
tabindex="<?php echo $TI++;?>" 
>
<?php
echo FCBOO_("au_item","auxiliar","au_tab='MODA'",$StrMod,"N","N","au_orden");
?>
</select>

<div class="s1" style="left: 515px; top: 200px; width: 80px;">
SALDO
</div>
<input name="TxtSal" type="text" id="TxtSal" 
style="left: 515px; top: 219px; width: 81px; background-color:#CCCCCC; text-align:right" 
value="<?php echo $StrSal;?>"  
onkeydown="return SoloEnterosEx(this,event,'TxtObs');"
readonly="readonly" 
tabindex="<?php echo $TI++;?>" />


<div id="layer13" style="position:absolute; left: 30px; top: 251px; width: 335px; height: 15px;">
<div align="left" class="f2">COMPROBANTES RELACIONADOS AL COMPROBANTE</div>
</div>

<div class="s1" style="left: 387px; top: 251px; width: 580px;">
TIPO : REG =Regular (venta registrada antes que el cobro) / VPC = <b>V</b>enta registrada <b>P</b>osterior al <b>C</b>obro
</div>
<?php
//++
$REF_URL="";
if($REF_KOD==0){
	$REF_URL="about:blank";
}else{
	$REF_URL="cobroz_ventas.php?REF_COM=".$REF_COM."&REF_KOD=".$REF_KOD."&LECTURA=1&COB_KOD=".vbval($StrId);
}
?>
<div id="layer13" style="position:absolute; left: 30px; top:270px; width: 936px; height: 136px; background-color:#FFF">
<iframe src="<?php echo $REF_URL;?>" id="iFrmVen" frameborder="0" scrolling="no" style="border:none; width:100%; height:135px; margin:0; padding:0; position:absolute; left:0px; top:0px;">
</iframe>
</div>

<div id="layer13" style="position:absolute; left:30px; top: 426px; width: 103px;">
<div align="left" class="f2">OBSERVACION</div>
</div>
<input name="TxtObs" type="text" id="TxtObs"  
style="position:absolute; left:30px; top: 446px; width: 147px;" 
value="<?php echo $StrObs;?>"  
onKeyDown="return SoloTextoEx(event,'TxtKon');" 
tabindex="<?php echo $TI++;?>" />


<div class="s1" style="left: 195px; top: 413px; width: 86px;">
N&ordm; CONTRATO (Opcional)
</div>
<input name="TxtKon" type="text" id="TxtKon" 
style="left: 194px; top: 446px; width: 85px;" 
value="<?php echo $StrKon;?>"  
onkeydown="return SoloEnterosEx(this,event,'Cue');" 
tabindex="<?php echo $TI++;?>" />

<div class="s1" style="left: 292px; top: 426px; width: 252px;"> DEPOSITO - CUENTA
</div>
<?php
if(vbval($StrId)==0){
?>
<select name="Cue" id="Cue" 
style="width:443px; position:absolute; left: 292px; top: 446px;" 
onkeydown="return SoloTextoEx(event,'OpeNro');" 
tabindex="<?php echo $TI++;?>" 
>
<?php
echo FCBO("MI_CUENTA","vis_cuentas_emp","ID_CTA>0",$Cue,"N","S");
?>
</select>
<?php
}else{
	echo "
	<input name='Cue' type='text' id='Cue' readonly='readonly'
	style='width:440px; position:absolute; left: 292px; top: 446px; background-color:#CCCCCC;' 
	value='".$Cue."'  onkeydown='return SoloTextoEx(event,\'OpeNro\');' tabindex='".$TI."'>";
}
?>

<?php
$RO=" readonly='readonly' ";
$CS=" background-color:#CCCCCC ";
if(vbval($StrId)==0){
	$RO="";
	$CS="";
}
?>

<div class="s1" style="left:745px; top: 415px; width: 102px;">
DEPOSITO - Nro OPERACION
</div>
<input name="OpeNro" type="text" id="OpeNro" <?php echo $RO;?>
style="left: 747px; top: 446px; width: 94px;<?php echo $CS;?>" 
value="<?php echo $OpeNro;?>"  
onkeydown="return SoloTextoEx(event,'OpeFec');" 
tabindex="<?php echo $TI++;?>" />


<div class="s1" style="left:854px; top: 415px; width: 105px;">
DEPOSITO - FECHA (dd-mm-yy)</div>
<input name="OpeFec" type="text" id="OpeFec"  <?php echo $RO;?>
style="left: 855px; top: 446px; width: 105px;<?php echo $CS;?>" 
value="<?php echo $OpeFec;?>"  
onkeydown="return SoloFec(this,event,'CmdG');" 
tabindex="<?php echo $TI++;?>" />

<?php
$DIS="";
if(vbval($StrId)==0)$DIS=' disabled="disabled" ';
?>
<script>
function VerPagAsi(){
	var kod=gv("TxtId");
	if(jVal(kod)==0){
		alert("No se puede determinar el id del registro activo");
		return;
	}
	//++
	Ow('cobroz_pagos.php?COB_KOD='+kod,920*ZO(),330*ZO());
}
function SetCuenta(){
	var kod=gv("TxtId");
	if(jVal(kod)==0){
		alert("No se puede determinar el id del registro activo");
		return;
	}
	var es_caj=jVal(gv("ES_CAJERO"));
	var es_fac=jVal(gv("ES_FACTURACION"));
	if(es_caj==1 || es_fac==1){
		Ow('cobroz_asignar_cuenta.php?COB_KOD='+kod,920*ZO(),220*ZO());
	}else{
		alert("Funcion valida solo para usuarios de tipo cajero o facturacion");
	}
}
</script>
<input type="button" name="CmdPagRel" id="CmdPagRel" 
value="Ver pagos asignados" <?php echo $DIS;?> 
onClick="VerPagAsi()" tabindex="15"
style="position:absolute; left: 30px; top: 482px; width: 149px;"
/>

<input type="button" name="CmdSetCue" id="CmdSetCue" 
value="Cambiar / asignar cuenta" <?php echo $DIS;?> 
onClick="SetCuenta()" tabindex="15"
style="position:absolute; left: 752px; top: 482px; width: 215px;"
/>



<div id="layer3" style="position:absolute; left:31px; top: 517px; width: 938px; height: 145px; overflow:auto; background-color:#FFF">
<div align="left" class="f2">
<table width="915" height="19" border="1" cellpadding="0" cellspacing="0">

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

<tr>
<td width="63" bgcolor="#999999" style="color:#000">FECHA</td>
<td width="96" bgcolor="#999999" style="color:#000">COMPROBANTE</td>
<td width="84" bgcolor="#999999" style="color:#000">NUMERO</td>
<td width="46" bgcolor="#999999" style="color:#000">ANU</td>
<td width="281" bgcolor="#999999" style="color:#000">CLIENTE</td>
<td width="72" bgcolor="#999999" style="text-align:right; color:#000">EFECTIVO</td>
<td width="69" bgcolor="#999999" style="text-align:right;color:#000">DEPOSITO</td>
<td width="51" bgcolor="#999999" style="text-align:right; color:#000">SALDO</td>
<td width="54" bgcolor="#999999" style="text-align:right; color:#000">USUARIO</td>
<td width="59" bgcolor="#999999" style="color:#000">VERIFICAR</td>

<td width="16" bgcolor="#999999">&nbsp;</td>
</tr>

<?php

$s="SELECT ID, DATE_FORMAT(FEC,'%d-%m-%y'), COM, CSER, CNUM,
	ROUND(TOT,2), TDP, ROUND(SAL,2), SUBSTRING(CLI,1,40), ANU, USU,REG_VER
	FROM vcobroz
	WHERE $w 
	ORDER BY ID DESC ";

$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);  		  				
$result = grs($s);
while ($row = $result->fetch_row()){
	$TDP=$row[6];
	$EFE="0.0";
	$DEP="0.0";
	if(strlen($row[3])>0 && strlen($row[4])>0 ){
		$_NUM=$row[3]."-".$row[4];
	}else{
		$_NUM=$row[4];
	}
	if($TDP=="EFECTIVO"){
		$EFE=NF3($row[5]);
	}else{
		$DEP=NF3($row[5]);
	}
	if($row[11]=="SI"){
		echo "<tr ondblclick=\"fActivar($row[0]);\" style=\"background-color:#FFFFCC\" >";
	}else{
		echo "<tr ondblclick=\"fActivar($row[0]);\" >";
	}
	echo "<td >	
	<span class=\"s5\">$row[1]</span></td>";
	echo "<td >
	<span class=\"s5\">$row[2]</span></td>";
	echo "<td >
	<span class=\"s5\">$_NUM</span></td>";
	
	echo "<td  style=\"text-align:center\">
	<span class=\"s5\" 
	>".$row[9]."</span></td>";
	
	echo "<td >
	<span class=\"s5\">$row[8]</span></td>";
	echo "<td  style=\"text-align:right\">
	<span class=\"s5\" 
	>".$EFE."</span></td>";
	echo "<td  style=\"text-align:right\" >
	<span class=\"s5\" 
	>".$DEP."</span></td>";
	echo "<td  style=\"text-align:right\">
	<span class=\"s5\" 
	>".NF3($row[7])."</span></td>";
	
	echo "<td  style=\"text-align:center\">
	<span class=\"s5\" 
	>".$row[10]."</span></td>";
	
	echo "<td  style=\"text-align:center\">
	<span class=\"s5\" 
	>".$row[11]."</span></td>";
	
	
	echo "<td  align=\"center\">
	<a href=\"javascript:void(0)\" onclick=\"fActivar($row[0]);\">
	<img src=\"img/b_edit.png\"  border=\"0\"/>
	</a>
	</td>";
	
	echo "</tr>";
}
?>	  

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


<div id="layer4" style="position:absolute; left: 30px; top: 85px; width: 442px; height: 26px;">
      <div align="left" class="f2">
<input name="CmdB" type="button" id="CmdG" value="Guardar" 
<?php
if(strlen($StrId)>0){
	echo " disabled=\"disabled\" ";
}
?>
onclick="fGuardar();" style="width:80px" tabindex="<?php echo $TI++;?>"/>

		<input name="CmdB" type="button" id="CmdC" value="Nuevo" 
        onclick="fCancelar();"  tabindex="<?php echo $TI++;?>"/>
        
		<input name="CmdB" type="button" id="CmdE" value="Eliminar" 
        onclick="flEliminar();"
		<?php
		$CMD_ANU=0;
		if(strlen($StrId)==0){
			$CMD_ANU=1;
			echo "disabled=\"disabled\"";
		}
		if($StrId>0 && $CMD_ANU==0){
			$TMP=gs("cob_anu","cobroz","id_cobro=$StrId");
			if($TMP=="SI"){
				echo " disabled=\"disabled\" ";
			}
		}
		?>
		 tabindex="<?php echo $TI++;?>"/>
         
		<input name="CmdB" type="button" id="CmdA" 
        value="Anular" onclick="flAnular();"
		<?php
		$CMD_ANU=0;
		if(strlen($StrId)==0){
			$CMD_ANU=1;
			echo " disabled=\"disabled\" ";
		}
		if($StrId>0 && $CMD_ANU==0){
			$TMP=gs("cob_anu","cobroz","id_cobro=$StrId");
			if($TMP=="SI"){
				echo " disabled=\"disabled\" ";
			}
		}
		?>
		tabindex="<?php echo $TI++;?>"/>
         
		<input name="CmdB" type="button" id="CmdB" 
value="Buscar" onclick="fBuscar('cobroz_buscar.php');"  tabindex="<?php echo $TI++;?>"/>
<input name="CmdB" type="button" id="CmdZ" 
value="Menu" onclick="fBuscar('menu.php');"  tabindex="<?php echo $TI++;?>"/>
      </div>
    </div>


</div>
</center>
<?php
$TOT_NDC=gn("count(*)","cuentas","id_cta>0 AND cta_mnd='SOLES' AND cta_hab='SI'");
?>
<input name="TOT_NDC" type="hidden" id="TOT_NDC" value="<?php echo $TOT_NDC;?>"/>
<input name="SYS_MSG" type="hidden" id="SYS_MSG" value="<?php echo $SYS_MSG;?>"/>
<input name="SYS_FOC" type="hidden" id="SYS_FOC" value="<?php echo $SYS_FOC;?>"/>
</form>
</body>
</html>
