<?php
session_start();

require_once('fpdf.php');
class PDF extends FPDF{


}


 $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','Letter');
 
    //$pdf->SetMargins(5, 0, 5); 
    $pdf->AddPage();
    $pdf->SetTopMargin(999999);
    
// $pdf->Image('logo.png',70,15, 22, 40);

   $id =$_GET['id'];
   
    $pdf->SetXY(10, 45);

    $pdf->SetFont('Arial','B',9);
    $pdf->Cell(78,7,'RECIBO Nro. ' .$_GET['id'] .' '. '- Fecha: '.date('d-m-Y'),'LTRB',0,'L');
    $pdf->Cell(18,7,'|','',0,'C');
    $pdf->Cell(98,7,'RECIBO Nro. ' .$_GET['id'] .' '. '- Fecha: '.date('d-m-Y'),'LTRB',1,'L');

$esult4=mysqli_query($connect, "SELECT DISTINCT a.id, a.person_id, b.rif_ci,b.name,b.lastname,
  b.address1 FROM sell a, person b WHERE a.id =$id and b.id=a.person_id");

   while($row44 = mysqli_fetch_array($esult4)){  

     $rif_ci = $row44['rif_ci']; 
     $lastname = $row44['lastname']; 
     $name = $row44['name']; 
     $address1 = $row44['address1']; 
     $CLIENTE = $name.' '.$lastname;
   

}

    $pdf->Cell(78,7,'RECIBIDO DE: ' .$CLIENTE,'LTRB',0,'L');
    $pdf->Cell(18,7,'|','',0,'C');
    $pdf->Cell(98,7,'RECIBIDO DE: ' .$CLIENTE,'LTRB',1,'L');


    $pdf->SetFont('Arial','B',7);

    $pdf->Cell(78,4,'POR CONCEPTO DE: ','LR',0,'C');
     $pdf->Cell(18,7,'|','',0,'C');
    $pdf->Cell(98,4,'POR CONCEPTO DE: ','LR',1,'C');
  $esult4=mysqli_query($connect, "SELECT DISTINCT a.created_at, a.sell_id, a.q, a.product_id, b.name, b.price_out, c.discount  FROM operation a,  sell c,  product b WHERE a.sell_id = $id and b.id=a.product_id and c.id=$id");
$po='';
   while($row44 = mysqli_fetch_array($esult4)){  
     $created_at = $row44['created_at']; 
   $ano2 = substr($created_at, -0, 10);

     $sell_id = $row44['sell_id']; 
     $product_id = $row44['product_id']; 
     $name = $row44['name']; 
     $price_out = $row44['price_out']; 
     $q = $row44['q']; 
     $discount = $row44['discount'];
$po += $q*$price_out;

  
    $pdf->Cell(78,4,$q. ' ' .$name,'LR',0,'L');
     $pdf->Cell(18,7,'|','',0,'C');
    $pdf->Cell(98,4,$q. ' ' .$name,'LR',1,'L');
}
    $pdf->Cell(78,4,'LA CANTIDAD DE Bs.: '.number_format($po-$discount,2, ',', '.'),'LTRB',0,'L');
     $pdf->Cell(18,7,'|','',0,'C');
    $pdf->Cell(98,4,'LA CANTIDAD DE Bs.: '.number_format($po-$discount,2, ',', '.'),'LTRB',1,'L');
    
    $pdf->Cell(19.5,4,'CHEQUE ','LR',0,'C');
    $pdf->Cell(19.5,4,'DEPOSITO ','LR',0,'C');
    $pdf->Cell(19.5,4,'EFECTIVO ','LR',0,'C');
    $pdf->Cell(19.5,4,'PUNTO V. ','LR',0,'C');
    $pdf->Cell(18,7,'|','',0,'C');
   
    $pdf->Cell(24.5,4,'CHEQUE ','LR',0,'C');
    $pdf->Cell(24.5,4,'DEPOSITO ','LR',0,'C');
    $pdf->Cell(24.5,4,'EFECTIVO ','LR',0,'C');
    $pdf->Cell(24.5,4,'PUNTO V. ','LR',1,'C');

    
    $pdf->Cell(19.5,4,' ','LRB',0,'C');
    $pdf->Cell(19.5,4,' ','LRB',0,'C');
    $pdf->Cell(19.5,4,' ','LRB',0,'C');
    $pdf->Cell(19.5,4,' ','LRB',0,'C');
    $pdf->Cell(18,7,'|','',0,'C');
    $pdf->Cell(24.5,4,' ','LRB',0,'C');
    $pdf->Cell(24.5,4,' ','LRB',0,'C');
    $pdf->Cell(24.5,4,' ','LRB',0,'C');
    $pdf->Cell(24.5,4,' ','LRB',1,'C');

    $pdf->Cell(78,7,'OBSERVACIONES: ','LTRB',0,'L');
     $pdf->Cell(18,7,'|','',0,'C');
    $pdf->Cell(98,7,'OBSERVACIONES: ','LTRB',1,'L');

   $pdf->Cell(78,9,'FIRMA : '.$CLIENTE,'LTRB',0,'L');
     $pdf->Cell(18,7,'|','',0,'C');
    $pdf->Cell(98,9,'FIRMA Y SELLO EMPRESA: ','LTRB',1,'L');

       $pdf->Ln(14);
    $pdf->Cell(0,7,'','B',0,'C');
 


mysqli_close($connect);
   

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