diff --git a/app/Filament/Tenant/Resources/LaborCategoryResource.php b/app/Filament/Tenant/Resources/LaborCategoryResource.php new file mode 100644 index 0000000..a3464b0 --- /dev/null +++ b/app/Filament/Tenant/Resources/LaborCategoryResource.php @@ -0,0 +1,97 @@ +components([ + Forms\Components\TextInput::make('name') + ->label(__('Denumire')) + ->required() + ->maxLength(80) + ->columnSpanFull(), + Forms\Components\TextInput::make('sort_order') + ->label(__('Ordine')) + ->numeric() + ->default(0), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('sort_order') + ->label('#') + ->sortable() + ->alignRight() + ->width(50), + Tables\Columns\TextColumn::make('name') + ->label(__('Categorie')) + ->searchable() + ->sortable(), + Tables\Columns\TextColumn::make('updated_at') + ->label(__('Modificat')) + ->dateTime('d.m.Y') + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->defaultSort('sort_order') + ->reorderable('sort_order') + ->actions([ + Actions\EditAction::make(), + Actions\DeleteAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListLaborCategories::route('/'), + 'create' => Pages\CreateLaborCategory::route('/create'), + 'edit' => Pages\EditLaborCategory::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Tenant/Resources/LaborCategoryResource/Pages/CreateLaborCategory.php b/app/Filament/Tenant/Resources/LaborCategoryResource/Pages/CreateLaborCategory.php new file mode 100644 index 0000000..053e1d3 --- /dev/null +++ b/app/Filament/Tenant/Resources/LaborCategoryResource/Pages/CreateLaborCategory.php @@ -0,0 +1,11 @@ +schema([ Forms\Components\Select::make('category') ->label(__('Categorie')) - ->options(\App\Support\I18n::opts(array_combine(Labor::CATEGORIES, Labor::CATEGORIES))) + ->options(fn () => \App\Models\Tenant\LaborCategory::orderBy('sort_order')->orderBy('name')->pluck('name', 'name')) ->required() ->searchable(), Forms\Components\TextInput::make('code')->label(__('Cod'))->maxLength(32), @@ -100,7 +100,7 @@ class LaborResource extends Resource ]) ->filters([ Tables\Filters\SelectFilter::make('category') - ->options(\App\Support\I18n::opts(array_combine(Labor::CATEGORIES, Labor::CATEGORIES))), + ->options(fn () => \App\Models\Tenant\LaborCategory::orderBy('sort_order')->orderBy('name')->pluck('name', 'name')), Tables\Filters\TernaryFilter::make('is_active')->label(__('Doar active')), ]) ->actions([ diff --git a/app/Models/Tenant/LaborCategory.php b/app/Models/Tenant/LaborCategory.php new file mode 100644 index 0000000..314b2e8 --- /dev/null +++ b/app/Models/Tenant/LaborCategory.php @@ -0,0 +1,15 @@ + 'integer']; +} diff --git a/database/migrations/2026_09_07_110000_create_labor_categories_table.php b/database/migrations/2026_09_07_110000_create_labor_categories_table.php new file mode 100644 index 0000000..754c45d --- /dev/null +++ b/database/migrations/2026_09_07_110000_create_labor_categories_table.php @@ -0,0 +1,50 @@ +id(); + $table->foreignId('company_id')->constrained()->cascadeOnDelete(); + $table->string('name'); + $table->unsignedSmallInteger('sort_order')->default(0); + $table->timestamps(); + + $table->unique(['company_id', 'name']); + $table->index('company_id'); + }); + + // Seed default categories for all existing companies + $defaults = [ + 'Motor', 'Frâne', 'Suspensie', 'Anvelope', 'ITP', + 'Cutie viteze', 'Caroserie', 'Electrică', 'Climatizare', + 'Eșapament', 'Altele', + ]; + + $companies = DB::table('companies')->pluck('id'); + $now = now(); + + foreach ($companies as $companyId) { + foreach ($defaults as $i => $name) { + DB::table('labor_categories')->insertOrIgnore([ + 'company_id' => $companyId, + 'name' => $name, + 'sort_order' => $i, + 'created_at' => $now, + 'updated_at' => $now, + ]); + } + } + } + + public function down(): void + { + Schema::dropIfExists('labor_categories'); + } +};