function sheet()
{
    $rep = new grp_report();
    $report = $rep->getReport();
    $selected = $rep->selected;
    $gdebit = $rep->totdebit;
    $gcredit = $rep->totcredit;
    $totdebit = 0;
    $totcredit = 0;
    $sql = "SELECT * FROM trial_bal WHERE div = '" . USER_DIV . "' order by topacc,accnum ASC";
    $accRslt = db_exec($sql) or errDie("Unable to get group accounts information.");
    while ($acc = pg_fetch_array($accRslt)) {
        if (in_array($acc['accid'], $selected)) {
            continue;
        }
        $report .= "<tr><td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>";
        if (true) {
            if ($acc['debit'] > $acc['credit']) {
                $acc['debit'] = sprint($acc['debit'] - $acc['credit']);
                $acc['credit'] = "0.00";
            }
            if ($acc['credit'] > $acc['debit']) {
                $acc['credit'] = sprint($acc['credit'] - $acc['debit']);
                $acc['debit'] = "0.00";
            }
            if ($acc['credit'] == $acc['debit']) {
                $acc['credit'] = "0.00";
                $acc['debit'] = "0.00";
            }
        }
        if (floatval($acc['debit']) == 0) {
            $report .= "<td align=right> - </td>";
        } else {
            $report .= "<td align=right>{$acc['debit']}</td>";
        }
        if (floatval($acc['credit']) == 0) {
            $report .= "<td align=right> - </td>";
        } else {
            $report .= "<td align=right>{$acc['credit']}</td>";
        }
        $report .= "</tr>";
        $totdebit += $acc['debit'];
        $totcredit += $acc['credit'];
    }
    $totdebit = sprint($totdebit + $gdebit);
    $totcredit = sprint($totcredit + $gcredit);
    /* -- Final Layout -- */
    $details = "Trial Balance\r\n\t<table cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' border=0 width=600>\r\n\t<tr><th width=40%></th><th width=30%>Debit</th><th width=30%>Credit</th></tr>\r\n\t{$report}\r\n\t<tr><td><b>Total</b></td><td align=right><b>{$totdebit}</b></td><td align=right><b>{$totcredit}</b></td></tr>\r\n\t<tr><td><br></td></tr>\r\n\t</table>";
    return $details;
}
function sheet()
{
    $rep = new grp_report();
    $report = $rep->getReport();
    $selected = $rep->selected;
    $gdebit = $rep->totdebit;
    $gcredit = $rep->totcredit;
    $totdebit = 0;
    $totcredit = 0;
    $sql = "SELECT * FROM trial_bal WHERE period='" . PRD_DB . "' AND div = '" . USER_DIV . "' order by topacc,accnum ASC";
    $accRslt = db_exec($sql) or errDie("Unable to get group accounts information.");
    while ($acc = pg_fetch_array($accRslt)) {
        if (in_array($acc['accid'], $selected)) {
            continue;
        }
        $report .= "<tr class='bg-odd'><td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>";
        if (true) {
            if ($acc['debit'] > $acc['credit']) {
                $acc['debit'] = sprint($acc['debit'] - $acc['credit']);
                $acc['credit'] = 0;
            }
            if ($acc['credit'] > $acc['debit']) {
                $acc['credit'] = sprint($acc['credit'] - $acc['debit']);
                $acc['debit'] = 0;
            }
            if ($acc['credit'] == $acc['debit']) {
                $acc['credit'] = 0;
                $acc['debit'] = 0;
            }
        }
        if (floatval($acc['debit']) == 0) {
            $report .= "<td align=right> - </td>";
        } else {
            $report .= "<td align=right>{$acc['debit']}</td>";
        }
        if (floatval($acc['credit']) == 0) {
            $report .= "<td align=right> - </td>";
        } else {
            $report .= "<td align=right>{$acc['credit']}</td>";
        }
        $report .= "</tr>";
        $totdebit += $acc['debit'];
        $totcredit += $acc['credit'];
    }
    $totdebit = sprint($totdebit + $gdebit);
    $totcredit = sprint($totcredit + $gcredit);
    /* -- Final Layout -- */
    $details = "<center>\n\t<h3>\n\t  " . COMP_NAME . " Trial Balance as at<br>\n\t  " . date("Y-m-d") . "\n\t</h3>\n\t<b>Author:</b> " . USER_NAME . "\n\t<form action='" . SELF . "' method=post name=form1>\n\t<input type=hidden name=key value=update>\n\t<table cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' border=0 width=600>\n\t<tr><th width=40%></th><th width=30%>Debit</th><th width=30%>Credit</th></tr>\n\t{$report}\n\t<tr class='bg-even'><td><b>Total</b></td><td align=right><b>{$totdebit}</b></td><td align=right><b>{$totcredit}</b></td></tr>\n\t<tr><td><br></td></tr>\n\t<tr><td colspan=2></form><form action='../xls/gen-trial-balance-xls.php' method=post name=form><input type=hidden name=key value=print><input type=submit name=xls value='Export to spreadsheet'></form></td></tr>\n\t</table></form>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=25%>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class=datacell><td align=center><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t</table></center>";
    return $details;
}