3c7e5fffbf
- client_id field: switched to relationship() with createOptionForm so new clients
can be created inline (name, phone, email); search also matches by phone
- vehicle_id field: added createOptionForm (make, model, plate, year, VIN); newly
created vehicle is automatically linked to the currently selected client
- master_id field: now shows only active users with role mechanic/master
- WorksRelationManager: labor catalog select marked optional; added createOptionForm
so new catalog entries can be added without leaving the WO form
- SubcontractJobsRelationManager: category table column now translates value via __()
and shows explicit label(__('Categorie'))
- PDF work-order: replaced 📞 / ✉ / ⚠ emojis with plain-text equivalents so
DomPDF/DejaVu Sans renders them correctly instead of showing "????"
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
80 lines
3.9 KiB
PHP
80 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Resources\WorkOrderResource\RelationManagers;
|
|
|
|
use App\Models\Tenant\Subcontractor;
|
|
use App\Models\Tenant\SubcontractJob;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class SubcontractJobsRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'subcontractJobs';
|
|
|
|
protected static ?string $title = null;
|
|
|
|
public static function getTitle(\Illuminate\Database\Eloquent\Model $ownerRecord, string $pageClass): string
|
|
{
|
|
return __('Lucrări la terți');
|
|
}
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Forms\Components\Select::make('subcontractor_id')
|
|
->label(__('Subcontractor'))
|
|
->options(fn () => Subcontractor::where('is_active', true)->pluck('name', 'id'))
|
|
->searchable()
|
|
->columnSpanFull(),
|
|
Forms\Components\Select::make('category')
|
|
->label(__('Categorie'))
|
|
->options(\App\Support\I18n::opts(array_combine(Subcontractor::SPECIALTIES, Subcontractor::SPECIALTIES)))
|
|
->searchable(),
|
|
Forms\Components\Select::make('status')->options(\App\Support\I18n::opts(SubcontractJob::STATUSES))->default('sent')->required(),
|
|
Forms\Components\Textarea::make('description')->label(__('Descriere'))->rows(2)->columnSpanFull(),
|
|
Forms\Components\TextInput::make('cost')->label(__('Cost (terț)'))->numeric()->default(0)->required(),
|
|
Forms\Components\TextInput::make('markup_pct')->label(__('Markup %'))->numeric()->default(0),
|
|
Forms\Components\TextInput::make('client_price')->label(__('Preț client'))->numeric()->default(0)
|
|
->helperText(__('Folosit dacă markup = 0.')),
|
|
Forms\Components\DatePicker::make('eta')->label(__('ETA')),
|
|
]);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('number')
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('number')->label(__('Nr.')),
|
|
Tables\Columns\TextColumn::make('subcontractor.name')->label(__('Terț'))->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('category')->label(__('Categorie'))
|
|
->formatStateUsing(fn ($s) => $s ? __($s) : '—')
|
|
->badge()->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('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 ($s) => (float) $s > 0 ? 'success' : ((float) $s < 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']]),
|
|
])
|
|
->headerActions([
|
|
Actions\CreateAction::make()
|
|
->label(__('Adaugă lucrare terți'))
|
|
->modalHeading(__('Adaugă lucrare la subcontractor')),
|
|
])
|
|
->actions([Actions\EditAction::make(), Actions\DeleteAction::make()])
|
|
->emptyStateHeading(__('Nicio lucrare la terți'))
|
|
->emptyStateDescription(__('Adaugă lucrări trimise la ateliere externe (turbo, cutii, vopsitorie). Costul + markup intră automat în totalul fișei.'))
|
|
->emptyStateIcon('heroicon-o-arrow-top-right-on-square');
|
|
}
|
|
}
|