diff --git a/app/Livewire/Flow2/UnderOverPayment.php b/app/Livewire/Flow2/UnderOverPayment.php index 2ae720ed19fa..2106f3321635 100644 --- a/app/Livewire/Flow2/UnderOverPayment.php +++ b/app/Livewire/Flow2/UnderOverPayment.php @@ -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() diff --git a/app/Livewire/InvoicePay.php b/app/Livewire/InvoicePay.php index 4d0539bddc59..5bcb8ded0f61 100644 --- a/app/Livewire/InvoicePay.php +++ b/app/Livewire/InvoicePay.php @@ -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; } diff --git a/resources/views/portal/ninja2020/components/livewire/under-over-payments.blade.php b/resources/views/portal/ninja2020/components/livewire/under-over-payments.blade.php index 6001075a453e..45e9019adaa8 100644 --- a/resources/views/portal/ninja2020/components/livewire/under-over-payments.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/under-over-payments.blade.php @@ -1,4 +1,4 @@ -