Преглед на файлове

wip timezone handling

3.x
Andrew Wallo преди 2 месеца
родител
ревизия
c68dd1cc28

+ 5
- 5
app/Models/Accounting/Adjustment.php Целия файл

@@ -126,11 +126,11 @@ class Adjustment extends Model
126 126
 
127 127
     public function calculateNaturalStatus(): AdjustmentStatus
128 128
     {
129
-        if ($this->start_date?->isFuture()) {
129
+        if ($this->start_date?->isAfter(company_now())) {
130 130
             return AdjustmentStatus::Upcoming;
131 131
         }
132 132
 
133
-        if ($this->end_date?->isPast()) {
133
+        if ($this->end_date?->isBefore(company_now())) {
134 134
             return AdjustmentStatus::Expired;
135 135
         }
136 136
 
@@ -144,7 +144,7 @@ class Adjustment extends Model
144 144
         }
145 145
 
146 146
         return $this->update([
147
-            'paused_at' => now(),
147
+            'paused_at' => company_now(),
148 148
             'paused_until' => $untilDate,
149 149
             'status' => AdjustmentStatus::Paused,
150 150
             'status_reason' => $reason,
@@ -172,7 +172,7 @@ class Adjustment extends Model
172 172
         }
173 173
 
174 174
         return $this->update([
175
-            'archived_at' => now(),
175
+            'archived_at' => company_now(),
176 176
             'status' => AdjustmentStatus::Archived,
177 177
             'status_reason' => $reason,
178 178
         ]);
@@ -182,7 +182,7 @@ class Adjustment extends Model
182 182
     {
183 183
         return $this->status === AdjustmentStatus::Paused &&
184 184
             $this->paused_until !== null &&
185
-            $this->paused_until->isPast();
185
+            $this->paused_until->isBefore(company_now());
186 186
     }
187 187
 
188 188
     public function refreshStatus(): bool

+ 3
- 3
app/Models/Accounting/Bill.php Целия файл

@@ -131,7 +131,7 @@ class Bill extends Document
131 131
 
132 132
     public function shouldBeOverdue(): bool
133 133
     {
134
-        return $this->due_date->isBefore(today()) && $this->canBeOverdue();
134
+        return $this->due_date->isBefore(company_today()) && $this->canBeOverdue();
135 135
     }
136 136
 
137 137
     public function wasInitialized(): bool
@@ -426,8 +426,8 @@ class Bill extends Document
426 426
             ->beforeReplicaSaved(function (self $original, self $replica) {
427 427
                 $replica->status = BillStatus::Open;
428 428
                 $replica->bill_number = self::getNextDocumentNumber();
429
-                $replica->date = now();
430
-                $replica->due_date = now()->addDays($original->company->defaultBill->payment_terms->getDays());
429
+                $replica->date = company_today();
430
+                $replica->due_date = company_today()->addDays($original->company->defaultBill->payment_terms->getDays());
431 431
             })
432 432
             ->databaseTransaction()
433 433
             ->after(function (self $original, self $replica) {

+ 11
- 11
app/Models/Accounting/Estimate.php Целия файл

@@ -132,7 +132,7 @@ class Estimate extends Document
132 132
 
133 133
     public function shouldBeExpired(): bool
134 134
     {
135
-        return $this->expiration_date?->isBefore(today()) && $this->canBeExpired();
135
+        return $this->expiration_date?->isBefore(company_today()) && $this->canBeExpired();
136 136
     }
137 137
 
138 138
     public function isDraft(): bool
@@ -257,7 +257,7 @@ class Estimate extends Document
257 257
             throw new \RuntimeException('Estimate is not in draft status.');
258 258
         }
259 259
 
260
-        $approvedAt ??= now();
260
+        $approvedAt ??= company_now();
261 261
 
262 262
         $this->update([
263 263
             'approved_at' => $approvedAt,
@@ -316,7 +316,7 @@ class Estimate extends Document
316 316
 
317 317
     public function markAsSent(?Carbon $sentAt = null): void
318 318
     {
319
-        $sentAt ??= now();
319
+        $sentAt ??= company_now();
320 320
 
321 321
         $this->update([
322 322
             'status' => EstimateStatus::Sent,
@@ -326,7 +326,7 @@ class Estimate extends Document
326 326
 
327 327
     public function markAsViewed(?Carbon $viewedAt = null): void
328 328
     {
329
-        $viewedAt ??= now();
329
+        $viewedAt ??= company_now();
330 330
 
331 331
         $this->update([
332 332
             'status' => EstimateStatus::Viewed,
@@ -357,8 +357,8 @@ class Estimate extends Document
357 357
             ->beforeReplicaSaved(function (self $original, self $replica) {
358 358
                 $replica->status = EstimateStatus::Draft;
359 359
                 $replica->estimate_number = self::getNextDocumentNumber();
360
-                $replica->date = now();
361
-                $replica->expiration_date = now()->addDays($original->company->defaultInvoice->payment_terms->getDays());
360
+                $replica->date = company_today();
361
+                $replica->expiration_date = company_today()->addDays($original->company->defaultInvoice->payment_terms->getDays());
362 362
             })
363 363
             ->databaseTransaction()
364 364
             ->after(function (self $original, self $replica) {
@@ -388,7 +388,7 @@ class Estimate extends Document
388 388
 
389 389
     public function markAsAccepted(?Carbon $acceptedAt = null): void
390 390
     {
391
-        $acceptedAt ??= now();
391
+        $acceptedAt ??= company_now();
392 392
 
393 393
         $this->update([
394 394
             'status' => EstimateStatus::Accepted,
@@ -417,7 +417,7 @@ class Estimate extends Document
417 417
 
418 418
     public function markAsDeclined(?Carbon $declinedAt = null): void
419 419
     {
420
-        $declinedAt ??= now();
420
+        $declinedAt ??= company_now();
421 421
 
422 422
         $this->update([
423 423
             'status' => EstimateStatus::Declined,
@@ -458,8 +458,8 @@ class Estimate extends Document
458 458
             'header' => $this->company->defaultInvoice->header,
459 459
             'subheader' => $this->company->defaultInvoice->subheader,
460 460
             'invoice_number' => Invoice::getNextDocumentNumber($this->company),
461
-            'date' => now(),
462
-            'due_date' => now()->addDays($this->company->defaultInvoice->payment_terms->getDays()),
461
+            'date' => company_today(),
462
+            'due_date' => company_today()->addDays($this->company->defaultInvoice->payment_terms->getDays()),
463 463
             'status' => InvoiceStatus::Draft,
464 464
             'currency_code' => $this->currency_code,
465 465
             'discount_method' => $this->discount_method,
@@ -477,7 +477,7 @@ class Estimate extends Document
477 477
 
478 478
         $this->replicateLineItems($invoice);
479 479
 
480
-        $convertedAt ??= now();
480
+        $convertedAt ??= company_now();
481 481
 
482 482
         $this->update([
483 483
             'status' => EstimateStatus::Converted,

+ 6
- 6
app/Models/Accounting/Invoice.php Целия файл

@@ -206,7 +206,7 @@ class Invoice extends Document
206 206
 
207 207
     public function shouldBeOverdue(): bool
208 208
     {
209
-        return $this->due_date->isBefore(today()) && $this->canBeOverdue();
209
+        return $this->due_date->isBefore(company_today()) && $this->canBeOverdue();
210 210
     }
211 211
 
212 212
     public function isDraft(): bool
@@ -369,7 +369,7 @@ class Invoice extends Document
369 369
 
370 370
         $this->createApprovalTransaction();
371 371
 
372
-        $approvedAt ??= now();
372
+        $approvedAt ??= company_now();
373 373
 
374 374
         $this->update([
375 375
             'approved_at' => $approvedAt,
@@ -613,7 +613,7 @@ class Invoice extends Document
613 613
 
614 614
     public function markAsSent(?Carbon $sentAt = null): void
615 615
     {
616
-        $sentAt ??= now();
616
+        $sentAt ??= company_now();
617 617
 
618 618
         $this->update([
619 619
             'status' => InvoiceStatus::Sent,
@@ -623,7 +623,7 @@ class Invoice extends Document
623 623
 
624 624
     public function markAsViewed(?Carbon $viewedAt = null): void
625 625
     {
626
-        $viewedAt ??= now();
626
+        $viewedAt ??= company_now();
627 627
 
628 628
         $this->update([
629 629
             'status' => InvoiceStatus::Viewed,
@@ -654,8 +654,8 @@ class Invoice extends Document
654 654
             ->beforeReplicaSaved(function (self $original, self $replica) {
655 655
                 $replica->status = InvoiceStatus::Draft;
656 656
                 $replica->invoice_number = self::getNextDocumentNumber();
657
-                $replica->date = now();
658
-                $replica->due_date = now()->addDays($original->company->defaultInvoice->payment_terms->getDays());
657
+                $replica->date = company_today();
658
+                $replica->due_date = company_today()->addDays($original->company->defaultInvoice->payment_terms->getDays());
659 659
             })
660 660
             ->databaseTransaction()
661 661
             ->after(function (self $original, self $replica) {

+ 5
- 5
app/Models/Accounting/RecurringInvoice.php Целия файл

@@ -209,7 +209,7 @@ class RecurringInvoice extends Document
209 209
         }
210 210
 
211 211
         // For unapproved/draft invoices, start date must be today or in the future
212
-        return $this->start_date?->gte(today()) ?? false;
212
+        return $this->start_date?->gte(company_today()) ?? false;
213 213
     }
214 214
 
215 215
     public function getScheduleDescription(): ?string
@@ -402,7 +402,7 @@ class RecurringInvoice extends Document
402 402
                 $data = $record->attributesToArray();
403 403
 
404 404
                 $data['day_of_month'] ??= DayOfMonth::First;
405
-                $data['start_date'] ??= now()->addMonth()->startOfMonth();
405
+                $data['start_date'] ??= company_today()->addMonth()->startOfMonth();
406 406
 
407 407
                 $form->fill($data);
408 408
             })
@@ -507,7 +507,7 @@ class RecurringInvoice extends Document
507 507
                             ->label('First invoice date')
508 508
                             ->softRequired()
509 509
                             ->live()
510
-                            ->minDate(today())
510
+                            ->minDate(company_today())
511 511
                             ->timezone(CompanySettingsService::getDefaultTimezone())
512 512
                             ->closeOnDateSelection()
513 513
                             ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
@@ -527,7 +527,7 @@ class RecurringInvoice extends Document
527 527
                                     $endType = EndType::parse($state);
528 528
 
529 529
                                     $set('max_occurrences', $endType?->isAfter() ? 1 : null);
530
-                                    $set('end_date', $endType?->isOn() ? now()->addMonth()->startOfMonth() : null);
530
+                                    $set('end_date', $endType?->isOn() ? company_today()->addMonth()->startOfMonth() : null);
531 531
                                 });
532 532
 
533 533
                             $endType = EndType::parse($get('end_type'));
@@ -606,7 +606,7 @@ class RecurringInvoice extends Document
606 606
             throw new \RuntimeException('Invoice is not in draft status.');
607 607
         }
608 608
 
609
-        $approvedAt ??= now();
609
+        $approvedAt ??= company_now();
610 610
 
611 611
         $this->update([
612 612
             'approved_at' => $approvedAt,

Loading…
Отказ
Запис