<?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;
}
//
//-------------------------
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
//-------------------------
$StrEmp=V($_POST['CboEmp']);		
$StrAlm=V($_POST['CboAlm']);		
$StrCom=V($_POST['CboCom']);		
$StrSer=V($_POST['TxtSer']);		
$StrDex=V($_POST['TxtDex']);
$StrHax=V($_POST['TxtHax']);		
$StrTdp=V($_POST['CboTdp']);
$Mod=V($_POST['Mod']);
//-------------------------
if(strlen($StrDex)==0)$StrDex=date("d-m-y");
if(strlen($StrHax)==0)$StrHax=date("d-m-y");
if(strlen($StrCom)==0) $StrCom="TODOS";
if(strlen($StrTdp)==0) $StrTdp=GetSO("tipp_nombre","tipos_pagos","","tipp_nombre");	
if(strlen($Mod)==0) $Mod="TODOS";
//-------------------------
if(strlen($StrEmp)==0)$StrEmp=GE("S");
if(strlen($StrAlm)==0)$StrAlm=GA($StrEmp,"S");
//-------------------------
$StrEmp_=LIKE($StrEmp);
$StrAlm_=LIKE($StrAlm);
$StrCom_=LIKE($StrCom);
$StrNum_=$StrNum."%";
$StrSer_=$StrSer."%";
if($StrTdp=="TODOS"){
	$StrTdp_="%";
}else{
	$StrTdp_=substr($StrTdp,0,2);
}
$StrDex_=val_dex($StrDex);
$StrHax_=val_hax($StrHax);
$StrPro_=$StrPro."%";
$Mod_=LIKE($Mod);
//-------------------------
$w="ID>0 AND EMPC LIKE '$StrEmp_' 
	AND ALM LIKE '$StrAlm_' 
	AND COM LIKE '$StrCom_' 
	AND NUM LIKE '$StrNum_' 
	AND SER LIKE '$StrSer_' 
	AND FEC >= '$StrDex_' 
	AND FEC <= '$StrHax_' 
	AND ANU='N' AND TDP LIKE '$StrTdp_' 
	AND CLI LIKE '$StrPro_' AND MODAL LIKE '$Mod_' ";

$LStrTR=gn("count(*)","vventas",$w);
$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=2000;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
//
if($StrCmd=="PDF"){	
//
$TI="REPORTE DE VENTAS ENTRE FECHAS :: ALMACEN : $StrAlm";
$s="SELECT COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),CLI,ROUND(TOT,1)
FROM vventas WHERE $w ORDER BY ALM,COM,ISER,INUM,FEC,CLI ";
$T="COMPROBANTE,NUMERO,FECHA,CLIENTE,TOTAL";
$E="12,12, 8,41,9";
$A=" 0, 0, 0,0, 2";		
//
$_ID=GenId("id","reportes");
PDF_TIT($_ID,$TI);
PDF_SQL($_ID,$s);
PDF_CAM($_ID,$T);
PDF_ESP($_ID,$E);
PDF_ANC($_ID,$A);		
$StrFilePDF=PDF_CREATE($_ID);	
//
JsDir($StrFilePDF);
return;			
}

?>
<!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 de ventas del dia</title>
<!--CSS_NEW------------------------------------->
<link rel="stylesheet" type="text/css" href="estiloss.css"  />
<link rel="stylesheet" type="text/css" href="basic.css"  />
<!--CSS_NEW------------------------------------->
<?php AddJs();?>
<script type="text/javascript" src="fe/funcionez.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();
});
});
function EM_OC(){	
	var Emp=gv("CboEmp");	
	var r=AX("03",Emp);
	if(r=="X"){
		CBO_CLS("CboAlm",1);
	}else{
		CBO_FILL("CboAlm",r,0);
	}
}

</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:1100px;
	height:600px;
	position:absolute;
	left:<?php echo "50%";?>;
	top:<?php echo "50%";?>;
	background-color:#006699;
	margin:<?php echo "-300px";?> 0 0 <?php echo "-550px";?>;
}
#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;}
.z4 {color: #000099}
.Estilo5 {color: #000000}

-->
</style>

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

  
<div id="layer5" style="position:absolute; left: 116px; top: 50px; width: 85px; height: 28px;">
<div align="left" class="f2">

<table width="100%" border="0">
<tr>
<td width="67%">
<input name="CmdV" type="button" id="CmdV" 
value="Volver" onclick="fVolver('menu.php');" />
</td>
<td width="33%">
<input name="CmdXls" type="button" id="CmdXls" 
value="Exportar" onclick="ExportarJS()" />
</td>
</tr>
</table>

<script>
function ExportarJS(){
		const bom = "\uFEFF"; // BOM en JavaScript
		const link = document.createElement("a");
		const content = document.getElementById("DIV_XLS").innerHTML;
		const file = new Blob([bom + content], { type: 'application/vnd.ms-excel;charset=utf-8;' });
		link.href = URL.createObjectURL(file);
		link.download = "reporte.xls";
		link.click();
		URL.revokeObjectURL(link.href);
}

</script>


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

<div id="layer3" style="position:absolute; left: 40px; top: 147px; width: 1049px; height: 428px; overflow:auto">
<div align="left" class="f2" id="DIV_XLS">
<table id="Exportar_a_Excel" width="1026" height="19" border="1" cellpadding="0" cellspacing="0">

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

<tr>
<td width="123" bgcolor="#999999"><span class="z4">EMPRESA / ALMACEN</span></td>
<td width="96" bgcolor="#999999"><span class="z4">COMPROB.</span></td>
<td width="86" bgcolor="#999999"><span class="z4">NUMERO</span></td>
<td width="77" bgcolor="#999999"><span class="z4">FECHA</span></td>
<td width="353" bgcolor="#999999"><span class="z4">CLIENTE</span></td>
<td width="87" bgcolor="#999999" 
style="text-align:right"><span class="z4">TOTAL</span></td>
<td width="85" bgcolor="#999999"><span class="z4">T.PAGO</span></td>
<td width="101" bgcolor="#999999"><span class="z4">MODALIDAD</span></td>
</tr>

<?php	
$TOTAL=0; 				  	
$s="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),
DATE_FORMAT(FEC,'%d-%m-%y'),SUBSTRING(CLI,1,42) AS CLI,TOT,EMPC,TDP_,MODAL
FROM vventas 
WHERE $w
ORDER BY ALM,COM,ISER,INUM,FEC,CLI ";

$X1="<td bgcolor=\"#FFFFFF\" style=\"white-space: nowrap;\"><span class=\"Estilo5\">";
$X2="</span></td>";
$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
$result = grs($s);				
while ($row = $result->fetch_row()){
echo "<tr>";
echo $X1.$row[7]." / ".$row[1].$X2;
echo $X1.$row[2].$X2;
echo $X1."'".$row[3].$X2;
echo $X1."'".$row[4].$X2;
echo $X1.$row[5].$X2;
echo "<td bgcolor=\"#FFFFFF\" 
style=\"text-align:right\">
<span class=\"Estilo5\">".NF3($row[6]).$X2;	
echo $X1.$row[8].$X2;
echo $X1.$row[9].$X2;				
echo "</tr>";

$TOTAL=$TOTAL + $row[6];
}

?>		  
<tr  >

<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF" >&nbsp;</td>
<td bgcolor="#FFFFFF" >&nbsp;</td>
<td bgcolor="#FFFFFF" style="text-align:right; color: #000;">TOTAL</td>
<td  bgcolor="#FFFFFF" style="text-align:right; color: #000;" ><?php echo NF3($TOTAL);?></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 DE VENTAS ENTRE FECHAS</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: 905px; top: 118px; width: 68px;"
value="Filtrar" onclick="fFiltrar();" />






<div id="layer14" style="position:absolute; left:38px; top: 103px; width: 102px;">
<div align="left" class="f2">EMPRESAS</div>
</div>

<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:38px; top:118px; width: 128px;" 
onchange="EM_OC();"
onkeydown="return SoloTextoEx(event,'CboAlm');" tabindex="1">
<?php 
	echo LE($StrEmp,"S","N"); 
?>
</select>

<div id="layer14" style="position:absolute; left: 174px; top: 103px; width: 102px;">
<div align="left" class="f2">ALMACEN</div>
</div>
<select name="CboAlm" id="CboAlm"  tabindex="2"
style="position:absolute; left: 172px; top: 118px; width: 110px;" 
onkeydown="return SoloTextoEx(event,'CboCom');">
<?php
	echo LA($StrEmp,$StrAlm,"S","N");
?>
</select>

<div id="layer13" style="position:absolute; left: 294px; top: 103px; width: 102px;">
<div align="left" class="f2">COMPROBANTE</div>
</div>
<select name="CboCom" id="CboCom"  tabindex="3"
style="position:absolute; left: 293px; top: 118px; width: 126px;" 
onkeydown="return SoloTextoEx(event,'TxtSer');">
<?php
echo FCBO_("com_nombre","comprobantes","id_comprobante>0",$StrCom,"S","N");
?>
</select>

<div id="layer15" style="position:absolute; left: 433px; top: 103px; width: 46px;">
<div align="left" class="f2">SERIE</div>
</div>
<input name="TxtSer" type="text" id="TxtSer" 
style="position:absolute; left: 431px; top: 118px; width: 71px;" 
onblur="_S(this);"
value="<?php echo $StrSer;?>"   maxlength="4"
onkeydown="return SoloTextoEx(event,'TxtDex');"
tabindex="4" />


<div id="layer7" style="position:absolute; left: 516px; top: 87px; width: 45px;">
<div align="left" class="f2">DESDE</div>
</div>
<div class="EV" style="left: 514px; top: 102px; width: 88px; color:#FF0">
<u><a onclick="fFecServer('TxtDex')">(dd-mm-yy) +</a></u></div>
<input name="TxtDex" type="text" id="TxtDex" 
style="position:absolute; left: 514px; top: 118px; width: 69px;" value="<?php echo $StrDex;?>"  
onkeydown="return SoloFec(this,event,'TxtHax');"
tabindex="5" />


<div id="layer6" style="position:absolute; left: 599px; top: 87px; width: 66px;">
<div align="left" class="f2">HASTA</div>
</div>
<div class="EV" style="left: 595px; top: 102px; width: 88px; color:#FF0"><u><a onclick="fFecServer('TxtHax')">(dd-mm-yy) +</a></u></div>
<input name="TxtHax" type="text" id="TxtHax" 
style="position:absolute; left: 596px; top: 118px; width: 73px;" value="<?php echo $StrHax;?>"  
onkeydown="return SoloFec(this,event,'CboTdp');"
tabindex="6" />


<div id="layer2" style="position:absolute; left: 685px; top: 103px; width: 87px;">
<div align="left" class="f2">TIPO DE PAGO</div>
</div>
<select name="CboTdp" id="CboTdp" style="position:absolute; left: 682px; top: 118px; width: 90px;" 
onkeydown="return SoloTextoEx(event,'Mod');" tabindex="7">
<?php
	echo FCBO_("tipp_nombre","tipos_pagos",
	       "tipp_nombre IN ('CONTADO','CREDITO')",$StrTdp,"S","N");
?>
</select>


<div id="layer2" style="position:absolute; left: 787px; top: 103px; width: 120px;">
<div align="left" class="f2">MODALIDAD</div>
</div>
<select name="Mod" id="Mod" style="position:absolute; left: 786px; top: 118px; width: 107px;" 
onkeydown="return SoloTextoEx(event,'CmdB');" tabindex="7">
<?php
	echo FCBOO_("au_item","auxiliar","au_tab='MODA'",$Mod,"S","N","au_orden");
?>
</select>




        <input name="CmdB" type="button" id="CmdB"
style="position:absolute; left: 979px; top: 118px; width: 85px;"
 value="Imprimir" onclick="fPDF();" />

  

</form>

<form action="ficheroExcel.php" method="post" target="_blank" id="FormularioExportacion" >
<div style="position:absolute; left: 189px; top: 50px; width: 45px; height: 15px; display:none">  
<input name="" type="button" class="botonExcel" value="Exportar" />
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
</div>
</form>

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