@php /** @var \App\Models\Tenant\WorkOrder $wo */ $wo = $this->record; $finance = $this->getFinance(); $history = $this->getRepairHistory(); $timeline = $this->getTimeline(); $messages = $this->getNotifications(); $prev = $this->getPrevWo(); $next = $this->getNextWo(); $tabs = [ 'works' => ['label' => __('Lucrări'), 'count' => $wo->works->count()], 'parts' => ['label' => __('Piese'), 'count' => $wo->parts->count()], 'diag' => ['label' => __('Diagnostic'), 'count' => null], 'photos' => ['label' => __('Foto'), 'count' => $wo->getMedia('photos')->count() ?? 0], 'docs' => ['label' => __('Documente'), 'count' => null], 'notes' => ['label' => __('Note'), 'count' => null], ]; $statusClass = match ($wo->status) { 'in_work' => 'wd-status-active', 'awaiting_parts' => 'wd-status-warn', 'ready' => 'wd-status-ready', 'done' => 'wd-status-done', 'cancelled' => 'wd-status-cancel', default => 'wd-status-new', }; @endphp
{{-- ── TOP BAR ── --}}
{{ __('Fișă') }} {{ $wo->number }} {{ __(\App\Models\Tenant\WorkOrder::STATUSES[$wo->status] ?? $wo->status) }}
✎ {{ __('Editează') }} @if ($wo->tracking_token) 🔗 {{ __('Link tracking') }} @endif
{{-- ── META HEADER ── --}}
{{ __('Data creării') }} {{ $wo->created_at?->format('d.m.Y H:i') ?? '—' }}
{{ __('Deschis') }} {{ $wo->opened_at?->format('d.m.Y H:i') ?? '—' }}
{{ __('ETA') }} {{ $wo->eta_at?->format('d.m.Y H:i') ?? '—' }}
{{ __('Responsabil') }} @if ($wo->master) {{ mb_strtoupper(mb_substr($wo->master->name, 0, 2)) }} {{ $wo->master->name }} @else — @endif
{{ __('Urgență') }} {{ __(\App\Models\Tenant\PricingCoefficient::URGENCY[$wo->urgency ?? 'normal'] ?? 'Normal') }}
{{ __('Data plății') }} {{ $wo->paidAmount() > 0 ? number_format($wo->paidAmount(), 2, '.', ' ') . ' MDL' : '—' }}
{{-- ── 3-COLUMN BODY ── --}}
{{-- ═══ LEFT SIDEBAR ═══ --}}
{{-- CLIENT CARD --}}

{{ __('Client') }}

@if ($wo->client) {{ __('Editează') }} @endif
@if ($wo->client)
{{ mb_strtoupper(mb_substr($wo->client->name, 0, 1)) }}
{{ $wo->client->name }}
@if ($wo->client->phone) 📞 {{ $wo->client->phone }} @endif @if ($wo->client->email) {{ $wo->client->email }} @endif
@if (! empty($wo->client->status)) {{ __(ucfirst($wo->client->status)) }} @endif @php $totalOrders = \App\Models\Tenant\WorkOrder::where('client_id', $wo->client_id)->count(); $totalSpent = (float) \App\Models\Tenant\WorkOrder::where('client_id', $wo->client_id)->sum('total'); $debt = (float) $wo->client->balance; @endphp
{{ __('Vizite') }}
{{ $totalOrders }}
{{ __('Total') }}
{{ number_format($totalSpent, 0, '.', ' ') }}
{{ __('Datorie') }}
{{ number_format($debt, 0, '.', ' ') }}
@else
{{ __('Fără client') }}
@endif
{{-- VEHICLE CARD --}}

{{ __('Automobil') }}

@if ($wo->vehicle) {{ __('Editează') }} @endif
@if ($wo->vehicle) @php $photoUrl = method_exists($wo->vehicle, 'getFirstMediaUrl') ? ($wo->vehicle->getFirstMediaUrl('photos') ?: null) : null; @endphp @if ($photoUrl) {{ $wo->vehicle->make }} @else
🚗
@endif
{{ $wo->vehicle->make }} {{ $wo->vehicle->model }} {{ $wo->vehicle->year }}
@if ($wo->vehicle->plate)
{{ __('Nr.') }}
{{ $wo->vehicle->plate }}
@endif @if ($wo->vehicle->vin)
VIN
{{ $wo->vehicle->vin }}
@endif @if ($wo->vehicle->mileage)
{{ __('Km') }}
{{ number_format($wo->vehicle->mileage, 0, '.', ' ') }}
@endif @if ($wo->vehicle->engine)
{{ __('Motor') }}
{{ $wo->vehicle->engine }}
@endif @if ($wo->vehicle->gearbox)
{{ __('Cutie') }}
{{ $wo->vehicle->gearbox }}
@endif
@else
{{ __('Fără mașină') }}
@endif
{{-- REPAIR HISTORY --}}

{{ __('Istoric reparații') }}

@forelse ($history as $h)
{{ $h->opened_at?->format('d.m.Y') }} {{ $h->number }} {{ number_format($h->total, 0, '.', ' ') }} MDL
@empty
{{ __('Prima vizită') }}
@endforelse
{{-- ═══ MIDDLE: TABS ═══ --}}
@foreach ($tabs as $key => $t) @endforeach
{{-- ── WORKS TAB ── --}}
@if ($wo->works->isNotEmpty()) @foreach ($wo->works as $i => $w) @endforeach
# {{ __('Manoperă') }} {{ __('Ore') }} {{ __('Mecanic') }} {{ __('Preț/h') }} {{ __('Total') }} {{ __('Status') }}
{{ $i + 1 }} {{ $w->labor?->label() ?: $w->name }} {{ rtrim(rtrim(number_format($w->hours, 2), '0'), '.') }} {{ $w->master?->name ?? '—' }} {{ number_format($w->price_per_hour, 2, '.', ' ') }} {{ number_format($w->total, 2, '.', ' ') }} {{ __(\App\Models\Tenant\WorkOrderWork::STATUSES[$w->status] ?? $w->status) }}
@else
{{ __('Nicio manoperă efectuată.') }}
@endif
{{-- ── PARTS TAB ── --}}
@if ($wo->parts->isNotEmpty()) @foreach ($wo->parts as $p) @endforeach
{{ __('Cod') }} {{ __('Denumire') }} {{ __('Brand') }} {{ __('Cant.') }} {{ __('Preț') }} {{ __('Total') }} {{ __('Status') }}
{{ $p->article ?? '—' }} {{ $p->name }} {{ $p->brand ?? '—' }} {{ rtrim(rtrim(number_format($p->qty, 2), '0'), '.') }} {{ $p->unitLabel() ?: '' }} {{ number_format($p->sell_price, 2, '.', ' ') }} {{ number_format($p->total, 2, '.', ' ') }} {{ __(\App\Models\Tenant\WorkOrderPart::STATUSES[$p->status] ?? $p->status) }}
@else
{{ __('Nicio piesă montată.') }}
@endif
{{-- ── DIAGNOSTIC TAB ── --}}

{{ __('Plângere client') }}

{{ $wo->complaint ?: '—' }}

{{ __('Diagnostic') }}

{{ $wo->diagnosis ?: '—' }}
{{-- ── PHOTOS TAB ── --}}
@php $photos = $wo->getMedia('photos'); @endphp @if ($photos->isNotEmpty())
@foreach ($photos as $ph) @endforeach
@else
{{ __('Nicio fotografie') }}
@endif
{{-- ── DOCUMENTS TAB ── --}}
📄 {{ __('Descarcă factură (PDF)') }} @php $signed = $wo->getMedia('signed_documents'); @endphp @if ($signed->isNotEmpty())
{{ __('Documente semnate') }}
@foreach ($signed as $doc) 📎 {{ $doc->name }} ({{ round($doc->size / 1024) }} KB) @endforeach @else
{{ __('Niciun document semnat încă. Poți încărca documente din formularul de editare al fișei.') }}
@endif
{{-- ── NOTES TAB ── --}}
{{ $wo->notes ?: __('Nicio notă internă.') }}
{{-- ═══ RIGHT COLUMN (placeholder — Phase 2) ═══ --}}

{{ __('Finanțe') }}

{{ __('Cost manopere') }} {{ number_format($finance['works_sum'], 2, '.', ' ') }}
{{ __('Cost piese') }} {{ number_format($finance['parts_sum'], 2, '.', ' ') }}
@if ($finance['discount'] > 0)
{{ __('Discount') }} −{{ number_format($finance['discount'], 2, '.', ' ') }}
@endif
{{ __('Total') }} {{ number_format($finance['total'], 2, '.', ' ') }} MDL
{{ __('Achitat') }} {{ number_format($finance['paid'], 2, '.', ' ') }}
@if ($finance['balance'] > 0)
{{ __('Rest de plată') }} {{ number_format($finance['balance'], 2, '.', ' ') }} MDL
@endif
{{-- TIMELINE --}}

{{ __('Timeline') }}

@if (! empty($timeline))
@foreach ($timeline as $ev)
{{ $ev['icon'] }}
{{ $ev['label'] }}
{{ $ev['at']->format('d.m.Y H:i') }} @if ($ev['meta']) · {{ $ev['meta'] }} @endif
@endforeach
@else
{{ __('Fără evenimente') }}
@endif
{{-- CHAT CLIENT --}} @php $tenantSettings = (array) (app(\App\Tenancy\TenantManager::class)->current()?->settings ?? []); $integrations = (array) ($tenantSettings['integrations'] ?? []); $telegramEnabled = (bool) data_get($integrations, 'telegram_bot.enabled') && filled(data_get($integrations, 'telegram_bot.fields.bot_token')); $whatsappEnabled = (bool) data_get($integrations, 'whatsapp_business.enabled') && filled(data_get($integrations, 'whatsapp_business.fields.token')); $messagingConfigured = $telegramEnabled || $whatsappEnabled; @endphp

{{ __('Chat client') }}

@if ($telegramEnabled && $wo->client?->telegram_chat_id) ✓ Telegram @elseif ($whatsappEnabled && $wo->client?->phone) ✓ WhatsApp @endif
@if (! $messagingConfigured)
{{ __('Mesageria nu este configurată.') }}
@elseif (! $wo->client)
{{ __('Fișa nu are client asociat.') }}
@else
@forelse ($messages as $m)
{{ strtoupper($m->channel) }} {{ $m->sent_at?->format('d.m H:i') }} @if ($m->status === 'failed')✕ {{ __('Eșuat') }}@endif
{{ $m->message_text }}
@empty
{{ __('Nicio conversație') }}
@endforelse
@endif
{{-- ── BOTTOM ACTION BAR ── --}}
📄 {{ __('Comandă repetată') }} @if ($wo->status !== 'done') @endif