@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 @foreach($incomeSubcats as $subcat) @endforeach @foreach($expenseSubcats as $subcat) @endforeach @foreach($ociSubcats as $subcat) @endforeach
Particulars Amount ({{ $currency }})
Incomes
{{ $subcat->name }} {{ number_format($subcat->total ?? 0,2) }}
Total Incomes {{ number_format($incomeTotal,2) }}
Expenses
{{ $subcat->name }} {{ number_format($subcat->total ?? 0,2) }}
Total Expenses {{ number_format($expenseTotal,2) }}
Other Comprehensive Income
{{ $subcat->name }} {{ number_format($subcat->total ?? 0,2) }}
Total Other Comprehensive Income {{ number_format($ociTotal,2) }}
Net Profit / Loss {{ number_format($netProfit,2) }}