@php // Computed here rather than in the component: these are three cheap // aggregates and keeping them beside the cards makes the page easy // to follow. $expToday = (float) \App\Models\IspExpense::whereDate('expense_date', today())->sum('amount'); $expMonth = (float) \App\Models\IspExpense::where('expense_date', '>=', now()->startOfMonth())->sum('amount'); $exp7 = (float) \App\Models\IspExpense::where('expense_date', '>=', now()->subDays(7))->sum('amount'); $expAll = (float) \App\Models\IspExpense::sum('amount'); $expCount = \App\Models\IspExpense::count(); @endphp
{{-- Filter Bar --}}
@foreach($categories as $key => $label) @if(isset($totals[$key]) && $totals[$key] > 0) @php $colorMap = ['item_purchase'=>'primary','raw_bill'=>'warning','employee_salary'=>'info','reseller_payout'=>'purple','miscellaneous'=>'secondary']; $c = $colorMap[$key] ?? 'secondary'; $style = $c === 'purple' ? 'background:rgba(124,58,237,.16);color:#a78bfa;border-color:rgba(124,58,237,.35);' : ''; @endphp {{ __($label) }}: Ksh {{ number_format($totals[$key], 2) }} @endif @endforeach
{{-- Grand Total Banner --}} @if($grandTotal > 0)
{{ __('Total Expenses (current filter):') }} Ksh {{ number_format($grandTotal, 2) }}
@endif {{-- Expense Table --}}
@forelse($expenses as $expense) @empty @endforelse
# {{ __('Date') }} {{ __('Category') }} {{ __('Title / Linked To') }} {{ __('Reference') }} {{ __('Added By') }} {{ __('Amount') }} {{ __('Actions') }}
{{ $loop->iteration + ($expenses->currentPage()-1) * $expenses->perPage() }} {{ $expense->expense_date->format('d M Y') }} @php $colorMap = ['item_purchase'=>'primary','raw_bill'=>'warning','employee_salary'=>'info','reseller_payout'=>'purple','miscellaneous'=>'secondary']; $c = $colorMap[$expense->category] ?? 'secondary'; $style = $c === 'purple' ? 'background:rgba(124,58,237,.16);color:#a78bfa;border:1px solid rgba(124,58,237,.35);' : ''; @endphp {{ __($expense->category_label) }}
{{ $expense->title }}
@if($expense->linkedUser)
{{ $expense->linkedUser->name }} @if($expense->linkedUser->mobile) · {{ $expense->linkedUser->mobile }}@endif
@elseif($expense->linkedReseller)
{{ $expense->linkedReseller->user?->name ?? 'Tenant' }} @if($expense->linkedReseller->company) ({{ $expense->linkedReseller->company }})@endif
@elseif($expense->description)
{{ Str::limit($expense->description, 55) }}
@endif
{{ $expense->reference_no ?? '—' }} {{ $expense->addedBy?->name ?? '—' }} Ksh {{ number_format($expense->amount, 2) }}
{{ __('No expenses found for the selected filters.') }}
@if($expenses->hasPages())
{{ $expenses->links() }}
@endif
{{-- ── Add / Edit Modal ─────────────────────────────────────── --}} @if($showModal) @endif {{-- ── Print Preview Modal ─────────────────────────────────── --}} @if($printExpense) @endif
@push('scripts') @endpush