diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php index bed3e12cca47..fcb9fc969253 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 a97e306d51c7..afda91176ea4 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 59e6f0f770aa..009aeb4d94b1 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 860f49073e7a..ebaebbaf3cdf 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()