Andrew Wallo 10 kuukautta sitten
vanhempi
commit
c5155a3550

+ 13
- 1
app/Filament/Company/Resources/Sales/InvoiceResource.php Näytä tiedosto

@@ -108,11 +108,23 @@ class InvoiceResource extends Resource
108 108
                                     ->label('P.O/S.O Number'),
109 109
                                 Forms\Components\DatePicker::make('date')
110 110
                                     ->label('Invoice Date')
111
-                                    ->default(now()),
111
+                                    ->live()
112
+                                    ->default(now())
113
+                                    ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
114
+                                        $date = $state;
115
+                                        $dueDate = $get('due_date');
116
+
117
+                                        if ($date && $dueDate && $date > $dueDate) {
118
+                                            $set('due_date', $date);
119
+                                        }
120
+                                    }),
112 121
                                 Forms\Components\DatePicker::make('due_date')
113 122
                                     ->label('Payment Due')
114 123
                                     ->default(function () use ($company) {
115 124
                                         return now()->addDays($company->defaultInvoice->payment_terms->getDays());
125
+                                    })
126
+                                    ->minDate(static function (Forms\Get $get) {
127
+                                        return $get('date') ?? now();
116 128
                                     }),
117 129
                             ])->grow(true),
118 130
                         ])->from('md'),

+ 1
- 1
app/Models/Accounting/Invoice.php Näytä tiedosto

@@ -231,7 +231,7 @@ class Invoice extends Model
231 231
             }
232 232
         }
233 233
 
234
-        $this->updateQuietly([
234
+        $this->update([
235 235
             'status' => InvoiceStatus::Unsent,
236 236
         ]);
237 237
     }

+ 8
- 0
app/Observers/InvoiceObserver.php Näytä tiedosto

@@ -2,6 +2,7 @@
2 2
 
3 3
 namespace App\Observers;
4 4
 
5
+use App\Enums\Accounting\InvoiceStatus;
5 6
 use App\Models\Accounting\DocumentLineItem;
6 7
 use App\Models\Accounting\Invoice;
7 8
 use App\Models\Accounting\Transaction;
@@ -30,6 +31,13 @@ class InvoiceObserver
30 31
         //
31 32
     }
32 33
 
34
+    public function saving(Invoice $invoice): void
35
+    {
36
+        if ($invoice->due_date->isBefore(today()) && $invoice->canBeOverdue()) {
37
+            $invoice->status = InvoiceStatus::Overdue;
38
+        }
39
+    }
40
+
33 41
     /**
34 42
      * Handle the Invoice "deleted" event.
35 43
      */

+ 1
- 1
app/Observers/TransactionObserver.php Näytä tiedosto

@@ -107,7 +107,7 @@ class TransactionObserver
107 107
 
108 108
         $invoiceTotal = (int) $invoice->getRawOriginal('total');
109 109
 
110
-        $invoice->updateQuietly([
110
+        $invoice->update([
111 111
             'amount_paid' => CurrencyConverter::convertCentsToFloat($totalPaid),
112 112
             'status' => match (true) {
113 113
                 $totalPaid > $invoiceTotal => InvoiceStatus::Overpaid,

+ 2
- 2
database/factories/Accounting/InvoiceFactory.php Näytä tiedosto

@@ -125,7 +125,7 @@ class InvoiceFactory extends Factory
125 125
 
126 126
             $this->recalculateTotals($invoice);
127 127
 
128
-            if ($invoice->due_date->isPast() && $invoice->canBeOverdue()) {
128
+            if ($invoice->due_date->isBefore(today()) && $invoice->canBeOverdue()) {
129 129
                 $invoice->updateQuietly([
130 130
                     'status' => InvoiceStatus::Overdue,
131 131
                 ]);
@@ -141,7 +141,7 @@ class InvoiceFactory extends Factory
141 141
             $discountTotal = $invoice->lineItems()->sum('discount_total') / 100;
142 142
             $grandTotal = $subtotal + $taxTotal - $discountTotal;
143 143
 
144
-            $invoice->updateQuietly([
144
+            $invoice->update([
145 145
                 'subtotal' => $subtotal,
146 146
                 'tax_total' => $taxTotal,
147 147
                 'discount_total' => $discountTotal,

Loading…
Peruuta
Tallenna