<?php
	session_start();
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.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']);
	
	$IdUsu=$_SESSION['SYS_USER_ID'];
	
	if($_SESSION['SYS_USER_ALM']=="%"){
		if(strlen($StrAlm)==0)$StrAlm=T($StrAlm);//$StrAlm=GetSO("alm_nombre","almacenes","","alm_nombre");
	}else{
		$StrAlm=$_SESSION['SYS_USER_ALM'];
	}	

	
	$StrAlm=T($StrAlm);

	
	if(strlen($StrDex)==0){
		$StrDex_="2000-01-01";
	}else{
		$StrDex_=ToDate($StrDex);
	}
	if(strlen($StrHax)==0){
		$StrHax_="2020-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=15;	
	$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
	

?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajustes automaticos</title>
<!----------------------------------------->
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>

<!----------------------------------------->
<link rel="stylesheet" type="text/css" href="css/estiloss.css"  />
<link rel="stylesheet" type="text/css" href="css/basic.css"  />
<link rel="stylesheet" type="text/css" href="css/mnu.css"  />
<!----------------------------------------->
<style type="text/css">
.cF {height:600px;width:1250px;position:relative;top:0px}
.mM {height:34px;width:1250px;position:relative;top:0px;background-color:#09C; z-index:500;}
</style>

<!----------------------------------------->
<script>
$(document).ready(function(){  
   Inicializar();
   jF("CboAlm");
});


$(document).keydown(function(e){
	var AT=gv("TxtAT");

	if(e.which==66 && e.altKey){
		if(AT=="1"){	
		document.getElementById("CmdB").click();
		return;
		}
	}

	if(e.which==86 && e.altKey){
		if(AT=="1"){
		document.getElementById("CmdZ").click();
		return;
		}
	}
  
});
</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>
<!----------------------------------------->

<body  <?php echo $LStrMsg;?>  >
<div align="center">

<div class="mM" align="left" style="font-size:12px">
<?php
$HTM=file_get_contents("http://inversionessounduniversal.com/ventas/phpmnu.php?USER_ID=$IdUsu");
echo $HTM;
?>
</div>

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" action="ajustex.php" style="margin:0px; padding:0px; display:inline;" onSubmit="return false;">

<!----------------------------------------->
<div id="DivT" class="dT"  style="width:1250px;">
<img src="b.png" class="iT" />
<div class="tT">AJUSTES AUTOMATICOS</div>
</div>
<!----------------------------------------->

<div class="s1" style="left: 34px; top: 117px; width: 102px;">ALMACEN</div>
<select name="CboAlm" id="CboAlm" 
class="lt"  style="left: 35px; top: 134px; width: 235px" 
tabindex="<?php echo ++$TI;?>">
<?php 
	if($IdUsu>=1  && V($_SESSION['SYS_USER_ALM'])!="%"){
		echo ListALM($StrAlm); 
	}else{
    	echo FCBO("alm_nombre","almacenes","id_almacen>0",$StrAlm,"S","N");
    }
?>
</select>

<div class="s1" style="left: 277px; top: 117px; width: 45px;">DESDE</div>
<input name="TxtDex" type="text" id="TxtDex" 
class="fe"  style="left: 277px; top: 134px; width: 70px"
value="<?php echo $StrDex;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 359px; top: 117px; width: 60px;">HASTA</div>
<input name="TxtHax" type="text" id="TxtHax" 
class="fe"  style="left: 360px; top: 134px; width: 70px" 
value="<?php echo $StrHax;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 437px; top: 117px; width: 74px;">CODIGO</div>
<input name="TxtCod" type="text" id="TxtCod" 
class="lt"  style="left: 435px; top: 134px; width: 80px;" 
value="<?php echo $StrNum;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 528px; top: 117px; width: 100px;">DESCRIPCION</div>
<input name="TxtDes" type="text" id="TxtDes" 
class="lt"  style="left: 526px; top: 134px; width: 523px" 
value="<?php echo $StrPro;?>"  
tabindex="<?php echo ++$TI;?>"/>

<!----------------------------------------->
<div id="DivBtn" align="left" style="position:absolute; left: 33px; top: 71px; width: 551px; height: 26px;">
<input name="CmdB" type="button" id="CmdB" class="btm"
value="Buscar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />
</div>

<!----------------------------------------->    

<div class="datagrid" style="position: absolute; left: 35px; top: 165px; width: 1177px; height: 400px; overflow: auto">
<table id="Exportar_a_Excel" width="75%">
<thead>
<tr>
<td colspan="7" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>

<tr>
<th width="235">ALMACEN</th>
<th width="81">FECHA</th>
<th width="89">CODIGO</th>
<th width="582">DESCRIPCION</th>
<th width="59">ACCION</th>
<th width="67" style="text-align:right;">CANT</th>
<th width="30">&nbsp;</th>
</tr>
</thead>
<tbody>
<?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\">";
	$Z1="<td bgcolor=\"#FFFFFF\" style=\"text-align:right\"><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>";
	$ST=$ST+$row[6];
	}

?> 
<tr>
<td colspan="5" bgcolor="#999999" style="text-align:right"><span class="Estilo4"><b>TOTAL</b></span></td>
<td width="67" bgcolor="#999999" style="text-align:right"><span class="Estilo4"><b><?php echo $ST;?></b></span></td>
<td width="30" bgcolor="#999999">&nbsp;</td>
</tr>  
    
</tbody>
</table>

</div>

<!----------------------------------------->    
<?php include("ocultos.php");?>
<input id="TxtRegID" name="TxtRegID" type="hidden" value="<?php echo $StrRegID;?>" />

</form>

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

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