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

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