feat: add one-click orphaned WO recovery button for admins
Instead of relying on terminal/artisan commands, admins see a warning button on the WO list when orphaned WOs exist (wrong company_id due to Octane singleton bug). One click moves them all to the current tenant. Button only shows if there are orphaned WOs and user is admin/owner. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
namespace App\Filament\Tenant\Resources\WorkOrderResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\WorkOrderResource;
|
||||
use App\Tenancy\TenantManager;
|
||||
use Filament\Actions;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ListWorkOrders extends ListRecords
|
||||
{
|
||||
@@ -12,6 +15,42 @@ class ListWorkOrders extends ListRecords
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\CreateAction::make()];
|
||||
$actions = [Actions\CreateAction::make()];
|
||||
|
||||
// Show "recover orphaned WOs" button only for admin/owner
|
||||
$user = auth()->user();
|
||||
if ($user && $user->isAdmin()) {
|
||||
$tenantId = app(TenantManager::class)->currentId();
|
||||
$orphaned = $tenantId
|
||||
? DB::table('work_orders')
|
||||
->whereNull('deleted_at')
|
||||
->where('company_id', '!=', $tenantId)
|
||||
->count()
|
||||
: 0;
|
||||
|
||||
if ($orphaned > 0) {
|
||||
$actions[] = Actions\Action::make('recover_wos')
|
||||
->label("Recuperează {$orphaned} fișe din alt tenant")
|
||||
->color('warning')
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Recuperează fișe de lucru')
|
||||
->modalDescription("Există {$orphaned} fișe create cu tenant greșit (bug Octane). Vrei să le muți în compania curentă?")
|
||||
->modalSubmitActionLabel('Da, mută-le')
|
||||
->action(function () use ($tenantId, $orphaned) {
|
||||
$moved = DB::table('work_orders')
|
||||
->whereNull('deleted_at')
|
||||
->where('company_id', '!=', $tenantId)
|
||||
->update(['company_id' => $tenantId]);
|
||||
|
||||
Notification::make()
|
||||
->title("{$moved} fișe recuperate cu succes")
|
||||
->success()
|
||||
->send();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user