<?php require('vendor/fpdf/fpdf.php'); $connect = mysqli_connect('localhost','root',''); mysqli_select_db($connect,'egm_simple_invoice'); class PDF extends FPDF { function Header(){ $connect = mysqli_connect('localhost','root',''); mysqli_select_db($connect,'egm_simple_invoice'); $sql_order="SELECT order_id, order_receiver_name, receiver_contact, order_receiver_address, order_total_before_tax, order_total_tax, order_total_after_tax, order_created_at FROM tbl_orders WHERE order_id = '".$_GET["order_id"]."'"; $query_invoice = mysqli_query($connect, $sql_order); $row = mysqli_fetch_array($query_invoice); $this->SetFont('Arial','B',30); $this->Cell(12); $this->Image('images/foundation.jpeg',20,20,50); $this->SetTextColor(0, 0, 0); $this->SetY(30); $this->SetFont('Arial','B',20); $this->Cell(323,-40,'RECEIPT',0,10,'C'); $this->SetFont('Arial','',12); $this->Cell(323,52,'No. '.$row['order_id'],0,10,'C'); $this->SetX(605); $this->Ln(1); $cellWidth = 50; $cellHeight = 5; $this->SetY(10); $this->SetFont('Arial','B',13); $this->Cell(323,40,'Issued to:',0,0,'C'); $this->SetFont('Arial','',20); $this->SetTextColor(0,0,220); $this->Ln(27); $this->Cell(135,50,'',0,0); $this->MultiCell($cellWidth,$cellHeight,$row['order_receiver_name'],0, 0); $this->SetFont('Arial','',10); $this->SetTextColor(0,0,0); $this->Ln(1); $this->Cell(135,100,'',0,0); $this->MultiCell($cellWidth,$cellHeight,$row['receiver_contact'],0, 0); $this->Cell(135,100,'',0,0); $this->MultiCell($cellWidth,$cellHeight,$row['order_receiver_address'],0, 10); $this->SetX(605); $this->Ln(10); $this->SetY(25); $this->SetFont('Arial', 'B', 10); $this->SetTextColor(0,0,0); $this->Ln(0); $this->SetX(65); $this->Ln(10); $this->SetX(-25); $this->SetFont('Arial','B',14); $this->Cell(450 ,3,'',0,1); $this->SetFont('Arial','B',10); $this->Cell(0 ,5,' EIN: 86-2617396 ',0,0); $this->SetFont('Arial','',14); $this->Cell(0 ,5,'',0,1); $this->SetFont('Arial','',10); $this->Cell(0 ,5,' Sheridan, WY, USA 82801 ',0,1); $this->SetY(505); $this->SetY(15); $this->Ln(30); $this->Ln(20); $this->SetFont('Arial','B',12); $this->SetFillColor(0, 0, 230); $this->SetDrawColor(0,0,0); $this->SetFont('Arial', 'B', 12); $this->SetTextColor(255,255,255); $this->Cell(64,10,'Description',0,0,'',true); $this->Cell(63,10,'Date',0,0,'',true); $this->Cell(63,10,'Amount',0,1,'',true); } function Footer(){ $this->SetY(-15); $this->SetFont('Arial','',8); $this->Cell(0,10,'Page '.$this->PageNo()." / {pages}",0,0,'C'); } } $pdf = new PDF('P','mm','A4'); $pdf->AliasNbPages('{pages}'); $pdf->SetAutoPageBreak(true,15); $pdf->AddPage(); $pdf->SetFont('Arial','',10); $pdf->SetDrawColor(0,0,0); $sql_item="SELECT i.item_name, i.order_item_quantity, i.order_item_price, i.order_item_tax_amount, i.order_item_subtotal_amount, i.order_item_final_amount, o.order_created_at FROM invoice_order_item AS i, tbl_orders as o WHERE i.order_id = o.order_id AND i.order_id = '".$_GET["order_id"]."'"; $query_item = mysqli_query($connect, $sql_item); while($data = mysqli_fetch_array($query_item)){ $cellWidth = 64; $cellHeight = 5; if($pdf->GetStringWidth($data[0]) < $cellWidth){ $line = 1; }else{ $textLength = strlen($data[0]); $errMargin = 10; $startChar = 0; $maxChar = 0; $textArray = array(); $tmpString = ""; while($startChar < $textLength){ while( $pdf->GetStringWidth( $tmpString ) < ($cellWidth-$errMargin) && ($startChar+$maxChar) < $textLength ) { $maxChar++; $tmpString = substr($data[0],$startChar,$maxChar); } $startChar = $startChar+$maxChar; array_push($textArray,$tmpString); $maxChar = 0; $tmpString = ''; } $line = count($textArray); } $xPos = $pdf->GetX(); $yPos = $pdf->GetY(); $pdf->MultiCell($cellWidth,$cellHeight,$data[0],0); $pdf->SetXY($xPos + $cellWidth , $yPos); $pdf->Cell(63,($line * $cellHeight),$data[6],0,0); $pdf->Cell(63,($line * $cellHeight),$data[4],0,1); } $pdf->Ln(20); $connect = mysqli_connect('localhost','root',''); mysqli_select_db($connect,'egm_simple_invoice'); $sql_order="SELECT order_total_before_tax, order_total_tax, order_total_after_tax, order_note FROM tbl_orders WHERE order_id = '".$_GET["order_id"]."'"; $query_invoice = mysqli_query($connect, $sql_order); $row = mysqli_fetch_array($query_invoice); $pdf->SetFont('Arial','B',11); $pdf->SetFillColor(0, 0, 230); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(130,5,'',0,0); $pdf->Cell(30,5,'Sub Total',0,0); $pdf->Cell(30,5,'$ '.number_format($row['order_total_before_tax'],2),0,1); $pdf->SetTextColor(255, 0, 0); $pdf->Cell(130,5,'',0,0); $pdf->Cell(30,5,'Platform Fee',0,0); $pdf->Cell(30,5,'$ '.number_format($row['order_total_tax'],2),0,1); $pdf->SetTextColor(0, 0, 0); $pdf->Ln(1); $pdf->Cell(130,40,'',0,0); $pdf->Cell(5,-5,'__________________________',0,0); $pdf->Ln(1); $pdf->Cell(130,5,'',0,0); $pdf->Cell(30,5,'Total',0,0); $pdf->Cell(30,5,'$ '.number_format($row['order_total_after_tax'],2),0,1); // $pdf->Ln(10); //$pdf->SetFont('Arial','B',10); //$pdf->Cell(190,5,'Note:',0,1); //$pdf->SetFont('Arial','',10); // $cellWidth = 190; // $cellHeight = 5; // $pdf->MultiCell($cellWidth,$cellHeight,$row['order_note'],0); // // $pdf->Ln(10); //$pdf->SetFont('Arial','B',10); //$pdf->Cell(100,5,'Note:',0,1); //$pdf->SetFont('Arial','',10); //$cellWidth = 190; //$cellHeight = 5; //$pdf->MultiCell($cellWidth,$cellHeight,$row['order_note'],0); $connect = mysqli_connect('localhost','root',''); mysqli_select_db($connect,'egm_simple_invoice'); $sql_order="SELECT order_created_at FROM tbl_orders WHERE order_id = '".$_GET["order_id"]."'"; $query_invoice = mysqli_query($connect, $sql_order); $row = mysqli_fetch_array($query_invoice); $pdf->Ln(50); $pdf->SetFont('Arial','B',11); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(140,5,'',0,0); $pdf->Cell(30,5,'Tyler C. Andrews',0,1); $pdf->Cell(130,-40,'',0,0); $pdf->Cell(80,-1,'________________________',0,1); $pdf->SetFont('Arial','',10); $pdf->Cell(146,5,'',0,0); $pdf->Cell(45,15,'President ',2,0,0); $pdf->Ln(30); $pdf->SetFont('Arial','B',11); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(10,5,'',0,0); $pdf->Cell(30,5,'Issued on: ',0,1); $pdf->SetFont('Arial','',10); $pdf->Cell(10,5,'',0,0); $pdf->Cell(45,5,$row['order_created_at'],2,0,0); if(isset($_GET["output"])){ $pdf->Output('D','Invoice.pdf'); }else{ $pdf->Output('I','Invoice.pdf'); } ?>