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

$query="SELECT * FROM articulos WHERE referencia='$codarticulo'";
$rs_query=mysql_query($query);


$codunidad=mysql_result($rs_query,0,"codunidad");
$codfamilia=mysql_result($rs_query,0,"codfamilia");
$codprov=mysql_result($rs_query,0,"identidad");
$nom_prov=mysql_result($rs_query,0,"nombre");


//nombre familia
	   $query_familia="SELECT * FROM grupos WHERE idgrupos='$codfamilia'";
	   $res_familia=mysql_query($query_familia);
	   $nom_familia=mysql_result($res_familia,0,"nombre_grupo");
//nombre unidad
	   $query_unidad="SELECT * FROM unidad WHERE codunidad='$codunidad'";
	   $res_unidad=mysql_query($query_unidad);
	   $nom_unidad=mysql_result($res_unidad,0,"nombre");

//nombre suscursal
	   //$query_nom="SELECT * FROM sucu WHERE codsucu='$sucu'";
	   //$res_nom=mysql_query($query_nom);
	   //$nom_sucu=mysql_result($res_nom,0,"nombre");
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
  

    <meta charset="utf-8">
    <title></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>  
     <link href="../../../calendario/calendar-blue.css" rel="stylesheet" type="text/css">
	<script type="text/JavaScript" language="javascript" src="../../../calendario/calendar.js"></script>
	<script type="text/JavaScript" language="javascript" src="../../../calendario/lang/calendar-sp.js"></script>
	<script type="text/JavaScript" language="javascript" src="../../../calendario/calendar-setup.js"></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=formulario.codigo.value;
		  var fam=formulario.familia.value;
		  var des=formulario.des.value;
		  var stk=formulario.stock.value;
		  var stk_min=formulario.stock_minimo.value;
		  var fec=formulario.fecha.value;
		  
		  //detalles compra
		  var ident=formulario.identidad.value;
		  var nom=formulario.nombre.value;
		  var n_compra=formulario.neto_compra.value;
		  var i_compra=formulario.iva_compra.value;
		  var t_compra=formulario.total_compra.value;
		  
		  //detalles venta
		  
		  var n_venta=formulario.neto_venta.value;
		  var i_venta=formulario.iva_venta.value;
		  var t_compra=formulario.total_venta.value;
		  
		  var desc=formulario.descuento.value;
          var obs=formulario.obs.value;

		   
		  //preguntamos si no hay campos vacios
		  if(cod!="" && fam!="" && stk!="" && fec!="" && t_compra!="" && t_venta!="" && desc!="")
		  {
		      //Enviamos mediante el metodo post de JQuery $.post("archivo.php",{parametros}, callback);
		      $.post("mod_reg.php", {enviar:formulario.enviar.value, codigo:cod, familia:fam, des:des, stock:stk,stock_minimo:stk_min, fecha:fec,neto_compra:n_compra,iva_compra:i_compra,total_compra:t_compra, neto_venta:n_venta,iva_venta:i_venta,total_venta:t_venta,descuento:desc,obs:obs}, function(output){
			    //El parametro output, recibe como salida lo generado por el script php
				alert(output);
				//con esta linea limpiamos el formulario
				document.formulario.reset();
		      });
		  }
		  else
		  {
			  alert("Campos obligatorios (*) vacios!");
		  }
	  });
  });
  
  function proveedor(){
			miPopup = window.open("ver_residente.php","residente","width=700,height=380,scrollbars=yes");
			miPopup.focus();
		}

function v_total(){
			miPopup = window.open("calc_venta.php?total_venta_uno="+document.getElementById('total_venta_uno').value+"","residente","width=250,height=150,scrollbars=yes");
			miPopup.focus();
		}

function c_total(){
			miPopup = window.open("calc_compra.php?total_venta_uno="+document.getElementById('total_compra').value+"","residente","width=250,height=150,scrollbars=yes");
			miPopup.focus();
		}

function c_total2(){
			miPopup = window.open("calc_compra2.php?total_venta_uno="+document.getElementById('neto_compra').value+"","residente","width=250,height=150,scrollbars=yes");
			miPopup.focus();
		}
		
</script>
<script type='text/javascript' src='jquery-1.7.1.min.js'></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>Modificar Articulos</h3>
     <p >
       <form id="formulario" name="formulario" method="post" action="mod_reg.php" enctype="multipart/form-data" >
         <fieldset><legend>Modificar registro</legend>
         <table width="729">
           
           <tr>
             <td width="140" height="32" align="right">Código de producto:</td>
             <td colspan="2"><input style="background-color:#CCC" name="codigo" type="text" id="codigo" value="<?php echo mysql_result($rs_query,0,"referencia")?>" readonly  /></td>
           </tr>
           <tr>
             <td height="30" align="right">Familias: </td>
             <?    $query_familias="SELECT * FROM familias WHERE borrado=0 ORDER BY nombre ASC";
						$res_familias=mysql_query($query_familias);
						$contador=0;
				  ?>
             <td colspan="2"><select id="familia" name="familia" >
               <option value="<? echo $codfamilia; ?>">
                 <?  echo $nom_familia; ?>
                 </option>
                 
               <option value="">
                 ---
                 </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="6" align="right">Descripción:</td>
             <td colspan="2"><input type="text" name="des" id="des" value="<?php echo mysql_result($rs_query,0,"descripcion")?>" /></td>
           </tr>
           <tr>
             <td height="7" align="right">Unidad de medida: </td>
             <td colspan="2">
              <?    $query_unidad="SELECT * FROM unidad WHERE borrado=0 ORDER BY nombre ASC";
						$res_unidad=mysql_query($query_unidad);
						$contador=0;
				  ?>
       <select id="unidad" name="unidad" >
         <option value="<? echo $codunidad ?>">
           <?  echo $nom_unidad ?>
           </option>
           
            <option value="">
                 ---
                 </option>
         <?php
								while ($contador < mysql_num_rows($res_unidad)) { ?>
         <option value="<?php echo mysql_result($res_unidad,$contador,"codunidad")?>"><?php echo mysql_result($res_unidad,$contador,"nombre")?></option>
         <? $contador++;
								} ?>
       </select>
             
             </td>
           </tr>
           <tr>
             <td height="7" align="right">Stock mínimo: </td>
             <td colspan="2"><input type="text" name="stock_minimo" id="stock_minimo"
             value="<?php echo mysql_result($rs_query,0,"stock_minimo")?>" /></td>
           </tr>
           <tr>
             <td height="26" align="right">Fecha de ingreso:</td>
             <td width="125"><input name="fecha" type="text" id="fecha" value="<?php echo mysql_result($rs_query,0,"fecha_alta")?>" readonly /></td>
             <td width="448">
             <img src="../../images/postdateicon.png" name="Image1" id="Image1">
        <script type="text/javascript">
					Calendar.setup(
					  {
					inputField : "fecha",
					ifFormat   : "%Y-%m-%d",
					button     : "Image1"
					  }
					);
		</script>
             
             </td>
           </tr>
           <tr>
             <td height="2" colspan="3" align="right">
              <fieldset>
         <legend>Detalles de compra</legend>
           
              
                 <table width="651" border="0">
                   <tr>
                     <td width="127">R.U.T. (Proveedor):</td>
                     <td width="122"><input name="identidad" type="text" style="background-color:#CCC" id="identidad" value="<? echo $codprov ?>" readonly /></td>
                     <td width="82"><img src="../../images/searchicon.png" alt="" width="16" height="16" onClick="proveedor()"></td>
                     <td width="302"><input name="nombre" value="<? echo $nom_prov; ?>" type="text" id="nombre" style="background-color:#CCC"
    size="60"readonly></td>
                   </tr>
                   <tr>
                     <td>NETO:</td>
                     <td><input type="text" name="neto_compra" id="neto_compra" 
                     value="<?php echo mysql_result($rs_query,0,"neto_compra")?>" ></td>
                     <td><img src="../../../images/calculadora.jpg" alt="" width="16" height="16" onClick="c_total2()"></td>
                     <td>&nbsp;</td>
                   </tr>
                   <tr>
                     <td>IVA:</td>
                     <td colspan="3"><input name="iva_compra" type="text" id="iva_compra" style="background-color:#CCC" readonly value="<?php echo mysql_result($rs_query,0,"iva_compra")?>" > </td>
                   </tr>
                   <tr>
                     <td>TOTAL: </td>
                     <td><input name="total_compra" type="text" id="total_compra" value="<?php echo mysql_result($rs_query,0,"precio_compra")?>" > </td>
                     <td><img src="../../../images/calculadora.jpg" alt="" width="16" height="16" onClick="c_total()"></td>
                     <td>&nbsp;</td>
                   </tr>
                 </table>
             
          </fieldset>     

             
             </td>
           </tr>
           <tr>
             <td height="0" colspan="3" align="right">
             
             <fieldset>
            <legend>Detalles de venta sucursal</legend>
       
              <table width="406" border="0">
                <tr>
                  <td width="75">NETO:</td>
                  <td colspan="2"><input type="text" name="neto_venta_uno" id="neto_venta_uno"
                style="background-color:#CCC" value="<?php echo mysql_result($rs_query,0,"neto_tienda")?>" 
                 readonly="readonly"  ></td>
                </tr>
                <tr>
                  <td>IVA:</td>
                  <td colspan="2"><input type="text" name="iva_venta_uno" id="iva_venta_uno"  
                style="background-color:#CCC"
                 readonly="readonly" value="<?php echo mysql_result($rs_query,0,"iva_tienda")?>" > </td>
                </tr>
                <tr>
                  <td>TOTAL: </td>
                  <td width="123"><input type="text" name="total_venta_uno" id="total_venta_uno" value="<?php echo mysql_result($rs_query,0,"precio_tienda")?>" > </td>
                  <td width="194"><img src="../../../images/calculadora.jpg" alt="" width="16" height="16" onClick="v_total()"></td>
                </tr>
              </table>
                     </fieldset>
         
             </td>
             </tr>
           <tr>
             <td colspan="3" align="right">
               <input type="hidden" name="descuento" id="descuento" value="<?php echo mysql_result($rs_query,0,"des")?>" />
               
               <input type="hidden" name="foto1" id="foto1">
               
               <p>
                 <?
      
        $sql=  mysql_query("select * from articulos where referencia='$codarticulo'");
        while($res=  mysql_fetch_array($sql)){
           
            echo '';
        }
		?>
                 
                 <input type="hidden" name="obs" id="obs" value="<?php echo mysql_result($rs_query,0,"obs")?>" />
               
               </td>
           </tr>
           <tr>
             <td colspan="3" align="right">
               <input type="submit" id="enviar" name="enviar" value="Modificar" class="art-button" />
               
               <input type="button" value="Cerrar ventana" class="art-button" onClick="cerrar()" /></td>
           </tr>
         </table>
       </fieldset>
       </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 © <? echo $ano ?>. 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>