<?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']);		
	$StrNum=V($_POST['TxtNum']);		
	$StrDam=V($_POST['TxtDam']);		
	$StrDex=V($_POST['TxtDex']);		
	$StrHax=V($_POST['TxtHax']);		
	$StrTdp=V($_POST['CboTdp']);		
	//
	if(strlen($StrEmp)==0)$StrEmp=GE("S");
	if(strlen($StrAlm)==0)$StrAlm=GA($StrEmp,"S");
	//		
	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");	
	//-------------------------
	$StrEmp_=LIKE($StrEmp);
	$StrAlm_=LIKE($StrAlm);
	$StrCom_=LIKE($StrCom);
	$StrSer_="%".$StrSer;
	$StrNum_="%".$StrNum;
	$StrDam_="%".$StrDam;
	$StrTdp_=substr($StrTdp,0,2);
	$StrDex_=val_dex($StrDex);
	$StrHax_=val_hax($StrHax);
	$StrPro_=$StrPro."%";
	//
	$FF="ID>0 AND EMPC LIKE '$StrEmp_' 
	AND ALMC LIKE '$StrAlm_' 
	AND COM LIKE '$StrCom_' 
	AND SER LIKE '$StrSer_' 
	AND NUM LIKE '$StrNum_' 
	AND DAM LIKE '$StrDam_' 
	AND FEC >= '$StrDex_' 
	AND FEC <= '$StrHax_' 
	AND ANU='N' 
	AND TDP LIKE '$StrTdp_' ";
	
	include("rep_compras_ef_pdf.php");
	//-------------------------
	$LStrTR=gn("count(*)","vcompras",$FF);
	$LStrPag=V($_POST['TxtPag']);	
	if($StrCmd=="F"){$LStrPag="1";}
	$VP_RegXPag=1000;	
	$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
	//
	$TI=0;
?>
<!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 compras entre fechas</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>
$(document).ready(function(){  
   Inicializar();
});
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);
	}
}

function fGenPDF(){
	var emp=gv("CboEmp");
	var alm=gv("CboAlm");
	if(emp=="TODOS"){
		alert("Seleccione una empresa");
		jF("CboEmp");return;
	}
	if(alm=="TODOS"){
		alert("Seleccione un almacen");
		jF("CboAlm");return;
	}
	document.getElementById("TxtAc").value="GEN_PDF_1";
	document.getElementById("Frm").submit();
}
</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();
});
});


$(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:1200px;
	height:600px;
	position:absolute;
	left:50%;
	top:50%;
	background-color:#006699;
	margin:-300px 0 0 -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: #FFFFFF; font-size: 12px; }
.Estilo3 {color: #FFFFFF; font-size: 12px; font-family: Arial, Helvetica, sans-serif;}
.x4 {color: #000099}
.x5 {color: #000000}
#Frm center #DivFRM #layer3 .f2 table tr td {
	color: #000;
	text-align: left;
}

-->
</style>

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

<div id="layer3" style="position:absolute; left: 30px; top: 153px; width: 1157px; ; height: 411px; overflow:auto">
<div align="left" class="f2">
<table id="Exportar_a_Excel" width="1137" height="19" border="1" cellpadding="0" cellspacing="0">

<tr>
<td colspan="8" bgcolor="#999999" height="18px" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>
<tr>
<td width="115" bgcolor="#999999"><span class="x4">EMPRESA</span></td>
<td width="115" bgcolor="#999999"><span class="x4">ALMACEN</span></td>
<td width="125" bgcolor="#999999"><span class="x4">COMPROB.</span></td>
<td width="125" bgcolor="#999999"><span class="x4">SERIE-NUMERO</span></td>
<td width="91" bgcolor="#999999"><span class="x4">FECHA</span></td>
<td width="457" bgcolor="#999999"><span class="x4">PROVEEDOR</span></td>
<td width="93" bgcolor="#999999" 
style="text-align:right"><span class="x4">TOTAL($)</span></td>
</tr>
<?php	
$TOTAL=0;		  		
$s="SELECT ID,ALMC,COM,NUM,DATE_FORMAT(FEC,'%d-%m-%y'),
	SUBSTRING(PROV,1,51) AS PROV,TOT,EMPC,SER
	FROM vcompras 
	WHERE $FF 
	ORDER BY ALM,COM,NUM,FEC,PROV ";		  			
$X1="<td bgcolor=\"#FFFFFF\"><span class=\"x5\">";
$X2="</span></td>";
$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
$result = grs($s);				
while ($row = $result->fetch_row()){
	echo "<tr>";
	echo $X1.$row[7].$X2;
	echo $X1.$row[1].$X2;
	echo $X1.$row[2].$X2;
	echo $X1."'".$row[3]."-".$row[8].$X2;
	echo $X1.$row[4].$X2;
	echo $X1.$row[5].$X2;
	echo "<td bgcolor=\"#FFFFFF\" 
	style=\"text-align:right\"><span class=\"x5\">".NF3($row[6]).$X2;
	echo "</tr>";
	$TOTAL=$TOTAL + $row[6];
}

?>		  
<tr class="x5">
<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF">

</td>
<td bgcolor="#FFFFFF" ></td>
<td bgcolor="#FFFFFF" ></td>
<td bgcolor="#FFFFFF"  style="text-align:right">TOTAL($)</td>
<td  bgcolor="#FFFFFF"   style="text-align:right"><?php echo NF3($TOTAL);?></td>
</tr>

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

<div id="layer" style="position:absolute; left: 116px; top: 30px; width: 412px; height: 24px;">
<div align="left" class="Estilo1">REPORTE DE COMPRAS 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>	

<div style="position:absolute; left:29px; top: 108px; width: 132px;">
<div align="left" class="f2">EMPRESA</div>
</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:29px; top:124px; width: 142px;" 
onchange="EM_OC();"
onkeydown="return SoloTextoEx(event,'CboAlm');" tabindex="<?php echo ++$TI;?>">
<?php 
	echo LE($StrEmp,"S","N"); 
?>
</select>
<div style="position:absolute; left: 182px; top: 108px; width: 132px;">
<div align="left" class="f2">ALMACEN</div>
</div>
<select name="CboAlm" id="CboAlm" 
style="position:absolute; left: 181px; top: 124px; width: 133px;" 
onkeydown="return SoloTextoEx(event,'CboCom');" tabindex="<?php echo ++$TI;?>">
<?php echo LA($StrEmp,$StrAlm,"S","N"); ?>
</select>

<div style="position:absolute; left: 327px; top: 108px; width: 102px;">
<div align="left" class="f2">COMPROBANTE</div>
</div>
<select name="CboCom" id="CboCom" 
style="position:absolute; left: 328px; top: 124px; width: 139px;" 
onkeydown="return SoloTextoEx(event,'TxtSer');" tabindex="<?php echo ++$TI;?>">
<?php
echo FCBO_("com_nombre","comprobantes","com_nombre IN ('FACTURA','BOLETA','CONTENEDOR')",$StrCom,"S","N");
?>
</select>

<div style="position:absolute; left:479px; top: 108px; width: 56px;">
<div align="left" class="f2">SERIE</div>
</div>
<input name="TxtSer" type="text" id="TxtSer" 
style="position:absolute; left:480px; top: 124px; width: 64px;" 
value="<?php echo $StrSer;?>"   
onkeydown="return SoloTextoEx(event,'TxtNum');"
tabindex="<?php echo ++$TI;?>" />


<div style="position:absolute; left: 559px; top: 108px; width: 85px;">
<div align="left" class="f2">NUMERO</div>
</div>
<input name="TxtNum" type="text" id="TxtNum" 
style="position:absolute; left: 558px; top: 124px; width: 88px;" 
value="<?php echo $StrNum;?>"  
onkeydown="return SoloTextoEx(event,'TxtDam');"
tabindex="<?php echo ++$TI;?>" />

<div style="position:absolute; left: 661px; top: 108px; width: 85px;">
<div align="left" class="f2">DAM</div>
</div>
<input name="TxtDam" type="text" id="TxtDam" 
style="position:absolute; left: 661px; top: 124px; width: 120px;" 
value="<?php echo $StrDam;?>"  
onkeydown="return SoloTextoEx(event,'TxtDex');"
tabindex="<?php echo ++$TI;?>" />

<div style="position:absolute; left: 792px; top: 108px; width: 85px;">
<div align="left" class="f2">DESDE</div>
</div>
<input name="TxtDex" type="text" id="TxtDex" 
style="position:absolute; left: 790px; top: 124px; width: 88px;" 
value="<?php echo $StrDex;?>"  
onkeydown="return SoloFec(this,event,'TxtHax');"
tabindex="<?php echo ++$TI;?>" />

<div style="position:absolute; left: 892px; top: 108px; width: 88px;">
<div align="left" class="f2">HASTA</div>
</div>
<input name="TxtHax" type="text" id="TxtHax" 
style="position:absolute; left: 891px; top: 124px; width: 89px;" 
value="<?php echo $StrHax;?>"  
onkeydown="return SoloFec(this,event,'CboTdp');"
tabindex="<?php echo ++$TI;?>" />
<div style="position:absolute; left: 993px; top: 108px; width: 104px;">
<div align="left" class="f2">TIPO DE PAGO</div>
</div>
<select name="CboTdp" id="CboTdp" style="position:absolute; left: 992px; top: 124px; width: 105px;" 
onkeydown="return SoloTextoEx(event,'CmdB');" tabindex="<?php echo ++$TI;?>">
<?php
echo FCBO_("tipp_nombre","tipos_pagos","",$StrTdp,"N","N");
?>
</select>

<input name="CmdB" type="button" id="CmdB"
style="position:absolute; left: 1105px; top: 124px; width: 63px;"
value="Filtrar" onclick="fFiltrar();" tabindex="<?php echo ++$TI;?>" />


<div id="layer5" style="position:absolute; left: 116px; top: 50px; width: 189px;">
<div align="left" class="f2">
<input name="CmdV" type="button" id="CmdV" 
value="Volver" onclick="fVolver('menu.php');" tabindex="<?php echo ++$TI;?>" />

<input name="CmdPDF" type="button" id="CmdPDF" 
value="Generar PDF" onclick="fGenPDF();" 
tabindex="<?php echo ++$TI;?>" />

<input type="hidden" name="TxtAc" id="TxtAc" />
<input name="TxtPag" id="TxtPag" type="hidden" value="<?php echo $LStrPag; ?>" />
</div>
</div>

  
<?php
if(strlen($StrDESCARGAR)>0){
echo "<div id=\"layer51\" 
	  style=\"position:absolute; left: 173px; top: 80px; 
	  width: 90px; background-color: #FFCC00; layer-background-color: #FFCC00; 
	  border: 1px none #000000; height: 17px;\">";
echo "<div align=\"center\" class=\"f2\"> ";
echo " <a href=\"$StrDESCARGAR\" download>Descarga.PDF</a> ";
echo "</div>";
echo "</div>";
}
?>

</form>

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

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