PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.0
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.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 / payments / edit.php

edit.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.0, at templates/payments/edit.php

279 lines 14.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Edit Payment Template
4 *
5 * @package Easy_Invoice
6 */
7
8 namespace EasyInvoice\Templates\Payments;
9
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14 use EasyInvoice\Models\Invoice;
15 use EasyInvoice\Models\Payment;
16
17 if (!isset($payment) || !($payment instanceof Payment)) {
18 wp_die(esc_html__('Invalid payment', 'easy-invoice'));
19 }
20 ?>
21
22 <div class="p-8">
23 <div class="flex justify-between items-center mb-6">
24 <h1 class="text-2xl font-bold text-gray-900">
25 <?php esc_html_e('Edit Payment', 'easy-invoice'); ?>
26 </h1>
27 <a href="<?php echo esc_url(admin_url('admin.php?page=easy-invoice-payments')); ?>"
28 class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
29 <?php esc_html_e('Back to Payments', 'easy-invoice'); ?>
30 </a>
31 </div>
32
33
34
35 <div class="bg-white shadow overflow-hidden sm:rounded-lg">
36 <form method="post" action="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" id="edit-payment-form" class="space-y-6 p-6">
37 <?php wp_nonce_field('easy_invoice_payment', 'payment_nonce'); ?>
38 <input type="hidden" name="action" value="easy_invoice_update_payment">
39 <input type="hidden" name="payment_id" value="<?php echo esc_attr($payment->getId()); ?>">
40
41 <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
42 <div>
43 <label for="invoice_id" class="block text-sm font-medium text-gray-700">
44 <?php esc_html_e('Invoice', 'easy-invoice'); ?> <span class="text-red-500">*</span>
45 </label>
46 <select name="invoice_id" id="invoice_id" required
47 class="mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
48 <option value=""><?php esc_html_e('Select Invoice', 'easy-invoice'); ?></option>
49 <?php
50 // Get current payment's invoice ID
51 $current_invoice_id = $payment->getInvoiceId();
52
53 // Get unpaid invoices
54 $unpaid_invoices = get_posts(array(
55 'post_type' => 'easy_invoice',
56 'posts_per_page' => -1,
57 'post_status' => 'publish',
58 'orderby' => 'date',
59 'order' => 'DESC',
60 'meta_query' => array(
61 'relation' => 'OR',
62 array(
63 'key' => '_payment_status',
64 'value' => 'unpaid',
65 'compare' => '='
66 ),
67 array(
68 'key' => '_payment_status',
69 'compare' => 'NOT EXISTS'
70 ),
71 array(
72 'key' => '_payment_status',
73 'value' => '',
74 'compare' => '='
75 )
76 )
77 ));
78
79 // Get current payment's invoice if it's not in unpaid list
80 $current_invoice = null;
81 if ($current_invoice_id) {
82 $current_invoice = get_post($current_invoice_id);
83 }
84
85 // Combine unpaid invoices with current invoice
86 $invoices = $unpaid_invoices;
87 if ($current_invoice && $current_invoice->post_type === 'easy_invoice') {
88 $invoices[] = $current_invoice;
89 }
90
91 foreach ($invoices as $post) {
92 $invoice = new Invoice($post);
93 $is_selected = ($invoice->getId() == $current_invoice_id);
94
95 // Get invoice number - try different methods
96 $invoice_number = $invoice->getNumber();
97 if (empty($invoice_number)) {
98 $invoice_number = get_post_meta($invoice->getId(), '_easy_invoice_number', true);
99 }
100 if (empty($invoice_number)) {
101 $invoice_number = 'INV-' . $invoice->getId();
102 }
103
104 // Get total amount
105 $total = $invoice->getTotal();
106 if (empty($total)) {
107 $total = get_post_meta($invoice->getId(), '_easy_invoice_total', true);
108 }
109 if (empty($total)) {
110 $total = 0;
111 }
112
113 // Get currency symbol
114 $currency_symbol = $invoice->getCurrencySymbol();
115 if (empty($currency_symbol)) {
116 $currency_symbol = get_option('easy_invoice_currency_symbol', '$');
117 }
118
119 printf(
120 '<option value="%d" %s>%s - %s</option>',
121 (int) $invoice->getId(),
122 $is_selected ? 'selected="selected"' : '', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- literal attribute.
123 esc_html($invoice_number),
124 esc_html($currency_symbol . number_format($total, 2))
125 );
126 }
127 ?>
128 </select>
129 </div>
130
131 <div>
132 <label for="payment_method" class="block text-sm font-medium text-gray-700">
133 <?php esc_html_e('Payment Method', 'easy-invoice'); ?> <span class="text-red-500">*</span>
134 </label>
135 <select name="payment_method" id="payment_method" required
136 class="mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
137 <option value=""><?php esc_html_e('Select Payment Method', 'easy-invoice'); ?></option>
138 <?php
139 $current_payment_method = $payment->getPaymentMethod();
140 if (empty($current_payment_method)) {
141 $current_payment_method = get_post_meta($payment->getId(), '_payment_method', true);
142 }
143
144 // Get available payment gateways (sorted)
145 $gateway_manager = \EasyInvoice\EasyInvoice::getInstance()->getGatewayManager();
146 $enabled_gateways = $gateway_manager->getEnabledGateways();
147
148 // Show only enabled gateways and manual options
149 $available_methods = [
150 'manual' => __('Manual', 'easy-invoice'),
151 ];
152
153 // Add enabled gateways only (already sorted)
154 foreach ($enabled_gateways as $gateway_id => $gateway) {
155 $available_methods[$gateway_id] = $gateway_manager->getGatewayDisplayName($gateway_id);
156 }
157
158 foreach ($available_methods as $method_id => $method_name) {
159 $is_selected = ($method_id === $current_payment_method);
160 printf(
161 '<option value="%s" %s>%s</option>',
162 esc_attr($method_id),
163 $is_selected ? 'selected="selected"' : '',
164 esc_html($method_name)
165 );
166 }
167 ?>
168 </select>
169 </div>
170
171 <div>
172 <label for="amount" class="block text-sm font-medium text-gray-700">
173 <?php esc_html_e('Amount', 'easy-invoice'); ?> <span class="text-red-500">*</span>
174 </label>
175 <div class="mt-1 relative rounded-md shadow-sm">
176 <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
177 <span class="text-gray-500 sm:text-sm"><?php echo esc_html(get_option('easy_invoice_currency_symbol', '$')); ?></span>
178 </div>
179 <input type="number" name="amount" id="amount" step="0.01" required
180 value="<?php echo esc_attr($payment->getAmount()); ?>"
181 class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 pl-7 pr-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
182 placeholder="0.00">
183 </div>
184 </div>
185
186 <div>
187 <label for="payment_date" class="block text-sm font-medium text-gray-700">
188 <?php esc_html_e('Payment Date', 'easy-invoice'); ?> <span class="text-red-500">*</span>
189 </label>
190 <input type="date" name="payment_date" id="payment_date"
191 value="<?php
192 $payment_date = $payment->getPaymentDate();
193 if (empty($payment_date)) {
194 $payment_date = get_post_meta($payment->getId(), '_payment_date', true);
195 }
196 if (empty($payment_date)) {
197 $payment_date = current_time('Y-m-d');
198 }
199
200 // Ensure date is in YYYY-MM-DD format for HTML date input
201 if (!empty($payment_date)) {
202 $timestamp = strtotime($payment_date);
203 if ($timestamp) {
204 $payment_date = gmdate('Y-m-d', $timestamp);
205 } else {
206 $payment_date = current_time('Y-m-d');
207 }
208 }
209
210 echo esc_attr($payment_date);
211 ?>" required
212 class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
213 </div>
214
215 <div>
216 <label for="status" class="block text-sm font-medium text-gray-700">
217 <?php esc_html_e('Status', 'easy-invoice'); ?> <span class="text-red-500">*</span>
218 </label>
219 <select name="status" id="status" required
220 class="mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
221 <option value="pending" <?php selected($payment->getStatus(), 'pending'); ?>><?php esc_html_e('Pending', 'easy-invoice'); ?></option>
222 <option value="completed" <?php selected($payment->getStatus(), 'completed'); ?>><?php esc_html_e('Completed', 'easy-invoice'); ?></option>
223 <option value="failed" <?php selected($payment->getStatus(), 'failed'); ?>><?php esc_html_e('Failed', 'easy-invoice'); ?></option>
224 <option value="refunded" <?php selected($payment->getStatus(), 'refunded'); ?>><?php esc_html_e('Refunded', 'easy-invoice'); ?></option>
225 </select>
226 </div>
227
228 <div class="sm:col-span-2">
229 <label for="notes" class="block text-sm font-medium text-gray-700">
230 <?php esc_html_e('Notes', 'easy-invoice'); ?>
231 </label>
232 <div class="mt-1">
233 <textarea name="notes" id="notes" rows="3"
234 class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
235 placeholder="<?php echo esc_js(__('Add any additional notes about this payment...', 'easy-invoice')); ?>"><?php echo wp_kses_post($payment->getNotes()); ?></textarea>
236 </div>
237 </div>
238 </div>
239
240 <div class="pt-5">
241 <div class="flex justify-end">
242 <button type="submit"
243 class="ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
244 <?php esc_html_e('Update Payment', 'easy-invoice'); ?>
245 </button>
246 </div>
247 </div>
248 </form>
249 </div>
250 </div>
251
252 <script>
253 jQuery(document).ready(function($) {
254 // Form submission
255 $('#edit-payment-form').on('submit', function(e) {
256 e.preventDefault();
257
258 var formData = new FormData(this);
259
260 $.ajax({
261 url: $(this).attr('action'),
262 type: 'POST',
263 data: formData,
264 processData: false,
265 contentType: false,
266 success: function(response) {
267 if (response.success) {
268 EasyInvoiceToast.success(response.data.message || '<?php echo esc_js(__('Payment updated successfully', 'easy-invoice')); ?>');
269 } else {
270 EasyInvoiceToast.error(response.data.message || '<?php echo esc_js(__('An error occurred', 'easy-invoice')); ?>');
271 }
272 },
273 error: function() {
274 EasyInvoiceToast.error('<?php echo esc_js(__('An error occurred', 'easy-invoice')); ?>');
275 }
276 });
277 });
278 });
279 </script>