diff options
author | arf20 <aruizfernandez05@gmail.com> | 2024-03-22 21:30:53 +0100 |
---|---|---|
committer | arf20 <aruizfernandez05@gmail.com> | 2024-03-22 21:30:53 +0100 |
commit | c9723ae608ad34b13371507f14b7a7d170f2ce78 (patch) | |
tree | 2811c65c7580673b4954aca7ef1853ee0551ce12 | |
parent | a7ef3f5a54cf45eaa5db4b200604a650929194dc (diff) | |
download | arfnet2-cstims-c9723ae608ad34b13371507f14b7a7d170f2ce78.tar.gz arfnet2-cstims-c9723ae608ad34b13371507f14b7a7d170f2ce78.zip |
Script to make invoices proof of concept
-rw-r--r-- | makeinvoices.php | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/makeinvoices.php b/makeinvoices.php new file mode 100644 index 0000000..c0c68cc --- /dev/null +++ b/makeinvoices.php @@ -0,0 +1,85 @@ +<?php + +// Run first day of every month + +require_once("/usr/share/doc/php-tcpdf/examples/tcpdf_include.php"); + +require_once "config.php"; + +// Get due orders +$sql = "SELECT id, service, name, client, billing FROM orders"; +$stmt = mysqli_prepare($link, $sql); +mysqli_stmt_execute($stmt); +$result = mysqli_stmt_get_result($stmt); +$dueorders = $result->fetch_all(MYSQLI_ASSOC); + +/*foreach ($dueorders as $dueorder) { + generate_pdf($dueorder); +}*/ +generate_pdf($dueorders[0]); + +function generate_pdf($dueorder) { + // Extend the TCPDF class to create custom Header and Footer + class InvoicePDF extends TCPDF { + //Page header + public function Header() { + // Logo + $image_file = "arfnet_logo.png"; + $this->Image($image_file, 10, 10, 15, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false); + // Set font + $this->SetFont('helvetica', 'B', 20); + // Title + $this->Cell(0, 15, 'ARFNET', 0, false, 'C', 0, '', 0, false, 'M', 'M'); + } + + // Page footer + public function Footer() { + // Position at 15 mm from bottom + $this->SetY(-15); + // Set font + $this->SetFont('helvetica', 'I', 8); + // Page number + $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); + } + } + + $pdf = new InvoicePDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); + + // set document information + $pdf->SetCreator(PDF_CREATOR); + $pdf->SetAuthor("ARFNET Client Service Ticket and Invoice Management System"); + $pdf->SetTitle("Invoice"); + + $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); + + $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); + $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); + + $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); + + $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); + $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); + $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); + + $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); + + $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); + + // ------------------------------ + $pdf->SetFont('times', 'B', 12); + + $pdf->AddPage(); + + $txt = + "Client ID: ".$dueorder["client"]."\n" + ."Order ID: ".$dueorder["id"]."\n\n" + ."Service: ".$dueorder["name"]."\n" + ."Amount: ".$dueorder["billing"]."\n" + ; + + $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0); + + $pdf->Output('invoice.pdf', 'I'); +} + +?>
\ No newline at end of file |