<?php
	ob_start();
	session_start();
    require '../../../conexion.php';
    require_once('../../../include/sesiones.php');
	
    //Variables por GET
    $fam_id=$_GET['fam_id'];
    $tar_id=$_GET['tar_id'];
    $mar_id=0;
    $cantidad='en_stock';
?>

<style type="text/css">
    #divid{
    float: left;
    width: 60mm;
    height:82mm;
    margin-left: 5mm;
    margin-top: 5mm;
    border: 2px solid #000000;
    border-radius:10px;
    word-wrap: break-word;   
    overflow: hidden;
    text-align: center;
    }

    .table {
    margin-top: 0px;
    margin-left: 1.5mm;
    margin-right: 1.5mm;
    text-align: center;    
    }
</style>

<page backtop="10mm" backbottom="10mm" backleft="10mm" backright="10mm" style="font-size: 10pt; font-family: arial; " >
  
    <?php
    $empresa=1;
    if ($fam_id<>0) 
    {
        if ($mar_id==0) 
        {
            if ($cantidad=='en_stock') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where a.familias_fam_id='$fam_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id and b.art_cantidad>0 and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc "); 
            }
            else if ($cantidad=='todos') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where a.familias_fam_id='$fam_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id  and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc "); 
            }
            else if ($cantidad=='agotados') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where a.familias_fam_id='$fam_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id  and b.art_cantidad<0 and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc "); 
            }
        } 
        else 
        {
            if ($cantidad=='en_stock') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where a.familias_fam_id='$fam_id' and a.marca_mar_id='$mar_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id and b.art_cantidad>0 and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc ");
            }
            else if ($cantidad=='todos') 
            {
               $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where a.familias_fam_id='$fam_id' and a.marca_mar_id='$mar_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc ");
            }
            else if ($cantidad=='agotados') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where a.familias_fam_id='$fam_id' and a.marca_mar_id='$mar_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id and b.art_cantidad<0 and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc ");
            }
        }
    }
    else
    {
         if ($mar_id==0) 
        {
            if ($cantidad=='en_stock') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where  a.empresa='$empresa' and a.art_id=b.articulos_art_id and b.art_cantidad>0 and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc "); 
            }
            else if ($cantidad=='todos') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where  a.empresa='$empresa' and a.art_id=b.articulos_art_id  and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc "); 
            }
            else if ($cantidad=='agotados') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where  a.empresa='$empresa' and a.art_id=b.articulos_art_id  and b.art_cantidad<0 and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc "); 
            }
        } 
        else 
        {
            if ($cantidad=='en_stock') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where  a.marca_mar_id='$mar_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id and b.art_cantidad>0 and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc ");
            }
            else if ($cantidad=='todos') 
            {
               $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where  a.marca_mar_id='$mar_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc ");
            }
            else if ($cantidad=='agotados') 
            {
                $can=mysqli_query($con,"SELECT *,LEFT(a.art_nombre,120) as nombre , a.art_id as art_id from articulos a , articulos_has_bodegas b where a.familias_fam_id='$fam_id' and a.marca_mar_id='$mar_id' AND a.empresa='$empresa' and a.art_id=b.articulos_art_id and b.art_cantidad<0 and b.empresa='$empresa' and art_estado='Activo' order by art_nombre asc ");
            }
        }
    }

    while($row=mysqli_fetch_array($can))
    {
        $art_id=$row['art_id'];
        $art_pvp=$row['art_pvp'];
        $art_referencia2=$row['art_referencia2'];        
        $new = '../../../img/articulos/'.$art_id.'.jpg';
        //Compruebo si existe la foto
        if (file_exists($new)) { 
    ?>
    <div id="divid">
        <table class="table" cellspacing="0" cellpadding="0" border="0" >
            <tr style=" ">
                <td ><center>
                    <img style="height:165px;padding:5px;" src="https://technopolis.vicpos.com/img/articulos/1000.png"></br>
                    <strong style="font-size:12px;"><?php  echo $row['nombre'];?></storng></br></br>
                    <spam>COD: <strong><?php echo $row['art_referencia']; ?></strong></spam>
                    <?php if ($art_referencia2<>null) 
                    { ?>
                        </br>
                     <spam>REF: <strong><?php echo $row['art_referencia2']; ?></strong></spam>
                     <?php 
                    }?>
                   </br>
                        <strong style="color: red; font-size: 15px;"> $: 
                            <?php 
                            $can1=mysqli_query($con,"SELECT * FROM precio where tarifas_tar_id='$tar_id' and articulos_art_id='$art_id' AND empresa='$empresa' ");
                            $dat1=mysqli_fetch_array($can1); 

                           echo number_format($dat1['pre_precio']); ?>
                        </strong></br>
                    </center>
                </td>
            </tr>
        </table> 
    </div>

    <?php } else { ?>

    <div id="divid">
        <table class="table" cellspacing="0" cellpadding="0" border="0" >
            <tr style=" ">
                <td style="width: 60%">
                    <img style="width: 165px;padding: 5px" src="https://technopolis.vicpos.com/img/articulos/1000.png">
                    <p><strong style="font-size:12px;"><?php  echo $row['nombre'];?><spam></p>
                    <spam>COD: <?php echo $row['art_referencia']; ?></spam></br>
                    <?php if ($art_referencia2<>null) 
                    { ?>
                     <spam>REF: <?php echo $row['art_referencia2']; ?></spam>
                     <?php 
                    }else { }?>
                   <p>
                        <strong style="color: red;"> $: 
                            <?php 
                            $can1=mysqli_query($con,"SELECT * FROM precio where tarifas_tar_id='$tar_id' and articulos_art_id='$art_id' AND empresa='$empresa' ");
                            $dat1=mysqli_fetch_array($can1); 

                             echo number_format($dat1['pre_precio']); ?>
                        </strong>
                    </p>
                </td>
            </tr>
        </table> 
    </div>
    <?php } } ?>
</page>

<script language="Javascript">
window.print();
window.onafterprint = function () {
    //window.close();
}

</script>

