<?php

		include('../conexion.php');
		
		session_start();
		 
		if($_SESSION['tipo_usu']=='a' or $_SESSION['tipo_usu']=='u'  or $_SESSION['tipo_usu']=='c'){
		}else{
			header('location:acceso_denegado.php');
		}



	$usu=$_SESSION['username'];
	
	$consulta = "SELECT * FROM usuarios WHERE usu='$usu'";
	$resultado = $mysqli->query($consulta);
	$row = $resultado->fetch_array();
	$nomb = $row["usu"];


$hoy=date("d/m/Y");
$hora=date("H:i:s");

 

$accion=$_POST["accion"];
if (!isset($accion)) { $accion=$_GET["accion"]; }

$cdgbar=strtoupper($_POST["Acdgbar"]);
$cdgbar= str_replace(' ', '', $cdgbar);


$cdgbar2=strtoupper($_POST["Acdgbar2"]);
$cdgbar2= str_replace(' ', '', $cdgbar2);

$cdgbar3=strtoupper($_POST["Acdgbar3"]);
$cdgbar3= str_replace(' ', '', $cdgbar3);


$dscart=strtoupper($_POST["Adscart"]);
//$dscart=str_replace('"','&quot;',$dscart); 
//$dscart = str_replace("'","&quot;",$dscart);  
$dscart = str_replace("á","A",$dscart);
$dscart = str_replace("é","E",$dscart);
$dscart = str_replace("í","I",$dscart);
$dscart = str_replace("ó","O",$dscart);
$dscart = str_replace("ú","U",$dscart);
$dscart = str_replace("ñ","Ñ",$dscart);
  
$estart=strtoupper($_POST["comboestatus"]);
$cob_iv=strtoupper($_POST["cob_iv"]);
$cdgtar=strtoupper($_POST["tarifa"]);

//$cdgbod=$_POST["cdgbod"];
if (!isset($_POST["cdgbod"])) { $cdgbod=0; } else  {  $cdgbod=$_POST["cdgbod"]; } 

$tipart=strtoupper($_POST["comboestatus"]);
$desart=$_POST["Adesart"];
$desart = str_replace (",","",$desart);
$exiact=$_POST["Aexiact"];
$exiact = str_replace (",","",$exiact);
$cosart=$_POST["Acosart"];
$cosart = str_replace (",","",$cosart);
$fleart=$_POST["fleart"];
$fleart = str_replace (",","",$fleart);
$impart=$_POST["impart"];
$impart = str_replace (",","",$impart);

$utiart1=$_POST["utiart1"];
$utiart1 = str_replace (",","",$utiart1);
$utiart2=$_POST["utiart2"];
$utiart2 = str_replace (",","",$utiart2);
$pre001=$_POST["pre001"];
$pre001 = str_replace (",","",$pre001);
$pre002=$_POST["pre002"];
$pre002 = str_replace (",","",$pre002);
$ivporc=$_POST["ivporc"];
$desmax=$_POST["desmax"];
$desmin=$_POST["desmin"];
$stockmax=$_POST["stockmax"];
$stockmin=$_POST["stockmin"];
$cdgact=$_POST["cdgact"];
$utisug=$_POST["utisug"];
$cdgfam=$_POST["Familia"];
$cdglin=$_POST["Linea"];
$cdgpro=$_POST["cdgpro"];
$unimed=$_POST["unimed"];
$estante=strtoupper($_POST["estante"]);
if (!isset($_POST["Adesfac"])) { $desfac=0; } else  {  $desfac=$_POST["Adesfac"]; } 

if (!isset($_POST["artpro"])) { $artpro=0; } else  {  $artpro=$_POST["artpro"]; } 

if (!isset($_POST["tipcanbas"])) { 
 $tipcanbas=0;
 $tarred=0.00;
 $cdgtarred="";
	 } else  { 
 $tipcanbas=$_POST["tipcanbas"];
 $tarred=1.00;
 $cdgtarred="02";
 }
  
if (!isset($_POST["cadena_busqueda"])) { $cadena_busqueda=""; } else  { $cadena_busqueda=$_POST["cadena_busqueda"]; }

$unimed=str_replace(' ','',$unimed);
$cdgtipart=$_POST["cdgtipart"];
$cdgtippro=$_POST["cdgtippro"];
$cdghac=$_POST["cdgcab"];


$cdghac=strtoupper($_POST["cdgcab"]);
$cdghac= str_replace(' ', '', $cdghac);


$preivi=$cosart+$impart;

if ( $cob_iv==2 ) { $ivporc=0; } 
$usuario=$nomb ;
$estatus="ACTIVO";
$fecha =date("Y-m-d");
$fecmod =$fecha;
//$fecha;


if ($accion=="alta") {
	$query_operacion="INSERT INTO web_1001 (cdgart, cdgbar, cdgbar2, cdgbar3, dscart, estart, cob_iv, tipart, desart,  exiact, cosart, utiart1, utiart2, pre001, pre002, impart, preivi, cdgfam, cdglin, nomusu, fecmod, desmax, desmin , stockmax, stockmin , utisug , fleart , cdgpro, ivporc, unimed, cdgtipart, cdgtippro, cdgbod , artpro , cdgtar, tipcanbas , tarred, cdgtarred, estante,cdghac,cdgact ) VALUES ('', '$cdgbar',  '$cdgbar2',  '$cdgbar3', '$dscart', '$estart','$cob_iv','$tipart','$desart','$exiact','$cosart', '$utiart1', '$utiart2', '$pre001', '$pre002', '$impart', '$preivi', '$cdgfam', '$cdglin',  '$usuario', '$fecmod', '$desmax', '$desmin', '$stockmax', '$stockmin' , '$utisug'  , '$fleart'   , '$cdgpro', '$ivporc' , '$unimed' , '$cdgtipart',  '$cdgtippro' , '$cdgbod' , '$artpro' , '$cdgtar', '$tipcanbas', '$tarred' , '$cdgtarred' , '$estante','$cdghac','$cdgact' )";					
	$mysqli->query($query_operacion);
    $mensaje="El Articulo ha sido creado exitosamente"; 
	$cabecera1=" Nuevo Articulo ";
	$cabecera2="Modulo Nuevo Articulo ";
	$cdgart= $mysqli-> insert_id ;
}

if ($accion=="modificar") {
	$cdgart=$_POST["cdgart"];
	
	if ($cdglin=="") {
  $query="UPDATE web_1001 SET cdgbar='$cdgbar', cdgbar2='$cdgbar2', cdgbar3='$cdgbar3',  dscart='$dscart', estart='$estart', cob_iv='$cob_iv',tipart='$tipart', desart='$desart', exiact='$exiact', cosart='$cosart', utiart1='$utiart1', utiart2='$utiart2', pre001='$pre001', pre002='$pre002', impart='$impart', preivi='$preivi',  nomusu='$nomb',  fecmod='$fecmod',  desmax='$desmax',  desmin='$desmin' , stockmax='$stockmax', stockmin='$stockmin',  utisug='$utisug'  , fleart='$fleart'    , cdgpro='$cdgpro'  , ivporc='$ivporc'  , unimed='$unimed'  , cdgtipart='$cdgtipart' , cdgtippro='$cdgtippro'  , cdgbod='$cdgbod' , artpro='$artpro'  , cdgtar='$cdgtar' , desfac='$desfac', tipcanbas='$tipcanbas' , tarred='$tarred' , cdgtarred='$cdgtarred' , estante='$estante', cdghac='$cdghac',cdgact='$cdgact' WHERE cdgart='$cdgart'";
  
$mysqli->query($query);
	$mensaje="El Articulo  ha sido modificado exitosamente"; 
	$cabecera1="Inicio >> Invemtario &gt;&gt; Modificar Artículo ";
	$cabecera2="Modulo Modificar Artículo ";
} else  {

  $query="UPDATE web_1001 SET cdgbar='$cdgbar', cdgbar2='$cdgbar2', cdgbar3='$cdgbar3', dscart='$dscart', estart='$estart', cob_iv='$cob_iv',tipart='$tipart', desart='$desart', exiact='$exiact', cosart='$cosart', utiart1='$utiart1', utiart2='$utiart2', pre001='$pre001', pre002='$pre002', impart='$impart', preivi='$preivi', cdgfam='$cdgfam',cdglin='$cdglin', nomusu='$nomb',  fecmod='$fecmod' , desmax='$desmax',  desmin='$desmin'  , stockmax='$stockmax', stockmin='$stockmin',  utisug='$utisug'  , fleart='$fleart'    , cdgpro='$cdgpro'   , ivporc='$ivporc'   , unimed='$unimed'  , cdgtipart='$cdgtipart' , cdgtippro='$cdgtippro'  , cdgbod='$cdgbod' , artpro='$artpro' , cdgtar='$cdgtar' , desfac='$desfac',  tipcanbas='$tipcanbas' , tarred='$tarred' , cdgtarred='$cdgtarred'  , estante='$estante', cdghac='$cdghac',cdgact='$cdgact'  WHERE cdgart='$cdgart'";
  

$mysqli->query($query);
	$mensaje="El Articulo  ha sido modificado exitosamente"; 
	$cabecera1="Inicio >> Invemtario &gt;&gt; Modificar Artículo ";
	$cabecera2="Modulo Modificar Artículo ";

}

}

?>

	

<html>
	<head>
		<title>Principal</title>
		<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
		<script type="text/javascript" src="../funciones/validar.js"></script>
		<script language="javascript">
		
		function aceptar() {
		location.href="index.php?cadena_busqueda=<?php echo $cadena_busqueda?>";
		}
		
		var cursor;
		if (document.all) {
		// Está utilizando EXPLORER
		cursor='hand';
		} else {
		// Está utilizando MOZILLA/NETSCAPE
		cursor='pointer';
		}
		


function nobackbutton(){	
   window.location.hash="no-back-button";	
   window.location.hash="Again-No-back-button" //chrome	
   window.onhashchange=function(){window.location.hash="no-back-button";}	
}
		


		
		</script>
	</head>
	
		<body onLoad="nobackbutton();">
		<div id="">
			<div id="zonaContenido">
				<div align="center">
				<div id="tituloForm" class="header"><?php echo $cabecera2?></div>
				<p>&nbsp;</p>
				<div id="formulario" class="contenidoCliente">
					<table class="fuente8" width="100%" cellspacing=0 cellpadding=3 border=0>
						<tr>
						  <td colspan="6" class="header2"><?php echo $mensaje;?></td>
						</tr>
						<tr>
						  <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td colspan="4">&nbsp;</td>
					  </tr>
						<tr>
						  <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td colspan="4">&nbsp;</td>
					  </tr>
						<tr>
						  <td width="10%">&nbsp;</td>
							<td width="19%">C&oacute;digo</td>
							<td colspan="4"><?php echo $cdgart?></td>
					    </tr>
						<tr>
						  <td width="10%">&nbsp;</td>
							<td width="19%">Código Barras </td>
						    <td colspan="4"><?php echo $cdgbar?></td>
					    </tr>
						<tr>
						  <td>&nbsp;</td>
						  <td width="19%">Descripcion</td>
						  <td colspan="4"><?php echo $dscart?></td>
					  </tr>
						<tr>
						  <td>&nbsp;</td>
						  <td width="19%">Costo </td>
						  <td width="19%"  align="right"><?php echo number_format($cosart,2,".",",")?></td>
						  <td width="10%">&nbsp;</td>
						  <td width="17%">&nbsp;</td>
						  <td width="25%">&nbsp;</td>
				      </tr>
						<tr>
						  <td>&nbsp;</td>
							<td width="19%">Precio </td>
							<td 
                            align="right"><?php echo number_format($pre001,2,".",",")?></td>
							<td>&nbsp;</td>
				
			
				
				
						    <td>&nbsp;</td>
							
							
						           			<?php
					

				
					$consulta = "SELECT * FROM familias WHERE cdgfam = $cdgfam";
					$resultado = $mysqli->query($consulta);
					$row = $resultado->fetch_assoc();
					$dscfam=$row["dscfam"];
					
					$consulta2 = "SELECT * FROM lineas WHERE cdglin = $cdglin and  cdgfam = $cdgfam ";
					$resultado2 = $mysqli->query($consulta2);
					$row2 = $resultado2->fetch_assoc();
					$dsclin=$row2["dsclin"];
					
			
					  ?>
                      
           
							
						    <td>&nbsp;</td>
						</tr>
			
						<tr>
						  <td>&nbsp;</td>
						  <td>Familia</td>
						  <td colspan="4" align="left"><?php echo $dscfam?></td>
					  </tr>
						<tr>
						  <td width="10%">&nbsp;</td>
							<td width="19%">Linea</td>
							<td colspan="4" align="left"><?php echo $dsclin?></td>
				
				        </tr>
					</table>
			  </div>
				<div id="" align="center">
					<img src="../img/Symbol-Check_48x48-32.png" width="48" height="48" onClick="aceptar()" border="0" onMouseOver="style.cursor=cursor" title="Aceptar">			  </div>
			 </div>
		  </div>
		</div>
	</body>
</html>

  