Last active
February 6, 2022 15:08
-
-
Save amattu2/31f843122783508fbb227c491eea9665 to your computer and use it in GitHub Desktop.
This is a PHP class for generating automotive-type invoices/repair orders. Uses FPDF as the PDF generator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Produced: Fri Jan 07 2022 | |
* Author: Alec M. | |
* GitHub: https://amattu.com/links/github | |
* Copyright: (C) 2022 Alec M. | |
* License: License GNU Affero General Public License v3.0 | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU Affero General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU Affero General Public License for more details. | |
* | |
* You should have received a copy of the GNU Affero General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
// Application Namespace | |
namespace amattu\PDF; | |
// Import FPDF | |
use FPDF; | |
/** | |
* A class for generating an automotive Repair Order | |
* | |
* @author Alec M. | |
*/ | |
class RepairOrder extends FPDF { | |
/** | |
* PDF Default Font Size | |
* | |
* @var integer | |
*/ | |
protected $fontSize = 9; | |
/** | |
* Dynamic PDF column width | |
* | |
* @var integer | |
*/ | |
protected $ColWidth = 0; | |
/** | |
* Default PDF line height | |
* | |
* @var integer | |
*/ | |
protected $lineHeight = 4; | |
/** | |
* Default space between PDF sections | |
* | |
* @var integer | |
*/ | |
protected $sectionSpace = 9; | |
/** | |
* Default space between PDF lines | |
* | |
* @var float | |
*/ | |
protected $totalSpace = 0.8; | |
/** | |
* Default footer signature line contents | |
* | |
* @var string | |
*/ | |
private $signature_line = 'DATE ____________________________ SIGNED _________________________________'; | |
/** | |
* Default footer email address (secondary line) | |
* | |
* @var string | |
*/ | |
private $email_line = 'EMAIL ADDRESS _________________________________'; | |
/** | |
* Class constructor | |
* | |
* @author Alec M. | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->SetTopMargin(15); | |
$this->Body(); | |
} | |
/** | |
* Write the PDF repair order header | |
* | |
* @return void | |
*/ | |
public function Header() : void | |
{ | |
// Company Information | |
$this->SetFont('Helvetica', '', 17); | |
$this->SetTextColor(0,0,0); | |
$this->Cell(0, 0, "Example Company, LTD.", 0, 2, 'L'); | |
$y = $this->GetY()-3; | |
$x = $this->GetPageWidth() - $this->GetX() - 71; | |
$this->Ln(6); | |
$this->SetFontSize(13); | |
$this->Cell(0, 0, "Street 1", 0, 2, 'L'); | |
$this->Ln(5); | |
$this->Cell(0, 0, "City, State Zip", 0, 2, 'L'); | |
$this->Ln(3); | |
$this->Cell(100, 5, "Phone Number", 0, 0, 'L'); | |
$this->Ln(7); | |
// Customer Information | |
$this->SetFontSize(11); | |
$this->setFillColor(189,189,189); | |
$this->Cell(80, 5, "Customer", 1, 0, 'L', 1); | |
$x3 = $this->GetX(); | |
$this->Ln(); | |
$this->SetFontSize(9); | |
$this->MultiCell(80, 5, "Name\nStreet\nCity, State Zip\nPhone Numbers", 1, 'L', false); | |
$y3 = $this->GetY() - 5; | |
// Vehicle Odometer | |
$this->SetFontSize(11); | |
$this->SetXY($this->GetPageWidth() - 71, $y3); | |
$this->Cell(20, 5, "Odometer", 1, 0, 'C', 1); | |
$this->SetFontSize(9); | |
$this->Cell(40, 5, "0mi", 1, 'L', false); | |
// Invoice Details | |
$this->SetXY($x, $y); | |
$this->SetFontSize(11); | |
$this->Cell(10, 5, "S/R", 1, 0, 'C', 1); | |
$this->Cell(30, 5, "Date", 1, 0, 'C', 1); | |
$this->Cell(30, 5, "Invoice #", 1, 0, 'C', 1); | |
$this->Ln(); | |
$this->SetFontSize(9); | |
$this->Cell($this->GetPageWidth() - 91, 1, '', 0, 0, 1); | |
$this->Cell(10, 7, "N/A", 1, 0, 'C'); | |
$this->Cell(30, 7, date( 'M jS, Y'), 1, 0, 'C'); | |
$this->Cell(30, 7, "53983", 1, 2, 'C'); | |
$this->Ln(3.5); | |
// Vehicle | |
$this->SetFontSize(11); | |
$this->SetX($this->GetPageWidth() - 71); | |
$this->Cell(60, 5, "Vehicle", 1, 0, 'L', 1); | |
$this->Ln(); | |
$this->SetFontSize(9); | |
$this->SetX($this->GetPageWidth() - 71); | |
$this->MultiCell(60, 5, "2022 BMW M550i xDrive\n4.4L V8 523BHP\n \n ", 1, 'L', false); | |
// Tag | |
$this->SetXY($this->GetPageWidth() - 71, $this->GetY() - 10); | |
$this->Cell(10, 5, "TAG", 1, 0, "C", 1); | |
$this->Cell(50, 5, "N/A", 0, 0, "L", 0); | |
$this->Ln(); | |
// VIN | |
$this->SetX($this->GetPageWidth() - 71); | |
$this->Cell(10, 5, "VIN", 1, 0, "C", 1); | |
$this->Cell(50, 5, "N/A", 0, 0, "L", 0); | |
$this->Ln(); | |
// Vehicle Truck | |
$this->SetFontSize(11); | |
$this->SetXY($x3 + 5, $y3); | |
$this->Cell(15, 5, "Truck #", 1, 0, 'C', 1); | |
$this->SetFontSize(7); | |
$this->Cell(30, 5, "xDrive", 1, 'L', false); | |
// Revert Y | |
$this->SetY($y3 + 10); | |
} | |
/** | |
* Create PDF body | |
* | |
* @return void | |
*/ | |
public function Body() : void | |
{ | |
// Variables | |
$this->ColWidth = $this->GetPageWidth() / 5; | |
$this->AddPage("P", "Letter"); | |
$AmountStrWidth = $this->GetStringWidth("Amount"); | |
// Labor Line | |
$this->SetFont('Helvetica', 'BU', $this->fontSize); | |
$this->Cell($this->ColWidth / 1.5, 0, ''); | |
$this->Cell($this->ColWidth + $this->ColWidth + ($this->ColWidth / 1.2), 0, "Labor", 0, 0, "L"); | |
$this->Cell($this->ColWidth / 2, 0, "Tech", 0, 0, "L"); | |
$this->Cell($this->ColWidth / 1.5, 0, "Amount", 0, 0, "R"); | |
$this->Ln(2); | |
$this->SetFont('Helvetica', '', $this->fontSize); | |
$this->Cell($this->ColWidth / 1.5, $this->lineHeight, "", 0, 0); | |
$this->Cell($this->ColWidth + $this->ColWidth + ($this->ColWidth / 1.2), $this->lineHeight, "Example Job Description Content", 0, 0); | |
$this->Cell($this->ColWidth / 2, $this->lineHeight, "N/A", 0, 0, "L"); | |
$this->Cell($this->ColWidth / 1.5, $this->lineHeight, "$0.00", 0, 0, "R"); | |
$this->Ln(); | |
$this->SetX($this->ColWidth * 4.38 + $this->GetX()); | |
$this->Cell($AmountStrWidth, 0, '', 1, 0); | |
$this->Ln($this->totalSpace); | |
$this->SetFont('Helvetica', 'B', $this->fontSize); | |
$this->Cell($this->ColWidth * 3.666, 4, '', 0, 0); | |
$this->Cell($this->ColWidth, 4, "$0.00", 0, 0, "R"); | |
$this->Ln($this->sectionSpace); | |
// Parts | |
$this->SetFont('Helvetica', 'BU', $this->fontSize); | |
$this->Cell($this->ColWidth / 1.5, 0, "Part No.", 0, 0, "L"); | |
$this->Cell($this->ColWidth + $this->ColWidth + ($this->ColWidth / 3), 0, "Parts", 0, 0, "L"); | |
$this->Cell($this->ColWidth / 2, 0, "Quantity", 0, 0, "C"); | |
$this->Cell($this->ColWidth / 2, 0, "Each", 0, 0, "R"); | |
$this->Cell($this->ColWidth / 1.5, 0, "Amount", 0, 0, "R"); | |
$this->Ln(2); | |
$this->SetFont('Helvetica', '', $this->fontSize); | |
$this->Cell($this->ColWidth / 1.5, $this->lineHeight, "194", 0, 0); | |
$this->Cell($this->ColWidth + $this->ColWidth + ($this->ColWidth / 3), $this->lineHeight, "OE Repl. High Intensity Tag Lamp Bulb", 0, 0); | |
$this->Cell($this->ColWidth / 2, $this->lineHeight, "1", 0, 0, "C"); | |
$this->Cell($this->ColWidth / 2, $this->lineHeight, "$0.00", 0, 0, "R"); | |
$this->Cell($this->ColWidth / 1.5, $this->lineHeight, "$0.00", 0, 0, "R"); | |
$this->Ln(); | |
$this->SetX($this->ColWidth * 4.38 + $this->GetX()); | |
$this->Cell($AmountStrWidth, 0, '', 1, 0); | |
$this->Ln($this->totalSpace); | |
$this->SetFont('Helvetica', 'B', $this->fontSize); | |
$this->Cell($this->ColWidth * 3.666, 4, '', 0, 0); | |
$this->Cell($this->ColWidth, 4, "$0.00", 0, 0, "R"); | |
$this->Ln($this->sectionSpace); | |
// Service Charges | |
$this->SetFont('Helvetica', 'BU', $this->fontSize); | |
$this->Cell($this->ColWidth / 1.5, 0, "", 0, 0, "L"); | |
$this->Cell($this->ColWidth + $this->ColWidth + ($this->ColWidth / 3), 0, "Service Charges", 0, 0, "L"); | |
$this->Cell($this->ColWidth / 2, 0, "", 0, 0, "R"); | |
$this->Cell($this->ColWidth / 2, 0, "", 0, 0, "R"); | |
$this->Cell($this->ColWidth / 1.5, 0, "Amount", 0,0, "R"); | |
$this->Ln(2); | |
$this->SetFont('Helvetica', '', $this->fontSize); | |
$this->Cell($this->ColWidth / 1.5, $this->lineHeight); | |
$this->Cell($this->ColWidth + $this->ColWidth + ($this->ColWidth / 3), $this->lineHeight, "Example Misc. Service Charge", 0, 0); | |
$this->Cell($this->ColWidth, $this->lineHeight); | |
$this->Cell($this->ColWidth / 1.5, $this->lineHeight, "$0.00", 0, 0, "R"); | |
$this->Ln(); | |
$this->SetX($this->ColWidth * 4.38 + $this->GetX()); | |
$this->Cell($AmountStrWidth, 0, '', 1, 0); | |
$this->Ln($this->totalSpace); | |
$this->SetFont('Helvetica', 'B', $this->fontSize); | |
$this->Cell($this->ColWidth * 3.666, 4, '', 0, 0); | |
$this->Cell($this->ColWidth, 4, "$0.00", 0, 0, "R"); | |
$this->Ln($this->sectionSpace); | |
// Invoice Totals | |
$this->SetFont('Helvetica', '', $this->fontSize); | |
$this->SetX($this->ColWidth * 4.35 + $this->GetX()); | |
$this->Cell($this->ColWidth / 3.5, 0, '', 1, 0); | |
$this->Ln(0.5); | |
$NotesY = $this->GetY(); | |
$this->SetFont('Helvetica', 'B', $this->fontSize); | |
$this->Cell($this->ColWidth * 4.259, 4, 'Subtotal', 0, 0, "R"); | |
$this->Cell($this->ColWidth / 2.5, 4, "$0.00", 0, 0, "R"); | |
$this->Ln(); | |
$this->SetFont('Helvetica', '', $this->fontSize); | |
$this->Cell($this->ColWidth * 4.259, 4, 'Tax', 0, 0, "R"); | |
$this->Cell($this->ColWidth / 2.5, 4, "$0.00", 0, 0, "R"); | |
$this->Ln(4); | |
$this->SetX($this->ColWidth * 4.35 + $this->GetX()); | |
$this->Cell($this->ColWidth / 3.5, 0, '', 1, 0); | |
$this->Ln(0.7); | |
$this->SetX($this->ColWidth * 4.35 + $this->GetX()); | |
$this->Cell($this->ColWidth / 3.5, 0, '', 1, 0); | |
$this->Ln(); | |
$this->SetFont('Helvetica', 'B', $this->fontSize); | |
$this->Cell($this->ColWidth * 4.259, 4, 'Total', 0, 0, "R"); | |
$this->Cell($this->ColWidth / 2.5, 4, "$0.00", 0, 0, "R"); | |
$this->Ln(); | |
// Comments | |
$this->SetFillColor(189,189,189); | |
$this->SetXY(10, $NotesY); | |
$this->SetFont('Helvetica', '', 11); | |
$this->Cell($this->ColWidth * 3.5, 5, "Comments", 1, 2, "L", true); | |
$this->SetFontSize($this->fontSize); | |
$this->MultiCell($this->ColWidth * 3.5, 4.5, "Example repair order notes here.\n\nSupports multi-line comments", 1, "L", false); | |
// Terms | |
$this->SetY($this->GetY() + 6); | |
$this->SetFont('Helvetica', '', 11); | |
$this->Cell(($this->ColWidth * 4.25) + ($this->ColWidth / 2.6), 5, "Terms", 1, 2, "L", true); | |
$this->SetFont('Courier', '', 10); | |
$this->MultiCell(($this->ColWidth * 4.25) + ($this->ColWidth / 2.6), 3.8, "Ticket terms go here...Or not\nAgain it supports multi\nline\ncomments", 1, "L", false); | |
// Signature Line | |
$this->Ln(8); | |
$this->SetFont('Courier', '', 11); | |
$this->Cell($this->ColWidth * 4.64, 4, $this->signature_line, 0, 0, "L"); | |
$this->Ln(); | |
$this->SetFont('Helvetica', '', 10); | |
$this->SetTextColor(175, 175, 175); | |
$this->Cell($this->ColWidth * 2.4, 5, "(". date('M jS, Y') .")", 0, 0, "C"); | |
$this->SetTextColor(0,0,0); | |
// Email Form | |
$this->Ln(8); | |
$this->SetFont('Courier', '', 11); | |
$this->Cell($this->ColWidth * 4.64, 4, str_pad($this->email_line, strlen($this->signature_line), " ", STR_PAD_LEFT), 0, 0, "L"); | |
} | |
/** | |
* Write a Repair Order footer | |
* | |
* @return void | |
*/ | |
public function Footer() : void | |
{ | |
/* Implement as necessary */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Introduction
This is a PHP class to write automotive repair orders with strict line-item repair costs. Built to support FPDF V1.84, but should work fine with newer/older versions.
Preview