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:
@@ -15,6 +15,26 @@ class EditWorkOrder extends EditRecord
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('apply_template')
|
||||
->label('Aplică șablon')
|
||||
->icon('heroicon-m-clipboard-document-list')
|
||||
->color('gray')
|
||||
->schema([
|
||||
\Filament\Forms\Components\Select::make('template_id')
|
||||
->label('Șablon serviciu')
|
||||
->options(fn () => \App\Models\Tenant\ServiceTemplate::where('is_active', true)->pluck('name', 'id'))
|
||||
->searchable()
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$template = \App\Models\Tenant\ServiceTemplate::with('items')->find($data['template_id']);
|
||||
if (! $template) return;
|
||||
$r = app(\App\Services\ServiceComposer::class)->applyTemplate($this->record, $template);
|
||||
$this->fillForm();
|
||||
\Filament\Notifications\Notification::make()
|
||||
->title("Șablon aplicat: {$r['labor']} manopere, {$r['parts']} piese")
|
||||
->success()->send();
|
||||
}),
|
||||
Actions\Action::make('ai_diagnose')
|
||||
->label('AI: sugerează diagnostic')
|
||||
->icon('heroicon-m-sparkles')
|
||||
|
||||
+17
-1
@@ -69,7 +69,23 @@ class WorksRelationManager extends RelationManager
|
||||
->colors(['gray' => ['todo'], 'warning' => ['in_progress'], 'success' => ['done']]),
|
||||
])
|
||||
->headerActions([
|
||||
Actions\CreateAction::make(),
|
||||
Actions\CreateAction::make()
|
||||
->after(function (WorkOrderWork $record) {
|
||||
// Auto-add the labor's default parts to the parent WO.
|
||||
if (! $record->labor_id) return;
|
||||
$labor = Labor::with('laborParts.part')->find($record->labor_id);
|
||||
$wo = $record->workOrder;
|
||||
if (! $labor || ! $wo || $labor->laborParts->isEmpty()) return;
|
||||
$composer = app(\App\Services\ServiceComposer::class);
|
||||
foreach ($labor->laborParts as $lp) {
|
||||
if ($lp->part) {
|
||||
$composer->addPart($wo, $lp->part, (float) $lp->qty, $lp->unit);
|
||||
}
|
||||
}
|
||||
\Filament\Notifications\Notification::make()
|
||||
->title('Piese implicite adăugate (' . $labor->laborParts->count() . ')')
|
||||
->success()->send();
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
Actions\EditAction::make(),
|
||||
|
||||
Reference in New Issue
Block a user