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

$ordenar=$_GET['ordenar'];
$art_proveedor=$_GET['art_proveedor'];

$sumador_total_costo=0; 
$sumador_total_venta=0; 

if($art_proveedor<>null)
{
    $query=mysqli_query($con, "SELECT * from articulos where proveedor_pro_id='$art_proveedor' and empresa='$empresa' order by $ordenar asc");
}
else
{
    $query=mysqli_query($con, "SELECT * from articulos where empresa='$empresa' order by $ordenar asc");
}


$pdf=new PDF_MC_Table('L','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','',14);
$pdf->AliasNbPages();

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

$pdf->SetFont('Arial','',7);
$pdf->SetFillColor(235,225,215);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(20,6,'CODIGO',1,0,'C',1);
$pdf->Cell(115,6,'NOMBRE',1,0,'C',1);
$pdf->Cell(15,6,'STOCK',1,0,'C',1);
$pdf->Cell(15,6,'IMP %',1,0,'C',1);
$pdf->Cell(25,6,'COSTO S/IVA',1,0,'C',1);
$pdf->Cell(25,6,'COSTO C/IVA',1,0,'C',1);
$pdf->Cell(21,6,'COSTO TOTAL',1,0,'C',1);
$pdf->Cell(20,6,'VENTA U',1,0,'C',1);
$pdf->Cell(20,6,'VENTA TOTAL',1,0,'C',1);
$pdf->Ln(); 
$pdf->SetFont('Arial','',7);

while ($row=mysqli_fetch_array($query))    
{
    $art_id=$row['art_id'];
    $art_referencia=$row['art_referencia'];
    $art_nombre=$row['art_nombre'];
    $art_cargo_adicional=$row['art_cargo_adicional'];
    $art_precio_costo=$row['art_precio_costo']+$art_cargo_adicional;
    if ($row['art_iva']>0){ $art_iva=$row['art_iva']; } else { $art_iva='0';}
    $art_pvp=$row['art_pvp'];

    $sql1c=mysqli_query($con,"SELECT sum(art_cantidad) as art_cantidad FROM articulos_has_bodegas where sucursal='$sucursal' and empresa='$empresa' and articulos_art_id='$art_id' ");
    $row1c=mysqli_fetch_array($sql1c);
    $art_cantidad=$row1c['art_cantidad'];
    if($art_cantidad<=0)
    {
        $art_cantidad1=0;
    }
    else
    {
        $art_cantidad1=$art_cantidad;
    }
    $iva0=$art_iva/100; //0.19
    $iva1=1+$iva0; //1.19
    $costo_unit_sin_iva=($art_precio_costo/$iva1); //precio sin iva  840.336

    $valor_costo=$art_precio_costo*$art_cantidad1;
    $valor_venta=$art_pvp*$art_cantidad1;
    $sumador_total_costo+=$valor_costo;
    $sumador_total_venta+=$valor_venta;

    $pdf->SetWidths(array(20,115,15,15,25,25,21,20,20));
    srand(time()*1000000);
    $pdf->Row(array($art_referencia,utf8_decode($art_nombre),$art_cantidad1,$art_iva,number_format($costo_unit_sin_iva,0),number_format($art_precio_costo,0),number_format($valor_costo,0),number_format($art_pvp,0),number_format($valor_venta,0)));
}
    $pdf->SetFillColor(135,245,115);
    $pdf->SetFont('Arial','B',8);
    $pdf->Cell(190,6,'',1,0,'C',1);
    $pdf->Cell(25,6,'TOTAL',1,0,'C',1);
    $pdf->Cell(21,6,number_format($sumador_total_costo,0),1,0,'C',1);
    $pdf->Cell(20,6,'',1,0,'C',1);
    $pdf->Cell(20,6,number_format($sumador_total_venta,0),1,0,'C',1);
    $pdf->Ln();

$pdf->Output();
?>