78ff8d4b43
User screenshots showed the tenant admin panel (Filament) had sidebar
labels stuck in Romanian even when switching to Russian: 'Cereri',
'Calendar vizual', 'Atelierul meu', 'KPI mecanici', 'Fișe lucru',
'Norme-ore', 'Tehnicieni', 'Șabloane servicii', 'Depozite', 'Scaner',
'Depozit', 'VIN-căutare', 'Furnizori', 'Achiziții', 'Procentaj',
'Coeficienți preț', plus all group headers.
Root cause: every Filament Resource and Page had static properties
'protected static ?string $navigationLabel = "Fișe lucru"' — string
literals baked into class definitions. Static properties don't run
through the translation layer.
Fix in two parts:
1. New translation files with 52 label keys + 12 group keys:
- lang/ro/nav.php — Romanian (identity)
- lang/ru/nav.php — full Russian translations (Заказ-наряды,
Автомобили, Клиенты, Календарь, Моя мастерская, Механики KPI,
Настройки, etc.)
- lang/en/nav.php — English translations (Work orders, Vehicles,
Clients, Calendar, My workshop, Mechanic KPI, Settings, etc.)
Keyed by the Romanian original so lookups map 1:1 —
'nav.label.Fișe lucru' returns 'Заказ-наряды' in RU, 'Work orders'
in EN, 'Fișe lucru' in RO.
2. Python transformer converted 54 files:
- 33 Filament Tenant Resources
- 15 Filament Tenant Pages
- 4 Filament Central Resources
- 1 Filament Central Page
- 1 Widget
Each 'protected static ?string $navigationLabel = "X";' became
'public static function getNavigationLabel(): string { return
__("nav.label.X"); }'. Same treatment for $navigationGroup.
Cleanup: 6 resources already had manually-added getNavigationLabel
methods from an earlier partial effort — those used flat JSON keys
(__("Cereri")) that never resolved. Deduped so only the nav.label.*
version remains.
Untouched (intentional):
- $modelLabel / $pluralModelLabel (used in breadcrumbs and headings —
still hardcoded, next tier of work)
- Section titles, column headers, form field labels (medium priority)
- $navigationSort (numeric, no translation needed)
- $navigationIcon (icon reference)
Suite: 306 passed (853 assertions). Unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
150 lines
6.8 KiB
PHP
150 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Resources;
|
|
|
|
use App\Filament\Tenant\Resources\SubcontractJobResource\Pages;
|
|
use App\Models\Tenant\Subcontractor;
|
|
use App\Models\Tenant\SubcontractJob;
|
|
use App\Models\Tenant\WorkOrder;
|
|
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 SubcontractJobResource extends Resource
|
|
{
|
|
protected static ?string $model = SubcontractJob::class;
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-arrow-top-right-on-square';
|
|
|
|
public static function getNavigationLabel(): string
|
|
{
|
|
return __('nav.label.Lucrări terți');
|
|
}
|
|
|
|
public static function getNavigationGroup(): ?string
|
|
{
|
|
return __('nav.group.Subcontractare');
|
|
}
|
|
|
|
protected static ?string $modelLabel = 'lucrare terți';
|
|
|
|
protected static ?string $pluralModelLabel = 'lucrări terți';
|
|
|
|
protected static ?int $navigationSort = 71;
|
|
|
|
public static function getNavigationBadge(): ?string
|
|
{
|
|
$open = static::getModel()::query()->whereNotIn('status', ['done', 'returned', 'cancelled'])->count();
|
|
return $open > 0 ? (string) $open : null;
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Schemas\Components\Section::make('Lucrare')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\TextInput::make('number')->label('Nr.')->disabled()->dehydrated(false)->placeholder('Generat automat'),
|
|
Forms\Components\Select::make('status')->options(SubcontractJob::STATUSES)->default('sent')->required(),
|
|
Forms\Components\Select::make('subcontractor_id')
|
|
->label('Subcontractor')
|
|
->options(fn () => Subcontractor::where('is_active', true)->pluck('name', 'id'))
|
|
->searchable(),
|
|
Forms\Components\Select::make('work_order_id')
|
|
->label('Fișă asociată')
|
|
->options(fn () => WorkOrder::whereNotIn('status', ['done', 'cancelled'])
|
|
->get()->mapWithKeys(fn ($w) => [$w->id => "#{$w->number} · " . ($w->vehicle?->plate ?? '')])->toArray())
|
|
->searchable(),
|
|
Forms\Components\Select::make('category')
|
|
->label('Categorie')
|
|
->options(array_combine(Subcontractor::SPECIALTIES, Subcontractor::SPECIALTIES))
|
|
->searchable(),
|
|
Forms\Components\Textarea::make('description')->label('Descriere')->rows(2)->columnSpanFull(),
|
|
]),
|
|
Schemas\Components\Section::make('Cost & marjă')
|
|
->columns(3)
|
|
->schema([
|
|
Forms\Components\TextInput::make('cost')->label('Cost (de la terț)')->numeric()->default(0)->required(),
|
|
Forms\Components\TextInput::make('markup_pct')->label('Markup %')->numeric()->default(0)
|
|
->helperText('> 0 calculează automat prețul client.'),
|
|
Forms\Components\TextInput::make('client_price')->label('Preț client')->numeric()->default(0)
|
|
->helperText('Setat manual dacă markup = 0.'),
|
|
Forms\Components\Toggle::make('paid_to_sub')->label('Plătit către terț'),
|
|
]),
|
|
Schemas\Components\Section::make('Termene')
|
|
->columns(3)
|
|
->schema([
|
|
Forms\Components\DatePicker::make('sent_at')->label('Trimis')->default(today()),
|
|
Forms\Components\DatePicker::make('eta')->label('ETA'),
|
|
Forms\Components\DatePicker::make('returned_at')->label('Returnat'),
|
|
Forms\Components\Textarea::make('notes')->label('Observații')->columnSpanFull()->rows(2),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('number')->label('Nr.')->searchable()->sortable(),
|
|
Tables\Columns\TextColumn::make('subcontractor.name')->label('Terț')->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('category')->badge()->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('workOrder.number')->label('Fișă')->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('cost')->label('Cost')->money('MDL')->alignRight(),
|
|
Tables\Columns\TextColumn::make('client_price')->label('Preț client')->money('MDL')->alignRight(),
|
|
Tables\Columns\TextColumn::make('margin')
|
|
->label('Marjă')
|
|
->state(fn (SubcontractJob $r) => $r->margin())
|
|
->money('MDL')
|
|
->alignRight()
|
|
->color(fn ($state) => (float) $state > 0 ? 'success' : ((float) $state < 0 ? 'danger' : 'gray')),
|
|
Tables\Columns\TextColumn::make('status')
|
|
->formatStateUsing(fn ($s) => SubcontractJob::STATUSES[$s] ?? $s)
|
|
->badge()
|
|
->colors([
|
|
'warning' => ['sent', 'in_progress'],
|
|
'success' => ['done', 'returned'],
|
|
'danger' => ['cancelled'],
|
|
]),
|
|
Tables\Columns\IconColumn::make('paid_to_sub')->label('Plătit terț')->boolean()->toggleable(),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('status')->options(SubcontractJob::STATUSES),
|
|
Tables\Filters\SelectFilter::make('subcontractor_id')
|
|
->label('Subcontractor')
|
|
->options(fn () => Subcontractor::pluck('name', 'id')),
|
|
])
|
|
->actions([
|
|
Actions\EditAction::make(),
|
|
Actions\DeleteAction::make(),
|
|
])
|
|
->emptyStateHeading('Nicio lucrare la terți')
|
|
->emptyStateDescription('Înregistrează lucrările trimise la ateliere externe (turbo, cutii, vopsitorie). Costul terțului + markup intră automat în totalul fișei asociate.')
|
|
->emptyStateIcon('heroicon-o-arrow-top-right-on-square')
|
|
->defaultSort('created_at', 'desc');
|
|
}
|
|
|
|
public static function getModelLabel(): string
|
|
{
|
|
return __('lucrare terți');
|
|
}
|
|
|
|
public static function getPluralModelLabel(): string
|
|
{
|
|
return __('lucrări terți');
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListSubcontractJobs::route('/'),
|
|
'create' => Pages\CreateSubcontractJob::route('/create'),
|
|
'edit' => Pages\EditSubcontractJob::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|