PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.7
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.7
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 / TemplateTextHelper.php

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

372 lines 18.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Template Text Helper
4 *
5 * Centralized helper for retrieving text settings used in invoice and quote templates.
6 * This prevents duplication and makes text management easier.
7 *
8 * @package EasyInvoice
9 * @since 2.0.0
10 */
11
12 namespace EasyInvoice\Helpers;
13
14 // Prevent direct access
15 if (!defined('ABSPATH')) {
16 exit;
17 }
18
19 class TemplateTextHelper {
20
21 /**
22 * Get all text settings for templates
23 *
24 * @return array Array of text settings
25 */
26 public static function getAllTextSettings(): array {
27 return [
28 // Invoice specific
29 'invoice_number' => \EasyInvoice\Controllers\SettingsController::getTextInvoiceNumber(),
30 'invoice_date' => \EasyInvoice\Controllers\SettingsController::getTextInvoiceDate(),
31 'due_date' => \EasyInvoice\Controllers\SettingsController::getTextDueDate(),
32 'total_due' => \EasyInvoice\Controllers\SettingsController::getTextTotalDue(),
33
34 // Quote specific
35 'quote_number' => \EasyInvoice\Controllers\SettingsController::getTextQuoteNumber(),
36 'quote_date' => \EasyInvoice\Controllers\SettingsController::getTextQuoteDate(),
37 'valid_until' => \EasyInvoice\Controllers\SettingsController::getTextValidUntil(),
38
39 // Common labels
40 'to' => \EasyInvoice\Controllers\SettingsController::getTextTo(),
41 'service' => \EasyInvoice\Controllers\SettingsController::getTextService(),
42 'qty' => \EasyInvoice\Controllers\SettingsController::getTextQty(),
43 'rate_price' => \EasyInvoice\Controllers\SettingsController::getTextRatePrice(),
44 'adjust' => \EasyInvoice\Controllers\SettingsController::getTextAdjust(),
45 'sub_total' => \EasyInvoice\Controllers\SettingsController::getTextSubTotal(),
46 'total' => \EasyInvoice\Controllers\SettingsController::getTextTotal(),
47 'tax' => \EasyInvoice\Controllers\SettingsController::getTextTax(),
48 'discount' => \EasyInvoice\Controllers\SettingsController::getTextDiscount(),
49
50 // Button labels
51 'print' => \EasyInvoice\Controllers\SettingsController::getTextPrint(),
52 'download_pdf' => \EasyInvoice\Controllers\SettingsController::getTextDownloadPdf(),
53 'send_email' => \EasyInvoice\Controllers\SettingsController::getTextSendEmail(),
54 'pay_now' => \EasyInvoice\Controllers\SettingsController::getTextPayNow(),
55 'accept_quote' => \EasyInvoice\Controllers\SettingsController::getTextAcceptQuote(),
56 'decline_quote' => \EasyInvoice\Controllers\SettingsController::getTextDeclineQuote(),
57 'decline_reason' => \EasyInvoice\Controllers\SettingsController::getTextDeclineReason(),
58 ];
59 }
60
61 /**
62 * Get company information from settings
63 *
64 * @return array Company information
65 */
66 public static function getCompanyInfo(): array {
67 $info = [
68 'name' => get_option('easy_invoice_company_name', 'Your Company Name'),
69 'address' => get_option('easy_invoice_company_address', ''),
70 'email' => get_option('easy_invoice_company_email', ''),
71 'phone' => get_option('easy_invoice_company_phone', ''),
72 'website' => get_option('easy_invoice_company_website', ''),
73 'logo' => get_option('easy_invoice_company_logo', ''),
74 'tax_number' => get_option('easy_invoice_tax_number', ''),
75 ];
76 /**
77 * Filter the resolved company info used by invoice/quote templates
78 * and PDF generation. The White-Label addon hooks this to replace
79 * the logo with its branded header image without forcing every
80 * admin to also see the white-label logo on their settings page.
81 *
82 * @param array<string,string> $info Resolved company info.
83 */
84 return apply_filters('easy_invoice_template_company_info', $info);
85 }
86
87 /**
88 * Get invoice specific text settings
89 *
90 * @return array Invoice text settings
91 */
92 public static function getInvoiceTextSettings(): array {
93 return [
94 'invoice_number' => \EasyInvoice\Controllers\SettingsController::getTextInvoiceNumber(),
95 'invoice_date' => \EasyInvoice\Controllers\SettingsController::getTextInvoiceDate(),
96 'due_date' => \EasyInvoice\Controllers\SettingsController::getTextDueDate(),
97 'total_due' => \EasyInvoice\Controllers\SettingsController::getTextTotalDue(),
98 'to' => \EasyInvoice\Controllers\SettingsController::getTextTo(),
99 'service' => \EasyInvoice\Controllers\SettingsController::getTextService(),
100 'qty' => \EasyInvoice\Controllers\SettingsController::getTextQty(),
101 'rate_price' => \EasyInvoice\Controllers\SettingsController::getTextRatePrice(),
102 'adjust' => \EasyInvoice\Controllers\SettingsController::getTextAdjust(),
103 'sub_total' => \EasyInvoice\Controllers\SettingsController::getTextSubTotal(),
104 'total' => \EasyInvoice\Controllers\SettingsController::getTextTotal(),
105 'tax' => \EasyInvoice\Controllers\SettingsController::getTextTax(),
106 'discount' => \EasyInvoice\Controllers\SettingsController::getTextDiscount(),
107 'print' => \EasyInvoice\Controllers\SettingsController::getTextPrint(),
108 'download_pdf' => \EasyInvoice\Controllers\SettingsController::getTextDownloadPdf(),
109 'send_email' => \EasyInvoice\Controllers\SettingsController::getTextSendEmail(),
110 'pay_now' => \EasyInvoice\Controllers\SettingsController::getTextPayNow(),
111 ];
112 }
113
114 /**
115 * Get quote specific text settings
116 *
117 * @return array Quote text settings
118 */
119 public static function getQuoteTextSettings(): array {
120 return [
121 'quote_number' => \EasyInvoice\Controllers\SettingsController::getTextQuoteNumber(),
122 'quote_date' => \EasyInvoice\Controllers\SettingsController::getTextQuoteDate(),
123 'valid_until' => \EasyInvoice\Controllers\SettingsController::getTextValidUntil(),
124 'to' => \EasyInvoice\Controllers\SettingsController::getTextTo(),
125 'service' => \EasyInvoice\Controllers\SettingsController::getTextService(),
126 'qty' => \EasyInvoice\Controllers\SettingsController::getTextQty(),
127 'rate_price' => \EasyInvoice\Controllers\SettingsController::getTextRatePrice(),
128 'adjust' => \EasyInvoice\Controllers\SettingsController::getTextAdjust(),
129 'sub_total' => \EasyInvoice\Controllers\SettingsController::getTextSubTotal(),
130 'total' => \EasyInvoice\Controllers\SettingsController::getTextTotal(),
131 'tax' => \EasyInvoice\Controllers\SettingsController::getTextTax(),
132 'discount' => \EasyInvoice\Controllers\SettingsController::getTextDiscount(),
133 'print' => \EasyInvoice\Controllers\SettingsController::getTextPrint(),
134 'download_pdf' => \EasyInvoice\Controllers\SettingsController::getTextDownloadPdf(),
135 'send_email' => \EasyInvoice\Controllers\SettingsController::getTextSendEmail(),
136 'accept_quote' => \EasyInvoice\Controllers\SettingsController::getTextAcceptQuote(),
137 'decline_quote' => \EasyInvoice\Controllers\SettingsController::getTextDeclineQuote(),
138 'decline_reason' => \EasyInvoice\Controllers\SettingsController::getTextDeclineReason(),
139 ];
140 }
141
142 /**
143 * Generate "From" section content for templates
144 *
145 * @param array $company_info Company information array
146 * @param bool $show_label Whether to show the "From" label
147 * @param string $style Style variant for the "From" section
148 * @return string Generated HTML for "From" section
149 */
150 public static function generateFromSection($company_info, $show_label = true, $style = 'default'): string {
151 $output = '';
152
153 switch ($style) {
154 case 'minimal':
155 // Minimal style - includes company name and details
156 $output .= '<div class="company-info-minimal">';
157 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
158 if ($company_info['address']) {
159 $output .= '<div class="company-address">' . nl2br(esc_html($company_info['address'])) . '</div>';
160 }
161 if ($company_info['email']) {
162 $output .= '<div class="company-email">' . esc_html($company_info['email']) . '</div>';
163 }
164 if ($company_info['phone']) {
165 $output .= '<div class="company-phone">' . esc_html($company_info['phone']) . '</div>';
166 }
167 if ($company_info['website']) {
168 $output .= '<div class="company-website">' . esc_html($company_info['website']) . '</div>';
169 }
170 $output .= '</div>';
171 break;
172
173 case 'details-only':
174 // Details only style - excludes company name (for use with separate company-name div)
175 $output .= '<div class="company-info-details-only">';
176 if ($company_info['address']) {
177 $output .= '<div class="company-address">' . nl2br(esc_html($company_info['address'])) . '</div>';
178 }
179 if ($company_info['email']) {
180 $output .= '<div class="company-email">' . esc_html($company_info['email']) . '</div>';
181 }
182 if ($company_info['phone']) {
183 $output .= '<div class="company-phone">' . esc_html($company_info['phone']) . '</div>';
184 }
185 if ($company_info['website']) {
186 $output .= '<div class="company-website">' . esc_html($company_info['website']) . '</div>';
187 }
188 $output .= '</div>';
189 break;
190
191 case 'elegant':
192 // Elegant style - subtle design
193 $output .= '<div class="company-info-elegant">';
194 if ($show_label) {
195 $output .= '<h3 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . '</h3>';
196 }
197 $output .= '<div class="company-details">';
198 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
199 if ($company_info['address']) {
200 $output .= '<div class="company-address">' . nl2br(esc_html($company_info['address'])) . '</div>';
201 }
202 if ($company_info['email']) {
203 $output .= '<div class="company-email">' . esc_html($company_info['email']) . '</div>';
204 }
205 if ($company_info['phone']) {
206 $output .= '<div class="company-phone">' . esc_html($company_info['phone']) . '</div>';
207 }
208 if ($company_info['website']) {
209 $output .= '<div class="company-website">' . esc_html($company_info['website']) . '</div>';
210 }
211 $output .= '</div>';
212 $output .= '</div>';
213 break;
214
215 case 'modern':
216 // Modern style - clean and bold
217 $output .= '<div class="company-info-modern">';
218 if ($show_label) {
219 $output .= '<h2 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . ':</h2>';
220 }
221 $output .= '<div class="address-content">';
222 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
223 if ($company_info['address']) {
224 $output .= nl2br(esc_html($company_info['address'])) . '<br>';
225 }
226 if ($company_info['email']) {
227 $output .= esc_html($company_info['email']) . '<br>';
228 }
229 if ($company_info['phone']) {
230 $output .= esc_html($company_info['phone']) . '<br>';
231 }
232 if ($company_info['website']) {
233 $output .= esc_html($company_info['website']);
234 }
235 $output .= '</div>';
236 $output .= '</div>';
237 break;
238
239 case 'professional':
240 // Professional style - structured layout
241 $output .= '<div class="company-info-professional">';
242 if ($show_label) {
243 $output .= '<h2 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . ':</h2>';
244 }
245 $output .= '<div class="address-content">';
246 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
247 if ($company_info['address']) {
248 $output .= nl2br(esc_html($company_info['address'])) . '<br>';
249 }
250 if ($company_info['email']) {
251 $output .= esc_html($company_info['email']) . '<br>';
252 }
253 if ($company_info['phone']) {
254 $output .= esc_html($company_info['phone']) . '<br>';
255 }
256 if ($company_info['website']) {
257 $output .= esc_html($company_info['website']);
258 }
259 $output .= '</div>';
260 $output .= '</div>';
261 break;
262
263 case 'creative':
264 // Creative style - artistic design
265 $output .= '<div class="company-info-creative">';
266 if ($show_label) {
267 $output .= '<h2 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . '</h2>';
268 }
269 $output .= '<div class="address-content">';
270 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
271 if ($company_info['address']) {
272 $output .= nl2br(esc_html($company_info['address'])) . '<br>';
273 }
274 if ($company_info['email']) {
275 $output .= esc_html($company_info['email']) . '<br>';
276 }
277 if ($company_info['phone']) {
278 $output .= esc_html($company_info['phone']) . '<br>';
279 }
280 if ($company_info['website']) {
281 $output .= esc_html($company_info['website']);
282 }
283 $output .= '</div>';
284 $output .= '</div>';
285 break;
286
287 default:
288 // Default style - standard layout
289 $output .= '<div class="company-info-default">';
290 if ($show_label) {
291 $output .= '<h2 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . ':</h2>';
292 }
293 $output .= '<div class="address-content">';
294 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
295 if ($company_info['address']) {
296 $output .= nl2br(esc_html($company_info['address'])) . '<br>';
297 }
298 if ($company_info['email']) {
299 $output .= esc_html($company_info['email']) . '<br>';
300 }
301 if ($company_info['phone']) {
302 $output .= esc_html($company_info['phone']) . '<br>';
303 }
304 if ($company_info['website']) {
305 $output .= esc_html($company_info['website']);
306 }
307 $output .= '</div>';
308 $output .= '</div>';
309 break;
310 }
311
312 return $output;
313 }
314
315 /**
316 * Generate totals section for invoice/quote templates
317 *
318 * @param mixed $document Invoice or Quote object
319 * @param array $text_settings Text settings array
320 * @param mixed $formatter Formatter object
321 * @param string $type 'invoice' or 'quote'
322 * @return string Generated HTML for totals section
323 */
324 public static function generateTotalsSection($document, array $text_settings, $formatter, string $type = 'invoice'): string {
325 $output = '';
326
327 // Subtotal
328 $output .= '<div class="' . $type . '-total-row">';
329 $output .= '<span class="' . $type . '-total-label">' . esc_html($text_settings['sub_total']) . ':</span>';
330 $output .= '<span class="' . $type . '-total-value">' . esc_html($formatter->format($document->getSubtotal())) . '</span>';
331 $output .= '</div>';
332
333 // Discount (if any)
334 if ($document->getDiscountAmount() > 0) {
335 $output .= '<div class="' . $type . '-total-row">';
336 $output .= '<span class="' . $type . '-total-label">' . esc_html($text_settings['discount']);
337 if ($document->getDiscountType() === 'percentage') {
338 $output .= ' (' . esc_html($document->getDiscountValue()) . '%)';
339 }
340 $output .= ':</span>';
341 $output .= '<span class="' . $type . '-total-value">-' . esc_html($formatter->format($document->getDiscountAmount())) . '</span>';
342 $output .= '</div>';
343 }
344
345
346 // Tax (if any)
347 if ($document->getTaxAmount() > 0) {
348 $output .= '<div class="' . $type . '-total-row">';
349 $output .= '<span class="' . $type . '-total-label">' . esc_html(easy_invoice_get_tax_name());
350 $output .= ' (' . esc_html($document->getTaxRate()) . '%):</span>';
351 $output .= '<span class="' . $type . '-total-value">' . esc_html($formatter->format($document->getTaxAmount())) . '</span>';
352 $output .= '</div>';
353 }
354
355 // Allow plugins to add content
356 if ($type === 'invoice') {
357 do_action('easy_invoice_invoice_totals_after_tax', $document);
358 do_action('easy_invoice_invoice_totals_after_discount', $document);
359 } else {
360 do_action('easy_invoice_quote_totals_after_tax', $document);
361 do_action('easy_invoice_quote_totals_after_discount', $document);
362 }
363
364 // Grand Total
365 $output .= '<div class="' . $type . '-total-row ' . $type . '-grand-total">';
366 $output .= '<span class="' . $type . '-total-label">' . esc_html($text_settings['total']) . ':</span>';
367 $output .= '<span class="' . $type . '-total-value">' . esc_html($formatter->format($document->getTotal())) . '</span>';
368 $output .= '</div>';
369
370 return $output;
371 }
372 }