acc->getAccountCategories($acgroup_id); $array = json_decode(json_encode($AccountCategories), true); $tree=buildCategoryTree($array, false); function buildCategoryTree($categories, $parent_id = 0, $showZero = true) { $tree = array(); foreach ($categories as $category) { if ($category['parent_category_id'] == $parent_id) { $children = buildCategoryTree($categories, $category['accategory_id'], $showZero); if (!empty($children)) { $category['children'] = $children; } if ($showZero && ($category['dr'] !== 0 || $category['cr'] !== 0)) { $tree[] = $category; } elseif (!$showZero && ($category['dr'] !== 0 && $category['cr'] !== 0)) { $tree[] = $category; } } } return $tree; } function displayCategoryTree($tree) { echo ''; foreach ($tree as $category) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if (isset($category['children']) && !empty($category['children'])) { echo ''; echo ''; echo ''; } } echo '
' . $category['accategory_id'] . '' . $category['accategory_name'] . '' . myCurrency($category['dr']) . '' . myCurrency($category['cr']) . '
'; displayCategoryTree($category['children']); echo '
'; } ?>
Particulars Opening This Year Closing
Dr. Amount Cr. Amount Dr. Amount Cr. Amount Dr. Amount Cr. Amount
10
Current Assets
Bank Assets
Nabil Bank
RBB Bank
Another Grandchild
Child 1
Child 2