From 496da291d8ffb11b80dbd0501a1054a5f34c5ab8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Aug 2022 16:08:30 +1000 Subject: [PATCH] Prevent negative credits from being applied as payments to a invoice --- app/Http/ValidationRules/Credit/ValidCreditsRules.php | 9 +++++++++ app/Services/ClientPortal/InstantPayment.php | 2 ++ 2 files changed, 11 insertions(+) diff --git a/app/Http/ValidationRules/Credit/ValidCreditsRules.php b/app/Http/ValidationRules/Credit/ValidCreditsRules.php index f745092fe967..b8d6d2624ed8 100644 --- a/app/Http/ValidationRules/Credit/ValidCreditsRules.php +++ b/app/Http/ValidationRules/Credit/ValidCreditsRules.php @@ -51,6 +51,15 @@ class ValidCreditsRules implements Rule $unique_array = []; + $total_credit_amount = array_sum(array_column($this->input['credits'], 'amount')); + + if($total_credit_amount <= 0){ + + $this->error_msg = "Total of credits must be more than zero."; + + return false; + } + $cred_collection = Credit::withTrashed()->whereIn('id', array_column($this->input['credits'], 'credit_id'))->get(); foreach ($this->input['credits'] as $credit) { diff --git a/app/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index 9ab3dc581e1e..9d03393b2e59 100644 --- a/app/Services/ClientPortal/InstantPayment.php +++ b/app/Services/ClientPortal/InstantPayment.php @@ -48,6 +48,7 @@ class InstantPayment public function run() { + $is_credit_payment = false; $tokens = []; @@ -107,6 +108,7 @@ class InstantPayment $payable_amount = Number::roundValue(Number::parseFloat($payable_invoice['amount'], $client->currency()->precision)); $invoice_balance = Number::roundValue(($invoice->partial > 0 ? $invoice->partial : $invoice->balance), $client->currency()->precision); + /*If we don't allow under/over payments force the payable amount - prevents inspect element adjustments in JS*/ if ($settings->client_portal_allow_under_payment == false && $settings->client_portal_allow_over_payment == false) {