Andrew Wallo 4 个月前
父节点
当前提交
4c72c999ad

+ 1
- 1
app/Filament/Company/Resources/Purchases/BillResource.php 查看文件

152
                                         $date = $get('date');
152
                                         $date = $get('date');
153
                                         $paymentTerms = $get('payment_terms');
153
                                         $paymentTerms = $get('payment_terms');
154
 
154
 
155
-                                        if (! $date || $paymentTerms === 'custom') {
155
+                                        if (! $date || $paymentTerms === 'custom' || ! $paymentTerms) {
156
                                             return;
156
                                             return;
157
                                         }
157
                                         }
158
 
158
 

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

23
 use Illuminate\Database\Eloquent\Attributes\CollectedBy;
23
 use Illuminate\Database\Eloquent\Attributes\CollectedBy;
24
 use Illuminate\Database\Eloquent\Attributes\ObservedBy;
24
 use Illuminate\Database\Eloquent\Attributes\ObservedBy;
25
 use Illuminate\Database\Eloquent\Builder;
25
 use Illuminate\Database\Eloquent\Builder;
26
-use Illuminate\Database\Eloquent\Casts\Attribute;
27
 use Illuminate\Database\Eloquent\Model;
26
 use Illuminate\Database\Eloquent\Model;
28
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
27
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
29
 use Illuminate\Database\Eloquent\Relations\MorphMany;
28
 use Illuminate\Database\Eloquent\Relations\MorphMany;
130
         return $this->amount_due;
129
         return $this->amount_due;
131
     }
130
     }
132
 
131
 
133
-    protected function isCurrentlyOverdue(): Attribute
132
+    public function shouldBeOverdue(): bool
134
     {
133
     {
135
-        return Attribute::get(function () {
136
-            return $this->due_date->isBefore(today()) && $this->canBeOverdue();
137
-        });
134
+        return $this->due_date->isBefore(today()) && $this->canBeOverdue();
138
     }
135
     }
139
 
136
 
140
     public function wasInitialized(): bool
137
     public function wasInitialized(): bool

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

130
         return $this->total;
130
         return $this->total;
131
     }
131
     }
132
 
132
 
133
-    protected function isCurrentlyExpired(): Attribute
133
+    public function shouldBeExpired(): bool
134
     {
134
     {
135
-        return Attribute::get(function () {
136
-            return $this->expiration_date?->isBefore(today());
137
-        });
135
+        return $this->expiration_date?->isBefore(today()) && $this->canBeExpired();
138
     }
136
     }
139
 
137
 
140
     public function isDraft(): bool
138
     public function isDraft(): bool

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

198
             ->where('status', InvoiceStatus::Overdue);
198
             ->where('status', InvoiceStatus::Overdue);
199
     }
199
     }
200
 
200
 
201
-    protected function isCurrentlyOverdue(): Attribute
201
+    public function shouldBeOverdue(): bool
202
     {
202
     {
203
-        return Attribute::get(function () {
204
-            return $this->due_date->isBefore(today()) && $this->canBeOverdue();
205
-        });
203
+        return $this->due_date->isBefore(today()) && $this->canBeOverdue();
206
     }
204
     }
207
 
205
 
208
     public function isDraft(): bool
206
     public function isDraft(): bool

+ 7
- 1
app/Observers/BillObserver.php 查看文件

17
 
17
 
18
     public function saving(Bill $bill): void
18
     public function saving(Bill $bill): void
19
     {
19
     {
20
-        if ($bill->is_currently_overdue) {
20
+        if ($bill->isDirty('due_date') && $bill->status === BillStatus::Overdue && ! $bill->shouldBeOverdue()) {
21
+            $bill->status = BillStatus::Open;
22
+
23
+            return;
24
+        }
25
+
26
+        if ($bill->shouldBeOverdue()) {
21
             $bill->status = BillStatus::Overdue;
27
             $bill->status = BillStatus::Overdue;
22
         }
28
         }
23
     }
29
     }

+ 2
- 2
app/Observers/EstimateObserver.php 查看文件

15
             return;
15
             return;
16
         }
16
         }
17
 
17
 
18
-        if ($estimate->isDirty('expiration_date') && $estimate->status === EstimateStatus::Expired && ! $estimate->is_currently_expired) {
18
+        if ($estimate->isDirty('expiration_date') && $estimate->status === EstimateStatus::Expired && ! $estimate->shouldBeExpired()) {
19
             $estimate->status = $estimate->hasBeenSent() ? EstimateStatus::Sent : EstimateStatus::Unsent;
19
             $estimate->status = $estimate->hasBeenSent() ? EstimateStatus::Sent : EstimateStatus::Unsent;
20
 
20
 
21
             return;
21
             return;
22
         }
22
         }
23
 
23
 
24
-        if ($estimate->is_currently_expired && $estimate->canBeExpired()) {
24
+        if ($estimate->shouldBeExpired()) {
25
             $estimate->status = EstimateStatus::Expired;
25
             $estimate->status = EstimateStatus::Expired;
26
         }
26
         }
27
     }
27
     }

+ 11
- 1
app/Observers/InvoiceObserver.php 查看文件

12
 {
12
 {
13
     public function saving(Invoice $invoice): void
13
     public function saving(Invoice $invoice): void
14
     {
14
     {
15
-        if ($invoice->approved_at && $invoice->is_currently_overdue) {
15
+        if (! $invoice->wasApproved()) {
16
+            return;
17
+        }
18
+
19
+        if ($invoice->isDirty('due_date') && $invoice->status === InvoiceStatus::Overdue && ! $invoice->shouldBeOverdue()) {
20
+            $invoice->status = $invoice->hasBeenSent() ? InvoiceStatus::Sent : InvoiceStatus::Unsent;
21
+
22
+            return;
23
+        }
24
+
25
+        if ($invoice->shouldBeOverdue()) {
16
             $invoice->status = InvoiceStatus::Overdue;
26
             $invoice->status = InvoiceStatus::Overdue;
17
         }
27
         }
18
     }
28
     }

+ 1
- 1
database/factories/Accounting/BillFactory.php 查看文件

207
                 'order_number' => "PO-{$number}",
207
                 'order_number' => "PO-{$number}",
208
             ]);
208
             ]);
209
 
209
 
210
-            if ($bill->wasInitialized() && $bill->is_currently_overdue) {
210
+            if ($bill->wasInitialized() && $bill->shouldBeOverdue()) {
211
                 $bill->updateQuietly([
211
                 $bill->updateQuietly([
212
                     'status' => BillStatus::Overdue,
212
                     'status' => BillStatus::Overdue,
213
                 ]);
213
                 ]);

+ 1
- 1
database/factories/Accounting/EstimateFactory.php 查看文件

181
                 'reference_number' => "REF-{$number}",
181
                 'reference_number' => "REF-{$number}",
182
             ]);
182
             ]);
183
 
183
 
184
-            if ($estimate->wasApproved() && $estimate->is_currently_expired) {
184
+            if ($estimate->wasApproved() && $estimate->shouldBeExpired()) {
185
                 $estimate->updateQuietly([
185
                 $estimate->updateQuietly([
186
                     'status' => EstimateStatus::Expired,
186
                     'status' => EstimateStatus::Expired,
187
                 ]);
187
                 ]);

+ 1
- 1
database/factories/Accounting/InvoiceFactory.php 查看文件

232
                 'order_number' => "ORD-{$number}",
232
                 'order_number' => "ORD-{$number}",
233
             ]);
233
             ]);
234
 
234
 
235
-            if ($invoice->wasApproved() && $invoice->is_currently_overdue) {
235
+            if ($invoice->wasApproved() && $invoice->shouldBeOverdue()) {
236
                 $invoice->updateQuietly([
236
                 $invoice->updateQuietly([
237
                     'status' => InvoiceStatus::Overdue,
237
                     'status' => InvoiceStatus::Overdue,
238
                 ]);
238
                 ]);

正在加载...
取消
保存