@php use App\Models\LoanBookApplication; $events = collect(); foreach ($recentPayments ?? collect() as $payment) { $at = $payment->transaction_at ?? $payment->created_at; $loan = $payment->loan; $events->push([ 'at' => $at, 'type' => 'Payment', 'title' => 'Payment received', 'amount' => (float) ($payment->amount ?? 0), 'meta' => $loan?->loan_number, 'href' => $loan ? route('loan.book.loans.show', $loan) : null, 'tone' => 'success', ]); } foreach (($clientApplications ?? collect())->take(5) as $app) { $events->push([ 'at' => $app->updated_at ?? $app->created_at, 'type' => 'Application', 'title' => $app->reference, 'amount' => (float) $app->displayPrincipal(), 'meta' => str((string) $app->stage)->headline(), 'href' => route('loan.book.applications.show', $app), 'tone' => 'info', ]); } foreach (array_slice($communicationTimeline ?? [], 0, 5) as $item) { $events->push([ 'at' => filled($item['occurred_at'] ?? null) ? \Illuminate\Support\Carbon::parse($item['occurred_at']) : null, 'type' => ucfirst((string) ($item['channel'] ?? 'SMS')), 'title' => str($item['event'] ?? $item['template_code'] ?? 'Message')->limit(48)->toString(), 'amount' => null, 'meta' => (string) ($item['delivery_canonical'] ?? $item['status'] ?? ''), 'href' => null, 'tone' => in_array(strtolower((string) ($item['delivery_canonical'] ?? $item['status'] ?? '')), ['failed', 'undelivered'], true) ? 'danger' : 'neutral', ]); } foreach (($clientTransfers ?? collect())->take(3) as $transfer) { $events->push([ 'at' => $transfer->created_at, 'type' => 'Transfer', 'title' => ($transfer->to_branch ?: 'Reassigned'), 'amount' => null, 'meta' => $transfer->toEmployee?->full_name, 'href' => null, 'tone' => 'neutral', ]); } foreach (($walletStatement ?? collect())->take(3) as $tx) { $events->push([ 'at' => $tx->created_at ?? $tx->transaction_at ?? null, 'type' => 'Wallet', 'title' => str((string) ($tx->type ?? 'Tx'))->headline(), 'amount' => (float) ($tx->amount ?? 0), 'meta' => null, 'href' => null, 'tone' => 'neutral', ]); } $timeline = $events ->filter(fn ($e) => $e['at'] !== null) ->sortByDesc(fn ($e) => $e['at']) ->take(10) ->values(); $grouped = $timeline->groupBy(fn ($e) => $e['at']->format('Y-m-d')); @endphp @if ($timeline->isNotEmpty()) Recent activity View full timeline → @foreach ($grouped as $dateKey => $dayEvents) @php $dateLabel = $dayEvents->first()['at']->isToday() ? 'Today' : ($dayEvents->first()['at']->isYesterday() ? 'Yesterday' : $dayEvents->first()['at']->format('M j, Y')); @endphp {{ $dateLabel }} @foreach ($dayEvents as $event) @php $toneDot = match ($event['tone'] ?? 'neutral') { 'success' => 'bg-emerald-500', 'danger' => 'bg-rose-500', 'info' => 'bg-sky-500', default => 'bg-slate-300', }; @endphp @if (! empty($event['href'])) {{ $event['title'] }} @else {{ $event['title'] }} @endif @if (! empty($event['meta'])) ยท {{ $event['meta'] }} @endif @if ($event['amount'] !== null) KES {{ number_format($event['amount'], 0) }} @endif {{ $event['at']->format('g:i A') }} @endforeach @endforeach @else Recent activity No recent activity recorded. @endif
@if (! empty($event['href'])) {{ $event['title'] }} @else {{ $event['title'] }} @endif @if (! empty($event['meta'])) ยท {{ $event['meta'] }} @endif
No recent activity recorded.