<?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']);
	$StrRegID=V($_POST['TxtRegID']);
	if(strlen($StrRegID)==0)$StrRegID="0";
	//-------------------------
	if($StrCmd=="KILLER"){
		$T_ID_ALM=gn("id_almacen","ajustex","id_ajuste=$StrRegID");
		$T_ID_PRO=gn("id_producto","ajustex","id_ajuste=$StrRegID");
		$T_ID_CAN=gn("cant","ajustex","id_ajuste=$StrRegID");
		$T_ID_ACC=gn("accion","ajustex","id_ajuste=$StrRegID");
		if($T_ID_ACC=="A"){
			ejt("UPDATE stocks SET stock=stock - $T_ID_CAN ".
				"WHERE id_almacen=$T_ID_ALM AND id_producto=$T_ID_PRO");
		}else{
			ejt("UPDATE stocks SET stock=stock + $T_ID_CAN ".
				"WHERE id_almacen=$T_ID_ALM AND id_producto=$T_ID_PRO");
		}
		ejt("DELETE FROM ajustex WHERE id_ajuste=$StrRegID");
		$StrRegID="0";
	}
	//-------------------------
	$StrAlm=V($_POST['CboAlm']);		
	$StrDex=V($_POST['TxtDex']);		
	$StrHax=V($_POST['TxtHax']);			
	$StrCod=V($_POST['TxtCod']);
	$StrDes=V($_POST['TxtDes']);
	
	if($_SESSION['SYS_USER_ALM']=="%"){
		if(strlen($StrAlm)==0)$StrAlm=GetSO("alm_obs","almacenes","","alm_obs");
	}else{
		$StrAlm=$_SESSION['SYS_USER_ALM'];
	}	
	if(strlen($StrDex)==0){
		$StrDex_="2000-01-01";
	}else{
		$StrDex_=ToDate($StrDex);
	}
	if(strlen($StrHax)==0){
		$StrHax_="2030-12-01";//
	}else{
		$StrHax_=ToDate($StrHax);
	}
	$StrCod_=$StrCod."%";
	$StrDes_="%".$StrDes."%";
	//-------------------------
	$FF="ID>0 AND ALM LIKE '$StrAlm' AND FEC >= '$StrDex_' AND FEC <= '$StrHax_' AND 
		 COD LIKE '$StrCod_' AND DES LIKE '$StrDes_' ";
	$LStrTR=gn("count(*)","vajustex",$FF);
	$LStrPag=V($_POST['TxtPag']);	
	if($StrCmd=="F"){$LStrPag="1";}
	$VP_RegXPag=10;	
	$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 automaticos</title>
<script type="text/javascript" src="fe/funciones.js"></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:800px;
	height:600px;
	position:absolute;
	left:50%;
	top:50%;
	background-color:#006699;
	margin:-300px 0 0 -400px;
}
#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;}
.Estilo4 {
	color: #000099;
	text-align: right;
}
.Estilo5 {color: #000000}
#Frm center #DivFRM #layer3 .f2 table {
	font-weight: normal;
}

-->
</style>

</head>
<body  <?php echo $StrMsg;?>>
<form id="Frm" name="Frm" method="post" action="ajustex.php">
<input id="TxtAc" name="TxtAc" type="hidden" value="" />
<input id="TxtRegID" name="TxtRegID" type="hidden" value="<?php echo $StrRegID;?>" />
<center> 
  <div Id="DivFRM"  class="centrarFrm" >
    <div id="layer6" style="position:absolute; left: 313px; top: 88px; width: 74px;">
      <div align="left" class="f2">CODIGO</div>
    </div>
    <div id="layer5" style="position:absolute; left: 116px; top: 50px; width: 85px; height: 28px;">
      <div align="left" class="f2">
        <input name="CmdV" type="button" id="CmdV" 
        value="Volver" onclick="fVolver('menu.php');" />
      </div>
    </div>
    <div id="layer3" style="position:absolute; left: 30px; top: 138px; width: 740px; height: 200px;">
      <div align="left" class="f2">
        <table width="739" height="19" border="1" cellpadding="0" cellspacing="0">
        <tr  >
            <td height="18" colspan="7" bgcolor="#666666" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
            </td>
           
          </tr>
          <tr>
<td width="78" bgcolor="#999999"><span class="Estilo4"><b>ALMACEN</b></span></td>
<td width="97" bgcolor="#999999"><span class="Estilo4"><b>FECHA</b></span></td>
<td width="57" bgcolor="#999999"><span class="Estilo4"><b>CODIGO</b></span></td>
<td width="355" bgcolor="#999999"><span class="Estilo4"><b>DESCRIPCION</b></span></td>
<td width="46" bgcolor="#999999"><span class="Estilo4"><b>ACCION</b></span></td>
<td width="54" bgcolor="#999999" style="text-align:right"><span class="Estilo4"><b>CANT</b></span></td>
<td width="36" bgcolor="#999999">&nbsp;</td>
          </tr>
<?php		  		
	
	$s="SELECT ID,ALM,DATE_FORMAT(FEC,'%d-%m-%y'),COD,DES,ACC,CANT
		 FROM vajustex WHERE $FF ORDER BY FEC,ID ";				
	$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>";
		echo $X1.$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\">".$row[6].$X2;
		echo "<td bgcolor=\"#FFFFFF\" align=\"center\">
			 <a href=\"javascript:void(0)\" onclick=\"fKillerEx('$row[0]');\" >
			 <img src=\"img/eliminar.png\"  border=\"0\"/>
			 </a>
			 </td>";
		echo "</tr>";
	}

?>         
        </table>
      </div>
    </div>
    <div id="layer" style="position:absolute; left: 116px; top: 30px; width: 412px; height: 24px;">
      <div align="left" class="Estilo1">AJUSTES AUTOMATICOS</div>
    </div>


          <input name="TxtCod" type="text" id="TxtCod" 
          style="position:absolute; left: 311px; top: 109px; width: 83px;"
          value="<?php echo $StrNum;?>"  
          onkeydown="return SoloTextoEx(event,'TxtDes');"
          tabindex="1" />

    <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" style="position:absolute; left: 721px; top: 109px; width: 57px;"
        id="CmdB" value="Filtrar" onclick="fFiltrar();" />

    <div id="layer7" style="position:absolute; left: 149px; top: 88px; width: 45px;">
      <div align="left" class="f2">DESDE</div>
    </div>

        <input name="TxtDex" type="text" id="TxtDex" 
        style="position:absolute; left: 149px; top: 109px; width: 73px;"
        value="<?php echo $StrDex;?>"  
        onkeydown="return SoloFec(this,event,'TxtHax');"
        tabindex="1" />


        <input name="TxtDes" type="text" id="TxtDes" 
        style="position:absolute; left: 402px; top: 109px; width: 294px;" 
        value="<?php echo $StrPro;?>"  
        onkeydown="return SoloTextoEx(event,'CmdB');" 
        tabindex="1" />

    <div id="layer10" style="position:absolute; left: 404px; top: 86px; width: 100px;">
      <div align="left" class="f2">DESCRIPCION</div>
    </div>
    <div id="layer11" style="position:absolute; left: 231px; top: 88px; width: 60px;">
      <div align="left" class="f2">HASTA</div>
    </div>


        <input name="TxtHax" type="text" id="TxtHax" 
        style="position:absolute; left: 232px; top: 109px; width: 73px;" 
        value="<?php echo $StrHax;?>"  
        onkeydown="return SoloFec(this,event,'TxtCod');"
        tabindex="1" />


<select name="CboAlm" id="CboAlm" style="position:absolute; left: 31px; top: 109px; width: 109px;" 
onkeydown="return SoloTextoEx(event,'TxtDex');">
 <?php echo ListALM($StrAlm); ?>
</select>


    <div id="layer14" style="position:absolute; left: 34px; top: 88px; width: 102px;">
      <div align="left" class="f2">ALMACEN</div>
    </div>
  </div>
</center>	
</form>
</body>
</html>
