コード例 #1
0
function view()
{
    # Just months
    $months = array("1", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    # Check if year has been opened
    core_connect();
    $sql = "SELECT * FROM active";
    $cRs = db_exec($sql) or errDie("Database Access Failed - check year open.", SELF);
    if (pg_numrows($cRs) > 0) {
        # Get the range
        core_connect();
        $sql = "SELECT * FROM range";
        $Rslt = db_exec($sql);
        if (pg_numrows($Rslt) < 1) {
            $OUTPUT = "<center><li class=err>ERROR : The Financial year Period range was not found on Database, Please make sure that everything is set during instalation.";
            require "template.php";
        }
        $range = Pg_fetch_array($Rslt);
        global $PRDMON, $MONPRD;
        $pmon = 0;
        $fyear = getFinYear() - (int) ($PRDMON[1] > 1);
        $prddesc = array();
        for ($i = 1; $i <= 12; $i++) {
            $mon = $PRDMON[$i];
            if ($mon < $pmon) {
                ++$fyear;
            }
            $pmon = $mon;
            if ($i == 1) {
                $smonth = getMonthName($mon) . " {$fyear}";
            } else {
                if ($i == 12) {
                    $endmon = getMonthName($mon) . " {$fyear}";
                }
            }
        }
        $prddesc = implode(" to ", $prddesc);
        $ret = "<p><p>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t\t<tr><td colspan=2><li class=err>Financial year period range has already been set.</td></tr>\n\t\t\t<tr><th>Field</th><th>Value</th></tr>\n\t\t\t<tr class='bg-odd'><td>Financial Year Starts in</td><td align=center>{$smonth}</td></tr>\n\t\t\t<tr class='bg-even'><td>Financial Year Ends in</td><td align=center>{$endmon}</td></tr>\n\t\t</table>\n\t\t<p>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=100>\n\t\t\t<tr><th>Quick Links</th></tr>\n\t\t\t<tr bgcolor='#88BBFF'><td><a href='../main.php'>Main Menu</a></td></tr>\n\t\t</table>";
        return $ret;
    }
    $month = 1;
    $smonth = "<select name=smonth>";
    while ($month <= 12) {
        $smonth .= "<option value='{$month}'>{$months[$month]}</option>";
        $month++;
    }
    $smonth .= "</select>";
    //layout
    $view = "\n\t<h3>Set Financial Year Period Range</h3>\n\t<form action='" . SELF . "' method=post name=form>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=300>\n\t\t<input type=hidden name=key value=confirm>\n\t\t<tr><th>Field</th><th>Value</th></tr>\n\t\t<tr class='bg-odd'><td>Financial Years Start in</td><td valign=center>{$smonth}</td></tr>\n\t\t<tr><td><br></td></tr>\n\t\t<tr><td><input type=button value='&laquo Back' onClick='javascript:history.back()'></td><td align=right><input type=submit value='Continue &raquo'></td></tr>\n\t</table>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=100>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t</form>\n\t</table>";
    return $view;
}
コード例 #2
0
#
#The full software license can be found here:
#http://www.accounting-123.com/a.php?a=153/GPLv3
#
#
#
#
#
#
#
#
#
#
#
# If this script is called by itself, abort
if (basename(getenv("SCRIPT_NAME")) == "core-settings.php") {
    exit;
}
core_connect("core");
$sql = "SELECT * FROM active";
$rslt = db_exec($sql);
$rows = pg_numrows($rslt);
if (empty($rows)) {
    $OUTPUT = "<center>ERROR : There Current Period is not Selected Yet. You Cannot continue without Selecting a period";
    require "template.php";
}
$act = Pg_fetch_array($rslt);
define("PRD_DB", $act['prddb']);
define("YR_DB", $act['yrdb']);
define("PRD_NAME", $act['prdname']);
define("YR_NAME", $act['yrname']);
コード例 #3
0
function write_sets($_POST)
{
    global $catids, $CUBIT_MODULES;
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($smonth, "num", 1, 2, "Invalid Financial year starting month.");
    /*$v->isOk ($monthend,"num",1 ,2, "Invalid month end date");
    	$v->isOk ($int1,"float",1 ,5, "Invalid interest 1.");
    	$v->isOk ($int2,"float",1 ,5, "Invalid interest 2.");
    	$v->isOk ($int3,"float",1 ,5, "Invalid interest 3.");
    	$v->isOk ($brack1,"float",1 ,10, "Invalid bracket 1.");
    	$v->isOk ($brack2,"float",1 ,10, "Invalid bracket 2.");*/
    # display errors, if any
    if ($v->isError()) {
        $confirmCust = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirmCust .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        return $confirmCust;
    }
    pglib_transaction("BEGIN");
    makemap($smonth);
    core_connect();
    $sql = "SELECT accname FROM accounts WHERE accnum != '999' AND div = '" . USER_DIV . "'";
    $Rslt = db_exec($sql) or errDie("Unable to check database for existing accounts.");
    if (pg_numrows($Rslt) > 0) {
        $acc = "\n\t\t\t\t\t<center>\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<td><li class='err'>ERROR : There are already accounts in Cubit</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<th>Note : </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>Quick Setup can only be run on a new cubit installation.</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t" . TBL_BR . "\n\t\t\t\t\t</table>\n\t\t\t\t\t<p>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='15%'>\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<th>Quick Links</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t\t\t</table>";
        return $acc;
    }
    $sql = "\n\t\tINSERT INTO cubit.compinfo (\n\t\t\tcompname, slogan, logoimg, addr1, addr2, addr3, \n\t\t\taddr4, paddr1, paddr2, paddr3, tel, fax, \n\t\t\tvatnum, regnum, imgtype, img, div, paye, \n\t\t\tterms, postcode, img2, imgtype2, logoimg2, diplomatic_indemnity\n\t\t) VALUES (\n\t\t\t'{$_SESSION['comp']}', '', '', '', '', '', \n\t\t\t'', '', '', '', '', '',\n\t\t\t'', '', '', '', '" . USER_DIV . "', '', \n\t\t\t'', '', '', '', '', 'N'\n\t\t);";
    db_exec($sql) or errDie("Unable to update company information.");
    db_conn('cubit');
    $sql = "SELECT label FROM set WHERE label = 'ACCNEW_LNK' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to check database for existing account creation settings.");
    if (pg_num_rows($rslt) > 0) {
        $sql = "\n\t\t\tUPDATE set \n\t\t\tSET value = 'acc-new2.php', type = 'Account Creation' \n\t\t\tWHERE label = 'ACCNEW_LNK'";
    } else {
        $sql = "\n\t\t\tINSERT INTO set (\n\t\t\t\ttype, label, value, \n\t\t\t\tdescript, div\n\t\t\t) VALUES (\n\t\t\t\t'Account Creation', 'ACCNEW_LNK', 'acc-new2.php', \n\t\t\t\t'Use user selected account numbers', '" . USER_DIV . "'\n\t\t\t)";
    }
    db_exec($sql) or errDie("Unable to insert account creation settings to Cubit.");
    /* account categories */
    $catids = array("I" => 0, "E" => 0, "B" => 0);
    $sql = "\n\t\tINSERT INTO core.income (\n\t\t\tcatid, catname, div\n\t\t) VALUES (\n\t\t\t'I' || nextval('core.income_seq'), 'Income', '" . USER_DIV . "'\n\t\t)";
    $catRslt = db_exec($sql) or errDie("Unable to add income Category to Database.");
    $catids["I"] = "I" . pglib_getlastid("core.income_seq");
    $sql = "\n\t\tINSERT INTO core.expenditure (\n\t\t\tcatid, catname, div\n\t\t) VALUES (\n\t\t\t'E' || nextval('core.expenditure_seq'),'Expenditure', '" . USER_DIV . "'\n\t\t)";
    $catRslt = db_exec($sql) or errDie("Unable to add expense Category to Database.");
    $catids["E"] = "E" . pglib_getlastid("core.expenditure_seq");
    $sql = "\n\t\tINSERT INTO core.balance (\n\t\t\tcatid, catname, div\n\t\t) VALUES (\n\t\t\t'B' || nextval('core.balance_seq'),'Balance', '" . USER_DIV . "'\n\t\t)";
    $catRslt = db_exec($sql) or errDie("Unable to add balance Category to Database.");
    $catids["B"] = "B" . pglib_getlastid("core.balance_seq");
    /* START SETUP */
    $catid = $catids["I"];
    $sales_account = newacc("1000", "000", "Sales", "I", "f", "sales");
    $pos_sales_account = newacc("1100", "000", "Point of Sale - Sales", "I", "f", "sales");
    newacc("1150", "000", "Interest Received", "I", "f");
    newacc("1200", "000", "Sundry Income", "I", "f");
    newacc("1250", "000", "Exchange Rate Profit/Loss", "I", "f", "other_income");
    newacc("1300", "000", "Sale of Assets", "I", "f", "sales");
    linkacc("1300", "000", "salesacc", "saleofassets");
    linkacc("1150", "000", "salacc", "interestreceived");
    newacc("1660", "000", "Creditors Settlement Discount", "I", "f");
    newacc("1995", "000", "Previous Year Adjustment Income 1", "I", "f");
    newacc("1996", "000", "Previous Year Adjustment Income 2", "I", "f");
    newacc("1997", "000", "Previous Year Adjustment Income 3", "I", "f");
    newacc("1998", "000", "Previous Year Adjustment Income 4", "I", "f");
    newacc("1999", "000", "Previous Year Adjustment Income 5", "I", "f");
    $catid = $catids["E"];
    $cost_account = newacc("2150", "000", "Cost of Sales", "E", "f", "cost_of_sales");
    $pension_account = newacc("2510", "000", "Pension", "E", "f");
    newacc("2520", "000", "Retirement Annuity Fund", "E", "f");
    linkacc("2520", "000", "salacc", "retireexpense");
    newacc("2530", "000", "Provident Fund", "E", "f");
    linkacc("2530", "000", "salacc", "providentexpense");
    newacc("2540", "000", "Medical Aid", "E", "f");
    linkacc("2540", "000", "salacc", "medicalexpense");
    newacc("2160", "000", "Cost Variance", "E", "f", "cost_of_sales");
    linkacc("2160", "000", "pchsacc", "Cost Variance");
    newacc("2170", "000", "Variance", "E", "f", "cost_of_sales");
    linkacc("2170", "000", "salesacc", "sales_variance");
    newacc("2500", "000", "Salaries and Wages", "E", "f");
    linkacc("2500", "000", "salacc", "salaries");
    newacc("2550", "000", "Salaries - Commission", "E", "f");
    linkacc("2550", "000", "salacc", "Commission");
    newacc("2555", "000", "Salaries - Bonus", "E", "f");
    linkacc("2555", "000", "salacc", "Bonus");
    newacc("2560", "000", "UIF", "E", "f");
    linkacc("2560", "000", "salacc", "uifexp");
    newacc("2570", "000", "SDL", "E", "f");
    linkacc("2570", "000", "salacc", "sdlexp");
    newacc("2000", "000", "Accounting Fees", "E", "f");
    newacc("2050", "000", "Advertising and Promotions", "E", "f");
    newacc("2100", "000", "Bank Charges", "E", "f");
    newacc("2200", "000", "Depreciation", "E", "f");
    newacc("2250", "000", "Electricity and Water", "E", "f");
    newacc("2300", "000", "General Expenses", "E", "f");
    newacc("2350", "000", "Insurance", "E", "f");
    newacc("2400", "000", "Interest Paid", "E", "f");
    newacc("2450", "000", "Printing and Stationery", "E", "f");
    newacc("2650", "000", "Rent Paid", "E", "f");
    newacc("2600", "000", "Telephone and Fax", "E", "f");
    newacc("2700", "000", "POS Rounding", "E", "f", "cost_of_sales");
    linkacc("2700", "000", "salesacc", "rounding");
    newacc("2800", "000", "Normal Tax", "E", "f", "tax");
    linkacc("2510", "000", "salacc", "pensionexpense");
    newacc("2660", "000", "Creditors Settlement Discount", "E", "f");
    newacc("3660", "000", "Debtors Settlement Discount", "E", "f");
    newacc("4995", "000", "Previous Year Adjustment Expense 1", "E", "f");
    newacc("4996", "000", "Previous Year Adjustment Expense 2", "E", "f");
    newacc("4997", "000", "Previous Year Adjustment Expense 3", "E", "f");
    newacc("4998", "000", "Previous Year Adjustment Expense 4", "E", "f");
    newacc("4999", "000", "Previous Year Adjustment Expense 5", "E", "f");
    $catid = $catids["B"];
    newacc("5200", "000", "Retained Income / Accumulated Loss", "B", "f", "retained_income");
    newacc("5250", "000", "Share Capital / Members Contribution", "B", "f", "share_capital");
    newacc("5300", "000", "Shareholder / Director / Members Loan Account", "B", "f", "shareholders_loan");
    newacc("6000", "000", "Land & Buildings - Net Value", "B", "f", "fixed_asset");
    newacc("6000", "010", "Land & Buildings - Cost", "B", "f", "fixed_asset");
    newacc("6000", "020", "Land & Buildings - Accum Depreciation", "B", "f", "fixed_asset");
    newacc("6100", "020", "Motor Vehicle - Accum Depreciation", "B", "f", "fixed_asset");
    newacc("6100", "000", "Motor Vehicle - Net Value", "B", "f", "fixed_asset");
    newacc("6100", "010", "Motor Vehicle - Cost", "B", "f", "fixed_asset");
    newacc("6150", "000", "Computer Equipment - Net Value", "B", "f", "fixed_asset");
    newacc("6150", "010", "Computer Equipment - Cost", "B", "f", "fixed_asset");
    newacc("6150", "020", "Computer Equipment - Accum Depreciation", "B", "f", "fixed_asset");
    newacc("6160", "000", "Office Equipment - Net Value", "B", "f", "fixed_asset");
    newacc("6160", "010", "Office Equipment - Cost", "B", "f", "fixed_asset");
    newacc("6160", "020", "Office Equipment - Accum Depreciation", "B", "f", "fixed_asset");
    newacc("6170", "000", "Furniture & Fittings - Net Value", "B", "f", "fixed_asset");
    newacc("6170", "010", "Furniture & Fittings - Cost", "B", "f", "fixed_asset");
    newacc("6170", "020", "Furniture & Fittings - Accum Depreciation", "B", "f", "fixed_asset");
    $stock_control = newacc("6300", "000", "Inventory Suspense Account", "B", "f", "current_asset");
    $stock_account = newacc("6350", "000", "Inventory", "B", "f", "current_asset");
    $deptors_account = newacc("6400", "000", "Customer Control Account", "B", "f", "current_asset");
    $creditors_account = newacc("6500", "000", "Supplier Control Account", "B", "f", "current_liability");
    newacc("6600", "000", "Employees Control Account", "B", "f", "current_liability");
    newacc("2151", "000", "Stock Take Suspense Account", "E", "f", "cost_of_sales");
    linkacc("6600", "000", "salacc", "salaries control");
    linkacc("6600", "000", "salacc", "salaries control original");
    newacc("6700", "000", "Employee Loan Account", "B", "f", "current_asset");
    linkacc("6700", "000", "salacc", "loanacc");
    $bank_account = newacc("7000", "000", "Bank", "B", "f", "current_asset");
    newacc("7100", "000", "Petty Cash", "B", "f", "current_asset");
    linkacc("7100", "000", "bankacc", "Petty Cash");
    $pos_cash_account = newacc("7200", "000", "Cash on Hand", "B", "f", "current_asset");
    linkacc("7200", "000", "salacc", "cash");
    newacc("7300", "000", "POS Credit Card Control", "B", "f", "current_asset");
    linkacc("7300", "000", "salacc", "cc");
    newacc("8000", "000", "VAT Control Account", "B", "f", "current_liability");
    linkacc("8000", "000", "salesacc", "VAT");
    newacc("8010", "000", "VAT Input Account", "B", "f", "current_liability");
    linkacc("8010", "000", "salesacc", "VATIN");
    newacc("8020", "000", "VAT Output Account", "B", "f", "current_liability");
    linkacc("8020", "000", "salesacc", "VATOUT");
    newacc("8100", "000", "PAYE Payable", "B", "f", "current_liability");
    linkacc("8100", "000", "salacc", "PAYE");
    newacc("8200", "000", "UIF Payable", "B", "f", "current_liability");
    linkacc("8200", "000", "salacc", "UIF");
    linkacc("8200", "000", "salacc", "uifbal");
    newacc("8300", "000", "SDL Payable", "B", "f", "current_liability");
    linkacc("8300", "000", "salacc", "sdlbal");
    newacc("8400", "000", "Pension Payable", "B", "f", "current_liability");
    linkacc("8400", "000", "salacc", "pension");
    newacc("8500", "000", "Medical Aid Payable", "B", "f", "current_liability");
    linkacc("8500", "000", "salacc", "medical");
    newacc("8600", "000", "Retirement Annuity Fund Payable", "B", "f", "current_liability");
    linkacc("8600", "000", "salacc", "retire");
    newacc("8700", "000", "Provident Fund Payable", "B", "f", "current_liability");
    linkacc("8700", "000", "salacc", "provident");
    newacc("9000", "000", "Opening Balances / Suspense Account", "B", "f", "current_liability");
    newacc("9995", "000", "Previous Year Adjustment Balance 1", "B", "f", "fixed_asset");
    newacc("9996", "000", "Previous Year Adjustment Balance 2", "B", "f", "fixed_asset");
    newacc("9997", "000", "Previous Year Adjustment Balance 3", "B", "f", "fixed_asset");
    newacc("9998", "000", "Previous Year Adjustment Balance 4", "B", "f", "fixed_asset");
    newacc("9999", "000", "Previous Year Adjustment Balance 5", "B", "f", "fixed_asset");
    # Check if year has been opened
    $sql = "DELETE FROM core.year";
    $rslt = db_exec($sql);
    for ($i = 1; $i <= 10; $i++) {
        $sql = "INSERT INTO core.year VALUES('y" . ($selyear + $i - 1) . "', 'yr{$i}', 'n', '" . USER_DIV . "')";
        $rslt = db_exec($sql) or errDie("Could not set year name in Cubit", SELF);
    }
    $yrname = "y{$selyear}";
    $endmon = $smonth - 1;
    if (intval($endmon) == 0) {
        $endmon = 12;
    }
    $Sql = "TRUNCATE core.range";
    $Rs = db_exec($Sql) or errDie("Unable to empty year range", SELF);
    $firstmonth = $smonth;
    $activeyear = $yrname;
    $sql = "\n\t\tINSERT INTO core.range (\n\t\t\t\"start\", \"end\", div\n\t\t) VALUES (\n\t\t\t'{$smonth}', '{$endmon}', '" . USER_DIV . "'\n\t\t)";
    $Rslt = db_exec($sql) or errDie("Unable to insert year range", SELF);
    $sql = "SELECT * FROM core.year WHERE yrname='{$yrname}'";
    $yrs = db_exec($sql);
    $yr = pg_fetch_array($yrs);
    if ($yr['closed'] == 'y') {
        return "<center><li class='err'>ERROR : The Selected Financial year : <b>{$yrname}</b> has been closed.\n\t\t<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
    }
    $yrdb = $yr['yrdb'];
    $sql = "SELECT * FROM core.range";
    $Rslt = db_exec($sql);
    if (pg_numrows($Rslt) < 1) {
        $OUTPUT = "<center><li class='err'>ERROR : The Financial year Period range was not found on Database, Please make sure that everything is set during instalation.</li>";
        require "template.php";
    }
    $range = Pg_fetch_array($Rslt);
    // Months array
    $months = array("dummy", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    $sql = "INSERT INTO core.active (yrdb, yrname, prddb, prdname, div) VALUES ('{$yrdb}', '{$yrname}', '{$range['start']}', '" . $months[$range['start']] . "', '" . USER_DIV . "')";
    $rslt = db_exec($sql) or errDie("Could not Set Next Year Database and Name", SELF);
    db_conn("exten");
    $sql = "INSERT INTO departments (deptno, deptname, incacc, debtacc, credacc, pia, pca, div) VALUES ('1', 'Ledger 1', '{$sales_account}', '{$deptors_account}', '{$creditors_account}', '{$pos_sales_account}', '{$pos_cash_account}', '" . USER_DIV . "')";
    $deptRslt = db_exec($sql) or errDie("Unable to add deparment to system.", SELF);
    $sql = "INSERT INTO salespeople (salespno, salesp, div) VALUES ('1', 'General', '" . USER_DIV . "')";
    $salespRslt = db_exec($sql) or errDie("Unable to add warehouse to system.", SELF);
    $sql = "INSERT INTO  categories (category, div) VALUES ('General', '" . USER_DIV . "')";
    $catRslt = db_exec($sql) or errDie("Unable to add category to system.", SELF);
    $sql = "INSERT INTO  class (classname, div) VALUES ('General', '" . USER_DIV . "')";
    $catRslt = db_exec($sql) or errDie("Unable to add fringe benefit to system.", SELF);
    $sql = "INSERT INTO warehouses (whno, whname, stkacc, cosacc, conacc, div) VALUES ('1', 'Store 1', '{$stock_account}', '{$cost_account}', '{$stock_control}', '" . USER_DIV . "')";
    $whouseRslt = db_exec($sql) or errDie("Unable to add warehouse to system.", SELF);
    $whid = pglib_lastid("warehouses", "whid");
    $sql = "INSERT INTO  pricelist (listname, div) VALUES ('Standard', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to price list to system.", SELF);
    $sql = "INSERT INTO cubit.stockcat (catcod, cat, descript, div) VALUES('1', 'General', 'General Stock Category', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert stock category to Cubit.", SELF);
    $sql = "INSERT INTO cubit.stockclass (classcode, classname, div) VALUES ('1', 'General', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to add class to system.", SELF);
    $sql = "SELECT label FROM cubit.set WHERE label = 'DEF_WH' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to check database for existing settings.");
    if (pg_num_rows($rslt) > 0) {
        $sql = "UPDATE cubit.set SET value = '{$whid}', type = 'Default Warehouse' WHERE label = 'DEF_WH' AND div = '" . USER_DIV . "'";
    } else {
        $sql = "INSERT INTO cubit.set (type, label, value, descript, div) VALUES('Default Warehouse', 'DEF_WH', '{$whid}', '1 &nbsp;&nbsp;&nbsp; Store1', '" . USER_DIV . "')";
    }
    db_exec($sql) or errDie("Unable to insert settings to Cubit.");
    $sql = "SELECT label FROM cubit.set WHERE label = 'SELAMT_VAT' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to check database for existing settings.");
    if (pg_num_rows($rslt) > 0) {
        $sql = "UPDATE cubit.set SET value = 'inc', descript = 'Vat Inclusive' WHERE label = 'SELAMT_VAT' AND div = '" . USER_DIV . "'";
    } else {
        $sql = "INSERT INTO cubit.set (type, label, value, descript, div) VALUES('Vat type on stock selling price', 'SELAMT_VAT', 'inc', 'Vat Inclusive', '" . USER_DIV . "')";
    }
    db_exec($sql) or errDie("Unable to insert settings to Cubit.");
    $sql = "INSERT INTO cubit.currency (symbol,curcode,descrip,rate,def) VALUES ('R','ZAR', 'Rand',0.00,'')";
    db_exec($sql) or errDie("Unable to insert currency.");
    $sql = "\n\t\tINSERT INTO cubit.bankacct (\n\t\t\tacctype, bankname, branchname, branchcode, accname, \n\t\t\taccnum, details, div, btype, \n\t\t\tfcid, currency\n\t\t) VALUES (\n\t\t\t'Cheque', 'Bank', 'Branch', '000000', 'Account Name', \n\t\t\t'000000000000', 'Default bank Account', '" . USER_DIV . "', 'loc', \n\t\t\t(SELECT fcid FROM cubit.currency WHERE curcode='ZAR' LIMIT 1), 'Rand'\n\t\t)";
    db_exec($sql) or errDie("Unable to add bank account to database.");
    $accid = pglib_lastid("cubit.bankacct", "bankid");
    $sql = "INSERT INTO cubit.set (type, label, value, descript, div)\n\t\t\tVALUES('Banking Details Account', 'BANK_DET', '3', 'Bank Account: Account Name - Bank', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to set default bank account.");
    $hook = "INSERT INTO core.bankacc (accid, accnum, div) VALUES('{$accid}', '{$bank_account}', '" . USER_DIV . "')";
    $Rlst = db_exec($hook) or errDie("Unable to add link for for new bank account", SELF);
    $sql = "INSERT INTO crm.links (name,script) VALUES ('Add Client','../customers-new.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('View Client','../customers-view.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('New Invoice','../cust-credit-stockinv.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('Find Invoice','../invoice-search.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('View Stock','../stock-view.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('Add Supplier','../supp-new.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('View Suppliers','../supp-view.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('New Purchase','../purchase-new.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('View Purchases','../purchase-view.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('Add Quote','../quote-new.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('View Invoices','../invoice-view.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('View Quotes','../quote-view.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('Debtors Age Analysis','../reporting/debt-age-analysis.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('Creditors Age Analysis','../reporting/cred-age-analysis.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.links (name,script) VALUES ('Bank Reconciliation','../reporting/bank-recon.php')";
    db_exec($sql) or errDie("Unable to insert link.");
    $sql = "INSERT INTO crm.teams (name,div) VALUES ('Sales','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.teams (name,div) VALUES ('Support','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.teams (name,div) VALUES ('Accounts','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.teams (name,div) VALUES ('Company Relations','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.teams (name,div) VALUES ('Purchasing - Supplier Relations','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Product Enquiries','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Place an Order','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Complain','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Account querries','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Delivery or Installation Tracking','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Comment on good service or Remarks','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Ask about employment','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('General','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Potential Supplier','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.tcats (name,div) VALUES ('Product Support','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into teams");
    $sql = "INSERT INTO crm.actions (action) VALUES ('Called - Need to call again.')";
    db_exec($sql) or errDie("Unable to insert action.");
    $sql = "INSERT INTO crm.actions (action) VALUES ('Called - Could not get in touch')";
    db_exec($sql) or errDie("Unable to insert action.");
    $sql = "INSERT INTO crm.actions (action) VALUES ('Requested more information')";
    db_exec($sql) or errDie("Unable to insert action.");
    $sql = "INSERT INTO crm.actions (action) VALUES ('Sent Fax')";
    db_exec($sql) or errDie("Unable to insert action.");
    $pactivemonth = $activemonth;
    $pactivemonth--;
    if ($pactivemonth == 0) {
        $pactivemonth = 12;
    }
    $i = 0;
    $current = $firstmonth;
    $current--;
    if ($current == 0) {
        $current = 12;
    }
    /* disabled, it wurks differently now */
    while ($current != $pactivemonth && 0) {
        $i++;
        if ($i > 20) {
            break;
        }
        $current++;
        if ($current == 13) {
            $current = 1;
        }
        close_month('yr1', $current);
    }
    for ($i = 1; $i <= 12; ++$i) {
        close_month('yr1', $i);
    }
    $sql = "SELECT accid FROM core.accounts WHERE accname='Bank Charges'";
    $rslt = db_exec($sql);
    $ad = pg_fetch_array($rslt);
    $bc = $ad['accid'];
    $sql = "SELECT accid FROM core.accounts WHERE accname='Interest Paid'";
    $rslt = db_exec($sql);
    $ad = pg_fetch_array($rslt);
    $i = $ad['accid'];
    $sql = "SELECT accid FROM core.accounts WHERE accname='Interest Received'";
    $rslt = db_exec($sql);
    $ad = pg_fetch_array($rslt);
    $ii = $ad['accid'];
    $sql = "INSERT INTO exten.spricelist (listname,div) VALUES ('Standard','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert into supplier price list.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('CASH DEPOSIT FEE','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('FEE CHEQUE CASHED','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('FEE-SPECIAL PRESENTATION','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('SERVICE FEE','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('OVERDRAFT LEDGER FEE','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('INTEREST','i','-','c','{$i}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('INTEREST','i','+','c','{$ii}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('TRANSACTION CHARGE ','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('ADMIN CHARGE','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('GARAGE CRD CHARGES','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('STAMP DUTY','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('BANKING CHARGES','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.statement_refs (ref,dets,pn,action,account,by) VALUES ('01 CASH DEP','i','-','c','{$bc}','Default');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "CREATE INDEX stkid_stock_key ON cubit.stock USING btree(stkid);";
    db_exec($sql) or errDie("Unable to index.");
    $sql = "CREATE INDEX accid_accounts_key ON core.accounts USING btree(accid);";
    db_exec($sql) or errDie("Unable to index.");
    $sql = "CREATE INDEX accid_trial_bal_key ON core.trial_bal USING btree(accid);";
    db_exec($sql) or errDie("Unable to index.");
    $sql = "INSERT INTO cubit.vatcodes (code,description,del,zero,vat_amount) VALUES ('01','Normal','Yes','No','14');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.vatcodes (code,description,del,zero,vat_amount) VALUES ('02','Capital Goods','No','No','14');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.vatcodes (code,description,del,zero,vat_amount) VALUES ('03','Capital Goods','No','Yes','0');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.vatcodes (code,description,del,zero,vat_amount) VALUES ('04','Zero VAT','No','Yes','0');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.vatcodes (code,description,del,zero,vat_amount) VALUES ('05','VAT Exempt','No','Yes','0');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Disciplinary Verbal Warning','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Disciplinary Written Warning','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Dismissal','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Corrective Counselling','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Performance Counselling','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Grievance','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Disputes Mediation','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Disputes Conciliation','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.report_types (type,div) VALUES ('Disputes Arbitration','" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.login_retries (tries, minutes) VALUES ('0', '0');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.supp_groups (id, groupname) VALUES ('0', '[None]');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.template_settings (template, filename, div) VALUES ('statements', 'pdf/pdf-statement.php', '" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.template_settings (template, filename, div) VALUES ('invoices', 'invoice-print.php', '" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.template_settings (template, filename, div) VALUES ('reprints', 'new', '" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.workshop_settings (setting, value, div) VALUES ('workshop_conditions', 'As per display notice.', '" . USER_DIV . "');";
    db_exec($sql) or errDie("Unable to insert data.");
    $sql = "INSERT INTO cubit.set(type, label, value, descript, div) VALUES('Block main accounts', 'BLOCK', 'use', 'Block main accounts', '" . USER_DIV . "')";
    db_exec($sql) or errDie("Error setting up default setting.");
    $sql = "INSERT INTO exten.ct (days,div) VALUES ('0','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.ct (days,div) VALUES ('7','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.ct (days,div) VALUES ('14','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.ct (days,div) VALUES ('30','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.ct (days,div) VALUES ('60','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.ct (days,div) VALUES ('90','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.ct (days,div) VALUES ('120','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.od (days,div) VALUES ('0','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.od (days,div) VALUES ('7','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.od (days,div) VALUES ('14','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.od (days,div) VALUES ('30','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.od (days,div) VALUES ('60','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.od (days,div) VALUES ('90','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    $sql = "INSERT INTO exten.od (days,div) VALUES ('120','" . USER_DIV . "')";
    db_exec($sql) or errDie("Unable to insert default terms");
    if (is_readable("setup-ratios.php")) {
        include "setup-ratios.php";
    }
    if (!isset($inst_mode) or strlen($inst_mode) < 1) {
        $inst_mode = "hq";
    }
    #record the install type ...
    $sql = "\n\t\tINSERT INTO cubit.settings (\n\t\t\tconstant, label, value, type, datatype, \n\t\t\tminlen, maxlen, div, readonly\n\t\t) VALUES (\n\t\t\t'INST_MODE', 'Cubit Install Mode', '{$inst_mode}', 'company', 'allstring', \n\t\t\t'1', '250', '0', 'f'\n\t\t);";
    db_exec($sql) or errDie("Unable to insert install mode.");
    /* run the addon setups */
    foreach ($CUBIT_MODULES as $modulename) {
        if (is_readable("{$modulename}/setup-addon.php")) {
            include "{$modulename}/setup-addon.php";
        }
    }
    db_conn('core');
    block();
    pglib_transaction("COMMIT");
    $sets = "\n\t\t\t\t<table " . TMPL_tblDflts . " width='50%'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Setup Complete</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>Cubit is ready to be used.</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t<p>\n\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Quick Links</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><a href='main.php'>Main Menu</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>";
    return $sets;
}
コード例 #4
0
function write($_POST)
{
    # get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    require_lib("validate");
    $v = new validate();
    $v->isOk($yrname, "string", 1, 14, "Invalid Year Name.");
    $v->isOk($yrdb, "string", 1, 4, "Invalid Year Database.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class=err>" . $e["msg"];
        }
        $confirm .= "<p><input type=button onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    // Get first period name from range get range
    core_connect();
    $sql = "SELECT * FROM range";
    $Rslt = db_exec($sql);
    if (pg_numrows($Rslt) < 1) {
        $OUTPUT = "<center><li class=err>ERROR : The Financial year Period range was not found on Database, Please make sure that everything is set during instalation.";
        require "template.php";
    }
    $range = Pg_fetch_array($Rslt);
    // Months array
    $months = array("1", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    // Update Active Year Db and name
    db_conn("core");
    $sql = "UPDATE active SET yrdb = '{$yrdb}', yrname = '{$yrname}',  prddb = '{$range['start']}', prdname='" . $months[$range['start']] . "'";
    $rslt = db_exec($sql) or errDie("Could not Set Next Year Database and Name", SELF);
    if (pg_cmdtuples($rslt) < 1) {
        $sql = "INSERT INTO active (yrdb, yrname, prddb, prdname) VALUES ('{$yrdb}', '{$yrname}', '{$range['start']}', '" . $months[$range['start']] . "')";
        $rslt = db_exec($sql) or errDie("Could not Set Next Year Database and Name", SELF);
    }
    $write = "<center>\r\n\t<br>\r\n\t<h3> Selected Financial year has been opened and activated</h3>\r\n\t<input type=button value='Main' Onclick=document.location='../main.php'></a>\r\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=100>\r\n\t<tr><th>Quick Links</th></tr>\r\n\t<script>document.write(getQuicklinkSpecial());</script>\r\n\t<tr bgcolor='#88BBFF'><td><a href='../main.php'>Main Menu</a></td></tr>\r\n\t</table>";
    return $write;
}
コード例 #5
0
function write($_POST)
{
    # Get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    if (isset($back)) {
        return view($_POST);
    }
    # Validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($brancod, "string", 0, 50, "Invalid branch code.");
    $v->isOk($branname, "string", 1, 255, "Invalid branch name.");
    $v->isOk($brandet, "string", 0, 255, "Invalid branch details.");
    # Display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class=err>{$e['msg']}</li>";
        }
        $confirm .= "</li><p><input type=button onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    # Check stock code
    db_connect();
    $sql = "SELECT branname FROM branches WHERE lower(branname) = lower('{$branname}')";
    $cRslt = db_exec($sql);
    if (pg_numrows($cRslt) > 0) {
        $error = "<li class=err>Branch name : <b>{$branname}</b> already exists.</li>";
        $error .= "<p><input type=button onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $error;
    }
    // Insert into stock
    db_connect();
    $sql = "INSERT INTO branches(brancod, branname, brandet) VALUES('{$brancod}', '{$branname}', '{$brandet}')";
    $rslt = db_exec($sql) or errDie("Unable to insert branch to Cubit.", SELF);
    $div = pglib_lastid("branches", "div");
    /*
    // Insert sequences
    $sql = "INSERT INTO seq(type, last_value, div) VALUES('inv', '0', '$div')";
    $rslt = db_exec($sql) or errDie("Unable to insert branch to Cubit.",SELF);
    $sql = "INSERT INTO seq(type, last_value, div) VALUES('pur', '0', '$div')";
    $rslt = db_exec($sql) or errDie("Unable to insert branch to Cubit.",SELF);
    $sql = "INSERT INTO seq(type, last_value, div) VALUES('note', '0', '$div')";
    $rslt = db_exec($sql) or errDie("Unable to insert branch to Cubit.",SELF);
    */
    # Create Default Accounts
    // Profit/Loss account (999/999)
    db_conn('cubit');
    // ,bc='$bc',vat='$vat',cs='$cs'
    //Select user selected account numbering
    $sql = "SELECT label FROM set WHERE label = 'ACCNEW_LNK' AND div = '{$div}'";
    $Rslt = db_exec($sql) or errDie("Unable to check database for existing account creation settings.");
    if (pg_numrows($Rslt) > 0) {
        $Sql = "UPDATE set SET value = 'acc-new2.php', type = 'Account Creation' WHERE label = 'ACCNEW_LNK'";
    } else {
        $Sql = "INSERT INTO set(type, label, value, descript, div) VALUES('Account Creation', 'ACCNEW_LNK', 'acc-new2.php', 'Use user selected account numbers', '{$div}')";
    }
    $setRslt = db_exec($Sql) or errDie("Unable to insert account creation settings to Cubit.");
    db_conn('core');
    //Insert Income Account Category
    $sql = "INSERT INTO income (catid, catname, div) VALUES ('I' || nextval('income_seq'), 'Income', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add income Category to Database.");
    # Get last inserted id for new cat
    $catid = pglib_getlastid("income_seq");
    $catid = "I" . $catid;
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('1000', '000', 'Sales','I', '{$catid}', 'f', 'sales', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $sales_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '1000', '000', 'Sales', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('1100', '000', 'Point of Sale - Sales','I', '{$catid}', 'f', 'sales', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $pos_sales_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '1100', '000', 'Point of Sale - Sales', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('1150', '000', 'Interest Received','I', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $interest_received_acc = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '1150', '000', 'Interest Received', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('1200', '000', 'Sundry Income','I', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '1200', '000', 'Sundry Income', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('1250', '000', 'Exchange Rate Profit/Loss','I', '{$catid}', 'f', 'other_income', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '1250', '000', 'Exchange Rate Profit/Loss', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    //Insert Expense Account Category
    $sql = "INSERT INTO expenditure (catid, catname, div) VALUES ('E' || nextval('expenditure_seq'),'Expenditure', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add expense Category to Database.");
    /*
    $sql = "SELECT * FROM expenditure";
    $catRslt = db_exec($sql) or errDie("Could not retrieve expense Categories Information from the Database.");
    $rows = pg_numrows($catRslt);
    if($rows < 1){
    		return "There are no Account Categories under expen";
    }
    $cat = pg_fetch_array($catRslt);
    $catid=$cat['catid'];
    */
    # Get last inserted id for new cat
    $catid = pglib_getlastid("expenditure_seq");
    $catid = "E" . $catid;
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('2150', '000', 'Cost of Sales','E', '{$catid}', 'f', 'cost_of_sales', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $cost_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2150', '000', 'Cost of Sales', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2510', '000', 'Pension','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $pension_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2510', '000', 'Pension', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2520', '000', 'Retirement Annuity Fund','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $retiree_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2520', '000', 'Retirement Annuity Fund', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2530', '000', 'Provident Fund','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $providente_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2530', '000', 'Provident Fund', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2540', '000', 'Medical Aid','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $medical_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2540', '000', 'Medical Aid', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('2160', '000', 'Cost Variance','E', '{$catid}', 'f', 'cost_of_sales', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $costvar_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2160', '000', 'Cost Variance', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('2170', '000', 'Variance','E', '{$catid}', 'f', 'cost_of_sales', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $salesvar_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2170', '000', 'Variance', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2500', '000', 'Salaries and Wages','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $salaries_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2500', '000', 'Salaries and Wages', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2550', '000', 'Salaries - Commission','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $commision_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2550', '000', 'Salaries - Commission', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2560', '000', 'UIF','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $uifexp = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2560', '000', 'UIF', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2570', '000', 'SDL','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $sdlexp = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2570', '000', 'SDL', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2000', '000', 'Accounting Fees','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2000', '000', 'Accounting Fees', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2050', '000', 'Advertising and Promotions','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2050', '000', 'Advertising and Promotions', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2100', '000', 'Bank Charges','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2100', '000', 'Bank Charges', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2200', '000', 'Depreciation','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2200', '000', 'Depreciation', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2250', '000', 'Electricity and Water','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2250', '000', 'Electricity and Water', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2300', '000', 'General Expenses','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2300', '000', 'General Expenses', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2350', '000', 'Insurance','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2350', '000', 'Insurance', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2400', '000', 'Interest Paid','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2400', '000', 'Interest Paid', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2450', '000', 'Printing and Stationery','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2450', '000', 'Printing and Stationery', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2650', '000', 'Rent Paid','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2650', '000', 'Rent Paid', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, div) VALUES ('2600', '000', 'Telephone and Fax','E', '{$catid}', 'f', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2600', '000', 'Telephone and Fax', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('2700', '000', 'POS Rounding','E', '{$catid}', 'f', 'cost_of_sales', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $racc = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2700', '000', 'POS Rounding', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    //Insert Balance Account Category
    $sql = "INSERT INTO balance (catid, catname, div) VALUES ('B' || nextval('balance_seq'),'Balance', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add balance Category to Database.");
    /*
    $sql = "SELECT * FROM balance";
    $catRslt = db_exec($sql) or errDie("Could not retrieve income Categories Information from Cubit.");
    $rows = pg_numrows($catRslt);
    if($rows < 1){
    		return "There are no Account Categories under income";
    }
    $cat = pg_fetch_array($catRslt);
    $catid=$cat['catid'];
    */
    # Get last inserted id for new cat
    $catid = pglib_getlastid("balance_seq");
    $catid = "B" . $catid;
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6400', '000', 'Customer Control Account','B', '{$catid}', 'f', 'current_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $deptors_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6400', '000', 'Customer Control Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6500', '000', 'Supplier Control Account','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $creditors_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6500', '000', 'Supplier Control Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('7200', '000', 'Cash on Hand','B', '{$catid}', 'f', 'current_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $pos_cash_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '7200', '000', 'Cash on Hand', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('7300', '000', 'POS Credit Card Control','B', '{$catid}', 'f', 'current_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $cc = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '7300', '000', 'POS Credit Card Control', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8000', '000', 'VAT Control Account','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $vat_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '8000', '000', 'VAT Control Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8010', '000', 'VAT Input Account','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $vat_in = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '8010', '000', 'VAT Input Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8020', '000', 'VAT Output Account','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $vat_out = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '8020', '000', 'VAT Output Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6350', '000', 'Inventory','B', '{$catid}', 'f', 'current_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $stock_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6350', '000', 'Inventory', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6300', '000', 'Inventory Suspense Account','B', '{$catid}', 'f', 'current_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sales Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $stock_control = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6300', '000', 'Inventory Suspense Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add sales Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6600', '000', 'Employees Control Account','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $salary_control_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div ) VALUES('{$accid}', '6600', '000', 'Employees Control Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add salaries control Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8400', '000', 'Pension Payable','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $pensionc_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div ) VALUES('{$accid}', '8400', '000', 'Pension Payable', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add salaries control Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8500', '000', 'Medical Aid Payable','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $medicalc_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div ) VALUES('{$accid}', '8500', '000', 'Medical Aid Payable', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add salaries control Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8600', '000', 'Retirement Annuity Fund Payable','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $retire_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div ) VALUES('{$accid}', '8600', '000', 'Retirement Annuity Fund Payable', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add salaries control Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8700', '000', 'Provident Fund Payable','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $provident_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div ) VALUES('{$accid}', '8700', '000', 'Provident Fund Payable', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add salaries control Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8100', '000', 'PAYE Payable','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $paye_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '8100', '000', 'PAYE Payable', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add salaries control Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8200', '000', 'UIF Payable','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $uif_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '8200', '000', 'UIF Payable', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add uif control Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('8300', '000', 'SDL Payable','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $sdlbal = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '8300', '000', 'SDL Payable', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add uif control Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6700', '000', 'Employee Loan Account','B', '{$catid}', 'f', 'current_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add sasalaries control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $loan_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6700', '000', 'Employee Loan Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add loan Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('7000', '000', 'Bank','B', '{$catid}', 'f', 'current_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $bank_account = $accid;
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '7000', '000', 'Bank', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('5200', '000', 'Retained Income / Accumulated Loss','B', '{$catid}', 'f', 'retained_income', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '5200', '000', 'Retained Income / Accumulated Loss', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('5250', '000', 'Share Capital / Members Contribution','B', '{$catid}', 'f', 'share_capital', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '5250', '000', 'Share Capital / Members Contribution', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('5300', '000', 'Shareholder / Director / Members Loan Account','B', '{$catid}', 'f', 'shareholders_loan', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '5300', '000', 'Shareholder / Director / Members Loan Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6000', '000', 'Land & Buildings - Net Value','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6000', '000', 'Land & Buildings - Net Value', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6000', '010', 'Land & Buildings - Cost','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6000', '010', 'Land & Buildings - Cost', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6000', '020', 'Land & Buildings - Accum Depreciation','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6000', '020', 'Land & Buildings - Accum Depreciation', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6100', '020', 'Motor Vehicle - Accum Depreciation','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6100', '020', 'Motor Vehicle - Accum Depreciation', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6100', '000', 'Motor Vehicle - Net Value','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6100', '000', 'Motor Vehicle - Net Value', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6100', '010', 'Motor Vehicle - Cost','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6100', '010', 'Motor Vehicle - Cost', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6150', '000', 'Computer Equipment - Net Value','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6150', '000', 'Computer Equipment - Net Value', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6150', '010', 'Computer Equipment - Cost','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6150', '010', 'Computer Equipment - Cost', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6150', '020', 'Computer Equipment - Accum Depreciation','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6150', '020', 'Computer Equipment - Accum Depreciation', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6160', '000', 'Office Equipment - Net Value','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6160', '000', 'Office Equipment - Net Value', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6160', '010', 'Office Equipment - Cost','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6160', '010', 'Office Equipment - Cost', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6160', '020', 'Office Equipment - Accum Depreciation','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6160', '020', 'Office Equipment - Accum Depreciation', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6170', '000', 'Furniture & Fittings - Net Value','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6170', '000', 'Furniture & Fittings - Net Value', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6170', '010', 'Furniture & Fittings - Cost','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6170', '010', 'Furniture & Fittings - Cost', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('6170', '020', 'Furniture & Fittings - Accum Depreciation','B', '{$catid}', 'f', 'fixed_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '6170', '020', 'Furniture & Fittings - Accum Depreciation', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('7100', '000', 'Petty Cash','B', '{$catid}', 'f', 'current_asset', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    $pettya = $accid;
    # Insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '7100', '000', 'Petty Cash', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # Write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('9000', '000', 'Opening Balances / Suspense Account','B', '{$catid}', 'f', 'current_liability', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add bank control Account to Database.", SELF);
    # Get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # Insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '9000', '000', 'Opening Balances / Suspense Account', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add bank Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    # Begin sql transaction
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    # Write to DB
    $sql = "INSERT INTO accounts (topacc, accnum, accname, acctype, catid, vat, toptype, div) VALUES ('2800', '000', 'Normal Tax','E', 'E10', 'f', 'tax', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add Normal Tax Account to Database.", SELF);
    # Get last inserted id for new acc
    $accid = pglib_lastid("accounts", "accid");
    # Insert account into trial Balance
    $query = "INSERT INTO trial_bal(accid, topacc, accnum, accname, vat, div) VALUES('{$accid}', '2800', '000', 'Normal Tax', 'f', '{$div}')";
    $trialRslt = db_exec($query) or errDie("Unable to add Normal Tax Account to Database.", SELF);
    # Commit sql transaction
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    $sql = "SELECT * FROM bankacc WHERE name = 'Petty Cash' AND div = '{$div}'";
    $checkRslt = db_exec($sql) or errDie("Unable to retrieve Petty Cash Account details from database.");
    if (pg_numrows($checkRslt) > 0) {
        $link = "UPDATE bankacc SET accnum='{$pettya}' WHERE name = 'Petty Cash', '{$div}'";
    } else {
        $link = "INSERT INTO bankacc(name, accnum, div) VALUES('Petty Cash', '{$pettya}', '{$div}')";
    }
    $linkRslt = db_exec($link) or errDie("Unable to add Petty Cash Account link to Database.", SELF);
    # Check if year has been opened
    core_connect();
    $sql = "SELECT * FROM active";
    $cRs = db_exec($sql) or errDie("Database Access Failed - check year open.", SELF);
    if (pg_numrows($cRs) < 1) {
        /* Skip Period Management */
        # Empty the year name table
        $sql = "DELETE FROM year";
        $rslt = db_exec($sql);
        for ($i = 1; $i <= 10; $i++) {
            $sql = "INSERT INTO year VALUES('y" . ($selyear + $i - 1) . "', 'yr{$i}', 'n', '{$div}')";
            $rslt = db_exec($sql) or errDie("Could not set year name in Cubit", SELF);
        }
        $yrname = "y{$selyear}";
        $endmon = $smonth - 1;
        if (intval($endmon == 0)) {
            $endmon = 12;
        }
        $Sql = "TRUNCATE range";
        $Rs = db_exec($Sql) or errDie("Unable to empty year range", SELF);
        $firstmonth = $smonth;
        $activeyear = $yrname;
        $sql = "INSERT INTO range(\"start\", \"end\", div) VALUES('{$smonth}', '{$endmon}', '{$div}')";
        $Rslt = db_exec($sql) or errDie("Unable to insert year range", SELF);
        $sql = "SELECT * FROM year WHERE yrname='{$yrname}'";
        $yrs = db_exec($sql);
        $yr = pg_fetch_array($yrs);
        if ($yr['closed'] == 'y') {
            return "<center><li class=err>ERROR : The Selected Financial year : <b>{$yrname}</b> has been closed.\n\t\t\t<p><input type=button onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        }
        $yrdb = $yr['yrdb'];
        $sql = "SELECT * FROM range";
        $Rslt = db_exec($sql);
        if (pg_numrows($Rslt) < 1) {
            $OUTPUT = "<center><li class=err>ERROR : The Financial year Period range was not found on Database, Please make sure that everything is set during instalation.";
            require "template.php";
        }
        $range = Pg_fetch_array($Rslt);
        // Months array
        $months = array("1", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
        $sql = "UPDATE active SET yrdb = '{$yrdb}', yrname = '{$yrname}',  prddb = '{$range['start']}', prdname='" . $months[$range['start']] . "' WHERE div = '{$div}'";
        $rslt = db_exec($sql) or errDie("Could not Set Next Year Database and Name", SELF);
        if (pg_cmdtuples($rslt) < 1) {
            $sql = "INSERT INTO active (yrdb, yrname, prddb, prdname, div) VALUES ('{$yrdb}', '{$yrname}', '{$range['start']}', '" . $months[$range['start']] . "', '{$div}')";
            $rslt = db_exec($sql) or errDie("Could not Set Next Year Database and Name", SELF);
        }
        /* Skiped the period management stuff */
    } else {
        $firstmonth = $smonth;
    }
    $link = "INSERT INTO pchsacc(name, accnum, div) VALUES('Cost Variance', '{$costvar_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "DELETE FROM salesacc WHERE name='VAT' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salesacc(name, accnum, div) VALUES('VAT', '{$vat_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add vat Account link to Database.", SELF);
    $link = "DELETE FROM salesacc WHERE name='rounding' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salesacc(name, accnum, div) VALUES('rounding', '{$racc}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add vat Account link to Database.", SELF);
    $link = "DELETE FROM salesacc WHERE name='VATIN' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salesacc(name, accnum, div) VALUES('VATIN', '{$vat_in}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add vat Account link to Database.", SELF);
    $link = "DELETE FROM salesacc WHERE name='VATOUT' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salesacc(name, accnum, div) VALUES('VATOUT', '{$vat_out}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add vat Account link to Database.", SELF);
    $link = "DELETE FROM salesacc WHERE name='sales_variance' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salesacc(name, accnum, div) VALUES('sales_variance', '{$salesvar_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add vat Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='salaries' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('salaries', '{$salaries_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='cash' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('cash', '{$pos_cash_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='cc' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('cc', '{$cc}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='salaries control' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('salaries control', '{$salary_control_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('salaries control original', '{$salary_control_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='Commision' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('Commission', '{$commision_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='PAYE' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('PAYE', '{$paye_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='UIF' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('UIF', '{$uif_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='loanacc' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('loanacc', '{$loan_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='uifexp' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('uifexp', '{$uifexp}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='uifbal' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('uifbal', '{$uif_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='sdlexp' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('sdlexp', '{$sdlexp}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='sdlbal' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('sdlbal', '{$sdlbal}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='pensionexpense' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('pensionexpense', '{$pension_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='interestreceived' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete interest received Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('interestreceived', '{$interest_received_acc}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add interest received link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='medicalexpense' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('medicalexpense', '{$medical_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('retire', '{$retire_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('retireexpense', '{$retiree_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('provident', '{$provident_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Provident Fund Payable link to Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('providentexpense', '{$providente_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Provident Fund Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='pension' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('pension', '{$pensionc_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    $link = "DELETE FROM salacc WHERE name='medical' AND div = '{$div}'";
    $linkRslt = db_exec($link) or errDie("Unable to delete vat Account link from Database.", SELF);
    $link = "INSERT INTO salacc(name, accnum, div) VALUES('medical', '{$medicalc_account}', '{$div}')";
    $linkRslt = db_exec($link) or errDie("Unable to add Salaries Account link to Database.", SELF);
    db_conn("exten");
    $sql = "INSERT INTO departments(deptno, deptname, incacc, debtacc, credacc, pia, pca, div) VALUES ('1', 'Ledger 1', '{$sales_account}', '{$deptors_account}', '{$creditors_account}', '{$pos_sales_account}', '{$pos_cash_account}', '{$div}')";
    $deptRslt = db_exec($sql) or errDie("Unable to add deparment to system.", SELF);
    $sql = "INSERT INTO salespeople(salespno, salesp, div) VALUES ('1', 'General', '{$div}')";
    $salespRslt = db_exec($sql) or errDie("Unable to add warehouse to system.", SELF);
    $sql = "INSERT INTO  categories(category, div) VALUES ('General', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add category to system.", SELF);
    $sql = "INSERT INTO  class(classname, div) VALUES ('General', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add fringe benefit to system.", SELF);
    $sql = "INSERT INTO warehouses(whno, whname, stkacc, cosacc, conacc, div) VALUES ('1', 'Store 1', '{$stock_account}', '{$cost_account}', '{$stock_control}', '{$div}')";
    $whouseRslt = db_exec($sql) or errDie("Unable to add warehouse to system.", SELF);
    $whid = pglib_lastid("warehouses", "whid");
    $sql = "INSERT INTO  pricelist(listname, div) VALUES ('Standard', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to price list to system.", SELF);
    db_conn("cubit");
    $sql = "INSERT INTO stockcat(catcod, cat, descript, div) VALUES('1', 'General', 'General Stock Category', '{$div}')";
    $rslt = db_exec($sql) or errDie("Unable to insert stock category to Cubit.", SELF);
    $sql = "INSERT INTO stockclass(classcode, classname, div) VALUES ('1', 'General', '{$div}')";
    $catRslt = db_exec($sql) or errDie("Unable to add class to system.", SELF);
    # check if setting exists(default warehouse)
    $sql = "SELECT label FROM set WHERE label = 'DEF_WH' AND div = '{$div}'";
    $Rslt = db_exec($sql) or errDie("Unable to check database for existing settings.");
    if (pg_numrows($Rslt) > 0) {
        $Sql = "UPDATE set SET value = '{$whid}', type = 'Default Warehouse' WHERE label = 'DEF_WH' AND div = '{$div}'";
    } else {
        $Sql = "INSERT INTO set(type, label, value, descript, div) VALUES('Default Warehouse', 'DEF_WH', '{$whid}', '1 &nbsp;&nbsp;&nbsp; Store1', '{$div}')";
    }
    $setRslt = db_exec($Sql) or errDie("Unable to insert settings to Cubit.");
    # Check if setting exists (vat type)
    $sql = "SELECT label FROM set WHERE label = 'SELAMT_VAT' AND div = '{$div}'";
    $Rslt = db_exec($sql) or errDie("Unable to check database for existing settings.");
    if (pg_numrows($Rslt) > 0) {
        $Sql = "UPDATE set SET value = 'inc', descript = 'Vat Inclusive' WHERE label = 'SELAMT_VAT' AND div = '{$div}'";
    } else {
        $Sql = "INSERT INTO set(type, label, value, descript, div) VALUES('Vat type on stock selling price', 'SELAMT_VAT', 'inc', 'Vat Inclusive', '{$div}')";
    }
    $setRslt = db_exec($Sql) or errDie("Unable to insert settings to Cubit.");
    # begin sql transaction
    # pglib_transaction ("BEGIN") or errDie("Unable to start a database transaction.",SELF);
    $sql = "INSERT INTO bankacct (acctype, bankname, branchname, branchcode, accname, accnum, details, div,btype) VALUES ('Cheque', 'Bank', 'Branch', '000000', 'Account Name', '000000000000', 'Default bank Account', '{$div}','loc')";
    $bankAccRslt = db_exec($sql) or errDie("Unable to add bank account to database.");
    $accid = pglib_lastid("bankacct", "bankid");
    # Commit sql transaction
    # pglib_transaction ("COMMIT") or errDie("Unable to finish a database transaction.",SELF);
    db_conn("core");
    $hook = "INSERT INTO bankacc(accid, accnum, div) VALUES('{$accid}', '{$bank_account}', '{$div}')";
    $Rlst = db_exec($hook) or errDie("Unable to add link for for new bank account", SELF);
    db_conn("crm");
    $Sl = "INSERT INTO links (name,script) VALUES ('Add Client','../customers-new.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('View Client','../customers-view.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('New Invoice','../cust-credit-stockinv.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('Find Invoice','../invoice-search.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('View Stock','../stock-view.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('Add Supplier','../supp-new.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('View Suppliers','../supp-view.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('New Purchase','../purchase-new.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('View Purchases','../purchase-view.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('Add Quote','../quote-new.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('View Invoices','../invoice-view.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('View Quotes','../quote-view.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('Debtors Age Analysis','../reporting/debt-age-analysis.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('Creditors Age Analysis','../reporting/cred-age-analysis.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO links (name,script) VALUES ('Bank Reconciliation','../reporting/bank-recon.php')";
    $Ry = db_exec($Sl) or errDie("Unable to insert link.");
    $Sl = "INSERT INTO teams (name,div) VALUES ('Sales','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO teams (name,div) VALUES ('Support','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO teams (name,div) VALUES ('Accounts','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO teams (name,div) VALUES ('Company Relations','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO teams (name,div) VALUES ('Purchasing - Supplier Relations','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Product Enquiries','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Place an Order','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Complain','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Account querries','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Delivery or Installation Tracking','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Comment on good service or Remarks','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Ask about employment','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('General','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Potential Supplier','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO tcats (name,div) VALUES ('Product Support','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into teams");
    $Sl = "INSERT INTO actions (action) VALUES ('Called - Need to call again.')";
    $Ry = db_exec($Sl) or errDie("Unable to insert action.");
    $Sl = "INSERT INTO actions (action) VALUES ('Called - Could not get in touch')";
    $Ry = db_exec($Sl) or errDie("Unable to insert action.");
    $Sl = "INSERT INTO actions (action) VALUES ('Requested more information')";
    $Ry = db_exec($Sl) or errDie("Unable to insert action.");
    $Sl = "INSERT INTO actions (action) VALUES ('Sent Fax')";
    $Ry = db_exec($Sl) or errDie("Unable to insert action.");
    $pactivemonth = $activemonth;
    $pactivemonth--;
    if ($pactivemonth == 0) {
        $pactivemonth = 12;
    }
    $i = 0;
    $current = $firstmonth;
    $current--;
    if ($current == 0) {
        $current = 12;
    }
    while ($current != $pactivemonth) {
        $i++;
        if ($i > 20) {
            break;
        }
        $current++;
        if ($current == 13) {
            $current = 1;
        }
        //close_month('yr1',$current);
    }
    // 	//if(is/*set($firstmonth)) {
    // 		$start=$firstmonth;
    //
    // 		for($i=1; $i<=12; $i++) {
    // 			if(($i<$activemonth) and ($i>=$start)) {
    // 				close_month('yr1',$i);
    // 			}
    // 		}
    // //	}
    db_conn('core');
    $Sl = "SELECT accid FROM accounts WHERE accname='Bank Charges'";
    $Ri = db_exec($Sl);
    $ad = pg_fetch_array($Ri);
    $bc = $ad['accid'];
    $Sl = "SELECT accid FROM accounts WHERE accname='Interest Paid'";
    $Ri = db_exec($Sl);
    $ad = pg_fetch_array($Ri);
    $i = $ad['accid'];
    $Sl = "SELECT accid FROM accounts WHERE accname='Interest Received'";
    $Ri = db_exec($Sl);
    $ad = pg_fetch_array($Ri);
    $ii = $ad['accid'];
    db_conn('exten');
    $Sl = "INSERT INTO spricelist (listname,div) VALUES ('Standard','{$div}')";
    $Ry = db_exec($Sl) or errDie("Unable to insert into supplier price list.");
    db_conn('cubit');
    $Sl = "INSERT INTO currency (symbol,descrip,rate,def) VALUES ('R','Rand',0.00,'')";
    $Ry = db_exec($Sl) or errDie("Unable to insert currency.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('CASH DEPOSIT FEE','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('FEE CHEQUE CASHED','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('FEE-SPECIAL PRESENTATION','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('SERVICE FEE','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('OVERDRAFT LEDGER FEE','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('INTEREST','i','-','c','{$i}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('INTEREST','i','+','c','{$ii}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('TRANSACTION CHARGE ','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('ADMIN CHARGE','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('GARAGE CRD CHARGES','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('STAMP DUTY','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('BANKING CHARGES','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO statement_refs (ref,dets,pn,action,account,by) VALUES ('01 CASH DEP','i','-','c','{$bc}','Default');";
    $Ry = db_exec($Sl) or errDie("Unable to insert data.");
    //  	db_conn('cubit');
    //
    //  	$Sl="CREATE INDEX stkid_stock_key ON stock USING btree(stkid);";
    //  	$Ri=db_exec($Sl) or errDie("Unable to index.");
    //
    //  	db_conn('core');
    //
    //  	$Sl="CREATE INDEX accid_accounts_key ON accounts USING btree(accid);";
    //  	$Ri=db_exec($Sl) or errDie("Unable to index.");
    //
    // 	$Sl="CREATE INDEX accid_trial_bal_key ON trial_bal USING btree(accid);";
    // 	$Ri=db_exec($Sl) or errDie("Unable to index.");
    //
    // 	/*for($p = 1; $p <=12; $p++){
    // 		db_conn($p);
    //
    // 		$Sl="CREATE INDEX accid_accounts_key ON accounts USING btree(accid);";
    //  		$Ri=db_exec($Sl) or errDie("Unable to index.");
    //
    //  		$Sl="CREATE INDEX accid_trial_bal_key ON trial_bal USING btree(accid);";
    //  		$Ri=db_exec($Sl) or errDie("Unable to index.");
    //
    // 	}*/
    db_conn('cubit');
    $Sl = "INSERT INTO vatcodes (code,description,del,zero,vat_amount) VALUES ('01','Normal','Yes','No','14');";
    $Ri = db_exec($Sl) or errDie("Unabel to insert data.");
    $Sl = "INSERT INTO vatcodes (code,description,del,zero,vat_amount) VALUES ('02','Capital Goods','No','No','0');";
    $Ri = db_exec($Sl) or errDie("Unabel to insert data.");
    $Sl = "INSERT INTO vatcodes (code,description,del,zero,vat_amount) VALUES ('03','Capital Goods','No','Yes','0');";
    $Ri = db_exec($Sl) or errDie("Unabel to insert data.");
    $Sl = "INSERT INTO vatcodes (code,description,del,zero,vat_amount) VALUES ('04','Zero VAT','No','Yes','0');";
    $Ri = db_exec($Sl) or errDie("Unabel to insert data.");
    $Sl = "INSERT INTO vatcodes (code,description,del,zero,vat_amount) VALUES ('05','VAT Exempt','No','Yes','0');";
    $Ri = db_exec($Sl) or errDie("Unabel to insert data.");
    $Sl = "INSERT INTO login_retries (tries, minutes) VALUES ('0', '0');";
    $Ri = db_exec($Sl) or errDie("Unabel to insert data.");
    $Sl = "INSERT INTO supp_groups (id, groupname) VALUES ('0', '[None]');";
    $Ri = db_exec($Sl) or errDie("Unabel to insert data.");
    $Sl = "INSERT INTO template_settings (template, filename, div) VALUES ('statements', 'pdf/cust-pdf-stmnt.php', '{$div}');";
    $Ri = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO template_settings (template, filename, div) VALUES ('invoices', 'invoice-print.php', '{$div}');";
    $Ri = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO template_settings (template, filename, div) VALUES ('reprints', 'default', '{$div}');";
    $Ri = db_exec($Sl) or errDie("Unable to insert data.");
    $Sl = "INSERT INTO workshop_settings (setting, value, div) VALUES ('workshop_conditions', 'As per display notice.', '{$div}');";
    $Ri = db_exec($Sl) or errDie("Unable to insert data.");
    db_conn('cubit');
    $Sql = "INSERT INTO set(type, label, value, descript, div) VALUES('Block main accounts', 'BLOCK', 'use', 'Block main accounts', '{$div}')";
    $Ri = db_exec($Sql);
    db_conn('exten');
    $Sl = "INSERT INTO ct (days,div) VALUES ('0','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO ct (days,div) VALUES ('7','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO ct (days,div) VALUES ('14','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO ct (days,div) VALUES ('30','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO ct (days,div) VALUES ('60','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO ct (days,div) VALUES ('90','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO ct (days,div) VALUES ('120','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO od (days,div) VALUES ('0','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO od (days,div) VALUES ('7','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO od (days,div) VALUES ('14','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO od (days,div) VALUES ('30','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO od (days,div) VALUES ('60','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO od (days,div) VALUES ('90','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    $Sl = "INSERT INTO od (days,div) VALUES ('120','{$div}')";
    $Ri = db_exec($Sl) or errDie("Unable to insert default terms");
    db_conn('core');
    block();
    $catid = createcat("Profit/Loss", $div, "B");
    if (createacc("9999", "999", "Profit/Loss account", $catid, "B", "n", $div) > 0) {
        return "<li class=err>Failed to create default accounts</li>";
    }
    // Total Income account (199/999)
    $catid = createcat("Total Income", $div, "I");
    if (createacc("1999", "999", "Total Income account", $catid, "I", "n", $div) > 0) {
        return "<li class=err>Failed to create default accounts</li>";
    }
    // Total Expenses account (499/999)
    $catid = createcat("Total Expenses", $div, "E");
    if (createacc("4999", "999", "Total Expenses account", $catid, "E", "n", $div) > 0) {
        return "<li class=err>Failed to create default accounts</li>";
    }
    // Layout
    $write = "\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='50%'>\n\t<tr><th>New Branch added to database</th></tr>\n\t<tr class=datacell><td>New Branch, {$branname} ({$brancod}) has been successfully added to Cubit.</td></tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='2' cellspacing='1'>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td><a href='admin-branview.php'>View Branches</a></td></tr>\n\t\t<tr class='bg-odd'><td><a href='main.php'>Main Menu</a></td></tr>\n\t</table>";
    return $write;
}
コード例 #6
0
function selectNextYear($nextyr)
{
    // get next year name
    $sql = "SELECT * FROM year WHERE yrdb ='" . $nextyr . "'";
    $rslt = db_exec($sql);
    $yr = pg_fetch_array($rslt);
    // get first period name
    // Get range
    core_connect();
    $sql = "SELECT * FROM range";
    $Rslt = db_exec($sql);
    if (pg_numrows($Rslt) < 1) {
        $OUTPUT = "<center><li class=err>ERROR : The Financial year Period range was not found on Database, Please make sure that everything is set during instalation.";
        require "template.php";
    }
    $range = Pg_fetch_array($Rslt);
    // Months array
    $months = array("1", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    db_connect();
    $sql = "delete from set where label = 'YRCLOSE'";
    $rslt = db_exec($sql) or errDie("Could not Set Next Year Database and Name", SELF);
    // Update Active Year Db and name
    db_conn("core");
    $sql = "UPDATE active SET yrdb = '{$nextyr}', yrname = '{$yr['yrname']}', prddb = '{$range['start']}', prdname='" . $months[$range['start']] . "'";
    $rslt = db_exec($sql) or errDie("Could not Set Next Year Database and Name", SELF);
    $sql = "UPDATE year SET closed = 'y' WHERE yrdb = '" . YR_DB . "'";
    $rslt = db_exec($sql) or errDie("Could not Set Last Year Database as Closed.", SELF);
}
コード例 #7
0
$active = Pg_fetch_array($rslt);
// check if its december
if ($active['prddb'] == 12) {
    $nxprd = 1;
} else {
    $nxprd = $active['prddb'] + 1;
}
// Get range
core_connect();
$sql = "SELECT * FROM range";
$Rslt = db_exec($sql);
if (pg_numrows($Rslt) < 1) {
    $OUTPUT = "<center><li class=err>ERROR : The Financial year Period range was not found on Database, Please make sure that everything is set during instalation.";
    require "template.php";
}
$range = Pg_fetch_array($Rslt);
// the f***** year is over B***** !!
if ($nxprd == $range['start']) {
    db_connect();
    $sql = "Insert into set(label) values('YRCLOSE')";
    $rslt = db_exec($sql) or errDie("Could not Set Next Period Database", SELF);
    $ERROR = "( i )<li>You have reached the end of the current Financial. you have to close a financial year before you continue.( i )";
} else {
    // Months array
    $months = array("1", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    // Update Active Period Db and name
    db_conn("core");
    $sql = "UPDATE active SET prddb = '{$nxprd}', prdname = '{$months[$nxprd]}'";
    $rslt = db_exec($sql) or errDie("Could not Set Next Period Database", SELF);
    $ERROR = "( i ) The next period has been activated ( i )";
}