@include('templates.pdf_header', [
'organisation' => $organisation,
'title' => 'Income Statement',
'currency_code' => $currency
])
@php
function getSubcategories($current, $sectionName){
// Flatten all items across sections
$items = collect($current)->flatMap(fn($section) => $section->items ?? []);
// Find the matching item by name
$item = $items->firstWhere('name', $sectionName);
// Return its subcategories
return collect($item->subcategories ?? []);
}
// Group incomes
$incomeSubcats = collect(getSubcategories($current, 'Sales Revenue'))
->merge(getSubcategories($current, 'Other Income'));
$incomeTotal = $incomeSubcats->sum(fn($s) => $s->total ?? 0);
// Group all expenses
$expenseSubcats = collect(getSubcategories($current, 'Direct Costs'))
->merge(getSubcategories($current, 'Operating Expenses'))
->merge(getSubcategories($current, 'Interest Expenses'))
->merge(getSubcategories($current, 'Taxes Expenses'));
$expenseTotal = $expenseSubcats->sum(fn($s) => $s->total ?? 0);
// Other comprehensive income (optional - can come from data)
$ociSubcats = collect(getSubcategories($current, 'Other Comprehensive Income'));
$ociTotal = $ociSubcats->sum(fn($s) => $s->total ?? 0);
// Net profit
$netProfit = $incomeTotal - $expenseTotal + $ociTotal;
@endphp
| Particulars |
Amount ({{ $currency }}) |
@foreach($incomeSubcats as $subcat)
| {{ $subcat->name }} |
{{ number_format($subcat->total ?? 0,2) }} |
@endforeach
| Total Incomes |
{{ number_format($incomeTotal,2) }} |
@foreach($expenseSubcats as $subcat)
| {{ $subcat->name }} |
{{ number_format($subcat->total ?? 0,2) }} |
@endforeach
| Total Expenses |
{{ number_format($expenseTotal,2) }} |
@foreach($ociSubcats as $subcat)
| {{ $subcat->name }} |
{{ number_format($subcat->total ?? 0,2) }} |
@endforeach
| Total Other Comprehensive Income |
{{ number_format($ociTotal,2) }} |
| Net Profit / Loss |
{{ number_format($netProfit,2) }} |