169 lines
6.4 KiB
PHP
169 lines
6.4 KiB
PHP
<?php
|
|
$drWidth = 250;
|
|
$crWidth = 250;
|
|
$Accounts = $this->acc->getAccountsByCategory($accategory_id);
|
|
$array = json_decode(json_encode($Accounts), true);
|
|
// print_r($array);die;
|
|
$tree = buildCategoryTree($array, false);
|
|
function buildCategoryTree($categories, $parent_id = 0, $showZero = true)
|
|
{
|
|
$tree = array();
|
|
foreach ($categories as $category) {
|
|
// print_r($category);die;
|
|
// print_r(myCurrency(getBalance($category['account_id'])));die;
|
|
$category['dr'] = getDrTotal('account_id');
|
|
$category['cr'] = getCrTotal('account_id');
|
|
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 '<table id="myTable" class="table table-bordered">';
|
|
echo '<thead>';
|
|
echo '<tr>';
|
|
echo '<th>Sn</th>';
|
|
echo '<th>Account</th>';
|
|
echo '<th class="text-right">Balance</th>';
|
|
echo '</tr>';
|
|
echo '</thead>';
|
|
echo '<tbody>';
|
|
$BalanceTotal = 0;
|
|
foreach ($tree as $category) {
|
|
echo '<tr>';
|
|
echo '<td class="col-1">' . $category['account_id'] . '</td>';
|
|
echo '<td class="col-9"><a href="#" onClick="showLedger(' . $category['account_id'] . ')">' . $category['account_name'] . '</a></td>';
|
|
echo '<td class="col-2">' . myCurrency(getBalance($category['account_id'])) . '</td>';
|
|
$BalanceTotal += getBalance($category['account_id']);
|
|
echo '</tr>';
|
|
if (isset($category['children']) && !empty($category['children'])) {
|
|
echo '<tr>';
|
|
echo '<td colspan="4 ">';
|
|
displayCategoryTree($category['children']);
|
|
echo '</td>';
|
|
echo '</tr>';
|
|
}
|
|
}
|
|
echo '</tbody>';
|
|
echo '<tfoot>';
|
|
echo "<tr><th colspan=2 class='text-right'>Total</th><th class='text-right'>" . myCurrency($BalanceTotal) . "</th></tr>";
|
|
echo '</table>';
|
|
}
|
|
$html = "";
|
|
$html .= " <div class=\"modal fade\" id=\"ledgerdetails_box\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"ledgerdetails_box\" aria-hidden=\"true\">
|
|
<div class=\"modal-dialog modal-xl\" role=\"document\">
|
|
<div class=\"modal-content\">
|
|
<div class=\"modal-header\">
|
|
<h5 class=\"modal-title\" id=\"exampleModalLabel\">Ledger Details</h5>
|
|
<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">
|
|
<span aria-hidden=\"true\">×</span>
|
|
</button>
|
|
</div>
|
|
<div class=\"modal-body\" id=\"details_container\">
|
|
Ledger Details Goes Here
|
|
</div>
|
|
<!--<div class=\"modal-footer\">
|
|
<button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Close</button>
|
|
<button type=\"button\" class=\"btn btn-success\" data-dismiss=\"modal\">Print</button>
|
|
</div>-->
|
|
</div>
|
|
</div>
|
|
</div>";
|
|
$html .= '<script>function showLedger(id) {$.ajax({url: \'';
|
|
$html .= site_url("accounts/reports/ajax/getledgersummary/");
|
|
$html .= '\' + id,success: function(data) {$(\'#ledgerdetails_box #details_container\').html(data);$(\'#ledgerdetails_box\').modal(\'show\');}});}</script>';
|
|
echo $html;
|
|
?>
|
|
<style>
|
|
.expandable {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
</style>
|
|
<div class="content-wrapper">
|
|
<div class="content">
|
|
<div class="container-fluid">
|
|
<?php //pre($tree);
|
|
?>
|
|
<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">
|
|
Show Zero Balances
|
|
</label>
|
|
<?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';
|
|
}
|
|
function showLedger(id) {
|
|
// $("#accountsContainer").html("");
|
|
// alert(id);
|
|
$.ajax({
|
|
url: "<?php echo site_url("accounts/reports/ajax/getledgersummary/"); ?>" + id, //accounts/getledgersummary/
|
|
success: function(data) {
|
|
$("#ledgerdetails_box #details_container").html(data);
|
|
$("#ledgerdetails_box").modal("show");
|
|
$('.dataTable').DataTable().clear().destroy();
|
|
$(".dataTable").dataTable();
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
<!-- pdf document -->
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
|
|
|
|
<script>
|
|
document.getElementById('downloadCsv').addEventListener('click', function() {
|
|
const table = document.getElementById('myTable');
|
|
const rows = Array.from(table.rows);
|
|
const data = [];
|
|
|
|
rows.forEach((row) => {
|
|
const cells = Array.from(row.cells);
|
|
const rowData = [];
|
|
cells.forEach((cell) => {
|
|
// Handle colspan
|
|
const colspan = cell.colSpan || 1;
|
|
for (let i = 0; i < (colspan - 1); i++) {
|
|
rowData.push(''); // Fill empty cells for merged columns
|
|
}
|
|
for (let i = 0; i < 1; i++) {
|
|
rowData.push(cell.innerText.trim());
|
|
}
|
|
// Fill empty cells for colspan
|
|
});
|
|
data.push(rowData);
|
|
});
|
|
|
|
// Create a worksheet
|
|
const worksheet = XLSX.utils.aoa_to_sheet(data);
|
|
const workbook = XLSX.utils.book_new();
|
|
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
|
|
|
|
// Export to Excel
|
|
XLSX.writeFile(workbook, 'table.xlsx');
|
|
});
|
|
</script>
|
|
<!-- pdf document ends-->
|
|
</div>
|
|
<!-- /.content -->
|