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

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

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