Andrew Wallo 10 月之前
父節點
當前提交
c5155a3550

+ 13
- 1
app/Filament/Company/Resources/Sales/InvoiceResource.php 查看文件

108
                                     ->label('P.O/S.O Number'),
108
                                     ->label('P.O/S.O Number'),
109
                                 Forms\Components\DatePicker::make('date')
109
                                 Forms\Components\DatePicker::make('date')
110
                                     ->label('Invoice Date')
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
                                 Forms\Components\DatePicker::make('due_date')
121
                                 Forms\Components\DatePicker::make('due_date')
113
                                     ->label('Payment Due')
122
                                     ->label('Payment Due')
114
                                     ->default(function () use ($company) {
123
                                     ->default(function () use ($company) {
115
                                         return now()->addDays($company->defaultInvoice->payment_terms->getDays());
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
                             ])->grow(true),
129
                             ])->grow(true),
118
                         ])->from('md'),
130
                         ])->from('md'),

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

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

+ 8
- 0
app/Observers/InvoiceObserver.php 查看文件

2
 
2
 
3
 namespace App\Observers;
3
 namespace App\Observers;
4
 
4
 
5
+use App\Enums\Accounting\InvoiceStatus;
5
 use App\Models\Accounting\DocumentLineItem;
6
 use App\Models\Accounting\DocumentLineItem;
6
 use App\Models\Accounting\Invoice;
7
 use App\Models\Accounting\Invoice;
7
 use App\Models\Accounting\Transaction;
8
 use App\Models\Accounting\Transaction;
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
      * Handle the Invoice "deleted" event.
42
      * Handle the Invoice "deleted" event.
35
      */
43
      */

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

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

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

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

Loading…
取消
儲存