<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php'); 
$tipo=mysqli_real_escape_string($con,(strip_tags($_REQUEST['tipo'], ENT_QUOTES)));
$pen_id=mysqli_real_escape_string($con,(strip_tags($_REQUEST['pen_id'], ENT_QUOTES)));

if($tipo=='categorias')
{
	$fam_id=mysqli_real_escape_string($con,(strip_tags($_REQUEST['fam_id'], ENT_QUOTES)));
	$art=mysqli_query($con,"SELECT *, a.art_id as art_id ,b.art_id as art_id_bod FROM articulos a, articulos_has_bodegas b
	where a.familias_fam_id='$fam_id' and a.art_tipo='articulo' and a.art_id=b.articulos_art_id and a.empresa='$empresa' and b.sucursal='$sucursal' and a.art_estado='Activo'  order by a.art_nombre ASC ");
	while ($row=mysqli_fetch_array($art))
	{
	    $art_id=$row['art_id'];
	    $art_cantidad_existente=$row['art_cantidad'];
	    $art_id_bod=$row['art_id_bod'];
	    $art_referencia=$row['art_referencia'];
	    $art_nombre=$row['art_nombre'];            
	    $art_precio_costo=$row["art_precio_costo"];
	    $art_iva=$row["art_iva"];

	    $sql_tar=mysqli_query($con, "SELECT * from cliente c,pedido cc where c.clie_id=cc.clie_id and cc.pen_id='$pen_id' and cc.empresa='$empresa'")or die(mysqli_error($con));
	    $rw_tar=mysqli_fetch_array($sql_tar);
	    $tarifas_tar_id=$rw_tar['tarifas_tar_id'];

		$sql_pre=mysqli_query($con, "SELECT * from precio WHERE articulos_art_id='$art_id' and tarifas_tar_id='$tarifas_tar_id'");
		if ($rw_pre= mysqli_fetch_array($sql_pre))
		{
			$pre_precio=$rw_pre['pre_precio'];
		}
		else 
		{
			$pre_precio=$row['art_pvp'];
		}
	?>
	    <div id="" class="efec col-xs-6 col-sm-4" style="width:128px;" onclick="agregar_articulo('<?php echo $art_id_bod ?>')">
	        <div class="panel panel-success"> 
	         <span id="notification_menu">$ <?php echo number_format($pre_precio,0);?> </span>
	         
	            <div class="" style="background-position:center; ">
	                <?php  $nu=rand(1,1000);$nu;?>
	                <center><img src="img\articulos\<?php echo $art_id.'.jpg?' .$nu .''; ?>" alt="" height="100px;" width="100%;" ></center>
	            </div>
	            <div style="height:50px;background-color: #CCC">
	                <h5 style="text-align:center">
	                <p style="color:#000;font-size:10px;"><?php echo $art_nombre; ?>
	                <span style="color: red;">
					<?php if($row["art_atributo_estado"]=='si') 
					{  
						$atributo1=$row['atributo1'];
                        $atri1=mysqli_query($con,"SELECT * FROM atributos1 where atri_art_id='$art_id' and atri_id='$atributo1'");
                        $fila1 = mysqli_fetch_array($atri1);
                        if (isset($fila1['atri_nombre'])) { echo $atri_nombre1=$fila1['atri_nombre']; }
                    	$atributo2=$row['atributo2'];
                        $atri2=mysqli_query($con,"SELECT * FROM atributos2 where atri_art_id2='$art_id' and atri_id2='$atributo2'");
                        $fila2 = mysqli_fetch_array($atri2);
                        if (isset($fila2['atri_nombre2'])) { echo ' / '; echo $atri_nombre2=$fila2['atri_nombre2']; }
                    } ?>
               	 	</span>
               	 	</p></h5>
	            </div>
	        </div>
	    </div>

	    <input type="hidden" id="art_id<?php echo $art_id_bod; ?>" value="<?php echo $art_id; ?>">
		<input type="hidden" id="nombre<?php echo $art_id_bod; ?>" value="<?php echo $art_nombre; ?>">
		<input type="hidden" id="cantidadexistente<?php echo $art_id_bod; ?>" value="<?php echo $art_cantidad_existente; ?>">
	    <input type="hidden" id="cantidad<?php echo $art_id_bod; ?>" value="1">
	    <input type="hidden" id="art_iva<?php echo $art_id_bod;?>" value="<?php echo $art_iva;?>" >
	    <input type="hidden" id="descuento<?php echo $art_id_bod; ?>" value="0"> 
	    <input type="hidden" id="precio_venta<?php echo $art_id_bod; ?>" value="<?php echo $pre_precio;?>"> 
	<?php  }  
	$art=mysqli_query($con,"SELECT * FROM articulos WHERE familias_fam_id='$fam_id' and art_tipo='producto' and art_estado='Activo' and empresa='$empresa'")or die(mysqli_error($con));
	while ($row=mysqli_fetch_array($art))
	{
	    $art_id=$row['art_id'];
	    $art_referencia=$row['art_referencia'];
	    $art_nombre=$row['art_nombre'];            
	    $art_precio_costo=$row["art_precio_costo"];
	    $art_iva=$row["art_iva"];
	    $pre_precio=$row['art_pvp'];
	?>
	    <div id="" class="efec col-xs-6 col-sm-4" style="width:130px;" onclick="agregar_producto_servicio('<?php echo $art_id ?>')">
	        <div class="panel panel-success "> 
	         <span id="notification_menu">$ <?php echo number_format($pre_precio,0);?> </span>
	            <div class="" style=" background-position:center; ">
	                <?php $nu=rand(1,1000);$nu;?>
	                <center><img src="img\articulos\<?php echo $art_id.'.jpg?' .$nu .''; ?>" alt="" height="100px;" width="100%;" ></center>
	            </div>
	            <div class="" style="height:50px;background-color: #CCC">
	                <h5 style="text-align:center">
	                <p style="color:#000;font-size:10px;"><?php echo $art_nombre; ?></p></h5>
	            </div>
	        </div>
	    </div>
	    <input type="hidden" id="tipo<?php echo $art_id; ?>" value="producto">
	    <input type="hidden" id="art_id<?php echo $art_id; ?>" value="<?php echo $art_id; ?>">
	    <input type="hidden" id="art_referencia<?php echo $art_id; ?>" value="<?php echo $art_referencia; ?>">
		<input type="hidden" id="nombre<?php echo $art_id; ?>" value="<?php echo $art_nombre; ?>">
	    <input type="hidden" id="cantidad<?php echo $art_id; ?>" value="1">
	    <input type="hidden" id="descuento<?php echo $art_id; ?>" value="0"> 
	    <input type="hidden" id="art_iva<?php echo $art_id;?>" value="<?php echo $art_iva; ?>" >
	    <input type="hidden" id="precio_venta<?php echo $art_id; ?>" value="<?php echo $pre_precio;?>"> 

<?php  }  
$com=mysqli_query($con,"SELECT * FROM combos WHERE familias_fam_id='$fam_id' and com_estado='Activo' and empresa='$empresa'")or die(mysqli_error($con));
   	while ($res=mysqli_fetch_array($com))
    {
        $com_id=$res['com_id'];
        $com_referencia=$res['com_referencia'];
        $com_nombre=$res['com_nombre'];
        $com_iva=$res['com_iva'];
        $pre_precio=0;
        $sql_pre=mysqli_query($con, "SELECT * from combos_articulos WHERE combos_com_id='$com_id'")or die(mysqli_error($con));
        while ($rw_pre=mysqli_fetch_array($sql_pre)) 
        {
	        $coma_art_id = $rw_pre['coma_art_id'];
	        $coma_art_cantidad = $rw_pre['coma_art_cantidad'];
	        $coma_art_precio = $rw_pre['coma_art_precio'];

	        $precio=$coma_art_cantidad*$coma_art_precio;
	        $pre_precio+=$precio;
        }
	?>
        <div id="" class="efec col-xs-6 col-sm-4" style="width:130px;" onclick="agregarcombo('<?php echo $com_id ?>')">
            <div class="panel panel-success "> 
             <span id="notification_menu">$ <?php echo number_format($pre_precio,0);?> </span>
                <div class="" style=" background-position:center; ">
                    <?php $nu=rand(1,1000);$nu;?>
                    <center><img src="img\combos\<?php echo $com_id.'.jpg?' .$nu .''; ?>" alt="" height="100px;" width="100%;" ></center>
                </div>
                <div class="" style="height:50px;background-color: #CCC">
                    <h5 style="text-align:center">
                    <p style="color:#000;font-size:10px;"><?php echo $com_nombre; ?></p></h5>
                </div>
            </div>
        </div>
        <input type="hidden" id="com_id<?php echo $com_id; ?>" value="<?php echo $com_id; ?>" >
        <input type="hidden" id="com_nombre<?php echo $com_id; ?>" value="<?php echo $com_nombre; ?>" >
        <input type="hidden" id="com_iva<?php echo $com_id; ?>" value="<?php echo $com_iva; ?>" >
	    <input type="hidden" id="com_cantidad<?php echo $com_id; ?>" value="1">
	    <input type="hidden" id="com_descuento<?php echo $com_id; ?>" value="0"> 
	    <input type="hidden" id="com_precio_venta<?php echo $com_id; ?>" value="<?php echo $pre_precio;?>" > 

<?php  
	}  

}





else if ($tipo=='combo')
{
   	$art=mysqli_query($con,"SELECT * FROM combos WHERE empresa='$empresa'")or die(mysqli_error($con));
   	while ($row=mysqli_fetch_array($art))
    {
        $com_id=$row['com_id'];
        $com_referencia=$row['com_referencia'];
        $com_nombre=$row['com_nombre'];
        $com_iva=$row['com_iva'];
        $pre_precio=0;
        $sql_pre=mysqli_query($con, "SELECT * from combos_articulos WHERE combos_com_id='$com_id'")or die(mysqli_error($con));
        while ($rw_pre=mysqli_fetch_array($sql_pre)) 
        {
	        $coma_art_id = $rw_pre['coma_art_id'];
	        $coma_art_cantidad = $rw_pre['coma_art_cantidad'];
	        $coma_art_precio = $rw_pre['coma_art_precio'];

	        $precio=$coma_art_cantidad*$coma_art_precio;
	        $pre_precio+=$precio;
        }
	?>
        <div id="" class="efec col-xs-6 col-sm-4" style="width:130px;" onclick="agregarcombo('<?php echo $com_id ?>')">
            <div class="panel panel-success "> 
             <span id="notification_menu">$ <?php echo number_format($pre_precio,0);?> </span>
                <div class="" style=" background-position:center; ">
                    <?php $nu=rand(1,1000);$nu;?>
                    <center><img src="img\combos\<?php echo $com_id.'.jpg?' .$nu .''; ?>" alt="" height="100px;" width="100%;" ></center>
                </div>
                <div class="" style="height:50px;background-color: #CCC">
                    <h5 style="text-align:center">
                    <p style="color:#000;font-size:10px;"><?php echo $com_nombre; ?></p></h5>
                </div>
            </div>
        </div>
        <input type="hidden" id="com_id<?php echo $com_id; ?>" value="<?php echo $com_id; ?>" >
        <input type="hidden" id="com_nombre<?php echo $com_id; ?>" value="<?php echo $com_nombre; ?>" >
        <input type="hidden" id="com_iva<?php echo $com_id; ?>" value="<?php echo $com_iva; ?>" >
	    <input type="hidden" id="com_cantidad<?php echo $com_id; ?>" value="1">
	    <input type="hidden" id="com_descuento<?php echo $com_id; ?>" value="0"> 
	    <input type="hidden" id="com_precio_venta<?php echo $com_id; ?>" value="<?php echo $pre_precio;?>" > 

<?php  
	}  
} 







else if ($tipo=='productos')
{
	$art=mysqli_query($con,"SELECT * FROM articulos WHERE art_tipo='producto' and art_estado='Activo' and empresa='$empresa'")or die(mysqli_error($con));
	while ($row=mysqli_fetch_array($art))
	{
	    $art_id=$row['art_id'];
	    $art_referencia=$row['art_referencia'];
	    $art_nombre=$row['art_nombre'];            
	    $art_precio_costo=$row["art_precio_costo"];
	    $art_iva=$row["art_iva"];
	    $pre_precio=$row['art_pvp'];
	?>
	    <div id="" class="efec col-xs-6 col-sm-4" style="width:130px;" onclick="agregar_producto_servicio('<?php echo $art_id ?>')">
	        <div class="panel panel-success "> 
	         <span id="notification_menu">$ <?php echo number_format($pre_precio,0);?> </span>
	            <div class="" style=" background-position:center; ">
	                <?php $nu=rand(1,1000);$nu;?>
	                <center><img src="img\articulos\<?php echo $art_id.'.jpg?' .$nu .''; ?>" alt="" height="100px;" width="100%;" ></center>
	            </div>
	            <div class="" style="height:50px;background-color: #CCC">
	                <h5 style="text-align:center">
	                <p style="color:#000;font-size:10px;"><?php echo $art_nombre; ?></p></h5>
	            </div>
	        </div>
	    </div>
	    <input type="hidden" id="tipo<?php echo $art_id; ?>" value="producto">
	    <input type="hidden" id="art_id<?php echo $art_id; ?>" value="<?php echo $art_id; ?>">
	    <input type="hidden" id="art_referencia<?php echo $art_id; ?>" value="<?php echo $art_referencia; ?>">
		<input type="hidden" id="nombre<?php echo $art_id; ?>" value="<?php echo $art_nombre; ?>">
	    <input type="hidden" id="cantidad<?php echo $art_id; ?>" value="1">
	    <input type="hidden" id="descuento<?php echo $art_id; ?>" value="0"> 
	    <input type="hidden" id="art_iva<?php echo $art_id;?>" value="<?php echo $art_iva; ?>" >
	    <input type="hidden" id="precio_venta<?php echo $art_id; ?>" value="<?php echo $pre_precio;?>">  
<?php  }  } 





else if ($tipo=='servicio')
{
	$art=mysqli_query($con,"SELECT * FROM articulos WHERE art_tipo='servicio' and empresa='$empresa'")or die(mysqli_error($con));
	while ($row=mysqli_fetch_array($art))
	{
	    $art_id=$row['art_id'];
	    $art_referencia=$row['art_referencia'];
	    $art_nombre=$row['art_nombre'];            
	    $art_precio_costo=$row["art_precio_costo"];
	    $art_iva=$row["art_iva"];
	    $pre_precio=$row['art_pvp'];
	?>
	    <div id="" class="efec col-xs-6 col-sm-4" style="width:130px;" onclick="agregar_producto_servicio('<?php echo $art_id ?>')">
	        <div class="panel panel-success "> 
	         <span id="notification_menu">$ <?php echo number_format($pre_precio,0);?> </span>
	            <div class="" style=" background-position:center; ">
	                <?php $nu=rand(1,1000);$nu;?>
	                <center><img src="img\articulos\<?php echo $art_id.'.jpg?' .$nu .''; ?>" alt="" height="100px;" width="100%;" ></center>
	            </div>
	            <div class="" style="height:50px;background-color: #CCC">
	                <h5 style="text-align:center">
	                <p style="color:#000;font-size:10px;"><?php echo $art_nombre; ?></p></h5>
	            </div>
	        </div>
	    </div>

	    <input type="hidden" id="tipo<?php echo $art_id; ?>" value="servicio">
	    <input type="hidden" id="art_id<?php echo $art_id; ?>" value="<?php echo $art_id; ?>">
	    <input type="hidden" id="art_referencia<?php echo $art_id; ?>" value="<?php echo $art_referencia; ?>">
		<input type="hidden" id="nombre<?php echo $art_id; ?>" value="<?php echo $art_nombre; ?>">
	    <input type="hidden" id="cantidad<?php echo $art_id; ?>" value="1">
	    <input type="hidden" id="descuento<?php echo $art_id; ?>" value="0"> 
	    <input type="hidden" id="art_iva<?php echo $art_id;?>" value="<?php echo $art_iva; ?>" >
	    <input type="hidden" id="precio_venta<?php echo $art_id; ?>" value="<?php echo $pre_precio;?>"> 
<?php } } ?>

<style>
.efec 
{
	transition: background-color .1s;
}

.efec:active 
{
  	background-color: orange;
  	border-radius: 5px;
}
</style>