@extends('index') @section('content')
Customer No: {{$order['customer_no']}}
Customer Name: {{$order['fname']}} {{$order['lname']}}
Order No {{$order['order_no']}}
Job No: {{$order['job_no']}}
Date: {{\Carbon\Carbon::parse($order['order_date'])->format('d-m-Y')}}
Order Status: @if($order['order_status'] == 1) Draft @elseif($order['order_status'] == 2) Confirmed @elseif($order['order_status'] == 3) Dispatched @elseif($order['order_status'] == 4) Delivered @elseif($order['order_status'] == 5) Cancelled @else @endif
@php // Pre-group stock data by product_type_id for easy lookup of total stock $groupedStock = $stock->groupBy('product_type_id'); @endphp
@if($remainingItems->count()) @php $prev_product_name = ''; $prev_size_name = ''; $rowIndex = 1; @endphp @foreach($remainingItems as $item) @php // Calculate total stock for this product + size $stageStockItems = $groupedStock->get($item->product_type_id, collect()); $totalStock = $stageStockItems->sum(function($si) { return ($si->stockIn ?? 0) - ($si->stockOut ?? 0); }); $isNewProduct = ($item->product_name != $prev_product_name); $isNewSize = ($isNewProduct || $item->size_name != $prev_size_name); @endphp @if($isNewProduct) @else @endif @if($isNewSize) @else @endif {{-- Total Stock Column from deleted tab --}} {{-- Actions Column from deleted tab --}} @php $prev_product_name = $item->product_name; $prev_size_name = $item->size_name; @endphp @endforeach @else @endif
Sr. Article No Item / Product Size Stage Ordered Qty Total Stock Delivered Qty Returned Qty Remaining Qty Actions
{{ $rowIndex++ }}{{$item->article_no}} {{$item->product_name}}{{$item->size_name}}{{$item->stage_name}} {{number_format($item->ordered_quantity)}} {{$item->unit_name}} @if($isNewSize) @if($totalStock > 0) {{ number_format($totalStock) }} {{$item->unit_name}} @elseif($totalStock < 0) {{ number_format($totalStock) }} {{$item->unit_name}} @else 0 {{$item->unit_name}} @endif @endif {{number_format($item->delivered_quantity)}} {{$item->unit_name}} @if($item->returned_quantity > 0) {{number_format($item->returned_quantity)}} {{$item->unit_name}} @else 0 {{$item->unit_name}} @endif @if($item->remaining_quantity > 0) {{number_format($item->remaining_quantity)}} {{$item->unit_name}} @else 0 {{$item->unit_name}} @endif @if($isNewSize) @endif
No items found for this order
Sr. Article No Item / Product Size Stage Ordered Qty Total Stock Delivered Qty Returned Qty Remaining Qty Actions
{{-- Summary Statistics --}}
Delivery Summary
@php $totalItems = $remainingItems->count(); $completedItems = $remainingItems->where('remaining_quantity', '<=', 0)->count(); $partialItems = $remainingItems->where('net_delivered_quantity', '>', 0)->where('remaining_quantity', '>', 0)->count(); $pendingItems = $remainingItems->where('net_delivered_quantity', '<=', 0)->count(); $completionPercentage = $totalItems > 0 ? round(($completedItems / $totalItems) * 100, 2) : 0; @endphp

{{$totalItems}}

Total Items

{{$completedItems}}

Completed

{{$partialItems}}

Partial

{{$pendingItems}}

Pending

{{$completionPercentage}}% Complete
@if($stock->count()) @php $groupedStockForModals = $stock->groupBy('product_type_id'); @endphp @foreach($groupedStockForModals as $productTypeId => $stageItems) @php $firstItem = $stageItems->first(); $totalStock = $stageItems->sum(function($item) { return $item->stockIn - $item->stockOut; }); @endphp @endforeach @endif @endsection