PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.0
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.0
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Helpers / PdfHelper.php

PdfHelper.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.0, at includes/Helpers/PdfHelper.php

99 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PDF Helper Class
4 *
5 * @package Easy_Invoice
6 * @subpackage Helpers
7 */
8
9 namespace EasyInvoice\Includes\Helpers;
10
11 use EasyInvoice\Models\Invoice;
12
13 /**
14 * PDF Helper Class
15 *
16 * Handles PDF generation for invoices with styling consistent with the web view
17 */
18 class PdfHelper {
19
20 /**
21 * Get invoice data for PDF generation
22 * @param \EasyInvoice\Includes\Models\Invoice $invoice
23 * @return array
24 */
25 public static function getInvoiceDataForPdf($invoice) {
26 $company = [
27 'name' => get_bloginfo('name'),
28 'address' => get_option('easy_invoice_company_address'),
29 'email' => get_option('easy_invoice_company_email'),
30 'phone' => get_option('easy_invoice_company_phone')
31 ];
32
33 $customer = [
34 'name' => $invoice->getCustomerName(),
35 'address' => $invoice->getCustomerAddress(),
36 'email' => $invoice->getCustomerEmail()
37 ];
38
39 $items = [];
40 foreach ($invoice->getItems() as $item) {
41 $items[] = [
42 'name' => $item->getName(),
43 'description' => $item->getDescription(),
44 'quantity' => $item->getQuantity(),
45 'price' => $item->getPrice(),
46 'adjust' => $item->getAdjust(),
47 'total' => $item->getAmount()
48 ];
49 }
50
51 $totals = [
52 'subtotal' => $invoice->getSubtotal(),
53 'tax' => $invoice->getTaxAmount(),
54 'discount' => $invoice->getDiscountAmount(),
55 'total' => $invoice->getTotal()
56 ];
57
58 return [
59 'number' => $invoice->getNumber(),
60 'date' => $invoice->getIssueDate(),
61 'dueDate' => $invoice->getDueDate(),
62 'status' => $invoice->getStatus(),
63 'company' => $company,
64 'customer' => $customer,
65 'items' => $items,
66 'totals' => $totals,
67 'notes' => $invoice->getNotes(),
68 'currency_code' => $invoice->getCurrencyCode() ?: 'USD',
69 'currency_symbol' => \EasyInvoice\Helpers\CurrencyHelper::getCurrencySymbol($invoice->getCurrencyCode() ?: 'USD'),
70 'symbol_position' => get_option('easy_invoice_currency_symbol_position', 'before'),
71 'template' => $invoice->getTemplate() ?: 'standard'
72 ];
73 }
74
75 /**
76 * Enqueue required scripts for PDF generation
77 */
78 public static function enqueuePdfScripts() {
79 // Bundled locally, not from a CDN — WordPress.org requires every asset
80 // to ship inside the plugin. html2canvas is registered alongside jsPDF
81 // because document-pdf.js needs both to render a PDF.
82 wp_enqueue_script(
83 'html2canvas',
84 EASY_INVOICE_PLUGIN_URL . 'assets/js/vendors/html2canvas.min.js',
85 [],
86 '1.4.1',
87 true
88 );
89
90 wp_enqueue_script(
91 'jspdf',
92 EASY_INVOICE_PLUGIN_URL . 'assets/js/vendors/jspdf.umd.min.js',
93 [],
94 '2.5.1',
95 true
96 );
97 }
98 }
99