diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 4c2788908b9a..75769fda1a5f 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -93,7 +93,7 @@ class StorePaymentRequest extends Request } if (! isset($input['date'])) { - $input['date'] = now()->addSeconds($user->company()->timezone()->utc_offset)->format('Y-m-d'); + $input['date'] = now()->addSeconds($user->company()->utc_offset())->format('Y-m-d'); } if (! isset($input['idempotency_key'])) { diff --git a/app/Models/Client.php b/app/Models/Client.php index bb83e7297552..c5e41724cf8d 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -776,14 +776,8 @@ class Client extends BaseModel implements HasLocalePreference return 0; } - $timezone = $this->company->timezone(); + $offset -= $this->company->utc_offset(); - //2023-11-08 adjustments for DST - date_default_timezone_set('GMT'); - $date = new \DateTime("now", new \DateTimeZone($timezone->name)); - $offset -= $date->getOffset(); - -// $offset -= $timezone->utc_offset; $offset += ($entity_send_time * 3600); return $offset; diff --git a/app/Models/Company.php b/app/Models/Company.php index 2f10c9d9ae2a..9ab2e5a280a7 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -911,9 +911,14 @@ class Company extends BaseModel public function utc_offset(): int { + $offset = 0; $timezone = $this->timezone(); - return $timezone->utc_offset ?? 0; + date_default_timezone_set('GMT'); + $date = new \DateTime("now", new \DateTimeZone($timezone->name)); + $offset = $date->getOffset(); + + return $offset; } public function timezone_offset(): int diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index d1e2eddc6ec3..6bba73c0cb67 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -325,7 +325,7 @@ class BaseDriver extends AbstractPaymentDriver $payment->company_gateway_id = $this->company_gateway->id; $payment->status_id = $status; $payment->currency_id = $this->client->getSetting('currency_id'); - $payment->date = Carbon::now()->addSeconds($this->client->company->timezone()->utc_offset)->format('Y-m-d'); + $payment->date = Carbon::now()->addSeconds($this->client->company->utc_offset())->format('Y-m-d'); $payment->gateway_type_id = $data['gateway_type_id']; $client_contact = $this->getContact(); diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index a6c5bbcdef69..d96efd669705 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -119,7 +119,7 @@ class CreditService $payment->type_id = PaymentType::CREDIT; $payment->is_manual = true; $payment->currency_id = $this->credit->client->getSetting('currency_id'); - $payment->date = now()->addSeconds($this->credit->company->timezone()->utc_offset)->format('Y-m-d'); + $payment->date = now()->addSeconds($this->credit->company->utc_offset())->format('Y-m-d'); $payment->saveQuietly(); $payment->number = $payment->client->getNextPaymentNumber($payment->client, $payment); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 1464d3f0dbff..1d9aaf7d4f9a 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -182,7 +182,7 @@ class AutoBillInvoice extends AbstractService // $payment->applied = $amount; $payment->client_id = $this->invoice->client_id; $payment->currency_id = $this->invoice->client->getSetting('currency_id'); - $payment->date = now()->addSeconds($this->invoice->company->timezone()->utc_offset)->format('Y-m-d'); + $payment->date = now()->addSeconds($this->invoice->company->utc_offset())->format('Y-m-d'); $payment->status_id = Payment::STATUS_COMPLETED; $payment->type_id = PaymentType::CREDIT; $payment->service()->applyNumber()->save(); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 8899377af7a4..3ecd0acb1d0b 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -72,7 +72,7 @@ class MarkPaid extends AbstractService $payment->is_manual = true; if ($this->invoice->company->timezone()) { - $payment->date = now()->addSeconds($this->invoice->company->timezone()->utc_offset)->format('Y-m-d'); + $payment->date = now()->addSeconds($this->invoice->company->utc_offset())->format('Y-m-d'); } $payment_type_id = $this->invoice->client->getSetting('payment_type_id');