<?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;
	}
	//+++
	$StrCmd=V($_POST['TxtAc']);
	//+++	
	$StrEmp=V($_POST['CboEmp']);
	$StrAlm=V($_POST['CboAlm']);
	$StrFec=V($_POST['TxtFec']);
	$StrSN=V($_POST['CboSN']);
	$StrAG=V($_POST['CboAG']);
	$Usu=V($_POST['CboUsu']);
	//
	if(strlen($StrEmp)==0)$StrEmp=GE("N");
	if(strlen($StrAlm)==0)$StrAlm="TODOS";
	if(strlen($Usu)==0)$Usu="TODOS";
	/*
	error_reporting(E_ALL);
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	*/
	if($Usu=="TODOS"){
		$UZU=0;
	}else{
		$UZU=gn("id_usuario","usuarios","nom='$Usu'");
	}
	//			
	if(strlen($StrAG)==0){
		$XYZ=gs("valor","valores","dato='AGRUPAR'");
		$StrAG=$XYZ;
	}else{
		ejt("UPDATE valores SET valor='$StrAG' WHERE dato='AGRUPAR'");
	}	
	if(strlen($StrSN)==0)$StrSN="NO";
	if($StrSN=="NO"){
		$StrSN_=substr($StrSN,0,1)."%";
	}else{
		$StrSN_="%";
	}
	if(strlen($StrFec)==0)$StrFec=date("d-m-y");
	$StrEmp_=LIKE($StrEmp);
	$StrAlm_=LIKE($StrAlm);
	$StrFec_=val_dex($StrFec);
	//
	$CX=0;
	ejt("DELETE FROM cobros_temp");
	//PROFORMAS
	$s="SELECT GUIA,IMPORTE,EFE,BAN,SAL,CLI,GI,ANU,ID,ISER,INUM ".
	   "FROM viz_cotizacion_efe_dep_xx
	   WHERE FEC='$StrFec_' AND ( EFE>=0 OR BAN>=0) AND 
	   CAST(ANU AS CHAR) LIKE '$StrSN_' AND EMPC LIKE '$StrEmp_' AND 
	   ALM_NC LIKE '$StrAlm_' ";
	if($UZU>0){
		$s=$s." AND KOD_USU=".$UZU." ";
	}
	$s=$s." ORDER BY ID";
	//echo $s;
	$result = grs($s);	
    while ($row = $result->fetch_assoc()){
		$I_S=$row['ISER'];
		$I_N=$row['INUM'];
		$_ID=$row['ID'];
		$_GI=$row['GI'];
		$_GU=$row['GUIA'];
		$_IM=$row['IMPORTE'];
		$_EF=$row['EFE'];
		$_BA=$row['BAN'];
		$_TR=0;
		$_SA=$row['SAL'];
		$_CL=$row['CLI'];
		$_AN=substr($row['ANU'],0,1);
		if($_AN=="S"){
			$_SA=0;
		}
		$OBS="[A:".NF3($_EF + $_BA)."]";
		$CX++;		
		$s="INSERT INTO cobros_temp ".
		   "VALUES ($CX,'',$_GI,'$_GU',$_IM,$_EF,$_BA,$_TR,
		   $_SA,'$_CL','$OBS','$_AN','P',$_ID,$I_S,$I_N)";
		ejt($s);
		//echo $s;
		
	}
	//FACTURAS/BOLETAS
	$s="SELECT GUIA,IMPORTE,EFE,BAN,SAL,CLI,GI,ANU,ID,ISER,INUM ".
	   "FROM viz_ventas_efe_dep_xx 
	    WHERE FEC='$StrFec_' AND (EFE>=0 OR BAN>=0)  AND 
	    ANU LIKE '$StrSN_'  AND EMPC LIKE '$StrEmp_' AND 
		ALM_NC LIKE '$StrAlm_' ";
	if($UZU>0){
		$s=$s." AND KOD_USU=".$UZU." ";
	}
	$s=$s." ORDER BY ID";
	$result = grs($s);	
    while ($row = $result->fetch_assoc()){
		$I_S=$row['ISER'];
		$I_N=$row['INUM'];
		$_ID=$row['ID'];
		$_GI=$row['GI'];
		$_GU=$row['GUIA'];
		$_IM=$row['IMPORTE'];
		$_EF=$row['EFE'];
		$_BA=$row['BAN'];
		$_TR=0;
		$_SA=$row['SAL'];
		$_CL=$row['CLI'];
		$_AN=substr($row['ANU'],0,1);
		if($_AN=="S"){
			$_SA=0;
		}
		$CX++;
		$s="INSERT INTO cobros_temp ".
		   "VALUES ($CX,'',$_GI,'$_GU',$_IM,$_EF,
		   $_BA,$_TR,$_SA,'$_CL','','$_AN','V',$_ID,$I_S,$I_N)";
		ejt($s);
		
	}
	//COBROS REGULARES
	$s="SELECT GUIA,IMPORTE,EFE,BAN,SAL,CLI,GI,ID_KON,ANU,COM as _C,".
	   "ICSER as _S,ICNUM as _N,NUM ".
	   "FROM vcobroz_dia_xx 
	   WHERE FEC='$StrFec_' AND (EFE>=0 OR BAN>=0)  AND 
	   ANU LIKE '$StrSN_'  AND EMPC LIKE '$StrEmp_' AND 
	   ALM_NC LIKE '$StrAlm_' ";
	if($UZU>0){
		$s=$s." AND KOD_USU=".$UZU." ";
	}
	$s=$s." ORDER BY ID";
	//echo $s;	
	$result = grs($s);	
    while ($row = $result->fetch_assoc()){
		$_AN=substr($row['ANU'],0,1);
		$_NU=$row['NUM'];
		$_GI=$row['GI'];
		$_GU=$row['GUIA'];
		$_IM=$row['IMPORTE'];
		$_EF=$row['EFE'];
		$_BA=$row['BAN'];
		$_TR=0;
		$_SA=$row['SAL'];
		$_CL=$row['CLI'];
		$_KO=$row['ID_KON'];		
		$OBS="";
		if($_KO>0){
			$OBS="[CONTRATO : ".gs("con_numero","contratos","id_contrato=$_KO")."]";
		}
		if($_AN=="S"){
			$_SA=0;
		}
		//INI_METODO_NUEVO
		if($StrAG=="SI"){			
			if($_AN=="N"){
				$_CO_T=substr($row['_C'],0,1);
				$_CO_S=$row['_S'];
				$_CO_N=$row['_N'];			
				if($_CO_T=="P"){
					$_CO_I=gn("id_cotizacion","cotizaciones",
							  "iser=$_CO_S AND inum=$_CO_N");
				}else{
					$_CO_T="V";
					$_CO_I=gn("id_venta","ventas",
					          "iser=$_CO_S AND inum=$_CO_N");
				}				
				//
				$_CX=gn("cx","cobros_temp","com='$_CO_T' AND id=$_CO_I");
				if($_CX>0){
					$OBS="[C:$_NU/".NF3($_EF + $_BA)."]";
					$s="UPDATE cobros_temp SET 
						ef=ef + $_EF,
						ba=ba + $_BA,
						sa=$_SA,
						obs=CONCAT(obs,' ','$OBS') WHERE cx=$_CX";				
					ejt($s);
				}else{			
					$CX++;
					$s="INSERT INTO cobros_temp ".
					   "VALUES ($CX,'',$_GI,'$_GU',$_IM,$_EF,$_BA,$_TR,$_SA,'$_CL','$OBS','$_AN','$_CO_T',$_CO_I,$_CO_S,$_CO_N)";
					ejt($s);
					
				}
			}
		//FIN_METODO_NUEVO
		}else{
		//METODO ANTERIOR
			$CX++;
			$s="INSERT INTO cobros_temp ".
			   "VALUES ($CX,'',$_GI,'$_GU',$_IM,$_EF,$_BA,$_TR,$_SA,'$_CL','$OBS','$_AN','',0,0,0)";
			ejt($s);				
		}
		
	}
	//COBROS TRANSFERENCIA (DEJA/DEVO)
	$s="SELECT GUIA,TOTAL,SALDO,CLI,GI,IMPORTE,DEV_NRO,".
	   "DATE_FORMAT(DEV_FEC,'%d-%m-%y') as D_F,SUBSTRING(DEV_COM,1,1) as X_D,".
	   "DEV_CON_SER as XS,DEV_COM_NUM as XN,DEV_TIPO as TIP,
	    ANU,COM as _C, ISER as _S,INUM as _N,NUM ".
	   "FROM vcobrox_dia_xx 
	   WHERE FEC='$StrFec_' AND TOTAL>=0 AND 
	   ANU LIKE '$StrSN_' AND EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_' ";		
	if($UZU>0){
		$s=$s." AND KOD_USU=".$UZU." ";
	}
	$s=$s." ORDER BY ID";
	$result = grs($s);	
	while ($row = $result->fetch_assoc()){
		$_AN=substr($row['ANU'],0,1);
		$_NU=$row['NUM'];
		$_GI=$row['GI'];
		$_GU=$row['GUIA'];
		$_IM=$row['IMPORTE'];
		$_EF=0;
		$_BA=0;
		$_TR=$row['TOTAL'];
		$_SA=$row['SALDO'];
		$_CL=$row['CLI'];
		$_TI=$row['TIP'];
		if($_TI=="D")$_TI="DEV";
		if($_TI=="J")$_TI="DEJ";
		if($_AN=="S"){
			$_SA=0;
		}
		$_OB=$row['DEV_NRO']." | ".$row['D_F']." | ".$row['X_D'].$row['XS']."-".$row['XN']." | ".$_TI;			
		//INI_METODO_NUEVO
		if($StrAG=="SI"){			
			if($_AN=="N"){
				$_CO_T=substr($row['_C'],0,1);
				$_CO_S=$row['_S'];
				$_CO_N=$row['_N'];
				if($_CO_T=="P"){
					$_CO_I=gn("id_cotizacion","cotizaciones","iser=$_CO_S AND inum=$_CO_N");
				}else{
					$_CO_T="V";
					$_CO_I=gn("id_venta","ventas","iser=$_CO_S AND inum=$_CO_N");
				}					
				$_CX=gn("cx","cobros_temp","com='$_CO_T' AND id=$_CO_I");
				if($_CX>0){
					$OBS="[T:$_NU/".NF3($_TR)."]";
					$s="UPDATE cobros_temp SET 
						tr=tr + $_TR,			
						obs=CONCAT(obs,' ','$OBS'),
						sa=$_SA WHERE cx=$_CX";
	
					ejt($s);
				}else{					
					$CX++;
					$s="INSERT INTO cobros_temp ".
					   "VALUES ($CX,'',$_GI,'$_GU',$_IM,$_EF,$_BA,$_TR,$_SA,'$_CL','$_OB','$_AN','$_CO_T',$_CO_I,$_CO_S,$_CO_N)";
					ejt($s);				
				}
			}
		//FIN_METODO_NUEVO
		}else{
		//METODO ANTERIOR
			$CX++;
			$s="INSERT INTO cobros_temp VALUES ($CX,'',$_GI,'$_GU',$_IM,$_EF,$_BA,$_TR,$_SA,'$_CL','$_OB','$_AN','',0,0,0)";
			ejt($s);			
		}
	}
	//1==1 --PARA IMPORTACIONES LQ
	if(1==1){
		$s="SELECT GUIA,IMPORTE,EFE,BAN,SAL,CLI,GI,ANU,ID ".
		   "FROM viz_contratos_efe_dep_xx 
		   WHERE FEC='$StrFec_' AND ( EFE>=0 OR BAN>=0 ) AND 
		   CAST(ANU AS CHAR) LIKE '$StrSN_' AND EMPC LIKE '$StrEmp_' AND 
		   ALM_NC LIKE '$StrAlm_' ";
		if($UZU>0){
			$s=$s." AND KOD_USU=".$UZU." ";
		}
		$s=$s." ORDER BY ID";
		//echo $s."<br>";
		$result = grs($s);	
		//echo $s."<br>";
		while ($row = $result->fetch_assoc()){
			$_ID=$row['ID'];
			//echo $_ID;
			$_GI=$row['GI'];
			$_GU=$row['GUIA'];
			$_IM=$row['IMPORTE'];
			$_EF=$row['EFE'];
			$_BA=$row['BAN'];
			$_TR=0;
			$_SA=$row['SAL'];
			$_CL=$row['CLI'];
			$_AN=substr($row['ANU'],0,1);
			$CX++;
			$OBS="[ADE:".NF3($_EF + $_BA)."]";
			$s="INSERT INTO cobros_temp VALUES ($CX,'',$_GI,'$_GU',$_IM,$_EF,$_BA,$_TR,$_SA,'$_CL','$OBS','$_AN','C',$_ID,0,0)";
			ejt($s);
			//echo $s."<br>";			
		}
		//
		$s="SELECT GUIA,IMPORTE,EFE,BAN,SAL,CLI,GI,ID_KON,ANU,NUM ".
		   "FROM viz_con_ing_dia_xx 
		    WHERE FEC='$StrFec_' AND (EFE >=0 OR BAN>=0) AND 
		    EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_' ";		
		if($UZU>0){
			$s=$s." AND KOD_USU=".$UZU." ";
		}
		$s=$s." ORDER BY ID";
		//echo $s."<br>";
		$result = grs($s);	
		while ($row = $result->fetch_assoc()){
			$_CO_T="C";
			$_CO_I=$row['ID_KON'];				
			$_NU=$row['NUM'];
			$_GI=$row['GI'];
			$_GU=$row['GUIA'];
			$_IM=$row['IMPORTE'];
			$_EF=$row['EFE'];
			$_BA=$row['BAN'];
			$_TR=0;
			$_SA=$row['SAL'];
			$_CL=$row['CLI'];
			$_KO=$row['ID_KON'];
			$_AN=substr($row['ANU'],0,1);
			$OBS="";
			if($_KO>0){
				$OBS="CONTRATO : ".gs("con_numero","contratos","id_contrato=$_KO");
			}
			//INI_METODO_NUEVO
			if($StrAG=="SI"){				
				$_CX=gn("cx","cobros_temp","com='$_CO_T' AND id=$_CO_I");
				//echo $_CX."@";
				if($_CX>0){
					$OBS="[C:$_NU/".NF3($_EF + $_BA)."]";
					$s="UPDATE cobros_temp SET 
						ef=ef + $_EF,
						ba=ba + $_BA,
						sa=$_SA,
						obs=CONCAT(obs,' ','$OBS') WHERE cx=$_CX";				
					ejt($s);
				}else{
					$OBS="[C:$_NU/".NF3($_EF + $_BA)."]";
					$CX++;
					$s="INSERT INTO cobros_temp VALUES ".
					   "($CX,'',$_GI,'$_GU',$_IM,$_EF,$_BA,$_TR,$_SA,'$_CL','$OBS','$_AN','C',$_KO,0,0)";
					ejt($s);
				}
			//FIN_METODO_NUEVO
			}else{			
			//INI_METODO_ANTERIOR			
				$CX++;
				$s="INSERT INTO cobros_temp VALUES ".
				   "($CX,'',$_GI,'$_GU',$_IM,$_EF,$_BA,$_TR,$_SA,'$_CL','$OBS','$_AN','',0,0,0)";
				ejt($s);
			//FIN_METODO_ANTERIOR			
			}
		}
	}
	//
	//
	//
	//
	//
	//
	//
	//
	//
	//
	$CX=1;
	$s="SELECT * FROM cobros_temp  ORDER BY gi";
	$result = grs($s);
	while ($row = $result->fetch_assoc()){
		$_SA=0;
		$_GI=$row['gi'];
		$_CO=$row['com'];
		$_ID=$row['id'];
		$_IM=$row['im'];
		$_SE=$row['ser'];
		$_NU=$row['num'];
		$_EF=$row['ef'];
		$_BA=$row['ba'];
		$_TR=$row['tr'];
		
		if($StrAG=="SI"){
			if($_CO=="P"){
				$_ADE=gn("SUM(TOT)","viz_cotizacion_efe_dep_xx",
					  "FEC<'$StrFec_' AND ID=$_ID AND ANU='N' AND EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_' ");
				$_COB=gn("SUM(TOT)","vcobroz_dia","FEC<'$StrFec_' AND COM='PROFORMA' AND ICSER=$_SE AND ICNUM=$_NU AND ANU='NO' AND EMPC LIKE '$StrEmp_'");
				$_COT=gn("SUM(TOTAL)","vcobrox_dia_xx",
					  "FEC<'$StrFec_' AND COM='PROFORMA' AND ISER=$_SE AND INUM=$_NU AND ANU='NO' AND EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_' ");
				$_SA=round($_IM - ( ($_ADE+$_COB+$_COT) + ($_EF + $_BA + $_TR) ),2);
				ejt("UPDATE cobros_temp SET cx=$CX,sa=$_SA WHERE gi=$_GI");
			}
			if($_CO=="V"){
				$_ADE=gn("SUM(TOT)","viz_ventas_efe_dep_xx",
					"FEC<'$StrFec_' AND ID=$_ID AND ANU='N' AND EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_' ");
				$_COB=gn("SUM(TOT)","vcobroz_dia_xx",
				      "FEC<'$StrFec_' AND COM<>'PROFORMA' AND ICSER=$_SE AND ICNUM=$_NU AND ANU='NO' AND EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_' ");
				$_COT=gn("SUM(TOTAL)","vcobrox_dia_xx",
					  "FEC<'$StrFec_' AND COM<>'PROFORMA' AND ISER=$_SE AND INUM=$_NU AND ANU='NO' AND EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_' ");
				$_SA=round($_IM - ( ($_ADE+$_COB+$_COT) + ($_EF + $_BA + $_TR) ),2);
				ejt("UPDATE cobros_temp SET cx=$CX,sa=$_SA WHERE gi=$_GI");
			}
			if($_CO=="C"){
				$_ADE=gn("SUM(TOT)","viz_contratos_efe_dep_xx",
					  "FEC<'$StrFec_' AND ID=$_ID AND ANU='N' AND EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_' ");
				$_COB=gn("SUM(TOT)","viz_con_ing_dia_xx",
					  "FEC<'$StrFec_' AND ID_KON=$_ID AND ANU='N' AND EMPC LIKE '$StrEmp_' AND ALM_NC LIKE '$StrAlm_'");			
				$_SA=round($_IM - ( ($_ADE+$_COB) + ($_EF + $_BA + $_TR) ),2);
				ejt("UPDATE cobros_temp SET cx=$CX,sa=$_SA WHERE gi=$_GI");
			}
		}else{
			ejt("UPDATE cobros_temp SET cx=$CX WHERE gi=$_GI");
		}
		
		$CX++;
	}
	
?>
<!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>Reporte - Cobros del dia</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 src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>

<script>
$(document).ready(function(){
   $("#TxtFec").mask("99-99-99"); 
   jFocus("CboEmp");     
});
</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();
});
});
//.filter((_, idx) => idx !== 0 && idx !== totalCols - 1 && idx !== totalCols - 2)
async function exportarExcel() {
	/*
	var tabla = document.getElementById('Exportar_a_Excel');
  	var libro = XLSX.utils.table_to_book(tabla, {sheet:"Hoja1",raw: true});
  	XLSX.writeFile(libro, 'Reporte.xlsx');
	*/
	
	const tablaHTML = document.getElementById("Exportar_a_Excel").outerHTML;

    // Convertimos el HTML a un blob (como si fuera un archivo)
    const blob = new Blob([tablaHTML], { type: "text/html" });

    const formData = new FormData();
    formData.append("archivo", blob, "tabla.html"); // Nombre simulado

    const response = await fetch("exportar.php", {
        method: "POST",
        body: formData
    });

    // Forzamos la descarga del Excel
    const blobRespuesta = await response.blob();
    const url = window.URL.createObjectURL(blobRespuesta);
    const a = document.createElement("a");
    a.href = url;
    a.download = "reporte.xls";
    document.body.appendChild(a);
    a.click();
    a.remove();
	
	
}


</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:1200px;
	height:600px;
	position:absolute;
	left:<?php echo "50%";?>;
	top:<?php echo "50%";?>;
	background-color:#006699;
	margin:<?php echo "-300px";?> 0 0 <?php echo "-600px";?>;
}
#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: #999;
	font-size: 12px;
}
.Estilo3 {color: #FFFFFF; font-size: 12px; font-family: Arial, Helvetica, sans-serif;}
.s4 {
	color: #000099;
	text-align: right;
}
.s5 {color: #000000}

-->
</style>

</head>
<body  <?php echo $StrMsg;?>>
<div Id="DivFRM"  class="centrarFrm" >  
<form id="Frm" name="Frm" method="post" action="rpt_cob_dia.php" onsubmit="return false;">
<center> 
  

<input name="CmdV" type="button" id="CmdV" 
style="position:absolute; left: 116px; top: 50px; width: 60px; "
value="Volver" onclick="fVolver('menu.php');" tabindex="5" />
<input type="hidden" name="TxtAc" id="TxtAc" />

<input name="FEC_SERVER" type="hidden" id="FEC_SERVER" value="<?php echo date("d-m-y");?>"/> 

<div id="layer3" style="position:absolute; left: 23px; top: 152px; width: 1166px; height: 428px; overflow:auto">
<div align="left" class="f2">
<table id="Exportar_a_Excel" width="1149" height="86" border="1" cellpadding="0" cellspacing="0">

<tr>
<td width="105" bgcolor="#999999" style="color:#000">GUIA</td>
<td width="81" bgcolor="#999999" style="color:#000">IMPORTE</td>
<td width="81" bgcolor="#999999" style="color:#000">EFECTIVO</td>
<td width="75" bgcolor="#999999" style="color:#000">BANCO</td>
<td width="78" bgcolor="#999999" style="color:#000">TRANSF.</td>
<td width="91" bgcolor="#999999" style="color:#000">SALDO</td>
<td width="317" bgcolor="#999999" style="color:#000">CLIENTE</td>
<td width="303" bgcolor="#999999" style="color:#000">OBSERVACION</td>
</tr>
<?php	
$TOT_E=0; 				  		
$TOT_B=0; 
$TOT_T=0;				  		
$s="SELECT gu,im,ef,ba,tr,sa,SUBSTRING(cl,1,30) as KL,obs,anu ".
   "FROM cobros_temp ORDER BY cx";
$X1="<td bgcolor=\"#FFFFFF\"><span class=\"s5\">";
$X1B="<td bgcolor=\"#FFFFFF\" align=\"right\"><span style=\"color: #000;\">";
$X2="</span></td>";
$result = grs($s);				
while ($row = $result->fetch_assoc()){
	echo "<tr>";
	if($row['anu']=="S"){
		echo $X1."(".$row['gu'].")".$X2;
	}else{
		echo $X1.$row['gu'].$X2;
	}
	echo $X1B.NF3($row['im']).$X2;
	echo $X1B.NF3($row['ef']).$X2;
	echo $X1B.NF3($row['ba']).$X2;
	echo $X1B.NF3($row['tr']).$X2;					
	echo $X1B.NF3($row['sa']).$X2;					
	echo $X1.$row['KL'].$X2;
	if($row['anu']=="S"){						
		echo $X1."*** ANULADO ***".$X2;					
	}else{
		echo $X1.$row['obs'].$X2;
		$TOT_E=$TOT_E + $row['ef'];
		$TOT_B=$TOT_B + $row['ba'];
		$TOT_T=$TOT_T + $row['tr'];
	}
	echo "</tr>";
}

?>		  
<tr  >
  <td colspan="8" >&nbsp;</td>
  </tr>
<tr  >
<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF"><span style="text-align:right; color: #000;">SUB.TOTAL</span></td>
<td bgcolor="#FFFFFF" align="right" ><span style="color: #000;"><?php echo NF3($TOT_E);?></span></td>
<td bgcolor="#FFFFFF" align="right" ><span style="color: #000;"><?php echo NF3($TOT_B);?></span></td>
<td bgcolor="#FFFFFF"  align="right" ><span style="color: #000;"><?php echo NF3($TOT_T);?></span></td>
<td bgcolor="#FFFFFF" >&nbsp;</td>
<td bgcolor="#FFFFFF" >&nbsp;</td>
<td  bgcolor="#FFFFFF" ></td>
</tr>
<tr  >
  <td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF"><span style="text-align:right; color: #000;">TOTAL</span></td>
<td bgcolor="#FFFFFF" align="right" ><span style="color: #000;"><?php echo NF3($TOT_E + $TOT_B+ $TOT_T);?></span></td>
<td bgcolor="#FFFFFF"  align="right" >&nbsp;</td>
<td bgcolor="#FFFFFF" >&nbsp;</td>
<td bgcolor="#FFFFFF" >&nbsp;</td>
<td bgcolor="#FFFFFF" >&nbsp;</td>
<td  bgcolor="#FFFFFF" >&nbsp;</td>
</tr>

</table>
</div>
</div>
<div id="layer" style="position:absolute; left: 116px; top: 30px; width: 622px; height: 20px;">
<div align="left" class="Estilo1">REPORTE COBROS DEL DIA</div>
</div>
<div id="LblTit" style="position:absolute; left: 57px; top: 25px; width: 64px;">
<div align="left" class="Estilo1"><img src="img/buscar.png" width="57" height="60" /></div>
</div>	
<input name="CmdB" type="button" id="CmdB" 
style="position:absolute; left: 789px; top: 123px; width: 64px;"
value="Filtrar" onclick="fFiltrar();" tabindex="7" />

<input name="Cmdxls" type="button" id="Cmdxls" 
style="position: absolute; left: 856px; top: 123px; width: 64px;"
value="Exportar" onclick="exportarExcel();" tabindex="8" />

<script>
function flFiltrar(){
	var emp=gv("CboEmp");
	if(jL(emp)==0){
		return AF("Seleccione una empresa","CboEmp");
	}
	SM("F");
}
function EM_OC(){
	var Emp=gv("CboEmp");	
	var r=AX("02_22",Emp);
	//alert(r);
	if(r=="X"){
		CBO_CLS("CboAlm",1);
	}else{
		CBO_FILL("CboAlm",r,0);
	}
}
</script>
<div class="s1" style="left:23px; top: 107px; width: 121px;"> EMPRESA
</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:22px; top:123px; width: 126px;" 
onkeydown="return SoloTextoEx(event,'CboAlm');" 
onchange="EM_OC();" tabindex="1">
<?php 
	echo LE($StrEmp,"N","S"); 
?>
</select>

<div class="s1" style="position:absolute; left: 167px; top: 107px; width: 106px;">
PUNTO DE VENTA</div>
<select name="CboAlm" id="CboAlm" 
style="left: 168px; top: 123px; width:120px;" 
onkeydown="return SoloTextoEx(event,'TxtFec');" 
tabindex="2" >
<?php
	echo LA($StrEmp,$StrAlm,"S","N"); 
?>
</select>


<div class="s1" style="left: 308px; top: 91px; width: 45px;">
FECHA</div>
<div class="EV" style="left: 307px; top: 107px; width: 88px; color:#FF0"><u><a onclick="fFecServer('TxtFec')">(dd-mm-yy) +</a></u></div>
<input name="TxtFec" type="text" id="TxtFec" 
style="left: 306px; top: 123px; width: 96px;" value="<?php echo $StrFec;?>"  
onkeydown="return SoloFec(this,event,'CboSN');"
tabindex="3" />

<div class="s1" style="left: 416px; top: 91px; width: 45px;">
INCLUIR REG.ANULADOS</div>
</center>	
<select name="CboSN" id="CboSN" style="position:absolute; left: 415px; top: 123px; width: 108px;"
onkeydown="return SoloTextoEx(event,'CboAG');" tabindex="4"> 
<?php echo FCBO_("au_item","auxiliar","au_tab='SI_NO'",$StrSN,"N","N");?>
</select>

<div class="s1" style="left: 535px; top: 91px; width: 81px;">
AGRUPAR REGISTROS</div>
<select name="CboAG" id="CboAG" style="position:absolute; left: 535px; top: 123px; width: 80px;"
onkeydown="return SoloTextoEx(event,'CboUsu');" tabindex="5"> 
<?php echo FCBO_("au_item","auxiliar","au_tab='SI_NO'",$StrAG,"N","N");?>
</select>

<div class="s1" style="left:631px; top: 107px; width: 141px;"> USUARIO
</div>
<select name="CboUsu" id="CboUsu" 
style="position:absolute; left:626px; top:123px; width: 151px;" 
onkeydown="return SoloTextoEx(event,'CmdB');" tabindex="6">
<?php
	echo FCBO("USU","vis_usuarios_cargos","CAR='CAJERO'",$Usu,"S","N");
?>
</select>



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