Fixes for due date days calculations

This commit is contained in:
David Bomba 2025-01-23 13:03:13 +11:00
parent f223a84af2
commit 57d3d9211c
2 changed files with 9 additions and 4 deletions

View File

@ -62,9 +62,12 @@ class SendRecurring implements ShouldQueue
// Generate Standard Invoice // Generate Standard Invoice
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client); $invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client);
// $date = now()->addSeconds($this->recurring_invoice->client->timezone_offset())->format('Y-m-d'); Rev 1
$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. Rev 2.
// $date = date('Y-m-d'); //@todo this will always pull UTC date. // 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; $invoice->date = $date;
nlog("Recurring Invoice Date Set on Invoice = {$invoice->date} - ". now()->format('Y-m-d')); nlog("Recurring Invoice Date Set on Invoice = {$invoice->date} - ". now()->format('Y-m-d'));

View File

@ -745,7 +745,9 @@ class RecurringInvoice extends BaseModel
default: 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 = now()->addSeconds($this->client->timezone_offset());
//$date = Carbon::parse($date)->addSeconds($this->client->timezone_offset()); //$date = Carbon::parse($date)->addSeconds($this->client->timezone_offset());
return $this->setDayOfMonth($date, $this->due_date_days); return $this->setDayOfMonth($date, $this->due_date_days);