瀏覽代碼

wip adjustment statuses

3.x
Andrew Wallo 6 月之前
父節點
當前提交
bccd1e2517

+ 55
- 16
app/Filament/Company/Clusters/Settings/Resources/AdjustmentResource.php 查看文件

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

+ 1
- 0
app/Models/Accounting/Adjustment.php 查看文件

162
         }
162
         }
163
 
163
 
164
         return $this->update([
164
         return $this->update([
165
+            'archived_at' => now(),
165
             'status' => AdjustmentStatus::Archived,
166
             'status' => AdjustmentStatus::Archived,
166
             'status_reason' => $reason,
167
             'status_reason' => $reason,
167
         ]);
168
         ]);

Loading…
取消
儲存