@extends('store.layout.main')
@section('title', 'Sales Orders')
@section('page-header')
| Order | Customer | Amount | Delivery | Status | Fulfillment | Actions | |
|---|---|---|---|---|---|---|---|
| {{-- Order: items first, then order#, then date --}} |
{{ $sale->orderDetails->count() }}
#{{ getOrderNumber($sale) }}
{{ $sale->created_at->format('d M Y · h:i A') }}
|
{{-- Customer --}}
{{ $sale->customer_name ?: 'Walk-in' }}
@if($sale->customer_phone)
{{ $sale->customer_phone }}
@endif
|
{{-- Amount --}}
{{ format_currency($sale->grand_total) }}
@if($sale->amount_due > 0)
Due: {{ format_currency($sale->amount_due) }}
@else
Cleared
@endif
@php $saleDiscount = ($sale->total_discount ?? 0) + ($sale->coupon_discount ?? 0); @endphp
@if($saleDiscount > 0)
-{{ format_currency($saleDiscount) }}
@endif
|
{{-- Delivery / fulfillment snapshot --}}
@php
$isPosRow = \Illuminate\Support\Str::startsWith((string) ($sale->order_number ?? ''), 'PS-');
$resolvedDel = store_order_resolved_delivery_type($sale->shipping_delivery_type ?? null, $sale->shipping_method ?? null);
$delLabel = store_order_delivery_type_label($resolvedDel ?? 'none');
$rateLbl = store_order_shipping_rate_label($sale->shipping_rate_mode ?? null);
$shipFeeRow = (float) ($sale->shipping_fee ?? 0);
$dPkgLine = store_order_delivery_package_display(
$sale->shipping_method ?? null,
$sale->shipping_option_key ?? null,
$sale->shipping_delivery_type ?? $resolvedDel
);
@endphp
@if ($isPosRow)
POS
@if ($dPkgLine !== '' || filled($sale->shipping_method ?? null) || $shipFeeRow > 0)
{{ Str::limit($dPkgLine !== '' ? $dPkgLine : (string) ($sale->shipping_method ?? '—'), 26) }}
@endif
@elseif ($resolvedDel === null && !filled($sale->shipping_method ?? null) && $shipFeeRow < 0.01)
—
@else
@php
$delBadgeScheme = match ($resolvedDel ?? 'none') {
'pickup' => ['bg' => 'warning-lt', 'text' => 'warning', 'border' => 'warning'],
'delivery' => ['bg' => 'azure-lt', 'text' => 'azure', 'border' => 'azure'],
default => ['bg' => 'secondary-lt', 'text' => 'secondary', 'border' => 'secondary'],
};
@endphp
{{ $delLabel }}
@if (($resolvedDel ?? '') === 'delivery' && $dPkgLine !== '')
{{ Str::limit($dPkgLine, 26) }}
@endif
@if (($sale->shipping_rate_mode ?? null) && ($resolvedDel ?? '') === 'delivery')
{{ $rateLbl }}
@endif
@if (($sale->shipping_distance_km ?? null) !== null && (float) $sale->shipping_distance_km >= 0 && ($resolvedDel ?? '') === 'delivery')
{{ number_format((float) $sale->shipping_distance_km, 2) }} km
@endif
@if ($shipFeeRow > 0.005)
{{ format_currency($shipFeeRow) }}
@endif
@endif
|
{{-- Status --}}
@php
$sCls = match($sale->status) {
'completed' => 'success',
'cancelled' => 'danger',
default => 'secondary',
};
$pCls = match($sale->payment_status) {
'paid' => 'success',
'unpaid' => 'danger',
'partial' => 'warning',
default => 'secondary',
};
@endphp
{{ ucfirst($sale->status) }} {{ ucfirst($sale->payment_status) }} @if($sale->payment_proof_path) @php $proofUrl = asset('storage/' . ltrim($sale->payment_proof_path, '/')); @endphp @endif |
{{-- Fulfillment --}}
@php
$fStatus = $sale->fulfillment_status ?? 'pending';
if ($fStatus === 'accepted') {
$fStatus = 'approved';
}
$fBadge = match($fStatus) {
'approved' => ['label' => 'Approved', 'bg' => '#e6f7f5', 'color' => '#0d5c56', 'dot' => '#0d9488'],
'shipped' => ['label' => 'Shipped', 'bg' => '#f3e8ff', 'color' => '#7c3aed', 'dot' => '#7c3aed'],
'delivered' => ['label' => 'Delivered', 'bg' => '#dcfce7', 'color' => '#16a34a', 'dot' => '#16a34a'],
'cancelled' => ['label' => 'Cancelled', 'bg' => '#fee2e2', 'color' => '#dc2626', 'dot' => '#dc2626'],
default => ['label' => 'Pending', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'],
};
// Delivery progress bar
$dpBar = null;
if ($sale->estimated_delivery && $sale->shipping_tracking_no) {
$dpDays = match($sale->estimated_delivery) {
'3-5 days' => 5,
'1 week' => 7,
'2 weeks' => 14,
'3 weeks' => 21,
'1 month' => 30,
'2 months' => 60,
'6 months' => 180,
default => null,
};
if ($dpDays) {
$dpStart = $sale->updated_at ?? $sale->created_at;
$dpEnd = $dpStart->copy()->addDays($dpDays);
$dpElapsed = (int) $dpStart->diffInDays(now());
$dpPct = min(100, round($dpElapsed / $dpDays * 100));
$dpLeft = max(0, (int) now()->diffInDays($dpEnd, false));
$dpOverdue = now()->gt($dpEnd);
$dpColor = $dpOverdue ? '#dc2626' : ($dpPct >= 80 ? '#f59e0b' : ($dpPct >= 55 ? '#3b82f6' : '#22c55e'));
$dpLabel = $dpOverdue
? 'Overdue by ' . (int) $dpEnd->diffInDays(now()) . 'd'
: $dpLeft . ' day' . ($dpLeft === 1 ? '' : 's') . ' left';
$dpBar = ['pct' => $dpPct, 'color' => $dpColor, 'label' => $dpLabel, 'overdue' => $dpOverdue];
}
}
@endphp
{{-- Status split-pill --}}
{{ $fBadge['label'] }}
{{-- Status dropdown --}}
{{ $sale->courier->name ?? '' }}
{{ $sale->shipping_tracking_no ?? '' }}
@if($sale->shipping_tracking_no)
@else
@endif
{{-- Estimated delivery + progress bar --}}
{{ $sale->estimated_delivery ? '~'.$sale->estimated_delivery : '' }}
@if($dpBar)
{{ $dpBar['label'] }}
@endif
@if($dpBar)
@endif
|
{{-- Actions --}}
@php
$courierTooltip = $sale->shipping_tracking_no
? 'Show Courier Details'
: 'Enter Tracking#';
@endphp
{{-- Courier --}}
{{-- Three-dot menu --}}
|
|
Base Price
{{ format_currency($sale->order_base_price) }}
Subtotal
{{ format_currency($sale->subtotal) }}
Discount
-{{ format_currency($sale->total_discount) }}
Tax
@if($sale->coupon_code)
{{ format_currency($sale->total_tax) }}
Coupon
@endif
{{ $sale->coupon_code }} (-{{ format_currency($sale->coupon_discount) }})
Grand Total
@if($sale->payment_method)
{{ format_currency($sale->grand_total) }}
Payment Method
@endif
@if($sale->transaction_id)
{{ ucfirst(str_replace('_', ' ', $sale->payment_method)) }}
Transaction ID
@endif
@if(filled($sale->shipping_method) || filled($sale->shipping_delivery_type) || filled($sale->shipping_rate_mode) || (float)($sale->shipping_fee ?? 0) > 0 || $sale->shipping_distance_km !== null)
{{ $sale->transaction_id }}
Delivery
@endif
@if($sale->customer_note)
@php $expDel = store_order_resolved_delivery_type($sale->shipping_delivery_type ?? null, $sale->shipping_method ?? null) ?? 'none'; @endphp {{ store_order_delivery_type_label($expDel) }} @if(filled($sale->shipping_method ?? null)) {{ Str::limit($sale->shipping_method, 40) }}
@endif
@if(filled($sale->shipping_rate_mode ?? null))
{{ store_order_shipping_rate_label($sale->shipping_rate_mode) }}
@endif
@if($sale->shipping_distance_km !== null)
{{ number_format((float)$sale->shipping_distance_km, 2) }} km
@endif
@if((float)($sale->shipping_fee ?? 0) > 0)
{{ format_currency((float)$sale->shipping_fee) }}
@endif
Note: {{ $sale->customer_note }}
@endif
@php
$expandAddr = array_filter([
filled($sale->shipping_address_line ?? null) ? $sale->shipping_address_line : null,
filled($sale->shipping_area ?? null) ? 'Area: ' . $sale->shipping_area : null,
filled($sale->shipping_city ?? null) ? 'City: ' . $sale->shipping_city : null,
filled($sale->shipping_state ?? null) ? 'State: ' . $sale->shipping_state : null,
filled($sale->shipping_postal_code ?? null) ? $sale->shipping_postal_code : null,
filled($sale->shipping_country ?? null) ? strtoupper($sale->shipping_country) : null,
]);
@endphp
@if (count($expandAddr))
Address:
{{ implode(', ', $expandAddr) }}
@endif
|
|||||||
| No sales found @if($searchQuery || $activeFilter) — clear filters @endif | |||||||