Files
autocrm/app/Filament/Tenant/Resources/ServiceTemplateResource/RelationManagers/ItemsRelationManager.php
T
Vasyka 95aeecb932 i18n: fix widget heading, translate Select options from model consts, +40 keys
- LowStockTable: rename getHeading → getTableHeading (correct Filament API)
- Global I18n::opts() helper wraps Model::CONST values in __() so
  Select dropdowns show translated status/type/season/etc. labels
- Sed-transform ->options(X::CONST), ->options(array_combine(X::A,X::A)),
  and formatStateUsing(fn($s)=>X::CONST[$s]??$s) → wrap with __()
  (58 options + 10 combines + 7 formatStateUsing across 28 files)
- CalendarBoard: all 7 day names now via __() (was missing 4)
- calendar-board.blade: fix untranslated 'săptămâna curentă', 'capacitate',
  'rata confirmare', 'mediu', 'plin', 'Pod / Zi' / 'Mecanic / Zi'
- +40 RU/EN translations (Client & Auto, Maistru / Mecanic, Programat,
  Sosit, Finalizat, Anulat, Neprezentat, days of week, calendar KPIs)

All 306 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-16 06:42:16 +00:00

85 lines
3.5 KiB
PHP

<?php
namespace App\Filament\Tenant\Resources\ServiceTemplateResource\RelationManagers;
use App\Models\Tenant\Labor;
use App\Models\Tenant\Part;
use App\Models\Tenant\ServiceTemplateItem;
use Filament\Actions;
use Filament\Forms;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;
class ItemsRelationManager extends RelationManager
{
protected static string $relationship = 'items';
protected static ?string $title = null;
public static function getTitle(\Illuminate\Database\Eloquent\Model $ownerRecord, string $pageClass): string
{
return __('Conținut șablon');
}
public function form(Schema $schema): Schema
{
return $schema->components([
Forms\Components\Select::make('kind')
->label(__('Tip'))
->options(\App\Support\I18n::opts(ServiceTemplateItem::KINDS))
->default('labor')
->live()
->required(),
Forms\Components\Select::make('labor_id')
->label(__('Manoperă'))
->options(fn () => Labor::where('is_active', true)->pluck('name_ro', 'id'))
->searchable()
->visible(fn (Get $get) => $get('kind') === 'labor')
->live()
->afterStateUpdated(function ($state, Set $set) {
if ($state && $l = Labor::find($state)) {
$set('name', $l->name_ro);
$set('hours', $l->hours);
}
}),
Forms\Components\Select::make('part_id')
->label(__('Piesă'))
->options(fn () => Part::where('is_active', true)
->get()->mapWithKeys(fn ($p) => [$p->id => "{$p->name} " . ($p->article ? "[{$p->article}]" : '')])->toArray())
->searchable()
->visible(fn (Get $get) => $get('kind') === 'part')
->live()
->afterStateUpdated(function ($state, Set $set) {
if ($state && $p = Part::find($state)) $set('name', $p->name);
}),
Forms\Components\TextInput::make('name')->label(__('Denumire'))->required()->columnSpanFull(),
Forms\Components\TextInput::make('hours')->label(__('Ore'))->numeric()
->visible(fn (Get $get) => $get('kind') === 'labor'),
Forms\Components\TextInput::make('qty')->label(__('Cantitate'))->numeric()->default(1)
->visible(fn (Get $get) => $get('kind') === 'part'),
]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('kind')
->label(__('Tip'))
->formatStateUsing(fn ($s) => ServiceTemplateItem::KINDS[$s] ?? $s)
->badge()
->color(fn ($s) => $s === 'labor' ? 'info' : 'gray'),
Tables\Columns\TextColumn::make('name')->wrap(),
Tables\Columns\TextColumn::make('hours')->label(__('Ore'))->placeholder('—')->alignRight(),
Tables\Columns\TextColumn::make('qty')->label(__('Cant.'))->placeholder('—')->alignRight(),
])
->headerActions([Actions\CreateAction::make()])
->actions([Actions\EditAction::make(), Actions\DeleteAction::make()]);
}
}