From 27f678bd8c1f89edc20ff1c7728ef3a34df90da1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 15 Oct 2020 15:07:42 +1100 Subject: [PATCH] working on credit payments --- app/Models/Client.php | 2 +- app/Services/Credit/ApplyPayment.php | 6 +++--- app/Services/Invoice/AutoBillInvoice.php | 2 +- .../2020_10_14_201320_project_ids_to_entities.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index b2a0d8dfd093..a97e306d51c7 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_credit_payment = 'optin' && $this->service()->getCreditBalance() > 0) { + if($this->company->use_credits_payment == 'option' && $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 e9a5665e5f39..59e6f0f770aa 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -47,6 +47,7 @@ class ApplyPayment //$available_credit_balance = $this->credit->balance; $applicable_amount = min($this->amount, $this->credit->balance); $invoice_balance = $this->invoice->balance; + $credit_balance = $this->credit->balance; /* Check invoice partial for amount to be cleared first */ if($this->invoice->partial > 0){ @@ -56,7 +57,7 @@ class ApplyPayment $this->invoice->partial -= $partial_payment; $invoice_balance -= $partial_payment; $this->amount -= $partial_payment; - // $this->credit->balance -= $partial_payment; + $credit_balance -= $partial_payment; $applicable_amount -= $partial_payment; $this->amount_applied += $partial_payment; @@ -65,11 +66,10 @@ class ApplyPayment /* If there is remaining amount use it on the balance */ if($this->amount > 0 && $applicable_amount > 0 && $invoice_balance > 0){ - $balance_payment = min($invoice_balance, $this->amount); + $balance_payment = min($invoice_balance, min($this->amount, $credit_balance)); $invoice_balance -= $balance_payment; $this->amount -= $balance_payment; - // $this->credit->balance -= $balance_payment; $this->amount_applied += $balance_payment; } diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 9c53612e7f7c..860f49073e7a 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -56,7 +56,7 @@ class AutoBillInvoice extends AbstractService //if the credits cover the payments, we stop here, build the payment with credits and exit early - if($this->invoice->company->use_credits_payment == 'always' || $this->invoice->company->use_credits_payment == 'optin') + if($this->invoice->company->use_credits_payment == 'always' || $this->invoice->company->use_credits_payment == 'option') $this->applyCreditPayment(); info("partial = {$this->invoice->partial}"); diff --git a/database/migrations/2020_10_14_201320_project_ids_to_entities.php b/database/migrations/2020_10_14_201320_project_ids_to_entities.php index 5b61a0a911fe..f203b9de1bea 100644 --- a/database/migrations/2020_10_14_201320_project_ids_to_entities.php +++ b/database/migrations/2020_10_14_201320_project_ids_to_entities.php @@ -24,7 +24,7 @@ class ProjectIdsToEntities extends Migration Schema::table('companies', function (Blueprint $table) { $table->boolean('mark_expenses_invoiceable')->default(0); $table->boolean('mark_expenses_paid')->default(0); - $table->enum('use_credits_payment', ['always', 'off', 'optin'])->nullable(); + $table->enum('use_credits_payment', ['always', 'off', 'option'])->default('off'); });