@extends('app.shell') @section('body') @php /** @var \Illuminate\Support\Collection $groups */ /** @var \Illuminate\Support\Collection $expenses */ $types = ['home', 'trip', 'event']; $typeEmoji = ['home' => '🏠', 'trip' => '✈️', 'event' => 'πŸŽ‰']; $typeLabel = ['home' => __('Home'), 'trip' => __('Trip'), 'event' => __('Event')]; $meId = $mePersonId ?? null; $locale = app()->getLocale(); $defaultCurrency = request()->user()?->profile?->currency ?: 'USD'; $totalOwed = 0.0; $totalOwe = 0.0; foreach ($groups as $g) { $balanceMap = []; foreach ($g->members as $m) { $balanceMap[$m->id] = 0.0; } foreach ($expenses as $exp) { if ($exp->group_id !== $g->id || $exp->shared_list_id) continue; $payerId = (string) $exp->paid_by_person_id; $balanceMap[$payerId] = ($balanceMap[$payerId] ?? 0) + (float) $exp->amount; $split = is_array($exp->split_among) ? $exp->split_among : []; foreach ($split as $row) { $uid = (string) (data_get($row, 'user.id') ?? data_get($row, 'userId') ?? ''); if ($uid === '') continue; $amt = (float) (data_get($row, 'amount') ?? 0); $balanceMap[$uid] = ($balanceMap[$uid] ?? 0) - $amt; } } $myAmt = $meId ? (float) ($balanceMap[$meId] ?? 0) : 0.0; if ($myAmt > 0.009) { $totalOwed += $myAmt; } elseif ($myAmt < -0.009) { $totalOwe += abs($myAmt); } } @endphp

{{ __('Shared spaces') }}

{{ __('Groups') }}

{{ __('Keep home, trips, and events organized in one place.') }}

{{ trans_choice(':count group|:count groups', $groups->count(), ['count' => $groups->count()]) }}

πŸ‘₯

{{ __('Open') }}

{{ $groups->count() }}

{{ __('Owed') }}

{{ \App\Support\Money::formatConvertedWithOriginal($totalOwed, $defaultCurrency, $defaultCurrency, $locale)['primary'] }}

{{ __('You owe') }}

{{ \App\Support\Money::formatConvertedWithOriginal($totalOwe, $defaultCurrency, $defaultCurrency, $locale)['primary'] }}

$groups->count() === 0])>
@foreach ($types as $type) @php $count = $groups->where('type', $type)->count(); @endphp @if ($count) @endif @endforeach
@foreach ($types as $type) @php $bucket = $groups->where('type', $type)->values(); @endphp @if ($bucket->count())

{{ $typeEmoji[$type] }} {{ $typeLabel[$type] }}

{{ trans_choice(':count group|:count groups', $bucket->count(), ['count' => $bucket->count()]) }}

@foreach ($bucket as $g) @php $balanceMap = []; foreach ($g->members as $m) { $balanceMap[$m->id] = 0.0; } $groupExpenses = $expenses->where('group_id', $g->id)->where('shared_list_id', null); foreach ($groupExpenses as $exp) { $payerId = (string) $exp->paid_by_person_id; $balanceMap[$payerId] = ($balanceMap[$payerId] ?? 0) + (float) $exp->amount; $split = is_array($exp->split_among) ? $exp->split_among : []; foreach ($split as $row) { $uid = (string) (data_get($row, 'user.id') ?? data_get($row, 'userId') ?? ''); if ($uid === '') continue; $amt = (float) (data_get($row, 'amount') ?? 0); $balanceMap[$uid] = ($balanceMap[$uid] ?? 0) - $amt; } } $myAmt = $meId ? (float) ($balanceMap[$meId] ?? 0) : 0.0; $displayCurrency = request()->user()?->profile?->currency ?: ($g->currency ?? 'USD'); $fmt = \App\Support\Money::formatConvertedWithOriginal((float) abs($myAmt), $g->currency ?? 'USD', $displayCurrency, $locale); $totalSpent = (float) $groupExpenses->sum('amount'); $spentFmt = \App\Support\Money::formatConvertedWithOriginal($totalSpent, $g->currency ?? 'USD', $displayCurrency, $locale); $searchText = collect([$g->name, $typeLabel[$type], $g->members->pluck('name')->join(' ')])->filter()->join(' '); @endphp {{ $g->emoji }}

{{ $g->name }}

{{ $g->members->count() }} {{ __('members') }} Β· {{ $groupExpenses->count() }} {{ __('expenses') }}

{{ $typeLabel[$type] }}
@if ($totalSpent > 0)

{{ __('Spent') }}

{{ $spentFmt['primary'] }}

@endif @if (abs($myAmt) < 0.01)

{{ __('Settled') }}

@elseif ($myAmt > 0)

{{ __('You’re owed') }}

{{ $fmt['primary'] }}

@else

{{ __('You owe') }}

{{ $fmt['primary'] }}

@endif
@endforeach
@endif @endforeach
$groups->count() > 0])>
πŸ‘₯

{{ __('No groups yet') }}

{{ __('Create your first group to start sharing.') }}

{{ __('Create group') }}
@endsection