<?php
session_start();





require_once('fpdf.php');
class PDF extends FPDF{
	function Header()
{ 
 $this->SetXY(0, 0);
 $this->Image('logo.png',70,15, 65, 40);
 $this->Ln(4);   
}
function Footer()
{
    $this->SetY(15);
    $this->SetFont('Arial','I',12);
}
}

$pdf = new PDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','',6);








	$pdf->SetFillColor(102,178,255);
    $pdf->SetFont('Arial','B',10);
    $pdf->SetXY(10, 45);
    $pdf->Cell(17,10,utf8_decode('ID Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(27,10,utf8_decode('Fecha Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(73,10,utf8_decode('Denominación'),'LTRB',0,'C',true);
    $pdf->Cell(43,10,utf8_decode('Monto'),'LTRB',1,'C',true);

 





 $db_host = 'localhost';
$db_name = 'rblcomve_inventiolite';
$db_user = 'rblcomve_root';
$db_pass = '$0WBF2agJ.G_';

$connect = new mysqli ($db_host, $db_user, $db_pass, $db_name);

$inicial=$_POST['inicial'];
$final=$_POST['final'];



    $pdf = new PDF('P','mm','A4');
    $pdf->AddPage();

    $pdf->SetFillColor(102,178,255);
    $pdf->SetFont('Arial','B',8.4);
    $pdf->SetXY(10, 45);
 
    $pdf->SetFont('Arial','B',12);
    $pdf->Cell(0,7,'CONTROL DEL INVENTARIO DIARIO DE RBL C.A.','',1,'C');
       $pdf->SetFont('Arial','B',10);
    $pdf->Ln(3);


$fecha = $inicial;
$ano = substr($fecha, -10, 4);
$mes = substr($fecha, -5, 2);
$dia = substr($fecha, -2, 2);

$fecha2 = $querys_pdf->FECHA_BAUTISMO;
$ano2 = substr($fecha2, -10, 4);
$mes2 = substr($fecha2, -5, 2);
$dia2 = substr($fecha2, -2, 2);

if ($mes=='01'){
    $mes_le='Enero';
}elseif ($mes=='02'){
    $mes_le='Febrero';
}elseif ($mes=='03'){
    $mes_le='Marzo';
}elseif ($mes=='04'){
    $mes_le='Abril';
}elseif ($mes=='05'){
    $mes_le='Mayo';
}elseif ($mes=='06'){
    $mes_le='Junio';
}elseif ($mes=='07'){
    $mes_le='Julio';
}elseif ($mes=='08'){
    $mes_le='Agosto';
}elseif ($mes=='09'){
    $mes_le='Septiembre';
}elseif ($mes=='10'){
    $mes_le='Octubre';
}elseif ($mes=='11'){
    $mes_le='Noviembre';
}elseif ($mes=='12'){
    $mes_le='Diciembre';
}





    $pdf->Cell(0,7,'Santa Ana de Coro, '.$dia.' de '.$mes_le.' del '.$ano ,'',1,'R');
    $pdf->Ln(4);
    $pdf->SetFont('Arial','B',8.4);

$result=mysqli_query($connect, "SELECT a.product_id, b.name, SUM(a.`q`) FROM `operation` a, product b WHERE a.operation_type_id=1 and a.created_at between '$inicial' and '$final' and b.id=a.product_id group by a.product_id");

$pdf->Cell(0,7,'ENTRADAS','',1,'C');    
 $pdf->Cell(19,7,'','',0,'C');
    $pdf->Cell(19,7,utf8_decode('Cod. Prod.'),'LTRB',0,'C',true);
    $pdf->Cell(100,7,utf8_decode('Denominacion'),'LTRB',0,'C',true);
    $pdf->Cell(33,7,utf8_decode('Cantidad. Sal.'),'LTRB',1,'C',true);

$total_total='';
 while($row2 = mysqli_fetch_array($result))
{  

 $product_id = $row2['product_id'];
 $name = $row2['name'];
 $product_id = $row2['product_id'];
 $suma2 = $row2['SUM(a.`q`)'];

$pdf->Cell(19,7,'','',0,'C');
 $pdf->Cell(19,7,$product_id,'LTRB',0,'C');
 $pdf->Cell(100,7,$name,'LTRB',0,'C');
 $pdf->Cell(33,7,$suma2,'LTRB',1,'C');

}





    $pdf->Ln(4);







$pdf->Cell(0,7,'SALIDAS','',1,'C');
    $pdf->Cell(19,7,'','',0,'C');
    $pdf->Cell(19,7,utf8_decode('Cod. Prod.'),'LTRB',0,'C',true);
    $pdf->Cell(100,7,utf8_decode('Denominacion'),'LTRB',0,'C',true);
    $pdf->Cell(33,7,utf8_decode('Cantidad. Sal.'),'LTRB',1,'C',true);



$result=mysqli_query($connect, "SELECT a.product_id, b.name, SUM(a.`q`) FROM `operation` a, product b WHERE a.operation_type_id=2 and a.created_at between '$inicial' and '$final' and b.id=a.product_id group by a.product_id");

    
$total_total='';
 while($row2 = mysqli_fetch_array($result))
{  

 $product_id = $row2['product_id'];
 $name = $row2['name'];
 $product_id = $row2['product_id'];
 $suma1 = $row2['SUM(a.`q`)'];

$pdf->Cell(19,7,'','',0,'C');
 $pdf->Cell(19,7,$product_id,'LTRB',0,'C');
 $pdf->Cell(100,7,$name,'LTRB',0,'C');
 $pdf->Cell(33,7,$suma1,'LTRB',1,'C');

}



  $pdf->Ln(4);



 $pdf->Cell(0,7,'CEMENTO USADO POR LA BLOQUERA RBL CA','',1,'C');    
 $pdf->Cell(19,7,'','',0,'C');
    $pdf->Cell(19,7,utf8_decode('Cod. Prod.'),'LTRB',0,'C',true);
    $pdf->Cell(100,7,utf8_decode('Denominacion'),'LTRB',0,'C',true);
    $pdf->Cell(33,7,utf8_decode('Usados:'),'LTRB',1,'C',true);
$total_total='';
 
$result1=mysqli_query($connect, "SELECT a.product_id, b.name, SUM(a.`q`) FROM `operation` a, product b WHERE a.operation_type_id=2 and a.created_at between '$inicial' and '$final' and b.id=a.product_id and sell_id in (SELECT id FROM `sell` WHERE `person_id` = 45 and created_at between '$inicial' and '$final' ) group by a.product_id");
 while($row2 = mysqli_fetch_array($result1))
{  
 $product_id = $row2['product_id'];
 $name = $row2['name'];
 $product_id = $row2['product_id'];
 $suma = $row2['SUM(a.`q`)'];

$pdf->Cell(19,7,'','',0,'C');
 $pdf->Cell(19,7,$product_id,'LTRB',0,'C');
 $pdf->Cell(100,7,$name,'LTRB',0,'C');
 $pdf->Cell(33,7,$suma,'LTRB',1,'C');

}


   

$pdf->Output('mov_inventario.pdf','D');
?>