@include('templates.pdf_header', [ 'organisation' => $organisation, 'title' => 'Income Statement', 'currency_code'=>"ass" ]) @php // Recursive function to render subcategories with indentation function renderItem($item, $level = 0) { $padding = $level * 20; // 20px per level @endphp @php if(!empty($item->children)){ foreach($item->children as $child){ renderItem($child, $level + 1); } } } @endphp @php // Helper to get subcategories from current data 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 ?? []); } // Extract subcategories $salesSubcats = getSubcategories($current, 'Sales Revenue'); $directSubcats = getSubcategories($current, 'Direct Costs'); $otherIncomeSubcats = getSubcategories($current, 'Other Income'); $operatingSubcats = getSubcategories($current, 'Operating Expenses'); $interestSubcats = getSubcategories($current, 'Interest Expenses'); $taxSubcats = getSubcategories($current, 'Taxes Expenses'); // ✅ use "Taxes Expenses" as per your JSON // Compute totals $salesTotal = $salesSubcats->sum(fn($s) => $s->total ?? 0); $directTotal = $directSubcats->sum(fn($s) => $s->total ?? 0); $otherIncomeTotal = $otherIncomeSubcats->sum(fn($s) => $s->total ?? 0); $operatingTotal = $operatingSubcats->sum(fn($s) => $s->total ?? 0); $interestTotal = $interestSubcats->sum(fn($s) => $s->total ?? 0); $taxTotal = $taxSubcats->sum(fn($s) => $s->total ?? 0); // Calculations $grossProfit = $salesTotal - $directTotal; $operatingProfit = $grossProfit + $otherIncomeTotal - $operatingTotal; $ebt = $operatingProfit - $interestTotal; $netProfit = $ebt - $taxTotal; @endphp @foreach($salesSubcats as $subcat) @php renderItem($subcat); @endphp @endforeach @foreach($directSubcats as $subcat) @php renderItem($subcat); @endphp @endforeach @foreach($otherIncomeSubcats as $subcat) @php renderItem($subcat); @endphp @endforeach @foreach($operatingSubcats as $subcat) @php renderItem($subcat); @endphp @endforeach @foreach($interestSubcats as $subcat) @php renderItem($subcat); @endphp @endforeach @foreach($taxSubcats as $subcat) @php renderItem($subcat); @endphp @endforeach
Particulars Amount ({{ $currency }})
{{ $item->name }} @if(isset($item->code)) ({{ $item->code }}) @endif {{ number_format($item->total ?? 0, 2) }}
Sales Revenue
Total Sales Revenue {{ number_format($salesTotal,2) }}
Direct Costs / Cost of Goods Sold
Total Direct Costs {{ number_format($directTotal,2) }}
Gross Profit {{ number_format($grossProfit,2) }}
Other Income
Total Other Income {{ number_format($otherIncomeTotal,2) }}
Operating Expenses
Total Operating Expenses {{ number_format($operatingTotal,2) }}
Operating Profit {{ number_format($operatingProfit,2) }}
Interest Expenses
Total Interest Expenses {{ number_format($interestTotal,2) }}
Earnings Before Tax (EBT) {{ number_format($ebt,2) }}
Income Tax Expenses
Total Income Tax Expenses {{ number_format($taxTotal,2) }}
Net Profit / Loss {{ number_format($netProfit,2) }}