@php
// parents: Collection of parent cost centers
// $account, $index, $type, $saved_centers must be passed from controller
$savedByParent = collect();
if (isset($saved_centers) && $saved_centers->count()) {
$savedByParent = $saved_centers->groupBy(function ($r) {
return optional($r->cost_center)->parent_center_id ?? 0;
});
}
@endphp
@foreach($parents as $parent)
@php
$parentId = $parent->id;
$children = $parent->children_centers ?? collect();
$rows = $savedByParent->get($parentId, collect());
$hasSavedRows = $rows->count() > 0;
@endphp
{{ $parent->{'center_name_' . trans('admin.lang')} }}
{{-- ===== Saved rows ===== --}}
@if($hasSavedRows)
@foreach($rows as $rIndex => $r)
@php
$centerId = $r->center_id;
$perc = $r->amount_perc;
$mVal = $r->cost_type == 2 ? $r->amount : 0;
$dVal = $r->cost_type == 1 ? $r->amount : 0;
@endphp
{{-- Cost Center --}}
@Lang('admin.cost_center') *
{{-- Account name --}}
{{-- Percentage --}}
{{-- Madeen/Daen --}}
{{-- Actions --}}
@endforeach
@else
{{-- ===== Default row ===== --}}
@Lang('admin.cost_center') *
@endif
@endforeach