Andrew Wallo пре 4 месеци
родитељ
комит
4c72c999ad

+ 1
- 1
app/Filament/Company/Resources/Purchases/BillResource.php Прегледај датотеку

@@ -152,7 +152,7 @@ class BillResource extends Resource
152 152
                                         $date = $get('date');
153 153
                                         $paymentTerms = $get('payment_terms');
154 154
 
155
-                                        if (! $date || $paymentTerms === 'custom') {
155
+                                        if (! $date || $paymentTerms === 'custom' || ! $paymentTerms) {
156 156
                                             return;
157 157
                                         }
158 158
 

+ 2
- 5
app/Models/Accounting/Bill.php Прегледај датотеку

@@ -23,7 +23,6 @@ use Filament\Actions\ReplicateAction;
23 23
 use Illuminate\Database\Eloquent\Attributes\CollectedBy;
24 24
 use Illuminate\Database\Eloquent\Attributes\ObservedBy;
25 25
 use Illuminate\Database\Eloquent\Builder;
26
-use Illuminate\Database\Eloquent\Casts\Attribute;
27 26
 use Illuminate\Database\Eloquent\Model;
28 27
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
29 28
 use Illuminate\Database\Eloquent\Relations\MorphMany;
@@ -130,11 +129,9 @@ class Bill extends Document
130 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 137
     public function wasInitialized(): bool

+ 2
- 4
app/Models/Accounting/Estimate.php Прегледај датотеку

@@ -130,11 +130,9 @@ class Estimate extends Document
130 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 138
     public function isDraft(): bool

+ 2
- 4
app/Models/Accounting/Invoice.php Прегледај датотеку

@@ -198,11 +198,9 @@ class Invoice extends Document
198 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 206
     public function isDraft(): bool

+ 7
- 1
app/Observers/BillObserver.php Прегледај датотеку

@@ -17,7 +17,13 @@ class BillObserver
17 17
 
18 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 27
             $bill->status = BillStatus::Overdue;
22 28
         }
23 29
     }

+ 2
- 2
app/Observers/EstimateObserver.php Прегледај датотеку

@@ -15,13 +15,13 @@ class EstimateObserver
15 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 19
             $estimate->status = $estimate->hasBeenSent() ? EstimateStatus::Sent : EstimateStatus::Unsent;
20 20
 
21 21
             return;
22 22
         }
23 23
 
24
-        if ($estimate->is_currently_expired && $estimate->canBeExpired()) {
24
+        if ($estimate->shouldBeExpired()) {
25 25
             $estimate->status = EstimateStatus::Expired;
26 26
         }
27 27
     }

+ 11
- 1
app/Observers/InvoiceObserver.php Прегледај датотеку

@@ -12,7 +12,17 @@ class InvoiceObserver
12 12
 {
13 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 26
             $invoice->status = InvoiceStatus::Overdue;
17 27
         }
18 28
     }

+ 1
- 1
database/factories/Accounting/BillFactory.php Прегледај датотеку

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

+ 1
- 1
database/factories/Accounting/EstimateFactory.php Прегледај датотеку

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

+ 1
- 1
database/factories/Accounting/InvoiceFactory.php Прегледај датотеку

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

Loading…
Откажи
Сачувај