@extends('layouts.app') @section('title', $order->order_number) @section('content')

{{ $order->order_number }} @include('work-orders.partials.status-badge', ['order' => $order]) @if($order->priority !== 'normal') {{ ucfirst($order->priority) }} @endif

{{ $order->typeLabel() }}

@if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif @if($errors->any())
@endif {{-- The state banner. `completed` is called out explicitly because it is the one status that looks finished and is not. --}} @if($order->status === 'completed')
Waiting on the office. {{ $order->completedBy?->name ?? 'The field worker' }} marked this done {{ $order->completed_at?->diffForHumans() }}. It is not closed until someone verifies it. @if($order->requiresFinalReading() && $order->meterReading) Verifying will approve the final reading of {{ rtrim(rtrim(number_format($order->meterReading->reading_value, 2), '0'), '.') }} and raise the closing bill. @endif
@elseif($order->status === 'rejected')
Sent back. {{ $order->rejection_reason }}
@elseif($order->status === 'cancelled')
Cancelled by {{ $order->cancelledBy?->name ?? 'the office' }} on {{ $order->cancelled_at?->format('M d, Y g:i A') }}. @if($order->cancellation_reason) — {{ $order->cancellation_reason }} @endif
@elseif($order->status === 'verified')
Verified and closed by {{ $order->verifiedBy?->name }} on {{ $order->verified_at?->format('M d, Y g:i A') }}. @if($order->verification_notes) — {{ $order->verification_notes }} @endif
@endif
Connection
@if($order->client)
{{ $order->client->name }} @if($order->client->status === 'disconnected') Disconnected @endif
Account {{ $order->client->account_number }} · Meter {{ $order->client->meter_number ?: '—' }}
{{ $order->address ?: $order->client->full_address }}
View client
{{-- Two balances on purpose: what the office saw when it raised the job, and what is owed now. A reconnection raised in error has to be explainable after the customer has paid. --}}
Owed when raised
{{ $order->outstanding_balance_snapshot !== null ? '₱' . number_format($order->outstanding_balance_snapshot, 2) : '—' }}
Owed now
₱{{ number_format($order->client->outstanding_balance, 2) }}
@else No client attached to this job. @endif
{{-- Where the job came from. A disconnection raised off an overdue billing has to lead back to that billing, because verifying the job is what moves the billing's own disconnection status. --}} @if($source)
Raised from
@if($order->source_type === \App\Models\WorkOrder::SOURCE_BILLING) Billing {{ $source->billing_number }} — ₱{{ number_format($source->total_amount_due, 2) }} due, ₱{{ number_format($source->balance, 2) }} outstanding. @if(!$order->isTerminal())
Verifying this job updates that billing's disconnection status.
@endif @elseif($order->source_type === \App\Models\WorkOrder::SOURCE_APPLICATION) New connection application {{ $source->reference_number }} for {{ $source->full_name }}. @if(!$order->isTerminal())
Verifying this job completes the application's installation step and makes the connection active.
@endif @endif
@endif @if($order->notes || $order->completion_notes)
Notes
@if($order->notes)
From the office
{{ $order->notes }}
@endif @if($order->completion_notes)
From the field
{{ $order->completion_notes }}
@endif
@endif @if($order->requiresFinalReading())
Final meter reading
@if($order->meterReading)
Reading
{{ rtrim(rtrim(number_format($order->meterReading->reading_value, 2), '0'), '.') }}
Taken {{ $order->meterReading->reading_date->format('M d, Y g:i A') }}
Reading status
@if($order->meterReading->status === 'draft') Draft — approved on verification @elseif($order->meterReading->status === 'approved') Approved @else {{ ucfirst($order->meterReading->status) }} @endif
@if($closingBilling)
Closing bill
{{ $closingBilling->billing_number }} — ₱{{ number_format($closingBilling->total_amount_due, 2) }}
@endif
@else

Not recorded yet. The meter is read before the water goes off — that reading is the last consumption this customer can be billed for, and the job cannot be completed without it. @if($readingFloor !== null)
Last approved reading: {{ rtrim(rtrim(number_format($readingFloor, 2), '0'), '.') }}. @endif

@endif
@endif
Actions
@forelse($actions as $action) @if($action === 'accept')
@csrf
@elseif($action === 'start')
@csrf
@elseif($action === 'complete') @elseif($action === 'verify') @elseif($action === 'reject') @elseif($action === 'assign') @elseif($action === 'cancel') @endif @empty

@if($order->isTerminal()) This job is closed. Nothing further to do. @elseif($isOffice && $order->status === 'completed' && $order->completed_by === auth()->id()) You completed this job, so someone else has to verify it. That separation is the whole point of the verification step. @else Nothing for you to do on this job right now. @endif

@endforelse
History
Raised
{{ optional($order->requested_at ?? $order->created_at)->format('M d, Y g:i A') }}
by {{ $order->requestedBy?->name ?? '—' }}
Scheduled
{{ $order->scheduled_date?->format('M d, Y') ?? '—' }}
Assigned to
{{ $order->assignee?->name ?? 'Unassigned' }}
Accepted
{{ $order->accepted_at?->format('M d, Y g:i A') ?? '—' }}
Started
{{ $order->started_at?->format('M d, Y g:i A') ?? '—' }}
Completed
{{ $order->completed_at?->format('M d, Y g:i A') ?? '—' }} @if($order->completedBy)
by {{ $order->completedBy->name }}@endif
Verified
{{ $order->verified_at?->format('M d, Y g:i A') ?? '—' }} @if($order->verifiedBy)
by {{ $order->verifiedBy->name }}@endif
{{-- Modals. Every one of these is re-parented to by the script below; see the comment there for why. --}} @if(in_array('complete', $actions)) @endif @if(in_array('verify', $actions)) @endif @if(in_array('reject', $actions)) @endif @if(in_array('assign', $actions)) @endif @if(in_array('cancel', $actions)) @endif @endsection @section('scripts') @endsection