From cecee6cbfe58fcaadf8960f610a25259a7c93f6d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 24 Jan 2021 20:28:18 +1100 Subject: [PATCH] Fixes for tests --- app/Jobs/Credit/ApplyCreditPayment.php | 4 ++-- app/Services/Credit/ApplyPayment.php | 1 + app/Services/Invoice/AutoBillInvoice.php | 20 +++++++------------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/Jobs/Credit/ApplyCreditPayment.php b/app/Jobs/Credit/ApplyCreditPayment.php index 8f8f6b526a9c..ae85e94515ea 100644 --- a/app/Jobs/Credit/ApplyCreditPayment.php +++ b/app/Jobs/Credit/ApplyCreditPayment.php @@ -70,7 +70,7 @@ class ApplyCreditPayment implements ShouldQueue $this->credit ->service() ->setStatus(Credit::STATUS_APPLIED) - ->updateBalance($this->amount * -1) + ->adjustBalance($this->amount * -1) ->updatePaidToDate($this->amount) ->save(); @@ -79,7 +79,7 @@ class ApplyCreditPayment implements ShouldQueue $this->credit ->service() ->setStatus(Credit::STATUS_PARTIAL) - ->updateBalance($this->amount * -1) + ->adjustBalance($this->amount * -1) ->updatePaidToDate($this->amount) ->save(); } diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index 6acbefdd583b..c69dcf1b8589 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -136,6 +136,7 @@ class ApplyPayment $this->invoice ->service() ->updateBalance($this->amount_applied * -1) + ->updatePaidToDate($this->amount_applied) ->updateStatus() ->save(); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 204d997a1312..7641f6caad30 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -49,15 +49,12 @@ class AutoBillInvoice extends AbstractService $this->invoice = $this->invoice->service()->markSent()->save(); /* Mark the invoice as paid if there is no balance */ - if ((int)$this->invoice->balance == 0) { + if ((int)$this->invoice->balance == 0) return $this->invoice->service()->markPaid()->save(); - } - + //if the credits cover the payments, we stop here, build the payment with credits and exit early - - if ($this->client->getSetting('use_credits_payment') != 'off') { + if ($this->client->getSetting('use_credits_payment') != 'off') $this->applyCreditPayment(); - } /* Determine $amount */ if ($this->invoice->partial > 0) { @@ -73,15 +70,12 @@ class AutoBillInvoice extends AbstractService $gateway_token = $this->getGateway($amount); /* Bail out if no payment methods available */ - if (! $gateway_token || ! $gateway_token->gateway->driver($this->client)->token_billing) { + if (! $gateway_token || ! $gateway_token->gateway->driver($this->client)->token_billing) return $this->invoice; - } - + /* $gateway fee */ $fee = $gateway_token->gateway->calcGatewayFee($amount, $gateway_token->gateway_type_id, $this->invoice->uses_inclusive_taxes); - //todo determine exact fee as per PaymentController - /* Build payment hash */ $payment_hash = PaymentHash::create([ 'hash' => Str::random(128), @@ -196,7 +190,7 @@ class AutoBillInvoice extends AbstractService if ($is_partial_amount) { //more credit than needed - if ($credit->balance >= $this->invoice->partial) { + if ($credit->balance > $this->invoice->partial) { $this->used_credit[$key]['credit_id'] = $credit->id; $this->used_credit[$key]['amount'] = $this->invoice->partial; $this->invoice->balance -= $this->invoice->partial; @@ -213,7 +207,7 @@ class AutoBillInvoice extends AbstractService } else { //more credit than needed - if ($credit->balance >= $this->invoice->balance) { + if ($credit->balance > $this->invoice->balance) { $this->used_credit[$key]['credit_id'] = $credit->id; $this->used_credit[$key]['amount'] = $this->invoice->balance; $this->invoice->paid_to_date += $this->invoice->balance;