{{-- resources/views/finance/client-profile.blade.php --}} @extends('layouts.finance.finance') @section('content')
{{-- Header & Profile Info --}}
{{-- Client Avatar --}}
{{ strtoupper(substr($name, 0, 1)) }}

{{ $name }}

{{ $totalProjects }} Total Projects {{ $executionProjects }} Running
{{-- Back Button --}} ← Back to Directory
{{-- Financial Summary Cards --}}
{{-- Total Invoiced --}}

Total Invoiced Amount

Rs {{ number_format($totalInvoiced, 2) }}

{{-- Total Collected --}}

Total Collected

Rs {{ number_format($totalCollected, 2) }}

{{-- Balance Due --}}

Total Balance Due

Rs {{ number_format(max(0, $balanceDue), 2) }}

{{-- Ledger / Activity Table --}}

Recent Financial Activity

{{-- NEW ACTION HEADER --}} @php $invoices = $clientProjects->flatMap->invoices; $receivables = $clientProjects->flatMap->receivableSchedules; $ledgerItems = collect()->concat($invoices)->concat($receivables)->sortByDesc('created_at'); @endphp @forelse ($ledgerItems as $item) @php $modelType = class_basename($item); $amount = $item->amount ?? $item->total_amount ?? $item->total ?? $item->grand_total ?? 0; if ($modelType === 'Invoice') { $ref = $item->invoice_number ?? ('INV #' . $item->id); } else { $scheduleName = $item->title ?? $item->name ?? $item->description ?? $item->milestone ?? ('Payment #' . $item->id); $ref = !empty($item->invoice_id) ? ($scheduleName . ' → For INV #' . $item->invoice_id) : $scheduleName; } @endphp {{-- NEW VIEW BUTTON --}} @empty {{-- Updated colspan to 7 to account for the new column --}} @endforelse
Date Type Project ID Reference / Detail Amount Status Action
{{ \Carbon\Carbon::parse($item->created_at)->format('M d, Y - g:i A') }} @if($modelType === 'Invoice') Invoice @else Payment Received @endif Project #{{ $item->project_id }} {{ $ref }} {{ $modelType === 'Invoice' ? '' : '+' }}Rs {{ number_format($amount, 2) }} @php $statusColor = in_array(strtolower($item->status ?? ''), ['paid', 'completed']) ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'; @endphp {{ ucfirst($item->status ?? 'Logged') }} @if($modelType === 'Invoice') {{-- CHANGED HERE: finance.invoices.show --}} View PDF @else {{-- If the payment is tied to an invoice, view the invoice. Otherwise, view the project --}} @if(!empty($item->invoice_id)) {{-- CHANGED HERE: finance.invoices.show --}} View PDF @else View Project @endif @endif
No financial activity found for this client yet.
@endsection