@include('templates.pdf_header', [ 'organisation' => $organisation, 'title' => 'Income Statement Comparison', 'currency_code'=>"" ]) @php // Recursive renderer for subcategories (two periods + variance) function renderItemComparison($item1, $item2 = null, $level = 0) { $padding = $level * 20; $total1 = $item1->total ?? 0; $total2 = $item2->total ?? 0; $variance = $total1 - $total2; @endphp @php if(!empty($item1->children)){ foreach($item1->children as $i => $child1){ $child2 = $item2->children[$i] ?? null; renderItemComparison($child1, $child2, $level + 1); } } } @endphp @php // Helper to match sections by name in both datasets function getSection($data, $name) { return collect($data)->firstWhere('name', $name); } // Sections $sales1 = getSection($current, 'Sales Revenue'); $sales2 = getSection($compare, 'Sales Revenue'); $direct1 = getSection($current, 'Direct Costs'); $direct2 = getSection($compare, 'Direct Costs'); $otherInc1 = getSection($current, 'Other Income'); $otherInc2 = getSection($compare, 'Other Income'); $operating1 = getSection($current, 'Operating Expenses'); $operating2 = getSection($compare, 'Operating Expenses'); $interest1 = getSection($current, 'Interest Expenses'); $interest2 = getSection($compare, 'Interest Expenses'); $tax1 = getSection($current, 'Income Tax Expenses'); $tax2 = getSection($compare, 'Income Tax Expenses'); // Totals $salesTotal1 = collect($sales1->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $salesTotal2 = collect($sales2->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $directTotal1 = collect($direct1->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $directTotal2 = collect($direct2->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $otherIncTotal1 = collect($otherInc1->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $otherIncTotal2 = collect($otherInc2->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $operatingTotal1 = collect($operating1->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $operatingTotal2 = collect($operating2->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $interestTotal1 = collect($interest1->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $interestTotal2 = collect($interest2->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $taxTotal1 = collect($tax1->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); $taxTotal2 = collect($tax2->subcategories ?? [])->sum(fn($s) => $s->total ?? 0); // Derived $grossProfit1 = $salesTotal1 - $directTotal1; $grossProfit2 = $salesTotal2 - $directTotal2; $operatingProfit1 = $grossProfit1 + $otherIncTotal1 - $operatingTotal1; $operatingProfit2 = $grossProfit2 + $otherIncTotal2 - $operatingTotal2; $ebt1 = $operatingProfit1 - $interestTotal1; $ebt2 = $operatingProfit2 - $interestTotal2; $netProfit1 = $ebt1 - $taxTotal1; $netProfit2 = $ebt2 - $taxTotal2; @endphp @foreach($sales1->subcategories ?? [] as $i => $subcat1) @php renderItemComparison($subcat1, $sales2->subcategories[$i] ?? null); @endphp @endforeach @foreach($direct1->subcategories ?? [] as $i => $subcat1) @php renderItemComparison($subcat1, $direct2->subcategories[$i] ?? null); @endphp @endforeach @foreach($otherInc1->subcategories ?? [] as $i => $subcat1) @php renderItemComparison($subcat1, $otherInc2->subcategories[$i] ?? null); @endphp @endforeach @foreach($operating1->subcategories ?? [] as $i => $subcat1) @php renderItemComparison($subcat1, $operating2->subcategories[$i] ?? null); @endphp @endforeach @foreach($interest1->subcategories ?? [] as $i => $subcat1) @php renderItemComparison($subcat1, $interest2->subcategories[$i] ?? null); @endphp @endforeach @foreach($tax1->subcategories ?? [] as $i => $subcat1) @php renderItemComparison($subcat1, $tax2->subcategories[$i] ?? null); @endphp @endforeach
Particulars {{ $period1Label }} {{ $period2Label }} Variance
{{ $item1->name }} @if(isset($item1->code)) ({{ $item1->code }}) @endif {{ number_format($total1, 2) }} {{ number_format($total2, 2) }} {{ number_format($variance, 2) }}
Sales Revenue
Total Sales Revenue {{ number_format($salesTotal1,2) }} {{ number_format($salesTotal2,2) }} {{ number_format($salesTotal1 - $salesTotal2,2) }}
Direct Costs
Total Direct Costs {{ number_format($directTotal1,2) }} {{ number_format($directTotal2,2) }} {{ number_format($directTotal1 - $directTotal2,2) }}
Gross Profit {{ number_format($grossProfit1,2) }} {{ number_format($grossProfit2,2) }} {{ number_format($grossProfit1 - $grossProfit2,2) }}
Other Income
Total Other Income {{ number_format($otherIncTotal1,2) }} {{ number_format($otherIncTotal2,2) }} {{ number_format($otherIncTotal1 - $otherIncTotal2,2) }}
Operating Expenses
Total Operating Expenses {{ number_format($operatingTotal1,2) }} {{ number_format($operatingTotal2,2) }} {{ number_format($operatingTotal1 - $operatingTotal2,2) }}
Operating Profit {{ number_format($operatingProfit1,2) }} {{ number_format($operatingProfit2,2) }} {{ number_format($operatingProfit1 - $operatingProfit2,2) }}
Interest Expenses
Total Interest Expenses {{ number_format($interestTotal1,2) }} {{ number_format($interestTotal2,2) }} {{ number_format($interestTotal1 - $interestTotal2,2) }}
Earnings Before Tax (EBT) {{ number_format($ebt1,2) }} {{ number_format($ebt2,2) }} {{ number_format($ebt1 - $ebt2,2) }}
Income Tax Expenses
Total Income Tax Expenses {{ number_format($taxTotal1,2) }} {{ number_format($taxTotal2,2) }} {{ number_format($taxTotal1 - $taxTotal2,2) }}
Net Profit / Loss {{ number_format($netProfit1,2) }} {{ number_format($netProfit2,2) }} {{ number_format($netProfit1 - $netProfit2,2) }}