<?
ini_set('error_reporting',1);
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = 'index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
$id_autoriza=33;
?>
<?
/*Sesiones*/
include("../conex.php");
include("../autoriza.php");
if ($editar==0)  
{
?>
		<script>
		alert ("No Autorizado");
		parent.location.href = 'index.php';
		</script>
	<? 
	exit();
}
$get_cod_producto = $_GET["cp"];
$sql_bpro = "SELECT * FROM productos WHERE codigo = $get_cod_producto AND empresa=$id_empresa";
$res_bpro = mysql_query($sql_bpro,$enlace);
if (mysql_fetch_object ($res_bpro))
	{
	$sql_codigo = mysql_result($res_bpro, 0, "codigo");
	$sql_descripcion = mysql_result($res_bpro, 0, "descripcion");
	$sql_precio = mysql_result($res_bpro, 0, "precio");
	$sql_saldo = mysql_result($res_bpro, 0, "saldo");
	$sql_unidad_medida = mysql_result($res_bpro, 0, "unidad_medida");
	$sql_costo = mysql_result($res_bpro, 0, "costo");
	$sql_u_entrada = mysql_result($res_bpro, 0, "u_entrada");
	$sql_u_salida = mysql_result($res_bpro, 0, "u_salida");
	$sql_cod_familia = mysql_result($res_bpro, 0, "cod_familia");
	$sql_proveedor = mysql_result($res_bpro, 0, "proveedor");
	$sql_observaciones = mysql_result($res_bpro, 0, "observaciones");
	$sql_cod_fabricante = mysql_result($res_bpro, 0, "codigo_fabricante");
	$sql_cod_eq_prov = mysql_result($res_bpro, 0, "codigo_equivalente_proveedor");
	$sql_unidades = mysql_result($res_bpro, 0, "unidades");
	$sql_caja = mysql_result($res_bpro, 0, "caja");
	$sql_ven_prod_param = mysql_result($res_bpro, 0, "vencimiento_producto_param");
	$sql_inv_prod = mysql_result($res_bpro, 0, "inventariable");
	$sql_prod_ser_param = mysql_result($res_bpro, 0, "producto_seriado_param");
	$sql_peso = mysql_result($res_bpro, 0, "peso");
	$sql_volumen = mysql_result($res_bpro, 0, "volumen");
	$sql_impuestos1 = mysql_result($res_bpro, 0, "impuestos1");
	$sql_impuesto2 = mysql_result($res_bpro, 0, "impuesto2");
	
	
	}

else
	{
		$sql_codigo = $get_cod_producto;
	}
	
if ($sql_unidades == '') $sql_unidades = 1;
if ($sql_caja == '') $sql_caja = 1;	
if ($sql_codigo==0) $sql_inv_prod='S';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Nuevo Producto</title>
<style type="text/css">
<!--
body {
	background-color: #CCCCCC;
	margin-left: 0px;
	margin-top: 3px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.Estilo7 {
	font-size: small;
	color: #000099;
}
.Estilo11 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small; color: #000099; }
.Estilo13 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	color: #000099;
	text-decoration: underline;
}
.Estilo14 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	color: #000099;
}
.titulos2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 13px;
	color: #003366;
	background-color: #CCCCCC;
	font-style: normal;
	font-weight: bold;
}
.botones {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	height:26px;
}
-->
</style>

</head>

<table width="90%" border="0" align="center">
	<tr>
		<td><div align="center" class="titulos2">
		Editar Producto
		</div></td>
	</tr>
</table>
<body vlink="#2293ff" alink="#2293ff" link="#2293ff" onLoad="validacodigo();">
<form name="form1" method="post" action="guardae_producto.php">
<div align="left" class="titulos2" style="font-size:12px">

  <table width="90%" border="1" align="center">
	 <tr>
      <td>Codigo</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcodigo" type="text" id="txtcodigo" value="<?=$sql_codigo?>" readonly="1" size="40""></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	 <tr>
      <td>Descripción</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtdescripcion" type="text" id="txtdescripcion" size="40" value="<?=$sql_descripcion?>"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Precio (Con IVA) </td>
      <td height="1px">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtprecio" type="text" id="txtprecio" size="40" value="<?=$sql_precio?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	   <td>Saldo</td>
      <td height="1px">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtsaldo" type="text" id="txtsaldo" size="40" value="<?=$sql_saldo?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Unidad de Medida </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="40%">
			<?
			$sql_umed = "SELECT * FROM unidad_medida ORDER BY descripcion";
			$res_umed = mysql_query($sql_umed,$enlace);
			$cont=0;
			?>
              <select name="lstum" id="lstum" style="width:267px">
			  <?
			  while (mysql_fetch_object ($res_umed))
				{
				$sql_umed_cod = mysql_result($res_umed, $cont, "codigo");
				$sql_umed_nom = mysql_result($res_umed, $cont, "nomenclatura");
				$sql_umed_des = mysql_result($res_umed, $cont, "descripcion");
				if ($sql_umed_des=='Unidad'){
			?>
                <option value="<?=$sql_umed_cod?>" selected="selected"><? echo $sql_umed_des." (".$sql_umed_nom.")";?></option>
			<?
					}
				else
					{
			?>
                <option value="<?=$sql_umed_cod?>"><? echo $sql_umed_des." (".$sql_umed_nom.")";?></option>
			<?
					}
				$cont = $cont+1;
			}
			?>
              </select>
            </td>
            <td width="60%">&nbsp;&nbsp;<a onClick="JavaScript:PopWindow('<? echo "1";?>')"><IMG align="middle" border="0" src="../Images/modificar.gif" style="visibility:hidden;cursor:pointer" title="Presione aqui para buscar producto" width="16" height="16"></a></td>
          </tr>
        </table></td>
    </tr>
	  <td>Costo (Con IVA) </td>
        <td height="1px">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcosto" type="text" id="txtcosto" size="40" value="<?=$sql_costo?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Unidad de Entrada</td>
      <td height="1px">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtuentrada" type="text" id="txtuentrada" size="40"  value="<?=$sql_u_entrada?>" readonly="1"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	      <td>Unidad de Salida</td>
      <td height="1px">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtusalida" type="text" id="txtusalida" size="40" value="<?=$sql_u_salida?>" readonly="1"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
      <td>Familia</td>
      <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="40%">
            
			<?
			$sql_fam = "SELECT * FROM familia ORDER BY descripcion";
			$res_fam = mysql_query($sql_fam,$enlace);
			$cont=0;
			?>
              <select name="lstfamilia" id="lstfamilia" style="width:267px">
			  <?
			  while (mysql_fetch_object ($res_fam))
				{
				$sql_fam_cod = mysql_result($res_fam, $cont, "id");
				$sql_fam_des = mysql_result($res_fam, $cont, "descripcion");
				if ($sql_fam_cod==$sql_cod_familia){
			?>
                <option value="<?=$sql_fam_cod?>" selected="selected"><? echo $sql_fam_des;?></option>
			<?
				}
			else
				{
			?>
                <option value="<?=$sql_fam_cod?>"><? echo $sql_fam_des;?></option>
			<?
				}
				$cont = $cont+1;
			}
			?>
              </select>
			
          </td>
          <td width="60%">&nbsp;&nbsp;<a onClick="JavaScript:PopWindow('<? echo "2";?>')"><IMG align="middle" border="0" src="../Images/modificar.gif" style="visibility:hidden;cursor:pointer" title="Presione aqui para buscar producto" width="16" height="16"></a></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>Proveedor</td>
      <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="40%">
						<?
			$sql_prov = "SELECT * FROM nombres WHERE proveedor = 'True' ORDER BY razon_social";
			$res_prov = mysql_query($sql_prov,$enlace);
			$cont=0;
			?>
              <select name="lstproveedor" id="lstproveedor" style="width:267px">
			  <?
			  while (mysql_fetch_object ($res_prov))
				{
				$sql_prov_cod = mysql_result($res_prov, $cont, "rut");
				$sql_prov_des = mysql_result($res_prov, $cont, "razon_social");
				if ($sql_proveedor==$sql_prov_cod){
			?>
                <option value="<?=$sql_prov_cod?>" selected="selected"><? echo $sql_prov_des;?></option>
			<?
					}
				else
					{
			?>
                <option value="<?=$sql_prov_cod?>"><? echo $sql_prov_des;?></option>
			<?
					}
				$cont = $cont+1;
			}
			?>
              </select>
              
			</td>
            <td width="60%">&nbsp;&nbsp;<a onClick="JavaScript:PopWindow('<? echo "3";?>')"><IMG align="middle" border="0" src="../Images/modificar.gif" style="visibility:hidden;cursor:pointer;" title="Presione aqui para buscar producto" width="16" height="16"></a></td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Observaciones</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtobs" id="txtobs" type="text" size="40" value="<?=$sql_observaciones?>"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>C&oacute;digo Fabricante </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcodfabricante" type="text" size="40" value="<?=$sql_cod_fabricante?>"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>C&oacute;digo Equivalente Proveedor </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcodeqprov" id="txtcodeqprov" type="text" size="40" value="<?=$sql_cod_eq_prov?>"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Unidades</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtunidades" type="text" size="40" value="<?=$sql_unidades?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Caja</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcaja" type="text" size="40" value="<?=$sql_caja?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Inventariable </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="inv_prod" type="checkbox" id="inv_prod" value="1" <? if ($sql_inv_prod=='S') { ?> checked="checked" <? }?>></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	<tr>
      <td>Vencimiento Producto </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="ven_prod" type="checkbox" id="ven_prod" value="1" <? if ($sql_ven_prod_param==1) { ?> checked="checked" <? }?>></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Producto Seriado </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td>

			<select name="lstser" id="lstser" style="width:267px">
            <option value="0" <? if ($sql_prod_ser_param==0) { ?>selected="selected" <? }?>>Sin Seriado</option>
			<option value="1" <? if ($sql_prod_ser_param==1) { ?>selected="selected" <? }?>>Seriado Vehicular</option>
			<option value="2" <? if ($sql_prod_ser_param==2) { ?>selected="selected" <? }?>>Seriado Simple</option>
            </select></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Peso</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtpeso" id="volumen" type="text" size="40" value="<?=$sql_peso?>" onKeyPress="return valida2(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Volumen</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtvolumen" id="volumen" type="text" size="40" value="<?=$sql_volumen?>" onKeyPress="return valida2(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	 <tr>
      <td>Impuestos 1</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtimpuestos1" type="text" size="40" value="<?=$sql_impuestos1?>" onKeyPress="return valida2(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	 <tr>
      <td>Impuestos 2</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtimpuesto2" type="text" size="40" value="<?=$sql_impuesto2?>" onKeyPress="return valida2(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
  </table>
  
  <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td>&nbsp;</td>
      <td><div align="center">
        <label>
        <input type="button" name="Submit" value="Guardar" onClick="enviar();">
        </label>
      </div></td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>
</form>
<script language="javascript">
var nav4 = window.Event ? true : false;
<!-- Ingreso solo letras -->
function valida(evt){
var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));
	}
function valida2(evt){
var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57) || key==46);
	}


function validacodigo()
	{
	if (document.form1.txtsaldo.value!=0) 
		{ 
		document.form1.txtsaldo.readOnly=1;
		}
	else
		{ 
		document.form1.txtcosto.readOnly=0;
		}
		if (document.form1.txtcosto.value!=0) 
		{ 
		document.form1.txtcosto.readOnly=1;
		}
	else
		{ 
		document.form1.txtcosto.readOnly=0;
		}

	}
function enviar()
	{
	if (document.form1.txtdescripcion.value=='')
		{
		alert('Ingrese Descripcion');
		document.form1.txtdescripcion.focus();
		return false;
		}
	if (document.form1.txtprecio.value=='')
		{
		alert('Ingrese Precio');
		document.form1.txtprecio.focus();
		return false;
		}
	if (document.form1.txtsaldo.value=='')
		{
		alert('Ingrese Saldo');
		document.form1.txtsaldo.focus();
		return false;
		}
	if (document.form1.txtcosto.value=='')
		{
		alert('Ingrese Costo');
		document.form1.txtcosto.focus();
		return false;
		}
	if (document.form1.txtunidades.value=='')
		{
		alert('Ingrese Unidades');
		document.form1.txtunidades.focus();
		return false;
		}		
	if (document.form1.txtcaja.value=='')
		{
		alert('Ingrese Caja');
		document.form1.txtcaja.focus();
		return false;
		}		
	if (document.form1.txtpeso.value=='')
		{
		document.form1.txtpeso.value='1';
		}
	if (document.form1.txtvolumen.value=='')
		{
		document.form1.txtvolumen.value='1';
		}
	document.form1.submit();

	}
</script>