<?php
include "../session.php"; 

include "conect.php";

$code=$_POST['codeConsult'];

date_default_timezone_set('America/Guatemala');
$date=date("Y-m-d");
$hora=date('h:i:s');



$consulta = mysqli_query($con, "SELECT * FROM asociados WHERE (BARCODE = '$code' OR CODIGO = '$code')");
$conteo   = mysqli_num_rows($consulta);

if ($conteo>0) {

	while ($row3 = mysqli_fetch_array($consulta)) {

                    $user    = $row3['NAME'];
                    $codigo = $row3['CODIGO'];
                    $barcode      = $row3['BARCODE'];
					$statusConsult = $row3['STATUS'];

    }


	if ($statusConsult == null || $statusConsult== "inactivo"){

		echo 1;

	} else if($statusConsult=='activo'){
	


?>

    <div class="clientConsult">
    	<label><h2><?php echo $user; ?></h2></label></br>
        <label>Cod. <b><?php echo $codigo; ?></b></label></br>

        <label><?php echo $barcode; ?></label>

        <br>
        <center>
        	<form method="post" onsubmit="return false" id="datosConsultados">
        		<input id="usuarioConsultado" type="hidden" name="" value="<?php echo $user; ?>">
        		<input id="codigoConsultado" type="hidden" name="" value="<?php echo $codigo; ?>">
        		<input id="barcodeConsultado" type="hidden" name="" value="<?php echo $barcode; ?>">
        	

        	<?php 
        	$consultaProducts = mysqli_query($con, "SELECT * FROM producto WHERE STATUS=true");
			$conteoProducts   = mysqli_num_rows($consultaProducts);

			if ($conteoProducts>0) {

				

				while ($rowProd = mysqli_fetch_array($consultaProducts)) {


                    
                    $codProduct  = $rowProd['COD_TIPO'];
                    $nameProduct = $rowProd['NOMBRE'];
                    $tipoProduct = $rowProd['TIPO'];
                    $catProduct = $rowProd['CAT_PROD'];
                    $id = $rowProd['ID'];





 					?>
                    <button onclick="pedido(<?php echo ("'".$codProduct."'"); ?>)" id="iniciarPedido" class="boton_general" value="<?php echo $codProduct; ?>"><?php echo ($catProduct."<br>".$tipoProduct); ?></button>
                    <?php                   
    			}

    			mysqli_close($con);






			}else{
				echo "no se han encontrado productos";
			};

        	 ?>
        	

        	</form>
        </center>


        
    </div>
        

    <?php

	

}

else{
	echo 1;
}


}

else{
	echo 1;

	}




 ?>