mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
improvements for validation of over/under payments
This commit is contained in:
parent
aa5695ac45
commit
73c1f1b767
@ -24,12 +24,43 @@ class UnderOverPayment extends Component
|
||||
|
||||
public $currency;
|
||||
|
||||
public $invoice_amount;
|
||||
|
||||
public $errors = '';
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$invoice = $this->context['invoice'];
|
||||
$invoice_amount = $invoice->partial > 0 ? $invoice->partial : $invoice->balance;
|
||||
$this->invoice_amount = $invoice->partial > 0 ? $invoice->partial : $invoice->balance;
|
||||
$this->currency = $invoice->client->currency();
|
||||
$this->payableAmount = Number::formatValue($invoice_amount, $this->currency);
|
||||
$this->payableAmount = Number::formatValue($this->invoice_amount, $this->currency);
|
||||
}
|
||||
|
||||
public function checkValue($value)
|
||||
{
|
||||
|
||||
$this->errors = '';
|
||||
|
||||
$settings = $this->context['settings'];
|
||||
$input_amount = Number::parseFloat($value);
|
||||
|
||||
if($settings->client_portal_allow_under_payment && $settings->client_portal_under_payment_minimum != 0)
|
||||
{
|
||||
if($input_amount <= $settings->client_portal_under_payment_minimum){
|
||||
// return error message under payment too low.
|
||||
$this->errors = ctrans('texts.minimum_required_payment', ['amount' => $settings->client_portal_under_payment_minimum]);
|
||||
$this->dispatch('errorMessageUpdate', errors: $this->errors);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$settings->client_portal_allow_over_payment && ($input_amount > $this->invoice_amount)){
|
||||
$this->errors = ctrans('texts.over_payments_disabled');
|
||||
$this->dispatch('errorMessageUpdate', errors: $this->errors);
|
||||
|
||||
}
|
||||
|
||||
if(!$this->errors)
|
||||
$this->dispatch('payable-amount', payable_amount: $value );
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
@ -43,8 +43,6 @@ class InvoicePay extends Component
|
||||
|
||||
public $required_fields = false;
|
||||
|
||||
public $ready = true;
|
||||
|
||||
public array $context = [];
|
||||
|
||||
#[On('update.context')]
|
||||
@ -122,7 +120,6 @@ class InvoicePay extends Component
|
||||
|
||||
// if($this->ready)
|
||||
|
||||
nlog("computed");
|
||||
|
||||
return ProcessPayment::class;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div x-data="{ payableAmount: '{{ $payableAmount }}' }" class="px-4 py-5 bg-white sm:gap-4 sm:px-6">
|
||||
<div x-data="{ payableAmount: '{{ $payableAmount }}', errors: @entangle('errors') }" class="px-4 py-5 bg-white sm:gap-4 sm:px-6">
|
||||
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.payment_amount') }}
|
||||
@ -17,6 +17,10 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<template x-if="errors.length > 0">
|
||||
<div x-text="errors" class="alert alert-failure mb-4"></div>
|
||||
</template>
|
||||
|
||||
@if($settings->client_portal_allow_under_payment)
|
||||
<span class="mt-1 text-sm text-gray-800">{{ ctrans('texts.minimum_payment') }}: {{ $settings->client_portal_under_payment_minimum }}</span>
|
||||
@endif
|
||||
@ -25,7 +29,7 @@
|
||||
<div class="bg-white px-4 py-5 flex w-full justify-end">
|
||||
<button
|
||||
class="button button-primary bg-primary payment-method flex items-center justify-center relative py-4"
|
||||
@click="$wire.dispatch('payable-amount', { payable_amount: payableAmount })">
|
||||
wire:click="checkValue(payableAmount)">
|
||||
<svg class="animate-spin h-5 w-5 text-white hidden" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
@ -33,5 +37,4 @@
|
||||
<span>{{ ctrans('texts.next') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user