Browse Source

wip timezone handling

3.x
Andrew Wallo 2 months ago
parent
commit
a146271f4c

+ 5
- 5
app/Models/Accounting/Budget.php View File

@@ -154,14 +154,14 @@ class Budget extends Model
154 154
     public function scopeCurrentlyActive(Builder $query): Builder
155 155
     {
156 156
         return $query->active()
157
-            ->where('start_date', '<=', now())
158
-            ->where('end_date', '>=', now());
157
+            ->where('start_date', '<=', company_now())
158
+            ->where('end_date', '>=', company_now());
159 159
     }
160 160
 
161 161
     protected function isCurrentlyInPeriod(): Attribute
162 162
     {
163 163
         return Attribute::get(function () {
164
-            return now()->between($this->start_date, $this->end_date);
164
+            return company_now()->between($this->start_date, $this->end_date);
165 165
         });
166 166
     }
167 167
 
@@ -174,7 +174,7 @@ class Budget extends Model
174 174
             throw new \RuntimeException('Budget cannot be approved.');
175 175
         }
176 176
 
177
-        $approvedAt ??= now();
177
+        $approvedAt ??= company_now();
178 178
 
179 179
         $this->update([
180 180
             'status' => BudgetStatus::Active,
@@ -191,7 +191,7 @@ class Budget extends Model
191 191
             throw new \RuntimeException('Budget cannot be closed.');
192 192
         }
193 193
 
194
-        $closedAt ??= now();
194
+        $closedAt ??= company_now();
195 195
 
196 196
         $this->update([
197 197
             'status' => BudgetStatus::Closed,

+ 1
- 1
app/Models/Accounting/BudgetAllocation.php View File

@@ -38,6 +38,6 @@ class BudgetAllocation extends Model
38 38
 
39 39
     public function isCurrentPeriod(): bool
40 40
     {
41
-        return now()->between($this->start_date, $this->end_date);
41
+        return company_now()->between($this->start_date, $this->end_date);
42 42
     }
43 43
 }

+ 1
- 1
app/Models/Accounting/RecurringInvoice.php View File

@@ -693,7 +693,7 @@ class RecurringInvoice extends Document
693 693
 
694 694
         $nextDate = $this->calculateNextDate();
695 695
 
696
-        if (! $nextDate || $nextDate->startOfDay()->isFuture()) {
696
+        if (! $nextDate || $nextDate->startOfDay()->isAfter(company_now())) {
697 697
             return false;
698 698
         }
699 699
 

+ 2
- 2
app/Models/Setting/Localization.php View File

@@ -63,7 +63,7 @@ class Localization extends Model
63 63
     public static function getWeekStart(string $locale): int
64 64
     {
65 65
         /** @var Carbon $date */
66
-        $date = now()->locale($locale);
66
+        $date = company_now()->locale($locale);
67 67
 
68 68
         $firstDay = $date->startOfWeek()->dayOfWeekIso;
69 69
 
@@ -91,7 +91,7 @@ class Localization extends Model
91 91
     public function fiscalYearEndDate(): string
92 92
     {
93 93
         return once(function () {
94
-            $today = now();
94
+            $today = company_now();
95 95
             $fiscalYearEndThisYear = Carbon::createFromDate($today->year, $this->fiscal_year_end_month, $this->fiscal_year_end_day);
96 96
 
97 97
             if ($today->gt($fiscalYearEndThisYear)) {

+ 1
- 1
app/Observers/AdjustmentObserver.php View File

@@ -78,7 +78,7 @@ class AdjustmentObserver
78 78
 
79 79
         // Ensure consistency between paused status and paused_at field
80 80
         if ($adjustment->status === AdjustmentStatus::Paused && ! $adjustment->paused_at) {
81
-            $adjustment->paused_at = now();
81
+            $adjustment->paused_at = company_now();
82 82
         }
83 83
     }
84 84
 }

+ 1
- 1
app/Observers/RecurringInvoiceObserver.php View File

@@ -20,7 +20,7 @@ class RecurringInvoiceObserver
20 20
 
21 21
         if ($recurringInvoice->end_type?->isAfter() && $recurringInvoice->occurrences_count >= $recurringInvoice->max_occurrences) {
22 22
             $recurringInvoice->status = RecurringInvoiceStatus::Ended;
23
-            $recurringInvoice->ended_at = now();
23
+            $recurringInvoice->ended_at = company_now();
24 24
         }
25 25
     }
26 26
 

Loading…
Cancel
Save