<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
include("phpmnu_fun.php");
//if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//
$HW=$_SESSION['SYS_HW'];
$StrGT="";$LStrMsg="";$LStrFoc="";$LStrMM="";
//
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
$LStrPag=V($_POST['TxtPag']);
//
include("productos_proc.php");
//
$VP_RegXPag=5;
$LStrTR=gn("count(*)","vproductos","ID>0");
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$TI=0;
//
$IdUsu=vbval(V($_SESSION['SYS_USER_ID']));
$AT=gs("at","usuarios","id_usuario=$IdUsu");
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Productos</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>
<script type="text/javascript" src="ja/productox.js"></script>
<!--FIN_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();
});
</script>
</head>

<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 GEN_MENU($IdUsu);
?>
</div>

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

<!--INI_TITULO--------------------------------->
<div id="DivT" class="dT" >
<img src="img/productos2.png" width="54" height="53" class="iT" />
<div class="tT">PRODUCTOS</div>
</div>
<!--FIN_TITULO--------------------------------->

<div class="s11" style="left: 31px; top: 247px; width: 629px;">
STOCKS (Los cambios generara un ajuste automatico)</div>

<div class="s1" style="left: 31px; top: 115px; width: 70px;">CODIGO</div>
<input name="TxtCod"  type="text" id="TxtCod" maxlength="15"
class="lt" style="left: 31px; top: 135px; width: 139px"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $StrCod;?>"/>

<div class="s1" style="left: 176px; top: 115px; width: 145px; cursor: pointer; color: #00F" 
onClick="InsLin()">TIPO DE ARTICULO</div>
<select name="CboLin" id="CboLin" 
class="lt" style="left: 176px; top: 135px; width: 248px"
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("lin_nombre","lineas","id_linea>0",$StrLin,"","S")?>
</select>

<div class="s1" style="left: 436px; top: 115px; width: 223px;"> NOMBRE / DESCRIPCION *</div>
<input name="TxtDes"  type="text" id="TxtDes"
class="lt" style="left: 436px; top: 135px; width: 460px"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $StrDes;?>"/>

<div class="s1" style="left: 906px; top: 115px; width: 117px; cursor: pointer; color: #00F" 
onClick="InsMar()">MARCA</div>
<select name="CboMar" id="CboMar" 
class="lt" style="left: 905px; top: 135px; width: 165px"
tabindex="<?php echo ++$TI;?>">
<?php 
	echo FCBO_("mar_nombre","marcas","id_marca>0",$StrMar,"","S");
?>
</select>

<div class="s1" style="left: 1082px; top: 115px; width: 132px; cursor: pointer; color: #00F" 
onClick="InsUni()">UNIDAD</div>
<select name="CboUni" id="CboUni" 
class="lt" style="left: 1080px; top: 135px; width: 137px"
tabindex="<?php echo ++$TI;?>">
<?php 
echo FCBO_("uni_nombre","unidades","id_unidad>0",$StrUni,"","S");
?>
</select>

<div class="s1" style="left: 31px; top: 166px; width: 119px;">PRECIO DE COMPRA</div>
<input name="TxtPco"  type="text" id="TxtPco" onKeyUp="CalPCS();"
class="ndd" style="left: 31px; top: 199px; width:139px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $StrPco;?>"/>

<?php if(strlen($StrMnd)==0)$StrMnd="SOLES";?>
<div class="s1" style="left: 176px; top: 167px; width: 99px;">MONEDA DE COMPRA*</div>
<select name="CboMnd" id="CboMnd"  onChange="CalPCS()"
class="lt" style="left: 176px; top: 199px; width: 101px"
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("mon_nombre","monedas","id_moneda IN ('S','D')",$StrMnd,"N","N")?>
</select>
<script>
function onTC(){
	var tca=gv("TxtTC");
	var tcn=prompt("Ingrese el tipo de cambio",tca);
	if(jVal(tcn)<=0){
		alert("Tipo de cambio no valido, el tipo de cambio debe ser mayor a cero");
		return;
	}
	var d=AX("UTC",tcn);
	var r=d.split("|");
	if(r[1]=="OK"){
		sv("TxtTC",tcn);
		CalPCS();
		jF("TxtPvs");
	}else{
		alert("Error al intentar actualizar");
	}
}
</script>

<div class="s1" onClick="onTC()" 
style="left: 284px; top: 180px; width: 51px;cursor: pointer; color: #00F">T. CAM</div>
<input name="TxtTC"  type="text" id="TxtTC"
class="rod" style="left: 283px; top: 199px; width:53px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $StrTC;?>"/>

<div class="s1" style="left: 347px; top: 167px; width: 69px;">PRECIO COMPRA S/</div>
<input name="TxtPcs"  type="text" id="TxtPcs"
class="rod" style="left: 347px; top: 199px; width:75px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $StrPcs;?>"/>

<div class="s1" style="left:436px; top: 181px; width: 113px;">PRECIO VENTA S/.</div>
<input name="TxtPvs"  type="text" id="TxtPvs"
class="ndd" style="left:436px; top: 199px; width:114px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $StrPvs;?>"/>

<div class="s1" style="left: 565px; top: 180px; width: 151px; cursor: pointer; color: #00F" 
onClick="InsPro()">PROVEEDOR</div>
<select name="CboPrv" id="CboPrv" 
class="lt" style="left: 564px; top: 199px; width: 333px;"
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("NOMBRE","vproveedores","ID>0",$StrPrv,"","S")?> 
</select>


<div class="s1" style="left: 31px; top:226px; width: 629px;">STOCKS ACTUAL</div>

<div id="DivSTOCK" class="s1" style="position:absolute; left: 31px; top: 241px; width: 867px; height: 24px;">
<?php
if(1==1){
echo "<table  border=\"0\"><tr>";      
$_IDP=$StrId;
if(strlen($_IDP)==0)$_IDP=0;
$s="SELECT id_almacen,alm_obs FROM almacenes WHERE id_almacen>= 0 ORDER BY alm_obs";
$result = grs($s);
while ($row = $result->fetch_row()){
echo "<td style=\"font-size:12px;\" width=\"50\">$row[1]:</td>";
$nn="TXT_ALM_".$row[0];
$zz=gn("stock","stocks","id_almacen=$row[0] AND id_producto=$_IDP");

echo "<td width=\"50\">";
echo "<input name=\"$nn\" type=\"text\" maxlength=\"4\" 
	  class=\"nei\" style=\"position:inherit;width:50px\" 
	  tabindex=".++$TI."  value=\"$zz\"/>";
echo "</td>";
}
echo "</tr></table>";
}
?>
</div>

<div class="s1" style="left: 31px; top: 268px; width: 629px;">STOCKS MINIMOS</div>
<div class="s1" id="DivSTOCKm" style="position:absolute; left: 31px; top: 286px; width: 865px; height: 24px;">
<?php
if(1==1){
echo "<table  border=\"0\"><tr>";      
$_IDP=$StrId;
if(strlen($_IDP)==0)$_IDP=0;
$s="SELECT id_almacen,alm_obs 
	FROM almacenes 
	WHERE id_almacen>= 0 ORDER BY alm_obs";
$result = grs($s);
while ($row = $result->fetch_row()){
echo "<td style=\"font-size:12px;\" width=\"50\">$row[1]:</td>";
$nn="TXT_MIN_".$row[0];
$zz=gn("cantidad","stockm","id_almacen=$row[0] AND id_producto=$_IDP");
echo "<td width=\"50\">";
echo "<input name=\"$nn\" type=\"text\" maxlength=\"4\" 
	  class=\"nei\" 
	  style=\"position:inherit;width:50px\" tabindex=".++$TI." value=\"$zz\" />";
echo "</td>";
}
echo "</tr></table>";
}
?>
</div>


<!--INI_BOTONES-------------------------------->
<div id="DivBtn" align="left" style="position:absolute; left: 33px; top: 71px; width:1000px; height: 26px;">
<input name="CmdB" type="button" id="CmdG" class="btm" 
<?php GOM($StrId);?>
onclick="fGuardar();"  
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" id="CmdC"  class="btm" 
value="Nuevo" onClick="fCancelar();"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdE" class="btm" 
value="Eliminar" onClick="fEliminar();"
<?php DIS($StrId);?>
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdB" class="btm"
value="Buscar" onClick="fBuscar('productos_buscar.php?CmdB=CallBack');"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdB"  class="btm"
value="Stock" onClick="fBuscar('rep_stock.php');"
tabindex="<?php echo ++$TI;?>" />
</div>
<!--FIN_BOTONES-------------------------------->


<div class="datagrid" style="position: absolute; left: 31px; top: 397px; ; width: 1180px; height: 180px; overflow:auto">
<table width="100%">
<thead>
<tr>
<td colspan="10" height="18" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>
</tr>
<tr>
<th width="13%">CODIGO</th>
<th width="19%">TIPO DE ARTICULO*</th>
<th width="47%">DESCRIPCION*</th>
<th width="15%">MARCA</th>
<th width="4%">STOCK</th>
<th width="2%">&nbsp;</th>
</tr>
</thead>
<tbody>


<?php	
	$s="SELECT ID,SUBSTRING(COD,1,10) AS COD,
		SUBSTRING(LINEA,1,26) AS LINEA,
		DESCRIPCION,MARCA 
		FROM vproductos
		WHERE ID> 0 
		ORDER BY LINEA,DESCRIPCION";	
	$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
	$result = grs($s);
	while ($r = $result->fetch_assoc()){
		$STOCK=gn("SUM(stock)","stocks","id_producto=".$r['ID']);
		?>
        <tr onDblClick="fActivar(<?php echo $r['ID'];?>);">
        <!----------------------------------------------->
        <td><?php echo $r['COD'];?></td>
        <td><?php echo $r['LINEA'];?></td>
       	<td><?php echo $r['DESCRIPCION'];?></td>
       	<td><?php echo $r['MARCA'];?></td>
        <td align="right"><?php echo $STOCK;?></td>
        <!----------------------------------------------->
        <td align="center">
        <a href="javascript:void(0)" onClick="fActivar(<?php echo $r['ID'];?>);">
        <img src="img/b_edit.png"  border="0"/></a></td>
        </tr>
		<?php
	}
?>		  

</tbody>
</table>
</div>

<!--INI_OCULTOS-------------------------------->
<?php include("ocultos.php");?>

<input name="FFab" type="hidden" id="FFab" onClick="fFabricantes();" />
<input name="FLin" type="hidden" id="FLin" onClick="fLinea();" />
<input name="FMod" type="hidden" id="FMod" onClick="fModelos();" />
<input name="FMar" type="hidden" id="FMar" onClick="fMarcas();" />
<input name="FUni" type="hidden" id="FUni" onClick="fUnidades();" />
<input name="FPro" type="hidden" id="FPro" onClick="fProveedores();" />
<!--FIN_OCULTOS-------------------------------->










<div class="s1" style="left: 31px; top: 317px; width: 766px;">
SELECCIONAR IMAGEN DEL PRODUCTO (LIMITE DE ESPACIO.. <span style="color:#F00">
TEMPORALMENTE ESTA OPCION HA SIDO BLOQUEADA)</span>	
</div>

<div align="left" style="position:absolute; left: 31px; top: 364px; width: 942px; font-size:11px; color:#F00; font-family:Verdana, Geneva, sans-serif">
<b>IMPORTANTE</b> LAS IMAGENES DEBEN SER DE EXTENSION .PNG DE PREFERENCIA MENOR A 200 Kb , SE DEBE INGRESAR UN CODIGO UNICO POR PRODUCTO, EN CASO DE CARGA MASIVA EL NOMBRE DE LA IMAGEN DEBE SER EL CODIGO DEL PRODUCTO CORRESPONDIENTE</div>

<div  align="left" style="position:absolute; left:31px; top: 334px; width: 658px; height: 24px">
<input name="Foto" type="file" id="Foto"  
tabindex="<?php echo ++$TI;?>"/>
</div>

<?php
	$IMG="vacio.png";
	$Z=0;
	$Y=0;
	if(vbval($StrId)>0){
		$COD=gs("pro_codigo","productos","id_producto=$StrId");
		if(strlen($COD)==0){
			$IMG="vacio.png";
		}else{
			if(!is_numeric($COD)){
				$IMG="fotos/".$COD.".png";
				if(!file_exists($IMG)){
					$IMG="vacio.png";
				}
			}else{
				$COD=vbval($COD)*1;
				$IMG="fotos/".$COD.".png";				
				$Z=1;
				$Y=$Y.$IMG."@";
				if(!file_exists($IMG)){
					$IMG="fotos/0".$COD.".png";
					$Z=2;
					$Y=$Y.$IMG."@";
					if(!file_exists($IMG)){
						$IMG="fotos/00".$COD.".png";
						$Z=3;
						$Y=$Y.$IMG."@";
						if(!file_exists($IMG)){
							$IMG="fotos/000".$COD.".png";
							$Z=4;
							$Y=$Y.$IMG."@";
							if(!file_exists($IMG)){
								$IMG="fotos/0000".$COD.".png";								
								$Z=5;
								$Y=$Y.$IMG."@";
								if(!file_exists($IMG)){
									$IMG="vacio.png";
								}
							}
						}
					}
				}
			}
		}		
	}
?>


<?php if(strlen($StrId)>0 && strlen(ImgA("fotos/pro".$StrId))>0){?>
<div id="FA" class="s1" style="left: 983px; top: 198px; width: 229px; height: 180px">
    <img src="<?php echo ImgA("fotos/pro".$StrId); ?> " width="100%" height="100%">   
    
    <div class="s1" style="left: 233px; top: 1px; width: 15px; height: 15px; color: #00F; cursor: pointer;" onClick="fEfoto()"><img src="img/el1.png" width="15" height="15"></div>
</div>
<?php }?>

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