function adjust_update()
{
    extract($_REQUEST);
    pglib_transaction("BEGIN");
    foreach ($update as $stkid => $value) {
        $sql = "UPDATE cubit.stock_take SET adjusted='1' WHERE stkid='{$stkid}'";
        db_exec($sql) or errDie("Unable to update stock take.");
        if ($adjust_qty[$stkid] > 0) {
            increase_stock($stkid, $adjust_qty[$stkid]);
        } elseif ($adjust_qty[$stkid] < 0) {
            decrease_stock($stkid, abs($adjust_qty[$stkid]));
        }
        unblock_stock($stkid);
    }
    pglib_transaction("COMMIT");
    return adjust_display();
}
function complete()
{
    extract($_REQUEST);
    pglib_transaction("BEGIN");
    $datetime = date("Y-m-d G:i:s");
    foreach ($adjust_qty as $stkid => $value) {
        $sql = "UPDATE cubit.stock_take SET adjusted='1'\n\t\t\t\tWHERE stkid='{$stkid}'";
        db_exec($sql) or errDie("Unable to update stock take.");
        if ($adjust_qty[$stkid] > 0) {
            increase_stock($stkid, $adjust_qty[$stkid]);
        } elseif ($adjust_qty[$stkid] < 0) {
            decrease_stock($stkid, abs($adjust_qty[$stkid]));
        }
        unblock_stock($stkid);
    }
    $sql = "SELECT stkid, qty FROM cubit.stock_take";
    $stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock.");
    while (list($stkid, $qty) = pg_fetch_array($stock_rslt)) {
        $sql = "INSERT INTO cubit.stock_take_report (timestamp, stkid, qty)\n\t\t\t\tVALUES ('{$datetime}', '{$stkid}', '{$qty}')";
        db_exec($sql) or errDie("Unable to add to report.");
    }
    $sql = "DELETE FROM cubit.stock_take";
    db_exec($sql) or errDie("Unable to remove from stock take.");
    pglib_transaction("COMMIT");
    $OUTPUT = "\n\t<h3>Stock Take</h3>\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr><th>Complete</th></tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td><li>Page has successfully been completed.</td></li>\n\t\t</tr>\n\t</table>";
    return adjust_display();
    return $OUTPUT;
}