<?php

 $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->Image('logo.png',70,15, 22, 40);

   $id =$_GET['id'];

session_start();

require_once('fpdf.php');

$pdf = new FPDF();
$pdf->SetMargins(5, 5, 30); 
$pdf->SetAutoPageBreak(true,5);
$pdf->AddPage();



$esult4=mysqli_query($connect, "SELECT DISTINCT a.id, a.person_id, b.rif_ci,b.name,b.lastname,
  b.address1, a.created_at 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;
     $created_at = $row44['created_at']; 
   

}



    $pdf->SetFont('Arial','B',8);
    $pdf->Cell(37,4,'RECIBO Nro. ' .$_GET['id'],'LTRB',1,'C');
     $pdf->Cell(37,4, 'Fecha: '.$created_at,'LTRB',1,'C');
   

    $pdf->Cell(37,4,'RECIBIDO DE:','LTR',1,'C');
    $pdf->Cell(37,4,$CLIENTE,'LRB',1,'L');

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

    $pdf->Cell(37,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, product b, sell c 
  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(37,4,$q,'LR',1,'C');
    $pdf->Cell(37,4,$name,'LR',1,'C');
}
    $pdf->SetFont('Arial','B',8);
    $pdf->Cell(37,4,'LA CANTIDAD DE Bs.: ','LTR',1,'C');
    $pdf->Cell(37,4,number_format($po-$discount,2, ',', '.'),'LRB',1,'C');
     $pdf->SetFont('Arial','B',4.5);
    
    $pdf->Cell(9.25,4,'CHEQUE ','LR',0,'C');
    $pdf->Cell(9.25,4,'DEPOSITO ','LR',0,'C');
    $pdf->Cell(9.25,4,'EFECTIVO ','LR',0,'C');
    $pdf->Cell(9.25,4,'PUNTO V. ','LR',1,'C');
  

    
    $pdf->Cell(9.25,4,' ','LRB',0,'C');
    $pdf->Cell(9.25,4,' ','LRB',0,'C');
    $pdf->Cell(9.25,4,' ','LRB',0,'C');
    $pdf->Cell(9.25,4,' ','LRB',1,'C');
     $pdf->SetFont('Arial','B',7);

    $pdf->Cell(37,7,'OBSERVACIONES: ','LTRB',1,'L');
    
$esult4=mysqli_query($connect, "SELECT DISTINCT a.id, a.person_id, b.rif_ci,b.name,b.lastname,
  b.address1, a.created_at 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;
     $created_at = $row44['created_at']; 
   

}
 
   $pdf->Cell(37,6,$CLIENTE,'LTR',1,'L');
   $pdf->Cell(37,6,'FIRMA :',' LRB ',1,'L');   
     
$pdf->Cell(37,7,'','B',1,'C');
    $pdf->Ln(2);

 $pdf->SetFont('Arial','B',8);
    $pdf->Cell(37,4,'RECIBO Nro. ' .$_GET['id'],'LTRB',1,'C');
     $pdf->Cell(37,4, 'Fecha: '.$created_at,'LTRB',1,'C');
   



    $pdf->Cell(37,4,'RECIBIDO DE:','LTR',1,'C');
    $pdf->Cell(37,4,$CLIENTE,'LRB',1,'L');

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

    $pdf->Cell(37,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, product b, sell c 
  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(37,4,$q,'LR',1,'C');
    $pdf->Cell(37,4,$name,'LR',1,'C');
}
    $pdf->SetFont('Arial','B',8);
    $pdf->Cell(37,4,'LA CANTIDAD DE Bs.: ','LTR',1,'C');
    $pdf->Cell(37,4,number_format($po-$discount,2, ',', '.'),'LRB',1,'C');
     $pdf->SetFont('Arial','B',4.5);
    
    $pdf->Cell(9.25,4,'CHEQUE ','LR',0,'C');
    $pdf->Cell(9.25,4,'DEPOSITO ','LR',0,'C');
    $pdf->Cell(9.25,4,'EFECTIVO ','LR',0,'C');
    $pdf->Cell(9.25,4,'PUNTO V. ','LR',1,'C');
  

    
    $pdf->Cell(9.25,4,' ','LRB',0,'C');
    $pdf->Cell(9.25,4,' ','LRB',0,'C');
    $pdf->Cell(9.25,4,' ','LRB',0,'C');
    $pdf->Cell(9.25,4,' ','LRB',1,'C');
     $pdf->SetFont('Arial','B',7);

    $pdf->Cell(37,7,'OBSERVACIONES: ','LTRB',1,'L');
    

 
   $pdf->Cell(37,6,'EMPRESA:','LTR',1,'L');
   $pdf->Cell(37,6,'FIRMA/SELLO:',' LRB ',1,'L');   
     
 




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