<?php
session_start();
?>
<html >
<head>
<?php
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
$REF_COM=trim(V($_GET['REF_COM']));
$REF_KOD=vbval(V($_GET['REF_KOD']));
$COB_KOD=vbval(V($_GET['COB_KOD']));
$LECTURA=vbval(V($_GET['LECTURA']));
$XXX=vbval(V($_GET['XXX']));
//++
$ES_FACTURACION=0;
$ES_CAJERO=0;
if(USU_PER_GET_ES_CAJERO()){
	$ES_CAJERO=1;
}
//++++++
if(USU_PER_GET_ES_FACTURACION()){
	$ES_FACTURACION=1;
}
//++++++++
$COB_ANU="NO";
if($COB_KOD>0){
	$COB_ANU=gs("cob_anu","cobroz","id_cobro=$COB_KOD");
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.tableFixHead          { overflow-y: auto; }
.tableFixHead thead th { position: sticky; top: 0; }

table  {border-collapse:collapse;width:100%;}
th, td {padding: 3px 3px;}
th     {background:#666;}

.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>

</head>
<body style="margin:0 0 0 0; padding:0 0 0 0">
<form id="Frm" style="padding:0 0 0 0; margin:0 0 0 0">
<input name="ES_CAJERO" id="ES_CAJERO" type="hidden" value="<?php echo $ES_CAJERO;?>">
<input name="ES_FACTURACION" id="ES_FACTURACION" type="hidden" value="<?php echo $ES_FACTURACION;?>">
<input name="ANU" id="ANU" type="hidden" value="<?php echo $COB_ANU;?>">
<script>
function jVal(lpStr){
	if(typeof lpStr=='number'){
		return lpStr;
	}
	if(lpStr.trim().length==0){
		return parseFloat("0");
	}else{
		if(isNaN(lpStr)){
			return parseFloat("0");
		}else{
			return parseFloat(lpStr);
		}
	}
}
function UpData(){
	var lis="";
	frm = document.getElementById("Frm");
	if (!frm) return;var mayor=0;	
	for(i=0; i<frm.elements.length; i++){
		var t=frm.elements[i].type;		
		if (t=="checkbox"){
			if(frm.elements[i].checked){
				var id=frm.elements[i].id;
				var da=id.split("_");
				lis=lis+da[1]+"@";
			}
		}		
	}	
	parent.Frm.LIS_VENTAS.value=lis;
}
function fPagar(cob_id,ven_id){
	var es_caj=jVal(document.getElementById("ES_CAJERO").value);
	var es_fac=jVal(document.getElementById("ES_FACTURACION").value);
	var anu=document.getElementById("ANU").value;
	if(es_caj==1 | es_fac==1){
		//OK
	}else{
		alert("Valido solo para usuarios de cargo cajero o facturacion");
		return;
	}
	if(anu=="SI"){
		alert("El cobro se encuentra anulado, no se puede proceder");
		return;
	}
	if(confirm("¿Esta seguro que desea proceder?")){
		if(parent.F_PAGAR(cob_id,ven_id)){
			var td="TD_PAG_"+ven_id;
			var cm="CM_PAG_"+ven_id;
			document.getElementById(td).innerHTML="SI";
			document.getElementById(cm).style.display="none";
			alert("Pago procesado correctamente");
		}
		
	}
}
</script>
<div class="tableFixHead" style="position: absolute; left: 0px; top: 0px; width: 935px; height: 136px; overflow:auto; border:solid 1px #FFFFF">
<table id="Exportar_a_Excel" width="100%" style="font-family:Arial, Helvetica, sans-serif; font-size:11px">
<thead>
<tr>
<th width="13" style="text-align:left; background:#999">#</th>
<th width="141" style="text-align:left; background:#999">COMPROBANTE</th>
<th width="52"  style="text-align:left; background:#999">SERIE</th>
<th width="69"  style="text-align:left; background:#999">NUMERO</th>
<th width="54" style="text-align:left; background:#999">FECHA</th>
<th width="237" style="text-align:left; background:#999">CLIENTE</th>
<th width="77" style="text-align:right; background:#999">TOTAL</th>
<th width="56" style="text-align:right; background:#999">ANULADO</th>
<th width="67" style="text-align:right; background:#999">PAGADO</th>
<th width="59" style="background:#999" align="center">TIPO</th>
<th width="60" align="center" style="background:#999">#</th>
</tr>
</thead>
<tbody>
<?php
$SUM_TOTAL=0;
$CX=0;
$s="SELECT * FROM vis_cot_ven_cob 
	WHERE REF_COM='$REF_COM' AND REF_KOD=$REF_KOD 
	ORDER BY FEC,ID";
$rs=grs($s);				
while($r=$rs->fetch_assoc()){
	$CX++;
	$CSS="";
	if($CX%2==0)$CSS=' style="background-color:#CCCCCC" ';
	$CH="CH_".$r['ID'];
	$SEL="";
	if($r['PAGADO']=="SI")$SEL=" checked ";	
	//
	$TD="TD_PAG_".$r['ID'];
	$CM="CM_PAG_".$r['ID'];
	//++++
	$VEN_ANU=$r['ANU'];
	//+++++++
	$SUM_TOTAL=$SUM_TOTAL + $r['TOT'];
?>	
	<tr <?php echo $CSS;?> >
	<!----------------------------------------------->
    <td><?php echo $CX;?></td>  
	<td><?php echo $r['COM'];?></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"><?php echo NF2($r['TOT'],2);?></td>
    <td align="center"><?php echo $r['ANU'];?></td> 
    <td align="center" id="<?php echo $TD;?>">
    <?php if($LECTURA==0){?>
    	<?php if($r['PAGADO']=="SI"){?>
        	<?php echo $r['PAGADO'];?>
        <?php }else{?>			
            <input name="<?php echo $CH;?>" id="<?php echo $CH;?>" 
            onClick="UpData()" type="checkbox" <?php echo $SEL;?> value="" 
            style="position:inherit">
        <?php } ?>
    <?php }else{ ?>
    	<?php echo $r['PAGADO'];?>
    <?php } ?>
    
    </td> 
    <td align="center"><?php echo $r['MODO'];?></td> 
    <td align="center">
    <?php
	$DIX="";
	if(($r['PAGADO']=="NO" || $r['PAGADO']=="ND") && $XXX==0){
		if($COB_ANU=="SI"){
			$DIX=" disabled ";
		}
		if($VEN_ANU=="S"){
			$DIX=" disabled ";
		}
	?>
    <input name="CmdP" type="button" id="<?php echo $CM;?>"  <?php echo $DIX;?>
    onClick="fPagar('<?php echo $COB_KOD;?>','<?php echo $r['ID'];?>');" value="Pagar">
    <?php
	}
	?>
    </td> 
	<!----------------------------------------------->
	</tr>
<?php
}
?>
<tr >
<td>&nbsp;</td>
<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($SUM_TOTAL,2);?></b></td>
<td align="center">&nbsp;</td>
<td align="center" >&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
	  
</tbody>
</table>
</div>
</form>
</body>
</html>
