00fb4a304a
- Migration: create `units` table + nullable unit_id FK on
parts / wo_parts / purchase_items / labor_parts. Seeds ~11 standard
units (buc/set/l/ml/kg/g/m/cm/m²/oră/pack) for every existing
tenant and backfills unit_id by matching the legacy string `unit`
column. Keeps `unit` string as fallback so old code paths keep
rendering.
- Unit model: label(locale), forSelect(locale), labelFor(id, code)
helpers. All 4 owner models get unitModel() relation + unitLabel()
accessor.
- UnitResource under Depozit group with Filament UI: code, sort,
is_active + separate name_ro/name_ru/name_en fields.
- Filament forms/tables updated: Part / PurchaseItem / LaborPart /
WorkOrderPart now use Select('unit_id')->options(Unit::forSelect())
for input and TextColumn->getStateUsing(unitLabel()) for display.
Selecting a part auto-fills unit_id when the source has one.
- +10 translations for the new resource + defaults; nav.label
'Unități de măsură' added to all 3 lang files.
All 306 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
105 lines
3.7 KiB
PHP
105 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Resources;
|
|
|
|
use App\Filament\Tenant\Resources\UnitResource\Pages;
|
|
use App\Models\Tenant\Unit;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class UnitResource extends Resource
|
|
{
|
|
protected static ?string $model = Unit::class;
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-scale';
|
|
|
|
public static function getNavigationLabel(): string
|
|
{
|
|
return __('nav.label.Unități de măsură');
|
|
}
|
|
|
|
public static function getNavigationGroup(): ?string
|
|
{
|
|
return __('nav.group.Depozit');
|
|
}
|
|
|
|
protected static ?int $navigationSort = 48;
|
|
|
|
public static function getModelLabel(): string
|
|
{
|
|
return __('unitate de măsură');
|
|
}
|
|
|
|
public static function getPluralModelLabel(): string
|
|
{
|
|
return __('unități de măsură');
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Schemas\Components\Section::make(__('Cod & sortare'))
|
|
->columns(3)
|
|
->schema([
|
|
Forms\Components\TextInput::make('code')
|
|
->label(__('Cod'))
|
|
->required()
|
|
->maxLength(16)
|
|
->helperText(__('Codul intern (buc, l, kg, ...) — stocat în DB.')),
|
|
Forms\Components\TextInput::make('sort_order')
|
|
->label(__('Ordine'))
|
|
->numeric()
|
|
->default(100),
|
|
Forms\Components\Toggle::make('is_active')
|
|
->label(__('Activ'))
|
|
->default(true),
|
|
]),
|
|
Schemas\Components\Section::make(__('Nume în cele 3 limbi'))
|
|
->columns(3)
|
|
->schema([
|
|
Forms\Components\TextInput::make('name_ro')->label('Română (RO)')->required()->maxLength(40),
|
|
Forms\Components\TextInput::make('name_ru')->label('Русский (RU)')->required()->maxLength(40),
|
|
Forms\Components\TextInput::make('name_en')->label('English (EN)')->required()->maxLength(40),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('sort_order')->label(__('Ordine'))->sortable(),
|
|
Tables\Columns\TextColumn::make('code')->searchable()->sortable(),
|
|
Tables\Columns\TextColumn::make('name_ro')->label('RO')->searchable(),
|
|
Tables\Columns\TextColumn::make('name_ru')->label('RU')->searchable(),
|
|
Tables\Columns\TextColumn::make('name_en')->label('EN')->searchable(),
|
|
Tables\Columns\IconColumn::make('is_active')->label(__('Activ'))->boolean(),
|
|
])
|
|
->defaultSort('sort_order')
|
|
->filters([
|
|
Tables\Filters\TernaryFilter::make('is_active')->label(__('Active')),
|
|
])
|
|
->actions([
|
|
Actions\EditAction::make(),
|
|
Actions\DeleteAction::make(),
|
|
])
|
|
->emptyStateHeading(__('Niciun UM înregistrat'))
|
|
->emptyStateDescription(__('Migrarea inițială a creat setul standard. Adaugă altele dacă ai nevoie (ex: rulou, doză, cutie).'))
|
|
->emptyStateIcon('heroicon-o-scale');
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListUnits::route('/'),
|
|
'create' => Pages\CreateUnit::route('/create'),
|
|
'edit' => Pages\EditUnit::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|