<?php

	
	session_start();
		include('../conectar.php'); 
		if($_SESSION['tipo_usu']=='u' or $_SESSION['tipo_usu']=='a' ){
		}else{
			header('location:error.php');
		}
		if($_SESSION['tipo_usu']=='a'){
			$titulo='Administrador';
		}else{
			$titulo='Secretaria/o';
		}
        $usuario=$_SESSION['username'];
		$sqll=mysql_query("SELECT * FROM usuarios WHERE usu='$usuario'");
		if($dato=mysql_fetch_array($sqll)){
			$nombre=$dato['usu'];
			$palabra=explode(" ", $nombre);
			$nomb=$palabra[0];
		}


$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);

$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"]);
$tipart=strtoupper($_POST["comboestatus"]);
$desart=$_POST["Adesart"];
$desart = ereg_replace ("[,]","",$desart);
$exiact=$_POST["Aexiact"];
$exiact = ereg_replace ("[,]","",$exiact);
$cosart=$_POST["Acosart"];
$cosart = ereg_replace ("[,]","",$cosart);
$fleart=$_POST["fleart"];
$fleart = ereg_replace ("[,]","",$fleart);
$impart=$_POST["impart"];
$utiart1=$_POST["utiart1"];
$utiart1 = ereg_replace ("[,]","",$utiart1);
$utiart2=$_POST["utiart2"];
$utiart2 = ereg_replace ("[,]","",$utiart2);
$pre001=$_POST["pre001"];
$pre001 = ereg_replace ("[,]","",$pre001);
$pre002=$_POST["pre002"];
$pre002 = ereg_replace ("[,]","",$pre002);
$ivporc=$_POST["ivporc"];
$desmax=$_POST["desmax"];
$desmin=$_POST["desmin"];
$utisug=$_POST["utisug"];
$cdgfam=$_POST["Familia"];
$cdglin=$_POST["Linea"];
$cdgpro=1;


$usuario=$nomb ;
$estatus="ACTIVO";
$fecha =date("Y-m-d");
$fecmod =$fecha;
//$fecha;


if ($accion=="alta") {
	$query_operacion="INSERT INTO web_1001 (cdgart, cdgbar, dscart, estart, cob_iv, tipart, desart,  exiact, cosart, utiart1, utiart2, pre001, pre002, impart, preivi, cdgfam, cdglin, nomusu, fecmod, desmax, desmin , utisug , fleart , cdgpro, ivporc) VALUES ('', '$cdgbar', '$dscart', '$estart','$cob_iv','$tipart','$desart','$exiact','$cosart', '$utiart1', '$utiart2', '$pre001', '$pre002', '$impart', '$preivi', '$cdgfam', '$cdglin',  '$usuario', '$fecmod', '$desmax', '$desmin' , '$utisug'  , '$fleart'   , '$cdgpro', '$ivporc' )";					
	$rs_operacion=mysql_query($query_operacion);
	if ($rs_operacion) { $mensaje="El Articulo ha sido creado exitosamente"; }
	$cabecera1="Inicio >> inventario &gt;&gt; Nuevo Articulo ";
	$cabecera2="Modulo Nuevo Articulo ";
	$sel_maximo="SELECT max(cdgart) as maximo FROM web_1001";
	$rs_maximo=mysql_query($sel_maximo);
	$cdgart=mysql_result($rs_maximo,0,"maximo");
}

if ($accion=="modificar") {
	$cdgart=$_POST["cdgart"];
	
	if ($cdglin=="") {
  $query="UPDATE web_1001 SET cdgbar='$cdgbar', 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' ,  utisug='$utisug'  , fleart='$fleart'    , cdgpro='$cdgpro'  , ivporc='$ivporc' WHERE cdgart='$cdgart'";
	$rs_query=mysql_query($query);
	if ($rs_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', 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'  ,  utisug='$utisug'  , fleart='$fleart'    , cdgpro='$cdgpro'   , ivporc='$ivporc' WHERE cdgart='$cdgart'";
	$rs_query=mysql_query($query);
	if ($rs_query) { $mensaje="El Articulo  ha sido modificado exitosamente"; }
	$cabecera1="Inicio >> Invemtario &gt;&gt; Modificar Artículo ";
	$cabecera2="Modulo Modificar Artículo ";

}

}
if ($accion=="baja") {
	$cdgart=$_GET["cdgart"];
	 $consulta2 = "DELETE FROM web_1001  WHERE cdgart ='$cdgart'";
    $rs_consulta2 = mysql_query($consulta2);

	
	$rs_query=mysql_query($query);
	if ($rs_query) { $mensaje="El articulo ha sido eliminado correctamente"; }
	$cabecera1="Inicio >> Inventario &gt;&gt; Eliminar articulo ";
	$cabecera2="Modulo Eliminar Articulo ";

}

if ($accion=="baja"){

?>
	<script language="javascript">
		var cursor;
		if (document.all) {
		// Está utilizando EXPLORER
		cursor='hand';
		} else {
		// Está utilizando MOZILLA/NETSCAPE
		cursor='pointer';
		}
		
		function aceptar() {
			location.href="nueva_proforma_super.php";
		}
		
		function imprimir(codfactura) {
		//	window.open("../fpdf/imprimir_factura.php?codfactura="+codfactura);
		//window.open("../fpdf/imprimir_factura_PUNTO_VENTA_SUPER.php?codfactura="+codfactura);
		//window.open("../fpdf/imprimir_factura_PUNTO_VENTA.php?codfactura="+codfactura);
		
		location.href="index.php";
		}
		
		
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>
<? 
		
	
echo "<script>";
echo "imprimir();";
echo "</script>";	





} else  {
?>
<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";
		}
		
		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>
				
									        <?php
						
					  	$query_articulo="SELECT * FROM web_1001 WHERE cdgart = '$cdgart'  ";
						$res_articulo=mysql_query($query_articulo);
						$contador=0;
						$cdgfam=mysql_result($res_articulo,$contador,"cdgfam");
						$cdglin=mysql_result($res_articulo,$contador,"cdglin");
					  ?>
				
				
						    <td>&nbsp;</td>
							
									        <?php
						
					  	$query_Familia="SELECT * FROM familias WHERE cdgfam = $cdgfam  ";
						$res_Familia=mysql_query($query_Familia);
						$contador=0;
					  ?>
                      
                      			<?php
					
					  	$query_Linea="SELECT * FROM lineas WHERE cdglin = $cdglin  ";
						$res_Linea=mysql_query($query_Linea);
						$contador=0;
					  ?>
							
						    <td>&nbsp;</td>
						</tr>
			
						<tr>
						  <td>&nbsp;</td>
						  <td>Familia</td>
						  <td colspan="4" align="left"><?php echo mysql_result($res_Familia,$contador,"dscfam")?></td>
					  </tr>
						<tr>
						  <td width="10%">&nbsp;</td>
							<td width="19%">Linea</td>
							<td colspan="4" align="left"><?php echo mysql_result($res_Linea,$contador,"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>
<?
}



 

	 
echo "<script languaje='javascript' type='text/javascript'>parent.opener.validararticulo();</script>";
echo "<script languaje='javascript' type='text/javascript'>window.close();</script>";



  ?>
  
  