# easy-invoice/2.4.1/templates/payments/new.php

Easy Invoice – Invoice Generator, PDF Quotes &amp; Payments, version 2.4.1. 227 lines.

- Page: https://pluginprobe.com/plugins/easy-invoice/2.4.1/code/templates/payments/new.php
- Raw: https://pluginprobe.com/plugins/easy-invoice/2.4.1/raw/templates/payments/new.php
- Modified: 2026-09-15T12:31:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/easy-invoice/2.4.1/code/templates/payments/new.php#L10-L20`.

```php
<?php
/**
 * New Payment Template
 *
 * @package Easy_Invoice
 */

namespace EasyInvoice\Templates\Payments;


if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
use EasyInvoice\Models\Invoice;
?>

<div class="p-8">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2xl font-bold text-gray-900">
            <?php esc_html_e('Add New Payment', 'easy-invoice'); ?>
        </h1>
        <a href="<?php echo esc_url(admin_url('admin.php?page=easy-invoice-payments')); ?>" 
           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">
            <?php esc_html_e('Back to Payments', 'easy-invoice'); ?>
        </a>
    </div>

    <div class="bg-white shadow overflow-hidden sm:rounded-lg">
        <form method="post" action="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" id="new-payment-form" class="space-y-6 p-6">
            <?php wp_nonce_field('easy_invoice_payment', 'payment_nonce'); ?>
            <input type="hidden" name="action" value="easy_invoice_record_payment">

            <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
                <div>
                    <label for="invoice_id" class="block text-sm font-medium text-gray-700">
                        <?php esc_html_e('Invoice', 'easy-invoice'); ?> <span class="text-red-500">*</span>
                    </label>
                    <input type="search" id="invoice_filter" class="mt-1 mb-2 block w-full border border-gray-300 rounded-md py-2 px-3 sm:text-sm" placeholder="<?php esc_attr_e( 'Type an invoice number or title to filter the list', 'easy-invoice' ); ?>" autocomplete="off">
                    <select name="invoice_id" id="invoice_id" required
                            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">
                        <option value=""><?php esc_html_e('Select Invoice', 'easy-invoice'); ?></option>
                        <?php
                        // Only invoices that can still take a payment, newest first, and
                        // never the whole table: a shop with ten thousand invoices used
                        // to get every one of them instantiated into this list. The
                        // balance shown is what is still due, primed in two queries.
                        $ei_open_statuses  = [ 'available', 'unpaid', 'overdue', 'partial', 'pending_verification', 'sent' ];
                        $ei_open_statuses  = apply_filters( 'easy_invoice_payment_form_open_statuses', $ei_open_statuses );
                        $ei_preselect      = isset( $_GET['invoice_id'] ) ? absint( $_GET['invoice_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                        $ei_limit          = (int) apply_filters( 'easy_invoice_payment_form_invoice_limit', 300 );
                        $ei_open_ids       = get_posts( [
                            'post_type'      => 'easy_invoice',
                            'post_status'    => 'publish',
                            'posts_per_page' => $ei_limit,
                            'orderby'        => 'date',
                            'order'          => 'DESC',
                            'fields'         => 'ids',
                            'meta_query'     => [ [ 'key' => '_easy_invoice_status', 'value' => $ei_open_statuses, 'compare' => 'IN' ] ],
                        ] );
                        if ( $ei_preselect && ! in_array( $ei_preselect, $ei_open_ids, true ) && 'easy_invoice' === get_post_type( $ei_preselect ) ) {
                            array_unshift( $ei_open_ids, $ei_preselect );
                        }
                        $ei_open_ids = array_map( 'intval', $ei_open_ids );
                        if ( $ei_open_ids ) {
                            update_meta_cache( 'post', $ei_open_ids );
                            _prime_post_caches( $ei_open_ids, false, false );
                            \EasyInvoice\Services\InvoiceBalance::prime( $ei_open_ids );
                        }
                        foreach ( $ei_open_ids as $ei_id ) {
                            // Read the option straight from the primed meta cache. Building an
                            // Invoice model per row (items, totals) cost ~2 s for 300 options.
                            $invoice_number = (string) get_post_meta( $ei_id, '_easy_invoice_number', true ) ?: 'INV-' . $ei_id;
                            $ei_cached      = get_post_meta( $ei_id, \EasyInvoice\Services\InvoiceTotalsCache::META_TOTAL, true );
                            if ( '' === (string) $ei_cached ) {
                                $ei_model  = new Invoice( $ei_id ); // not backfilled yet: compute once and store
                                $ei_cached = $ei_model->getTotal();
                                \EasyInvoice\Services\InvoiceTotalsCache::store( $ei_model );
                            }
                            $ei_due          = max( 0, (float) $ei_cached - \EasyInvoice\Services\InvoiceBalance::paid( $ei_id ) - \EasyInvoice\Services\InvoiceBalance::credited( $ei_id ) );
                            $ei_currency     = strtoupper( (string) get_post_meta( $ei_id, '_easy_invoice_currency_code', true ) );
                            if ( '' === $ei_currency || 'GLOBAL' === $ei_currency ) {
                                $ei_currency = strtoupper( (string) get_option( 'easy_invoice_currency_code', 'USD' ) );
                            }
                            $currency_symbol = \EasyInvoice\Helpers\CurrencyHelper::getCurrencySymbol( $ei_currency ) ?: get_option( 'easy_invoice_currency_symbol', '$' );
                            $ei_title        = (string) get_post_field( 'post_title', $ei_id );
                            printf(
                                '<option value="%d"%s>%s - %s</option>',
                                (int) $ei_id,
                                selected( $ei_preselect, $ei_id, false ),
                                esc_html( $invoice_number . ( '' !== $ei_title && $ei_title !== $invoice_number ? ' · ' . wp_html_excerpt( $ei_title, 40, '…' ) : '' ) ),
                                esc_html( $currency_symbol . number_format( $ei_due, 2 ) )
                            );
                        }
                        ?>
                    </select>
                </div>

                <div>
                    <label for="payment_method" class="block text-sm font-medium text-gray-700">
                        <?php esc_html_e('Payment Method', 'easy-invoice'); ?> <span class="text-red-500">*</span>
                    </label>
                    <select name="payment_method" id="payment_method" required
                    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">
                        <option value=""><?php esc_html_e('Select Payment Method', 'easy-invoice'); ?></option>
                        <?php
                        // Get available payment gateways (sorted)
                        $gateway_manager = \EasyInvoice\EasyInvoice::getInstance()->getGatewayManager();
                        $enabled_gateways = $gateway_manager->getEnabledGateways();
                        
                        // Show only enabled gateways and manual options
                        // How the money arrived. Cash and cheque are always
                        // possible whether or not a gateway for them is on.
                        $available_methods = [
                            'cash'          => __('Cash', 'easy-invoice'),
                            'cheque'        => __('Cheque', 'easy-invoice'),
                            'bank_transfer' => __('Bank transfer', 'easy-invoice'),
                            'other'         => __('Other', 'easy-invoice'),
                        ];
                        
                        // Add enabled gateways only (already sorted)
                        foreach ($enabled_gateways as $gateway_id => $gateway) {
                            $available_methods[$gateway_id] = $gateway_manager->getGatewayDisplayName($gateway_id);
                        }
                        
                        foreach ($available_methods as $method_id => $method_name) {
                            printf(
                                '<option value="%s">%s</option>',
                                esc_attr($method_id),
                                esc_html($method_name)
                            );
                        }
                        ?>
                    </select>
                </div>

                <div>
                    <label for="amount" class="block text-sm font-medium text-gray-700">
                        <?php esc_html_e('Amount', 'easy-invoice'); ?> <span class="text-red-500">*</span>
                    </label>
                    <div class="mt-1 relative rounded-md shadow-sm">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <span class="text-gray-500 sm:text-sm"><?php echo esc_html(get_option('easy_invoice_currency_symbol', '$')); ?></span>
                        </div>
                        <input type="number" name="amount" id="amount" step="0.01" required
                               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"
                               placeholder="0.00">
                    </div>
                </div>

                <div>
                    <label for="payment_date" class="block text-sm font-medium text-gray-700">
                        <?php esc_html_e('Payment Date', 'easy-invoice'); ?> <span class="text-red-500">*</span>
                    </label>
                    <input type="date" name="payment_date" id="payment_date" 
                           value="<?php echo esc_attr(current_time('Y-m-d')); ?>" required
                           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">
                </div>

                <div class="sm:col-span-2">
                    <label for="notes" class="block text-sm font-medium text-gray-700">
                        <?php esc_html_e('Notes', 'easy-invoice'); ?>
                    </label>
                    <div class="mt-1">
                        <textarea name="notes" id="notes" rows="3"
                                  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"
                                  placeholder="<?php echo esc_js(__('Add any additional notes about this payment...', 'easy-invoice')); ?>"></textarea>
                    </div>
                </div>
            </div>

            <div class="pt-5">
                <div class="flex justify-end">
                    <button type="submit"
                            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">
                        <?php esc_html_e('Add Payment', 'easy-invoice'); ?>
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
jQuery(document).ready(function($) {
    // Filter the (capped) invoice list as the user types.
    var $invoiceOptions = $('#invoice_id option');
    $('#invoice_filter').on('input', function() {
        var q = $(this).val().toLowerCase();
        $invoiceOptions.each(function() { var t = $(this).text().toLowerCase(); $(this).toggle(!q || !this.value || t.indexOf(q) !== -1); });
    });
    // Update amount when invoice is selected
    $('#invoice_id').on('change', function() {
        var selectedOption = $(this).find('option:selected');
        var amount = selectedOption.text().split(' - ')[1];
        if (amount) {
            $('#amount').val(amount.replace(/[^0-9.-]+/g, ''));
        }
    });

    if ($('#invoice_id').val()) { $('#invoice_id').trigger('change'); }

    // Form submission
    $('#new-payment-form').on('submit', function(e) {
        e.preventDefault();
        
        var formData = new FormData(this);
        
        $.ajax({
            url: $(this).attr('action'),
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success: function(response) {
                if (response.success) {
                    window.location.href = '<?php echo esc_url(admin_url('admin.php?page=easy-invoice-payments')); ?>';
                } else {
                    EasyInvoiceToast.error(response.data.message || '<?php echo esc_js(__('An error occurred', 'easy-invoice')); ?>');
                }
            },
            error: function() {
                EasyInvoiceToast.error('<?php echo esc_js(__('An error occurred', 'easy-invoice')); ?>');
            }
        });
    });
});
</script> 
```
