<?php

require("../conexion.php");
 include ('includes/validarnum.php');
$cdgart=strtoupper($_POST["cdgart"]);
$cdgbar=strtoupper($_POST["cdgbar"]);
$dscart=strtoupper($_POST["dscart"]);
$cdgpro=strtoupper($_POST["cdgpro"]);
$cabys=strtoupper($_POST["cdgcabys"]);

$cdgfam=$_POST["cdgfam"];

$cadena_busqueda=$_POST["cadena_busqueda"];

$where="1=1";
if ($cdgart <> "") { $where.=" AND cdgart='$cdgart'"; }
if ($dscart <> "") { $where.=" AND dscart like '%".$dscart."%'"; }
if ($cdgbar <> "") { $where.=" AND cdgbar='$cdgbar'"; }
if ($cdgfam <> "") { $where.=" AND CDGFAM='$cdgfam'"; }
if ($cabys  == 1)  { $where.=" AND cdghac=''"; }
if ($cabys  == 2)  { $where.=" AND cdghac <> ''"; }
if ($cdgpro <> "") { $where.=" AND cdgpro='$cdgpro'"; }

 ////////////////////////   Averigua el numero de FILAS ////////////////////////////
if ($result = $mysqli->query("SELECT cdgart FROM web_1001 WHERE ".$where )) {
   $filas = $result->num_rows;
   $result->close();
}

 $where.=" ORDER BY CDGART DESC LIMIT 500";

?>
<html>
	<head>
		<title>Articulos</title>
		<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
		<script language="javascript">
		
		function ver_articulo(cdgart) {
			parent.location.href="ver_articulo.php?cdgart=" + cdgart + "&cadena_busqueda=<?php echo $cadena_busqueda?>";
		}
		
		function modificar_articulo(cdgart) {
			parent.location.href="modificar_articulo.php?cdgart=" + cdgart + "&cadena_busqueda=<?php echo $cadena_busqueda?>";
		}
		
		function eliminar_articulo(cdgart) {
			parent.location.href="eliminar_articulo.php?cdgart=" + cdgart + "&cadena_busqueda=<?php echo $cadena_busqueda?>";
		}
		
		
		  function  actualizar_articulo_cabys(cdgbar,cdghac){

	document.getElementById("frame_datos3").src="actualizar_articulo.php?cdgbar="+cdgbar+"&cdghac="+cdghac;


}

/*funcion para actulizar la rejilla*/
function actualizar() {

	parent.document.getElementById("form_busqueda").submit();

	}
	
	
function hola() {

	alert("holaa11");

	}
		
	
				function abreVentanaCabys(cdgart){
			miPopup = window.open("ver_cabys2.php?cdgbar="+cdgart,"miwin","width=900,height=650,scrollbars=yes");
			miPopup.focus();
			//	document.getElementById("Acosart").focus();
				//document.getElementById("Acosart").select();
		
		}
		
		function inicio() {
			var numfilas=document.getElementById("numfilas").value;
			var indi=parent.document.getElementById("iniciopagina").value;
			var contador=1;
			var indice=0;
			if (indi>numfilas) { 
				indi=1; 
			}
			parent.document.form_busqueda.filas.value=numfilas;
			parent.document.form_busqueda.paginas.innerHTML="";		
			while (contador<=numfilas) {
				texto=contador + "-" + parseInt(contador+200);
				if (indi==contador) {
					parent.document.form_busqueda.paginas.options[indice]=new Option (texto,contador);
					parent.document.form_busqueda.paginas.options[indice].selected=true;
				} else {
					parent.document.form_busqueda.paginas.options[indice]=new Option (texto,contador);
				}
				indice++;
				contador=contador+200;
			}
		}
		
		
		function inicio2() {
		
			var cdghac=document.getElementById("cdgcab").value;
			var impuesto=document.getElementById("impuesto").value;
			var cdgbar=document.getElementById("cdgbar").value;

			
			
			if(cdgbar!=""){

			document.getElementById("frame_datos3").src="actualizar_articulo2.php?cdgbar="+cdgbar+"&cdghac="+cdghac;	
			}
			}
			
							function ver_compras(cdgbar) {
			
			
			miPopup = window.open("ver_compras.php?cdgbar=" + cdgbar,"miwin","width=750,height=400,scrollbars=yes");
				buscar();
			miPopup.focus();
		}	
			
		</script>
	</head>

	<body onload=inicio();>	
		<div id="">
			<div id="zonaContenidoPP">

			<div align="center">
			<table class="fuente9" width="100%" cellspacing=0 cellpadding=0 border=0 ID="Table1">
			<input type="hidden" name="numfilas" id="numfilas" value="<?php echo $filas?>">
            
            <input type="hidden" name="cdgcab" id="cdgcab" value="">
            <input type="hidden" name="dscprohac" id="dscprohac" value="">
            <input type="hidden" name="impuesto" id="impuesto" value="">
            <input type="hidden" name="cdgbar" id="cdgbar" value="">
           
            
           
	
<?php






$contador=0;
if ( $filas > 0) {
 
$consulta2 = "SELECT CDGART FROM web_1001 WHERE  cdgart  <> 101 and cdgart  <> 102	  and  ".$where;

if ($resultado2 = $mysqli->query($consulta2)) 

    while ($fila2 = $resultado2->fetch_assoc()) {

	$cdgart = $fila2["CDGART"];
	
	
$consulta = "SELECT CDGART, CDGBAR, DSCART,EXIACT,PRE001,cdghac,ivporc FROM web_1001 WHERE  cdgart = '$cdgart' ";
$resultado = $mysqli->query($consulta);
$fila = $resultado->fetch_array();


        $cdgart = $fila["CDGART"];
        $cdgbar = $fila["CDGBAR"];
        $dscart = $fila["DSCART"];
        $exiact = $fila["EXIACT"];
        $pre001 = $fila["PRE001"];
		$cdghac = $fila["cdghac"];
		$ivporc = $fila["ivporc"];
        $dscart = substr($dscart, 0, 60);  
		
		$ivporc = substr($ivporc, 0, 2);  
   $resultado->close();
						 if ($contador % 2) { $fondolinea="itemParTabla"; } else { $fondolinea="itemImparTabla"; }?>
						<tr class="<?php echo $fondolinea?>">
						<td  width="2%"></td>
						<td width="7%"><div align="left"><?php echo $cdgart?></div></td>
						<td width="12%"><div align="left"><?php echo $cdgbar?></div></td>
						<td class="aDerecha" width="34%" title="<?php echo "Tarifa [".number_format($ivporc,0,",",".")."%] "?>"><div align="left"><?php echo $dscart?></div></td>
						<td width="2%"><div align="right"><?php echo $ivporc?></div></td>
                        <td  width="16%"><div align="left"> <input type="text"   value="<?php echo $cdghac; ?>"  name="cdghac" id="cdghac"  onkeypress=""  style='text-align:right;' onChange="actualizar_articulo_cabys('<?php echo $cdgart ?>',this.value)" onKeyDown=""     maxlength="25" size="10" autocomplete="off"    /><a href="#"><img src="../img/Search_Male_User_Icon_32.png" alt="Buscar" width="20" height="20" title="Catálogo de bienes y servicios"  onClick="abreVentanaCabys('<?php echo $cdgart ?>')" onMouseOver="style.cursor=cursor"></a> </div> </td>
						<td   align="center" width="3%"><div align="right"><?php echo $exiact?></div></td>
						<td class="aDerecha" width="12%"><div align="right"><?php echo  number_format($pre001,2,".",",")?></div></td>
                        <td width="2%"></td>
						<td width="2%"><div align="center"><a href="#"><img src="../img/Edit_Male_User_Icon_32.png" width="25" height="25" border="0" onClick="modificar_articulo(<?php echo $cdgart?>)" title="Modificar"></a></div></td>
						<td width="2%"><div align="center"><a href="#"><img src="../img/Search_Male_User_Icon_32.png" width="25" height="25" border="0" onClick="ver_articulo(<?php echo $cdgart?>)" title="Visualizar"></a></div></td>
							<td width="2%"><div align="center"><a href="#"><img src="../img/Remove_Male_User_Icon_32.png" width="25" height="25" border="0" onClick="eliminar_articulo(<?php echo $cdgart?>)" title="Eliminar"></a></div></td>
													   <td width="2%"><div align="center"><a href="#"><img src="../img/carrito.png" alt="" width="25" height="25" title="Ver Compras" onClick="ver_compras('<?php echo $cdgbar ?>' )" border="0"></a></div></td>
						</tr>
						<?php 
		$contador++ ;				
							}
							
		$resultado2->close();
						?>			
					</table>
					<?php } else { ?>
					<table class="fuente8" width="87%" cellspacing=0 cellpadding=3 border=0>
						<tr>
							<td width="100%" class="mensaje"><?php echo "No hay ning&uacute;n articulo que cumpla con los criterios de b&uacute;squeda";?></td
					    ></tr>
					</table>					
					<?php } ?>					
			  </div>
			</div>
		  </div>			
		</div>
        
              <iframe id="frame_datos3" name="frame_datos3" width="0%" height="0" frameborder="0">
  <ilayer width="0" height="0" id="frame_datos3" name="frame_datos3"></ilayer>
  </iframe>	
	</body>
</html>
