浏览代码

wip timezone handling

3.x
Andrew Wallo 2 个月前
父节点
当前提交
c68dd1cc28

+ 5
- 5
app/Models/Accounting/Adjustment.php 查看文件

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

+ 3
- 3
app/Models/Accounting/Bill.php 查看文件

131
 
131
 
132
     public function shouldBeOverdue(): bool
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
     public function wasInitialized(): bool
137
     public function wasInitialized(): bool
426
             ->beforeReplicaSaved(function (self $original, self $replica) {
426
             ->beforeReplicaSaved(function (self $original, self $replica) {
427
                 $replica->status = BillStatus::Open;
427
                 $replica->status = BillStatus::Open;
428
                 $replica->bill_number = self::getNextDocumentNumber();
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
             ->databaseTransaction()
432
             ->databaseTransaction()
433
             ->after(function (self $original, self $replica) {
433
             ->after(function (self $original, self $replica) {

+ 11
- 11
app/Models/Accounting/Estimate.php 查看文件

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

+ 6
- 6
app/Models/Accounting/Invoice.php 查看文件

206
 
206
 
207
     public function shouldBeOverdue(): bool
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
     public function isDraft(): bool
212
     public function isDraft(): bool
369
 
369
 
370
         $this->createApprovalTransaction();
370
         $this->createApprovalTransaction();
371
 
371
 
372
-        $approvedAt ??= now();
372
+        $approvedAt ??= company_now();
373
 
373
 
374
         $this->update([
374
         $this->update([
375
             'approved_at' => $approvedAt,
375
             'approved_at' => $approvedAt,
613
 
613
 
614
     public function markAsSent(?Carbon $sentAt = null): void
614
     public function markAsSent(?Carbon $sentAt = null): void
615
     {
615
     {
616
-        $sentAt ??= now();
616
+        $sentAt ??= company_now();
617
 
617
 
618
         $this->update([
618
         $this->update([
619
             'status' => InvoiceStatus::Sent,
619
             'status' => InvoiceStatus::Sent,
623
 
623
 
624
     public function markAsViewed(?Carbon $viewedAt = null): void
624
     public function markAsViewed(?Carbon $viewedAt = null): void
625
     {
625
     {
626
-        $viewedAt ??= now();
626
+        $viewedAt ??= company_now();
627
 
627
 
628
         $this->update([
628
         $this->update([
629
             'status' => InvoiceStatus::Viewed,
629
             'status' => InvoiceStatus::Viewed,
654
             ->beforeReplicaSaved(function (self $original, self $replica) {
654
             ->beforeReplicaSaved(function (self $original, self $replica) {
655
                 $replica->status = InvoiceStatus::Draft;
655
                 $replica->status = InvoiceStatus::Draft;
656
                 $replica->invoice_number = self::getNextDocumentNumber();
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
             ->databaseTransaction()
660
             ->databaseTransaction()
661
             ->after(function (self $original, self $replica) {
661
             ->after(function (self $original, self $replica) {

+ 5
- 5
app/Models/Accounting/RecurringInvoice.php 查看文件

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

正在加载...
取消
保存