PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.6
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.6
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 / live-preview.php

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

242 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <div class="bg-white shadow rounded-lg" style="padding: 10px;">
2
3 <div class="px-6 py-5 border-b border-gray-200" style="margin-bottom: 10px;">
4 <div class="flex justify-between items-center">
5 <div class="flex items-center">
6 <div class="flex-shrink-0 bg-indigo-100 rounded-lg p-3">
7 <i class="fas fa-eye text-indigo-600 text-xl"></i>
8 </div>
9 <div class="ml-4">
10 <h2 class="text-lg font-medium text-gray-900">Invoice Preview</h2>
11 <p class="mt-1 text-sm text-gray-500">Live preview of your invoice</p>
12 </div>
13 </div>
14 <?php if($invoice_id > 0 ){ ?>
15 <a href="<?php echo get_permalink($invoice_id); ?>" target="_blank" class="inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
16 <i class="fas fa-external-link-alt mr-2"></i>
17 Full Preview
18 </a>
19 <?php } ?>
20 </div>
21 </div>
22
23 <?php
24 // Get the current template (default to 'standard')
25 $current_template = $invoice ? $invoice->getTemplate() : 'standard';
26 if (empty($current_template)) {
27 $current_template = 'standard';
28 }
29 $template_class = 'template-' . $current_template;
30
31 // Initialize formatter for the invoice templates
32 $formatter = new \EasyInvoice\Helpers\InvoiceFormatter($invoice);
33 ?>
34
35 <div id="invoice-container" class="invoice-container">
36 <?php
37 // Add custom template builder CSS if using a custom template
38 if ($invoice && method_exists($invoice, 'getId')) {
39 $template_id = get_post_meta($invoice->getId(), '_easy_invoice_invoice_template', true);
40 if ($template_id && class_exists('\EasyInvoicePro\TemplateParser') && class_exists('\EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController')) {
41 $templateData = \EasyInvoicePro\TemplateParser::parseTemplateFromDatabase($template_id);
42 if ($templateData && isset($templateData['elements'])) {
43 echo '<style>';
44 // Canvas settings
45 $canvas = $templateData['canvas'] ?? [];
46 $canvasWidth = $canvas['width'] ?? 794;
47 $canvasHeight = $canvas['height'] ?? 1123;
48 $canvasDesignCSS = \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController::generateCanvasCSS($templateData);
49
50 echo "#canvas { position: relative; width: " . floatval($canvasWidth) . "px; height: " . floatval($canvasHeight) . "px; margin: 0; overflow: visible; ";
51 if ($canvasDesignCSS) {
52 echo str_replace('!important;', ';', $canvasDesignCSS);
53 }
54 echo " }\n";
55
56 // Element styles
57 foreach ($templateData['elements'] as $element) {
58 $elementId = $element['id'] ?? '';
59 if (!$elementId) continue;
60
61 echo "#{$elementId} { position: absolute; ";
62 if (isset($element['position']['left'])) echo "left: " . floatval($element['position']['left']) . "px; ";
63 if (isset($element['position']['top'])) echo "top: " . floatval($element['position']['top']) . "px; ";
64 if (isset($element['dimensions']['width'])) echo "width: " . floatval($element['dimensions']['width']) . "px; ";
65 if (isset($element['dimensions']['height'])) echo "min-height: " . floatval($element['dimensions']['height']) . "px; ";
66
67 if (isset($element['styles']) && is_array($element['styles'])) {
68 foreach ($element['styles'] as $property => $value) {
69 if ($value !== '' && !in_array($property, ['position', 'dimensions'])) {
70 echo esc_attr($property) . ": " . esc_attr($value) . "; ";
71 }
72 }
73 }
74 echo "}\n";
75 }
76 echo '</style>';
77 }
78 }
79 }
80
81 // Dynamically load the selected template
82 $template_file = EASY_INVOICE_PLUGIN_DIR . 'templates/invoice-templates/' . $current_template . '.php';
83
84 $template_file = file_exists($template_file) ? $template_file : EASY_INVOICE_PLUGIN_DIR . 'templates/invoice-templates/default.php';
85 if (file_exists($template_file)) {
86 include_once $template_file;
87 } else {
88 // Show template not found message
89 ?>
90 <div class="template-not-found">
91 <div class="template-not-found-icon">
92 <i class="fas fa-exclamation-circle"></i>
93 </div>
94 <h3>Template Not Found</h3>
95 <p>The selected template "<?php echo esc_html($current_template); ?>" does not exist.</p>
96 <p>Please select a different template or contact support if you believe this is an error.</p>
97 </div>
98 <style>
99 .template-not-found {
100 text-align: center;
101 padding: 40px;
102 background: #fff;
103 border-radius: 8px;
104 box-shadow: 0 2px 4px rgba(0,0,0,0.1);
105 }
106 .template-not-found-icon {
107 font-size: 48px;
108 color: #dc3545;
109 margin-bottom: 20px;
110 }
111 .template-not-found h3 {
112 font-size: 24px;
113 color: #32325d;
114 margin-bottom: 10px;
115 }
116 .template-not-found p {
117 color: #8898aa;
118 margin-bottom: 10px;
119 }
120 </style>
121 <?php
122 }
123 ?>
124 </div>
125 </div>
126
127 <style>
128 /* Loading state styles */
129 .loading-overlay {
130 position: absolute;
131 top: 0;
132 left: 0;
133 right: 0;
134 bottom: 0;
135 background: rgba(255, 255, 255, 0.9);
136 display: flex;
137 justify-content: center;
138 align-items: center;
139 z-index: 1000;
140 }
141
142 .loading-spinner {
143 text-align: center;
144 }
145
146 .invoice-container.loading .loading-overlay {
147 display: flex;
148 }
149
150 /* (Resize logic removed per request) */
151 </style>
152
153 <script>
154 // Localize easyInvoice object for this page
155 window.easyInvoice = window.easyInvoice || {};
156 window.easyInvoice.isPro = <?php echo easy_invoice_has_pro() ? 'true' : 'false'; ?>;
157 window.easyInvoice.ajaxUrl = '<?php echo admin_url('admin-ajax.php'); ?>';
158 window.easyInvoice.nonce = '<?php echo wp_create_nonce('easy_invoice_nonce'); ?>';
159
160 jQuery(document).ready(function($) {
161 // Function to update the live preview
162 function updateLivePreview(templateId) {
163 // Show loading state
164 $('#invoice-container').addClass('loading');
165
166 // Make AJAX call to load the template
167 $.ajax({
168 url: window.easyInvoice.ajaxUrl,
169 type: 'POST',
170 data: {
171 action: 'easy_invoice_load_template',
172 template: templateId,
173 invoice_id: '<?php echo esc_js($invoice_id); ?>',
174 nonce: window.easyInvoice.nonce
175 },
176 success: function(response) {
177 if (response.success) {
178 // Update the preview content
179 $('#invoice-container').html(response.data.html);
180 } else {
181 // Show error message
182 $('#invoice-container').html(`
183 <div class="template-not-found">
184 <div class="template-not-found-icon">
185 <i class="fas fa-exclamation-circle"></i>
186 </div>
187 <h3>Template Not Found</h3>
188 <p>The selected template "${templateId}" does not exist.</p>
189 <p>Please select a different template or contact support if you believe this is an error.</p>
190 </div>
191 `);
192 }
193 },
194 error: function(xhr, status, error) {
195 // Show error message
196 $('#invoice-container').html(`
197 <div class="template-not-found">
198 <div class="template-not-found-icon">
199 <i class="fas fa-exclamation-circle"></i>
200 </div>
201 <h3>Error Loading Template</h3>
202 <p>There was an error loading the template. Please try again.</p>
203 </div>
204 `);
205 },
206 complete: function() {
207 // Remove loading state
208 $('#invoice-container').removeClass('loading');
209 }
210 });
211 }
212
213 // Listen for template changes from the template cards
214 $('.template-card').on('click', function(e) {
215 const templateId = $(this).data('template-id');
216
217 // Check if this is a premium template in free version
218 const isPremium = $(this).attr('data-is-premium') === 'true';
219 const isFreeVersion = !window.easyInvoice || !window.easyInvoice.isPro;
220 if (isPremium && isFreeVersion) {
221 // Show premium upgrade modal instead of selecting the template
222 if (typeof EasyInvoiceConfirmation !== 'undefined' && EasyInvoiceConfirmation.showFeatureUpgrade) {
223 EasyInvoiceConfirmation.showFeatureUpgrade('<?php _e('Premium Templates', 'easy-invoice'); ?>', '<?php _e('Access all premium templates including Modern, Professional, Classic, and more to give your invoices a unique and professional look.', 'easy-invoice'); ?>');
224 } else {
225 alert('<?php _e('This is a premium feature. Please upgrade to Pro to access all templates.', 'easy-invoice'); ?>');
226 }
227 return;
228 }
229
230 updateLivePreview(templateId);
231 });
232
233 // Listen for template changes from the gallery
234 $('.gallery-template-card').on('click', function() {
235 const templateId = $(this).data('template-id');
236 updateLivePreview(templateId);
237 });
238
239
240 });
241 </script>
242