<?php
session_start();
require('../fpdf/fpdf.php');
require('plantilla_general.php');
require '../../../conexion.php';
require_once('../../../include/sesiones.php');

$art_familia=$_GET['art_familia'];
$art_proveedor=$_GET['art_proveedor'];
$stock=$_GET['stock'];

if($art_familia<>null  && $art_proveedor<>null)
{
    $sql1=mysqli_query($con,"SELECT * from articulos a, articulos_has_bodegas ab where familias_fam_id like '$art_familia' and proveedor_pro_id like '$art_proveedor' and a.art_id=ab.articulos_art_id and ab.bodegas='$bod_id' and a.empresa='$empresa' and ab.sucursal='$sucursal' and ab.art_cantidad<='$stock' group by a.art_id order by a.art_referencia asc");
}
else if($art_familia==null && $art_proveedor==null)
{
    $sql1=mysqli_query($con,"SELECT * from articulos a, articulos_has_bodegas ab where a.art_id=ab.articulos_art_id and ab.bodegas='$bod_id' and a.empresa='$empresa' and ab.sucursal='$sucursal' and ab.art_cantidad<='$stock' group by a.art_id order by a.art_referencia asc");
}

else if($art_familia<>null && $art_proveedor==null)
{
    $sql1=mysqli_query($con,"SELECT * from articulos a, articulos_has_bodegas ab where familias_fam_id like '$art_familia' and a.art_id=ab.articulos_art_id and ab.bodegas='$bod_id' and a.empresa='$empresa' and ab.sucursal='$sucursal' and ab.art_cantidad<='$stock' group by a.art_id order by a.art_referencia asc");
}
else if($art_familia==null && $art_proveedor<>null)
{
    $sql1=mysqli_query($con,"SELECT * from articulos a, articulos_has_bodegas ab where proveedor_pro_id like '$art_proveedor' and a.art_id=ab.articulos_art_id and ab.bodegas='$bod_id' and a.empresa='$empresa' and ab.sucursal='$sucursal' and ab.art_cantidad<='$stock' group by a.art_id order by a.art_referencia asc");
}
    
$pdf=new PDF_MC_Table();
$pdf->AddPage();
$pdf->SetFont('Arial','',14);
$pdf->AliasNbPages();

$pdf->Cell(0,10,'INVENTARIO ESCASO',0,1);

$pdf->SetFont('Arial','',7);
$pdf->SetFillColor(235,225,215);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(15,6,'CODIGO',1,0,'C',1);
$pdf->Cell(90,6,'NOMBRE',1,0,'C',1);
$pdf->Cell(20,6,'CATEGORIA',1,0,'C',1);
$pdf->Cell(25,6,'PROVEEDOR',1,0,'C',1);
$pdf->Cell(15,6,'CANTIDAD',1,0,'C',1);
$pdf->Cell(25,6,'COSTO',1,0,'C',1);
$pdf->Ln(); 
$pdf->SetFont('Arial','',7);

while ($row=mysqli_fetch_array($sql1))    
{
    $art_id=$row['art_id'];
    $art_referencia=$row['art_referencia'];
    $art_nombre=$row['art_nombre'];
    $art_precio_costo=$row['art_precio_costo'];
    $art_cantidad=$row['art_cantidad'];
    $familias_fam_id=$row['familias_fam_id'];
    $proveedor_pro_id=$row['proveedor_pro_id'];

    $sql=mysqli_query($con, "SELECT * from familias where fam_id='$familias_fam_id' and empresa='$empresa'");
    $roww=mysqli_fetch_array($sql);
    $fam_nombre = $roww ? $roww['fam_nombre'] : 'SIN FAMILIA';
  
   
    $sql=mysqli_query($con, "SELECT * from proveedor where pro_id='$proveedor_pro_id' and empresa='$empresa'");
    $roww=mysqli_fetch_array($sql);
    $pro_nombre = $roww ? $roww['pro_nombre'] : 'SIN PROVEEDOR';

    $pdf->SetWidths(array(15,90,20,25,15,25));
    srand(time()*1000000);
    $pdf->Row(array($art_referencia,utf8_decode($art_nombre),utf8_decode($fam_nombre),utf8_decode($pro_nombre),$art_cantidad,number_format($art_precio_costo,0)));
}

$pdf->Output();
?>