From 57d3d9211c67e19d2d91409091bd22ff257f7db9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 23 Jan 2025 13:03:13 +1100 Subject: [PATCH] Fixes for due date days calculations --- app/Jobs/RecurringInvoice/SendRecurring.php | 9 ++++++--- app/Models/RecurringInvoice.php | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 3896876d61..39323c7e35 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -61,10 +61,13 @@ class SendRecurring implements ShouldQueue { // Generate Standard Invoice $invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client); - - $date = now()->addSeconds($this->recurring_invoice->client->timezone_offset())->format('Y-m-d'); - // $date = date('Y-m-d'); //@todo this will always pull UTC date. + // $date = now()->addSeconds($this->recurring_invoice->client->timezone_offset())->format('Y-m-d'); Rev 1 + // $date = date('Y-m-d'); //@todo this will always pull UTC date. Rev 2. + // 2025-01-23 - We need to know the current date in the users timezone, as we send recurring invoices around the + // clock the actual date is not always the same as the UTC date. + // be _very_ careful with this, as it will change the due date of the invoice. + $date = now()->setTimezone($this->recurring_invoice->client->timezone()->name)->format('Y-m-d'); $invoice->date = $date; nlog("Recurring Invoice Date Set on Invoice = {$invoice->date} - ". now()->format('Y-m-d')); diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 171a95c938..e755bd2ed1 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -745,7 +745,9 @@ class RecurringInvoice extends BaseModel default: - $date = Carbon::parse($date); + // 2025-01-23 - Reverting this back, this is tightly linked to recurring invoice generation and + // the timezone offset of the client AND when it was generated. + $date = Carbon::parse($date); // $date = now()->addSeconds($this->client->timezone_offset()); //$date = Carbon::parse($date)->addSeconds($this->client->timezone_offset()); return $this->setDayOfMonth($date, $this->due_date_days);