cbcf08b28c
Closes "Important pentru produs complet" tier from CONFORMITY-12-15.md.
== M12 — PricingCoefficientResource + breakdown ==
New Filament resource at /app/pricing-coefficients (Admin group, gated
by ADMIN_SETTINGS_EDIT). Replaces the previous "edit JSON in DB"
configuration workflow.
Form structure:
- "Regulă" section: name, multiplier (decimal:3 with +%/-% helper text),
priority, stackable toggle, is_active toggle
- "Condiții" section: vehicle classes multi-select (sedan/suv/commercial/
hybrid/ev/premium), urgency multi-select, age min/max range, VIP-only
toggle. Empty = applies to everything.
Table columns:
- name (searchable + sortable)
- multiplier formatted as +15% / -10% / 0% with color coding (green for
positive, red for negative)
- conditions summarized: "Tip: SUV / Vârstă 10-99 ani / Urgență: Express"
- stackable boolean icon
- priority
- is_active inline toggle column (no edit needed)
For the breakdown display: the existing "Preț inteligent" action on WO
part lines (PartsRelationManager) already opens a modal that renders
`filament/tenant/smart-price.blade.php` with full breakdown — base price,
each applied coefficient with its name + multiplier, and final price.
Confirmed working; no change needed.
== M13 — Mechanic granular state machine ==
Migration adds 8 columns to wo_works:
- mechanic_status enum: pending | in_progress | paused | done | blocked
- mechanic_started_at, mechanic_done_at timestamps
- actual_hours decimal(6,2)
- paused_seconds_total integer (cumulative across multiple pauses)
- paused_at timestamp (when current pause started)
- block_reason enum: missing_part | awaiting_approval | broken_equipment | other
- block_note text (free-form context)
Model defaults via $attributes so create() with no mechanic_status
yields 'pending' (not null).
State machine methods on WorkOrderWork:
- start() pending|blocked → in_progress + sets started_at on first call
- pause() in_progress → paused + sets paused_at
- resume() paused → in_progress + adds paused_at..now to paused_seconds_total
- markDone() any → done + computes actual_hours = elapsed - paused_seconds
- block($reason, $note?) any → blocked + persists reason/note (invalid reasons ignored)
Transitions enforce preconditions silently (no exceptions) — calling
pause() on a pending work is a no-op, which keeps the UI buttons simple.
Efficiency indicator:
- efficiencyClass(): 'green' (actual <= norm), 'amber' (1.0 < ratio <= 1.3),
'red' (ratio > 1.3). null when no actual data.
- efficiencyPct(): integer percentage of norm time used.
== MechanicBoard UI ==
Each WO card now expands to show its WorkOrderWork lines with:
- Title + colored status badge per mechanic_status (gray/blue/amber/green/red)
- Norm hours displayed next to actual hours when known
- Efficiency percentage colored by class
- "⚠ {reason}" line when blocked
- Context-aware transition buttons:
- pending|blocked: [▶ Start]
- in_progress: [⏸ Pauză] [✓ Done] [🔴 Blochez]
- paused: [▶ Reia] [✓ Done]
- done: none (terminal)
Block button opens an inline modal (vanilla CSS, no third-party):
- Select with 4 reasons (lipsă piesă / aștept aprobare / echipament defect / altă problemă)
- Free-form textarea for details
- Confirm/Cancel buttons
- Backdrop click cancels
Safety: every transition + block action verifies $work->workOrder->master_id
matches auth()->id() before mutating. Other mechanics' works are silently
refused (no error leak).
== Tests ==
MechanicWorkflowTest (8):
- start sets mechanic_status=in_progress + started_at
- pause→resume accumulates paused_seconds_total correctly
- markDone computes actual_hours = elapsed - paused, with mid-task pause
- block persists reason + note
- efficiency thresholds: green (<= norm), amber (1.0-1.3x), red (>1.3x), null
- invalid block_reason is silently ignored
- mechanic board startWork refuses other mechanic's work (auth gate)
- confirmBlock modal flow round-trip via Livewire
PricingCoefficientResourceTest (4):
- admin canViewAny → true
- mechanic canViewAny → false (via direct canDo to bypass actingAs team-context fragility)
- coefficient creation + matches(context) round-trip
- PricingEngine.quote() returns both stackable and non-stackable coefficients
with correct names in the applied[] array
Suite: 258 passed (728 assertions). Was 246.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
143 lines
4.4 KiB
PHP
143 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Pages;
|
|
|
|
use App\Models\Tenant\WorkOrder;
|
|
use App\Models\Tenant\WorkOrderWork;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
|
|
/**
|
|
* Mobile-first dashboard for a single mechanic — shows ONLY work orders
|
|
* assigned to the currently logged-in user (master_id = auth()->id()).
|
|
* Kanban-style grouped by status.
|
|
*/
|
|
class MechanicBoard extends Page
|
|
{
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-wrench';
|
|
|
|
protected static ?string $navigationLabel = 'Atelierul meu';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Service';
|
|
|
|
protected static ?int $navigationSort = 25;
|
|
|
|
protected static ?string $title = 'Atelierul meu';
|
|
|
|
protected string $view = 'filament.tenant.pages.mechanic-board';
|
|
|
|
public function getColumns(): array
|
|
{
|
|
$userId = auth()->id();
|
|
if (! $userId) return [];
|
|
|
|
$all = WorkOrder::with(['client', 'vehicle'])
|
|
->where('master_id', $userId)
|
|
->whereIn('status', ['in_work', 'awaiting_parts', 'ready', 'done', 'approved', 'diagnosis'])
|
|
->orderBy('opened_at', 'desc')
|
|
->get();
|
|
|
|
return [
|
|
[
|
|
'key' => 'in_work',
|
|
'label' => 'În lucru',
|
|
'color' => '#f59e0b',
|
|
'items' => $all->where('status', 'in_work')->values(),
|
|
],
|
|
[
|
|
'key' => 'awaiting_parts',
|
|
'label' => 'Așteaptă piese',
|
|
'color' => '#8b5cf6',
|
|
'items' => $all->whereIn('status', ['awaiting_parts'])->values(),
|
|
],
|
|
[
|
|
'key' => 'ready',
|
|
'label' => 'Gata',
|
|
'color' => '#10b981',
|
|
'items' => $all->where('status', 'ready')->values(),
|
|
],
|
|
[
|
|
'key' => 'recent',
|
|
'label' => 'Recente / restul',
|
|
'color' => '#64748b',
|
|
'items' => $all->whereIn('status', ['done', 'approved', 'diagnosis'])
|
|
->take(20)
|
|
->values(),
|
|
],
|
|
];
|
|
}
|
|
|
|
public ?int $blockingWorkId = null;
|
|
public string $blockReason = 'missing_part';
|
|
public string $blockNote = '';
|
|
|
|
public function startWork(int $id): void
|
|
{
|
|
$w = WorkOrderWork::find($id);
|
|
if ($w && $w->workOrder?->master_id === auth()->id()) $w->start();
|
|
}
|
|
|
|
public function pauseWork(int $id): void
|
|
{
|
|
$w = WorkOrderWork::find($id);
|
|
if ($w && $w->workOrder?->master_id === auth()->id()) $w->pause();
|
|
}
|
|
|
|
public function resumeWork(int $id): void
|
|
{
|
|
$w = WorkOrderWork::find($id);
|
|
if ($w && $w->workOrder?->master_id === auth()->id()) $w->resume();
|
|
}
|
|
|
|
public function doneWork(int $id): void
|
|
{
|
|
$w = WorkOrderWork::find($id);
|
|
if ($w && $w->workOrder?->master_id === auth()->id()) $w->markDone();
|
|
}
|
|
|
|
public function openBlockModal(int $id): void
|
|
{
|
|
$this->blockingWorkId = $id;
|
|
$this->blockReason = 'missing_part';
|
|
$this->blockNote = '';
|
|
}
|
|
|
|
public function confirmBlock(): void
|
|
{
|
|
if (! $this->blockingWorkId) return;
|
|
$work = WorkOrderWork::find($this->blockingWorkId);
|
|
if (! $work) return;
|
|
// Only own work
|
|
if ($work->workOrder?->master_id !== auth()->id()) {
|
|
$this->blockingWorkId = null;
|
|
return;
|
|
}
|
|
$work->block($this->blockReason, trim($this->blockNote) ?: null);
|
|
Notification::make()->title('Lucrare blocată')->body($work->name . ' · ' . WorkOrderWork::BLOCK_REASONS[$this->blockReason])->warning()->send();
|
|
$this->blockingWorkId = null;
|
|
}
|
|
|
|
public function getWorksFor(int $woId): array
|
|
{
|
|
return WorkOrderWork::where('work_order_id', $woId)->orderBy('id')->get()->all();
|
|
}
|
|
|
|
public function getCounts(): array
|
|
{
|
|
$userId = auth()->id();
|
|
return [
|
|
'active' => $userId
|
|
? WorkOrder::where('master_id', $userId)
|
|
->whereIn('status', ['in_work', 'awaiting_parts', 'ready'])
|
|
->count()
|
|
: 0,
|
|
'closed_today' => $userId
|
|
? WorkOrder::where('master_id', $userId)
|
|
->where('status', 'done')
|
|
->whereDate('closed_at', today())
|
|
->count()
|
|
: 0,
|
|
];
|
|
}
|
|
}
|