<?php
$this->load->library("BIBAccounts");
$BIBAccounts = new BIBAccounts();
?>
<style>
    .expandable {
        text-decoration: underline;
    }
</style>
<div class="content-wrapper">
    <div class="content">
        <div class="container-fluid">
            
            <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">
                        <?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalances(); ?>
                            <table class="table table-bordered longdataTable">
                                <thead>
                                    <tr>
                                        <th>Account</th>
                                        <th width="<?php echo $drWidth; ?>">Dr</th>
                                        <th width="<?php echo $crWidth; ?>">Cr</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $drTotal = 0;
                                    $crTotal = 0;
                                    foreach ($AccountGroups->accounts as $Account) :
                                        $drTotal += $AccountCategory->dr;
                                        $crTotal += $AccountCategory->cr;
                                    ?>
                                        <tr>
                                            <td>
                                                <a href="<?php echo site_url("accounts/reports/balance_by_ledger") . "?group=" . $AccountCategory->accategory_id; ?>">
                                                    <?php echo $AccountCategory->accategory_name; ?>
                                                </a>
                                            </td>
                                            <td width="<?php echo $drWidth; ?>"><?php echo myCurrency($AccountCategory->dr); ?></td>
                                            <td width="<?php echo $crWidth; ?>"><?php echo myCurrency($AccountCategory->cr); ?></td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                                <thead>
                                    <tr>
                                        <th>Total</th>
                                        <td width="<?php echo $drWidth; ?>"><?php echo myCurrency($drTotal); ?></td>
                                        <td width="<?php echo $crWidth; ?>"><?php echo myCurrency($crTotal); ?></td>
                                    </tr>
                                </thead>
                            </table>
                        </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>