|
@@ -5,16 +5,17 @@ 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;
|
9
|
8
|
use App\Enums\Accounting\AdjustmentType;
|
10
|
9
|
use App\Filament\Company\Clusters\Settings;
|
11
|
10
|
use App\Filament\Company\Clusters\Settings\Resources\AdjustmentResource\Pages;
|
12
|
11
|
use App\Models\Accounting\Adjustment;
|
13
|
12
|
use Filament\Forms;
|
14
|
13
|
use Filament\Forms\Form;
|
|
14
|
+use Filament\Notifications\Notification;
|
15
|
15
|
use Filament\Resources\Resource;
|
16
|
16
|
use Filament\Tables;
|
17
|
17
|
use Filament\Tables\Table;
|
|
18
|
+use Illuminate\Database\Eloquent\Collection;
|
18
|
19
|
|
19
|
20
|
class AdjustmentResource extends Resource
|
20
|
21
|
{
|
|
@@ -110,17 +111,151 @@ class AdjustmentResource extends Resource
|
110
|
111
|
->actions([
|
111
|
112
|
Tables\Actions\ActionGroup::make([
|
112
|
113
|
Tables\Actions\EditAction::make(),
|
|
114
|
+ Tables\Actions\Action::make('pause')
|
|
115
|
+ ->label('Pause')
|
|
116
|
+ ->icon('heroicon-m-pause')
|
|
117
|
+ ->color('warning')
|
|
118
|
+ ->form([
|
|
119
|
+ Forms\Components\DateTimePicker::make('paused_until')
|
|
120
|
+ ->label('Auto-resume Date')
|
|
121
|
+ ->helperText('When should this adjustment automatically resume? Leave empty to keep paused indefinitely.')
|
|
122
|
+ ->after('now'),
|
|
123
|
+ Forms\Components\Textarea::make('status_reason')
|
|
124
|
+ ->label('Reason for Pausing')
|
|
125
|
+ ->maxLength(255),
|
|
126
|
+ ])
|
|
127
|
+ ->visible(fn (Adjustment $record) => $record->canBePaused())
|
|
128
|
+ ->action(function (Adjustment $record, array $data) {
|
|
129
|
+ $pausedUntil = $data['paused_until'] ?? null;
|
|
130
|
+ $reason = $data['status_reason'] ?? null;
|
|
131
|
+ $record->pause($reason, $pausedUntil);
|
|
132
|
+ }),
|
|
133
|
+ Tables\Actions\Action::make('resume')
|
|
134
|
+ ->label('Resume')
|
|
135
|
+ ->icon('heroicon-m-play')
|
|
136
|
+ ->color('success')
|
|
137
|
+ ->requiresConfirmation()
|
|
138
|
+ ->visible(fn (Adjustment $record) => $record->canBeResumed())
|
|
139
|
+ ->action(fn (Adjustment $record) => $record->resume()),
|
113
|
140
|
Tables\Actions\Action::make('archive')
|
114
|
141
|
->label('Archive')
|
115
|
|
- ->icon('heroicon-o-archive-box-x-mark')
|
|
142
|
+ ->icon('heroicon-m-archive-box')
|
116
|
143
|
->color('danger')
|
117
|
|
- ->requiresConfirmation()
|
118
|
|
- ->visible(static fn (Adjustment $record) => $record->status !== AdjustmentStatus::Archived)
|
119
|
|
- ->action(fn (Adjustment $record) => $record->update(['status' => AdjustmentStatus::Archived])),
|
|
144
|
+ ->form([
|
|
145
|
+ Forms\Components\Textarea::make('status_reason')
|
|
146
|
+ ->label('Reason for Archiving')
|
|
147
|
+ ->maxLength(255),
|
|
148
|
+ ])
|
|
149
|
+ ->visible(fn (Adjustment $record) => $record->canBeArchived())
|
|
150
|
+ ->action(function (Adjustment $record, array $data) {
|
|
151
|
+ $reason = $data['status_reason'] ?? null;
|
|
152
|
+ $record->archive($reason);
|
|
153
|
+ }),
|
120
|
154
|
]),
|
121
|
155
|
])
|
122
|
156
|
->bulkActions([
|
123
|
|
- //
|
|
157
|
+ Tables\Actions\BulkActionGroup::make([
|
|
158
|
+ Tables\Actions\BulkAction::make('pause')
|
|
159
|
+ ->label('Pause')
|
|
160
|
+ ->icon('heroicon-m-pause')
|
|
161
|
+ ->color('warning')
|
|
162
|
+ ->form([
|
|
163
|
+ Forms\Components\DateTimePicker::make('paused_until')
|
|
164
|
+ ->label('Auto-resume Date')
|
|
165
|
+ ->helperText('When should these adjustments automatically resume? Leave empty to keep paused indefinitely.')
|
|
166
|
+ ->after('now'),
|
|
167
|
+ Forms\Components\Textarea::make('status_reason')
|
|
168
|
+ ->label('Reason for Pausing')
|
|
169
|
+ ->maxLength(255),
|
|
170
|
+ ])
|
|
171
|
+ ->databaseTransaction()
|
|
172
|
+ ->successNotificationTitle('Adjustments paused')
|
|
173
|
+ ->failureNotificationTitle('Failed to pause adjustments')
|
|
174
|
+ ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
|
|
175
|
+ $isInvalid = $records->contains(fn (Adjustment $record) => ! $record->canBePaused());
|
|
176
|
+
|
|
177
|
+ if ($isInvalid) {
|
|
178
|
+ Notification::make()
|
|
179
|
+ ->title('Pause failed')
|
|
180
|
+ ->body('Only adjustments that are currently active can be paused. Please adjust your selection and try again.')
|
|
181
|
+ ->persistent()
|
|
182
|
+ ->danger()
|
|
183
|
+ ->send();
|
|
184
|
+
|
|
185
|
+ $action->cancel(true);
|
|
186
|
+ }
|
|
187
|
+ })
|
|
188
|
+ ->deselectRecordsAfterCompletion()
|
|
189
|
+ ->action(function (Collection $records, array $data) {
|
|
190
|
+ $pausedUntil = $data['paused_until'] ?? null;
|
|
191
|
+ $reason = $data['status_reason'] ?? null;
|
|
192
|
+
|
|
193
|
+ $records->each(function (Adjustment $record) use ($reason, $pausedUntil) {
|
|
194
|
+ $record->pause($reason, $pausedUntil);
|
|
195
|
+ });
|
|
196
|
+ }),
|
|
197
|
+ Tables\Actions\BulkAction::make('resume')
|
|
198
|
+ ->label('Resume')
|
|
199
|
+ ->icon('heroicon-m-play')
|
|
200
|
+ ->color('success')
|
|
201
|
+ ->databaseTransaction()
|
|
202
|
+ ->successNotificationTitle('Adjustments resumed')
|
|
203
|
+ ->failureNotificationTitle('Failed to resume adjustments')
|
|
204
|
+ ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
|
|
205
|
+ $isInvalid = $records->contains(fn (Adjustment $record) => ! $record->canBeResumed());
|
|
206
|
+
|
|
207
|
+ if ($isInvalid) {
|
|
208
|
+ Notification::make()
|
|
209
|
+ ->title('Resume failed')
|
|
210
|
+ ->body('Only adjustments that are currently paused can be resumed. Please adjust your selection and try again.')
|
|
211
|
+ ->persistent()
|
|
212
|
+ ->danger()
|
|
213
|
+ ->send();
|
|
214
|
+
|
|
215
|
+ $action->cancel(true);
|
|
216
|
+ }
|
|
217
|
+ })
|
|
218
|
+ ->deselectRecordsAfterCompletion()
|
|
219
|
+ ->action(function (Collection $records) {
|
|
220
|
+ $records->each(function (Adjustment $record) {
|
|
221
|
+ $record->resume();
|
|
222
|
+ });
|
|
223
|
+ }),
|
|
224
|
+ Tables\Actions\BulkAction::make('archive')
|
|
225
|
+ ->label('Archive')
|
|
226
|
+ ->icon('heroicon-m-archive-box')
|
|
227
|
+ ->color('danger')
|
|
228
|
+ ->form([
|
|
229
|
+ Forms\Components\Textarea::make('status_reason')
|
|
230
|
+ ->label('Reason for Archiving')
|
|
231
|
+ ->maxLength(255),
|
|
232
|
+ ])
|
|
233
|
+ ->databaseTransaction()
|
|
234
|
+ ->successNotificationTitle('Adjustments archived')
|
|
235
|
+ ->failureNotificationTitle('Failed to archive adjustments')
|
|
236
|
+ ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
|
|
237
|
+ $isInvalid = $records->contains(fn (Adjustment $record) => ! $record->canBeArchived());
|
|
238
|
+
|
|
239
|
+ if ($isInvalid) {
|
|
240
|
+ Notification::make()
|
|
241
|
+ ->title('Archive failed')
|
|
242
|
+ ->body('Only adjustments that are currently active or paused can be archived. Please adjust your selection and try again.')
|
|
243
|
+ ->persistent()
|
|
244
|
+ ->danger()
|
|
245
|
+ ->send();
|
|
246
|
+
|
|
247
|
+ $action->cancel(true);
|
|
248
|
+ }
|
|
249
|
+ })
|
|
250
|
+ ->deselectRecordsAfterCompletion()
|
|
251
|
+ ->action(function (Collection $records, array $data) {
|
|
252
|
+ $reason = $data['status_reason'] ?? null;
|
|
253
|
+
|
|
254
|
+ $records->each(function (Adjustment $record) use ($reason) {
|
|
255
|
+ $record->archive($reason);
|
|
256
|
+ });
|
|
257
|
+ }),
|
|
258
|
+ ]),
|
124
|
259
|
]);
|
125
|
260
|
}
|
126
|
261
|
|