function slctacc($_POST)
{
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($year, "string", 3, 4, "Invalid year.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = $v->genErrors();
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    db_conn('core');
    $Sl = "SELECT * FROM year WHERE yrdb='{$year}'";
    $Ri = db_exec($Sl) or errDie("Unable to get data.");
    $yd = pg_fetch_array($Ri);
    global $PRDMON;
    $fprds = finMonList("fprd", $PRDMON[1], false, $yd["yrname"]);
    $tprds = finMonList("tprd", PRD_DB, false, $yd["yrname"]);
    db_connect();
    $sql = "SELECT * FROM stock WHERE div = '" . USER_DIV . "' ORDER BY stkdes ASC";
    $stkRslt = db_exec($sql) or errDie("Could not retrieve Stock Information from the Database.", SELF);
    if (pg_numrows($stkRslt) < 1) {
        return "<li class='err'> There are no Stock Items in Cubit.</li>";
    }
    $stks = "<select name=stkids[] multiple size=10>";
    while ($stk = pg_fetch_array($stkRslt)) {
        $stks .= "<option value='{$stk['stkid']}'>{$stk['stkcod']} {$stk['stkdes']}</option>";
    }
    $stks .= "</select>";
    $slctacc = "\n\t\t<p>\n\t\t<h3>Inventory Ledger</h3>\n\t\t<h4>Select Options</h4>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t<input type='hidden' name='year' value='{$year}'>\n\t\t\t<input type='hidden' name='fprd' value='{$fprd}'>\n\t\t\t<input type='hidden' name='tprd' value='{$tprd}'>\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Stock Items</td>\n\t\t\t\t<td><input type='radio' name='accnt' value='slct' checked='yes'>Selected Items | <input type='radio' name='accnt' value='all'>All Items</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Select Stock Item(s)</td>\n\t\t\t\t<td>{$stks}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Select period</td>\n\t\t\t\t<td>{$fprds} to {$tprds}</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td align='center'></td>\n\t\t\t\t<td align='right'><input type='submit' value='Continue &raquo;'></td>\n\t\t\t</tr>\n\t\t</table>";
    return $slctacc;
}
function slctAcc()
{
    global $PRDMON;
    $fprd = finMonList("fprd", $PRDMON[1]);
    $tprd = finMonList("tprd", PRD_DB);
    // Layout
    $slctAcc = "\n\t\t<h3>Select Options</h3>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'>Period Range</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>From : {$fprd}</td>\n\t\t\t\t<td>To : {$tprd}</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td align='right'><input type='submit' value='View All &raquo;'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>\n\t\t<p>\n\t\t<table " . bgcolorg() . " width='100'>\n\t\t\t<tr><th>Quick Links</th></tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='index-reports-journal.php'>Current Year Details General Ledger Reports</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</a></td>\n\t\t\t</tr>\n\t\t</table>";
    return $slctAcc;
}
function slctacc($_POST)
{
    extract($_POST);
    # from period
    global $PRDMON;
    $fprds = finMonList("fprd", $PRDMON[1]);
    $tprds = finMonList("tprd", PRD_DB);
    if (isset($sortby) && $sortby == "desc_store") {
        $orderby = "ORDER BY stkcod ASC";
    } else {
        $orderby = "ORDER BY whid ASC";
    }
    db_connect();
    $sql = "SELECT * FROM stock WHERE div = '" . USER_DIV . "' {$orderby}";
    $stkRslt = db_exec($sql) or errDie("Could not retrieve Stock Information from the Database.", SELF);
    if (pg_numrows($stkRslt) < 1) {
        return "<li class='err'> There are no Stock Items in Cubit.</li>";
    }
    $stks = "<select name='stkids[]' multiple size='10'>";
    while ($stk = pg_fetch_array($stkRslt)) {
        db_conn("exten");
        #get this warehouse/store name
        $get_store = "SELECT * FROM warehouses WHERE whid = '{$stk['whid']}' AND div = '" . USER_DIV . "' LIMIT 1";
        $run_store = db_exec($get_store) or errDie("Unable to get get store information");
        if (pg_numrows($run_store) < 1) {
            $store = "";
        } else {
            $arr = pg_fetch_array($run_store);
            $store = "({$arr['whname']})";
        }
        if (!isset($sortby)) {
            $sortby = "store_desc";
        }
        $sel1 = "";
        $sel2 = "";
        if ($sortby == "desc_store") {
            $sort = "{$stk['stkcod']} {$stk['stkdes']} {$store}";
            $sel2 = "checked='yes'";
        } else {
            $sort = "{$store} {$stk['stkcod']} {$stk['stkdes']}";
            $sel1 = "checked='yes'";
        }
        $stks .= "<option value='{$stk['stkid']}'>{$sort}</option>";
    }
    $stks .= "</select>";
    $ssel1 = "";
    $ssel2 = "";
    if (isset($accnt) and $accnt == "all") {
        $ssel2 = "checked='yes'";
    } else {
        $ssel1 = "checked='yes'";
    }
    $slctacc = "\n\t\t\t\t\t<p>\n\t\t\t\t\t<h3>Inventory Ledger</h3>\n\t\t\t\t\t<h4>Select Options</h4>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<form action='" . SELF . "' method='POST' name='form1'>\n\t\t\t\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Field</th>\n\t\t\t\t\t\t\t<th>Value</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td valign='top'>Stock Items</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<input type='radio' name='accnt' value='slct' {$ssel1}>Selected Items | \n\t\t\t\t\t\t\t\t<input type='radio' name='accnt' value='all' {$ssel2}>All Items\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Sort Method</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<input type='radio' name='sortby' value='store_desc' {$sel1} onChange='javascript:document.form1.submit()'>Store - Description |\n\t\t\t\t\t\t\t\t<input type='radio' name='sortby' value='desc_store' {$sel2} onChange='javascript:document.form1.submit()'>Description - Store\n\t\t\t\t\t\t\t</td> \n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td valign='top'>Select Stock Item(s)</td>\n\t\t\t\t\t\t\t<td>{$stks}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Select period</td>\n\t\t\t\t\t\t\t<td>{$fprds} to {$tprds}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t" . TBL_BR . "\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='center'></td>\n\t\t\t\t\t\t\t<td align='right'><input type='submit' name='continue' value='Continue &raquo;'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<p>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t\t<td align='center'><a href='index-reports-other.php'>Other Reports</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>";
    return $slctacc;
}
function slctAcc()
{
    // Layout
    $slctAcc = "\n\t\t<h3>Select Account</h3>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Account Name</td>\n\t\t\t\t<td>\n\t\t\t\t\t<select name='accid'>";
    core_connect();
    $sql = "SELECT * FROM accounts WHERE div = '" . USER_DIV . "' ORDER BY accname ASC";
    $accRslt = db_exec($sql) or errDie("Could not retrieve Categories Information from the Database.", SELF);
    if (pg_numrows($accRslt) < 1) {
        return "<li class='err'> There are no Accounts in Cubit.</li>";
    }
    while ($acc = pg_fetch_array($accRslt)) {
        $slctAcc .= "<option value='{$acc['accid']}'>{$acc['accname']}</option>";
    }
    $slctAcc .= "\n\t\t\t\t\t</select>\n\t\t\t\t</td>\n\t\t\t\t<td><input type='submit' name='details' value='View Transactions'></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'><td colspan='3'><br></td></tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Account Number</td>\n\t\t\t\t<td><input type='text' name='topacc' size='4' maxlength='4'> / <input type='text' name='accnum' size='3' maxlength='3'></td>\n\t\t\t\t<td><input type='submit' value='View Transactions'></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Select Period</td>\n\t\t\t\t<td valign='center' colspan='3'>" . finMonList("prd", PRD_DB) . "</td>\n\t\t\t</tr>\n\t\t\t<tr><td></td></tr>\n\t\t</form>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . " width='100'>\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td></tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='index-reports-journal.php'>Current Year Details General Ledger Reports</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</a></td>\n\t\t\t</tr>\n\t\t</table>";
    return $slctAcc;
}
function slctacc()
{
    $prds = finMonList("prd", PRD_DB);
    core_connect();
    $sql = "SELECT * FROM accounts WHERE div = '" . USER_DIV . "' ORDER BY accname ASC";
    $accRslt = db_exec($sql) or errDie("Could not retrieve Categories Information from the Database.", SELF);
    if (pg_numrows($accRslt) < 1) {
        return "<li class='err'> There are no Accounts in Cubit.";
    }
    $accs = "<select name='accids[]' multiple size='10'>";
    while ($acc = pg_fetch_array($accRslt)) {
        $accs .= "<option value='{$acc['accid']}'>{$acc['accname']}</option>";
    }
    $accs .= "</select>";
    $slctacc = "\n\t\t\t<p>\n\t\t\t<h3>Journal Entries By Ref no.</h3>\n\t\t\t<h4>Select Options</h4>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Field</th>\n\t\t\t\t\t<th>Value</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Accounts</td>\n\t\t\t\t\t<td><input type='radio' name='accnt' value='slct' checked='yes'>Selected Accounts | <input type='radio' name='accnt' value='all'>All Accounts</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Select account(s)</td>\n\t\t\t\t\t<td>{$accs}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Select period</td>\n\t\t\t\t\t<td>{$prds}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td align='right'><input type='submit' value='Continue &raquo;'></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . " width='25%'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t<td align='center'><a href='index-reports-journal.php'>Current Year Details General Ledger Reports</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</td>\n\t\t\t\t</tr>\n\t\t\t</table>";
    return $slctacc;
}
function view()
{
    core_connect();
    $sql = "SELECT * FROM accounts WHERE div = '" . USER_DIV . "' ORDER BY accname ASC";
    $accRslt = db_exec($sql) or errDie("Could not retrieve Categories Information from the Database.", SELF);
    if (pg_numrows($accRslt) < 1) {
        return "<li class='err'> There are no Accounts in Cubit.</li>";
    }
    $slctAcc = "\n\t\t<select name='accid'>\n\t\t\t<option value='0'>All Accounts</option>";
    while ($acc = pg_fetch_array($accRslt)) {
        $slctAcc .= "<option value='{$acc['accid']}'>{$acc['accname']}</option>";
    }
    $slctAcc .= "</select>";
    $prds = finMonList("prd", PRD_DB);
    //layout
    $view = "\n\t\t<center>\n\t\t<h3>Journal Entries Report</h3>\n\t\t<table cellpadding='5' width='80%'>\n\t\t\t<tr>\n\t\t\t\t<td width='60%'>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='510'>\n\t\t\t\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t\t\t\t<input type='hidden' name='key' value='viewtrans'>\n\t\t\t\t\t\t<input type='hidden' name='search' value='date'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>By Date Range</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td width='80%' align='center'>\n\t\t\t\t\t\t\t\t<table>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td>" . mkDateSelect("from") . "</td>\n\t\t\t\t\t\t\t\t\t\t<td>&nbsp;&nbsp;TO&nbsp;&nbsp;</td>\n\t\t\t\t\t\t\t\t\t\t<td>" . mkDateSelect("to") . "</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Select Period  {$prds}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>Select Account</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td colspan='2'>{$slctAcc}</td>\n\t\t\t\t\t\t\t<td valign='bottom'><input type='submit' value='Search &raquo;'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</form>\n\t\t\t\t\t" . TBL_BR . "\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='370'>\n\t\t\t\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t\t\t\t<input type='hidden' name='key' value='viewtrans'>\n\t\t\t\t\t\t<input type='hidden' name='search' value='refnum'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>By Journal number</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td width='80%' align='center'>\n\t\t\t\t\t\t\t\tFrom <input type='text' size='5' name='fromnum'> to <input type='text' size='5' name='tonum'>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td rowspan='2' valign='bottom'><input type='submit' value='View All &raquo;'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Select Period {$prds}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</form>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='370'>\n\t\t\t\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t\t\t\t<input type='hidden' name='key' value='viewtrans'>\n\t\t\t\t\t\t<input type='hidden' name='search' value='all'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>View All</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Select Period {$prds}</td>\n\t\n\t\t\t\t\t\t\t<td rowspan='2' valign='bottom'><input type='submit' value='View All &raquo;'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</form>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . " width='25%'>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'><a href='index-reports-journal.php'>Current Year Details General Ledger Reports</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</td>\n\t\t\t</tr>\n\t\t</table>";
    return $view;
}
function slctacc()
{
    global $PRDMON;
    $fprds = finMonList("fprd", $PRDMON[1]);
    $tprds = finMonList("tprd", PRD_DB);
    db_connect();
    $sql = "SELECT * FROM suppliers WHERE div = '" . USER_DIV . "' ORDER BY supid ASC";
    $supRslt = db_exec($sql) or errDie("Could not retrieve suppliers Information from the Database.", SELF);
    if (pg_numrows($supRslt) < 1) {
        return "<li class='err'> There are no suppliers in Cubit.</li>";
    }
    $supts = "<select name='supids[]' multiple size='10'>";
    while ($sup = pg_fetch_array($supRslt)) {
        $supts .= "<option value='{$sup['supid']}'>{$sup['supname']}</option>";
    }
    $supts .= "</select>";
    $slctacc = "\n\t\t\t\t\t<p>\n\t\t\t\t\t<h3>Creditors Ledger</h3>\n\t\t\t\t\t<h4>Select Options</h4>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Field</th>\n\t\t\t\t\t\t\t<th>Value</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td valign='top'></td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<input type='radio' name='accnt' value='slct' checked='yes'>Selected Accounts | \n\t\t\t\t\t\t\t\t<input type='radio' name='accnt' value='all'>All Accounts\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td valign='top'>Select Supplier(s)</td>\n\t\t\t\t\t\t\t<td>{$supts}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Select period</td>\n\t\t\t\t\t\t\t<td>{$fprds} to {$tprds}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Order By</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\tTransaction Date <input type='radio' name='t' checked value='t'>\n\t\t\t\t\t\t\t\tSystem Date <input type='radio' name='t' value='s'>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td align='right'><input type='submit' value='Continue &raquo;'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<p>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='25%'>\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t\t<td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t\t<td align='center'><a href='index-reports-debtcred.php'>Debtors & Creditors Reports</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>";
    return $slctacc;
}
function slctacc($_POST)
{
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($year, "string", 1, 10, "Invalid year.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    db_conn('core');
    $Sl = "SELECT * FROM year WHERE yrdb='{$year}'";
    $Ri = db_exec($Sl) or errDie("Unable to get data.");
    $yd = pg_fetch_array($Ri);
    # from period
    global $PRDMON;
    $fprd = finMonList("fprd", $PRDMON[1], false, $yd["yrname"]);
    $tprd = finMonList("tprd", $PRDMON[12], false, $yd["yrname"]);
    db_conn($year);
    $sql = "SELECT * FROM year_balance WHERE div = '" . USER_DIV . "' ORDER BY accname ASC";
    $accRslt = db_exec($sql) or errDie("Could not retrieve Categories Information from the Database.", SELF);
    if (pg_numrows($accRslt) < 1) {
        return "<li class='err'> There are no Accounts in Cubit.</li>";
    }
    $accs = "<select name='accids[]' multiple size='10'>";
    while ($acc = pg_fetch_array($accRslt)) {
        $accs .= "<option value='{$acc['accid']}'>{$acc['accname']}</option>";
    }
    $accs .= "</select>";
    $slctacc = "\n\t\t<p>\n\t\t<h3>Previous Year Period Range General Ledger</h3>\n\t\t<h4>Select Options</h4>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t<input type='hidden' name='year' value='{$year}'>\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Accounts</td>\n\t\t\t\t<td><input type='radio' name='accnt' value='slct' checked='yes'>Selected Accounts | <input type='radio' name='accnt' value='all'>All Accounts</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Select account(s)</td>\n\t\t\t\t<td>{$accs}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Period Range :</td>\n\t\t\t\t<td valign='center' colspan='3'>{$fprd} To : {$tprd}</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td align='center'></td>\n\t\t\t\t<td align='center'><input type='submit' value='Continue &raquo;'></td>\n\t\t\t</tr>\n\t\t</table>";
    return $slctacc;
}
function slctacc()
{
    extract($_REQUEST);
    if (!isset($prd_f)) {
        $prd_f = $prd_t = PRD_DB;
    }
    $prds_f = finMonList("prd_f", $prd_f);
    $prds_t = finMonList("prd_t", $prd_t);
    db_connect();
    $sql = "SELECT * FROM employees WHERE div = '" . USER_DIV . "' ORDER BY sname,fnames ASC";
    $supRslt = db_exec($sql) or errDie("Could not retrieve employees Information from the Database.", SELF);
    if (pg_numrows($supRslt) < 1) {
        return "<li class=err> There are no employees in Cubit.";
    }
    $supts = "<select name='supids[]' multiple size=10>";
    while ($sup = pg_fetch_array($supRslt)) {
        $supts .= "<option value='{$sup['empnum']}'>{$sup['sname']},{$sup['fnames']}</option>";
    }
    $supts .= "</select>";
    $slctacc = "\n\t<p>\n\t<h3>Employee Ledger</h3>\n\t<h4>Select Options</h4>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t<form action='" . SELF . "' method='post'>\n\t<input type='hidden' name='key' value='viewtran' />\n\t<tr>\n\t\t<th>Field</th>\n\t\t<th>Value</th>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td valign='top'></td>\n\t\t<td><input type='radio' name='accnt' value='slct' checked='yes'>Selected Accounts | <input type=radio name=accnt value=all>All Accounts</td>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td valign='top'>Select Employees(s)</td>\n\t\t<td>{$supts}</td>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Select period</td>\n\t\t<td>{$prds_f} to {$prds_t}</td>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Order By</td>\n\t\t<td>Transaction Date<input type=radio name=t checked value='t'>System Date<input type=radio name=t value='s'></td>\n\t</tr>\n\t" . TBL_BR . "\n\t<tr>\n\t\t<td></td>\n\t\t<td align='right'><input type=submit value='Continue &raquo;'></td>\n\t</tr>\n\t</table>" . mkQuickLinks(ql("../admin-employee-add.php", "Add Employee"), ql("../admin-employee-view.php", "View Employees"));
    return $slctacc;
}
function slctacc($err = "")
{
    global $PRDMON;
    core_connect();
    $sql = "SELECT * FROM accounts WHERE div = '" . USER_DIV . "' ORDER BY accname ASC";
    $accRslt = db_exec($sql) or errDie("Could not retrieve Categories Information from the Database.", SELF);
    if (pg_numrows($accRslt) < 1) {
        return "<li class='err'> There are no Accounts in Cubit.</li>";
    }
    $accs = "<select name='accids[]' multiple size='10'>";
    while ($acc = pg_fetch_array($accRslt)) {
        $accs .= "<option value='{$acc['accid']}'>{$acc['accname']}</option>";
    }
    $accs .= "</select>";
    #make the from/to period dropdowns ...
    $fprd = finMonList("fprd", $PRDMON[1]);
    $tprd = finMonList("tprd", PRD_DB);
    db_conn('core');
    #get list of previous years ...
    $fin_year_drop = "<select name='fin_year'>";
    $fin_year_drop .= "<option value='0'>Current</option>";
    $get_years = "SELECT * FROM year WHERE closed = 'y'";
    $run_years = db_exec($get_years) or errDie("Unable to get previous year information");
    if (pg_numrows($run_years) < 1) {
        #no previous years ...
    } else {
        while ($parr = pg_fetch_array($run_years)) {
            $fin_year_drop .= "<option value='{$parr['yrname']}'>{$parr['yrname']}</option>";
        }
    }
    $fin_year_drop .= "</select>";
    //			<tr class='".bg_class()."'>
    //				<td>Financial Year</td>
    //				<td>$fin_year_drop</td>
    //			</tr>
    $slctacc = "\n\t\t<script>\n\t\t\tacclist_height = -1;\n\t\t\tfunction updateList(obj) {\n\t\t\t\ta = getObject('acclist');\n\t\t\t\tif (obj.value != 'slct') {\n\t\t\t\t\tif (acclist_height == -1) {\n\t\t\t\t\t\tacclist_height = a.offsetHeight;\n\t\t\t\t\t\ta.style.height = 0;\n\t\t\t\t\t\ta.style.visibility = 'hidden';\n\t\t\t\t\t}\n\t\t\t\t} else if (acclist_height >= 0) {\n\t\t\t\t\ta.style.height = acclist_height;\n\t\t\t\t\tacclist_height = -1;\n\t\t\t\t\ta.style.visibility = 'visible';\n\t\t\t\t}\n\t\t\t}\n\t\t</script>\n\n\t\t<h3>General Ledger Report</h3>\n\t\t<h4>Select Options</h4>\n\t\t{$err}\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='viewtran' />\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Date Range</td>\n\t\t\t\t<td>{$fprd} TO {$tprd}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Opening Balances</td>\n\t\t\t\t<td>\n\t\t\t\t\t<input type='radio' name='openbal' value='show' checked='yes' />Include Opening Balances<b> | </b>\n\t\t\t\t\t<input type='radio' name='openbal' value='none' />No Opening Balances\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Accounts</td>\n\t\t\t\t<td nowrap>\n\t\t\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='slct' checked='yes' />Selected Accounts<b> | </b>\n\t\t\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='allactive' />All Accounts with transactions<b> | </b>\n\t\t\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='all' />All Accounts\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' style='margin: 0px; padding: 0px;'>\n\t\t\t\t\t<div id='acclist'>\n\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='100%' height='100%'>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td valign='top'>Select account(s)</td>\n\t\t\t\t\t\t\t\t<td>{$accs}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</div>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<td align='right'><input type='submit' value='Continue &raquo;' /></td>\n\t\t\t</tr>\n\t\t</table>" . mkQuickLinks(ql("index-reports.php", "Financials"), ql("index-reports-journal.php", "Current Year Details General Ledger Reports"), ql("../core/acc-new2.php", "Add New Account"));
    return $slctacc;
}
function slctacc($err = "")
{
    global $PRDMON, $_POST;
    extract($_POST);
    $fprd = finMonList("fprd", $PRDMON[1]);
    $tprd = finMonList("tprd", PRD_DB);
    $fields["acc_first"] = "topacc";
    extract($fields, EXTR_SKIP);
    if ($acc_first == "topacc") {
        $sortacc_first = "topacc, accnum";
    } else {
        $sortacc_first = "accname";
    }
    core_connect();
    $sql = "SELECT * FROM accounts WHERE div = '" . USER_DIV . "' ORDER BY {$sortacc_first} ASC";
    $accRslt = db_exec($sql) or errDie("Could not retrieve Categories Information from the Database.", SELF);
    if (pg_numrows($accRslt) < 1) {
        return "<li class='err'> There are no Accounts in Cubit.</li>";
    }
    $accs = "<select name='accids[]' multiple size='10'>";
    while ($acc = pg_fetch_array($accRslt)) {
        if ($acc_first == "topacc") {
            $accs .= "<option value='{$acc['accid']}'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</option>";
        } else {
            $accs .= "<option value='{$acc['accid']}'>{$acc['accname']} - {$acc['topacc']}/{$acc['accnum']}</option>";
        }
    }
    $accs .= "</select>";
    if ($acc_first == "topacc") {
        $topacc = "checked";
        $accname = "";
    } else {
        $topacc = "";
        $accname = "checked";
    }
    $slctacc = "\n\t\t<script>\n\t\tacclist_height = -1;\n\t\tfunction updateList(obj) {\n\t\t\ta = getObject('acclist');\n\t\n\t\t\tif (obj.value != 'slct') {\n\t\t\t\tif (acclist_height == -1) {\n\t\t\t\t\tacclist_height = a.offsetHeight;\n\t\t\t\t\ta.style.height = 0;\n\t\t\t\t\ta.style.visibility = 'hidden';\n\t\t\t\t}\n\t\t\t} else if (acclist_height >= 0) {\n\t\t\t\ta.style.height = acclist_height;\n\t\t\t\tacclist_height = -1;\n\t\t\t\ta.style.visibility = 'visible';\n\t\t\t}\n\t\t}\n\t\t</script>\n\t\t<h3>Period Range General Ledger</h3>\n\t\t<h4>Select Options</h4>\n\t\t{$err}\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST' name='form1'>\n\t\t\t<input type='hidden' name='key' value='viewtran' />\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Accounts</td>\n\t\t\t\t<td nowrap>\n\t\t\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='slct' checked='yes' />Selected Accounts<b> | </b>\n\t\t\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='allactive' />All Active Accounts<b> | </b>\n\t\t\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='all' />All Accounts\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Sort By</td>\n\t\t\t\t<td>\n\t\t\t\t\t<input type='radio' name='acc_first' onClick='document.form1.submit();' value='topacc' {$topacc} />Account Number - Account Name<br />\n\t\t\t\t\t<input type='radio' name='acc_first' onClick='document.form1.submit();' value='accname' {$accname} />Account Name - Account Number<br/>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' style='margin: 0px; padding: 0px;'>\n\t\t\t\t\t<div id='acclist'>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='100%' height='100%'>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td valign='top'>Select account(s)</td>\n\t\t\t\t\t\t<td>{$accs}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</div>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Period Range :</td>\n\t\t\t\t<td valign='center' colspan='3'>{$fprd} To : {$tprd}</td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<td align='right'><input type='submit' name='continue' value='Continue &raquo;'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>" . mkQuickLinks(ql("index-reports.php", "Financials"), ql("index-reports-journal.php", "Current Year Details General Ledger Reports"), ql("../core/acc-new2.php", "Add New Account"));
    return $slctacc;
}
function slctacc()
{
    extract($_REQUEST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($year, "string", 1, 10, "Invalid year.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    db_conn('core');
    $Sl = "SELECT * FROM year WHERE yrdb='{$year}'";
    $Ri = db_exec($Sl) or errDie("Unable to get data.");
    $yd = pg_fetch_array($Ri);
    global $PRDMON;
    $fprds = finMonList("fprd", $PRDMON[1], false, $yd["yrname"]);
    $tprds = finMonList("tprd", PRD_DB, false, $yd["yrname"]);
    db_connect();
    $sql = "SELECT * FROM suppliers WHERE div = '" . USER_DIV . "' ORDER BY supid ASC";
    $supRslt = db_exec($sql) or errDie("Could not retrieve suppliers Information from the Database.", SELF);
    if (pg_numrows($supRslt) < 1) {
        return "<li class='err'> There are no suppliers in Cubit.</li>";
    }
    $supts = "<select name='supids[]' multiple size='10'>";
    while ($sup = pg_fetch_array($supRslt)) {
        $supts .= "<option value='{$sup['supid']}'>{$sup['supname']}</option>";
    }
    $supts .= "</select>";
    $slctacc = "\n\t\t<p>\n\t\t<h3>Creditors Ledger</h3>\n\t\t<h4>Select Options</h4>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t<input type='hidden' name='year' value='{$year}' />\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'></td>\n\t\t\t\t<td><input type='radio' name='accnt' value='slct' checked='yes'>Selected Accounts | <input type='radio' name='accnt' value='all'>All Accounts</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Select Supplier(s)</td>\n\t\t\t\t<td>{$supts}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Select period</td>\n\t\t\t\t<td>{$fprds} to {$tprds}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Order By</td>\n\t\t\t\t<td>Transaction Date<input type='radio' name='t' checked value='t'>System Date<input type='radio' name='t' value='s'></td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td align='right'><input type='submit' value='Continue &raquo;'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>\n\t\t<table " . TMPL_tblDflts . " width='25%'>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td></tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='index-reports-debtcred.php'>Debtors & Creditors Reports</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</td>\n\t\t\t</tr>\n\t\t</table>";
    return $slctacc;
}
示例#13
0
function slctacc()
{
    global $_POST;
    extract($_POST);
    $fields["acc_first"] = "topacc";
    extract($fields, EXTR_SKIP);
    $prds = finMonList("prd", PRD_DB);
    if ($acc_first == "topacc") {
        $sortacc_first = "topacc, accnum";
    } else {
        $sortacc_first = "accname";
    }
    // Retrieve main accounts from Cubit.
    db_conn("core");
    $sql = "SELECT * FROM accounts WHERE div='" . USER_DIV . "' ORDER BY {$sortacc_first}";
    $macc_rslt = db_exec($sql) or errDie("Unable to retrieve main accounts from Cubit.");
    $accs = "<select id='accids' name='accids[]' multiple size='10'>";
    $i = 0;
    while ($macc_data = pg_fetch_array($macc_rslt)) {
        ++$i;
        if ($acc_first == "accname") {
            $accs .= "<option value='{$macc_data['accid']}'>{$macc_data['accname']} - {$macc_data['topacc']}/{$macc_data['accnum']}</option>";
        } else {
            $accs .= "<option value='{$macc_data['accid']}'>{$macc_data['topacc']}/{$macc_data['accnum']} - {$macc_data['accname']}</option>";
        }
    }
    $accs .= "</select>";
    if ($acc_first == "topacc") {
        $topacc = "checked";
        $accname = "";
    } else {
        $topacc = "";
        $accname = "checked";
    }
    $slctacc = "\n\t<p>\n\t<h3>General Ledger</h3>\n\t<table " . TMPL_tblDflts . ">\n\t<form action='" . SELF . "' method='POST' name='form1'>\n\t<input type='hidden' name='key' value='viewtran' />\n\t<tr>\n\t\t<th colspan='2'>Options</th>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Select period</td>\n\t\t<td>{$prds}</td>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Order By</td>\n\t\t<td>\n\t\t\tTransaction Date<input type='radio' name='t' checked value='t'>\n\t\t\tSystem Date<input type='radio' name='t' value='s'>\n\t\t</td>\n\t</tr>\n\t" . TBL_BR . "\n\t<tr>\n\t\t<th colspan='2'>Account Options</th>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td valign='top'>Accounts</td>\n\t\t<td nowrap>\n\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='slct' checked='yes' />Selected Accounts<b> | </b>\n\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='allactive' />All Active Accounts<b> | </b>\n\t\t\t<input type='radio' onClick='updateList(this);' name='accnt' value='all' />All Accounts\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td colspan='2' style='margin: 0px; padding: 0px;'>\n\t\t\t<div id='acclist'>\n\t\t\t<table " . TMPL_tblDflts . " width='100%' height='100%'>\n\t\t\t\t<tr id='acclist1' class='" . bg_class() . "'>\n\t\t\t\t\t<td>Account List Options</td>\n\t\t\t\t\t<td colspan='2'>\n\t\t\t\t\t\t<input type='radio' name='acc_first' onClick='document.form1.submit();' value='topacc' {$topacc} />Account Number - Account Name<br />\n\t\t\t\t\t\t<input type='radio' name='acc_first' onClick='document.form1.submit();' value='accname' {$accname} />Account Name - Account Number<br/>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr id='acclist2' class='" . bg_class() . "'>\n\t\t\t\t\t<td valign='top'>Select account(s)</td>\n\t\t\t\t\t<td>{$accs}</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</div>\n\t\t</td>\n\t</tr>\n\t" . TBL_BR . "\n\t<tr>\n\t\t<td></td>\n\t\t<td align='right'><input id='sdf' type='submit' name='continue' value='Continue &raquo;'></td>\n\t</tr>\n\t</table>" . mkQuickLinks(ql("index-reports.php", "Financials"), ql("index-reports-journal.php", "Current Year Details General Ledger Reports"), ql("../core/acc-new2.php", "Add New Account"));
    return $slctacc;
}
function slctacc($_POST)
{
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($year, "string", 1, 10, "Invalid year.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    db_conn('core');
    $Sl = "SELECT * FROM year WHERE yrdb='{$year}'";
    $Ri = db_exec($Sl) or errDie("Unable to get data.");
    $yd = pg_fetch_array($Ri);
    # from period
    $prds = finMonList("prd", PRD_DB, false, $yd["yrname"]);
    db_connect();
    $sql = "SELECT * FROM employees WHERE div = '" . USER_DIV . "' ORDER BY sname,fnames";
    $supRslt = db_exec($sql) or errDie("Could not retrieve suppliers Information from the Database.", SELF);
    if (pg_numrows($supRslt) < 1) {
        return "<li class='err'> There are no employees in Cubit.";
    }
    $supts = "<select name='emps[]' multiple size='10'>";
    while ($sup = pg_fetch_array($supRslt)) {
        $supts .= "<option value='{$sup['empnum']}'>{$sup['sname']}, {$sup['fnames']}</option>";
    }
    $supts .= "</select>";
    $slctacc = "\n\t\t<p>\n\t\t<h3>Employee Ledger</h3>\n\t\t<h4>Select Options</h4>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='viewtran'>\n\t\t\t<input type='hidden' name='year' value='{$year}'>\n\t\t\t<tr>\n\t\t\t\t<th>Field</th>\n\t\t\t\t<th>Value</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Employees</td>\n\t\t\t\t<td><input type='radio' name='accnt' value='slct' checked='yes'>Selected Accounts | <input type='radio' name='accnt' value='all'>All Accounts</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td valign='top'>Select Employees(s)</td>\n\t\t\t\t<td>{$supts}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Select period</td>\n\t\t\t\t<td>{$prds}</td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td align='right'><input type='submit' value='Continue &raquo;'></td>\n\t\t\t</tr>\n\t\t</table>";
    return $slctacc;
}
function view()
{
    //layout
    $view = "\n\t\t<center>\n\t\t<h3>Detailed General ledger Report</h3>\n\t\t<table cellpadding='5' width='80%'>\n\t\t<tr>\n\t\t\t<td width='60%' align='center'>\n\t\t\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t\t\t<input type='hidden' name='key' value='viewtrans'>\n\t\t\t\t\t<input type='hidden' name='search' value='date'>\n\t\t\t\t<table " . TMPL_tblDflts . " width='470'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td class='err' colspan='2'>All transactions from selected period posted between the specified dates.</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th colspan='2'>By Date Range</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td width='95%' align='center'>\n\t\t\t\t\t\t\t<table>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td nowrap='t'>" . mkDateSelect("from", date("Y"), date("m"), "01") . "</td>\n\t\t\t\t\t\t\t\t\t<td>&nbsp;&nbsp;TO&nbsp;&nbsp;</td>\n\t\t\t\t\t\t\t\t\t<td nowrap='t'>" . mkDateSelect("to") . "</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td rowspan='2' valign='bottom'><input type='submit' value='Search &raquo;'></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<!--<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Select Period: " . finMonList("prd", PRD_DB) . "</td>\n\t\t\t\t\t</tr>-->\n\t\t\t\t</table>\n\t\t\t\t</form>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td align='center'>\n\t\t\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t\t\t<input type='hidden' name='key' value='viewtrans'>\n\t\t\t\t\t<input type='hidden' name='search' value='refnum'>\n\t\t\t\t<table " . TMPL_tblDflts . " width='370'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td class='err' colspan='2'>All transactions from selected period with reference numbers within the specified range.</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th colspan='2'>By Journal number</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td width='80%' align='center'>\n\t\t\t\t\t\t\tFrom <input type='text' size='5' name='fromnum'>\n\t\t\t\t\t\t\tto <input type='text' size='5' name='tonum'>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td rowspan='2' valign='bottom'><input type='submit' value='Search &raquo;'></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Select Period: " . finMonList("prd", PRD_DB) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t</form>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td align='center'>\n\t\t\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t\t\t<input type='hidden' name='key' value='viewtrans'>\n\t\t\t\t\t<input type='hidden' name='search' value='all'>\n\t\t\t\t<table " . TMPL_tblDflts . " width='370'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td class='err' colspan='2'>All transactions from selected period.</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th colspan='2'>View All</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='bg-even'>\n\t\t\t\t\t\t<td>Select Period: " . finMonList("prd", PRD_DB) . "</td>\n\t\t\t\t\t\t<td rowspan='2' valign='bottom'><input type='submit' value='View All &raquo;'></td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t</form>\n\t\t\t</td>\n\t\t</tr>\n\t</table>" . mkQuickLinks(ql("index-reports.php", "Financials"), ql("index-reports-journal.php", "Current Year Details General Ledger Reports"), ql("../core/acc-new2.php", "Add New Account"));
    return $view;
}
function customize($_POST)
{
    extract($_POST);
    $fields = array();
    $fields["account"] = 0;
    $fields["heading_1"] = COMP_NAME;
    $fields["heading_2"] = date("d/m/Y");
    $fields["heading_3"] = "Balance Sheet";
    $fields["heading_4"] = "Prepared by: " . USER_NAME;
    $fields["viewyear"] = "core";
    $fields["month_from"] = date("m");
    $fields["month_to"] = date("m");
    $fields["capital_employed_out"] = "Capital Employed";
    $fields["employment_of_capital_out"] = "Employment of Capital";
    $fields["period"] = substr(PRD_DB, 2);
    $fields["month"] = date("m");
    $fields["zero_balance"] = "";
    foreach ($fields as $var_name => $value) {
        if (!isset(${$var_name})) {
            ${$var_name} = $value;
        }
    }
    $qry = new dbSelect("year", "core", grp(m("where", "closed='y'"), m("order", "yrname ASC")));
    $qry->run();
    if (PRD_STATE == "py") {
        $curyear = PYR_NAME;
    } else {
        $curyear = YR_NAME;
    }
    $year_sel = "\n\t<select name='viewyear'>\n\t\t<option value='core'>" . $curyear . " (Current)</option>";
    while ($row = $qry->fetch_array()) {
        $sel = fsel($viewyear == $row["yrdb"]);
        $year_sel .= "<option {$sel} value='{$row['yrdb']}'>{$row['yrname']}</option>";
    }
    $year_sel .= "\n\t</select>";
    // Retrieve list of accounts for the account dropdown
    db_conn("core");
    $sql = "SELECT * FROM accounts WHERE acctype='B' ORDER BY accname ASC";
    $acc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts information from Cubit.");
    // Accounts dropdown output
    $acc_sel = "<select name='account' style='width: 200px'>\n\t\t<option value='0'>Please select</option>";
    while ($acc_data = pg_fetch_array($acc_rslt)) {
        if ($account == $acc_data["accid"]) {
            $selected = "selected";
        } else {
            $selected = "";
        }
        $acc_sel .= "<option value='{$acc_data['accid']}' {$selected}>{$acc_data['accname']}</option>";
    }
    $acc_sel .= "</select>";
    // Accounts list
    db_conn("cubit");
    $sql = "SELECT * FROM saved_bs_accounts";
    $sbsacc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts list from Cubit.");
    /*// the accounts list
    	$acc_list = "<tr>
    		<th colspan='4'>Accounts</th>
    	</tr>";
    
    	// has any accounts been added?
    	if (!pg_num_rows($sbsacc_rslt)) {
    		$acc_list .= "<tr class='bg-odd'>
    			<td>No accounts have been added, ALL balance accounts will be displayed.</td>
    		</tr>";
    	}
    
    	$i = 0;
    	while ($sbsacc_data = pg_fetch_array($sbsacc_rslt)) {
    		$i++;
    
    		if (empty($sbsacc_data["toptype"])) {
    			db_conn("core");
    			$sql = "SELECT toptype FROM accounts WHERE accid='$sbsacc_data[accid]'";
    			$rslt = db_exec($sql) or errDie("Unable to retrieve trial balance information from Cubit.");
    			$acc_toptype = pg_fetch_result($rslt, 0);
    		} else {
    			$acc_toptype = $sbsacc_data["toptype"];
    		}
    
    		$categories_sel = "<select name='toptype[$sbsacc_data[accid]]'>";
    		foreach ($ar_cats as $toptype=>$description) {
    			if ($acc_toptype == $toptype) {
    				$selected = "selected";
    			} else {
    				$selected = "";
    			}
    			$categories_sel .= "<option value='$toptype' $selected>$description</option>";
    		}
    		$categories_sel .= "</select>";
    
    		// has any of the checkboxes been checked?
    		if (isset($rem[$sbsacc_data["accid"]])) {
    			$checked = "checked";
    		} else {
    			$checked = "";
    		}
    
    		$acc_list .= "<tr class='".bg_class()."'>
    			<td>$sbsacc_data[accname]</td>
    			<td>$categories_sel</td>
    			<td><a href='#' onclick='openwindow(\"".SELF."?key=note_view&accid=$sbsacc_data[accid]\")'>Note</a></td>
    			<td><input type='checkbox' name='rem[$sbsacc_data[accid]]' value='$sbsacc_data[accid]' $checked></td>
    		</tr>";
    	}
    	$acc_list .= "<tr>
    		<td colspan='3' align='center'>
    			<input type='submit' name='key' value='Remove Selected'>
    			<input type='submit' name='key' value='Update'>
    		</td>
    	</tr>";*/
    $acc_list = "";
    // Period dropdown
    /*$month_frm_sel = "<select name='month_from'>";
    	for ($i = 1; $i <= 12; $i++) {
    		if ($month_from == $i) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    		$month_frm_sel .= "<option value='$i' $selected>".getMonthName($i)."</option>";
    	}
    	$month_frm_sel .= "</select>";*/
    // Period dropdown
    $month_to_sel = finMonList("month_to", $month_to, true);
    //------------------------------------------------------------------------
    if (isset($last_year_same_month) && $last_year_same_month) {
        $lysm = "checked";
    } else {
        $lysm = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_year_to_date) && $this_year_year_to_date) {
        $tyytd = "checked";
    } else {
        $tyytd = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_movement_to_date) && $this_year_movement_to_date) {
        $tymtd = "checked";
    } else {
        $tymtd = "";
    }
    //------------------------------------------------------------------------
    if (isset($last_year_year_to_date) && $last_year_year_to_date) {
        $lyytd = "checked";
    } else {
        $lyytd = "";
    }
    //------------------------------------------------------------------------
    if (isset($budget) && $budget) {
        $budget = "checked";
    } else {
        $budget = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_budget) && $this_year_budget) {
        $tybudget = "checked";
    } else {
        $tybudget = "";
    }
    // Layout
    $OUTPUT = "\n\t\t<h3>Balance Sheet</h3>\n\t\t<form method='POST' action='" . SELF . "'>\n\t\t\t<input type='hidden' name='key' value='display' />\n\t\t\t<input type='hidden' name='customized' value='true' />\n\t\t<table border='0' cellpadding='0' cellspacing='0'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'><h3>Customise</h3></th>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>Headings</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Heading 1</td>\n\t\t\t\t\t\t\t<td><input type='text' name='heading_1' value='{$heading_1}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Heading 2</td>\n\t\t\t\t\t\t\t<td><input type='text' name='heading_2' value='{$heading_2}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Heading 3</td>\n\t\t\t\t\t\t\t<td><input type='text' name='heading_3' value='{$heading_3}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Heading 4</td>\n\t\t\t\t\t\t\t<td><input type='text' name='heading_4' value='{$heading_4}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Capital Employed</td>\n\t\t\t\t\t\t\t<td><input type='text' name='capital_employed_out' value='{$capital_employed_out}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Employment of Capital</td>\n\t\t\t\t\t\t\t<td><input type='text' name='employment_of_capital_out' value='{$employment_of_capital_out}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<table " . TMPL_tblDflts . " style='margin: 0px; width: 300px'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>Display</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Last Year - Selected Month</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='last_year_same_month' value='true' {$lysm} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>This Year - Movement To Selected Month</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='this_year_movement_to_date' value='true' {$tymtd} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>This Year - To Selected Month</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='this_year_year_to_date' value='true' {$tyytd} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Last Year - Year End</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='last_year_year_to_date' value='true' {$lyytd} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Selected Month Budget</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='budget' value='true' {$budget} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<!--<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>This Year Budget To Month</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='this_year_budget' value='true' {$tybudget} \\></td>\n\t\t\t\t\t\t</tr>//-->\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Zero Balances</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='zero_balance' value='checked' {$zero_balance}></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<table " . TMPL_tblDflts . " style='margin: 0px; width: 300px'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Year</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td align='center'>{$year_sel}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Month</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td align='center'>{$month_to_sel}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<table " . TMPL_tblDflts . " style='margin: 0px; width: 300px'>\n\t\t\t\t\t\t<!--<tr>\n\t\t\t\t\t\t\t<th>Add Account</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td align='center'>\$acc_sel<input type='submit' name='key' value='Add'></td>\n\t\t\t\t\t\t</tr>//-->\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td><input type='submit' value='Display &raquo' style='width: 100%; font-weight: bold'></td>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<!--<td valign='top'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t{$acc_list}\n\t\t\t\t\t</table>\n\t\t\t\t</td>//-->\n\t\t\t</tr>\n\t\t</table>\n\t\t</form>";
    return $OUTPUT;
}
function slctCat($_POST)
{
    # get vars
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($type, "string", 1, 3, "Invalid category type.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    # Check Category name on selected type
    core_connect();
    switch ($type) {
        case "inc":
            $tab = "Income";
            break;
        case "exp":
            $tab = "Expenditure";
            break;
        case "bal":
            $tab = "Balance";
            break;
        default:
            return "<li>Invalid Category type";
    }
    $slctCat = "\n\t<h3>Select Category</h3>\n\t<table " . TMPL_tblDflts . ">\n\t<form action='" . SELF . "' method='POST'>\n\t\t<input type='hidden' name='key' value='viewtrans'>\n\t\t<input type='hidden' name='type' value='{$type}'>\n\t\t<input type='hidden' name='tab' value='{$tab}'>\n\t\t<tr>\n\t\t\t<th>Field</th>\n\t\t\t<th>Value</th>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Accounts Type</td>\n\t\t\t<td>{$tab}</td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Category Name</td>\n\t\t\t<td>\n\t\t\t\t<select name='catid'>";
    core_connect();
    $sql = "SELECT * FROM {$tab} WHERE div = '" . USER_DIV . "' ORDER BY catid";
    $catRslt = db_exec($sql) or errDie("Could not retrieve Categories Information from the Database.", SELF);
    $rows = pg_numrows($catRslt);
    if ($rows < 1) {
        return "There are no Account Categories under {$tab}";
    }
    while ($cat = pg_fetch_array($catRslt)) {
        $slctCat .= "<option value='{$cat['catid']}'>{$cat['catname']}</option>";
    }
    $slctCat .= "\n\t\t\t\t\t</select>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Select Period</td>\n\t\t\t\t<td valign='center'>" . finMonList("prd", PRD_DB) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td align='right'><input type='submit' value='View Transactions &raquo'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>\n\t\t<table " . TMPL_tblDflts . " width='100'>\n\t\t\t<tr>\n\t\t\t\t<th>Quick Links</th>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='index-reports-journal.php'>Current Year Details General Ledger Reports</a></td>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</a></td>\n\t\t\t</tr>\n\t\t</table>";
    return $slctCat;
}
function customize($_POST)
{
    extract($_POST);
    $fields["naccount"] = "";
    $fields["last_year"] = "checked";
    $fields["budget"] = "checked";
    $fields["month_from"] = (int) date("m");
    $fields["month_to"] = (int) date("m");
    $fields["heading_1"] = COMP_NAME;
    $fields["heading_2"] = date("d/m/Y");
    $fields["heading_3"] = "Trial Balance";
    $fields["heading_4"] = "Prepared by: " . USER_NAME;
    $fields["viewyear"] = "core";
    $fields["zero_balance"] = "";
    $fields["debit_credit"] = "";
    foreach ($fields as $var_name => $value) {
        if (!isset(${$var_name})) {
            ${$var_name} = $value;
        }
    }
    $qry = new dbSelect("year", "core", grp(m("where", "closed='y'"), m("order", "yrname ASC")));
    $qry->run();
    if (PRD_STATE == "py") {
        $curyear = PYR_NAME;
    } else {
        $curyear = YR_NAME;
    }
    $year_sel = "\n\t\t<select name='viewyear'>\n\t\t\t<option value='core'>" . $curyear . " (Current)</option>";
    while ($row = $qry->fetch_array()) {
        $sel = fsel($viewyear == $row["yrdb"]);
        $year_sel .= "<option {$sel} value='{$row['yrdb']}'>{$row['yrname']}</option>";
    }
    $year_sel .= "</select>";
    // Should we display the last year field
    if (substr(YR_DB, 2) - 1 > 0) {
        if (isset($last_year) && $last_year) {
            $ch = "checked='t'";
        } else {
            $ch = "";
        }
        $last_year_out = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Last Year</td>\n\t\t\t\t<td align='center'><input type='checkbox' name='last_year' value='checked' {$ch}></td>\n\t\t\t</tr>";
    } else {
        $last_year_out = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Last Year</td>\n\t\t\t\t<td align='center'>No prior years found.</td>\n\t\t\t</tr>";
    }
    /*$months_from = "<select name='month_from'>";
    	// Retrive month names
    	for ($i = 1; $i <= 12; $i++) {
    		if ($month_from == $i) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    		$months_from .= "<option value='$i' $selected>".getMonthName($i)."</option>";
    	}
    	$months_from .= "</select>";*/
    $months_to = finMonList("month_to", $month_to, true);
    /*// Retrieve list of accounts for the dropdowns
    	db_conn("core");
    	$sql = "SELECT * FROM trial_bal WHERE div='".USER_DIV."' ORDER BY topacc, accnum ASC";
    	$tb_rslt = db_exec($sql) or errDie("Unable to retrieve trial balance accounts from Cubit.");
    
    	$accounts = array();
    	while ($tb_data = pg_fetch_array($tb_rslt)) {
    		$accounts[$tb_data["accid"]] = "$tb_data[topacc]/$tb_data[accnum] $tb_data[accname]";
    	}
    
    	$naccount_out = "
    	<tr class='bg-odd'>
    		<td align=center><select name=naccount style='width: 240px'>
    		<option value='0'>Please select</option>";
    
    	foreach ($accounts as $accid=>$value) {
    		if ($naccount == $accid) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    
    		$naccount_out .= "<option value='$accid' $selected>$value</option>";
    	}
    
    	$naccount_out .= "</select></td>
    		<td><input type=submit name='key' value='Add'></td>
    	</tr>";*/
    // Retrieved the saved trial balance layout from Cubit
    db_conn("cubit");
    $sql = "SELECT * FROM saved_tb_accounts";
    $stbacc_rslt = db_exec($sql) or errDie("Unable to retrieve saved trial balance accounts from Cubit.");
    if (pg_num_rows($stbacc_rslt) == 0) {
        $accounts_out = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>No accounts have been selected, ALL accounts will be displayed.</td>\n\t\t\t</tr>";
    } else {
        $accounts_out = "";
    }
    $i = 0;
    while ($stbacc_data = pg_fetch_array($stbacc_rslt)) {
        $i++;
        // Was anything in the remove list selected
        if (isset($rem[$stbacc_data["id"]])) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        $accounts_out .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$stbacc_data['topacc']}/{$stbacc_data['accnum']}</td>\n\t\t\t\t<td>{$stbacc_data['accname']}</td>\n\t\t\t\t<td><input type='checkbox' name='rem[{$stbacc_data['id']}]' value='{$stbacc_data['id']}' {$checked}></td>\n\t\t\t\t<td><a href='#' onclick='popupSized(\"" . SELF . "?key=note_view&accid={$stbacc_data['accid']}\", 'note{$stbacc_data['accid']}', 480, 800, '');'>Note</a></td>\n\t\t\t</tr>";
    }
    // Layout
    $OUTPUT = "\n\t\t<h3>Trial Balance</h3>\n\t\t<form method='POST' action='" . SELF . "'>\n\t\t\t<input type='hidden' name='key' value='display'>\n\t\t\t<input type='hidden' name='acc_view' value='sel'>\n\t\t\t<input type='hidden' name='customized' value='true'>\n\t\t<table border='0' cellpadding='0' cellspacing='0'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'><h3>Customise</h3></th>\n\t\t\t</tr>\n\t\t\t<tr><td valign=top>\n\t\t\t<table " . TMPL_tblDflts . " style='width: 300px; margin: 0px;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Display</th>\n\t\t\t\t</tr>\n\t\t\t\t{$last_year_out}\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Annual Budget</td>\n\t\t\t\t\t<td align=center><input type=checkbox name=budget value='checked' {$budget}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Zero Balances</td>\n\t\t\t\t\t<td align='center'><input type='checkbox' name='zero_balance' value='checked' {$zero_balance}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>List Debit & Credit</td>\n\t\t\t\t\t<td align='center'><input type='checkbox' name='debit_credit' {$debit_credit}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Year</td>\n\t\t\t\t\t<td align='center'>{$year_sel}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Month</td>\n\t\t\t\t\t<td align=center nowrap>{$months_to}</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<!--<table " . TMPL_tblDflts . " style='width: 300px; margin: 0px;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Add Account</th>\n\t\t\t\t</tr>\n\t\t\t\t\$naccount_out\n\t\t\t</table>//-->\n\t\t\t<table " . TMPL_tblDflts . " style='width: 300px; margin: 0px;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Headings</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Heading 1</td>\n\t\t\t\t\t<td><input type='text' name='heading_1' value='{$heading_1}' style='width: 100%'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Heading 2</td>\n\t\t\t\t\t<td><input type='text' name='heading_2' value='{$heading_2}' style='width: 100%'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Heading 3</td>\n\t\t\t\t\t<td><input type='text' name='heading_3' value='{$heading_3}' style='width: 100%'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td width='0%'>Heading 4</td>\n\t\t\t\t\t<td><input type='text' name='heading_4' value='{$heading_4}' style='width: 100%'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='3'><input type='submit' value='Display &raquo' style='width:100%; font-weight: bold;'></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</td><td valign=top>\n\t\t\t<!--<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='4'>Accounts</th>\n\t\t\t\t</tr>\n\t\t\t\t{$accounts_out}\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='4' align='center'><input type='submit' name='key' value='Remove Selected'></td>\n\t\t\t\t</tr>\n\t\t\t</table>//-->\n\t\t</table>\n\t\t</form>";
    return $OUTPUT;
}
function enter_data($_POST, $_FILES = "")
{
    extract($_POST);
    if ($_FILES != "") {
        $importfile = tempnam("/tmp", "cubitimport_");
        $file = fopen($_FILES["compfile"]["tmp_name"], "r");
        if ($file == false) {
            return "<li class='err'>Cannot read file.</li>" . select_file();
        }
        db_conn('cubit');
        $Sl = "DROP TABLE import_data";
        $Ri = @db_exec_safe($Sl);
        $Sl = "\n\t\t\tCREATE TABLE import_data (\n\t\t\t\tid serial,\n\t\t\t\tdes1 varchar, des2 varchar,\n\t\t\t\tdes3 varchar, des4 varchar,\n\t\t\t\tdes5 varchar, des6 varchar,\n\t\t\t\tdes7 varchar, des8 varchar,\n\t\t\t\tdes9 varchar, des10 varchar,\n\t\t\t\tdes11 varchar, des12 varchar,\n\t\t\t\tdes13 varchar, des14 varchar,\n\t\t\t\tdes15 varchar, des16 varchar\n\t\t\t)";
        $Ri = @db_exec($Sl);
        $Sl = "DELETE FROM import_data";
        $Ri = db_exec($Sl) or errDie("Unable to clear import table");
        while (!feof($file)) {
            $data = safe(fgets($file, 4096));
            $datas = explode(",", $data);
            if (!isset($datas[1])) {
                continue;
            }
            $temp = explode('/', $datas['0']);
            $valtemp = $temp['0'];
            $datas['0'] = str_pad($valtemp, 4, "0") . "/" . $temp['1'];
            $datas[2] = sprint(abs($datas[2]));
            $datas[3] = sprint(abs($datas[3]));
            $Sl = "\n\t\t\t\tINSERT INTO import_data (\n\t\t\t\t\tdes1, des2, des3, des4\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$datas['0']}', '{$datas['1']}', '{$datas['2']}', '{$datas['3']}'\n\t\t\t\t)";
            $Rl = db_exec($Sl) or errDie("Unable to insert data.");
        }
        fclose($file);
    }
    global $_SESSION;
    $out = "\n\t\t<h3>Trial Balance Import</h3>\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='enter2'>\n\t\t\t<input type='hidden' name='login' value='1'>\n\t\t\t<input type='hidden' name='div' value='{$_SESSION['USER_DIV']}'>\n\t\t\t<input type='hidden' name='login_user' value='{$_SESSION['USER_NAME']}'>\n\t\t\t<input type='hidden' name='login_pass' value='{$_SESSION['USER_PASS']}'>\n\t\t\t<input type='hidden' name='code' value='{$_SESSION['code']}'>\n\t\t\t<input type='hidden' name='comp' value='{$_SESSION['comp']}'>\n\t\t\t<input type='hidden' name='noroute' value='1'>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' class='err'># Indicates an account (Number) that already exists</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' class='err'>! Indicates an account (Number) that is a duplicate of\n\t\t\t\t\tanother account number in the import file.</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' class='err'>In order to avoid errors, ensure that account numbers\n\t\t\t\t\tare in the correct format</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' class='err'>Remember to select the accounts to link to in the lists provided.\n\t\t\t\t\tIf the account you wish to link with does not exist, you can specify that the account\n\t\t\t\t\tshould be created. Do this by selecting one of the following options:<br />\n\t\t\t\t\t1. New Income Account, will create a new Income account<br />\n\t\t\t\t\t2. New Balance Account, will create and new Balance Sheet account<br />\n\t\t\t\t\t3. New Expense Account, will create a new Expense account.\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr bgcolor='" . bgcolorc(1) . "'>\n\t\t\t\t<th>Period to import into:</th>\n\t\t\t\t<td>" . finMonList("prd", PRD_DB) . "</td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<th>Acc No</th>\n\t\t\t\t<th>Account Name</th>\n\t\t\t\t<th>Debit</th>\n\t\t\t\t<th>Credit</th>\n\t\t\t\t<th>Select Account to link to</th>\n\t\t\t</tr>";
    $accsql = new dbSelect("accounts", "core", array("order" => "accname"));
    $accsql->run();
    $acclist = array();
    while ($ai = $accsql->fetch_array()) {
        $acclist[$ai["accname"]] = $ai["accid"];
    }
    db_conn('cubit');
    $Sl = "SELECT * FROM import_data ORDER BY des1";
    $Ri = db_exec($Sl);
    $i = 0;
    $tot_debit = 0;
    $tot_credit = 0;
    db_conn('core');
    $newacc_selections = array();
    while ($fd = pg_fetch_array($Ri)) {
        $fid = $fd['id'];
        $bgcolor = bgcolor($i);
        $Accounts = "\n\t\t<select name='accounts[{$fid}]' id='accounts[{$fid}]'>\n\t\t<optgroup label='Create New Account'>\n\t\t\t<option value='n1'>New Income Account</option>\n\t\t\t<option value='n2'>New Expense Account</option>\n\t\t\t<option value='n3'>New Balance Account</option>\n\t\t</optgroup>\n\t\t<optgroup label='Use Existing Account'>";
        $has_sel = false;
        foreach ($acclist as $accname => $accid) {
            $sel = "";
            if (!$has_sel) {
                $m1 = isset($accounts[$fid]) && $accounts[$fid] == $accid;
                $m2 = $accname == $fd['des2'] && !isset($accounts[$fid]);
                $m3 = !empty($fd["des2"]) && stristr($accname, $fd['des2']) && !isset($accounts[$fid]) && !isset($acclist[$fd["des2"]]);
                if ($m1 || $m2 || $m3) {
                    $sel = "selected";
                    $has_sel = true;
                }
            }
            $Accounts .= "<option value='{$accid}' {$sel}>{$accname}</option>";
        }
        $Accounts .= "\n\t\t</optgroup>\n\t\t</select>";
        list($var1, $var2) = explode('/', $fd['des1']);
        if (!$has_sel) {
            if ($var1 >= MIN_INC && $var1 <= MAX_INC) {
                $newacc_selections[$fid] = "n1";
            } else {
                if ($var1 >= MIN_EXP && $var1 <= MAX_EXP) {
                    $newacc_selections[$fid] = "n2";
                } else {
                    if ($var1 >= MIN_BAL && $var1 <= MAX_BAL) {
                        $newacc_selections[$fid] = "n3";
                    }
                }
            }
        }
        db_conn('core');
        $get_check = "SELECT * FROM accounts WHERE topacc = '{$var1}' AND accnum = '{$var2}'";
        $run_check = db_exec($get_check) or errDie("Unable to get account check");
        if (pg_numrows($run_check) < 1) {
            $showerr = "";
        } else {
            $showerr = "<b class='err'>#</b>";
        }
        $check_dup = new dbSelect("import_data", "cubit", grp(m("where", "des1='{$fd['des1']}' AND id!='{$fd['id']}'")));
        $check_dup->run();
        if ($check_dup->num_rows() > 0) {
            $showerr .= "<b class='err'>!</b>";
        }
        $out .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$showerr} {$fd['des1']}</td>\n\t\t\t\t<td>{$fd['des2']}</td>\n\t\t\t\t<td>{$fd['des3']}</td>\n\t\t\t\t<td>{$fd['des4']}</td>\n\t\t\t\t<td>{$Accounts}</td>\n\t\t\t</tr>";
        $tot_debit += $fd['des3'];
        $tot_credit += $fd['des4'];
    }
    $bgcolor = bgcolor($i);
    $tot_debit = sprint($tot_debit);
    $tot_credit = sprint($tot_credit);
    $out .= "\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td colspan='2'>Total</td>\n\t\t\t<td align='right'>{$tot_debit}</td>\n\t\t\t<td align='right'>{$tot_credit}</td>\n\t\t</tr>";
    if ($tot_debit == $tot_credit) {
        $out .= "\n\t\t\t<tr>\n\t\t\t\t<td colspan='3' align='right'><input type='submit' value='Continue &raquo;'></td>\n\t\t\t</tr>";
    } else {
        $out .= "\n\t\t\t<li class='err'>The Total debit and credit are not the same. You cannot import a trial balance that doesnt balance.<br>\n\t\t\tPlease check the file you are trying to import, the total debits and total credits should be the same.<br>\n\t\t\tPlease fix the file and try again.</li>";
    }
    $out .= "\n\t\t</form>\n\t\t</table>\n\t\t<script>";
    foreach ($newacc_selections as $fid => $pval) {
        $out .= "l = document.getElementById('accounts[{$fid}]'); l.value='{$pval}';";
    }
    $out .= "\n\t</script>";
    return $out;
}
function slct($errors = "")
{
    global $_POST;
    extract($_POST);
    $fields = array();
    $fields["category"] = 0;
    $fields["accid"] = 0;
    $fields["month_from"] = (int) date("m");
    $fields["month_to"] = (int) date("m");
    foreach ($fields as $var_name => $value) {
        if (!isset(${$var_name})) {
            ${$var_name} = $value;
        }
    }
    // Accounts dropdown
    db_conn("core");
    $sql = "SELECT * FROM accounts WHERE div='" . USER_DIV . "' ORDER BY accname ASC";
    $acc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts from Cubit.");
    $acc_sel = "<select name='accid' style='width: 270px'>";
    while ($acc_data = pg_fetch_array($acc_rslt)) {
        if ($acc_data["accid"] == $accid) {
            $selected = "selected";
        } else {
            $selected = "";
        }
        $acc_sel .= "<option value='{$acc_data['accid']}' {$selected}>{$acc_data['accname']}</option>";
    }
    $acc_sel .= "</select>";
    // Categories dropdown
    $cat_list = array("nciis" => "Non cash items in Income Statement", "ciaal" => "Change in Assets and Liabilities", "cffuif" => "Cash Flows From / Used in Financing", "cffuii" => "Cash Flows From / Used in Investing");
    $cat_sel = "<select name='category' style='width: 270px'>";
    foreach ($cat_list as $key => $value) {
        if ($key == $category) {
            $selected = "selected";
        } else {
            $selected = "";
        }
        $cat_sel .= "<option value='{$key}' {$selected}>{$value}</option>";
    }
    $cat_sel .= "</select>";
    // Retrieve the accounts list from Cubit
    db_conn("cubit");
    $sql = "SELECT * FROM saved_cf_accounts";
    $cfacc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts list from Cubit.");
    if (pg_num_rows($cfacc_rslt)) {
        $i = 0;
        while ($cfacc_data = pg_fetch_array($cfacc_rslt)) {
            // Multidimensional array, variable variable
            ${$cfacc_data["category"]}[] = $cfacc_data["accid"];
        }
    } else {
        // Create default accounts
        $_POST["key"] = "default";
        return update($_POST);
    }
    // Output the headings and accounts
    $acc_out = "";
    $i = 0;
    foreach ($cat_list as $key => $value) {
        if (isset(${$key})) {
            $acc_out .= "<tr><th colspan='5' class='cashflow_cats'>{$value}</th></tr>";
            foreach (${$key} as $accid) {
                $i++;
                // Retrieve the account info from the trial balance
                db_conn("core");
                $sql = "SELECT * FROM trial_bal WHERE accid='{$accid}'";
                $acc_rslt = db_exec($sql) or errDie("Unable to retrieve account information from Cubit.");
                $acc_data = pg_fetch_array($acc_rslt);
                $acc_out .= "\n\t\t\t\t<input type='hidden' name='acc_{$key}[]' value='{$accid}'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$acc_data['accname']}</td>\n\t\t\t\t\t<td align='center'><input type='checkbox' name='rem[{$acc_data['accid']}]' value='{$acc_data['accid']}'></td>\n\t\t\t\t</tr>";
            }
        }
    }
    // Period dropdown
    $month_frm_sel = finMonList("month_from", $month_from);
    $month_to_sel = finMonList("month_to", $month_to);
    // Layout
    $OUTPUT = "\n\t<h3>Statement of Cash Flow</h3>\n\t<form method='post' action='" . SELF . "'>\n\t<input type='hidden' name='key' value='display'>\n\t<table " . TMPL_tblDflts . " style='width: 600px; margin: 0px'>\n\t\t<tr>\n\t\t\t<td>{$errors}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan='3'>Note</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td colspan='3'>\n\t\t\t\tDefault accounts will be added if no accounts have\n\t\t\t\tbeen selected, or if ALL accounts have been removed.\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan='3'>Range</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td colspan='3' align='center'>{$month_frm_sel} <b>TO</b> {$month_to_sel}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan='3'>Select Account to be Added to the List of Accounts\n\t\t\t\tDisplayed on Cash Flow Statement</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th>Account Name</th>\n\t\t\t<th colspan='2'>Cash Flow Statement Section to Display Under</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td align='center'>{$acc_sel}</td>\n\t\t\t<td align='center'>{$cat_sel}</td>\n\t\t\t<td align='center'><input type='submit' name='key' value='Select Account'></td>\n\t\t</tr>\n\t</table>\n\t<table " . TMPL_tblDflts . " style='width: 600px; margin: 0px'>\n\t\t<tr>\n\t\t\t<th colspan='4'>Accounts List</th>\n\t\t</tr>\n\t\t\t{$acc_out}\n\t\t<tr>\n\t\t\t<td colspan='4' align='center'>\n\t\t\t\t<table border='0' cellpadding='0' cellspacing='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<input type='submit' name='key' value='Remove Selected'></td>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<input type='submit' value='Display &raquo' style='font-weight: bold'>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n\t</table>\n\t</form>" . mkQuickLinks(ql("../core/acc-new2.php", "Add New Journal Account"), ql("index-reports.php", "Financials"), ql("index-reports-stmnt.php", "Current Year Financial Statements"));
    return $OUTPUT;
}
function slct($_POST)
{
    extract($_POST);
    if (!isset($prd)) {
        $prd = "";
    }
    if (!isset($project1)) {
        $project1 = "";
    }
    if (!isset($project2)) {
        $project2 = "";
    }
    if (!isset($old_project1)) {
        $old_project1 = "";
    }
    if (!isset($old_project2)) {
        $old_project2 = "";
    }
    db_conn(YR_DB);
    $sql = "SELECT * FROM info WHERE prdname !=''";
    $prdRslt = db_exec($sql);
    if (pg_numrows($prdRslt) < 1) {
        return "<li class='err'>ERROR : There are no periods set for the current year.</li>";
    }
    //	$Prds = "<select name='prd'>";
    //	while($prd = pg_fetch_array($prdRslt)){
    //		if($prd['prddb'] == PRD_DB){
    //			$sel = "selected";
    //		}else{
    //			$sel= "";
    //		}
    //		$Prds .= "<option value='$prd[prddb]' $sel>$prd[prdname]</option>";
    //	}
    //	$Prds .= "</select>";
    //	print getfinyear ();
    $Prds = finMonList("prd", $prd);
    #reset all lower levels if master changed
    if ($old_project1 != $project1) {
        //		unset ($project2);
        $project2 = "";
        //		unset ($project3);
        $project3 = "";
    }
    if ($old_project2 != $project2) {
        //		unset ($project3);
        $project3 = "";
    }
    if (!isset($project1) or strlen($project1) < 1) {
        $project1 = "0";
        $sel1 = "selected";
    } else {
        $sel1 = "";
    }
    if (!isset($project2) or strlen($project2) < 1) {
        $project2 = "0";
        $sel2 = "selected";
    } else {
        $sel2 = "";
    }
    if (!isset($project3) or strlen($project3) < 1) {
        $project3 = "0";
        $sel3 = "selected";
    } else {
        $sel3 = "";
    }
    db_connect();
    $get_lev1 = "SELECT * FROM projects ORDER BY project_name";
    $run_lev1 = db_exec($get_lev1) or errDie("Unable to get project information.");
    if (pg_numrows($run_lev1) < 1) {
        return "No Projects Found. Please add 1.";
    }
    $lev1_drop = "<select name='project1' onChange='javascript:document.form1.submit()'>";
    $lev1_drop .= "<option disabled value='0' {$sel1}>Search For A Project</option>";
    while ($larr1 = pg_fetch_array($run_lev1)) {
        if ($larr1["id"] == $project1) {
            $lev1_drop .= "<option value='{$larr1['id']}' selected>{$larr1['project_name']}</option>";
        } else {
            $lev1_drop .= "<option value='{$larr1['id']}'>{$larr1['project_name']}</option>";
        }
    }
    $lev1_drop .= "</select>";
    $get_lev2 = "SELECT * FROM sub_projects WHERE project_id = '{$project1}' ORDER BY sub_project_name";
    $run_lev2 = db_exec($get_lev2) or errDie("Unable to get sub-project information.");
    //	if(pg_numrows($run_lev2) < 1)
    //		return "No Sub-Project Groups Found. Please add 1.";
    $lev2_drop = "<select name='project2' onChange='javascript:document.form1.submit()'>";
    $lev2_drop .= "<option disabled value='0' {$sel2}>Search For A Sub-Section</option>";
    while ($larr2 = pg_fetch_array($run_lev2)) {
        if ($larr2["id"] == $project2) {
            $lev2_drop .= "<option value='{$larr2['id']}' selected>{$larr2['sub_project_name']}</option>";
        } else {
            $lev2_drop .= "<option value='{$larr2['id']}'>{$larr2['sub_project_name']}</option>";
        }
    }
    $lev2_drop .= "</select>";
    $get_lev3 = "SELECT * FROM sub_sub_projects WHERE sub_project_id = '{$project2}' ORDER BY sub_sub_project_name";
    $run_lev3 = db_exec($get_lev3) or errDie("Unable to get sub-sub-project information.");
    //	if(pg_numrows($run_lev3) < 1)
    //		return "No Sub-Sub-Project Groups Found. Please add 1.";
    $lev3_drop = "<select name='project3' onChange='javascript:document.form1.submit()'>";
    $lev3_drop .= "<option disabled value='0' {$sel3}>Search For A Sub-Sub-Section</option>";
    while ($larr3 = pg_fetch_array($run_lev3)) {
        if ($larr3["id"] == $project3) {
            $lev3_drop .= "<option value='{$larr3['id']}' selected>{$larr3['sub_sub_project_name']}</option>";
        } else {
            $lev3_drop .= "<option value='{$larr3['id']}'>{$larr3['sub_sub_project_name']}</option>";
        }
    }
    $lev3_drop .= "</select>";
    //layout
    $slct = "\n\t\t<br><br>\n\t\t<table " . TMPL_tblDflts . " width='300'>\n\t\t<form action='" . SELF . "' method='POST' name='form1'>\n\t\t\t<input type='hidden' name='key' value='view'>\n\t\t\t<input type='hidden' name='old_project1' value='{$project1}'>\n\t\t\t<input type='hidden' name='old_project2' value='{$project2}'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'>Cost Ledger</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Select Period</td>\n\t\t\t\t<td>{$Prds}</td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<td class='err' colspan='2'>In The Following Section, Select Only The Items You Want To Include In The Report</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='2'>{$lev1_drop}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='2'>{$lev2_drop}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='2'>{$lev3_drop}</td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<td valign='bottom'><input type='submit' name='done' value='View'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>\n\t\t<p>";
    return $slct;
}
function customize($_POST)
{
    extract($_POST);
    $fields = array();
    $fields["heading_1"] = COMP_NAME;
    $fields["heading_2"] = date("d/m/Y");
    $fields["heading_3"] = "Income Statement";
    $fields["heading_4"] = "Prepared by: " . USER_NAME;
    $fields["viewview"] = "core";
    $fields["month_from"] = (int) date("m");
    $fields["month_to"] = (int) date("m");
    $fields["this_year_this_month"] = true;
    $fields["last_year_same_month"] = true;
    $fields["this_year_year_to_date"] = true;
    $fields["last_year_year_to_date"] = true;
    $fields["budget"] = true;
    $fields["this_year_budget"] = true;
    $fields["zero_balance"] = "";
    $fields["naccount"] = "";
    foreach ($fields as $var_name => $value) {
        if (!isset(${$var_name})) {
            ${$var_name} = $value;
        }
    }
    $qry = new dbSelect("year", "core", grp(m("where", "closed='y'"), m("order", "yrname ASC")));
    $qry->run();
    if (PRD_STATE == "py") {
        $curyear = PYR_NAME;
    } else {
        $curyear = YR_NAME;
    }
    $year_sel = "\n\t<select name='viewyear'>\n\t\t<option value='core'>" . $curyear . " (Current)</option>";
    while ($row = $qry->fetch_array()) {
        $sel = fsel($viewyear == $row["yrdb"]);
        $year_sel .= "<option {$sel} value='{$row['yrdb']}'>{$row['yrname']}</option>";
    }
    $year_sel .= "\n\t</select>";
    /*$months_from = "<select name='month_from'>";
    	// Retrive month names
    	for ($i = 1; $i <= 12; $i++) {
    		if ($month_from == $i) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    		$months_from .= "<option value='$i' $selected>".getMonthName($i)."</option>";
    	}
    	$months_from .= "</select>";*/
    $months_to = finMonList("month_to", $month_to, true);
    // Retrieve list of accounts for the account dropdown
    db_conn("core");
    $sql = "SELECT * FROM accounts WHERE acctype='I' OR acctype='E' ORDER BY accname,topacc ASC";
    $acc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts information from Cubit.");
    /*
    	// Accounts dropdown output
    	$acc_sel = "<select name='naccount' style='width: 200px'>
    		<option value='0'>Please select</option>";
    	while ($acc_data = pg_fetch_array($acc_rslt)) {
    		if ($naccount == $acc_data["accid"]) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    
    		$acc_sel .= "<option value='$acc_data[accid]' $selected>$acc_data[accname]</option>";
    	}
    	$acc_sel .= "</select>";
    
    	// Retrieve saved accounts from Cubit
    	db_conn("cubit");
    	$sql = "SELECT * FROM saved_is_accounts";
    	$sisacc_rslt = db_exec($sql) or errDie("Unable to retrieve saved income statement accounts from Cubit");
    
    	if (!pg_num_rows($sisacc_rslt)) {
    		$accounts_out = "
    		<tr class='bg-odd'>
    			<td>No accounts have been selected, ALL accounts will be displayed</td>
    		</tr>";
    	} else {
    		$accounts_out = "";
    	}
    
    	$i = 0;
    	while ($sisacc_data = pg_fetch_array($sisacc_rslt)) {
    		// Alternate the background colour
    		$i++;
    
    		if (isset($rem[$sisacc_data["id"]])) {
    			$checked = "checked";
    		} else {
    			$checked = "";
    		}
    
    		$accounts_out .= "
    		<tr class='".bg_class()."'>
    			<td>$sisacc_data[accname]</td>
    			<td><input type='checkbox' name='rem[$sisacc_data[id]]' value='$sisacc_data[id]' $checked></td>
    		</tr>";
    	}*/
    $accounts_out = "";
    //------------------------------------------------------------------------
    if (isset($last_year_same_month) && $last_year_same_month) {
        $lysm = "checked";
    } else {
        $lysm = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_year_to_date) && $this_year_year_to_date) {
        $tyytd = "checked";
    } else {
        $tyytd = "";
    }
    //------------------------------------------------------------------------
    if (isset($last_year_year_to_date) && $last_year_year_to_date) {
        $lyytd = "checked";
    } else {
        $lyytd = "";
    }
    //------------------------------------------------------------------------
    if (isset($budget) && $budget) {
        $budget = "checked";
    } else {
        $budget = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_budget) && $this_year_budget) {
        $tybudget = "checked";
    } else {
        $tybudget = "";
    }
    // Layout
    $OUTPUT = "<h3>Income Statement</h3>\n\t<form method='post' action='" . SELF . "'>\n\t<input type='hidden' name='key' value='display' />\n\t<input type='hidden' name='acc_view' value='sel'>\n\t<input type='hidden' name='customized' value='true'>\n\t<table border='0' cellpadding='0' cellspacing='0'>\n\t\t<tr>\n\t\t\t<th colspan=2><h3>Customise<h3></th>\n\t\t</tr>\n\n\t\t<tr><td valign='top'>\n\t\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' style='margin: 0px; width: 300px'>\n\t\t\t<tr>\n\t\t\t\t<th colspan=2>Headings</th>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>Heading 1</td>\n\t\t\t\t<td><input type=text name='heading_1' value='{$heading_1}' style='width: 100%'></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td>Heading 2</td>\n\t\t\t\t<td><input type=text name='heading_2' value='{$heading_2}' style='width: 100%'></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>Heading 3</td>\n\t\t\t\t<td><input type=text name='heading_3' value='{$heading_3}' style='width: 100%'></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td width='0%'>Heading 4</td>\n\t\t\t\t<td><input type=text name='heading_4' value='{$heading_4}' style='width: 100%'></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th colspan=2>Display</th>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>Last Year - Same Month</td>\n\t\t\t\t<td><input type='checkbox' name='last_year_same_month' value='true' {$lysm} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td>This Year - To Month</td>\n\t\t\t\t<td><input type='checkbox' name='this_year_year_to_date' value='true' {$tyytd} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>Last Year - Year To Date</td>\n\t\t\t\t<td><input type='checkbox' name='last_year_year_to_date' value='true' {$lyytd} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td>Month Budget</td>\n\t\t\t\t<td><input type='checkbox' name='budget' value='true' {$budget} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>This Year Budget To Month</td>\n\t\t\t\t<td><input type='checkbox' name='this_year_budget' value='true' {$tybudget} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td>Zero Balances</td>\n\t\t\t\t<td><input type='checkbox' name='zero_balance' value='checked' {$zero_balance} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td colspan='2'>\n\t\t\t\t\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t\t\t\t<tr class='bg-odd'>\n\t\t\t\t\t\t<td>Year</td>\n\t\t\t\t\t\t<td align='center'>{$year_sel}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Month</td>\n\t\t\t\t\t\t<td nowrap>{$months_to}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' style='margin: 0px; width: 300px'>\n\t\t\t<!--<tr>\n\t\t\t\t<th colspan='2'>Add Account</th>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td align='center'>\$acc_sel</td>\n\t\t\t\t<td align='center'><input type='submit' name='key' value='Add'></td>\n\t\t\t</tr>//-->\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><input type='submit' value='Display' style='width: 100%; font-weight: bold;'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t</td>\n\n\t\t<!--<td valign='top'>\n\t\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='250px'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'>Accounts</th>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t{$accounts_out}\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td align='center'><input type='submit' name='key' value='Remove Selected'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t</td>//-->\n\t\t</tr>\n\t</table>\n\t</form>";
    return $OUTPUT;
}