<? 
$nivel = $_GET["nivel"];
$nombrevar =$_GET["nombreuser"];
$codigo =$_GET["codigo"];
$numero =$_GET["num"];
$hoy=date("Y-m-d");
require_once('../../conf/connection.php');

            
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
  

    <meta charset="utf-8">
    <title>INVENTARIO</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">

    <!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <link rel="stylesheet" href="../../style.css" media="screen">
    <!--[if lte IE 7]><link rel="stylesheet" href="../style.ie7.css" media="screen" /><![endif]-->
    <link rel="stylesheet" href="../../style.responsive.css" media="all">

    <script src="../../jquery.js"></script>
    <script src="../../script.js"></script>
    <script src="../../script.responsive.js"></script>



<style>.art-content .art-postcontent-0 .layout-item-0 { border-top-width:1px;border-top-style:solid;border-top-color:#B1C9C7;margin-top: 10px;margin-bottom: 10px;  }
.art-content .art-postcontent-0 .layout-item-1 { border-right-style:solid;border-right-width:1px;border-right-color:#B1C9C7; padding-right: 10px;padding-left: 10px;  }
.ie7 .art-post .art-layout-cell {border:none !important; padding:0 !important; }
.ie6 .art-post .art-layout-cell {border:none !important; padding:0 !important; }

</style>
    <script>
$(document).ready(function(){
// Demo 5
$('#identidad').Rut({
  on_error: function(){ alert('Rut incorrecto'); },
  format_on: 'keyup' 
});
$("#content > ul").tabs();
});

function cerrar() {
			window.close();
		}
		
</script>  
 <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
   <script src="js/jquery.Rut.js" type="text/javascript"></script>
  <script type="text/javascript" src="../../funciones/scripts.js"></script>
  <script type="text/javascript">

 //He aqui la magia de AJAX gracias al Framework JQuery!
  $(document).ready(function(){
	  //programamos el vento click del boton enviar del formulario
	  $("#enviar").click(function() {
		  
		  //Variables del formulario
		  var cod=frm_add.codigo.value;
		  var fam=frm_add.familia.value;
		  var des=frm_add.des.value;
		  var stk=frm_add.stock.value;
		  var fec=frm_add.fecha.value;
		  var p_comp=frm_add.precio_compra.value;
		  var p_vent=frm_add.precio_venta.value;
		  var desc=frm_add.descuento.value;
		  var des=frm_add.des.value;

		   
		  //preguntamos si no hay campos vacios
		  if(cod!="" && fam!="" && stk!="" && fec!="" && p_comp!="" && p_vent!="" && desc!="")
		  {
		      //Enviamos mediante el metodo post de JQuery $.post("archivo.php",{parametros}, callback);
		      $.post("add_reg2.php", {enviar:frm_add.enviar.value, codigo:cod, familia:fam, des:des, stock:stk, fecha:fec, precio_compra:p_comp, precio_venta:p_vent, descuento:desc, des:des}, function(output){
			    //El parametro output, recibe como salida lo generado por el script php
				alert(output);
				//con esta linea limpiamos el formulario
		
				window.close();
		      });
		  }
		  else
		  {
			  alert("Campos obligatorios (*) vacios!");
		  }
	  });
  });
</script>
</head>
<body>
<div id="art-main">

<div class="art-sheet clearfix">
            <div class="art-layout-wrapper">
                <div class="art-content-layout">
                  <div class="art-content-layout-row">
                    <div class="art-layout-cell art-content"><article class="art-post art-article">
                                
                                                
                                <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-1" style="width: 100%" >
        <h3>Agregar producto</h3>
     <p >
       <form id="frm_add" name="frm_add" method="post">
   <table width="514">
     <tr>
       <td height="6" colspan="2"><strong>FORMULARIO DE INGRESO</strong></td>
     </tr>
     
     <tr>
       <td width="168" height="32" align="right">CODIGO DE PRODUCTO</td>
       <td width="334"><input type="text" name="codigo" id="codigo" value="<? echo $codigo; ?>" autofocus  /></td>
     </tr>
     <tr>
       <td height="30" align="right">FAMILIA</td>
                  <?    $query_familias="SELECT * FROM familias WHERE borrado=0 ORDER BY nombre ASC";
						$res_familias=mysql_query($query_familias);
						$contador=0;
				  ?>
       <td><select id="familia" name="familia" >
							
								<option value="<? echo $cd_familia ?>"><?  echo $cd_nombre?></option>
								<?php
								while ($contador < mysql_num_rows($res_familias)) { ?>
								<option value="<?php echo mysql_result($res_familias,$contador,"codfamilia")?>"><?php echo mysql_result($res_familias,$contador,"nombre")?></option>
								<? $contador++;
								} ?>				
								</select></td>
     </tr>
     <tr>
       <td height="15" align="right">DESCRIPCION DEL PRODUCTO</td>
       <td><input type="text" name="des" id="des" /></td>
     </tr>
     <tr>
       <td height="16" align="right">STOCK </td>
       <td><input name="stock" type="text" id="stock" style="background:#999" value="0" readonly /></td>
     </tr>
     <tr>
       <td height="26" align="right">FECHA DE INGRESO</td>
       <td><input name="fecha" type="text" id="fecha" value="<? echo $hoy; ?>" readonly /></td>
     </tr>
      <tr>
        <td height="2" colspan="2" align="right"><strong>DETALLES DE VENTAS </strong></td>
      </tr>
      <tr>
        <td height="0" align="right">PRECIO DE COMPRA</td>
        <td height="0" align="right"><input name="precio_compra" type="text" id="precio_compra" size="15" maxlength="15" /></td>
      </tr>
      <tr> 
        <td height="-1" align="right">PRECIO DE VENTA </td>
        <td height="-1" align="right"><input type="text" name="precio_venta" id="precio_venta" /></td>
      </tr>
      <tr>
        <td height="-1" align="right">DESCUENTO MAXIMO</td>
        <td height="-1" align="right"><input name="descuento" type="text" id="descuento" value="0" readonly /></td>
      </tr>
     
     <tr>
       <td colspan="2" align="right"><input type="button" id="enviar" name="enviar" value="Guardar" class="art-button" />
         <input type="reset" id="cancel" name="cancel" value="Cancelar" class="art-button" />
         <input type="submit" value="Cerrar ventana" class="art-button" onClick="cerrar()" /></td>
     </tr>
     </table>
</form>
 

     
     <hr> </p>
     <p align="left">  
     <div id="resultado">
     </div></p>
    
    </div>
    </div>
</div>
<div class="art-content-layout-br layout-item-0">
</div></div>


</article></div>
                    </div>
                </div>
            </div><footer class="art-footer">

<p>Copyright © 2015. All Rights Reserved.</p>
</footer>

    </div>
    <p class="art-page-footer">
        <span id="art-footnote-links">Informatica Francisco Arias E.I.R.L.</span>
    </p>
</div>


</body></html>