{{ Tree($items) }}
@php
$gtotal = 0;
function Tree($elements, $prefix = 10) {
global $gtotal;
foreach ($elements as $k=> $element) {
if(!empty($element['invoices_total'])){
$invoiceTotal = $element['invoices_total'][0]['total_amount'];
}else {
$invoiceTotal = 0;
}
$gtotal = $gtotal + $invoiceTotal;
@endphp
{{ $element['name'] }}
@money($invoiceTotal,'USD', true)
@if (isset($element['children']))
@php
Tree($element['children'], $prefix+20 );
@endphp
@endif
@if($element['parent_id'] == NULL)
Total {{ $element['name'] }}
@money($gtotal,'USD', true)
@php
$gtotal = 0;
@endphp
@endif
@php
}
}
@endphp