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>
139 lines
5.7 KiB
PHP
139 lines
5.7 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Tenant\Resources;
|
||
|
||
use App\Filament\Tenant\Resources\MarkupRuleResource\Pages;
|
||
use App\Models\Tenant\MarkupRule;
|
||
use App\Models\Tenant\Part;
|
||
use Filament\Actions;
|
||
use Filament\Forms;
|
||
use Filament\Notifications\Notification;
|
||
use Filament\Resources\Resource;
|
||
use Filament\Schemas;
|
||
use Filament\Schemas\Components\Utilities\Get;
|
||
use Filament\Schemas\Schema;
|
||
use Filament\Tables;
|
||
use Filament\Tables\Table;
|
||
|
||
class MarkupRuleResource extends Resource
|
||
{
|
||
protected static ?string $model = MarkupRule::class;
|
||
|
||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-percent-badge';
|
||
|
||
public static function getNavigationLabel(): string
|
||
{
|
||
return __('nav.label.Procentaj');
|
||
}
|
||
|
||
public static function getNavigationGroup(): ?string
|
||
{
|
||
return __('nav.group.Depozit');
|
||
}
|
||
|
||
protected static ?string $modelLabel = 'regulă';
|
||
|
||
protected static ?string $pluralModelLabel = 'reguli markup';
|
||
|
||
protected static ?int $navigationSort = 44;
|
||
|
||
public static function form(Schema $schema): Schema
|
||
{
|
||
return $schema->components([
|
||
Schemas\Components\Section::make('Regulă')
|
||
->columns(2)
|
||
->schema([
|
||
Forms\Components\Select::make('type')
|
||
->label('Tip')
|
||
->options(MarkupRule::TYPES)
|
||
->default('category')
|
||
->required()
|
||
->live(),
|
||
Forms\Components\Select::make('key')
|
||
->label(fn (Get $get) => $get('type') === 'brand' ? 'Brand' : 'Categorie')
|
||
->options(fn (Get $get) => $get('type') === 'brand'
|
||
? Part::distinct()->pluck('brand', 'brand')->filter()->toArray()
|
||
: array_combine(Part::CATEGORIES, Part::CATEGORIES))
|
||
->visible(fn (Get $get) => in_array($get('type'), ['category', 'brand'], true))
|
||
->searchable()
|
||
->required(fn (Get $get) => in_array($get('type'), ['category', 'brand'], true)),
|
||
Forms\Components\TextInput::make('range_from')
|
||
->label('De la (preț achiziție)')
|
||
->numeric()
|
||
->visible(fn (Get $get) => $get('type') === 'range'),
|
||
Forms\Components\TextInput::make('range_to')
|
||
->label('Până la (gol = ∞)')
|
||
->numeric()
|
||
->visible(fn (Get $get) => $get('type') === 'range'),
|
||
Forms\Components\TextInput::make('markup_pct')
|
||
->label('Markup %')
|
||
->numeric()
|
||
->required()
|
||
->suffix('%')
|
||
->helperText('Ex 30 → preț vânzare = preț achiziție × 1.30'),
|
||
Forms\Components\TextInput::make('priority')
|
||
->label('Prioritate')
|
||
->numeric()
|
||
->default(100)
|
||
->helperText('Mai mic = aplicat primul.'),
|
||
Forms\Components\Toggle::make('is_active')->label('Activă')->default(true),
|
||
]),
|
||
]);
|
||
}
|
||
|
||
public static function table(Table $table): Table
|
||
{
|
||
return $table
|
||
->columns([
|
||
Tables\Columns\TextColumn::make('priority')->label('#')->sortable(),
|
||
Tables\Columns\TextColumn::make('type')
|
||
->formatStateUsing(fn ($s) => MarkupRule::TYPES[$s] ?? $s)
|
||
->badge(),
|
||
Tables\Columns\TextColumn::make('key')->label('Cheie')->placeholder('—'),
|
||
Tables\Columns\TextColumn::make('range_from')->label('De la')->placeholder('—'),
|
||
Tables\Columns\TextColumn::make('range_to')->label('Până la')->placeholder('∞'),
|
||
Tables\Columns\TextColumn::make('markup_pct')
|
||
->label('Markup')
|
||
->formatStateUsing(fn ($s) => '+' . $s . '%')
|
||
->color('success')
|
||
->weight('bold'),
|
||
Tables\Columns\IconColumn::make('is_active')->boolean(),
|
||
])
|
||
->filters([
|
||
Tables\Filters\SelectFilter::make('type')->options(MarkupRule::TYPES),
|
||
])
|
||
->headerActions([
|
||
Actions\Action::make('apply_all')
|
||
->label('Aplică toate regulile la stoc')
|
||
->icon('heroicon-m-bolt')
|
||
->color('warning')
|
||
->requiresConfirmation()
|
||
->modalDescription('Va recalcula sell_price pentru TOATE piesele active. Continui?')
|
||
->action(function () {
|
||
$count = 0;
|
||
Part::where('is_active', true)->where('buy_price', '>', 0)->chunk(100, function ($parts) use (&$count) {
|
||
foreach ($parts as $part) {
|
||
MarkupRule::applyToPart($part);
|
||
$count++;
|
||
}
|
||
});
|
||
Notification::make()->title("Recalculat preț pentru {$count} piese")->success()->send();
|
||
}),
|
||
])
|
||
->actions([
|
||
Actions\EditAction::make(),
|
||
Actions\DeleteAction::make(),
|
||
])
|
||
->defaultSort('priority');
|
||
}
|
||
|
||
public static function getPages(): array
|
||
{
|
||
return [
|
||
'index' => Pages\ListMarkupRules::route('/'),
|
||
'create' => Pages\CreateMarkupRule::route('/create'),
|
||
'edit' => Pages\EditMarkupRule::route('/{record}/edit'),
|
||
];
|
||
}
|
||
}
|