{{-- resources/views/returns/index.blade.php --}} @extends('layouts.app') @section('title', 'Return History') @section('content') @php /** * Group returns by return_no (preferred). * If return_no missing, fallback grouping: type-party-date-note */ $groups = collect($returns->items() ?? $returns)->groupBy(function ($r) { $key = $r->return_no ?? null; if ($key) return $key; $date = $r->date ? \Carbon\Carbon::parse($r->date)->format('Y-m-d') : 'no-date'; $note = trim((string)($r->note ?? '')); return "{$r->type}-{$r->party_id}-{$date}-{$note}"; }); // nice group label helper $getPartyName = function($row) { if ($row->type === 'customer') return optional($row->customer)->name ?? '—'; return optional($row->supplier)->name ?? '—'; }; $getTypeBadge = function($row) { if ($row->type === 'customer') { return 'Customer'; } return 'Supplier'; }; @endphp

Return History

← Back + New Return
@forelse($groups as $groupKey => $rows) @php $first = $rows->first(); $groupTotal = (float) $rows->sum('total'); $partyName = $getPartyName($first); $dateLabel = $first->date ? \Carbon\Carbon::parse($first->date)->format('d-m-Y') : '-'; $returnNo = $first->return_no ?? '—'; $collapseId = 'ret_' . md5($groupKey); @endphp {{-- Header row --}} {{-- Items row (collapse) --}} @empty @endforelse
ID Return No Type Party Date Total Note
@forelse($rows as $item) @empty @endforelse
Product Qty Unit Price Line Total
{{ optional($item->product)->name ?? '—' }}
Product ID: {{ $item->product_id }}
{{ (int) $item->qty }} {{ number_format((float)$item->unit_price, 2) }} {{ number_format((float)$item->total, 2) }}
No items
Grand Total {{ number_format($groupTotal, 2) }}
No returns found.
{{-- Pagination --}} @if(method_exists($returns, 'links'))
{{ $returns->links() }}
@endif @endsection