From 8f5fb2ca9fc0fb606411777a3b4810047dac8f52 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 24 Nov 2022 17:23:36 +1100 Subject: [PATCH] Fixes for recurring invoice edge case --- app/Jobs/Util/ReminderJob.php | 2 +- app/Models/Company.php | 1 + app/Models/PurchaseOrder.php | 3 ++- app/Services/Client/ClientService.php | 3 --- app/Services/Invoice/InvoiceService.php | 2 +- app/Transformers/CompanyTransformer.php | 1 + app/Transformers/PurchaseOrderTransformer.php | 1 + .../2022_11_22_215618_lock_tasks_when_invoiced.php | 6 ++++++ 8 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 23875c3f6c..90dd5e35fe 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -215,7 +215,7 @@ class ReminderJob implements ShouldQueue $client = $client->fresh(); nlog('adjusting client balance and invoice balance by #'.$invoice->number.' '.($invoice->balance - $temp_invoice_balance)); - $client->service()->updateBalance($invoice->balance - $temp_invoice_balance)->save(); + $client->service()->updateBalance($invoice->balance - $temp_invoice_balance); $invoice->ledger()->updateInvoiceBalance($invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$invoice->number}"); $transaction = [ diff --git a/app/Models/Company.php b/app/Models/Company.php index 407cdb5ce8..37d4814e4d 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -125,6 +125,7 @@ class Company extends BaseModel 'invoice_task_project', 'report_include_deleted', 'invoice_task_lock', + 'use_vendor_currency', ]; protected $hidden = [ diff --git a/app/Models/PurchaseOrder.php b/app/Models/PurchaseOrder.php index 851822e098..5ef33b62dc 100644 --- a/app/Models/PurchaseOrder.php +++ b/app/Models/PurchaseOrder.php @@ -79,7 +79,8 @@ class PurchaseOrder extends BaseModel 'partial', 'paid_to_date', 'vendor_id', - 'last_viewed' + 'last_viewed', + 'currency_id', ]; protected $casts = [ diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index a4d033c345..6ffec56c20 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -29,7 +29,6 @@ class ClientService public function updateBalance(float $amount) { - // $this->client->balance += $amount; \DB::connection(config('database.default'))->transaction(function () use($amount) { @@ -44,8 +43,6 @@ class ClientService public function updateBalanceAndPaidToDate(float $balance, float $paid_to_date) { - // $this->client->balance += $amount; - // $this->client->paid_to_date += $amount; \DB::connection(config('database.default'))->transaction(function () use($balance, $paid_to_date) { diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 0717804d70..9a0efc7347 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -117,7 +117,7 @@ class InvoiceService public function applyPayment(Payment $payment, float $payment_amount) { // $this->deletePdf(); - $this->invoice = $this->markSent(); + $this->invoice = $this->markSent()->save(); $this->invoice = (new ApplyPayment($this->invoice, $payment, $payment_amount))->run(); diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 0651bc1eb7..1b47cdbd5b 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -189,6 +189,7 @@ class CompanyTransformer extends EntityTransformer 'invoice_task_project' => (bool) $company->invoice_task_project, 'report_include_deleted' => (bool) $company->report_include_deleted, 'invoice_task_lock' => (bool) $company->invoice_task_lock, + 'use_vendor_currency' => (bool) $company->use_vendor_currency, ]; } diff --git a/app/Transformers/PurchaseOrderTransformer.php b/app/Transformers/PurchaseOrderTransformer.php index fd0684c76c..d444addf07 100644 --- a/app/Transformers/PurchaseOrderTransformer.php +++ b/app/Transformers/PurchaseOrderTransformer.php @@ -132,6 +132,7 @@ class PurchaseOrderTransformer extends EntityTransformer 'paid_to_date' => (float)$purchase_order->paid_to_date, 'subscription_id' => $this->encodePrimaryKey($purchase_order->subscription_id), 'expense_id' => $this->encodePrimaryKey($purchase_order->expense_id), + 'currency_id' => $purchase_order->currency_id ? (string) $purchase_order->currency_id : '', ]; } diff --git a/database/migrations/2022_11_22_215618_lock_tasks_when_invoiced.php b/database/migrations/2022_11_22_215618_lock_tasks_when_invoiced.php index 00c1925cb0..30bb7f5726 100644 --- a/database/migrations/2022_11_22_215618_lock_tasks_when_invoiced.php +++ b/database/migrations/2022_11_22_215618_lock_tasks_when_invoiced.php @@ -22,6 +22,12 @@ return new class extends Migration Schema::table('companies', function (Blueprint $table) { $table->boolean('invoice_task_lock')->default(false); + $table->boolean('use_vendor_currency')->default(false); + }); + + Schema::table('purchase_orders', function (Blueprint $table) + { + $table->unsignedInteger('currency_id')->nullable(); }); Schema::table('bank_transactions', function (Blueprint $table)