where('business_id', auth()->user()->business_id) ->where('type', '=', 'Supplier') ->latest() ->get(); $totalAmount = $suppliers->sum(function ($customer) { return $customer->purchases?->sum('totalAmount') ?? 0; }); $totalPaid = $suppliers->sum(function ($customer) { return $customer->purchases?->sum('paidAmount') ?? 0; }); $totalDue = $suppliers->sum(function ($customer) { return $customer->purchases?->sum('dueAmount') ?? 0; }); return view('business::party-reports.supplier-ledger.excel-csv', compact('suppliers', 'totalAmount', 'totalPaid', 'totalDue')); } }