<?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']);			
	$StrPro=V($_POST['TxtPro']);
	$StrSN=V($_POST['CboSN']);			
	$StrDes=V($_POST['TxtDes']);		
	$StrMar=V($_POST['TxtMar']);			
	$StrET=V($_POST['CboET']);
	$StrCod=V($_POST['TxtCod']);
	//
	if(strlen($StrEmp)==0)$StrEmp=GE("S");
	if(strlen($StrAlm)==0)$StrAlm=GA($StrEmp,"S");
	//
	if(strlen($StrCom)==0) $StrCom="TODOS";	
	if(strlen($StrSN)==0)$StrSN="NO";
	if(strlen($StrET)==0)$StrET="NO";
	$StrSN_=substr($StrSN,0,1);	
	$StrET_=$StrET;
	//-------------------------
	$StrEmp_=LIKE($StrEmp);
	$StrAlm_=LIKE($StrAlm);
	$StrCom_=LIKE($StrCom);
	$StrSer_="%".$StrSer;
	$StrNum_="%".$StrNum;
	$StrDam_=$StrDam."%";
	$StrDex_=val_dex($StrDex);
	$StrHax_=val_hax($StrHax);
	$StrPro_=$StrPro."%";
	$StrCod_=$StrCod."%";
	$StrDes_=$StrDes."%";
	$StrMar_=$StrMar."%";	
	//--------------------------
	$FF="ID>0 AND EMPC LIKE '$StrEmp_' AND ALMC LIKE '$StrAlm_' AND 
		 COM LIKE '$StrCom_' AND SER LIKE '$StrSer_' AND 
		 NUM LIKE '$StrNum_' AND FEC >= '$StrDex_' AND 
		 FEC <= '$StrHax_' AND PROV LIKE '$StrPro_' AND 
		 ANU LIKE '$StrSN_' AND DES LIKE '$StrDes_' AND 
		 LINEA LIKE '$StrMar_' AND ET LIKE '$StrET_' AND 
		 COD LIKE '$StrCod_' AND DAM LIKE '$StrDam_'";
	include("compras_pdf.php");
	$LStrTR=gn("count(*)","vcompras_det",$FF);
	$LStrPag=V($_POST['TxtPag']);	
	if($StrCmd=="F"){$LStrPag="1";}
	$VP_RegXPag=1000;	
	$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
	//
	$LStrFoc="document.getElementById('CboEmp').focus();";
	$LStrMsg="onload=\"$LStrFoc;\"";
	$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>Compras - Buscar- Detallado</title>
<?php AddJs();?>
<script type="text/javascript" src="fe/funcionez.js"></script>
<script>
$(document).ready(function(){  
   Inicializar();
});
//--------------------
function fGenPDF(PDF){
	var emp=gv("CboEmp");
	var alm=gv("CboAlm");
	if(emp=="TODOS"){
		alert("Seleccione una empresa");
		jF("CboEmp");return;
	}
	if(emp=="TODOS"){
		alert("Seleccione un almacen");
		jF("CboAlm");return;
	}
	document.getElementById("TxtAc").value=PDF;
	document.getElementById("Frm").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);
	}
}
$(document).ready(function(){
   $("#TxtDex").mask("99-99-99");    
   $("#TxtHax").mask("99-99-99");    
});
</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();
});
});
</script>
<!--CSS_NEW------------------------------------->
<link rel="stylesheet" type="text/css" href="estiloss.css"  />
<link rel="stylesheet" type="text/css" href="basic.css"  />
<!--CSS_NEW------------------------------------->
<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;
	
	color: #FFFFFF;
}
.s2 {font-family: Arial, Helvetica, sans-serif;  color: #FFFFFF; font-size: 12px; }
.Estilo3 {color: #FFFFFF; font-size: 12px; font-family: Arial, Helvetica, sans-serif;}

.eS4 {
	color: #000099;
	text-align: right;
}

.Estilo5 {color: #000000}


-->
</style>

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

<div class="TITULO BLANCO" style="left: 116px; top: 30px; width: 412px;">COMPRAS - BUSCAR - Detallado</div>

<div class="ICONO" style=" left: 57px; top: 25px; width: 64px;">
<img src="img/buscar.png" width="57" height="60" /></div>

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

<div class="s1" style="position:absolute; left:16px; top: 120px; width: 90px;">EMPRESA</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:16px; top:139px; width: 90px;" 
onchange="EM_OC();"
onkeydown="return SoloTextoEx(event,'CboAlm');" tabindex="<?php echo $TI;?>">
  <?php 
	echo LE($StrEmp,"S","N"); 
?>
</select>

<div class="s1" style="position:absolute; left:118px; top: 120px; width: 90px;">ALMACEN</div>
<select name="CboAlm" id="CboAlm" 
style="position:absolute; left: 115px; top: 138px; width:90px;" 
onkeydown="return SoloTextoEx(event,'CboCom');" tabindex="<?php echo $TI;?>">
<?php
	echo LA($StrEmp,$StrAlm,"S","N");
?>
</select>


<div class="s1" style="left: 211px; top: 120px; width: 102px;">COMPROBANTE</div>
<select name="CboCom" id="CboCom" style="position:absolute; left: 211px; top: 138px; width: 90px;" 
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 class="s1" style="left: 311px; top: 120px; width: 49px;">SERIE</div>
<input name="TxtSer" type="text" id="TxtSer" 
style="position:absolute; left: 311px; top: 138px; width: 44px;" 
value="<?php echo $StrSer;?>"  
onkeydown="return SoloTextoEx(event,'TxtNum');"
tabindex="<?php echo $TI;?>" />


<div class="s1" style="left: 364px; top: 120px; width: 74px;">NUMERO</div>
<input name="TxtNum" type="text" id="TxtNum" 
style="position:absolute; left: 362px; top: 138px; width: 67px;" value="<?php echo $StrNum;?>"  
onkeydown="return SoloTextoEx(event,'TxtDam');"
tabindex="<?php echo $TI;?>" />

<div class="s1" style="left: 436px; top: 120px; width: 74px;">DAM</div>
<input name="TxtDam" type="text" id="TxtDam" 
style="position:absolute; left: 436px; top: 138px; width: 67px;" value="<?php echo $StrDam;?>"  
onkeydown="return SoloTextoEx(event,'TxtDex');"
tabindex="<?php echo $TI;?>" />

<div  class="s1" style="left: 514px; top: 106px; width: 45px;">DESDE</div>
<div class="EV" style="left: 513px; top: 122px; 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: 138px; width: 69px;" 
value="<?php echo $StrDex;?>"  
onkeydown="return SoloFec(this,event,'TxtHax');"
tabindex="<?php echo $TI;?>" />

<div class="s1" style="left: 592px; top: 106px; width: 60px;">HASTA</div>
<div class="EV" style="left: 591px; top: 122px; 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: 593px; top: 138px; width: 68px;" 
value="<?php echo $StrHax;?>"  
onkeydown="return SoloFec(this,event,'TxtPro');"
tabindex="<?php echo $TI;?>" />

<div class="s1" style="left: 669px; top: 120px; width: 84px;">PROVEEDOR</div>
<input name="TxtPro" type="text" id="TxtPro" 
style="position:absolute; left: 667px; top: 138px; width: 85px;" value="<?php echo $StrPro;?>"  
onkeydown="return SoloTextoEx(event,'CboSN');" 
tabindex="<?php echo $TI;?>" />

<div class="s1" style="left: 760px; top: 120px; width: 63px;">ANULADO</div>
<select name="CboSN" id="CboSN" 
style="position:absolute; left: 759px; top: 138px; width: 58px;" 
onkeydown="return SoloTextoEx(event,'TxtCod');" tabindex="<?php echo $TI;?>">
<?php echo FCBO_("au_item","auxiliar","au_tab='SI_NO'",$StrSN,"N","N");?>
</select>

<div class="s1" style="left: 826px; top: 120px; width: 73px;">CODIGO</div>
<input name="TxtCod" type="text" id="TxtCod" 
style="position:absolute; left: 825px; top: 138px; width: 59px;" 
value="<?php echo $StrCod;?>"  
onkeydown="return SoloTextoEx(event,'TxtDes');" 
tabindex="<?php echo $TI;?>" />


<div class="s1" style="left: 895px; top: 120px; width: 104px;">DESCRIPCION</div>
<input name="TxtDes" type="text" id="TxtDes" 
style="position:absolute; left: 893px; top: 138px; width: 88px;" value="<?php echo $StrDes;?>"  
onkeydown="return SoloTextoEx(event,'TxtMar');"
tabindex="<?php echo $TI;?>" />

<div class="s1" style="left: 990px; top: 120px; width: 45px;">LINEA</div>
<input name="TxtMar" type="text" id="TxtMar" 
style="position:absolute; left: 989px; top: 138px; width: 47px;" value="<?php echo $StrMar;?>"  
onkeydown="return SoloTextoEx(event,'CboET');"
tabindex="<?php echo $TI;?>" />

<div class="s1" style="left: 1045px; top: 104px; width: 66px;">EN TRANSITO</div>
<select name="CboET" id="CboET" 
style="position:absolute; left: 1043px; top: 137px; width: 56px;" 
onkeydown="return SoloTextoEx(event,'CmdB');" tabindex="<?php echo $TI;?>">
<?php echo FCBO_("au_item","auxiliar","au_tab='SI_NO'",$StrET,"N","N");?>
</select>

<input name="CmdB" type="button" id="CmdB" 
style="position:absolute; left: 1106px; top: 137px; width: 60px;" 
value="Filtrar" onclick="fFiltrar();" tabindex="11" />


<div class="ps" style="left: 116px; top: 50px; width: 543px;">
<input name="CmdB" type="button" id="CmdB" class="bt"
value="Volver" onclick="fVolver('compras.php?TxtAc=X');"
tabindex="<?php echo ++$TI;?>" />

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


<div id="layer3" class="s2" style="position:absolute; left: 16px; top: 169px; width: 1175px; height: 386px; overflow:auto">
<table id="Exportar_a_Excel" width="1151" height="19" border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="18" colspan="13" bgcolor="#666666" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>

<tr>
<td width="77" bgcolor="#999999"><span class="eS4"><b>EMP/ALM</b></span></td>
<td width="82" bgcolor="#999999"><span class="eS4"><b>DAM</b></span></td>
<td width="101" bgcolor="#999999"><span class="eS4"><b>COMPROB.</b></span></td>
<td width="109" bgcolor="#999999"><span class="eS4"><b>NUMERO</b></span></td>
<td width="61" bgcolor="#999999"><span class="eS4"><b>FECHA</b></span></td>
<td width="165" bgcolor="#999999"><span class="eS4"><b>PROVEEDOR</b></span></td>
<td width="104" bgcolor="#999999"><span class="eS4"><b>CODIGO</b></span></td>
<td width="172" bgcolor="#999999"><span class="eS4"><b>DESCRIPCION</b></span></td>
<td width="54" bgcolor="#999999"><span class="eS4"><b>LINEA</b></span></td>
<td width="39" bgcolor="#999999" style="text-align:right"><span class="eS4"><b>CANT</b></span></td>
<td width="42" bgcolor="#999999" style="text-align:right"><span class="eS4"><b>PIEZAS</b></span></td>
<td width="49" bgcolor="#999999" style="text-align:right"><span class="eS4"><b>PRECIO</b></span></td>
<td width="68" bgcolor="#999999" style="text-align:right"><span class="eS4"><b>IMPORTE</b></span></td>
</tr>

<?php		
$_TP=0;
$_TO=0;  		
$s="SELECT ID, ALMC , COM , NUM,DATE_FORMAT(FEC,'%d-%m-%y') , 
		   SUBSTRING(PROV,1,18) AS PROV , SUBSTRING(DES,1,16) AS DES , 
		   SUBSTRING(LINEA,1,11) AS LINEA , KA,
		   ROUND(PR,1) , ROUND(IMP ,1) , COD , PIEZAS , EMPC , SER , DAM
	 FROM vcompras_det WHERE $FF ORDER BY ALM,SER,NUM ";		
			
$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
$X2="</span></td>";
$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
$result = grs($s);				
while ($row = $result->fetch_row()){
	echo "<tr ondblclick=\"location.href='compras.php?Id=$row[0]&Pag=0';\">";
	echo $X1.$row[13]."/".$row[1].$X2;
	echo $X1.$row['DAM'].$X2;
	echo $X1.$row[2].$X2;
	echo "<td bgcolor=\"#FFFFFF\"><a target=\"_blank\" href=\"compras.php?Id=$row[0]\">'".$row[14]."-".$row[3]."</a></td>";
	echo $X1.$row[4].$X2;
	echo $X1.$row[5].$X2;
	echo $X1."'".$row[11].$X2;
	echo $X1.$row[6].$X2;
	echo $X1.$row[7].$X2;	
	echo $X1.$row[8].$X2;
	echo $X1.$row[12].$X2;
	echo "<td bgcolor=\"#FFFFFF\"  style=\"text-align:right\">
	<span class=\"Estilo5\">".NF3($row[9]).$X2;
	echo "<td bgcolor=\"#FFFFFF\"  style=\"text-align:right\">
	<span class=\"Estilo5\">".NF3($row[10]).$X2;
	echo "</tr>";
	$_TO=$_TO + $row[10];
	$_TP=$_TP + $row['KA'];
}

?>     
<tr>
<td width="77" bgcolor="#999999">&nbsp;</td>
<td width="82" bgcolor="#999999">&nbsp;</td>
<td width="101" bgcolor="#999999">&nbsp;</td>
<td width="109" bgcolor="#999999">&nbsp;</td>
<td width="61" bgcolor="#999999">&nbsp;</td>
<td width="165" bgcolor="#999999">&nbsp;</td>
<td width="104" bgcolor="#999999">&nbsp;</td>
<td width="172" bgcolor="#999999">&nbsp;</td>
<td width="54" bgcolor="#999999"><span class="eS4"><b>TOTAL</b></span></td>
<td width="39" bgcolor="#999999" style="text-align:right"><span class="eS4"><b><?php echo NF4($_TP)?></b></span></td>
<td width="42" bgcolor="#999999" style="text-align:right">&nbsp;</td>
<td width="49" bgcolor="#999999" style="text-align:right">&nbsp;</td>
<td width="68" bgcolor="#999999" style="text-align:right"><span class="eS4"><b><?php echo NF3($_TO)?></b></span></td>
</tr>    
</table>
</div>

<div class="s1" style="left: 19px; top: 559px; width: 890px;">
Doble Click sobre el registro para activar Actualizacion  | <b> Los registros se muestran en forma descendente segun la fecha </b> </div>

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



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




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