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>
160 lines
4.7 KiB
PHP
160 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Pages;
|
|
|
|
use App\Models\Tenant\Part;
|
|
use App\Models\Tenant\Purchase;
|
|
use App\Models\Tenant\PurchaseItem;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Livewire\Attributes\On;
|
|
|
|
/**
|
|
* Mobile scanner: opens camera in the browser, decodes QR/barcode, looks up
|
|
* Part by:
|
|
* - `PART:<article|id>` payload (our own QR labels)
|
|
* - exact barcode match on parts.barcode
|
|
* - exact article match on parts.article
|
|
* On match → redirect to Part edit page.
|
|
*/
|
|
class Scanner extends Page
|
|
{
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-qr-code';
|
|
|
|
public static function getNavigationLabel(): string
|
|
{
|
|
return __('nav.label.Scaner');
|
|
}
|
|
|
|
public static function getNavigationGroup(): ?string
|
|
{
|
|
return __('nav.group.Depozit');
|
|
}
|
|
|
|
protected static ?int $navigationSort = 39;
|
|
|
|
protected static ?string $title = 'Scaner cod QR / Bare';
|
|
|
|
protected string $view = 'filament.tenant.pages.scanner';
|
|
|
|
public string $manual = '';
|
|
public ?int $purchaseId = null;
|
|
public array $receivedToasts = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
// Optional ?purchase=N → receipt mode: scans mark items received
|
|
$purchase = request()->query('purchase');
|
|
if ($purchase && ctype_digit((string) $purchase)) {
|
|
$this->purchaseId = (int) $purchase;
|
|
}
|
|
}
|
|
|
|
public function getActivePurchase(): ?Purchase
|
|
{
|
|
return $this->purchaseId ? Purchase::find($this->purchaseId) : null;
|
|
}
|
|
|
|
public function getPendingItems(): array
|
|
{
|
|
if (! $this->purchaseId) return [];
|
|
return PurchaseItem::where('purchase_id', $this->purchaseId)
|
|
->whereColumn('qty_received', '<', 'qty')
|
|
->orderBy('article')
|
|
->get(['id', 'article', 'name', 'qty', 'qty_received'])
|
|
->toArray();
|
|
}
|
|
|
|
#[On('scanner-decoded')]
|
|
public function decoded(string $text): void
|
|
{
|
|
$this->process(trim($text));
|
|
}
|
|
|
|
public function submitManual(): void
|
|
{
|
|
if (trim($this->manual) === '') return;
|
|
$this->process(trim($this->manual));
|
|
$this->manual = '';
|
|
}
|
|
|
|
protected function process(string $code): void
|
|
{
|
|
// Receipt mode: increment qty_received on matching purchase item
|
|
if ($this->purchaseId) {
|
|
$this->markReceivedByScan($code);
|
|
return;
|
|
}
|
|
$this->resolveAndRedirect($code);
|
|
}
|
|
|
|
protected function markReceivedByScan(string $code): void
|
|
{
|
|
$clean = str_starts_with($code, 'PART:') ? substr($code, 5) : $code;
|
|
|
|
$item = PurchaseItem::where('purchase_id', $this->purchaseId)
|
|
->whereColumn('qty_received', '<', 'qty')
|
|
->where(function ($q) use ($clean, $code) {
|
|
$q->where('article', $clean)->orWhere('article', $code);
|
|
})
|
|
->first();
|
|
|
|
if (! $item) {
|
|
Notification::make()
|
|
->title('Articol nu se potrivește comenzii')
|
|
->body('Codul ' . $code . ' nu apare în liniile neîncasate ale acestei comenzi.')
|
|
->warning()->send();
|
|
return;
|
|
}
|
|
|
|
$item->qty_received = min((float) $item->qty, (float) $item->qty_received + 1);
|
|
$item->save();
|
|
|
|
$this->receivedToasts[] = [
|
|
'article' => $item->article,
|
|
'name' => $item->name,
|
|
'qty_received' => (float) $item->qty_received,
|
|
'qty_total' => (float) $item->qty,
|
|
'at' => now()->format('H:i:s'),
|
|
];
|
|
|
|
Notification::make()
|
|
->title("+1 {$item->article} — {$item->qty_received}/{$item->qty}")
|
|
->success()->send();
|
|
}
|
|
|
|
protected function resolveAndRedirect(string $code): void
|
|
{
|
|
$clean = $code;
|
|
if (str_starts_with($clean, 'PART:')) {
|
|
$clean = substr($clean, 5);
|
|
}
|
|
|
|
$part = Part::where(function ($q) use ($clean, $code) {
|
|
$q->where('article', $clean)
|
|
->orWhere('barcode', $clean)
|
|
->orWhere('barcode', $code);
|
|
if (ctype_digit($clean)) $q->orWhere('id', (int) $clean);
|
|
})
|
|
->first();
|
|
|
|
if (! $part) {
|
|
Notification::make()
|
|
->title('Cod necunoscut')
|
|
->body('Nu am găsit nicio piesă pentru: ' . $code)
|
|
->warning()
|
|
->send();
|
|
return;
|
|
}
|
|
|
|
Notification::make()
|
|
->title('Piesă găsită: ' . $part->name)
|
|
->success()
|
|
->send();
|
|
|
|
$this->redirect(
|
|
route('filament.tenant.resources.parts.edit', ['record' => $part->id])
|
|
);
|
|
}
|
|
}
|