|
@@ -8,6 +8,7 @@ use App\Filament\Forms\Components\CustomSection;
|
8
|
8
|
use App\Filament\Forms\Components\CustomTableRepeater;
|
9
|
9
|
use App\Models\Accounting\Account;
|
10
|
10
|
use App\Models\Accounting\Budget;
|
|
11
|
+use App\Models\Accounting\BudgetAllocation;
|
11
|
12
|
use App\Models\Accounting\BudgetItem;
|
12
|
13
|
use App\Utilities\Currency\CurrencyConverter;
|
13
|
14
|
use Awcodes\TableRepeater\Header;
|
|
@@ -269,8 +270,8 @@ class BudgetResource extends Resource
|
269
|
270
|
];
|
270
|
271
|
|
271
|
272
|
foreach ($periods as $period) {
|
272
|
|
- $headers[] = Header::make($period)
|
273
|
|
- ->label($period)
|
|
273
|
+ $headers[] = Header::make($period->period)
|
|
274
|
+ ->label($period->period)
|
274
|
275
|
->width('120px')
|
275
|
276
|
->align(Alignment::Right);
|
276
|
277
|
}
|
|
@@ -294,7 +295,7 @@ class BudgetResource extends Resource
|
294
|
295
|
$total = 0;
|
295
|
296
|
// Calculate the total for this budget item across all periods
|
296
|
297
|
foreach ($periods as $period) {
|
297
|
|
- $allocation = $record->allocations->firstWhere('period', $period);
|
|
298
|
+ $allocation = $record->allocations->firstWhere('period', $period->period);
|
298
|
299
|
$total += $allocation ? $allocation->getRawOriginal('amount') : 0;
|
299
|
300
|
}
|
300
|
301
|
$component->state(CurrencyConverter::convertCentsToFormatSimple($total));
|
|
@@ -321,20 +322,20 @@ class BudgetResource extends Resource
|
321
|
322
|
foreach ($periods as $index => $period) {
|
322
|
323
|
$amount = $baseAmount + ($index === 0 ? $remainder : 0);
|
323
|
324
|
$formattedAmount = CurrencyConverter::convertCentsToFormatSimple($amount);
|
324
|
|
- $set("allocations.{$period}", $formattedAmount);
|
|
325
|
+ $set("allocations.{$period->period}", $formattedAmount);
|
325
|
326
|
}
|
326
|
327
|
}),
|
327
|
328
|
]),
|
328
|
329
|
|
329
|
330
|
// Create a field for each period
|
330
|
|
- ...collect($periods)->map(function ($period) {
|
331
|
|
- return Forms\Components\TextInput::make("allocations.{$period}")
|
|
331
|
+ ...collect($periods)->map(function (BudgetAllocation $period) {
|
|
332
|
+ return Forms\Components\TextInput::make("allocations.{$period->period}")
|
332
|
333
|
->mask(RawJs::make('$money($input)'))
|
333
|
334
|
->stripCharacters(',')
|
334
|
335
|
->numeric()
|
335
|
336
|
->afterStateHydrated(function ($component, $state, BudgetItem $record) use ($period) {
|
336
|
337
|
// Find the allocation for this period
|
337
|
|
- $allocation = $record->allocations->firstWhere('period', $period);
|
|
338
|
+ $allocation = $record->allocations->firstWhere('period', $period->period);
|
338
|
339
|
$component->state($allocation ? $allocation->amount : 0);
|
339
|
340
|
})
|
340
|
341
|
->dehydrated(false); // We'll handle saving manually
|