{{-- resources/views/customers/show.blade.php --}} @extends('layouts.app') @section('title', $customer->name) @section('content') @php // Opening balance $opening = (float) ($customer->opening_balance ?? 0); // সব সেল controller থেকে $sales হিসেবে আসছে (DESC order) $totalSales = isset($sales) ? (float) $sales->sum('total') : 0; $totalPaid = isset($sales) ? (float) $sales->sum('paid') : 0; // returns $totalReturns = (float) $returns->sum('total'); // Final হিসাব: // Opening + Total sales - Total paid - customer returns $currentDue = $opening + $totalSales - $totalPaid - $totalReturns; @endphp

{{ $customer->name }}

Phone: {{ $customer->phone ?? '-' }} | Address: {{ $customer->address ?? '-' }}
Opening Balance: {{ number_format($opening, 2) }}
Total Sales: {{ number_format($totalSales, 2) }}
Total Paid: {{ number_format($totalPaid, 2) }}
Total Returns: {{ number_format($totalReturns, 2) }}
Current Due: {{ number_format($currentDue, 2) }}
← Back to Customers {{-- 🔸 Sales History --}}
Sales History
@if($sales->isEmpty())

No sales for this customer yet.

@else @foreach($sales as $sale) {{-- Sale Items --}} @endforeach
Date Invoice Total Paid Due Status Next Due
{{ $sale->date ? \Carbon\Carbon::parse($sale->date)->format('d-m-Y') : '-' }} {{ $sale->invoice_no }} {{ number_format($sale->total ?? 0, 2) }} {{ number_format($sale->paid ?? 0, 2) }} {{ number_format($sale->due ?? 0, 2) }} @if($sale->status === 'paid') Paid @else Due @endif {{ $sale->next_due_date ? \Carbon\Carbon::parse($sale->next_due_date)->format('d-m-Y') : '-' }}
@forelse($sale->items as $item) @empty @endforelse
  Product Qty Price Line Total
  {{ $item->product->name ?? '—' }} {{ $item->qty }} {{ number_format($item->price ?? 0, 2) }} {{ number_format($item->line_total ?? 0, 2) }}
  No items
@endif
{{-- 🔹 Payment History --}}
Payment History
@if($payments->isEmpty())

No payments from this customer yet.

@else @foreach($payments as $pay) @endforeach
Date Method Amount Ref No Note
{{ $pay->date ? \Carbon\Carbon::parse($pay->date)->format('d-m-Y') : '-' }} {{ $pay->method }} {{ number_format($pay->amount ?? 0, 2) }} {{ $pay->ref_no ?? '-' }} {{ $pay->note ?? '-' }}
@endif
{{-- 🔥 Return History --}}
Return History
@if($returns->isEmpty())

No return entries for this customer.

@else @foreach($returns as $r) @endforeach
Date Product Qty Unit Price Total Note
{{ $r->date ? $r->date->format('d-m-Y') : '-' }} {{ optional($r->product)->name ?? '—' }} {{ $r->qty }} {{ number_format($r->unit_price, 2) }} {{ number_format($r->total, 2) }} {{ $r->note ?? '-' }}
@endif
@endsection