@php $__lu = auth('location')->user(); $pendingPacklistCount = null; $dispatchShortPicklistCount = null; $dispatchShortPacklistCount = null; $dispatchBookingPendingCount = null; $dispatchConversionPendingCount = null; $dispatchShortageCount = null; $dispatchLrPendingCount = null; try { $__locationId = session('location_id'); if ($__locationId) { // Pending packlist SOs (packing done but not yet completed in pipeline/invoice) $baseSoNumbers = \DB::table('so_packing') ->where('location_id', $__locationId) ->whereIn('status', ['completed', 'force_completed']) ->pluck('so_no') ->filter() ->unique() ->values(); if ($baseSoNumbers->isNotEmpty()) { $pipelineRows = \DB::table('order_pipeline') ->select('so_numbers', 'booking_status') ->whereNotNull('booking_status') ->get(); $pipelineCompleted = $pipelineRows ->filter(function ($row) { $status = strtolower(trim((string) ($row->booking_status ?? ''))); return $status === 'completed'; }) ->flatMap(function ($row) { $result = []; if (!empty($row->so_numbers)) { $decoded = json_decode($row->so_numbers, true); if (is_array($decoded)) { foreach ($decoded as $so) { $so = trim((string) $so); if ($so !== '') { $result[] = $so; } } } else { $so = trim((string) $row->so_numbers); if ($so !== '') { $result[] = $so; } } } return $result; }) ->filter(); $invoiceCompleted = \DB::table('invoice_files') ->whereIn('so_no', $baseSoNumbers->all()) ->whereNotNull('so_no') ->where('so_no', '!=', '') ->pluck('so_no') ->map(function ($v) { return trim((string) $v); }) ->filter(); $completedCollection = $pipelineCompleted ->merge($invoiceCompleted) ->unique() ->values(); $pendingPacklistCount = $baseSoNumbers ->reject(function ($so) use ($completedCollection) { return $completedCollection->contains($so); }) ->count(); } // Dispatch: Short Picklist (hold items for this location) try { $dispatchShortPicklistCount = \DB::table('so_picklist') ->where('status', 'hold') ->where('location_id', $__locationId) ->count(); } catch (\Throwable $e2) { $dispatchShortPicklistCount = null; } // Dispatch: Short Packlist (hold boxes for this location) try { if (\Illuminate\Support\Facades\Schema::hasTable('so_packing')) { $dispatchShortPacklistCount = \DB::table('so_packing') ->where('status', 'hold') ->where('location_id', $__locationId) ->count(); } } catch (\Throwable $e3) { $dispatchShortPacklistCount = null; } // Dispatch: Booking Pending (converted freight not yet dispatched) try { if (\Illuminate\Support\Facades\Schema::hasTable('freight_bookings')) { $dispatchBookingPendingCount = \DB::table('freight_bookings') ->where('location_id', $__locationId) ->whereNull('dispatch_date') ->count(); } } catch (\Throwable $e4) { $dispatchBookingPendingCount = null; } // Dispatch: SO Conversion pending (invoice_files without invoice_id and status pending) try { if (\Illuminate\Support\Facades\Schema::hasTable('invoice_files')) { $convQuery = \DB::table('invoice_files') ->whereNull('invoice_id'); if (\Illuminate\Support\Facades\Schema::hasColumn('invoice_files', 'status')) { $convQuery->where('status', 'pending'); } if (\Illuminate\Support\Facades\Schema::hasColumn('invoice_files', 'location_id')) { $convQuery->where('location_id', $__locationId); } $dispatchConversionPendingCount = $convQuery->count(); } } catch (\Throwable $e5) { $dispatchConversionPendingCount = null; } // Dispatch/Account: Shortage pending (SO approval items with status = inv-completed) try { if (\Illuminate\Support\Facades\Schema::hasTable('so_picklist') && \Illuminate\Support\Facades\Schema::hasTable('so_packing')) { $pickShort = \DB::table('so_picklist') ->where('status', 'inv-completed') ->where('location_id', $__locationId) ->count(); $packShort = \DB::table('so_packing') ->where('status', 'inv-completed') ->where('location_id', $__locationId) ->count(); $dispatchShortageCount = $pickShort + $packShort; } } catch (\Throwable $e6) { $dispatchShortageCount = null; } // Dispatch: LR Upload pending (picking completed but not yet dispatched) try { if (\Illuminate\Support\Facades\Schema::hasTable('order_pipeline')) { $dispatchLrPendingCount = \DB::table('order_pipeline') ->where('picking_status', 'completed') ->where(function ($q) { $q->whereNull('dispatch_status') ->orWhere('dispatch_status', '!=', 'completed'); }) ->count(); } } catch (\Throwable $e7) { $dispatchLrPendingCount = null; } } } catch (\Throwable $e) { $pendingPacklistCount = null; $dispatchShortPicklistCount = null; $dispatchShortPacklistCount = null; $dispatchBookingPendingCount = null; $dispatchConversionPendingCount = null; $dispatchShortageCount = null; $dispatchLrPendingCount = null; } @endphp
@if(session('success')) @endif @if(session('error')) @endif

@yield('page-title', 'Location User Dashboard')

@yield('content')
Loading...
Processing, please wait...
@stack('scripts')