<?php
require("../conexion.php");
include ("../funciones/fechas.php");

$where="1=1";

$cligen="9999";
$dscart=strtoupper($_POST["dscart"]);
$estart="1";
 ////////////////////////   Averigua el numero de FILAS ////////////////////////////
if ($result = $mysqli->query("SELECT * FROM web_1001  WHERE  ESTART='$estart'  AND dscart like '%$dscart%'" )) {
   $filas = $result->num_rows;
   $result->close();
}

if (!isset($_POST["chkec_articulos"])) { $chkec=""; } else  { $chkec=$_POST["chkec_articulos"]; }
if (!isset($_POST["cdgarttmp"])) { $cdgarttmp=""; } else  { $cdgarttmp=$_POST["cdgarttmp"]; }

if ($chkec <> "" ) { 

					$query_update="UPDATE web_1001 SET checkunir='$chkec' WHERE CDGBAR='$cdgarttmp'";					
					$mysqli->query($query_update);
					
					if ($chkec == 1) { 
					
						$consulta1 = "SELECT *  FROM web_1001  WHERE  CDGBAR='$cdgarttmp'  ";
						$resultado1 = $mysqli->query($consulta1);
						$fila1 = $resultado1->fetch_array();

						$dscart_2 = $fila1["DSCART"];
		
		
	
					$query_insert="INSERT INTO tmp_web_1001(cdgart,dscart) VALUES('$cdgarttmp','$dscart_2')";					
					$mysqli->query($query_insert);

					}
					else {
						
						$query_delete="DELETE FROM tmp_web_1001 WHERE cdgart='$cdgarttmp'";					
					$mysqli->query($query_delete);
						
					}

}

?>
<html>
	<head>
		<title>Clientes</title>
		<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
		<script src="..//jquery/bootstrap.js"></script>
        <link href="..//estilos/bootstrap.css" type="text/css" rel="stylesheet">
		<script language="javascript">
		

	


				      

		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.totalproformas.value=document.getElementById("totalproformas").value;
			parent.document.form_busqueda.paginas.innerHTML="";		
			while (contador<=numfilas) {
				texto=contador + "-" + parseInt(contador+15);
				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+16;
			}
		}
		
		function CambiaColor(esto,fondo,texto)
		{
			colorfondo=esto.style.background;
			esto.style.background=fondo;
			esto.style.color=texto;
			return colorfondo;
		}
		
		function CambiaColor2(esto,texto)
		{
			esto.style.background=colorfondo;
			esto.style.color=texto;
		}
		
				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";}	
}
		
		function insert_tmp(cdgart,checked){

//parent.document.form1.accion.value=accion; 
parent.document.form_articulos.cdgarttmp.value=cdgart; 
parent.document.form_articulos.chkec_articulos.value=checked;
parent.document.getElementById("form_articulos").submit();

		}
		
		</script>
	</head>

	<body onload= nobackbutton(); 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="totalproformas" id="totalproformas" value="<?php echo $totalproformas?>">

<?php

$contador=0;
if ( $filas > 0) {


$consulta2 = "SELECT * FROM web_1001  WHERE  ESTART='$estart' AND dscart like '%$dscart%' ORDER BY DSCART ASC";



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

 
    while ($fila2 = $resultado2->fetch_assoc()) {
	
    $CDGBAR = $fila2["CDGBAR"];
	
$consulta = "SELECT *  FROM web_1001  WHERE  CDGBAR='$CDGBAR'  ";
$resultado = $mysqli->query($consulta);
$fila = $resultado->fetch_array();


		$cdgart = $fila["CDGART"];
		$CDGBAR = $fila["CDGBAR"];
        $dscart = $fila["DSCART"];
		 $PRE001 = $fila["PRE001"];
		
       
		
		
        $dscart = substr($dscart, 0, 55);  
		
		$check  = $fila["checkunir"];
		
		   $resultado->close();

		
		if ($contador % 2) { $fondolinea="itemParTabla"; } else { $fondolinea="itemImparTabla"; }?>
								
		<tr class="<?php echo $fondolinea ?>" onMouseOver="CambiaColor(this,'#000000','#ffffff')" onMouseOut="CambiaColor2(this,'#000000')" >
<td width="1%"><div align="left"></div></td>
		  <td width="17%"><div align="left"><?php echo $CDGBAR ?> </div></td>
								
								
		  <td width="38%"><div align="left"><?php echo 	$dscart?></div></td>	
								
																
			
	
          <td width="7%"><div align="right"><?php echo $PRE001?></div></td>
		
								<td width="10%">&nbsp;</td>
							
                                 <?php if ( $check ==0){ ?>
          <td width="2%"><input type="checkbox" value="otro" name="valores"   onClick="insert_tmp('<?php echo $CDGBAR ?>',<?php echo 1 ?>)" /> </td>
		       <?php } else { ?>
          <td width="4%"><input type="checkbox" value="otro" name="valores"   checked   onclick="insert_tmp('<?php echo $CDGBAR ?>',<?php echo 0 ?>)" /> </td>
                <?php }  ?> 
		  <td width="21%"><div align="left"></div></td>				
			  </tr>
						</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 ninguna factura que cumpla con los criterios de b&uacute;squeda";?></td>
					    </tr>
					</table>					
					<?php } ?>					
		  </div>
		  </div>
    </div>			
		</div>
        
            <iframe id="frame_datos1" name="frame_datos1" width="0%" height="0" frameborder="0">
  <ilayer width="0" height="0" id="frame_datos1" name="frame_datos1"></ilayer>
  </iframe>	
  
  
	</body>
    

</html>
