Stage 4 — Labor Catalog: fixed price + default parts + service templates

Schema:
- labors.pricing_mode (hourly/fixed) + fixed_price
- labor_parts (default parts auto-added with a labor)
- service_templates + service_template_items (labor/part bundles)

ServiceComposer:
- addLabor(wo, labor, withParts) — hourly (hours×rate) or fixed (fixed_price),
  then auto-adds the labor's default parts
- addPart(wo, part, qty) — catalog price snapshot
- applyTemplate(wo, template) — adds all labor+part lines, recalcs total
- hourlyRate from settings.labor_rate

Filament:
- LaborResource: pricing_mode (live) toggles hours/fixed_price fields,
  DefaultPartsRelationManager
- ServiceTemplateResource (Service group) with ItemsRelationManager
- WorkOrder edit "Aplică șablon" action → applyTemplate
- WorksRelationManager CreateAction auto-adds labor default parts

Tests (6 new):
- hourly rate×hours; fixed uses fixed_price; default parts auto-added;
  withParts=false skips; applyTemplate adds lines + recalcs total;
  templates tenant-isolated

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-28 06:16:50 +00:00
parent c90c35d930
commit a1be01b0d5
16 changed files with 788 additions and 5 deletions
@@ -3,6 +3,7 @@
namespace App\Filament\Tenant\Resources;
use App\Filament\Tenant\Resources\LaborResource\Pages;
use App\Filament\Tenant\Resources\LaborResource\RelationManagers;
use App\Models\Tenant\Labor;
use Filament\Actions;
use Filament\Forms;
@@ -42,8 +43,17 @@ class LaborResource extends Resource
Forms\Components\TextInput::make('code')->label('Cod')->maxLength(32),
Forms\Components\TextInput::make('name_ro')->label('Nume (RO)')->required()->maxLength(160),
Forms\Components\TextInput::make('name_ru')->label('Nume (RU)')->maxLength(160),
Forms\Components\TextInput::make('hours')->label('Ore')->numeric()->default(1)->required(),
Forms\Components\TextInput::make('price')->label('Preț (MDL)')->numeric()->default(0),
Forms\Components\Select::make('pricing_mode')
->label('Mod tarifare')
->options(Labor::PRICING_MODES)
->default('hourly')
->live()
->required(),
Forms\Components\TextInput::make('hours')->label('Ore (normă)')->numeric()->default(1)
->visible(fn (Schemas\Components\Utilities\Get $get) => $get('pricing_mode') !== 'fixed'),
Forms\Components\TextInput::make('fixed_price')->label('Preț fix (MDL)')->numeric()->default(0)
->visible(fn (Schemas\Components\Utilities\Get $get) => $get('pricing_mode') === 'fixed'),
Forms\Components\TextInput::make('price')->label('Preț orientativ (MDL)')->numeric()->default(0),
Forms\Components\Toggle::make('is_active')->label('Activă')->default(true),
]),
Forms\Components\Textarea::make('notes')->label('Observații')->columnSpanFull()->rows(2),
@@ -56,8 +66,15 @@ class LaborResource extends Resource
->columns([
Tables\Columns\TextColumn::make('category')->label('Categorie')->badge()->sortable(),
Tables\Columns\TextColumn::make('name_ro')->label('Manoperă')->searchable()->sortable(),
Tables\Columns\TextColumn::make('pricing_mode')
->label('Tarifare')
->formatStateUsing(fn ($s) => $s === 'fixed' ? 'Fix' : 'Pe oră')
->badge()
->color(fn ($s) => $s === 'fixed' ? 'info' : 'gray'),
Tables\Columns\TextColumn::make('hours')->label('Ore')->numeric(decimalPlaces: 2)->alignRight(),
Tables\Columns\TextColumn::make('price')->label('Preț')->money('MDL')->alignRight(),
Tables\Columns\TextColumn::make('fixed_price')->label('Preț fix')->money('MDL')->alignRight()
->placeholder('—')->toggleable(),
Tables\Columns\TextColumn::make('laborParts_count')->counts('laborParts')->label('Piese impl.')->alignRight()->toggleable(),
Tables\Columns\IconColumn::make('is_active')->label('Activă')->boolean(),
])
->filters([
@@ -73,6 +90,13 @@ class LaborResource extends Resource
->defaultGroup('category');
}
public static function getRelations(): array
{
return [
RelationManagers\DefaultPartsRelationManager::class,
];
}
public static function getPages(): array
{
return [