Expenses & P&L

@if(session('success'))
{{ session('success') }}
@endif @php $months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; $catColors = [ 'rent' => 'bg-blue-200', 'utilities' => 'bg-yellow-200', 'salaries' => 'bg-purple-200', 'equipment' => 'bg-orange-200', 'maintenance' => 'bg-red-200', 'marketing' => 'bg-pink-200', 'supplies' => 'bg-teal-200', 'insurance' => 'bg-indigo-200', 'software' => 'bg-cyan-200', 'miscellaneous' => 'bg-gray-200', ]; $methodBadge = [ 'cash' => 'bg-green-100 text-green-700', 'bank_transfer' => 'bg-blue-100 text-blue-700', 'upi' => 'bg-purple-100 text-purple-700', 'card' => 'bg-orange-100 text-orange-700', 'cheque' => 'bg-gray-100 text-gray-600', ]; $fmtAmt = fn($n) => $n >= 100000 ? '₹' . number_format($n/100000, 1) . 'L' : ($n >= 1000 ? '₹' . number_format($n/1000, 1) . 'K' : '₹' . number_format(abs($n ?? 0))); $maxCat = max(array_values(is_array($by_category ?? null) ? $by_category : collect($by_category ?? [])->toArray()) + [1]); @endphp {{-- Add Expense Modal --}}

Record Expense

@csrf
@error('title')

{{ $message }}

@enderror
{{-- Month picker --}}
{{-- KPI row --}}

Revenue

{{ $fmtAmt($total_revenue) }}

{{ $months[$month - 1] }} {{ $year }}

Expenses

{{ $fmtAmt($total_expense) }}

{{ $months[$month - 1] }} {{ $year }}

Net {{ $net_profit >= 0 ? 'Profit' : 'Loss' }}

{{ $net_profit < 0 ? '-' : '' }}{{ $fmtAmt(abs($net_profit)) }}

{{ $total_revenue > 0 ? round($net_profit / $total_revenue * 100) : 0 }}% margin

{{-- Expense table --}}

Expenses — {{ $months[$month - 1] }} {{ $year }}

{{ $expenses->total() }} entries
@if($expenses->isEmpty())

No expenses recorded

for {{ $months[$month - 1] }} {{ $year }}

@else
@foreach($expenses as $e) {{-- Inline edit row --}} @endforeach
Date Description Category Amount Method
{{ \Carbon\Carbon::parse($e->expense_date)->format('d M') }}

{{ $e->title }}

@if($e->vendor)

{{ $e->vendor }}

@endif
{{ $category_icons[$e->category] ?? '' }} {{ $e->category }} @if($e->is_recurring) {{ $e->recurrence }} @endif
₹{{ number_format($e->amount, 0) }} {{ str_replace('_', ' ', $e->payment_method) }}
@csrf @method('PATCH')
@endif
{{ $expenses->withQueryString()->links() }}
{{-- Right sidebar: charts --}}
{{-- P&L trend bar chart --}}

P&L Trend

@php $maxPL = max(1, ...array_map(fn($d) => max($d['revenue'] ?? 0, $d['expense'] ?? 0), collect($pl_trend ?? [])->toArray())); @endphp
@foreach($pl_trend ?? [] as $d)
{{ $d['label'] }}
@endforeach
Revenue Expenses
{{-- Category breakdown --}}

By Category

@if(empty($by_category))

No expenses this month.

@else
@foreach($by_category as $cat => $amt)
{{ $category_icons[$cat] ?? '' }}
{{ $fmtAmt($amt) }}
@endforeach
@endif
{{-- Profit margin --}}

Profit Margin

{{ $total_revenue > 0 ? round($net_profit / $total_revenue * 100) : 0 }}%

{{ $net_profit >= 0 ? $fmtAmt($net_profit) . ' profit' : $fmtAmt(abs($net_profit)) . ' loss' }}