@extends('store.layout.main') @section('title', 'Sales Orders') @section('page-header') @endsection @section('main-container') @php $totalShown = $sales->total(); $totalPayable = $sales->getCollection()->sum('grand_total'); $totalDue = $sales->getCollection()->sum('amount_due'); @endphp {{-- ── Summary Cards ────────────────────────────────────────── --}}
@php $cards = [ [ 'label' => 'Orders', 'value' => number_format($totalShown), 'icon' => 'bi-receipt', 'iconClr' => '#1d4ed8', 'iconBg' => '#dbeafe', 'shadow' => 'rgba(59,130,246,.18)', ], [ 'label' => 'Total Payable', 'value' => number_format($totalPayable, 2), 'icon' => 'bi-cash-coin', 'iconClr' => '#15803d', 'iconBg' => '#dcfce7', 'shadow' => 'rgba(34,197,94,.18)', ], [ 'label' => 'Total Due', 'value' => number_format($totalDue, 2), 'icon' => $totalDue > 0 ? 'bi-hourglass-split' : 'bi-check2-circle', 'iconClr' => $totalDue > 0 ? '#b45309' : '#0f766e', 'iconBg' => $totalDue > 0 ? '#fef3c7' : '#ccfbf1', 'shadow' => $totalDue > 0 ? 'rgba(245,158,11,.18)' : 'rgba(20,184,166,.18)', ], [ 'label' => 'Collected', 'value' => number_format($totalPayable - $totalDue, 2), 'icon' => 'bi-wallet2', 'iconClr' => '#6d28d9', 'iconBg' => '#ede9fe', 'shadow' => 'rgba(139,92,246,.18)', ], ]; @endphp @foreach($cards as $card)
{{ $card['label'] }}
{{ $card['value'] }}
@endforeach
{{-- ── Filters + Search ─────────────────────────────────────── --}} @php $activeFilter = request('filter', ''); $activeStatus = request('status', ''); $activePayment = request('payment', ''); $activeFulfillment = request('fulfillment', ''); $activeDiscounted = request('discounted', ''); $activeCustomerType = request('customer_type', ''); $activeOrderType = request('order_type', ''); $searchQuery = request('search', ''); $hasAnyFilter = $searchQuery || $activeFilter || $activeStatus || $activePayment || $activeFulfillment || $activeDiscounted || $activeCustomerType || $activeOrderType; $fpUrl = function(string $key, string $val): string { $params = array_filter([ 'search' => request('search', ''), 'filter' => request('filter', ''), 'status' => request('status', ''), 'payment' => request('payment', ''), 'fulfillment' => request('fulfillment', ''), 'discounted' => request('discounted', ''), 'customer_type' => request('customer_type', ''), 'order_type' => request('order_type', ''), ]); if ($val === '') unset($params[$key]); else $params[$key] = $val; return route('store.sales.list', $params); }; $filterGroups = [ 'filter' => [ 'label' => 'Date', 'active' => $activeFilter, 'default' => ['label' => 'All Dates', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'], 'options' => [ 'today' => ['label' => 'Today', 'bg' => '#dbeafe', 'color' => '#1d4ed8', 'dot' => '#1d4ed8'], 'yesterday' => ['label' => 'Yesterday', 'bg' => '#dbeafe', 'color' => '#1d4ed8', 'dot' => '#1d4ed8'], 'this_week' => ['label' => 'This Week', 'bg' => '#dbeafe', 'color' => '#1d4ed8', 'dot' => '#1d4ed8'], ], ], 'status' => [ 'label' => 'Status', 'active' => $activeStatus, 'default' => ['label' => 'All Status', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'], 'options' => [ 'completed' => ['label' => 'Completed', 'bg' => '#dcfce7', 'color' => '#15803d', 'dot' => '#15803d'], 'pending' => ['label' => 'Pending', 'bg' => '#f1f5f9', 'color' => '#475569', 'dot' => '#94a3b8'], 'cancelled' => ['label' => 'Cancelled', 'bg' => '#fee2e2', 'color' => '#b91c1c', 'dot' => '#b91c1c'], ], ], 'payment' => [ 'label' => 'Payment', 'active' => $activePayment, 'default' => ['label' => 'All Payment', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'], 'options' => [ 'paid' => ['label' => 'Paid', 'bg' => '#dcfce7', 'color' => '#15803d', 'dot' => '#15803d'], 'partial' => ['label' => 'Partial', 'bg' => '#fef3c7', 'color' => '#b45309', 'dot' => '#d97706'], 'unpaid' => ['label' => 'Unpaid', 'bg' => '#fee2e2', 'color' => '#b91c1c', 'dot' => '#b91c1c'], ], ], 'fulfillment' => [ 'label' => 'Fulfillment', 'active' => $activeFulfillment, 'default' => ['label' => 'All Fulfillment', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'], 'options' => [ 'pending' => ['label' => 'Pending', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'], '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'], ], ], 'discounted' => [ 'label' => 'Discount', 'active' => $activeDiscounted, 'default' => ['label' => 'Any Discount', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'], 'options' => [ 'yes' => ['label' => 'Discounted', 'bg' => '#fef3c7', 'color' => '#b45309', 'dot' => '#d97706'], 'no' => ['label' => 'No Discount', 'bg' => '#f1f5f9', 'color' => '#475569', 'dot' => '#94a3b8'], ], ], 'customer_type' => [ 'label' => 'Customer', 'active' => $activeCustomerType, 'default' => ['label' => 'All Customers', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'], 'options' => [ 'new' => ['label' => 'New Customer', 'bg' => '#ccfbf1', 'color' => '#0f766e', 'dot' => '#14b8a6'], 'guest' => ['label' => 'Guest / Walk-in','bg' => '#f0f9ff', 'color' => '#0369a1', 'dot' => '#0ea5e9'], ], ], 'order_type' => [ 'label' => 'Order Type', 'active' => $activeOrderType, 'default' => ['label' => 'All Types', 'bg' => '#f1f5f9', 'color' => '#64748b', 'dot' => '#94a3b8'], 'options' => [ 'pos' => ['label' => 'POS', 'bg' => '#e0e7ff', 'color' => '#4338ca', 'dot' => '#4338ca'], 'app' => ['label' => 'App / Online', 'bg' => '#f3e8ff', 'color' => '#7c3aed', 'dot' => '#7c3aed'], ], ], ]; @endphp
{{-- Row 1: Search + button + clear --}}
@foreach(['filter','status','payment','fulfillment','discounted','customer_type','order_type'] as $_pk) @if(request($_pk))@endif @endforeach
@if($hasAnyFilter) Clear All @endif
{{-- Row 2: Split-pill filter dropdowns --}}
@foreach($filterGroups as $paramKey => $cfg) @php $activeVal = $cfg['active']; $activeCfg = $activeVal && isset($cfg['options'][$activeVal]) ? $cfg['options'][$activeVal] : $cfg['default']; @endphp
{{-- Split pill --}}
{{ $activeCfg['label'] }}
{{-- Dropdown --}}
@endforeach
{{-- ── Table ────────────────────────────────────────────────── --}}
@forelse($sales as $sale) {{-- Main row --}} {{-- Expand toggle --}} {{-- Order: items first, then order#, then date --}} {{-- Customer --}} {{-- Amount --}} {{-- Delivery / fulfillment snapshot --}} {{-- Status --}} {{-- 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 {{-- Actions --}} @php $courierTooltip = $sale->shipping_tracking_no ? 'Show Courier Details' : 'Enter Tracking#'; @endphp {{-- Expandable detail row --}} @empty @endforelse
Order Customer Amount Delivery Status Fulfillment Actions
{{ $sale->product_hint }} {{ $sale->orderDetails->count() }}
#{{ getOrderNumber($sale) }}
{{ $sale->created_at->format('d M Y · h:i A') }}
{{ $sale->customer_name ?: 'Walk-in' }}
@if($sale->customer_phone)
{{ $sale->customer_phone }}
@endif
{{ 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
@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
@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
{{-- Status split-pill --}}
{{ $fBadge['label'] }}
{{-- Status dropdown --}}
{{-- Courier info (shown when set) --}}
{{ $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
{{-- Courier --}} {{-- Three-dot menu --}}
Base Price
{{ format_currency($sale->order_base_price) }}
Subtotal
{{ format_currency($sale->subtotal) }}
Discount
-{{ format_currency($sale->total_discount) }}
Tax
{{ format_currency($sale->total_tax) }}
@if($sale->coupon_code)
Coupon
{{ $sale->coupon_code }} (-{{ format_currency($sale->coupon_discount) }})
@endif
Grand Total
{{ format_currency($sale->grand_total) }}
@if($sale->payment_method)
Payment Method
{{ ucfirst(str_replace('_', ' ', $sale->payment_method)) }}
@endif @if($sale->transaction_id)
Transaction ID
{{ $sale->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)
Delivery
@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
@endif @if($sale->customer_note)
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
@if($sales->hasPages()) @endif
{{-- ── Courier Modal ────────────────────────────────────────── --}} {{-- Full-screen payment proof preview --}} @endsection @section('script') @endsection