<?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']);
	//
	$StrCod=V($_POST['TxtCod']);		
	$StrDes=V($_POST['TxtDes']);
	$StrLin=V($_POST['CboLin']);
	if(strlen($StrLin)==0)$StrLin=GetSO("lin_nombre","lineas","	id_linea>0","lin_nombre");		
	//
	$StrCodT=$StrCod."%";
	$StrDesT=$StrDes."%";
	$StrLinT=$StrLin;
	if($StrLinT=="TODOS") $StrLinT="%";
	//
	$FF="ID>0 AND COD LIKE '$StrCodT'  AND 
		 DESCRIPCION LIKE '$StrDesT' AND 
		 LINEA LIKE '$StrLinT' AND USO='SI'";
	//++++++++++++++
	if($StrCmd=="G"){
		//BIT
		$_BIT_MOD_ID="0";
		$_BIT_SQL_CAB="SQL";
		$_BIT_SQL_DET="";
		$_BIT_PHP="rep_precios_actualizar.php";
		$_BIT_ID=BIT_ADD("ACTUALIZACIONES","ACTUALIZAR PRECIO DE VENTA","GUARDAR",$_BIT_MOD_ID,$_BIT_SQL_CAB,$_BIT_SQL_DET,$_BIT_PHP);
		BIT_DET_ADD($_BIT_ID,"");
		//BIT			  	
		$s="SELECT ID	FROM vproductos WHERE ID>0 AND USO='SI' 
		 	 ORDER BY COD,DESCRIPCION ";
		$result = grs($s);
		while ($row = $result->fetch_row()){
			//
			$_ID=vbr("0000".$row[0],5);	
			$TM="TM".$_ID;
			$TW="TW".$_ID;
			//++
			$TZ=V($_POST[$TM]);
			if(strlen($TZ)>0){
				$NPre=vbval($TZ);
				$s="UPDATE productos SET pro_pv_min=$NPre WHERE id_producto=$row[0]";	
				ejt($s);
				BIT_DET_ADD($_BIT_ID,$s);
				//
				$s="UPDATE t_productos SET pro_pmi=$NPre WHERE pro_id=$row[0]";
				ejt($s);
				BIT_DET_ADD($_BIT_ID,$s);
				//
			}
			$TZ=V($_POST[$TW]);
			if(strlen($TZ)>0){
				$NPre=vbval($TZ);		
				$s="UPDATE productos SET pro_pv_max=$NPre WHERE id_producto=$row[0]";
				ejt($s);
				BIT_DET_ADD($_BIT_ID,$s);
				//
				$s="UPDATE t_productos SET pro_pma=$NPre WHERE pro_id=$row[0]";
				ejt($s);
				BIT_DET_ADD($_BIT_ID,$s);
				//
			}
			//++
		}				
	}	
	//-------------------------
	$LStrTR=gn("count(*)","vproductos",$FF);
	$LStrPag=V($_POST['TxtPag']);	
	if($StrCmd=="F"){$LStrPag="1";}
	$VP_RegXPag=50000;	
	$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
	//-------------------------
	$LStrFoc="document.getElementById('TxtCod').focus();";
	$LStrMsg="onload=\"$LStrFoc;\"";
?>
<!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>Actualizar Precio de Venta</title>
<?php AddJs();?>
<script type="text/javascript" src="fe/funciones.js"></script>
<script>
$(document).ready(function(){  
   Inicializar();
   jFocus("TxtCod");
});
</script>

<script>
function fGuardar(){
	if(confirm("Esta seguro que desea actualizar los nuevos precios")==true){
		document.getElementById("TxtAc").value="G";
	}else{
		return;
	}
	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();
});
});
</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:1000px;
	height:600px;
	position:absolute;
	left:<?php echo "50%";?>;
	top:<?php echo "50%";?>;
	background-color:#006699;
	margin:<?php echo "-300px";?> 0 0 <?php echo "-550px";?>;
}
#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}
#Frm center #DivFRM #layer3 .f2 table tr td {
	color: #000;
	text-align: left;
}

-->
</style>

</head>
<body  >
<div Id="DivFRM"  class="centrarFrm" >
<form id="Frm" name="Frm" method="post" action="rep_precios_actualizar.php">

<div class="TITULO BLANCO" style=" left: 100px; top: 30px; width: 412px;"> ACTUALIZAR PRECIO DE VENTA
</div>

<div class="ps" style=" left: 41px; 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="TxtAc" type="hidden" id="TxtAc" value="" />
<input name="TxtPag" type="hidden" id="TxtPag" value="<?php echo $LStrPag; ?>" />
</div>
<div class="s1" style="left: 34px; top: 95px; width: 931px;">SE RECOMIENDA APLICAR LOS FILTROS NECESARIOS, EL SISTEMA ACEPTA UN MAXIMO DE 800 REGISTROS POR ACTUALIZACION EN UN SOLO MOMENTO</div>
<div class="s1" style="left: 34px; top: 119px; width: 77px;">CODIGO</div>
<input name="TxtCod" type="text" id="TxtCod" 
style="position:absolute; left: 33px; top: 138px; width: 121px;" 
class="lt" value="<?php echo $StrCod;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 166px; top: 119px; width: 266px;">DESCRIPCION</div>
<input name="TxtDes" type="text" id="TxtDes" 
class="lt" style="position:absolute; left: 164px; top: 138px; width: 322px;" 
value="<?php echo $StrDes;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 503px; top: 119px; width: 102px;">LINEA</div>
<select name="CboLin" id="CboLin" 
class="lt" style="position:absolute; left: 501px; top:138px; width: 229px;" 
tabindex="<?php echo ++$TI;?>">
<?php	
echo FCBO_("lin_nombre","lineas","id_linea>0",$StrLin,"N","N");
?>
</select>


<div id="DivBtn" class="ps" style="left: 100px; top: 50px; width: 704px;">


<input name="CmdB" type="button" id="CmdB" 
style="position:absolute; left: 640px; top: 87px; width: 54px;"
value="Filtrar" onclick="fFiltrar();" 
tabindex="<?php echo ++$TI;?>" />
<input name="CmdG" type="button" id="CmdG" 
style="position:absolute; left: 703px; top: 87px; width: 60px;"
value="Guardar" onclick="fGuardar();" />

<input name="CmdV" type="button" id="CmdV" 
class="bt" value="Volver" onclick="fVolver('menu.php');" />
</div>



<div  class="datagrid" style="position:absolute; left: 30px; top: 169px; width: 945px; height: 391px; overflow:auto">
<table id="Exportar_a_Excel" width="817" height="19" border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="18" colspan="8" bgcolor="#666666" ><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>
</tr>
<tr>
<td width="34" bgcolor="#999999"><span class="z4">Nº</span></td>
<td width="104" bgcolor="#999999"><span class="z4">CODIGO</span></td>
<td width="318" bgcolor="#999999"><span class="z4">DESCRIPCION</span></td>
<td width="93" bgcolor="#999999"><span class="z4">LINEA</span></td>
<td width="91" bgcolor="#999999"><span class="z4">PRE.MIN.ACT</span></td>
<td width="94" bgcolor="#999999"><span class="z4">PRE.MAX.ACT</span></td>
<td width="94" bgcolor="#999999"><span class="z4">NUE.PRE.MIN</span></td>
<td width="99" bgcolor="#999999"><span class="z4">NUE.PRE.MAX</span></td>
</tr>

<?php
	$CX=0;
    $s="SELECT ID,COD,LINEA as LIN,DESCRIPCION as DES,PV_MIN ,PV_MAX 
		FROM vproductos 
		WHERE $FF ORDER BY COD,DESCRIPCION ";		  					
    $s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);				
    $result = grs($s);
    while ($row = $result->fetch_assoc()){
		$_ID=vbr("0000".$row['ID'],5);	
		$TM="TM".$_ID;
		$TW="TW".$_ID;
		$CX++;
	?>
    <tr>
    <td bgcolor="#FFFFFF"><?php echo $CX;?></td>
    <td bgcolor="#FFFFFF"><?php echo $row['COD']?></td>
    <td bgcolor="#FFFFFF"><?php echo $row['DES']?></td>
    <td bgcolor="#FFFFFF"><?php echo $row['LIN']?></td>
	<td bgcolor="#FFFFFF"  style="text-align:right"><?php echo $row['PV_MIN']?></td>
    <td bgcolor="#FFFFFF"  style="text-align:right"><?php echo $row['PV_MAX']?></td>
    <td bgcolor="#FFFFFF"  style="text-align:right">
    <input name="<?php echo $TM;?>" type="text" id="<?php echo $TM;?>" 
    class="nd" style=" position:inherit; width:75px" 
    value=""   onfocus="this.select();"    tabindex="<?php echo ++$TI;?>" />
	</td>
    <td bgcolor="#FFFFFF"  style="text-align:right">
    <input name="<?php echo $TW;?>" type="text" id="<?php echo $TW;?>" 
    class="nd" style=" position:inherit; width:75px" 
    value=""   onfocus="this.select();"    tabindex="<?php echo ++$TI;?>" />
	</td>
    </tr>
	<?php
    }
?>
</table>
</div>
</form>

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