|
@@ -2,6 +2,7 @@
|
2
|
2
|
|
3
|
3
|
namespace App\Filament\Company\Resources\Accounting;
|
4
|
4
|
|
|
5
|
+use App\Enums\Accounting\BudgetIntervalType;
|
5
|
6
|
use App\Filament\Company\Resources\Accounting\BudgetResource\Pages;
|
6
|
7
|
use App\Filament\Forms\Components\CustomSection;
|
7
|
8
|
use App\Models\Accounting\Account;
|
|
@@ -31,14 +32,8 @@ class BudgetResource extends Resource
|
31
|
32
|
->maxLength(255),
|
32
|
33
|
Forms\Components\Select::make('interval_type')
|
33
|
34
|
->label('Budget Interval')
|
34
|
|
- ->options([
|
35
|
|
- 'day' => 'Daily',
|
36
|
|
- 'week' => 'Weekly',
|
37
|
|
- 'month' => 'Monthly',
|
38
|
|
- 'quarter' => 'Quarterly',
|
39
|
|
- 'year' => 'Yearly',
|
40
|
|
- ])
|
41
|
|
- ->default('month')
|
|
35
|
+ ->options(BudgetIntervalType::class)
|
|
36
|
+ ->default(BudgetIntervalType::Month->value)
|
42
|
37
|
->required()
|
43
|
38
|
->live(),
|
44
|
39
|
Forms\Components\DatePicker::make('start_date')
|
|
@@ -75,7 +70,7 @@ class BudgetResource extends Resource
|
75
|
70
|
->label('Disperse')
|
76
|
71
|
->icon('heroicon-m-bars-arrow-down')
|
77
|
72
|
->color('primary')
|
78
|
|
- ->action(fn (Forms\Set $set, Forms\Get $get, $state) => self::disperseTotalAmount($set, $get, $state))
|
|
73
|
+ ->action(static fn (Forms\Set $set, Forms\Get $get, $state) => self::disperseTotalAmount($set, $get, $state))
|
79
|
74
|
),
|
80
|
75
|
|
81
|
76
|
CustomSection::make('Budget Allocations')
|
|
@@ -100,8 +95,7 @@ class BudgetResource extends Resource
|
100
|
95
|
Tables\Columns\TextColumn::make('interval_type')
|
101
|
96
|
->label('Interval')
|
102
|
97
|
->sortable()
|
103
|
|
- ->badge()
|
104
|
|
- ->formatStateUsing(fn (string $state) => ucfirst($state)),
|
|
98
|
+ ->badge(),
|
105
|
99
|
|
106
|
100
|
Tables\Columns\TextColumn::make('start_date')
|
107
|
101
|
->label('Start Date')
|
|
@@ -118,7 +112,7 @@ class BudgetResource extends Resource
|
118
|
112
|
->money()
|
119
|
113
|
->sortable()
|
120
|
114
|
->alignEnd()
|
121
|
|
- ->formatStateUsing(fn (Budget $record) => $record->budgetItems->sum(fn ($item) => $item->allocations->sum('amount'))),
|
|
115
|
+ ->getStateUsing(fn (Budget $record) => $record->budgetItems->sum(fn ($item) => $item->allocations->sum('amount'))),
|
122
|
116
|
])
|
123
|
117
|
->filters([
|
124
|
118
|
//
|
|
@@ -175,20 +169,23 @@ class BudgetResource extends Resource
|
175
|
169
|
{
|
176
|
170
|
$start = Carbon::parse($startDate);
|
177
|
171
|
$end = Carbon::parse($endDate);
|
|
172
|
+ $intervalTypeEnum = BudgetIntervalType::parse($intervalType);
|
178
|
173
|
$labels = [];
|
179
|
174
|
|
180
|
175
|
while ($start->lte($end)) {
|
181
|
|
- $labels[] = match ($intervalType) {
|
182
|
|
- 'month' => $start->format('M'), // Example: Jan, Feb, Mar
|
183
|
|
- 'quarter' => 'Q' . $start->quarter, // Example: Q1, Q2, Q3
|
184
|
|
- 'year' => (string) $start->year, // Example: 2024, 2025
|
|
176
|
+ $labels[] = match ($intervalTypeEnum) {
|
|
177
|
+ BudgetIntervalType::Week => 'W' . $start->weekOfYear . ' ' . $start->year, // Example: W10 2024
|
|
178
|
+ BudgetIntervalType::Month => $start->format('M'), // Example: Jan, Feb, Mar
|
|
179
|
+ BudgetIntervalType::Quarter => 'Q' . $start->quarter, // Example: Q1, Q2, Q3
|
|
180
|
+ BudgetIntervalType::Year => (string) $start->year, // Example: 2024, 2025
|
185
|
181
|
default => '',
|
186
|
182
|
};
|
187
|
183
|
|
188
|
|
- match ($intervalType) {
|
189
|
|
- 'month' => $start->addMonth(),
|
190
|
|
- 'quarter' => $start->addQuarter(),
|
191
|
|
- 'year' => $start->addYear(),
|
|
184
|
+ match ($intervalTypeEnum) {
|
|
185
|
+ BudgetIntervalType::Week => $start->addWeek(),
|
|
186
|
+ BudgetIntervalType::Month => $start->addMonth(),
|
|
187
|
+ BudgetIntervalType::Quarter => $start->addQuarter(),
|
|
188
|
+ BudgetIntervalType::Year => $start->addYear(),
|
192
|
189
|
default => null,
|
193
|
190
|
};
|
194
|
191
|
}
|
|
@@ -204,13 +201,15 @@ class BudgetResource extends Resource
|
204
|
201
|
|
205
|
202
|
$start = Carbon::parse($startDate);
|
206
|
203
|
$end = Carbon::parse($endDate);
|
|
204
|
+ $intervalTypeEnum = BudgetIntervalType::parse($intervalType);
|
207
|
205
|
$fields = [];
|
208
|
206
|
|
209
|
207
|
while ($start->lte($end)) {
|
210
|
|
- $label = match ($intervalType) {
|
211
|
|
- 'month' => $start->format('M'), // Example: Jan, Feb, Mar
|
212
|
|
- 'quarter' => 'Q' . $start->quarter, // Example: Q1, Q2, Q3
|
213
|
|
- 'year' => (string) $start->year, // Example: 2024, 2025
|
|
208
|
+ $label = match ($intervalTypeEnum) {
|
|
209
|
+ BudgetIntervalType::Week => 'W' . $start->weekOfYear . ' ' . $start->year, // Example: W10 2024
|
|
210
|
+ BudgetIntervalType::Month => $start->format('M'), // Example: Jan, Feb, Mar
|
|
211
|
+ BudgetIntervalType::Quarter => 'Q' . $start->quarter, // Example: Q1, Q2, Q3
|
|
212
|
+ BudgetIntervalType::Year => (string) $start->year, // Example: 2024, 2025
|
214
|
213
|
default => '',
|
215
|
214
|
};
|
216
|
215
|
|
|
@@ -220,10 +219,11 @@ class BudgetResource extends Resource
|
220
|
219
|
->required();
|
221
|
220
|
|
222
|
221
|
// Move to the next period
|
223
|
|
- match ($intervalType) {
|
224
|
|
- 'month' => $start->addMonth(),
|
225
|
|
- 'quarter' => $start->addQuarter(),
|
226
|
|
- 'year' => $start->addYear(),
|
|
222
|
+ match ($intervalTypeEnum) {
|
|
223
|
+ BudgetIntervalType::Week => $start->addWeek(),
|
|
224
|
+ BudgetIntervalType::Month => $start->addMonth(),
|
|
225
|
+ BudgetIntervalType::Quarter => $start->addQuarter(),
|
|
226
|
+ BudgetIntervalType::Year => $start->addYear(),
|
227
|
227
|
default => null,
|
228
|
228
|
};
|
229
|
229
|
}
|