Andrew Wallo před 10 měsíci
rodič
revize
1e7bd101ab

+ 9
- 3
app/Filament/Company/Resources/Purchases/BillResource.php Zobrazit soubor

@@ -54,17 +54,23 @@ class BillResource extends Resource
54 54
                             Forms\Components\Group::make([
55 55
                                 Forms\Components\TextInput::make('bill_number')
56 56
                                     ->label('Bill Number')
57
-                                    ->default(fn () => Bill::getNextDocumentNumber()),
57
+                                    ->default(fn () => Bill::getNextDocumentNumber())
58
+                                    ->required(),
58 59
                                 Forms\Components\TextInput::make('order_number')
59 60
                                     ->label('P.O/S.O Number'),
60 61
                                 Forms\Components\DatePicker::make('date')
61 62
                                     ->label('Bill Date')
62
-                                    ->default(now()),
63
+                                    ->default(now())
64
+                                    ->disabled(function (?Bill $record) {
65
+                                        return $record?->hasPayments();
66
+                                    })
67
+                                    ->required(),
63 68
                                 Forms\Components\DatePicker::make('due_date')
64 69
                                     ->label('Due Date')
65 70
                                     ->default(function () use ($company) {
66 71
                                         return now()->addDays($company->defaultBill->payment_terms->getDays());
67
-                                    }),
72
+                                    })
73
+                                    ->required(),
68 74
                             ])->grow(true),
69 75
                         ])->from('md'),
70 76
                         TableRepeater::make('lineItems')

+ 3
- 0
app/Filament/Company/Resources/Sales/InvoiceResource.php Zobrazit soubor

@@ -109,6 +109,9 @@ class InvoiceResource extends Resource
109 109
                                     ->label('Invoice Date')
110 110
                                     ->live()
111 111
                                     ->default(now())
112
+                                    ->disabled(function (?Invoice $record) {
113
+                                        return $record?->hasPayments();
114
+                                    })
112 115
                                     ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
113 116
                                         $date = $state;
114 117
                                         $dueDate = $get('due_date');

+ 5
- 0
app/Models/Accounting/Bill.php Zobrazit soubor

@@ -121,6 +121,11 @@ class Bill extends Model
121 121
         ]);
122 122
     }
123 123
 
124
+    public function hasPayments(): bool
125
+    {
126
+        return $this->payments->isNotEmpty();
127
+    }
128
+
124 129
     public static function getNextDocumentNumber(): string
125 130
     {
126 131
         $company = auth()->user()->currentCompany;

+ 5
- 0
app/Models/Accounting/Invoice.php Zobrazit soubor

@@ -159,6 +159,11 @@ class Invoice extends Model
159 159
         return in_array($this->status, InvoiceStatus::canBeOverdue());
160 160
     }
161 161
 
162
+    public function hasPayments(): bool
163
+    {
164
+        return $this->payments->isNotEmpty();
165
+    }
166
+
162 167
     public static function getNextDocumentNumber(): string
163 168
     {
164 169
         $company = auth()->user()->currentCompany;

+ 11
- 3
app/Observers/TransactionObserver.php Zobrazit soubor

@@ -35,7 +35,7 @@ class TransactionObserver
35 35
     {
36 36
         $this->transactionService->createJournalEntries($transaction);
37 37
 
38
-        if (! $transaction->is_payment) {
38
+        if (! $transaction->transactionable) {
39 39
             return;
40 40
         }
41 41
 
@@ -57,7 +57,7 @@ class TransactionObserver
57 57
 
58 58
         $this->transactionService->updateJournalEntries($transaction);
59 59
 
60
-        if (! $transaction->is_payment) {
60
+        if (! $transaction->transactionable) {
61 61
             return;
62 62
         }
63 63
 
@@ -78,7 +78,7 @@ class TransactionObserver
78 78
         DB::transaction(function () use ($transaction) {
79 79
             $this->transactionService->deleteJournalEntries($transaction);
80 80
 
81
-            if (! $transaction->is_payment) {
81
+            if (! $transaction->transactionable) {
82 82
                 return;
83 83
             }
84 84
 
@@ -103,6 +103,10 @@ class TransactionObserver
103 103
 
104 104
     protected function updateInvoiceTotals(Invoice $invoice, ?Transaction $excludedTransaction = null): void
105 105
     {
106
+        if (! $invoice->hasPayments()) {
107
+            return;
108
+        }
109
+
106 110
         $depositTotal = (int) $invoice->deposits()
107 111
             ->when($excludedTransaction, fn (Builder $query) => $query->whereKeyNot($excludedTransaction->getKey()))
108 112
             ->sum('amount');
@@ -138,6 +142,10 @@ class TransactionObserver
138 142
 
139 143
     protected function updateBillTotals(Bill $bill, ?Transaction $excludedTransaction = null): void
140 144
     {
145
+        if (! $bill->hasPayments()) {
146
+            return;
147
+        }
148
+
141 149
         $withdrawalTotal = (int) $bill->withdrawals()
142 150
             ->when($excludedTransaction, fn (Builder $query) => $query->whereKeyNot($excludedTransaction->getKey()))
143 151
             ->sum('amount');

Načítá se…
Zrušit
Uložit