BBnepal-Accounts/account/application/views/accounts/balances/bycategory.php

84 lines
3.1 KiB
PHP
Raw Normal View History

2024-07-10 12:43:19 +00:00
<?php
$drWidth = 250;
$crWidth = 250;
$AccountCategories = $this->acc->getAccountCategories($acgroup_id);
$array = json_decode(json_encode($AccountCategories), true);
2024-08-09 06:08:11 +00:00
$tree = buildCategoryTree($array, false);
2024-07-10 12:43:19 +00:00
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;
}
2024-08-09 06:08:11 +00:00
function displayCategoryTree($tree)
{
2024-07-10 12:43:19 +00:00
echo '<table class="table table-bordered">';
foreach ($tree as $category) {
2024-08-12 10:36:46 +00:00
// print_r($category);die;
2024-07-10 12:43:19 +00:00
echo '<tr>';
echo '<td class="col-1">' . $category['accategory_id'] . '</td>';
2024-08-12 10:36:46 +00:00
echo '<td class="col-6">'. ($category['parent_category_id'] == 0 ? "<b>" : "") .'<a href="' . site_url("accounts/reports/balance_by_group") . "?category=" . $category['accategory_id'] . '">' . $category['accategory_name'] . '</a>' .( $category['parent_category_id'] == 0? "</b>" : "") . '</td>';
2024-08-09 06:08:11 +00:00
echo '<td class="col-2">' . myCurrency($category['dr']) . '</td>';
echo '<td class="col-2">' . myCurrency($category['cr']) . '</td>';
2024-07-10 12:43:19 +00:00
echo '</tr>';
if (isset($category['children']) && !empty($category['children'])) {
echo '<tr>';
2024-08-09 06:08:11 +00:00
echo '<td colspan="4 ">';
2024-07-10 12:43:19 +00:00
displayCategoryTree($category['children']);
echo '</td>';
echo '</tr>';
}
}
echo '</table>';
}
?>
<style>
.expandable {
text-decoration: underline;
}
2024-08-09 06:08:11 +00:00
2024-07-10 12:43:19 +00:00
</style>
<div class="content-wrapper">
<div class="content">
<div class="container-fluid">
2024-08-09 06:08:11 +00:00
<?php //pre($tree);
?>
2024-07-10 12:43:19 +00:00
<div class="row">
<div class="col">
<div class="card card-primary card-outline">
<div class="card-header">
<h5 class="m-0"><?php echo $pageTitle; ?> </h5>
</div>
<div class="card-body">
<input type="checkbox" name="showZero" value="true" id="showZero">
<label for="showZero">
2024-08-09 06:08:11 +00:00
Show Zero Balances
</label>
2024-07-10 12:43:19 +00:00
<?php displayCategoryTree($tree); ?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<script>
function toggleSubTable(row) {
var subTable = row.nextElementSibling;
subTable.style.display = subTable.style.display === 'none' ? 'table-row' : 'none';
}
</script>
</div>
2024-08-09 06:08:11 +00:00
<!-- /.content -->