@if(isset($pickings) && $pickings->count())
| SO No
|
Items
|
Status |
Action |
@foreach($pickings->sortKeysDesc() as $so_no => $group)
| {{ $so_no }} |
@php
$allItems = collect();
foreach($group as $packing) {
$itemsData = $packing->items;
if(is_array($itemsData)) {
// Handle array of JSON strings
foreach($itemsData as $itemString) {
if(is_string($itemString)) {
$decoded = json_decode($itemString, true);
if(is_array($decoded) && isset($decoded['item']) && isset($decoded['qty'])) {
$allItems->push($decoded);
}
} elseif(is_array($itemString) && isset($itemString['item']) && isset($itemString['qty'])) {
$allItems->push($itemString);
}
}
} elseif(is_string($itemsData)) {
// Try to decode JSON string
$decoded = json_decode($itemsData, true);
if(is_array($decoded)) {
// If decoded result is an array of items
if(isset($decoded[0]) && is_array($decoded[0])) {
foreach($decoded as $item) {
if(isset($item['item']) && isset($item['qty'])) {
$allItems->push($item);
}
}
}
// If decoded result is a single item object
elseif(isset($decoded['item']) && isset($decoded['qty'])) {
$allItems->push($decoded);
}
}
}
}
// Remove duplicates and group by item
$uniqueItems = $allItems->groupBy('item')->map(function($group) {
return [
'item' => $group->first()['item'],
'qty' => $group->sum('qty')
];
})->values();
// Get comparison data for this SO
$shortItems = $comparisonData[$so_no] ?? [];
@endphp
@php
// Combine picked items and shortages for comprehensive display
$allDisplayItems = collect();
// Add picked items
foreach($uniqueItems as $item) {
$allDisplayItems->push([
'item' => $item['item'],
'picked_qty' => $item['qty'],
'short_qty' => 0,
'type' => 'picked'
]);
}
// Add shortage items (only if not already shown as picked)
foreach($shortItems as $shortItem) {
$existingItem = $allDisplayItems->where('item', $shortItem['item'])->first();
if($existingItem) {
// Update existing item with shortage info
$existingItem['short_qty'] = $shortItem['short_qty'];
} else {
// Add new shortage item
$allDisplayItems->push([
'item' => $shortItem['item'],
'picked_qty' => 0,
'short_qty' => $shortItem['short_qty'],
'type' => 'shortage'
]);
}
}
@endphp
@foreach($allDisplayItems as $displayItem)
|
@if($displayItem['type'] == 'shortage' && $displayItem['picked_qty'] == 0)
{{ $displayItem['item'] }}
@else
{{ $displayItem['item'] }}
@endif
|
@if($displayItem['picked_qty'] > 0)
{{ $displayItem['picked_qty'] }}
@else
0
@endif
|
@if($displayItem['short_qty'] > 0)
{{ $displayItem['short_qty'] }}
@else
-
@endif
|
@endforeach
|
@if($group->contains('status', 'hold'))
hold
@elseif($group->contains('status', 'force_completed'))
closed with shortage
@else
completed
@endif
|
@if($group->contains('status', 'hold'))
@elseif($group->contains('status', 'force_completed'))
Closed with shortage
@else
Completed
@endif
|
@endforeach
@else
No packings on hold found.
@endif