PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.2
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.1.2, at templates/payments/new.php

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