<?php
 include ("emenux.php"); 
 require ("conecta.php");
 $sw=$_POST['hdsw'];
 $sw2=$_POST['hdsw'];
 $cod_interno=strtoupper($_POST['cod_interno']);
 $cod_barra="";
 $cod_origen="";
 $glosa="";
 $cod_familia="";
 $cod_linea="";
 $cod_marca="";
 $modelos="";
 $fact_comisi="";
 $stock_min="";
 $fecha_agotamiento="";
 $fec_ult_venta="";
 $fec_ult_compra="";
 $cont=0;
 $error2= "0";
 $recomendacion2="0";
 if ($sw=="buscar"){
  $sqlb="select * from m07001 where cod_interno = '$cod_interno' ;";
  $resb=mysql_query($sqlb,$con);
  if (mysql_num_rows($resb)>0){ 
   $sw="encontrado";
   $sw2="encontrado";
   while ($filab = mysql_fetch_row($resb)){
    $cod_barra=$filab[1];
 	$cod_origen=$filab[2];
	$glosa=$filab[3];
	$cod_familia=$filab[4];
	$cod_linea=$filab[5];
	$cod_marca=$filab[6];
	$modelos=$filab[7];
	$fact_comisi=$filab[8];
	$stock_min=$filab[9];
	$fecha_agotamiento=$filab[10];
	$fec_ult_venta=$filab[11];
	$fec_ult_compra=$filab[12];
   }//while
  }else{
   $error2= "Codigo no encontrado.";
   $recomendacion2="->Agregar.";
  }//fin si
 }//fin de buscar
 if ($sw=="grabar"){
  $cod_interno=strtoupper($_POST['cod_interno']);
  $cod_barra=$_POST['cod_barra'];
  $cod_origen=$_POST['cod_origen'];
  $glosa=$_POST['glosa'];
  $cod_familia=$_POST['hdcod_familia'];
  $cod_linea=$_POST['hdcod_linea'];
  $cod_marca=$_POST['hdcod_marca'];
  $modelos=$_POST['modelos'];
  $fact_comisi=$_POST['fact_comisi'];
  $stock_min=$_POST['stock_min'];
  $fecha_agotamiento=$_POST['fecha_agotamiento'];
  $fec_ult_venta=$_POST['fec_ult_venta'];
  $fec_ult_compra=$_POST['fec_ult_compra'];
  $sqlg="replace into m07001   (cod_interno,cod_barra,cod_origen,glosa,cod_familia,cod_linea,cod_marca,modelos,fact_comisi,stock_min,fecha_agotamiento,fec_ult_venta,fec_ult_compra)
   values ('$cod_interno','$cod_barra','$cod_origen','$glosa','$cod_familia','$cod_linea','$cod_marca','$modelos','$fact_comisi','$stock_min','$fecha_agotamiento','$fec_ult_venta','$fec_ult_compra');";
  $resg=mysql_query($sqlg,$con); 
  $cod_interno="";
  $cod_barra="";
  $cod_origen="";
  $glosa="";
  $cod_familia="";
  $cod_linea="";
  $cod_marca="";
  $modelos="";
  $fact_comisi="";
  $stock_min="";
  $fecha_agotamiento="";
  $fec_ult_venta="";
  $fec_ult_compra="";
  $sw=""; 
 }//fin grabar 
 if ($sw=="eliminar"){
  $sqle="delete from m07001 where cod_interno='$cod_interno';";
  mysql_query($sqle,$con);
  $cod_interno="";
  $cod_barra="";
  $cod_origen="";
  $glosa="";
  $cod_familia="";
  $cod_linea="";
  $cod_marca="";
  $modelos="";
  $fact_comisi="";
  $stock_min="";
  $fecha_agotamiento="";
  $fec_ult_venta="";
  $fec_ult_compra="";
  $sw="";
 }//fin si de eliminar
// if (strlen($codcomuna)==0){$codcomuna="5406";}
// if (strlen($codcpago)==0){$codcpago="001";}
 //if (strlen($sexo)==0){$sexo="1";}
?>
<!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>
<TITLE>Maestro Articulos</TITLE>
<script language="javascript" src="fstandar.js">
</script>
<script language="javascript">
function ponefamilia(){
 document.form1.hdcod_familia.value=document.form1.cmbfamilia.value;
 //window.alert(document.form1.hdcod_familia.value);
}

function ponelinea(){
 document.form1.hdcod_linea.value=document.form1.cmblinea.value;
 //window.alert(document.form1.hdcod_linea.value);
}
function ponemarca(){
 document.form1.hdcod_marca.value=document.form1.cmbmarca.value;
 //window.alert(document.form1.hdcod_marca.value);
}
function valida(){ 
 if (document.form1.cod_interno.value.length > 0){
  err=0;
  if (err==0){
   document.form1.hdsw.value="grabar";
   document.form1.action="M0701001.php";
   document.form1.method="post";
   document.form1.submit();
  }
 }//fin si  
}  
function buscarut(){
if (document.form1.cod_interno.value.length > 0){
//  document.form1.cod_interno.style.backgroundColor="#FFFFFF";
  document.form1.hdsw.value="buscar";
  document.form1.action="M0701001.php";
  document.form1.method="post";
  document.form1.submit();
 }
}
function eliminar(){
 if(window.confirm("Seguro desea eliminar?")==true){
  document.form1.hdsw.value="eliminar";
  document.form1.action="M0701001.php";
  document.form1.method="post";
  document.form1.submit();
 }
}//fin eliminar 
</script>
<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {color: #FF0000}
.Estilo2 {color: #0000FF}
-->
</style>
</HEAD>
<BODY <?php
 if ($sw2=="buscar"){
  echo "onload='javascript:(document.form1.cod_barra.focus())'";
  }
 if ($sw2=="grabar" || $sw2=="eliminar"){
  echo "onload='javascript:(document.form1.cod_interno.focus())'";
  } 
 if ($sw2=="encontrado" ){
  echo "onload='javascript:(document.form1.cmdgra.focus())'";
  }  
  ?>>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle height="100%">
      <TABLE height=400 cellSpacing=0 cellPadding=0 width=718 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE height=22 cellSpacing=0 cellPadding=0 width="100%" 
              border=0><TBODY>
              <TR>
                <TD vAlign=top align=left width=24><A 
                  href="index.php"><IMG 
                  height=22 src="images/xc_left.gif" width=24 
                  border=0></A></TD>
                <TD vAlign=top align=left width="100%"><IMG height=22 
                  src="images/xc_center.gif" width="100%" 
                border=0></TD>
              <TD vAlign=top align=right width=24><IMG height=22 
                  src="images/xc_right.gif" width=24 
              border=0></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=BottomTable vAlign=top 
          background=images/xc_stripes.gif height="100%">
            <TABLE class=IconsTable height=33 cellSpacing=0 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD height="32"><div align="right" class="larger">
                  <div align="right">Vemol</div>
                </div></TD>
                </TR></TBODY></TABLE>
            <TABLE cellSpacing=0 cellPadding=0 width="715" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD vAlign=top align=left width=180 height=18>&nbsp;</TD>
                <TD width=12 height=18>&nbsp;</TD>
                <TD width="461" height=18 class=MainMenuHead>Articulos:</TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD vAlign=top align=left width=180 height="100%">
                  <TABLE cellSpacing=0 cellPadding=0 width="150" border=0>
                    <TBODY>
                    <TR>
                      <TD width=10 valign="top"><IMG height=12 
                        src="images/xc_dotgrey.gif" width=10></TD>
                      <TD width=4>&nbsp;</TD>
                      <TD class=LeftMenu noWrap>Ingreso de Articulos:<br />
                        -&gt;Agregar.<br />
-&gt;Modificar.<br />
-&gt;Eliminar.</TD>
                    </TR>
                    <tr>
                      <td valign="top"><img height="12" 
                        src="images/xc_dotgrey.gif" width="10" /></td>
                      <td>&nbsp;</td>
                      <td class="LeftMenu" nowrap="nowrap">Alertas:<span class="Estilo1"><br />
                            <?php echo $error2 ?></span></td>
                    </tr>
                    <tr>
                      <td valign="top"><img 
                        src="images/xc_dotgrey.gif" alt="1" width="10" height="12" /></td>
                      <td>&nbsp;</td>
                      <td class="LeftMenu" nowrap="nowrap">Se recomienda:<span class="Estilo2"><br />
                            <?php echo $recomendacion2 ?></span></td>
                    </tr>
                    </TBODY></TABLE></TD>
                <TD width=12 height="100%">&nbsp;</TD>
                <TD class=contentcell vAlign=top align=middle width=461 
                height="100%">
                  <TABLE width="100%">
                    <TBODY>
                    <TR>
                      <TD>
                        <form name="form1" method="post" action="">
                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <th scope="col"><div align="right" class="Emphasize">Codigo Interno:</div></th>
                              <th scope="col"><div align="left">
                                <input name="cod_interno" type="text" id="cod_interno" onblur="buscarut()" value="<?php echo $cod_interno ?>" size="21" maxlength="20" />
                                <input name="hdsw" type="hidden" id="hdsw" value="nada" />
                              </div></th>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Codigo Barra:</div></th>
                              <td><input name="cod_barra" type="text" id="cod_barra"  value="<?php echo $cod_barra ?>" size="21" maxlength="35"/></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"><span class="Emphasize">Codigo Original: </span></div></th>
                              <td><input name="cod_origen" type="text" id="cod_origen" value="<?php echo $cod_origen ?>" size="21" maxlength="20"/></td>
                            </tr>
                            <tr>
                              <th valign="top" scope="row"><div align="right" class="Emphasize">Glosa:</div></th>
                              <td><textarea name="glosa" cols="33" rows="3" id="glosa"><?php echo $glosa ?></textarea></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"><span class="Emphasize">Familia:</span></div></th>
                              <td><label>
                              <?php
									$sqlfam="select * from m07002 order by 2;";
									$resfam=mysql_query($sqlfam,$con) ;				
								?>
                                <select name="cmbfamilia" id="cmbfamilia" onchange="ponefamilia()">
								<OPTION value="xxx">Seleccione una familia</OPTION>
                                  <?php 
									while ($filafam=mysql_fetch_row($resfam)){			
									 if ($cod_familia==$filafam[0]){
									  echo "<option value=$filafam[0] selected='selected'>$filafam[1]</option>";
									  }else{						
									 echo "<option value=$filafam[0]>$filafam[1]</option>";								 
									 }//fin si
									}
								?>
                                </select>
																<input name="hdcod_familia" type="hidden" id="hdcod_familia" value="<?php echo $cod_familia ?>"/>
</label></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Linea:</div></th>
                              <td>
							  <div align="left">
							  	<?php
									$sqllin="select * from m07003 order by 2;";
									$reslin=mysql_query($sqllin,$con) ;				
								?>
                                <select name="cmblinea" id="cmblinea" onchange="ponelinea()">
								<OPTION value="xxx">Seleccione una Linea</OPTION>
                                  <?php 
									while ($filalin=mysql_fetch_row($reslin)){			
									 if ($cod_linea==$filalin[0]){
									  echo "<option value=$filalin[0] selected='selected'>$filalin[1]</option>";
									  }else{						
									 echo "<option value=$filalin[0]>$filalin[1]</option>";								 
									 }//fin si
									}
								?>
                                </select>
								<input name="hdcod_linea" type="hidden" id="hdcod_linea" value="<?php echo $cod_linea ?>"/>				
                              </div></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right" class="Emphasize">Marca:</div>
                                </label></th>
                              <td><?php
									$sqlmar="select * from m07004 order by 2;";
									$resmar=mysql_query($sqlmar,$con) ;				
								?>
                                <select name="cmbmarca" id="cmbmarca" onchange="ponemarca()">
								<OPTION value="xxx">Seleccione una Marca</OPTION>
                                  <?php 
									while ($filamar=mysql_fetch_row($resmar)){			
									 if ($cod_marca==$filamar[0]){
									  echo "<option value=$filamar[0] selected='selected'>$filamar[1]</option>";
									  }else{						
									 echo "<option value=$filamar[0]>$filamar[1]</option>";								 
									 }//fin si
									}
								?>
                                </select>
								<input name="hdcod_marca" type="hidden" id="hdcod_marca" value="<?php echo $cod_marca ?>"/></td>
                            </tr>
                            <tr>
                              <th valign="top" scope="row"><label>
                                <div align="right"><span class="Emphasize">Modelos</span>:</div>
                                </label></th>
                              <td><textarea name="modelos" cols="33" rows="3" id="modelos"><?php echo $modelos ?></textarea></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right"><span class="Emphasize">Fact_Comision</span>:</div>
                                </label>                                </th>
                              <td><input name="fact_comisi" type="text" id="fact_comisi" value="<?php echo $fact_comisi ?>" size="6" maxlength="5" /></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right"><span class="Emphasize">Stock Minimo</span>:</div>
                                </label></th>
                              <td><input name="stock_min" type="text" id="stock_min" value="<?php echo $stock_min ?>" size="5" maxlength="4"/></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"><span class="Emphasize">Fecha Agotamiento</span>:</div></th>
                              <td><input name="fecha_agotamiento" type="text" id="fecha_agotamiento" value="<?php echo $fecha_agotamiento ?>" size="9" maxlength="8" /></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"><span class="Emphasize">Fecha Ult Venta:</span></div></th>
                              <td><label>
                                <input name="fec_ult_venta" type="text" id="fec_ult_venta" value="<?php echo $fec_ult_venta ?>" size="9" maxlength="8" />
                              </label></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Fecha Ult Compra:</div></th>
                              <td><label>
                                <input name="fec_ult_compra" type="text" id="fec_ult_compra" value="<?php echo $fec_ult_compra ?>" size="9" maxlength="8" />
                              </label></td>
                            </tr>
                            <tr>
                              <th scope="row">&nbsp;</th>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <th colspan="2" scope="row"><input name="cmdgra" type="button" id="cmdgra" value="Grabar" onclick="valida()" />
                              <label></label>
                                &nbsp;&nbsp;
                                <label></label>
                                <label></label>                                
                                <label></label>
                                &nbsp;&nbsp;
								<input name="cmdel" type="button" id="cmdel" value="Eliminar" onclick="eliminar()"/>								</th>
                              </tr>
                          </table>
                                </form>						</TD>
                    </TR></TBODY></TABLE></TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD width=180 height=8>&nbsp;</TD>
                <TD width=12 height=8>&nbsp;</TD>
                <TD width="461" height=8>&nbsp;</TD>
        <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY>
<!-- /Footer -->
<script language="JavaScript" src="menu.js"></script>
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
	new menu (MENU_ITEMS, MENU_POS);
</script>
</TABLE>
</BODY><?php
	mysql_close($con);
?>
</HTML>