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 / new.php

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

217 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * New Payment Template
4 *
5 * @package Easy_Invoice
6 */
7
8 namespace EasyInvoice\Templates\Payments;
9
10 use EasyInvoice\Models\Invoice;
11 ?>
12
13 <div class="p-8">
14 <div class="flex justify-between items-center mb-6">
15 <h1 class="text-2xl font-bold text-gray-900">
16 <?php _e('Add New Payment', 'easy-invoice'); ?>
17 </h1>
18 <a href="<?php echo admin_url('admin.php?page=easy-invoice-payments'); ?>"
19 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">
20 <?php _e('Back to Payments', 'easy-invoice'); ?>
21 </a>
22 </div>
23
24 <div class="bg-white shadow overflow-hidden sm:rounded-lg">
25 <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?>" id="new-payment-form" class="space-y-6 p-6">
26 <?php wp_nonce_field('easy_invoice_payment', 'payment_nonce'); ?>
27 <input type="hidden" name="action" value="easy_invoice_process_payment">
28
29 <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
30 <div>
31 <label for="invoice_id" class="block text-sm font-medium text-gray-700">
32 <?php _e('Invoice', 'easy-invoice'); ?> <span class="text-red-500">*</span>
33 </label>
34 <select name="invoice_id" id="invoice_id" required
35 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">
36 <option value=""><?php _e('Select Invoice', 'easy-invoice'); ?></option>
37 <?php
38 $invoices = get_posts(array(
39 'post_type' => 'easy_invoice',
40 'posts_per_page' => -1,
41 'post_status' => 'publish',
42 'orderby' => 'date',
43 'order' => 'DESC',
44 'meta_query' => array(
45 'relation' => 'OR',
46 array(
47 'key' => '_payment_status',
48 'value' => 'unpaid',
49 'compare' => '='
50 ),
51 array(
52 'key' => '_payment_status',
53 'compare' => 'NOT EXISTS'
54 ),
55 array(
56 'key' => '_payment_status',
57 'value' => '',
58 'compare' => '='
59 )
60 )
61 ));
62
63 foreach ($invoices as $post) {
64 $invoice = new Invoice($post);
65
66 // Get invoice number - try different methods
67 $invoice_number = $invoice->getNumber();
68 if (empty($invoice_number)) {
69 $invoice_number = get_post_meta($invoice->getId(), '_easy_invoice_number', true);
70 }
71 if (empty($invoice_number)) {
72 $invoice_number = 'INV-' . $invoice->getId();
73 }
74
75 // Get total amount
76 $total = $invoice->getTotal();
77 if (empty($total)) {
78 $total = get_post_meta($invoice->getId(), '_easy_invoice_total', true);
79 }
80 if (empty($total)) {
81 $total = 0;
82 }
83
84 // Get currency symbol
85 $currency_symbol = $invoice->getCurrencySymbol();
86 if (empty($currency_symbol)) {
87 $currency_symbol = get_option('easy_invoice_currency_symbol', '$');
88 }
89
90 printf(
91 '<option value="%d">%s - %s</option>',
92 $invoice->getId(),
93 esc_html($invoice_number),
94 esc_html($currency_symbol . number_format($total, 2))
95 );
96 }
97 ?>
98 </select>
99 </div>
100
101 <div>
102 <label for="payment_method" class="block text-sm font-medium text-gray-700">
103 <?php _e('Payment Method', 'easy-invoice'); ?> <span class="text-red-500">*</span>
104 </label>
105 <select name="payment_method" id="payment_method" required
106 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">
107 <option value=""><?php _e('Select Payment Method', 'easy-invoice'); ?></option>
108 <?php
109 // Get available payment gateways (sorted)
110 $gateway_manager = \EasyInvoice\EasyInvoice::getInstance()->getGatewayManager();
111 $enabled_gateways = $gateway_manager->getEnabledGateways();
112
113 // Show only enabled gateways and manual options
114 $available_methods = [
115 'manual' => __('Manual', 'easy-invoice'),
116 ];
117
118 // Add enabled gateways only (already sorted)
119 foreach ($enabled_gateways as $gateway_id => $gateway) {
120 $available_methods[$gateway_id] = $gateway_manager->getGatewayDisplayName($gateway_id);
121 }
122
123 foreach ($available_methods as $method_id => $method_name) {
124 printf(
125 '<option value="%s">%s</option>',
126 esc_attr($method_id),
127 esc_html($method_name)
128 );
129 }
130 ?>
131 </select>
132 </div>
133
134 <div>
135 <label for="amount" class="block text-sm font-medium text-gray-700">
136 <?php _e('Amount', 'easy-invoice'); ?> <span class="text-red-500">*</span>
137 </label>
138 <div class="mt-1 relative rounded-md shadow-sm">
139 <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
140 <span class="text-gray-500 sm:text-sm"><?php echo get_option('easy_invoice_currency_symbol', '$'); ?></span>
141 </div>
142 <input type="number" name="amount" id="amount" step="0.01" required
143 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"
144 placeholder="0.00">
145 </div>
146 </div>
147
148 <div>
149 <label for="payment_date" class="block text-sm font-medium text-gray-700">
150 <?php _e('Payment Date', 'easy-invoice'); ?> <span class="text-red-500">*</span>
151 </label>
152 <input type="date" name="payment_date" id="payment_date"
153 value="<?php echo date('Y-m-d'); ?>" required
154 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">
155 </div>
156
157 <div class="sm:col-span-2">
158 <label for="notes" class="block text-sm font-medium text-gray-700">
159 <?php _e('Notes', 'easy-invoice'); ?>
160 </label>
161 <div class="mt-1">
162 <textarea name="notes" id="notes" rows="3"
163 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"
164 placeholder="<?php _e('Add any additional notes about this payment...', 'easy-invoice'); ?>"></textarea>
165 </div>
166 </div>
167 </div>
168
169 <div class="pt-5">
170 <div class="flex justify-end">
171 <button type="submit"
172 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">
173 <?php _e('Add Payment', 'easy-invoice'); ?>
174 </button>
175 </div>
176 </div>
177 </form>
178 </div>
179 </div>
180
181 <script>
182 jQuery(document).ready(function($) {
183 // Update amount when invoice is selected
184 $('#invoice_id').on('change', function() {
185 var selectedOption = $(this).find('option:selected');
186 var amount = selectedOption.text().split(' - ')[1];
187 if (amount) {
188 $('#amount').val(amount.replace(/[^0-9.-]+/g, ''));
189 }
190 });
191
192 // Form submission
193 $('#new-payment-form').on('submit', function(e) {
194 e.preventDefault();
195
196 var formData = new FormData(this);
197
198 $.ajax({
199 url: $(this).attr('action'),
200 type: 'POST',
201 data: formData,
202 processData: false,
203 contentType: false,
204 success: function(response) {
205 if (response.success) {
206 window.location.href = '<?php echo admin_url('admin.php?page=easy-invoice-payments'); ?>';
207 } else {
208 EasyInvoiceToast.error(response.data.message || '<?php _e('An error occurred', 'easy-invoice'); ?>');
209 }
210 },
211 error: function() {
212 EasyInvoiceToast.error('<?php _e('An error occurred', 'easy-invoice'); ?>');
213 }
214 });
215 });
216 });
217 </script>