From bbcbfe9821777329fc76851bc7b62f9028764839 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 8 Mar 2024 08:16:39 +1100 Subject: [PATCH] Fixes for recurring invoices - restarting completed recurring invoices --- app/Console/Commands/CheckData.php | 2 +- app/Models/RecurringInvoice.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index b843f33cb9e4..2941f2223d5a 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -884,7 +884,7 @@ class CheckData extends Command public function checkClientSettings() { if ($this->option('fix') == 'true') { - Client::query()->whereNull('country_id')->cursor()->each(function ($client) { + Client::query()->whereNull('country_id')->orWhere('country_id', 0)->cursor()->each(function ($client) { $client->country_id = $client->company->settings->country_id; $client->saveQuietly(); diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index a29e9f4023b6..0dd433c6be72 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -355,11 +355,13 @@ class RecurringInvoice extends BaseModel public function calculateStatus(bool $new_model = false) //15-02-2024 - $new_model needed { - if($this->remaining_cycles == 0) { + if($this->remaining_cycles == 0) return self::STATUS_COMPLETED; - } elseif ($new_model && $this->status_id == self::STATUS_ACTIVE && Carbon::parse($this->next_send_date)->isFuture()) + elseif ($new_model && $this->status_id == self::STATUS_ACTIVE && Carbon::parse($this->next_send_date)->isFuture()) return self::STATUS_PENDING; - + elseif($this->remaining_cycles != 0) + return self::STATUS_ACTIVE; + return $this->status_id; }