



<?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,b.phone1, 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']; 
      $phone1 = $row44['phone1']; 
     $CLIENTE = $name.' '.$lastname;
     $created_at = $row44['created_at']; 
     $fecha = $created_at;
$ano = substr($fecha, -10, 4);
$mes = substr($fecha, -5, 2);
$dia = substr($fecha, -2, 2);
   

}



    $pdf->SetFont('Arial','B',8);
     $pdf->Ln(6);
    $pdf->Cell(152,4,'','',0,'C');

    $pdf->Cell(37,4,'CORO                 ' .$dia.' '.$mes.'     '.$ano,'',1,'C');
     $pdf->Cell(37,4, '','',1,'C');
   

    $pdf->Cell(37,4,'','',1,'C');
    $pdf->Cell(37,4,'','',1,'L');

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

    $pdf->Cell(37,4,'','',1,'C');
         $pdf->Ln(7);
 
    $pdf->SetFont('Arial','B',8);

    $pdf->Cell(57,4,'','',0,'C');
    $pdf->Cell(37,4,$CLIENTE,'',1,'C');
    $pdf->Ln(5);
    $pdf->Cell(57,4,'','',0,'C');
    $pdf->Cell(37,4,$address1,'',1,'C');
    $pdf->Ln(5);
    $pdf->Cell(57,4,'','',0,'C');
    $pdf->Cell(27,4,$phone1,'',0,'C');
    $pdf->Cell(29,4,'','',0,'C');
    $pdf->Cell(27,4,$rif_ci,'',1,'C');
    $pdf->SetFont('Arial','B',9);
    $pdf->Ln(6);
    $pdf->Cell(99,4,'','',0,'C');
    $pdf->Cell(27,4,$created_at,'',1,'C');



       $pdf->Ln(10);
   $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->Ln(13);
  
    $pdf->Cell(17,4,$q,'',0,'C');
    $pdf->Cell(27,4,'','',0,'C');
    $pdf->Cell(37,4,$name,'',0,'C');
    $pdf->Cell(53,4,'','',0,'C');
    $pdf->Cell(37,4,number_format($price_out,2, ',', '.'),'',0,'C');
    $pdf->Cell(37,4,number_format($po,2, ',', '.'),'',0,'C');


}  
     $pdf->Ln(5); 
$pdf->Ln(144);
    $pdf->Cell(17,4,'','',0,'C');
    $pdf->Cell(27,4,'','',0,'C');
    $pdf->Cell(37,4,'','',0,'C');
    $pdf->Cell(53,4,'','',0,'C');
    $pdf->Cell(37,4,'','',0,'C');
    $ro=$po*0.12;
    $pdf->Cell(37,4,number_format($po,2, ',', '.'),'',1,'C');
    $pdf->Ln(1);

    $pdf->Cell(98,4,'','',0,'C');
    $pdf->Cell(3,4,'12  ','',0,'C');
    $pdf->Cell(73,4,'','',0,'C');
    $pdf->Cell(37,4,number_format($ro,2, ',', '.'),'',1,'C');
    $pdf->Ln(3);
    $pdf->Cell(171,4,'','',0,'C');
    $pdf->Cell(37,4,number_format($po+$ro,2, ',', '.'),'',0,'C');

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