From c9723ae608ad34b13371507f14b7a7d170f2ce78 Mon Sep 17 00:00:00 2001 From: arf20 Date: Fri, 22 Mar 2024 21:30:53 +0100 Subject: Script to make invoices proof of concept --- makeinvoices.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 makeinvoices.php (limited to 'makeinvoices.php') diff --git a/makeinvoices.php b/makeinvoices.php new file mode 100644 index 0000000..c0c68cc --- /dev/null +++ b/makeinvoices.php @@ -0,0 +1,85 @@ +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 -- cgit v1.2.3