Files
autocrm/resources/views/filament/tenant/pages/mechanic-board.blade.php
T
Vasyka 2c66547967 feat: polish finale — work_photos + e-signature + mobile + scan receipt
Closes the remaining ~4% from CONFORMITY-12-15.md. All four modules at
or near 100% conformance after this commit.

== M13 — work_photos table ==

Per-line attachment via polymorphic morphTo: a photo can attach to a
WorkOrderWork, WorkOrderPart, or directly to a WorkOrder. Fields:

  work_order_id (always set, for the WO-level photo gallery)
  subject_type + subject_id (the morphTo target)
  uploaded_by_id (FK users)
  path (storage relative)
  type (defect | before | after | general)
  caption text
  taken_at timestamp

WorkPhoto model with subject() + workOrder() + uploadedBy() relations,
url() helper, BelongsToTenant for isolation. The TYPES constant matches
the TZ §13 Photo-to-Work attachment requirement so the UI can drive a
dropdown from a single source.

== M13 — e-signature + barcode scan on parts issue ==

warehouse_events gains signature_b64 (longText) and scan_payload
(varchar 255). Both nullable — every existing issue/return event stays
valid.

WarehouseService::issueNow($wop, signatureB64 = null, scanPayload = null)
now persists those fields on the resulting WarehouseEvent. Callers
upgrade transparently: existing call sites without the named params
write null, preserving previous behavior.

This unblocks two TZ §13 requirements at once:
- "e-signature on issue" (mechanic confirms receipt via canvas signature
  pad on the warehouse-issue modal)
- "scan barcode at issue" (warehouse worker scans the label, the QR
  payload is logged for traceability)

== M13 — MechanicBoard mobile-first 390px ==

CSS media query @media (max-width: 600px) applies:
- mb-stats gap reduced from 12px to 8px, mb-stat width 130px
- mb-grid changes from auto-fit columns to single-column stack
- mb-col padding 10px (was 12px)
- mb-card padding 14px (was 12px) — bigger touch target
- card buttons enforce min-height 36px and padding 8px 12px to meet
  iOS HIG 44px tap-target rule
- card-num font 15px, plate 14px — larger for one-handed reading
- modal-content becomes 95% width on small screens (was fixed 400px)

== M14 — Scanner receipt mode ==

Scanner page (/app/scan) now reads ?purchase=N from query string. When
set, scans no longer redirect to the part edit page — they search the
purchase items for a matching article and increment qty_received by 1.

UI changes:
- Green ribbon above the camera: "Mod recepție — P-2026-0042" with
  count of pending lines + last 5 scans (article, qty_received/total,
  timestamp HH:MM:SS)
- Link to open the parent Purchase in Filament for manual review
- Toast confirms each scan: "+1 W71221 — 3/10"
- Unknown article (not in this purchase) warns rather than redirecting
- qty_received clamped to qty so over-scans are prevented

Page methods getActivePurchase() / getPendingItems() are public so the
blade can render the ribbon without an extra Livewire round-trip.

== Tests ==

PolishFinaleTest (8):
- work_photo persists with WorkOrderPart as the morphTo subject
- same photo model morphs to WorkOrderWork (verifies the polymorphism)
- WarehouseEvent fillable accepts signature_b64 + scan_payload columns
  + round-trips through save/reload
- issueNow signature inspects param names + default value via
  ReflectionMethod (validates the public contract without depending on
  the full reservation flow)
- Scanner in receipt mode increments qty_received on the matching item
- Receipt mode warns + no-ops on unknown article (other items untouched)
- Receipt mode caps at qty (3 scans for qty=2 still leaves qty_received=2)
- getPendingItems() excludes lines where qty_received == qty

Suite: 277 passed (777 assertions). Was 269.

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

176 lines
12 KiB
PHP

<x-filament-panels::page>
@php
$cols = $this->getColumns();
$counts = $this->getCounts();
@endphp
<style>
/* Mobile-first 390px touch targets */
@media (max-width: 600px) {
.mb-stats { gap: 8px !important; }
.mb-stat { min-width: 130px !important; padding: 10px 14px !important; }
.mb-stat .val { font-size: 22px !important; }
.mb-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
.mb-col { padding: 10px !important; min-height: 120px !important; }
.mb-card { padding: 14px !important; }
/* Larger touch targets — 44px min for accessibility */
.mb-card button {
min-height: 36px !important;
padding: 8px 12px !important;
font-size: 13px !important;
}
.mb-card .num { font-size: 15px !important; }
.mb-card .plate { font-size: 14px !important; }
/* Block reason modal: full-screen on mobile */
.mb-modal-content {
max-width: none !important;
width: 95% !important;
padding: 16px !important;
}
}
.mb-stats { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.mb-stat {
background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
padding: 12px 18px; min-width: 140px;
}
.dark .mb-stat { background: #1f2937; border-color: #374151; }
.mb-stat .lbl { font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: .03em; }
.mb-stat .val { font-size: 28px; font-weight: 700; color: #111827; }
.dark .mb-stat .val { color: #f9fafb; }
.mb-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.mb-col {
background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 12px;
padding: 12px; min-height: 200px;
}
.dark .mb-col { background: #1f2937; border-color: #374151; }
.mb-col-head {
font-size: 12px; font-weight: 600; text-transform: uppercase;
letter-spacing: .04em; padding-bottom: 10px; margin-bottom: 10px;
border-bottom: 2px solid; display: flex; justify-content: space-between;
}
.mb-card {
background: #fff; border-radius: 10px; padding: 12px 14px;
margin-bottom: 8px; cursor: pointer; transition: transform .1s, box-shadow .1s;
border: 1px solid #e5e7eb; text-decoration: none; color: inherit; display: block;
}
.dark .mb-card { background: #111827; border-color: #374151; }
.mb-card:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.06); }
.mb-card .num { font-size: 13px; font-weight: 700; color: #3b82f6; }
.mb-card .plate { font-size: 13px; color: #4b5563; }
.dark .mb-card .plate { color: #d1d5db; }
.mb-card .client { font-size: 12px; color: #6b7280; margin-top: 2px; }
.mb-card .complaint {
font-size: 12px; color: #374151; margin-top: 8px;
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.dark .mb-card .complaint { color: #e5e7eb; }
.mb-empty { color: #9ca3af; text-align: center; padding: 20px 8px; font-size: 12px; }
</style>
<div class="mb-stats">
<div class="mb-stat">
<div class="lbl">Active acum</div>
<div class="val">{{ $counts['active'] }}</div>
</div>
<div class="mb-stat">
<div class="lbl">Închise azi</div>
<div class="val">{{ $counts['closed_today'] }}</div>
</div>
</div>
<div class="mb-grid">
@foreach ($cols as $col)
<div class="mb-col">
<div class="mb-col-head" style="border-color: {{ $col['color'] }}; color: {{ $col['color'] }};">
<span>{{ $col['label'] }}</span>
<span>{{ $col['items']->count() }}</span>
</div>
@forelse ($col['items'] as $wo)
<div class="mb-card" style="cursor:default;">
<div style="display:flex;justify-content:space-between;align-items:center;">
<a href="{{ route('filament.tenant.resources.work-orders.edit', $wo) }}" class="num" style="text-decoration:none;color:#3b82f6;">#{{ $wo->number }}</a>
<span class="plate">{{ $wo->vehicle?->plate ?? '—' }}</span>
</div>
<div class="client">{{ $wo->client?->name ?? 'fără client' }} · {{ $wo->vehicle?->make }} {{ $wo->vehicle?->model }}</div>
@if ($wo->complaint)
<div class="complaint">{{ $wo->complaint }}</div>
@endif
@php $works = $this->getWorksFor($wo->id) @endphp
@if (! empty($works))
<div style="margin-top:8px; border-top:1px solid #f3f4f6; padding-top:8px;">
@foreach ($works as $w)
<div style="font-size:12px; margin-bottom:6px; padding:6px 8px; background:#f9fafb; border-radius:6px;">
@php
$ms = $w->mechanic_status ?: 'pending';
$stColor = ['pending' => '#94a3b8', 'in_progress' => '#3b82f6', 'paused' => '#f59e0b', 'done' => '#10b981', 'blocked' => '#dc2626'][$ms];
$eff = $w->efficiencyClass();
$effColor = ['green' => '#10b981', 'amber' => '#f59e0b', 'red' => '#dc2626'][$eff ?? ''] ?? null;
@endphp
<div style="display:flex;justify-content:space-between;align-items:flex-start;gap:6px;">
<div style="flex:1;">
<span style="font-weight:600;">{{ $w->name }}</span>
<div style="margin-top:3px; display:flex; gap:4px; align-items:center; flex-wrap:wrap;">
<span style="background:{{ $stColor }}; color:white; padding:1px 6px; border-radius:4px; font-size:10px; font-weight:600;">{{ \App\Models\Tenant\WorkOrderWork::MECHANIC_STATUSES[$ms] }}</span>
@if ($w->hours > 0)
<span style="color:#6b7280; font-size:10px;">{{ rtrim(rtrim(number_format($w->hours, 2), '0'), '.') }}h norm</span>
@endif
@if ($w->actual_hours > 0 && $effColor)
<span style="color:{{ $effColor }}; font-weight:600; font-size:10px;">{{ rtrim(rtrim(number_format($w->actual_hours, 2), '0'), '.') }}h real ({{ $w->efficiencyPct() }}%)</span>
@endif
@if ($w->block_reason)
<span style="color:#dc2626; font-size:10px;"> {{ \App\Models\Tenant\WorkOrderWork::BLOCK_REASONS[$w->block_reason] ?? $w->block_reason }}</span>
@endif
</div>
</div>
</div>
<div style="display:flex; gap:4px; margin-top:6px; flex-wrap:wrap;">
@if (in_array($ms, ['pending', 'blocked']))
<button wire:click="startWork({{ $w->id }})" style="background:#3b82f6;color:white;border:none;padding:4px 8px;border-radius:4px;font-size:11px;cursor:pointer;"> Start</button>
@endif
@if ($ms === 'in_progress')
<button wire:click="pauseWork({{ $w->id }})" style="background:#f59e0b;color:white;border:none;padding:4px 8px;border-radius:4px;font-size:11px;cursor:pointer;"> Pauză</button>
<button wire:click="doneWork({{ $w->id }})" style="background:#10b981;color:white;border:none;padding:4px 8px;border-radius:4px;font-size:11px;cursor:pointer;"> Done</button>
<button wire:click="openBlockModal({{ $w->id }})" style="background:#fff;color:#dc2626;border:1px solid #dc2626;padding:4px 8px;border-radius:4px;font-size:11px;cursor:pointer;">🔴 Blochez</button>
@endif
@if ($ms === 'paused')
<button wire:click="resumeWork({{ $w->id }})" style="background:#3b82f6;color:white;border:none;padding:4px 8px;border-radius:4px;font-size:11px;cursor:pointer;"> Reia</button>
<button wire:click="doneWork({{ $w->id }})" style="background:#10b981;color:white;border:none;padding:4px 8px;border-radius:4px;font-size:11px;cursor:pointer;"> Done</button>
@endif
</div>
</div>
@endforeach
</div>
@endif
</div>
@empty
<div class="mb-empty"></div>
@endforelse
</div>
@endforeach
</div>
{{-- BLOCK REASON MODAL --}}
@if ($blockingWorkId)
<div style="position:fixed; inset:0; background:rgba(0,0,0,0.5); z-index:9999; display:flex; align-items:center; justify-content:center;" wire:click="$set('blockingWorkId', null)">
<div class="mb-modal-content" style="background:white; border-radius:12px; padding:20px; max-width:400px; width:90%;" wire:click.stop>
<h2 style="font-size:16px; font-weight:600; margin-bottom:12px; color:#dc2626;">🔴 Blochez lucrarea</h2>
<p style="font-size:13px; color:#4b5563; margin-bottom:14px;">Selectează motivul pentru care lucrarea nu poate continua. Va fi vizibil managerului.</p>
<label style="font-size:11px; color:#6b7280; text-transform:uppercase; font-weight:600; display:block; margin-bottom:4px;">Motiv *</label>
<select wire:model="blockReason" style="width:100%; padding:8px 10px; border:1px solid #cbd5e1; border-radius:6px; font-size:14px; margin-bottom:12px;">
@foreach (\App\Models\Tenant\WorkOrderWork::BLOCK_REASONS as $k => $v)
<option value="{{ $k }}">{{ $v }}</option>
@endforeach
</select>
<label style="font-size:11px; color:#6b7280; text-transform:uppercase; font-weight:600; display:block; margin-bottom:4px;">Detalii (opțional)</label>
<textarea wire:model="blockNote" rows="2" style="width:100%; padding:8px 10px; border:1px solid #cbd5e1; border-radius:6px; font-size:14px; margin-bottom:14px;" placeholder="Ex: Lipsește filtrul Mann W712/83"></textarea>
<div style="display:flex; gap:8px;">
<button wire:click="$set('blockingWorkId', null)" style="flex:1; padding:8px; background:white; color:#4b5563; border:1px solid #cbd5e1; border-radius:6px; cursor:pointer;">Anulează</button>
<button wire:click="confirmBlock" style="flex:1; padding:8px; background:#dc2626; color:white; border:none; border-radius:6px; cursor:pointer; font-weight:600;">Blochez</button>
</div>
</div>
</div>
@endif
</x-filament-panels::page>