@extends('layouts.app') @section('title', $order->order_no) @section('content') @php $client = $order->client; $cancelled = $order->isCancelled(); $paid = $order->paid(); $due = $cancelled ? 0 : $order->due(); $pct = (float) $order->total > 0 ? min(100, round($paid / (float) $order->total * 100)) : 0; $cost = $order->cost(); $netSales = (float) $order->total - (float) $order->tax_amount; $margin = $netSales - $cost; $marginPct = $netSales > 0 ? round($margin / $netSales * 100) : null; $flow = ['pending' => 'Pending', 'in_production' => 'In production', 'ready' => 'Ready', 'delivered' => 'Delivered']; $keys = array_keys($flow); $currentIdx = array_search($order->status, $keys, true); $nextKey = $currentIdx !== false ? ($keys[$currentIdx + 1] ?? null) : null; $days = $order->delivery_date ? (int) now()->startOfDay()->diffInDays($order->delivery_date->copy()->startOfDay(), false) : null; $late = ! in_array($order->status, ['delivered', 'cancelled']) && $days !== null && $days < 0; $deliveryNote = match (true) { $cancelled => 'Order cancelled', $order->status === 'delivered' => 'Delivered', $days === null => 'No date set', $days < 0 => abs($days).' '.\Illuminate\Support\Str::plural('day', abs($days)).' overdue', $days === 0 => 'Due today', default => 'In '.$days.' '.\Illuminate\Support\Str::plural('day', $days), }; $pcs = rtrim(rtrim(number_format($order->items->sum('quantity'), 2), '0'), '.'); $area = $order->items->sum(fn ($i) => $i->totalArea()); $phone = $client->phone; @endphp {{-- ===== Header ===== --}}

{{ $order->order_no }} @if ($late)Overdue@endif

{{ $client->name }} · Placed {{ $order->order_date->format('d M Y') }}
@unless ($cancelled) @can('payments.create') Receive payment @endcan @endunless @can('amounts.view') Invoice @endcan @can('orders.edit') Edit @endcan @canany(['orders.status', 'orders.delete']) @endcanany
{{-- ===== Progress ===== --}}
@if ($cancelled)
This order was cancelled
It is excluded from sales, receivables and reports. Use More → Reopen order to bring it back.
@else
    @foreach ($flow as $key => $label) @php($i = array_search($key, $keys, true))
  1. @if ($i < $currentIdx)@elseif ($i === $currentIdx)@endif
    {{ $label }}
  2. @endforeach
@can('orders.edit') @if ($nextKey)
@csrf @method('PATCH')
@endif @endcan
@endif
{{-- ===== Key figures ===== --}}
Order total
{{ money($order->total) }}
{{ $order->items->count() }} {{ \Illuminate\Support\Str::plural('item', $order->items->count()) }} · {{ $pcs }} pcs
Received
{{ money($paid) }}
{{ $pct }}% of total
Balance due
{{ money($due) }}
{{ $cancelled ? 'Order cancelled' : ($due > 0.004 ? ($paid > 0 ? 'Partly paid' : 'Nothing received yet') : 'Settled in full') }}
Delivery
{{ $order->delivery_date?->format('d M Y') ?? '—' }}
{{ $deliveryNote }}
{{-- ===== Side: client + delivery (first on phones, sticky on desktop) ===== --}}
{{ $client->name }}
{{ $client->location() ?: ($client->contact_person ?: 'Client') }}
@if ($client->contact_person)
Contact
{{ $client->contact_person }}
@endif
Phone
@if ($phone){{ $phone }}@else—@endif
@if ($client->email)
Email
{{ $client->email }}
@endif
Delivery & notes
Ship to
{!! nl2br(e($order->shipping_address ?: ($client->shipping_address ?: $client->billing_address ?: '—'))) !!}
Placed
{{ $order->order_date->format('d M Y') }}
Delivery
{{ $order->delivery_date?->format('d M Y') ?? '—' }}
Notes
@if ($order->notes){!! nl2br(e($order->notes)) !!}@else—@endif
{{-- ===== Main: items, payments, costs ===== --}}
Work progress & timeline
What was done, how much is finished, and when
{{ $progress }}% done
@can('orders.update') @unless ($cancelled)
any() || $drafts->isNotEmpty() ? 'open' : '' }}> Post an update
@include('partials.work-form', ['action' => route('orders.updates.store', $order), 'uploadUrl' => route('orders.photos.store', $order), 'discardUrl' => route('orders.photos.destroy', [$order, '__ID__']), 'progress' => $progress, 'drafts' => $drafts, 'completeUrl' => null])
@endunless @endcan @include('partials.work-timeline', ['updates' => $updates, 'showAssignment' => true])
Items {{ $pcs }} pcs @if ($area > 0){{ number_format($area, 2) }} sq ft@endif
@foreach ($order->items as $i) @php($spec = collect([$i->material, $i->color])->filter()->join(' · ')) @endforeach
DesignSizeQtyRateAmount
{{ $i->design_name }}@if ($spec){{ $spec }}@endif {{ $i->sizeText() ?: '—' }}@if ($i->area_sqft){{ number_format($i->area_sqft, 2) }} sq ft each@endif {{ rtrim(rtrim(number_format($i->quantity, 2), '0'), '.') }} pcs @if ($i->totalArea()){{ number_format($i->totalArea(), 2) }} sq ft@endif {{ $i->rateText() }}@if (! $i->isPerSqft() && $i->ratePerSqft())≈ {{ money($i->ratePerSqft()) }} / sq ft@endif {{ money($i->line_total) }}
@can('payments.view')
Payments received @if ($order->payments->isNotEmpty()){{ money($paid) }}@endif @unless ($cancelled)@can('payments.create') Add@endcan @endunless
@if ($order->payments->isEmpty())
No payments yet. Money received for this order will show up here.
@else
@foreach ($order->payments as $p) @endforeach
DateMethodReferenceAmount
@can('payments.edit'){{ $p->paid_on->format('d M Y') }}@else{{ $p->paid_on->format('d M Y') }}@endcan {{ \App\Models\Payment::METHODS[$p->method] ?? $p->method }} {{ $p->reference ?: '—' }} +{{ money($p->amount) }}
@endif
@endcan @can('vendor_assignments.view')
Vendor assignments @can('vendor_assignments.create') Assign to vendor@endcan
@if ($order->vendorAssignments->isEmpty())
Not assigned to any vendor yet.
@else
@foreach ($order->vendorAssignments as $x) @endforeach
VendorNo.AgreedExtraPaidBalance
{{ $x->vendor->name }} {{ $x->number() }} {{ money($x->assigned_amount) }} {{ $x->extra() > 0.004 ? money($x->extra()) : '—' }} {{ money($x->paid()) }} {{ money($x->due()) }}
@endif
@endcan @can('vendor_bills.view')
Vendor costs @if ($order->vendorBills->isNotEmpty()) Cost {{ money($cost) }} Margin {{ money($margin) }}@if ($marginPct !== null) · {{ $marginPct }}%@endif @endif @can('vendor_bills.create') Add bill@endcan
@if ($order->vendorBills->isEmpty())
No vendor costs yet. Link vendor bills to this order to see its margin.
@else
@foreach ($order->vendorBills as $b) @endforeach
VendorBillDescriptionAmount
{{ $b->vendor->name }} {{ $b->bill_no ?: '#'.$b->id }} {{ $b->description ?: '—' }} {{ money($b->amount) }}
@endif
@endcan
@endsection