|
@@ -5,6 +5,7 @@ namespace App\Filament\Company\Clusters\Settings\Resources;
|
5
|
5
|
use App\Enums\Accounting\AdjustmentCategory;
|
6
|
6
|
use App\Enums\Accounting\AdjustmentComputation;
|
7
|
7
|
use App\Enums\Accounting\AdjustmentScope;
|
|
8
|
+use App\Enums\Accounting\AdjustmentStatus;
|
8
|
9
|
use App\Enums\Accounting\AdjustmentType;
|
9
|
10
|
use App\Filament\Company\Clusters\Settings;
|
10
|
11
|
use App\Filament\Company\Clusters\Settings\Resources\AdjustmentResource\Pages;
|
|
@@ -93,20 +94,53 @@ class AdjustmentResource extends Resource
|
93
|
94
|
Tables\Columns\TextColumn::make('name')
|
94
|
95
|
->label('Name')
|
95
|
96
|
->sortable(),
|
|
97
|
+ Tables\Columns\TextColumn::make('status')
|
|
98
|
+ ->badge(),
|
96
|
99
|
Tables\Columns\TextColumn::make('category')
|
97
|
100
|
->searchable(),
|
98
|
101
|
Tables\Columns\TextColumn::make('type')
|
99
|
102
|
->searchable(),
|
100
|
|
- Tables\Columns\TextColumn::make('status')
|
101
|
|
- ->badge(),
|
102
|
103
|
Tables\Columns\TextColumn::make('rate')
|
103
|
104
|
->localizeLabel()
|
104
|
105
|
->rate(static fn (Adjustment $record) => $record->computation->value)
|
105
|
106
|
->searchable()
|
106
|
107
|
->sortable(),
|
|
108
|
+ Tables\Columns\TextColumn::make('paused_until')
|
|
109
|
+ ->label('Auto-Resume Date')
|
|
110
|
+ ->dateTime()
|
|
111
|
+ ->sortable()
|
|
112
|
+ ->toggleable(isToggledHiddenByDefault: true),
|
|
113
|
+ Tables\Columns\TextColumn::make('start_date')
|
|
114
|
+ ->dateTime()
|
|
115
|
+ ->sortable()
|
|
116
|
+ ->toggleable(isToggledHiddenByDefault: true),
|
|
117
|
+ Tables\Columns\TextColumn::make('end_date')
|
|
118
|
+ ->dateTime()
|
|
119
|
+ ->sortable()
|
|
120
|
+ ->toggleable(isToggledHiddenByDefault: true),
|
107
|
121
|
])
|
108
|
122
|
->filters([
|
109
|
|
- //
|
|
123
|
+ Tables\Filters\TernaryFilter::make('archived')
|
|
124
|
+ ->label('Archived')
|
|
125
|
+ ->default(false)
|
|
126
|
+ ->attribute('archived_at')
|
|
127
|
+ ->nullable(),
|
|
128
|
+ Tables\Filters\SelectFilter::make('status')
|
|
129
|
+ ->label('Status')
|
|
130
|
+ ->native(false)
|
|
131
|
+ ->options(AdjustmentStatus::class),
|
|
132
|
+ Tables\Filters\SelectFilter::make('category')
|
|
133
|
+ ->label('Category')
|
|
134
|
+ ->native(false)
|
|
135
|
+ ->options(AdjustmentCategory::class),
|
|
136
|
+ Tables\Filters\SelectFilter::make('type')
|
|
137
|
+ ->label('Type')
|
|
138
|
+ ->native(false)
|
|
139
|
+ ->options(AdjustmentType::class),
|
|
140
|
+ Tables\Filters\SelectFilter::make('computation')
|
|
141
|
+ ->label('Computation')
|
|
142
|
+ ->native(false)
|
|
143
|
+ ->options(AdjustmentComputation::class),
|
110
|
144
|
])
|
111
|
145
|
->actions([
|
112
|
146
|
Tables\Actions\ActionGroup::make([
|
|
@@ -116,11 +150,11 @@ class AdjustmentResource extends Resource
|
116
|
150
|
->icon('heroicon-m-pause')
|
117
|
151
|
->form([
|
118
|
152
|
Forms\Components\DateTimePicker::make('paused_until')
|
119
|
|
- ->label('Auto-resume Date')
|
|
153
|
+ ->label('Auto-resume date')
|
120
|
154
|
->helperText('When should this adjustment automatically resume? Leave empty to keep paused indefinitely.')
|
121
|
155
|
->after('now'),
|
122
|
156
|
Forms\Components\Textarea::make('status_reason')
|
123
|
|
- ->label('Reason for Pausing')
|
|
157
|
+ ->label('Reason for pausing')
|
124
|
158
|
->maxLength(255),
|
125
|
159
|
])
|
126
|
160
|
->visible(fn (Adjustment $record) => $record->canBePaused())
|
|
@@ -141,7 +175,7 @@ class AdjustmentResource extends Resource
|
141
|
175
|
->color('danger')
|
142
|
176
|
->form([
|
143
|
177
|
Forms\Components\Textarea::make('status_reason')
|
144
|
|
- ->label('Reason for Archiving')
|
|
178
|
+ ->label('Reason for archiving')
|
145
|
179
|
->maxLength(255),
|
146
|
180
|
])
|
147
|
181
|
->visible(fn (Adjustment $record) => $record->canBeArchived())
|
|
@@ -156,20 +190,19 @@ class AdjustmentResource extends Resource
|
156
|
190
|
Tables\Actions\BulkAction::make('pause')
|
157
|
191
|
->label('Pause')
|
158
|
192
|
->icon('heroicon-m-pause')
|
159
|
|
- ->color('warning')
|
160
|
193
|
->form([
|
161
|
194
|
Forms\Components\DateTimePicker::make('paused_until')
|
162
|
|
- ->label('Auto-resume Date')
|
|
195
|
+ ->label('Auto-resume date')
|
163
|
196
|
->helperText('When should these adjustments automatically resume? Leave empty to keep paused indefinitely.')
|
164
|
197
|
->after('now'),
|
165
|
198
|
Forms\Components\Textarea::make('status_reason')
|
166
|
|
- ->label('Reason for Pausing')
|
|
199
|
+ ->label('Reason for pausing')
|
167
|
200
|
->maxLength(255),
|
168
|
201
|
])
|
169
|
202
|
->databaseTransaction()
|
170
|
203
|
->successNotificationTitle('Adjustments paused')
|
171
|
204
|
->failureNotificationTitle('Failed to pause adjustments')
|
172
|
|
- ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
|
|
205
|
+ ->beforeFormFilled(function (Collection $records, Tables\Actions\BulkAction $action) {
|
173
|
206
|
$isInvalid = $records->contains(fn (Adjustment $record) => ! $record->canBePaused());
|
174
|
207
|
|
175
|
208
|
if ($isInvalid) {
|
|
@@ -184,19 +217,21 @@ class AdjustmentResource extends Resource
|
184
|
217
|
}
|
185
|
218
|
})
|
186
|
219
|
->deselectRecordsAfterCompletion()
|
187
|
|
- ->action(function (Collection $records, array $data) {
|
|
220
|
+ ->action(function (Collection $records, array $data, Tables\Actions\BulkAction $action) {
|
188
|
221
|
$pausedUntil = $data['paused_until'] ?? null;
|
189
|
222
|
$reason = $data['status_reason'] ?? null;
|
190
|
223
|
|
191
|
224
|
$records->each(function (Adjustment $record) use ($reason, $pausedUntil) {
|
192
|
225
|
$record->pause($reason, $pausedUntil);
|
193
|
226
|
});
|
|
227
|
+
|
|
228
|
+ $action->success();
|
194
|
229
|
}),
|
195
|
230
|
Tables\Actions\BulkAction::make('resume')
|
196
|
231
|
->label('Resume')
|
197
|
232
|
->icon('heroicon-m-play')
|
198
|
|
- ->color('success')
|
199
|
233
|
->databaseTransaction()
|
|
234
|
+ ->requiresConfirmation()
|
200
|
235
|
->successNotificationTitle('Adjustments resumed')
|
201
|
236
|
->failureNotificationTitle('Failed to resume adjustments')
|
202
|
237
|
->before(function (Collection $records, Tables\Actions\BulkAction $action) {
|
|
@@ -214,10 +249,12 @@ class AdjustmentResource extends Resource
|
214
|
249
|
}
|
215
|
250
|
})
|
216
|
251
|
->deselectRecordsAfterCompletion()
|
217
|
|
- ->action(function (Collection $records) {
|
|
252
|
+ ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
|
218
|
253
|
$records->each(function (Adjustment $record) {
|
219
|
254
|
$record->resume();
|
220
|
255
|
});
|
|
256
|
+
|
|
257
|
+ $action->success();
|
221
|
258
|
}),
|
222
|
259
|
Tables\Actions\BulkAction::make('archive')
|
223
|
260
|
->label('Archive')
|
|
@@ -225,13 +262,13 @@ class AdjustmentResource extends Resource
|
225
|
262
|
->color('danger')
|
226
|
263
|
->form([
|
227
|
264
|
Forms\Components\Textarea::make('status_reason')
|
228
|
|
- ->label('Reason for Archiving')
|
|
265
|
+ ->label('Reason for archiving')
|
229
|
266
|
->maxLength(255),
|
230
|
267
|
])
|
231
|
268
|
->databaseTransaction()
|
232
|
269
|
->successNotificationTitle('Adjustments archived')
|
233
|
270
|
->failureNotificationTitle('Failed to archive adjustments')
|
234
|
|
- ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
|
|
271
|
+ ->beforeFormFilled(function (Collection $records, Tables\Actions\BulkAction $action) {
|
235
|
272
|
$isInvalid = $records->contains(fn (Adjustment $record) => ! $record->canBeArchived());
|
236
|
273
|
|
237
|
274
|
if ($isInvalid) {
|
|
@@ -246,12 +283,14 @@ class AdjustmentResource extends Resource
|
246
|
283
|
}
|
247
|
284
|
})
|
248
|
285
|
->deselectRecordsAfterCompletion()
|
249
|
|
- ->action(function (Collection $records, array $data) {
|
|
286
|
+ ->action(function (Collection $records, array $data, Tables\Actions\BulkAction $action) {
|
250
|
287
|
$reason = $data['status_reason'] ?? null;
|
251
|
288
|
|
252
|
289
|
$records->each(function (Adjustment $record) use ($reason) {
|
253
|
290
|
$record->archive($reason);
|
254
|
291
|
});
|
|
292
|
+
|
|
293
|
+ $action->success();
|
255
|
294
|
}),
|
256
|
295
|
]),
|
257
|
296
|
]);
|