@extends('layouts.location') @section('title', 'SO Approval') @section('page-title', 'SO Approval') @section('content')
@php $picklistGroups = collect($picklistRows ?? [])->groupBy('pic_id'); @endphp
@forelse($picklistGroups as $picId => $rows) @php $firstRow = $rows->first(); $soLabel = $rows->pluck('sales_order_number') ->filter() ->flatMap(function ($v) { return array_filter(array_map('trim', explode(',', (string) $v))); }) ->unique() ->values() ->implode(','); @endphp @empty @endforelse
SO No(s) PIC ID Status Accept Remark Reject Remark Action
{{ $soLabel ?: '-' }} {{ $picId ?? '-' }} {{ $firstRow->status ?? '-' }} {{ $firstRow->accept_remark_account ?? '' }} {{ $firstRow->reject_remark_account ?? '' }}
@foreach($rows as $row) @php $requireQty = (float) ($row->required_qty_calc ?? $row->required_qty ?? 0); $pickedQty = (float) ($row->pick_qty ?? 0); $shortQty = $requireQty - $pickedQty; @endphp @endforeach
SO No(s) SKU Require Qty Pick Qty Short Qty Action
{{ $row->sales_order_number ?? '-' }} {{ $row->sku ?? '-' }} {{ $requireQty }} {{ $pickedQty }} {{ $shortQty }}
No picklist records with status = inv-completed.
@php $packlistGroups = collect($packlistRows ?? [])->groupBy('so_no'); @endphp
@forelse($packlistGroups as $soNo => $rows) @php $boxCount = $rows->count(); $totalWeight = $rows->sum(function ($r) { return (float) ($r->weight ?? 0); }); $firstRow = $rows->first(); $diffsForSo = collect($shortPackDiffs[$soNo] ?? []); $normalizePackName = function ($name) { $name = trim((string) $name); if ($name === '') { return $name; } $parts = preg_split('/\s+/', $name); if (count($parts) > 1) { $last = end($parts); $cleanLast = preg_replace('/[^A-Z0-9-]/', '', strtoupper($last)); $looksLikeSku = ( $cleanLast !== '' && preg_match('/^[A-Z0-9-]+$/', $cleanLast) && (str_contains($cleanLast, '-') || (preg_match('/[A-Z]/', $cleanLast) && preg_match('/[0-9]/', $cleanLast))) ); if ($looksLikeSku) { array_pop($parts); $name = implode(' ', $parts); } } $name = str_replace(["*", "/", "\\", "×"], ' ', $name); $name = preg_replace('/\s+/', ' ', trim($name)); return $name; }; $boxKeysByPackId = []; $allBoxKeys = collect(); foreach ($rows as $row) { $keys = collect(); try { $items = json_decode($row->items, true); if (is_array($items)) { foreach ($items as $it) { if (is_string($it)) { $decoded = json_decode($it, true); $it = is_array($decoded) ? $decoded : $it; } if (is_array($it) && isset($it['item'])) { $rawName = (string) ($it['item'] ?? ''); $sku = trim((string) ($it['sku'] ?? '')); $key = $sku !== '' ? ('SKU:' . $sku) : ('NAME:' . $normalizePackName($rawName)); if ($key !== 'NAME:' && $key !== 'SKU:') { $keys->push($key); } } } } } catch (\Throwable $e) { } $keys = $keys->filter()->unique()->values(); $boxKeysByPackId[(string) $row->id] = $keys; $allBoxKeys = $allBoxKeys->merge($keys); } $allBoxKeys = $allBoxKeys->filter()->unique()->values(); @endphp @empty @endforelse
SO No Total Boxes Total Weight Status Accept Remark Reject Remark Action
{{ $soNo }} {{ $boxCount }} {{ $totalWeight }} {{ $firstRow->status ?? '-' }} {{ $firstRow->accept_remark_account ?? '' }} {{ $firstRow->reject_remark_account ?? '' }}
Short / Difference items for SO {{ $soNo }}: @php $unboxedDiffs = $diffsForSo->filter(function ($d) use ($allBoxKeys) { $k = isset($d['item_key']) ? (string) $d['item_key'] : ''; return $k !== '' && !$allBoxKeys->contains($k); })->values(); @endphp @if($rows->isNotEmpty()) @foreach($rows as $r) @php $packId = (string) $r->id; $keysForBox = isset($boxKeysByPackId[$packId]) ? $boxKeysByPackId[$packId] : collect(); if (!$keysForBox instanceof \Illuminate\Support\Collection) { $keysForBox = collect($keysForBox); } $diffsForBox = $diffsForSo->filter(function ($d) use ($keysForBox) { $k = isset($d['item_key']) ? (string) $d['item_key'] : ''; return $k !== '' && $keysForBox->contains($k); })->values(); $boxVal = $r->box; $boxDecoded = null; try { $boxDecoded = json_decode($r->box, true); } catch (\Throwable $e) { } if (is_array($boxDecoded)) { $boxVal = implode(', ', $boxDecoded); } @endphp
Box: {{ $boxVal }}
@if($diffsForBox->isNotEmpty())
@foreach($diffsForBox as $d) @endforeach
Item SO Qty Packed Qty Diff
{{ $d['item_name'] ?? '' }} {{ $d['so_qty'] ?? 0 }} {{ $d['packed_qty'] ?? 0 }} {{ $d['diff'] ?? 0 }}
@else
No quantity differences for this box.
@endif
@endforeach @endif @if($unboxedDiffs->isNotEmpty())
Box: -
@foreach($unboxedDiffs as $d) @endforeach
Item SO Qty Packed Qty Diff
{{ $d['item_name'] ?? '' }} {{ $d['so_qty'] ?? 0 }} {{ $d['packed_qty'] ?? 0 }} {{ $d['diff'] ?? 0 }}
@endif @if($diffsForSo->isEmpty())
No quantity differences for this SO.
@endif
No packlist records with status = inv-completed.
@endsection @push('scripts') @endpush