PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.2
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.1.2, at includes/Helpers/TemplateTextHelper.php

363 lines 18.1 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 return [
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
78 /**
79 * Get invoice specific text settings
80 *
81 * @return array Invoice text settings
82 */
83 public static function getInvoiceTextSettings(): array {
84 return [
85 'invoice_number' => \EasyInvoice\Controllers\SettingsController::getTextInvoiceNumber(),
86 'invoice_date' => \EasyInvoice\Controllers\SettingsController::getTextInvoiceDate(),
87 'due_date' => \EasyInvoice\Controllers\SettingsController::getTextDueDate(),
88 'total_due' => \EasyInvoice\Controllers\SettingsController::getTextTotalDue(),
89 'to' => \EasyInvoice\Controllers\SettingsController::getTextTo(),
90 'service' => \EasyInvoice\Controllers\SettingsController::getTextService(),
91 'qty' => \EasyInvoice\Controllers\SettingsController::getTextQty(),
92 'rate_price' => \EasyInvoice\Controllers\SettingsController::getTextRatePrice(),
93 'adjust' => \EasyInvoice\Controllers\SettingsController::getTextAdjust(),
94 'sub_total' => \EasyInvoice\Controllers\SettingsController::getTextSubTotal(),
95 'total' => \EasyInvoice\Controllers\SettingsController::getTextTotal(),
96 'tax' => \EasyInvoice\Controllers\SettingsController::getTextTax(),
97 'discount' => \EasyInvoice\Controllers\SettingsController::getTextDiscount(),
98 'print' => \EasyInvoice\Controllers\SettingsController::getTextPrint(),
99 'download_pdf' => \EasyInvoice\Controllers\SettingsController::getTextDownloadPdf(),
100 'send_email' => \EasyInvoice\Controllers\SettingsController::getTextSendEmail(),
101 'pay_now' => \EasyInvoice\Controllers\SettingsController::getTextPayNow(),
102 ];
103 }
104
105 /**
106 * Get quote specific text settings
107 *
108 * @return array Quote text settings
109 */
110 public static function getQuoteTextSettings(): array {
111 return [
112 'quote_number' => \EasyInvoice\Controllers\SettingsController::getTextQuoteNumber(),
113 'quote_date' => \EasyInvoice\Controllers\SettingsController::getTextQuoteDate(),
114 'valid_until' => \EasyInvoice\Controllers\SettingsController::getTextValidUntil(),
115 'to' => \EasyInvoice\Controllers\SettingsController::getTextTo(),
116 'service' => \EasyInvoice\Controllers\SettingsController::getTextService(),
117 'qty' => \EasyInvoice\Controllers\SettingsController::getTextQty(),
118 'rate_price' => \EasyInvoice\Controllers\SettingsController::getTextRatePrice(),
119 'adjust' => \EasyInvoice\Controllers\SettingsController::getTextAdjust(),
120 'sub_total' => \EasyInvoice\Controllers\SettingsController::getTextSubTotal(),
121 'total' => \EasyInvoice\Controllers\SettingsController::getTextTotal(),
122 'tax' => \EasyInvoice\Controllers\SettingsController::getTextTax(),
123 'discount' => \EasyInvoice\Controllers\SettingsController::getTextDiscount(),
124 'print' => \EasyInvoice\Controllers\SettingsController::getTextPrint(),
125 'download_pdf' => \EasyInvoice\Controllers\SettingsController::getTextDownloadPdf(),
126 'send_email' => \EasyInvoice\Controllers\SettingsController::getTextSendEmail(),
127 'accept_quote' => \EasyInvoice\Controllers\SettingsController::getTextAcceptQuote(),
128 'decline_quote' => \EasyInvoice\Controllers\SettingsController::getTextDeclineQuote(),
129 'decline_reason' => \EasyInvoice\Controllers\SettingsController::getTextDeclineReason(),
130 ];
131 }
132
133 /**
134 * Generate "From" section content for templates
135 *
136 * @param array $company_info Company information array
137 * @param bool $show_label Whether to show the "From" label
138 * @param string $style Style variant for the "From" section
139 * @return string Generated HTML for "From" section
140 */
141 public static function generateFromSection($company_info, $show_label = true, $style = 'default'): string {
142 $output = '';
143
144 switch ($style) {
145 case 'minimal':
146 // Minimal style - includes company name and details
147 $output .= '<div class="company-info-minimal">';
148 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
149 if ($company_info['address']) {
150 $output .= '<div class="company-address">' . nl2br(esc_html($company_info['address'])) . '</div>';
151 }
152 if ($company_info['email']) {
153 $output .= '<div class="company-email">' . esc_html($company_info['email']) . '</div>';
154 }
155 if ($company_info['phone']) {
156 $output .= '<div class="company-phone">' . esc_html($company_info['phone']) . '</div>';
157 }
158 if ($company_info['website']) {
159 $output .= '<div class="company-website">' . esc_html($company_info['website']) . '</div>';
160 }
161 $output .= '</div>';
162 break;
163
164 case 'details-only':
165 // Details only style - excludes company name (for use with separate company-name div)
166 $output .= '<div class="company-info-details-only">';
167 if ($company_info['address']) {
168 $output .= '<div class="company-address">' . nl2br(esc_html($company_info['address'])) . '</div>';
169 }
170 if ($company_info['email']) {
171 $output .= '<div class="company-email">' . esc_html($company_info['email']) . '</div>';
172 }
173 if ($company_info['phone']) {
174 $output .= '<div class="company-phone">' . esc_html($company_info['phone']) . '</div>';
175 }
176 if ($company_info['website']) {
177 $output .= '<div class="company-website">' . esc_html($company_info['website']) . '</div>';
178 }
179 $output .= '</div>';
180 break;
181
182 case 'elegant':
183 // Elegant style - subtle design
184 $output .= '<div class="company-info-elegant">';
185 if ($show_label) {
186 $output .= '<h3 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . '</h3>';
187 }
188 $output .= '<div class="company-details">';
189 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
190 if ($company_info['address']) {
191 $output .= '<div class="company-address">' . nl2br(esc_html($company_info['address'])) . '</div>';
192 }
193 if ($company_info['email']) {
194 $output .= '<div class="company-email">' . esc_html($company_info['email']) . '</div>';
195 }
196 if ($company_info['phone']) {
197 $output .= '<div class="company-phone">' . esc_html($company_info['phone']) . '</div>';
198 }
199 if ($company_info['website']) {
200 $output .= '<div class="company-website">' . esc_html($company_info['website']) . '</div>';
201 }
202 $output .= '</div>';
203 $output .= '</div>';
204 break;
205
206 case 'modern':
207 // Modern style - clean and bold
208 $output .= '<div class="company-info-modern">';
209 if ($show_label) {
210 $output .= '<h2 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . ':</h2>';
211 }
212 $output .= '<div class="address-content">';
213 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
214 if ($company_info['address']) {
215 $output .= nl2br(esc_html($company_info['address'])) . '<br>';
216 }
217 if ($company_info['email']) {
218 $output .= esc_html($company_info['email']) . '<br>';
219 }
220 if ($company_info['phone']) {
221 $output .= esc_html($company_info['phone']) . '<br>';
222 }
223 if ($company_info['website']) {
224 $output .= esc_html($company_info['website']);
225 }
226 $output .= '</div>';
227 $output .= '</div>';
228 break;
229
230 case 'professional':
231 // Professional style - structured layout
232 $output .= '<div class="company-info-professional">';
233 if ($show_label) {
234 $output .= '<h2 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . ':</h2>';
235 }
236 $output .= '<div class="address-content">';
237 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
238 if ($company_info['address']) {
239 $output .= nl2br(esc_html($company_info['address'])) . '<br>';
240 }
241 if ($company_info['email']) {
242 $output .= esc_html($company_info['email']) . '<br>';
243 }
244 if ($company_info['phone']) {
245 $output .= esc_html($company_info['phone']) . '<br>';
246 }
247 if ($company_info['website']) {
248 $output .= esc_html($company_info['website']);
249 }
250 $output .= '</div>';
251 $output .= '</div>';
252 break;
253
254 case 'creative':
255 // Creative style - artistic design
256 $output .= '<div class="company-info-creative">';
257 if ($show_label) {
258 $output .= '<h2 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . '</h2>';
259 }
260 $output .= '<div class="address-content">';
261 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
262 if ($company_info['address']) {
263 $output .= nl2br(esc_html($company_info['address'])) . '<br>';
264 }
265 if ($company_info['email']) {
266 $output .= esc_html($company_info['email']) . '<br>';
267 }
268 if ($company_info['phone']) {
269 $output .= esc_html($company_info['phone']) . '<br>';
270 }
271 if ($company_info['website']) {
272 $output .= esc_html($company_info['website']);
273 }
274 $output .= '</div>';
275 $output .= '</div>';
276 break;
277
278 default:
279 // Default style - standard layout
280 $output .= '<div class="company-info-default">';
281 if ($show_label) {
282 $output .= '<h2 class="from-label">' . esc_html(\EasyInvoice\Controllers\SettingsController::getTextFrom()) . ':</h2>';
283 }
284 $output .= '<div class="address-content">';
285 $output .= '<div class="company-name">' . esc_html($company_info['name']) . '</div>';
286 if ($company_info['address']) {
287 $output .= nl2br(esc_html($company_info['address'])) . '<br>';
288 }
289 if ($company_info['email']) {
290 $output .= esc_html($company_info['email']) . '<br>';
291 }
292 if ($company_info['phone']) {
293 $output .= esc_html($company_info['phone']) . '<br>';
294 }
295 if ($company_info['website']) {
296 $output .= esc_html($company_info['website']);
297 }
298 $output .= '</div>';
299 $output .= '</div>';
300 break;
301 }
302
303 return $output;
304 }
305
306 /**
307 * Generate totals section for invoice/quote templates
308 *
309 * @param mixed $document Invoice or Quote object
310 * @param array $text_settings Text settings array
311 * @param mixed $formatter Formatter object
312 * @param string $type 'invoice' or 'quote'
313 * @return string Generated HTML for totals section
314 */
315 public static function generateTotalsSection($document, array $text_settings, $formatter, string $type = 'invoice'): string {
316 $output = '';
317
318 // Subtotal
319 $output .= '<div class="' . $type . '-total-row">';
320 $output .= '<span class="' . $type . '-total-label">' . esc_html($text_settings['sub_total']) . ':</span>';
321 $output .= '<span class="' . $type . '-total-value">' . esc_html($formatter->format($document->getSubtotal())) . '</span>';
322 $output .= '</div>';
323
324 // Discount (if any)
325 if ($document->getDiscountAmount() > 0) {
326 $output .= '<div class="' . $type . '-total-row">';
327 $output .= '<span class="' . $type . '-total-label">' . esc_html($text_settings['discount']);
328 if ($document->getDiscountType() === 'percentage') {
329 $output .= ' (' . esc_html($document->getDiscountValue()) . '%)';
330 }
331 $output .= ':</span>';
332 $output .= '<span class="' . $type . '-total-value">-' . esc_html($formatter->format($document->getDiscountAmount())) . '</span>';
333 $output .= '</div>';
334 }
335
336
337 // Tax (if any)
338 if ($document->getTaxAmount() > 0) {
339 $output .= '<div class="' . $type . '-total-row">';
340 $output .= '<span class="' . $type . '-total-label">' . esc_html(easy_invoice_get_tax_name());
341 $output .= ' (' . esc_html($document->getTaxRate()) . '%):</span>';
342 $output .= '<span class="' . $type . '-total-value">' . esc_html($formatter->format($document->getTaxAmount())) . '</span>';
343 $output .= '</div>';
344 }
345
346 // Allow plugins to add content
347 if ($type === 'invoice') {
348 do_action('easy_invoice_invoice_totals_after_tax', $document);
349 do_action('easy_invoice_invoice_totals_after_discount', $document);
350 } else {
351 do_action('easy_invoice_quote_totals_after_tax', $document);
352 do_action('easy_invoice_quote_totals_after_discount', $document);
353 }
354
355 // Grand Total
356 $output .= '<div class="' . $type . '-total-row ' . $type . '-grand-total">';
357 $output .= '<span class="' . $type . '-total-label">' . esc_html($text_settings['total']) . ':</span>';
358 $output .= '<span class="' . $type . '-total-value">' . esc_html($formatter->format($document->getTotal())) . '</span>';
359 $output .= '</div>';
360
361 return $output;
362 }
363 }