@php
$totals = [
'revenue' => 0,
'other_income' => 0,
'direct_costs' => 0,
'operating_expenses' => 0,
'interest_expenses' => 0,
'tax_expenses' => 0
];
function renderItem($item, $key, &$totals, $level = 0) {
$padding = $level * 15;
$totals[$key] += $item->total ?? 0;
@endphp
| {{ $item->name }} |
{{ number_format($item->total_debit ?? 0, 2) }} |
{{ number_format($item->total_credit ?? 0, 2) }} |
@php
if(!empty($item->children)){
foreach($item->children as $child){
renderItem($child, $key, $totals, $level+1);
}
}
}
@endphp
@foreach([
['section'=>'REVENUE','items'=>$sales_revenue,'key'=>'revenue'],
['section'=>'OTHER INCOME','items'=>$other_income,'key'=>'other_income'],
['section'=>'DIRECT COSTS','items'=>$direct_costs,'key'=>'direct_costs'],
['section'=>'OPERATING EXPENSES','items'=>$operating_expenses,'key'=>'operating_expenses'],
['section'=>'INTEREST EXPENSES','items'=>$interest_expenses,'key'=>'interest_expenses'],
['section'=>'TAX EXPENSES','items'=>$tax_expenses,'key'=>'tax_expenses']
] as $group)
@foreach($group['items'] as $item)
@php renderItem($item, $group['key'], $totals); @endphp
@endforeach
| Total {{ $group['section'] }} |
{{ number_format($totals[$group['key']], 2) }} |
|
@endforeach
| Gross Profit |
{{ number_format($totals['revenue'] + $totals['other_income'], 2) }} |
|
| Operating Income |
{{ number_format(($totals['revenue'] + $totals['other_income']) - $totals['direct_costs'] - $totals['operating_expenses'], 2) }} |
|
| Net Income |
{{ number_format(($totals['revenue'] + $totals['other_income']) - $totals['direct_costs'] - $totals['operating_expenses'] - $totals['interest_expenses'] - $totals['tax_expenses'], 2) }} |
|