PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.1
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.1
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 / templates / invoices / preview.php

preview.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.1, at templates/invoices/preview.php

303 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Invoice Preview Template
4 *
5 * @package EasyInvoice
6 * @since 1.0.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12 // Get invoice data
13 $invoice_id = isset($_GET['invoice_id']) ? (int) $_GET['invoice_id'] : (isset($_GET['id']) ? (int) $_GET['id'] : 0); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
14 $invoice = $invoice ?? null;
15
16 if ($invoice_id <= 0 || !$invoice) {
17 wp_die(esc_html__('Invoice not found.', 'easy-invoice'));
18 }
19
20 // Initialize formatter for currency formatting
21 $formatter = $invoice ? new \EasyInvoice\Helpers\InvoiceFormatter($invoice) : null;
22
23 // Get the current template (default to 'standard')
24 $current_template = $invoice && method_exists($invoice, 'getTemplate') ? $invoice->getTemplate() : 'standard';
25 if (empty($current_template)) {
26 $current_template = 'standard';
27 }
28
29 // Get company information from settings
30 $company_name = get_option('easy_invoice_company_name', __('Your Company Name', 'easy-invoice'));
31 $company_address = get_option('easy_invoice_company_address', __('Your Company Address', 'easy-invoice'));
32 $company_email = get_option('easy_invoice_company_email', '[email protected]');
33 $company_phone = get_option('easy_invoice_company_phone', '+1 (555) 123-4567');
34 $company_website = get_option('easy_invoice_company_website', 'www.yourcompany.com');
35
36 ?>
37 <!DOCTYPE html>
38 <html lang="en">
39 <head>
40 <meta charset="UTF-8">
41 <meta name="viewport" content="width=device-width, initial-scale=1.0">
42 <title>Invoice <?php echo $invoice ? esc_html($invoice->getNumber()) : 'Unknown'; ?></title>
43
44 <?php
45 // Bundled locally (wp.org requires all assets to ship inside the plugin)
46 // and printed through the script registry so filters and dependencies apply.
47 if ( ! wp_script_is( 'jspdf', 'registered' ) ) {
48 wp_register_script( 'jspdf', EASY_INVOICE_PLUGIN_URL . 'assets/js/vendors/jspdf.umd.min.js', [], '2.5.1', false );
49 }
50 wp_print_scripts( [ 'jspdf' ] );
51 ?>
52
53 <style>
54 * {
55 margin: 0;
56 padding: 0;
57 box-sizing: border-box;
58 }
59
60 body {
61 font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
62 line-height: 1.6;
63 color: #333;
64 background: #f8f9fa;
65 }
66
67 .invoice-container {
68 max-width: 800px;
69 margin: 20px auto;
70 background: white;
71 box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
72 border-radius: 8px;
73 overflow: hidden;
74 }
75
76 .invoice-header {
77 background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
78 color: white;
79 padding: 30px;
80 text-align: center;
81 }
82
83 .invoice-header h1 {
84 font-size: 2.5rem;
85 font-weight: 300;
86 margin-bottom: 10px;
87 }
88
89 .invoice-header .invoice-number {
90 font-size: 1.2rem;
91 opacity: 0.9;
92 }
93
94 .invoice-content {
95 padding: 40px;
96 }
97
98 .company-info {
99 display: flex;
100 justify-content: space-between;
101 margin-bottom: 40px;
102 padding-bottom: 20px;
103 border-bottom: 2px solid #e9ecef;
104 }
105
106 .company-details h2 {
107 color: #495057;
108 font-size: 1.5rem;
109 margin-bottom: 10px;
110 }
111
112 .company-details p {
113 color: #6c757d;
114 margin-bottom: 5px;
115 }
116
117 .client-info h3 {
118 color: #495057;
119 font-size: 1.2rem;
120 margin-bottom: 10px;
121 }
122
123 .client-info p {
124 color: #6c757d;
125 margin-bottom: 5px;
126 }
127
128 .invoice-details {
129 margin-bottom: 30px;
130 }
131
132 .invoice-details table {
133 width: 100%;
134 border-collapse: collapse;
135 }
136
137 .invoice-details th,
138 .invoice-details td {
139 padding: 8px;
140 text-align: left;
141 border-bottom: 1px solid #e9ecef;
142 }
143
144 .invoice-details th {
145 background-color: #f8f9fa;
146 font-weight: 600;
147 color: #495057;
148 }
149
150 .items-table {
151 width: 100%;
152 border-collapse: collapse;
153 margin-bottom: 30px;
154 }
155
156 .items-table th,
157 .items-table td {
158 padding: 12px 8px;
159 text-align: left;
160 border-bottom: 1px solid #e9ecef;
161 }
162
163 .items-table th {
164 background-color: #f8f9fa;
165 font-weight: 600;
166 color: #495057;
167 }
168
169 .item-name {
170 font-weight: 500;
171 color: #495057;
172 }
173
174 .item-description {
175 font-size: 0.9rem;
176 color: #6c757d;
177 margin-top: 4px;
178 }
179
180 .amount {
181 font-weight: 600;
182 color: #495057;
183 }
184
185 .totals-section {
186 margin-bottom: 30px;
187 }
188
189 .totals-table {
190 width: 100%;
191 max-width: 300px;
192 margin-left: auto;
193 }
194
195 .total-row {
196 display: flex;
197 justify-content: space-between;
198 padding: 8px 0;
199 border-bottom: 1px solid #e9ecef;
200 }
201
202 .total-row:last-child {
203 border-bottom: 2px solid #495057;
204 font-weight: 600;
205 font-size: 1.1rem;
206 }
207
208 .notes-section {
209 margin-bottom: 30px;
210 }
211
212 .notes-section h3 {
213 color: #495057;
214 font-size: 1.2rem;
215 margin-bottom: 10px;
216 }
217
218 .notes-section p {
219 color: #6c757d;
220 line-height: 1.6;
221 }
222
223 .invoice-footer {
224 background-color: #f8f9fa;
225 padding: 20px;
226 text-align: center;
227 color: #6c757d;
228 }
229
230 .invoice-footer p {
231 margin-bottom: 5px;
232 }
233
234 /* Print styles */
235 @media print {
236 body {
237 background: white;
238 }
239
240 .invoice-container {
241 box-shadow: none;
242 margin: 0;
243 }
244 }
245 </style>
246 </head>
247 <body>
248 <div class="invoice-container">
249 <?php
250 // Dynamically load the selected template
251 $template_file = easy_invoice_design_template( 'invoice', (string) $current_template );
252 if (file_exists($template_file)) {
253 include_once $template_file;
254 } else {
255 // Fallback to standard template if selected template doesn't exist
256 $template_file = easy_invoice_design_template( 'invoice', 'standard' );
257 if (file_exists($template_file)) {
258 include_once $template_file;
259 } else {
260 // Show error if no template is available
261 echo '<div style="padding: 40px; text-align: center;">';
262 echo '<h2>Template Error</h2>';
263 echo '<p>The selected template "' . esc_html($current_template) . '" could not be loaded.</p>';
264 echo '</div>';
265 }
266 }
267 ?>
268 </div>
269
270 <script>
271 // Invoice data for PDF generation
272 window.invoiceData = <?php
273 $invoice_data = $invoice ? \EasyInvoice\Includes\Helpers\PdfHelper::getInvoiceDataForPdf($invoice) : [];
274 if ($invoice) {
275 $invoice_data['status'] = $invoice->getStatus();
276 }
277 echo json_encode($invoice_data);
278 ?>;
279
280 // Global function for downloading PDF
281 function downloadInvoicePdf(invoiceId) {
282 try {
283 if (typeof InvoicePdfGenerator !== 'undefined') {
284 // Use the new PDF generator that captures HTML directly
285 const pdfGenerator = new InvoicePdfGenerator();
286 pdfGenerator.generatePDF();
287
288 // Show success message after a short delay
289 setTimeout(function() {
290 alert('<?php echo esc_js(__('PDF generated successfully', 'easy-invoice')); ?>');
291 }, 2000);
292 } else {
293 alert('Error: PDF generator not available');
294 }
295 } catch (error) {
296 console.error('PDF generation error:', error);
297 alert('<?php echo esc_js(__('Error generating PDF', 'easy-invoice')); ?>');
298 }
299 }
300 </script>
301 </body>
302 </html>
303