This commit is contained in:
Raju Shrestha 2024-08-09 11:53:11 +05:45
parent e9fc0b8270
commit 213be12e2a
2 changed files with 19 additions and 35 deletions

View File

@ -3,19 +3,16 @@ $drWidth = 250;
$crWidth = 250; $crWidth = 250;
$AccountCategories = $this->acc->getAccountCategories($acgroup_id); $AccountCategories = $this->acc->getAccountCategories($acgroup_id);
$array = json_decode(json_encode($AccountCategories), true); $array = json_decode(json_encode($AccountCategories), true);
$tree=buildCategoryTree($array, false); $tree = buildCategoryTree($array, false);
function buildCategoryTree($categories, $parent_id = 0, $showZero = true) function buildCategoryTree($categories, $parent_id = 0, $showZero = true)
{ {
$tree = array(); $tree = array();
foreach ($categories as $category) { foreach ($categories as $category) {
if ($category['parent_category_id'] == $parent_id) { if ($category['parent_category_id'] == $parent_id) {
$children = buildCategoryTree($categories, $category['accategory_id'], $showZero); $children = buildCategoryTree($categories, $category['accategory_id'], $showZero);
if (!empty($children)) { if (!empty($children)) {
$category['children'] = $children; $category['children'] = $children;
} }
if ($showZero && ($category['dr'] !== 0 || $category['cr'] !== 0)) { if ($showZero && ($category['dr'] !== 0 || $category['cr'] !== 0)) {
$tree[] = $category; $tree[] = $category;
} elseif (!$showZero && ($category['dr'] !== 0 && $category['cr'] !== 0)) { } elseif (!$showZero && ($category['dr'] !== 0 && $category['cr'] !== 0)) {
@ -23,24 +20,21 @@ function buildCategoryTree($categories, $parent_id = 0, $showZero = true)
} }
} }
} }
return $tree; return $tree;
} }
function displayCategoryTree($tree)
function displayCategoryTree($tree) { {
echo '<table class="table table-bordered">'; echo '<table class="table table-bordered">';
foreach ($tree as $category) { foreach ($tree as $category) {
echo '<tr>'; echo '<tr>';
echo '<td class="col-1">' . $category['accategory_id'] . '</td>'; echo '<td class="col-1">' . $category['accategory_id'] . '</td>';
echo '<td><a href="'.site_url("accounts/reports/balance_by_group") . "?category=" . $category['accategory_id'] .'">' . $category['accategory_name'] . '</a></td>'; echo '<td class="col-6"><a href="' . site_url("accounts/reports/balance_by_group") . "?category=" . $category['accategory_id'] . '">' . $category['accategory_name'] . '</a></td>';
echo '<td width="250">' . myCurrency($category['dr']) . '</td>'; echo '<td class="col-2">' . myCurrency($category['dr']) . '</td>';
echo '<td>' . myCurrency($category['cr']) . '</td>'; echo '<td class="col-2">' . myCurrency($category['cr']) . '</td>';
echo '</tr>'; echo '</tr>';
if (isset($category['children']) && !empty($category['children'])) { if (isset($category['children']) && !empty($category['children'])) {
echo '<tr>'; echo '<tr>';
echo '<td colspan="4">'; echo '<td colspan="4 ">';
displayCategoryTree($category['children']); displayCategoryTree($category['children']);
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';
@ -53,12 +47,13 @@ function displayCategoryTree($tree) {
.expandable { .expandable {
text-decoration: underline; text-decoration: underline;
} }
</style> </style>
<div class="content-wrapper"> <div class="content-wrapper">
<div class="content"> <div class="content">
<div class="container-fluid"> <div class="container-fluid">
<?php //pre($tree); ?> <?php //pre($tree);
?>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<div class="card card-primary card-outline"> <div class="card card-primary card-outline">
@ -68,7 +63,7 @@ function displayCategoryTree($tree) {
<div class="card-body"> <div class="card-body">
<input type="checkbox" name="showZero" value="true" id="showZero"> <input type="checkbox" name="showZero" value="true" id="showZero">
<label for="showZero"> <label for="showZero">
Show Zero Balances Show Zero Balances
</label> </label>
<?php displayCategoryTree($tree); ?> <?php displayCategoryTree($tree); ?>
</div> </div>
@ -77,8 +72,6 @@ function displayCategoryTree($tree) {
</div> </div>
</div> </div>
</div> </div>
<div class="container"> <div class="container">
<script> <script>
function toggleSubTable(row) { function toggleSubTable(row) {
@ -86,9 +79,5 @@ function displayCategoryTree($tree) {
subTable.style.display = subTable.style.display === 'none' ? 'table-row' : 'none'; subTable.style.display = subTable.style.display === 'none' ? 'table-row' : 'none';
} }
</script> </script>
</div> </div>
<!-- /.content -->
<!-- /.content -->

View File

@ -1,31 +1,26 @@
<div class="content-wrapper"> <div class="content-wrapper">
<div class="content"> <div class="content">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<div class="card card-primary card-outline"> <div class="card card-primary card-outline">
<div class="card-header"> <div class="card-header">
<h5 class="m-0"><?php echo $pageTitle; ?> <?php showCreateButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/add", "Create New " . $pageTitle); ?></h5>
<h5 class="m-0"><?php echo $pageTitle; ?> <?php showCreateButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/add","Create New ".$pageTitle); ?></h5>
</div> </div>
<div class="card-body "> <div class="card-body ">
<?php $TableData = $this->db->query("select * from tbl_translations where status=1")->result(); ?> <?php $TableData = $this->db->query("select * from tbl_translations where status=1")->result(); ?>
<table class="table table-bordered table-striped longdataTable"> <table class="table table-bordered table-striped longdataTable">
<thead> <thead>
<tr> <tr>
<th class="text-center col-1"><?php myLang('Translation Id'); ?></th> <th class="text-center col-1"><?php myLang('Translation Id'); ?></th>
<th class="text-center col-2"><?php myLang('English'); ?></th> <th class="text-center col-5"><?php myLang('English'); ?></th>
<th class="text-center col-2"><?php myLang('Nepali'); ?></th> <th class="text-center col-5"><?php myLang('Nepali'); ?></th>
<th class="text-center col-1"><?php myLang('Action'); ?></th> <th class="text-center col-1"><?php myLang('Action'); ?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $a=0; foreach ($TableData as $TableRow) : $a++; ?> <?php $a = 0;
foreach ($TableData as $TableRow) : $a++; ?>
<?php foreach ($TableRow as $cols) : $id = $cols; <?php foreach ($TableRow as $cols) : $id = $cols;
break; break;
endforeach; ?><tr> endforeach; ?><tr>