<?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']);	
	$StrAcc=V($_POST['CboAcc']);		
	$StrNum=V($_POST['TxtNum']);		
	$StrDex=V($_POST['TxtDex']);		
	$StrHax=V($_POST['TxtHax']);	
	$StrSN=V($_POST['CboSN']);			
	$StrDes=V($_POST['TxtDes']);		
	$StrMar="%";
	$StrCod=V($_POST['TxtCod']);	
	//
	if(strlen($StrEmp)==0)$StrEmp=GE("S");
	if(strlen($StrAlm)==0)$StrAlm=GA($StrEmp,"S");
	//
	if(strlen($StrAcc)==0) $StrAcc="QUITAR";
	if(strlen($StrSN)==0) $StrSN="NO";
	//-------------------------
	$StrEmp_=LIKE($StrEmp);
	$StrAlm_=LIKE($StrAlm);
	$StrAcc=substr($StrAcc,0,1);
	$StrNum_=$StrNum."%";
	if(strlen($StrDex)==0){
		$StrDex_="2000-01-01";
	}else{
		$StrDex_=ToDate($StrDex);
	}
	if(strlen($StrHax)==0){
		$StrHax_="2030-12-01";//
	}else{
		$StrHax_=ToDate($StrHax);
	}
	$StrSN_=substr($StrSN,0,1);
	$StrDes_=$StrDes."%";
	$StrMar_=$StrMar."%";
	$StrCod_=$StrCod."%";
	//-------------------------
	$FF="ID>0 AND EMPC LIKE '$StrEmp_' 
		AND ALM LIKE '$StrAlm_' 
		AND ACC LIKE '$StrAcc' 
		AND NUM LIKE '$StrNum_' 
		AND FEC >= '$StrDex_' 
		AND FEC <= '$StrHax_' 
		AND ANU LIKE '$StrSN_' 
		AND DES LIKE '$StrDes_' 
		AND LINEA LIKE '$StrMar_'
		AND COD LIKE '$StrCod_' ";

	include("ajustes_pdf.php");
	$LStrTR=gn("count(*)","vajustes_det",$FF);					
	$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=1000;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
//-------------------------
?>
<!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>Ajustes - Buscar - Detallado</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 fGenPDF(){
	var emp=gv("CboEmp");
	var alm=gv("CboAlm");
	if(emp=="TODOS"){
		alert("Seleccione una empresa");
		return jF("CboEmp");
	}
	if(alm=="TODOS"){
		alert("Seleccione un almacen");
		return jF("CboAlm");
	}
	document.getElementById("TxtAc").value="GEN_PDF_3";
	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>

<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: #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="ajustes_buscar_det.php">




<div class="ps" style="left: 116px; top: 50px; width: 543px;">
<input name="CmdV" type="button" id="CmdV" class="bt"
value="Volver" onclick="fVolver('ajustes.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" style="position:absolute; left: 31px; top: 155px; width: 1150px; height: 390px;">
<div align="left" class="f2">
<table id="Exportar_a_Excel" width="1129" height="19" border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="18" colspan="11" bgcolor="#666666" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>
</tr>
<tr>
<td width="189" bgcolor="#999999"><span class="z4">EMPRESA</span></td>
<td width="229" bgcolor="#999999"><span class="z4">ALMACEN</span></td>
<td width="56" bgcolor="#999999"><span class="z4">ACCION</span></td>
<td width="60" bgcolor="#999999"><span class="z4">NUMERO</span></td>
<td width="57" bgcolor="#999999"><span class="z4">FECHA</span></td>
<td width="90" bgcolor="#999999"><span class="z4">CODIGO</span></td>
<td width="181" bgcolor="#999999"><span class="z4">DESCRIPCION</span></td>
<td width="98" bgcolor="#999999"><span class="z4">LINEA</span></td>
<td width="45" bgcolor="#999999"><span class="z4">CANT</span></td>
<td width="48" bgcolor="#999999"><span class="z4">PIEZAS</span></td>
<td width="52" bgcolor="#999999"><span class="z4">TOTAL</span></td>
</tr>
<?php		 
	$_TP=0; 			
	$s="SELECT ID,ALM,ACC,NUM,DATE_FORMAT(FEC,'%d-%m-%y') AS FEC,
		SUBSTRING(DES,1,33) AS DES,
		SUBSTRING(LINEA,1,13) AS LINEA,KA,
		COD,PIEZAS,EMPC
		FROM vajustes_det  
		WHERE  $FF ORDER BY ID,COD  ";
	$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);	  				
	$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
	$X2="</span></td>";
	$result = grs($s);	
	while ($row = $result->fetch_assoc()){
		echo "<tr ondblclick=\"location.href='ajustes.php?Id=$row[0]&Pag=0';\">";
		echo $X1.$row['EMPC'].$X2;
		echo $X1.$row['ALM'].$X2;
		echo $X1.$row['ACC'].$X2;
		//echo $X1."'".$row[NUM].$X2;
		echo "<td bgcolor=\"#FFFFFF\"><a target=\"_blank\" href=\"ajustes.php?Id=$row[0]\">'$row[NUM]</a></td>";
		echo $X1.$row['FEC'].$X2;
		echo $X1."'".$row['COD'].$X2;
		echo $X1.$row['DES'].$X2;
		echo $X1.$row['LINEA'].$X2;
		echo $X1.$row['KA'].$X2;
		echo $X1.$row['PIEZAS'].$X2;
		echo $X1.$row['PIEZAS']*$row['KA'].$X2;
		echo "</tr>";
		$_TP=$_TP + $row['KA'];
	}
?>		  
<tr>
<td width="189" bgcolor="#999999">&nbsp;</td>
<td width="229" bgcolor="#999999">&nbsp;</td>
<td width="56" bgcolor="#999999">&nbsp;</td>
<td width="60" bgcolor="#999999">&nbsp;</td>
<td width="57" bgcolor="#999999">&nbsp;</td>
<td width="90" bgcolor="#999999">&nbsp;</td>
<td width="181" bgcolor="#999999">&nbsp;</td>
<td width="98" bgcolor="#999999"><span class="z4">TOTAL CAJAS</span></td>
<td width="45" bgcolor="#999999"><span class="z4"><?php echo NF4($_TP);?></span></td>
<td width="48" bgcolor="#999999">&nbsp;</td>
<td width="52" bgcolor="#999999">&nbsp;</td>
</tr>      
         
</table>

      </div>
    </div>
    <div id="layer" style="position:absolute; left: 116px; top: 30px; width: 412px; height: 24px;">
      <div align="left" class="Estilo1">AJUSTES - BUSCAR
        <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");?>"/>  
      - Detallado</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" style="position:absolute; left: 990px; top: 126px; width: 57px;"
type="button" id="CmdB" value="Filtrar" onclick="fFiltrar();" />

<div style="position:absolute; left: 32px; top: 109px; width: 146px;">
<div align="left" class="f2">EMPRESA</div>
</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:29px; top:127px; width: 132px;" 
onchange="EM_OC();"
onkeydown="return SoloTextoEx(event,'CboAlm');" tabindex="1">
<?php 
	echo LE($StrEmp,"S","N"); 
?>
</select>


<div style="position:absolute; left: 172px; top: 109px; width: 106px;">
<div align="left" class="f2">ALMACEN</div>
</div>
<select name="CboAlm" id="CboAlm" 
style="position:absolute; left: 170px; top: 126px; width: 126px;" 
onkeydown="return SoloTextoEx(event,'CboAcc');">
<?php
	echo LA($StrEmp,$StrAlm,"S","N");
?>
</select>

<div style="position:absolute; left: 306px; top: 109px; width: 84px;">
<div align="left" class="f2">ACCION</div>
</div>
<select name="CboAcc" id="CboAcc" 
style="position:absolute; left: 304px; top: 126px; width: 104px;" 
onkeydown="return SoloTextoEx(event,'TxtNum');">
<?php
if(substr($StrAcc,0,1)=="Q" || strlen($StrAcc)==0){
echo "<option value=\"QUITAR\" selected=\"selected\">QUITAR</option>";
echo "<option value=\"AGREGAR\" >AGREGAR</option>";
}else{
echo "<option value=\"QUITAR\">QUITAR</option>";
echo "<option value=\"AGREGAR\"  selected=\"selected\">AGREGAR</option>";
}
?>
</select>

<div style="position:absolute; left: 417px; top: 109px; width: 74px;">
<div align="left" class="f2">NUMERO</div></div>
<input name="TxtNum" type="text" id="TxtNum" 
style="position:absolute; left: 416px; top: 126px; width: 78px;"
value="<?php echo $StrNum;?>"  
onkeydown="return SoloTextoEx(event,'TxtDex');"
tabindex="1" />

<div style="position:absolute; left: 505px; top: 95px; width: 45px;">
<div align="left" class="f2">DESDE</div>
</div>
<div class="EV" style="left: 501px; top: 108px; 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: 505px; top: 126px; width: 70px;" 
value="<?php echo $StrDex;?>"  
onkeydown="return SoloFec(this,event,'TxtHax');"
tabindex="1" />

<div style="position:absolute; left: 587px; top: 95px; width: 60px;">
<div align="left" class="f2">HASTA</div>
</div>
<div class="EV" style="left: 588px; top: 108px; 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: 588px; top: 126px; width: 70px;" 
value="<?php echo $StrHax;?>"  
onkeydown="return SoloFec(this,event,'CboSN');"
tabindex="1" />

<div style="position:absolute; left: 670px; top: 109px; width: 75px;">
<div align="left" class="f2">ANULADO</div>
</div>
<select name="CboSN" id="CboSN" 
style="position:absolute; left: 668px; top: 126px; width: 84px;" 
onkeydown="return SoloTextoEx(event,'TxtCod');">
<?php
	if($StrSN=="" || $StrSN=="NO"){
		AD("NO",1);	AD("SI",0);
	}else{
		AD("NO",0);	AD("SI",1);
	}
?>
</select>

<div style="position:absolute; left: 764px; top: 109px; width: 58px;">
<div align="left" class="f2">CODIGO</div>
</div>
<input name="TxtCod" type="text" id="TxtCod" 
style="position:absolute; left: 762px; top: 126px; width: 72px;" 
value="<?php echo $StrCod;?>"  
onkeydown="return SoloFec(this,event,'TxtDes');"
tabindex="1" />

<div id="layer17" style="position:absolute; left: 850px; top: 109px; width: 113px;">
<div align="left" class="f2">DESCRIPCION</div>
</div>


    <input name="TxtDes" type="text" id="TxtDes" 
          style="position:absolute; left: 848px; top: 126px; width: 117px;"
          value="<?php echo $StrDes;?>"  
          onkeydown="return SoloTextoEx(event,'TxtMar');"
          tabindex="1" />
    <div class="s1" style="left: 30px; top: 559px; width: 166px;">Doble Click sobre el registro para activar Actualizacion </div>


<?php
if(strlen($StrDESCARGAR)>0){
echo "<div id=\"layer51\" 
	  style=\"position:absolute; left: 211px; top: 77px; 
	  width: 100px; 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: 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>
