@extends('app.shell') @section('body') @php /** @var \Illuminate\Support\Collection $groups */ /** @var \Illuminate\Support\Collection $expenses */ /** @var \Illuminate\Support\Collection $activities */ /** @var \Illuminate\Support\Collection $sharedLists */ /** @var \Illuminate\Support\Collection $sharedPurchases */ /** @var \App\Models\Person|null $mePerson */ /** @var float $overallBalance */ $isPositive = ($overallBalance ?? 0) >= 0; $barWidth = min((abs((float) ($overallBalance ?? 0)) / 500) * 100, 100); $locale = app()->getLocale(); $displayCurrency = request()->user()?->profile?->currency ?: 'USD'; $money = function (float $n, string $originalCurrency = 'USD') use ($displayCurrency, $locale): array { return \App\Support\Money::formatConvertedWithOriginal($n, $originalCurrency, $displayCurrency, $locale); }; $listProgress = function (\App\Models\SharedList $list): array { $total = $list->items->count(); $done = $list->items->where('done', true)->count(); return ['done' => $done, 'total' => $total]; }; $listMyBalance = function (string $listId) use ($expenses, $mePerson): float { if (! $mePerson) return 0.0; $relevant = $expenses->where('shared_list_id', $listId); $paid = (float) $relevant->where('paid_by_person_id', $mePerson->id)->sum('amount'); $share = 0.0; foreach ($relevant as $exp) { $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 !== $mePerson->id) continue; $share += (float) (data_get($row, 'amount') ?? 0); } } return round($paid - $share, 2); }; @endphp
{{-- Header --}}

{{ __('Hello') }}

{{ __('Dashboard') }}

{{ $mePerson?->avatar ?? '๐Ÿ™‚' }}
{{-- BalanceSummary --}}

{{ $isPositive ? __('You are owed overall') : __('You owe overall') }}

@php $fmtBal = $money(abs((float) ($overallBalance ?? 0)), $displayCurrency); @endphp {{ $fmtBal['primary'] }}

{{ __('Balanced') }} {{ $isPositive ? '+' : '-' }}{{ $fmtBal['primary'] }}
{{-- Groups --}}

{{ __('Your groups') }}

{{ __('See all') }}
@if ($groups->count() === 0)

{{ __('Create a group') }}

{{ __('Start splitting expenses with friends.') }}

@else @endif
{{-- Shared Lists --}}

{{ __('Shared lists') }}

@if ($sharedLists->count() > 0) {{ __('See all') }} @endif
@if ($sharedLists->count() === 0)

{{ __('Create a shared list') }}

{{ __('Track items and split the checkout.') }}

@else @endif
{{-- Shared Purchases --}}

{{ __('Shared purchases') }}

@if ($sharedPurchases->count() > 0) {{ __('See all') }} @endif
@if ($sharedPurchases->count() === 0)

{{ __('Create a shared purchase') }}

{{ __('Plan a bigger buy together.') }}

@else
@foreach ($sharedPurchases as $purchase) @php $status = $purchase->status ?? 'planning'; $statusLabel = $status === 'bought' ? __('Bought') : ($status === 'decided' ? __('Decided') : __('Planning')); $statusColor = $status === 'bought' ? 'bg-[hsl(var(--success)/0.12)] text-[hsl(var(--success))]' : ($status === 'decided' ? 'bg-primary/10 text-primary' : 'bg-secondary text-muted-foreground'); @endphp
{{ $purchase->emoji }}

{{ $purchase->name }}

{{ $statusLabel }}
@endforeach
{{ __('New') }}
@endif
{{-- Recent Activity --}} @if ($activities->count() > 0)

{{ __('Recent activity') }}

{{ __('See all') }}
@foreach ($activities->take(4) as $i => $a)
{{ $a->user?->avatar ?? '๐Ÿ™‚' }}

{{ ($mePerson && $a->user_person_id === $mePerson->id) ? __('You') : ($a->user?->name ?? __('Someone')) }} {{ $a->description }}

@if ($a->list_name || $a->group_name) {{ $a->list_name ?: $a->group_name }} ยท @endif {{ optional($a->activity_at)->diffForHumans() }}

@if ($a->amount !== null)

@php $fmtAct = $money((float) $a->amount, $displayCurrency); @endphp {{ $fmtAct['primary'] }}

@endif
@if ($i < 3)
@endif
@endforeach
@endif
@endsection