From 90494547c5ca2744d582e4be7e7c2eff396bfeb2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 20 Oct 2020 13:23:48 +1100 Subject: [PATCH] Fix for whitelabel getter --- app/Jobs/User/UserEmailChanged.php | 2 +- app/Models/Client.php | 2 +- app/Services/Credit/ApplyPayment.php | 11 +++++++++-- app/Services/Invoice/AutoBillInvoice.php | 5 ++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php index bed3e12cca..fcb9fc9692 100644 --- a/app/Jobs/User/UserEmailChanged.php +++ b/app/Jobs/User/UserEmailChanged.php @@ -93,7 +93,7 @@ class UserEmailChanged extends BaseMailerJob implements ShouldQueue 'signature' => $this->company->owner()->signature, 'logo' => $this->company->present()->logo(), 'settings' => $this->settings, - 'whitelabel' => $this->client->user->account->isPaid() ? true : false, + 'whitelabel' => $this->company->account->isPaid() ? true : false, ]; } } diff --git a/app/Models/Client.php b/app/Models/Client.php index a97e306d51..afda91176e 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -524,7 +524,7 @@ class Client extends BaseModel implements HasLocalePreference } } - if($this->company->use_credits_payment == 'option' && $this->service()->getCreditBalance() > 0) { + if(($this->company->use_credits_payment == 'option' || $this->company->use_credits_payment == 'always') && $this->service()->getCreditBalance() > 0) { $payment_urls[] = [ 'label' => ctrans('texts.apply_credit'), 'company_gateway_id' => CompanyGateway::GATEWAY_CREDIT, diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index 59e6f0f770..009aeb4d94 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -74,8 +74,15 @@ class ApplyPayment } - $this->applyPaymentToCredit(); - + $this->credit->balance -= $this->amount_applied; + + if((int)$this->credit->balance == 0) + $this->credit->status_id = Credit::STATUS_APPLIED; + else + $this->credit->status_id = Credit::STATUS_PARTIAL; + + $this->credit->save(); + $this->addPaymentToLedger(); return $this->credit; diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 860f49073e..ebaebbaf3c 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -126,7 +126,10 @@ class AutoBillInvoice extends AbstractService { $current_credit = Credit::find($credit['credit_id']); $payment->credits()->attach($current_credit->id, ['amount' => $credit['amount']]); - $this->applyPaymentToCredit($current_credit, $credit['amount']); + + $current_credit->balance -= $credit['amount']; + $current_credit->save(); + // $this->applyPaymentToCredit($current_credit, $credit['amount']); } $payment->ledger()