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>
149 lines
6.3 KiB
PHP
149 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Resources;
|
|
|
|
use App\Filament\Tenant\Resources\OnlineOrderResource\Pages;
|
|
use App\Filament\Tenant\Resources\OnlineOrderResource\RelationManagers;
|
|
use App\Models\Tenant\OnlineOrder;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class OnlineOrderResource extends Resource
|
|
{
|
|
protected static ?string $model = OnlineOrder::class;
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-shopping-bag';
|
|
|
|
public static function getNavigationLabel(): string
|
|
{
|
|
return __('nav.label.Comenzi online');
|
|
}
|
|
|
|
public static function getNavigationGroup(): ?string
|
|
{
|
|
return __('nav.group.Magazin');
|
|
}
|
|
|
|
protected static ?string $modelLabel = 'comandă';
|
|
|
|
protected static ?string $pluralModelLabel = 'comenzi online';
|
|
|
|
protected static ?int $navigationSort = 50;
|
|
|
|
public static function getNavigationBadge(): ?string
|
|
{
|
|
$new = static::getModel()::query()->where('status', 'new')->count();
|
|
return $new > 0 ? (string) $new : null;
|
|
}
|
|
|
|
public static function getNavigationBadgeColor(): ?string
|
|
{
|
|
return 'warning';
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Schemas\Components\Section::make('Comandă')
|
|
->columns(3)
|
|
->schema([
|
|
Forms\Components\TextInput::make('number')->label('Nr.')->disabled()->dehydrated(false),
|
|
Forms\Components\Select::make('status')->options(OnlineOrder::STATUSES)->required(),
|
|
Forms\Components\Select::make('delivery_method')->label('Livrare')->options(OnlineOrder::DELIVERY)->required(),
|
|
Forms\Components\TextInput::make('customer_name')->label('Client')->required(),
|
|
Forms\Components\TextInput::make('customer_phone')->label('Telefon')->required(),
|
|
Forms\Components\TextInput::make('customer_email')->label('Email'),
|
|
Forms\Components\TextInput::make('address')->label('Adresă')->columnSpan(2),
|
|
Forms\Components\TextInput::make('delivery_fee')->label('Taxă livrare')->numeric(),
|
|
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('created_at')->label('Data')->dateTime('d.m.Y H:i')->sortable(),
|
|
Tables\Columns\TextColumn::make('customer_name')->label('Client')->searchable(),
|
|
Tables\Columns\TextColumn::make('customer_phone')->label('Telefon')->copyable(),
|
|
Tables\Columns\TextColumn::make('delivery_method')
|
|
->label('Livrare')
|
|
->formatStateUsing(fn ($s) => OnlineOrder::DELIVERY[$s] ?? $s),
|
|
Tables\Columns\TextColumn::make('status')
|
|
->formatStateUsing(fn ($s) => OnlineOrder::STATUSES[$s] ?? $s)
|
|
->badge()
|
|
->colors([
|
|
'warning' => ['new'],
|
|
'info' => ['confirmed', 'packed'],
|
|
'primary' => ['shipped'],
|
|
'success' => ['delivered'],
|
|
'danger' => ['cancelled'],
|
|
]),
|
|
Tables\Columns\TextColumn::make('total')->money('MDL')->alignRight()->sortable(),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('status')->options(OnlineOrder::STATUSES),
|
|
])
|
|
->actions([
|
|
Actions\Action::make('fulfill')
|
|
->label('Onorează (scade stoc)')
|
|
->icon('heroicon-m-check-badge')
|
|
->color('success')
|
|
->visible(fn (OnlineOrder $r) => ! in_array($r->status, ['delivered', 'cancelled'], true))
|
|
->requiresConfirmation()
|
|
->modalDescription('Scade din stoc piesele legate de catalog (FIFO) și marchează comanda confirmată.')
|
|
->action(function (OnlineOrder $r) {
|
|
$svc = app(\App\Services\Warehouse\WarehouseService::class);
|
|
$issued = 0; $skipped = 0;
|
|
foreach ($r->items as $item) {
|
|
if ($item->fulfilled) continue;
|
|
if (! $item->part_id) { $skipped++; continue; }
|
|
$part = \App\Models\Tenant\Part::find($item->part_id);
|
|
if (! $part) { $skipped++; continue; }
|
|
try {
|
|
$svc->issue($part, (float) $item->qty, null, $r, "Comandă online #{$r->number}");
|
|
$item->fulfilled = true;
|
|
$item->save();
|
|
$issued++;
|
|
} catch (\App\Services\Warehouse\InsufficientStockException $e) {
|
|
$skipped++;
|
|
}
|
|
}
|
|
if ($r->status === 'new') {
|
|
$r->status = 'confirmed';
|
|
$r->save();
|
|
}
|
|
Notification::make()
|
|
->title("Onorat: {$issued} linii scăzute" . ($skipped ? ", {$skipped} sărite (stoc/lipsă link)" : ''))
|
|
->{$skipped ? 'warning' : 'success'}()
|
|
->send();
|
|
}),
|
|
Actions\EditAction::make(),
|
|
])
|
|
->defaultSort('created_at', 'desc');
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationManagers\ItemsRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListOnlineOrders::route('/'),
|
|
'edit' => Pages\EditOnlineOrder::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|