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

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