Ejemplo n.º 1
0
function enter($err = "")
{
    extract($_REQUEST);
    $fields = array();
    $fields["price"] = "0.00";
    $fields["cust_id"] = 0;
    $fields["vatcode"] = "2";
    $fields["vatinc"] = "inc";
    if (!isset($date_year)) {
        explodeDate(DATE_STD, $date_year, $date_month, $date_day);
    }
    extract($fields, EXTR_SKIP);
    db_connect();
    // Retrieve asset
    $sql = "SELECT * FROM cubit.assets WHERE id='{$asset_id}'";
    $asset_rslt = db_exec($sql) or errDie("Unable to retrieve asset.");
    $asset_data = pg_fetch_array($asset_rslt);
    // Retrieve asset group
    $sql = "SELECT * FROM cubit.assetgrp WHERE grpid='{$asset_data['grpid']}'";
    $asgrp_rslt = db_exec($sql) or errDie("Unable to retrieve asset group.");
    $asgrp_data = pg_fetch_array($asgrp_rslt);
    // Retrieve customer
    $sql = "SELECT * FROM cubit.customers ORDER BY surname ASC";
    $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customers.");
    $cust_sel = "<select name='cust_id' style='width: 100%'>";
    $cust_sel .= "<option " . fsel($cust_id == "-1") . " value='-1'>Cash Sale</option>";
    //$cust_sel.= "<option ".fsel($cust_id == "-2")." value='-2'>Ledger Account Sale</option>";
    $cust_sel .= "<optgroup label='Customer Sale'>";
    while ($cust_data = pg_fetch_array($cust_rslt)) {
        $sel = fsel($cust_id == $cust_data["cusnum"]);
        $cust_sel .= "\r\n\t\t<option {$sel} value='{$cust_data['cusnum']}'>\r\n\t\t\t{$cust_data['cusname']} {$cust_data['surname']}\r\n\t\t</option>";
    }
    $cust_sel .= "</optgroup>";
    $cust_sel .= "</select>";
    $cds = qryVatcode();
    $sel_vatcode = db_mksel($cds, "vatcode", $vatcode, "#id", "#code");
    if ($asset_data["nonserial"] == "1") {
        if (!isset($qty)) {
            $qty = $asset_data["serial2"];
        }
        $qtyinput = "\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Sell Units</td>\r\n\t\t\t\t\t\t\t<td><input type='text' size='4' name='qty' value='{$qty}' /></td>\r\n\t\t\t\t\t\t</tr>";
    } else {
        $qtyinput = "<input type='hidden' name='qty' value='1' />";
    }
    $OUTPUT = "\r\n\t\t\t\t<center>\r\n\t\t\t\t<h3>Asset Sale</h3>\r\n\t\t\t\t{$err}\r\n\t\t\t\t<form method='POST' action='" . SELF . "'>\r\n\t\t\t\t\t<input type='hidden' name='key' value='confirm' />\r\n\t\t\t\t\t<input type='hidden' name='asset_id' value='{$asset_id}' />\r\n\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<th colspan='2'>Details</th>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Group</td>\r\n\t\t\t\t\t\t<td>{$asgrp_data['grpname']}</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Serial Number</td>\r\n\t\t\t\t\t\t<td>{$asset_data['serial']}</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>2nd Serial Number/Qty</td>\r\n\t\t\t\t\t\t<td>{$asset_data['serial2']}</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Description</td>\r\n\t\t\t\t\t\t<td>{$asset_data['des']}</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Customer</td>\r\n\t\t\t\t\t\t<td>{$cust_sel}</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Date</td>\r\n\t\t\t\t\t\t<td>" . mkDateSelect("date", $date_year, $date_month, $date_day) . "</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Vat</td>\r\n\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t<input type='radio' name='vatinc' value='inc' " . fcheck($vatinc != "exc") . " /> Including\r\n\t\t\t\t\t\t\t<input type='radio' name='vatinc' value='exc' " . fcheck($vatinc == "exc") . " /> Excluding\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Vatcode</td>\r\n\t\t\t\t\t\t<td>{$sel_vatcode}</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t{$qtyinput}\r\n\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t<td>Selling Price/Asset Unit</td>\r\n\t\t\t\t\t\t<td nowrap='t'>\r\n\t\t\t\t\t\t\t" . CUR . " <input type='text' size='10' name='price' value='{$price}'>\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td colspan='2' align='right'>\r\n\t\t\t\t\t\t\t<input type='submit' value='Confirm &raquo' />\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t</table>\r\n\t\t\t\t</form>\r\n\t\t\t\t</center>";
    return $OUTPUT;
}
function details($_POST, $error = "")
{
    extract($_REQUEST);
    $fields = array();
    $fields["deptid"] = 2;
    $fields["cusnum"] = 0;
    $fields["telno"] = "";
    $fields["cordno"] = "";
    $fields["des"] = "";
    $fields["pinv_day"] = date("d");
    $fields["pinv_month"] = date("m");
    $fields["pinv_year"] = date("Y");
    $fields["vatinc_yes"] = "checked";
    $fields["vatinc_no"] = "";
    $fields["vat14"] = AT14;
    $fields["vat"] = "0.00";
    $fields["total"] = "0.00";
    $fields["rounding"] = "";
    $fields["nhifrm_year"] = date("Y");
    $fields["nhifrm_month"] = date("m");
    $fields["nhifrm_day"] = date("d");
    $fields["nhito_year"] = date("Y");
    $fields["nhito_month"] = date("m");
    $fields["nhito_day"] = date("d");
    $fields["client_collect"] = "";
    $fields["collect"] = "";
    $fields["deliver"] = "";
    $fields["deposit_amt"] = "0.00";
    $fields["deposit_type"] = "CSH";
    $fields["custom_txt"] = "";
    $fields["monthly"] = false;
    $fields["bk_asset"] = 0;
    // 30 Asset
    $fields["bk_id"] = 0;
    $fields["reprint"] = 0;
    extract($fields, EXTR_SKIP);
    if (isset($bk_from)) {
        list($nhifrm_year, $nhifrm_month, $nhifrm_day) = explode("-", $bk_from);
    }
    if (isset($bk_to)) {
        list($nhito_year, $nhito_month, $nhito_day) = explode("-", $bk_to);
    }
    $subtot = 0;
    if (isset($hirenewBtn)) {
        newHire($_POST);
    }
    // Get us an invoice id
    if (!isset($invid)) {
        $invid = create_dummy($deptid);
    } else {
        $sql = "SELECT cusnum FROM hire.hire_invoices WHERE invid='{$invid}'";
        $cn_rslt = db_exec($sql) or errDie("Unable to retrieve invoices.");
        $cusnum = pg_fetch_result($cn_rslt, 0);
        updateTotals($invid);
    }
    $ind_ccol = "";
    $ind_col = "";
    $ind_del = "";
    $collect_ar = array();
    if (!empty($client_collect)) {
        $collect_ar[] = "Client Collect";
    }
    if (!empty($collect)) {
        $collect_ar[] = "Collect";
    }
    if (!empty($deliver)) {
        $collect_ar[] = "Deliver";
    }
    if (empty($client_collect) && empty($collect) && empty($deliver)) {
        $client_collect = "checked";
        $collect_ar[] = "Client Collect";
    }
    $collection = implode(", ", $collect_ar);
    if (empty($monthly)) {
        $sql = "SELECT *, extract('epoch' FROM expected) AS e_exp, extract('epoch' FROM to_date) AS e_to FROM hire.hire_invitems WHERE invid='{$invid}'";
        $item_rslt = db_exec($sql) or errDie("Unable to retrieve items.");
        while ($item_data = pg_fetch_array($item_rslt)) {
            if (!empty($item_data["expected"])) {
                if ($item_data["e_to"] > time()) {
                    $item_data["expected"] = date("Y-m-t", $item_data["e_to"]);
                } else {
                    if ($item_data["e_exp"] < time()) {
                        $item_data["expected"] = date("Y-m-t");
                    }
                }
                $sql = "\r\n\t\t\t\t\tUPDATE hire.hire_invitems \r\n\t\t\t\t\tSET from_date='{$item_data['to_date']}', to_date='{$item_data['expected']}', expected=NULL \r\n\t\t\t\t\tWHERE id='{$item_data['id']}'";
                db_exec($sql) or errDie("Unable to update invoice.");
            }
        }
    }
    // Retrieve the actual invoice
    $sql = "SELECT * FROM hire.hire_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
    $inv_rslt = db_exec($sql) or errDie("Unable to get invoice information");
    $inv_data = pg_fetch_array($inv_rslt);
    if ($cusnum == 0) {
        $cusnum = $inv_data["cusnum"];
    }
    if (empty($cordno)) {
        $cordno = $inv_data["cordno"];
    }
    $pinv_date = explode("-", $inv_data["odate"]);
    $pinv_year = $pinv_date[0];
    $pinv_month = $pinv_date[1];
    $pinv_day = $pinv_date[2];
    // Create the dropdowns ---------------------------------------------------
    // Retrieve departments
    $sql = "SELECT * FROM exten.departments ORDER BY deptname ASC";
    $dept_rslt = db_exec($sql) or errDie("Unable to retrieve departments.");
    // Create departments dropdown
    $dept_sel = "<select name='deptid' style='width: 100%'>";
    while ($dept_data = pg_fetch_array($dept_rslt)) {
        $dept_sel .= "<option value='{$dept_data['deptid']}'>{$dept_data['deptname']}</option>";
    }
    $dept_sel .= "</select>";
    // Check customer basis
    if ($cusnum > 0) {
        checkCustBasis($cusnum);
    }
    // Retrieve customers
    $sql = "SELECT * FROM cubit.customers ORDER BY surname ASC";
    $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customers.");
    // Create customers dropdown
    if (empty($cusnum)) {
        $cust_sel = "\r\n\t\t\t<select name='cusnum' style='width: 100%' onchange='javascript:document.form.submit()'>\r\n\t\t\t\t<option value='0'>[None]</option>";
        while ($cust_data = pg_fetch_array($cust_rslt)) {
            $sel = fsel(isset($cusnum) && $cusnum == $cust_data["cusnum"]);
            $cust_sel .= "<option value='{$cust_data['cusnum']}' {$sel}>{$cust_data['surname']}</option>";
        }
        $cust_sel .= "</select>";
    } else {
        $sql = "SELECT * FROM cubit.customers WHERE cusnum='{$cusnum}'";
        $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customer.");
        $cust_data = pg_fetch_array($cust_rslt);
        $cust_sel = $cust_data["surname"];
    }
    // Retrieve sales people
    $sql = "SELECT * FROM exten.salespeople ORDER BY salesp ASC";
    $salesp_rslt = db_exec($sql) or errDie("Unable to retrieve sales people.");
    // Create sales people dropdown
    $salesp_sel = "<select name='salespid' style='width: 100%'>";
    while ($salesp_data = pg_fetch_array($salesp_rslt)) {
        $salesp_sel .= "<option value='{$salesp_data['salespid']}'>{$salesp_data['salesp']}</option>";
    }
    $salesp_sel .= "</select>";
    // Deposit Options
    $deposit_list = array("CSH" => "Cash", "CHQ" => "Cheque", "CRD" => "Credit Card");
    // Create the deposit dropdown
    $deposit_sel = "<select name='deposit_type'>";
    foreach ($deposit_list as $key => $value) {
        if ($inv_data["deposit_type"] == $key) {
            $sel = "selected";
        } else {
            $sel = "";
        }
        $deposit_sel .= "<option value='{$key}' {$sel}>{$value}</option>";
    }
    $deposit_sel .= "</select>";
    // Items Display -------------------------------------------------------
    $basis_list = array("per_day" => "Per Day", "per_hour" => "Per Hour", "per_week" => "Per Week");
    // Retrieve items
    $sql = "SELECT * FROM hire.hire_invitems WHERE invid='{$invid}' ORDER BY id ASC";
    $items_rslt = db_exec($sql) or errDie("Unable to retrieve items.");
    $items_out = "";
    $temp_assets = array();
    while ($items_data = pg_fetch_array($items_rslt)) {
        $i = $items_data["id"];
        // Create the basis display
        $basis_disp = $basis_list[$items_data["basis"]];
        // Retrieve assets
        $sql = "SELECT * FROM cubit.assets WHERE id='{$items_data['asset_id']}'";
        $asset_rslt = db_exec($sql) or errDie("Unable to retrieve assets.");
        $ad = pg_fetch_array($asset_rslt);
        // Retrieve asset group
        $sql = "SELECT * FROM cubit.assetgrp WHERE grpid='{$ad['grpid']}'";
        $agrp_rslt = db_exec($sql) or errDie("Unable to retrieve asset group.");
        $agrp_data = pg_fetch_array($agrp_rslt);
        if ($agrp_data["grpname"] == "Temporary Asset") {
            $temp_assets[] = $agrp_data[$ad["id"]];
        }
        // 		if ($ad["serial"] == "CUBIT::-QTY-") {
        // 			$asset_disp = "$ad[des]";
        // 		} else {
        // 			$asset_disp = "$ad[des] ($ad[serial])";
        // 		}
        $asset_disp = $ad["des"] . " " . getSerial($ad["id"], 1);
        $subtot += $items_data["amt"];
        //*$items_data["qty"];
        if ($items_data["basis"] == "per_hour") {
            $from_disp = "Hours: {$items_data['hours']}";
            $to_disp = "";
        } else {
            if ($items_data["basis"] == "per_day") {
                $mfrm_date = $items_data["from_date"];
                $mfrm_date = explode("-", $mfrm_date);
                $mfrm_year[$i] = $mfrm_date[0];
                $mfrm_month[$i] = $mfrm_date[1];
                $mfrm_day[$i] = $mfrm_date[2];
                $mto_date = $items_data["to_date"];
                $mto_date = explode("-", $mto_date);
                $mto_year[$i] = $mto_date[0];
                $mto_month[$i] = $mto_date[1];
                $mto_day[$i] = $mto_date[2];
                $from_disp = mkDateSelectA("mfrm", $i, $mfrm_year[$i], $mfrm_month[$i], $mfrm_day[$i]);
                $to_disp = mkDateSelectA("mto", $i, $mto_year[$i], $mto_month[$i], $mto_day[$i]);
                // 				$from_disp = "
                // 				<input type='hidden' name='mfrm_year[$i]' value='$mfrm_year[$i]' />
                // 				<input type='hidden' name='mfrm_month[$i]' value='$mfrm_month[$i]' />
                // 				<input type='hidden' name='mfrm_day[$i]' value='$mfrm_day[$i]' />
                // 				$mfrm_day[$i]-$mfrm_month[$i]-$mfrm_year[$i]";
                // 				$to_disp = "
                // 				<input type='hidden' name='mto_year[$i]' value='$mto_year[$i]' />
                // 				<input type='hidden' name='mto_month[$i]' value='$mto_month[$i]' />
                // 				<input type='hidden' name='mto_day[$i]' value='$mto_day[$i]' />
                // 				$mto_day[$i]-$mto_month[$i]-$mto_year[$i]";
                $from_date[$i] = "{$mfrm_year[$i]}-{$mfrm_month[$i]}-{$mfrm_day[$i]}";
                $to_date[$i] = "{$mto_year[$i]}-{$mto_month[$i]}-{$mto_day[$i]}";
                $hidden_date = "\r\n\t\t\t\t\t<input type='hidden' name='from_date[{$i}]' value='{$from_date[$i]}' />\r\n\t\t\t\t\t<input type='hidden' name='to_date[{$i}]' value='{$to_date[$i]}' />";
                // 				$from_disp = "$items_data[from_date]";
                // 				$to_disp = "$items_data[to_date]";
            } else {
                if ($items_data["basis"] == "per_week") {
                    $from_disp = "Weeks: {$items_data['weeks']}";
                    $to_disp = "";
                }
            }
        }
        if (!isset($return[$i])) {
            $return[$i] = "";
        }
        if (!isset($hidden_date)) {
            $hidden_date = "";
        }
        if (!isset($rain_days[$i])) {
            $rain_days[$i] = 0;
        }
        if ($items_data["basis"] == "per_day") {
            $rd_disp = "<input type='hidden' name='rain_days[{$i}]' \t\t\t\r\n\t\t\t\t\t\tvalue='{$rain_days[$i]}' size='3' style='text align: center' />";
            if ($items_data["half_day"]) {
                //				$hd_disp = "<input type='checkbox' name='half_day[$i]' value='1' checked /> Half Day</b>";
                $hd_disp = "<input type='hidden' name='half_day[{$i}]' value='1' />";
            } else {
                $hd_disp = "<input type='hidden' name='half_day[{$i}]' value='0' />";
                //				$hd_disp = "<input type='checkbox' name='half_day[$i]' value='1' /> Half Day";
            }
        } else {
            $hd_disp = "";
            $rd_disp = "<input type='hidden' name='rain_days[{$i}]' value='0' />";
        }
        if ($items_data["weekends"]) {
            $weekends[$i] = "checked";
        } else {
            $weekends[$i] = "";
        }
        // Items should not be removed once processed, use reprint to check
        // if this hire note has already been processed.
        if (isset($reprint) && $reprint || !empty($monthly)) {
            $rem_cbox = "";
        } else {
            $rem_cbox = "<td><input type='checkbox' name='remove[{$i}]'></td>";
        }
        if (isset($monthly) && $monthly) {
            if ($items_data["basis"] == "per_day") {
                $ret_cbox = "<td><input type='checkbox' name='return[{$i}]' value='checked' {$return[$i]}></td>";
            } else {
                $ret_cbox = "<td>&nbsp;</td>";
            }
        } else {
            $ret_cbox = "<td><input type='checkbox' name='return[{$i}]' value='checked' {$return[$i]}></td>";
        }
        $amt = sprint($items_data["amt"]);
        if (user_is_admin(USER_ID)) {
            $amount_out = "<input type='text' name='amount[{$i}]' value='{$amt}' size='7' />";
        } else {
            $amount_out = "<input type='hidden' name='amount[{$i}]' value='{$amt}' />{$amt}";
        }
        $items_out .= "\r\n\t\t\t<input type='hidden' name='asset_id[{$i}]' value='{$ad['id']}' />\r\n\t\t\t<input type='hidden' name='basis[{$i}]' value='{$items_data['basis']}' />\r\n\t\t\t<input type='hidden' name='qty[{$i}]' value='{$items_data['qty']}' />\r\n\t\t\t{$hidden_date}\r\n\t\t\t{$rd_disp}\r\n\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t<td>{$basis_disp}</td>\r\n\t\t\t\t<td>{$asset_disp}</td>\r\n\t\t\t\t<td align='center'>{$items_data['qty']}</td>\r\n\t\t\t\t<td align='center'>{$from_disp}</td>\r\n\t\t\t\t<td align='center'>{$to_disp} {$hd_disp}</td>\r\n\t<!--\t\t\t\r\n\t\t\t\t<td align='center'>{$rd_disp}</td>\r\n\t\t\t\t<td align='center'>{$items_data['collection']}</td>\r\n\t-->\r\n\t\t\t\t<td>{$amount_out}</td>\r\n\t\t\t\t{$rem_cbox}\r\n\t\t\t\t{$ret_cbox}\r\n\t\t\t</tr>";
    }
    $temp_assets = implode(",", $temp_assets);
    // New Items --------------------------------------------------------------
    // Avoid undefined variable items_out
    if (empty($items_out)) {
        $items_out = "";
    }
    // Buttons
    if (!empty($cusnum)) {
        if ($deposit_type == "CSH" && $deposit_amt != "0.00") {
            $deposit_open = "popupOpen(\"hire-invoice-print.php?key=cash_receipt&invid={$inv_data['invid']}\")";
        } else {
            $deposit_open = "";
        }
        $sql = "SELECT * FROM cubit.customers WHERE cusnum='{$cusnum}'";
        $cust_rslt = db_exec($sql) or errDie("Unable to retrieve customers.");
        $cust_data = pg_fetch_array($cust_rslt);
        $telno = $cust_data["bustel"];
        $return_btn = "<input type='submit' name='upBtn' value='Return' />";
        if (isset($reprint) && $reprint) {
            $new_btn = "<input type='button' value='Reprint' onclick='javascript:printer(\"hire/hire_note_reprint.php?invid={$inv_data['invid']}\");{$deposit_open}'>";
            $purch_btn = "";
            //$purch_btn = "<input type='button' value='Payment' onclick='javascript:popupOpen(\"".SELF."?key=newpos&cusnum=$cusnum\");' />";
        } else {
            if (!$monthly) {
                $new_btn = "<input name='hirenewBtn' type='submit' value='Process' />";
            } else {
                $new_btn = "<input type='submit' name='upBtn' value='Invoice' />";
            }
            $purch_btn = "";
        }
        $hire_buttons = "\r\n\t\t\t<tr>\r\n\t\t\t\t<td>&nbsp;</td>\r\n\t\t\t\t<td align='center'>\r\n\t\t\t\t\t<input type='submit' name='upBtn' value='Update'>\r\n\t\t\t\t\t{$new_btn}\r\n\t\t\t\t\t{$return_btn}\r\n\t\t\t\t\t{$purch_btn}\r\n\t\t\t\t\t<!--<input type='button' value='Swap Hire' />-->\r\n\t\t\t\t</td>\r\n\t\t\t\t<td>&nbsp;</td>\r\n\t\t\t</tr>";
        $basevis = "visible";
        $credit_limit = CUR . sprint($cust_data["credlimit"] - $cust_data["balance"]);
        $cust_balance = CUR . $cust_data["balance"];
    } else {
        $hire_buttons = "";
        $basevis = "hidden";
        $credit_limit = "";
        $cust_balance = "";
    }
    // Retrieve assets
    $sql = "SELECT *  FROM cubit.assets ORDER BY des ASC";
    $nasset_rslt = db_exec($sql) or errDie("Unable to retrieve asset.");
    // Assets dropdown
    $nasset_sel = "\r\n\t\t<select name='nasset_id' style='visibility: {$basevis}; width: 120px' onchange='assetChange(this);'>\r\n\t\t\t<option value='0'>- SELECT PLANT -</option>";
    while ($ad = pg_fetch_array($nasset_rslt)) {
        $sql = "SELECT * FROM hire.hire_invitems WHERE asset_id='{$ad['id']}' AND invid='{$invid}'";
        $invitem_rslt = db_exec($sql) or errDie("Unable to retrieve items.");
        if (pg_num_rows($invitem_rslt)) {
            continue;
        }
        if (!empty($ad["remaction"])) {
            continue;
        }
        if (isHired($ad["id"], date("Y-m-d"))) {
            continue;
        }
        if (!isSerialized($ad["id"])) {
            $at = "q";
            //$asset_disp = "$ad[des] ($ad[serial2] available.)";
            $units_avail = unitsAvailable($ad["id"], date("Y-m-d"));
            $asset_disp = "{$ad['des']} {$units_avail} available.";
            if ($ad["serial2"] <= 0) {
                continue;
            }
        } else {
            $at = "s";
            $asset_disp = "{$ad['des']} ({$ad['serial']})";
        }
        if ($cust_bk = isBooked($ad["id"], date("Y-m-d"))) {
            $sql = "SELECT surname FROM cubit.customers WHERE cusnum='{$cust_bk}'";
            $surname_rslt = db_exec($sql) or errDie("Unable to retrieve customer.");
            $surname = pg_fetch_result($surname_rslt, 0);
            if (isSerialized($ad["id"])) {
                $asset_disp .= " Booked: {$surname}";
            } else {
                $units_booked = unitsBooked($ad["id"], date("Y-m-d"));
                $asset_disp .= " {$units_booked} Units Booked";
            }
        }
        if ($bk_asset == $ad["id"]) {
            $sel = "selected='selected'";
        } else {
            $sel = "";
        }
        $nasset_sel .= "<option value='{$at}:{$ad['id']}' {$sel}>{$asset_disp}</option>";
    }
    $nasset_sel .= "</select>";
    // Create basis dropdown
    $nbasis_sel = "\r\n\t\t<select name='nbasis' style='width: 100%; visibility: {$basevis};' onchange='basisChange(this);'>\r\n\t\t\t<option value='0'>- BASIS -</option>";
    foreach ($basis_list as $key => $value) {
        $nbasis_sel .= "<option value='{$key}'>{$value}</option>";
    }
    $nbasis_sel .= "</select>";
    // Create asset group dropdown
    $sql = "SELECT grpid, grpname FROM cubit.assetgrp ORDER BY grpname ASC";
    $grp_rslt = db_exec($sql) or errDie("Unable to retrieve groups.");
    if ($cusnum) {
        $OTS_OPT = onthespot_encode(SELF, "cust_selection", "deptid={$deptid}&cusnum={$cusnum}&invid={$invid}");
        // 		$cust_edit = "
        // 			<td nowrap>
        // 			<a href='javascript: popupSized(\"../cust-edit.php?cusnum=$cusnum&onthespot=$OTS_OPT\", \"edit_cust\", 700, 630);'>
        // 				Edit Customer Details
        // 			</a>
        // 			</td>";
        $cust_edit = "";
    } else {
        $cust_edit = "";
    }
    // Retrieve service date
    $sql = "SELECT * FROM hire.hire_invitems WHERE invid='{$invid}'";
    $invi_rslt = db_exec($sql) or errDie("Unable to retrieve item.");
    $sv_warn = "";
    while ($invi_data = pg_fetch_array($invi_rslt)) {
        $sql = "SELECT * FROM cubit.asset_svdates WHERE svdate<=CURRENT_DATE AND asset_id='{$invi_data['asset_id']}'";
        $sv_rslt = db_exec($sql) or errDie("Unable to retrieve service date.");
        $sv_data = pg_fetch_array($sv_rslt);
        // Retrieve asset
        if (pg_num_rows($sv_rslt)) {
            $sql = "SELECT * FROM cubit.assets WHERE id='{$sv_data['asset_id']}'";
            $asset_rslt = db_exec($sql) or errDie("Unable to retrieve asset.");
            $asset_data = pg_fetch_array($asset_rslt);
            $sv_warn .= "<li class='err'><b>SERVICING</b>: " . getSerial($asset_data["id"], 1) . "\r\n\t\t\t{$asset_data['des']} has a service date on {$sv_data['svdate']}.</li>";
        }
        if ($days = checkServicing($invi_data["asset_id"], 1)) {
            $sv_warn .= "<li class='err'><b>SERVICING</b>: {$asset_data['des']} needs servicing.</li>";
        }
    }
    // Check if we should use the default comments
    if (empty($inv_data["comm"])) {
        $sql = "SELECT value FROM cubit.settings WHERE constant='HIRE_COMMENTS'";
        $comment_rslt = db_exec($sql) or errDie("Unable to retrieve comments.");
        $inv_data["comm"] = pg_fetch_result($comment_rslt, 0);
    }
    // Site address
    $addr_sel = "";
    if ($cusnum) {
        // Retrieve branch address
        $sql = "SELECT branch_addr FROM hire.hire_invoices WHERE invid='{$invid}'";
        $addr_rslt = db_exec($sql) or errDie("Unable to retrieve branch address.");
        $branch_addr = pg_fetch_result($addr_rslt, 0);
        $sql = "SELECT id, branch_name FROM cubit.customer_branches WHERE cusnum='{$cusnum}'";
        $bran_rslt = db_exec($sql) or errDie("Unable to retrieve customer branch.");
        $addr_sel = "<select name='branch_addr' style='width: 100%' onchange='javascript:document.form.submit()'>";
        $addr_sel .= "<option value='0'>Physical Address</option>";
        while ($bran_data = pg_fetch_array($bran_rslt)) {
            if ($branch_addr == $bran_data["id"]) {
                $sel = "selected='selected'";
            } else {
                $sel = "";
            }
            $addr_sel .= "<option value='{$bran_data['id']}' {$sel}>{$bran_data['branch_name']}</option>";
        }
        $addr_sel .= "</select>";
        $addr_sel .= "<br />" . branchAddress($branch_addr, $cusnum);
    }
    $booked_items = getBookedItems($cusnum, date("Y-m-d"));
    foreach ($booked_items as $asset_id => $units_booked) {
        $sql = "SELECT des FROM cubit.assets WHERE id='{$asset_id}'";
        $bkdes_rslt = db_exec($sql) or errDie("Unable to retrieve bookings.");
        $bkdes = pg_fetch_result($bkdes_rslt, 0);
        $sv_warn .= "<li class='err'><b>BOOKING</b>: {$units_booked}x " . getSerial($asset_id, 1) . " {$bkdes} booked for this customer.</li>";
    }
    if ($monthly) {
        $ret_out = "Invoice";
    } else {
        $ret_out = "Return";
    }
    // Items should not be removed once processed, use reprint to check
    // if this hire note has already been processed or if its monthly.
    if (isset($reprint) && $reprint || !empty($monthly)) {
        $rem_th = "";
        $rem_nbsp = "";
    } else {
        $rem_th = "<th>Remove</th>";
        $rem_nbsp = "<td>&nbsp;</td>";
    }
    // Use the customer trad discount on default
    $sql = "SELECT traddisc FROM cubit.customers WHERE cusnum='{$cusnum}'";
    $cust_rslt = db_exec($sql) or errDie("Unable to retrieve discount.");
    $trade_discount = pg_fetch_result($cust_rslt, 0);
    // Determine if we got any items, if we do, we don't need to go for the
    // default value anymore, because the customer is already selected.
    $sql = "SELECT count(id) FROM hire.hire_invitems WHERE invid='{$invid}'";
    $count_rslt = db_exec($sql) or errDie("Unable to retrieve items.");
    $count = pg_fetch_result($count_rslt, 0);
    if ($count) {
        $trade_discount = $inv_data["traddisc"];
    }
    if (isset($bk_id) && $bk_id && !isset($bk_done)) {
        $sql = "\r\n\t\t\tSELECT serial FROM hire.bookings\r\n\t\t\t\tLEFT JOIN cubit.assets ON bookings.asset_id=assets.id\r\n\t\t\tWHERE bookings.id='{$bk_id}'";
        $bk_rslt = db_exec($sql) or errDie("Unable to retrieve booking.");
        $serialized = pg_fetch_result($bk_rslt, 0);
        if ($serialized == "Not Serialized") {
            $qty_disabled = "";
        } else {
            $qty_disabled = "disabled='t'";
        }
    } else {
        $qty_disabled = "disabled='t'";
    }
    // New Items
    $new_items_out = "\r\n\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t<td>{$nbasis_sel}</td>\r\n\t\t\t<td>{$nasset_sel}</td>\r\n\t\t\t<td align='center'>\r\n\t\t\t\t<input type='text' id='nqty' name='nqty' value='' size='3' class='clear' {$qty_disabled} style='text-align:center' />\r\n\t\t\t</td>\r\n\t\t\t<td align='left' nowrap='t'>\r\n\t\t\t\t<div id='d_wks' style='height: 0px; visibility: hidden;'>\r\n\t\t\t\t\tWeeks: <input type='text' name='weeks' size='5' style='text-align: center;' />\r\n\t\t\t\t</div>\r\n\t\t\t\t<div id='d_hrs' style='height: 0px; visibility: hidden;'>\r\n\t\t\t\t\tHours: <input type='text' name='hours' size='5'\r\n\t\t\t\t\t\tstyle='text-align: center;' />\r\n\t\t\t\t</div>\r\n\t\t\t\t<div id='d_fdate' style='visibility: hidden;'>\r\n\t\t\t\t\t" . mkDateSelect("nhifrm", $nhifrm_year, $nhifrm_month, $nhifrm_day) . "\r\n\t\t\t\t</div>\r\n\t\t\t</td>\r\n\t\t\t<td align='left' nowrap='t'>\r\n\t\t\t\t<div id='d_tdate' style='visibility: hidden;'>\r\n\t\t\t\t\t" . mkDateSelect("nhito", $nhito_year, $nhito_month, $nhito_day) . "\r\n\t<!--\t\t\t\t\r\n\t\t\t\t\t<input type='checkbox' name='nhalf_day' value='checked' />\r\n\t\t\t\t\tHalf Day\r\n\t-->\t\t\t\r\n\t\t\t\t</div>\r\n\t\t\t</td>\r\n\t\t\t<td>&nbsp;</td>\r\n\t\t\t{$rem_nbsp}\r\n\t\t\t<td>&nbsp;</td>\r\n\t\t</tr>";
    /* -- Final Layout -- */
    $details = "\r\n\t\t<script>\r\n\t\t\tfunction basisChange(o) {\r\n\t\t\t\thrs = getObject('d_hrs');\r\n\t\t\t\tfd = getObject('d_fdate');\r\n\t\t\t\ttd = getObject('d_tdate');\r\n\t\t\t\twks = getObject('d_wks');\r\n\r\n\t\t\t\tswitch (o.value) {\r\n\t\t\t\t\tcase 'per_hour':\r\n\t\t\t\t\t\thrs.style.visibility = 'visible';\r\n\t\t\t\t\t\tfd.style.visibility = 'hidden';\r\n\t\t\t\t\t\ttd.style.visibility = 'hidden';\r\n\t\t\t\t\t\twks.style.visibility = 'hidden';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'per_day':\r\n\t\t\t\t\t\thrs.style.visibility = 'hidden';\r\n\t\t\t\t\t\tfd.style.visibility = 'visible';\r\n\t\t\t\t\t\ttd.style.visibility = 'visible';\r\n\t\t\t\t\t\twks.style.visibility = 'hidden';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 'per_week':\r\n\t\t\t\t\t\thrs.style.visibility = 'hidden';\r\n\t\t\t\t\t\tfd.style.visibility = 'hidden';\r\n\t\t\t\t\t\ttd.style.visibility = 'hidden';\r\n\t\t\t\t\t\twks.style.visibility = 'visible';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\thrs.style.visibility = 'hidden';\r\n\t\t\t\t\t\tfd.style.visibility = 'hidden';\r\n\t\t\t\t\t\ttd.style.visibility = 'hidden';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tfunction assetChange(o) {\r\n\t\t\t\tqo = getObject('nqty');\r\n\r\n\t\t\t\tswitch(o.value.substr(0, 1)) {\r\n\t\t\t\t\tcase 'q':\r\n\t\t\t\t\t\tqo.value = '';\r\n\t\t\t\t\t\tqo.disabled = false;\r\n\t\t\t\t\t\tqo.className = 'std';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 's':\r\n\t\t\t\t\t\tqo.value = '1';\r\n\t\t\t\t\t\tqo.disabled = true;\r\n\t\t\t\t\t\tqo.className = 'clear';\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tqo.value = '';\r\n\t\t\t\t\t\tqo.disabled = true;\r\n\t\t\t\t\t\tqo.className = 'clear'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t</script>\r\n\t\t<style>\r\n\t\t\ttd, input, textarea, select { font-size: .75em; }\r\n\t\t</style>\r\n\t\t<center>\r\n\t\t<form method='POST' name='formName'>\r\n\t\t\t<input type='hidden' name='key' value='update'>\r\n\t\t</form>\r\n\t\t<form action='" . SELF . "' method='POST' name='form'>\r\n\t\t\t<input type='hidden' name='collection' value='{$collection}' />\r\n\t\t\t<input type='hidden' name='key' value='update'>\r\n\t\t\t<input type='hidden' name='invid' value='{$invid}' />\r\n\t\t\t<input type='hidden' name='temp_assets' value='{$temp_assets}' />\r\n\t\t\t<input type='hidden' name='monthly' value='{$monthly}' />\r\n\t\t\t<input type='hidden' name='cusnum' value='{$cusnum}' />\r\n\t\t\t<input type='hidden' name='chrgvat' value='no' />\r\n\t\t\t<input type='hidden' name='bk_id' value='{$bk_id}' />\r\n\t\t\t<input type='hidden' name='bk_done' value='1' />\r\n\t\t\t<input type='hidden' name='reprint' value='{$reprint}' />\r\n\t\t<table " . TMPL_tblDflts . " width='100%'>\r\n\t\t \t<tr>\r\n\t\t \t\t<td colspan='3' align='center'><h3>New Hire</h3></td>\r\n\t\t \t</tr>\r\n\t\t \t<tr>\r\n\t\t \t\t<td valign='top'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'> Customer Details </th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Department</td>\r\n\t\t\t\t\t\t\t<td valign='center'>{$dept_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Customer</td>\r\n\t\t\t\t\t\t\t<td valign='center'>{$cust_sel}</td>\r\n\t\t\t\t\t\t\t{$cust_edit}\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Customer Telephone Number</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='20' name='telno' value='{$telno}'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Customer Order number</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='10' name='cordno' value='{$cordno}'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Available Credit</td>\r\n\t\t\t\t\t\t\t<td>{$credit_limit}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Balance</td>\r\n\t\t\t\t\t\t\t<td>{$cust_balance}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Customer Address</td>\r\n\t\t\t\t\t\t\t<td>{$addr_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t<!--\r\n\t\t\t\t\t\t<tr><th colspan='2'>Point of Hire</th></tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Barcode</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='text' size='13' name='bar' value=''>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td nowrap='t'>Search for description</td>\r\n\t\t\t\t\t\t\t<td><input type='text' size='13' name='des' value='{$des}'></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td colspan='2' align='center'>\r\n\t\t\t\t\t\t\t\t<input type='submit' value='Search'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Collection Method</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='checkbox' name='client_collect' value='checked' {$client_collect} />\r\n\t\t\t\t\t\t\t\tClient Collect\r\n\t\t\t\t\t\t\t\t<br />\r\n\t\t\t\t\t\t\t\t<input type='checkbox' name='deliver' value='checked' {$deliver} />\r\n\t\t\t\t\t\t\t\tTo be Delivered\r\n\t\t\t\t\t\t\t\t<br />\r\n\t\t\t\t\t\t\t\t<input type='checkbox' name='collect' value='checked' {$collect} />\r\n\t\t\t\t\t\t\t\tTo be Collected\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t-->\r\n\t\t\t\t\t</table>\r\n\t\t\t\t<td valign='top' align='center' style='width: 100%;'>\r\n\t\t\t\t\t<img src='../compinfo/getimg.php' style='border: 1px solid #000' width='230' height='47' />\r\n\t\t\t\t</td>\r\n\t\t\t\t</td>\r\n\t\t\t\t<td valign='top' align='right'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan=2>Hire Details</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Hire No.</td>\r\n\t\t\t\t\t\t\t<td valign='center'>H{$inv_data['invnum']}" . rev($inv_data["invid"]) . "</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Sales Order No.</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='5' name='ordno' value='{$inv_data['ordno']}'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Hire Date</td>\r\n\t\t\t\t\t\t\t<td valign='center' nowrap='t'>\r\n\t\t\t\t\t\t\t\t" . mkDateSelect("pinv", $pinv_year, $pinv_month, $pinv_day) . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Sales Person</td>\r\n\t\t\t\t\t\t\t<td>{$salesp_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Trade Discount</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='5' name='traddisc'\r\n\t\t\t\t\t\t\t\tvalue='{$trade_discount}'>%\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td nowrap='t'>Delivery Charge</td>\r\n\t\t\t\t\t\t\t<td valign='center'>\r\n\t\t\t\t\t\t\t\t<input type='text' size='7' name='delchrg'\r\n\t\t\t\t\t\t\t\tvalue='{$inv_data['delchrg']}'>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'>Payment Details </th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>User</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='hidden' name='user' value='" . USER_NAME . "'>\r\n\t\t\t\t\t\t\t\t" . USER_NAME . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Deposit Type</td>\r\n\t\t\t\t\t\t\t<td>{$deposit_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Deposit Amount</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='text' name='deposit_amt'\r\n\t\t\t\t\t\t\t\tvalue='" . sprint($inv_data["deposit_amt"]) . "' size='7' />\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t\t<tr>\r\n\t\t\t\t<td colspan='3'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'></tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th>Basis</th>\r\n\t\t\t\t\t\t\t<th>Item</th>\r\n\t\t\t\t\t\t\t<th>Qty</th>\r\n\t\t\t\t\t\t\t<th>Hire Date</th>\r\n\t\t\t\t\t\t\t<th>Expected Return</th>\r\n\t\t\t<!--\t\t\t\r\n\t\t\t\t\t\t\t<th>Rain Days</th>\r\n\t\t\t\t\t\t\t<th>Collection</th>\r\n\t\t\t-->\r\n\t\t\t\t\t\t\t<th>Amount</th>\r\n\t\t\t\t\t\t\t{$rem_th}\r\n\t\t\t\t\t\t\t<th>{$ret_out}</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t{$items_out}\r\n\t\t\t\t\t\t{$new_items_out}\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t\t<tr>\r\n\t\t\t\t<td width='70%' valign='top' colspan='2'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td colspan='10'>{$sv_warn}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td rowspan='4' nowrap>" . mkQuickLinks(ql("javascript:popupOpen(\"../customers-new.php\")", "New Customer"), ql("../pos-invoice-new.php", "New POS Invoice"), ql("../nons-invoice-new.php", "New Non-Stock Invoice")) . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t<th>Comments</th>\r\n\t\t\t\t\t\t\t<th>Custom Text</th>\r\n\t\t\t\t\t\t\t<td rowspan='5' valign='top' width=40%>{$error}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td rowspan=4 align=center valign=top>\r\n\t\t\t\t\t\t\t\t<textarea name=comm cols=20 style='height: 100%'>{$inv_data['comm']}</textarea>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t<td rowspan='4' align='center' valign='top'>\r\n\t\t\t\t\t\t\t\t<textarea name='custom_txt' rows='4' cols='60' style='height: 100%'>{$custom_txt}</textarea>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t\t<td colspan='2' align='right' valign='top' width='30%'>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Delivery Charge</td>\r\n\t\t\t\t\t\t\t<td align=right>" . CUR . " {$inv_data['delivery']}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Trade Discount</td>\r\n\t\t\t\t\t\t\t<td align=right>" . CUR . " {$inv_data['discount']}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>SUBTOTAL</td>\r\n\t\t\t\t\t\t\t<td align=right>\r\n\t\t\t\t\t\t\t\t" . CUR . "<input type=hidden name='subtot' value='{$inv_data['subtot']}'>\r\n\t\t\t\t\t\t\t\t" . sprint($inv_data["subtot"]) . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td><b>VAT {$vat14}</b></td>\r\n\t\t\t\t\t\t\t<td align=right>" . CUR . " {$inv_data['vat']}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<th>GRAND TOTAL</th>\r\n\t\t\t\t\t\t\t<td align=right>" . CUR . " {$inv_data['total']}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t{$rounding}\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t{$hire_buttons}\r\n\t\t</table>\r\n\t\t<a name='bottom'>\r\n\t\t</form>\r\n\t\t</center>";
    return $details;
}
Ejemplo n.º 3
0
function customize($_POST)
{
    extract($_POST);
    $fields["naccount"] = "";
    $fields["last_year"] = "checked";
    $fields["budget"] = "checked";
    $fields["month_from"] = (int) date("m");
    $fields["month_to"] = (int) date("m");
    $fields["heading_1"] = COMP_NAME;
    $fields["heading_2"] = date("d/m/Y");
    $fields["heading_3"] = "Trial Balance";
    $fields["heading_4"] = "Prepared by: " . USER_NAME;
    $fields["viewyear"] = "core";
    $fields["zero_balance"] = "";
    $fields["debit_credit"] = "";
    foreach ($fields as $var_name => $value) {
        if (!isset(${$var_name})) {
            ${$var_name} = $value;
        }
    }
    $qry = new dbSelect("year", "core", grp(m("where", "closed='y'"), m("order", "yrname ASC")));
    $qry->run();
    if (PRD_STATE == "py") {
        $curyear = PYR_NAME;
    } else {
        $curyear = YR_NAME;
    }
    $year_sel = "\n\t\t<select name='viewyear'>\n\t\t\t<option value='core'>" . $curyear . " (Current)</option>";
    while ($row = $qry->fetch_array()) {
        $sel = fsel($viewyear == $row["yrdb"]);
        $year_sel .= "<option {$sel} value='{$row['yrdb']}'>{$row['yrname']}</option>";
    }
    $year_sel .= "</select>";
    // Should we display the last year field
    if (substr(YR_DB, 2) - 1 > 0) {
        if (isset($last_year) && $last_year) {
            $ch = "checked='t'";
        } else {
            $ch = "";
        }
        $last_year_out = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Last Year</td>\n\t\t\t\t<td align='center'><input type='checkbox' name='last_year' value='checked' {$ch}></td>\n\t\t\t</tr>";
    } else {
        $last_year_out = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Last Year</td>\n\t\t\t\t<td align='center'>No prior years found.</td>\n\t\t\t</tr>";
    }
    /*$months_from = "<select name='month_from'>";
    	// Retrive month names
    	for ($i = 1; $i <= 12; $i++) {
    		if ($month_from == $i) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    		$months_from .= "<option value='$i' $selected>".getMonthName($i)."</option>";
    	}
    	$months_from .= "</select>";*/
    $months_to = finMonList("month_to", $month_to, true);
    /*// Retrieve list of accounts for the dropdowns
    	db_conn("core");
    	$sql = "SELECT * FROM trial_bal WHERE div='".USER_DIV."' ORDER BY topacc, accnum ASC";
    	$tb_rslt = db_exec($sql) or errDie("Unable to retrieve trial balance accounts from Cubit.");
    
    	$accounts = array();
    	while ($tb_data = pg_fetch_array($tb_rslt)) {
    		$accounts[$tb_data["accid"]] = "$tb_data[topacc]/$tb_data[accnum] $tb_data[accname]";
    	}
    
    	$naccount_out = "
    	<tr class='bg-odd'>
    		<td align=center><select name=naccount style='width: 240px'>
    		<option value='0'>Please select</option>";
    
    	foreach ($accounts as $accid=>$value) {
    		if ($naccount == $accid) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    
    		$naccount_out .= "<option value='$accid' $selected>$value</option>";
    	}
    
    	$naccount_out .= "</select></td>
    		<td><input type=submit name='key' value='Add'></td>
    	</tr>";*/
    // Retrieved the saved trial balance layout from Cubit
    db_conn("cubit");
    $sql = "SELECT * FROM saved_tb_accounts";
    $stbacc_rslt = db_exec($sql) or errDie("Unable to retrieve saved trial balance accounts from Cubit.");
    if (pg_num_rows($stbacc_rslt) == 0) {
        $accounts_out = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>No accounts have been selected, ALL accounts will be displayed.</td>\n\t\t\t</tr>";
    } else {
        $accounts_out = "";
    }
    $i = 0;
    while ($stbacc_data = pg_fetch_array($stbacc_rslt)) {
        $i++;
        // Was anything in the remove list selected
        if (isset($rem[$stbacc_data["id"]])) {
            $checked = "checked";
        } else {
            $checked = "";
        }
        $accounts_out .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$stbacc_data['topacc']}/{$stbacc_data['accnum']}</td>\n\t\t\t\t<td>{$stbacc_data['accname']}</td>\n\t\t\t\t<td><input type='checkbox' name='rem[{$stbacc_data['id']}]' value='{$stbacc_data['id']}' {$checked}></td>\n\t\t\t\t<td><a href='#' onclick='popupSized(\"" . SELF . "?key=note_view&accid={$stbacc_data['accid']}\", 'note{$stbacc_data['accid']}', 480, 800, '');'>Note</a></td>\n\t\t\t</tr>";
    }
    // Layout
    $OUTPUT = "\n\t\t<h3>Trial Balance</h3>\n\t\t<form method='POST' action='" . SELF . "'>\n\t\t\t<input type='hidden' name='key' value='display'>\n\t\t\t<input type='hidden' name='acc_view' value='sel'>\n\t\t\t<input type='hidden' name='customized' value='true'>\n\t\t<table border='0' cellpadding='0' cellspacing='0'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'><h3>Customise</h3></th>\n\t\t\t</tr>\n\t\t\t<tr><td valign=top>\n\t\t\t<table " . TMPL_tblDflts . " style='width: 300px; margin: 0px;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Display</th>\n\t\t\t\t</tr>\n\t\t\t\t{$last_year_out}\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Annual Budget</td>\n\t\t\t\t\t<td align=center><input type=checkbox name=budget value='checked' {$budget}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Zero Balances</td>\n\t\t\t\t\t<td align='center'><input type='checkbox' name='zero_balance' value='checked' {$zero_balance}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>List Debit & Credit</td>\n\t\t\t\t\t<td align='center'><input type='checkbox' name='debit_credit' {$debit_credit}></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Year</td>\n\t\t\t\t\t<td align='center'>{$year_sel}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Month</td>\n\t\t\t\t\t<td align=center nowrap>{$months_to}</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<!--<table " . TMPL_tblDflts . " style='width: 300px; margin: 0px;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Add Account</th>\n\t\t\t\t</tr>\n\t\t\t\t\$naccount_out\n\t\t\t</table>//-->\n\t\t\t<table " . TMPL_tblDflts . " style='width: 300px; margin: 0px;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Headings</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Heading 1</td>\n\t\t\t\t\t<td><input type='text' name='heading_1' value='{$heading_1}' style='width: 100%'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Heading 2</td>\n\t\t\t\t\t<td><input type='text' name='heading_2' value='{$heading_2}' style='width: 100%'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Heading 3</td>\n\t\t\t\t\t<td><input type='text' name='heading_3' value='{$heading_3}' style='width: 100%'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td width='0%'>Heading 4</td>\n\t\t\t\t\t<td><input type='text' name='heading_4' value='{$heading_4}' style='width: 100%'></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='3'><input type='submit' value='Display &raquo' style='width:100%; font-weight: bold;'></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</td><td valign=top>\n\t\t\t<!--<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='4'>Accounts</th>\n\t\t\t\t</tr>\n\t\t\t\t{$accounts_out}\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='4' align='center'><input type='submit' name='key' value='Remove Selected'></td>\n\t\t\t\t</tr>\n\t\t\t</table>//-->\n\t\t</table>\n\t\t</form>";
    return $OUTPUT;
}
function method($_POST, $ex = "")
{
    extract($_POST);
    // customers Drop down selections
    db_connect();
    $cust = "<select name='cusid'>";
    $sql = "SELECT cusnum,cusname,surname FROM customers WHERE div = '" . USER_DIV . "' ORDER BY surname,cusname";
    $cusRslt = db_exec($sql) or errDie("Unable to get customers information.");
    $numrows = pg_numrows($cusRslt);
    if (empty($numrows)) {
        return "<li class='err'> There are no Debtors in Cubit.</li>" . mkQuickLinks(ql("trans-new.php", "Journal Transactions"), ql("../customers-view.php", "View Customers"));
    }
    if (!isset($rec_amount)) {
        $rec_amount = 1;
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($rec_amount, "num", 1, 10, "Invalid amount of receipt.");
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    $jump_bot = "";
    if (isset($another)) {
        $jump_bot = "\n\t\t\t<script>\n\t\t\t\twindow.location.hash='bottom';\n\t\t\t</script>";
        $rec_amount++;
    }
    if (isset($_GET["e"])) {
        $ex = "<input type='hidden' name='e' value='y'>";
    } else {
        $ex = "";
    }
    $listing = "";
    for ($i = 0; $i < $rec_amount; $i++) {
        #here we will make the entries ...
        ##################[ check the vars ]#####################
        if (!isset($cusid[$i])) {
            $bankid[$i] = "0";
            $descript[$i] = "";
            $cheqnum[$i] = "";
            $amt[$i] = "";
            $setamt[$i] = "";
            $setvat[$i] = "";
            $setvatcode = "";
            $reference[$i] = "";
            $setvat[$i] = "";
            $setvatcode[$i] = "";
        }
        if (!isset($date_day[$i])) {
            $trans_date_setting = getCSetting("USE_TRANSACTION_DATE");
            if (isset($trans_date_setting) and $trans_date_setting == "yes") {
                $trans_date_value = getCSetting("TRANSACTION_DATE");
                $date_arr = explode("-", $trans_date_value);
                $date_year[$i] = $date_arr[0];
                $date_month[$i] = $date_arr[1];
                $date_day[$i] = $date_arr[2];
            } else {
                if (isset($_SESSION["global_day"]) and strlen($_SESSION["global_day"]) > 0) {
                    $date_day[$i] = $_SESSION["global_day"];
                } else {
                    $date_day[$i] = date("d");
                }
                if (isset($_SESSION["global_month"]) and strlen($_SESSION["global_month"]) > 0) {
                    $date_month[$i] = $_SESSION["global_month"];
                } else {
                    $date_month[$i] = date("m");
                }
                if (isset($_SESSION["global_year"]) and strlen($_SESSION["global_year"]) > 0) {
                    $date_year[$i] = $_SESSION["global_year"];
                } else {
                    $date_year[$i] = date("Y");
                }
            }
        }
        #########################################################
        ##################[ get customer information ]###########
        db_connect();
        $customerdrop = "<select name='cusid[{$i}]'>";
        $sql = "SELECT cusnum,cusname,surname FROM customers WHERE div = '" . USER_DIV . "' ORDER BY surname,cusname";
        $cusRslt = db_exec($sql) or errDie("Unable to get customer information");
        if (pg_numrows($cusRslt) < 1) {
            return "\n\t\t\t\t<li> There are no Customers in Cubit.</li>\n\t\t\t\t<p>\n\t\t\t\t" . mkQuickLinks(ql("trans-new.php", "Journal Transactions"), ql("../customers-view.php", "View Customers"));
        }
        if (!isset($cusid[$i])) {
            $cusid[$i] = 0;
        }
        while ($cus = pg_fetch_array($cusRslt)) {
            if ($cus['cusnum'] == $cusid[$i]) {
                $sel = "selected";
            } else {
                $sel = "";
            }
            $customerdrop .= "<option {$sel} value='{$cus['cusnum']}'>{$cus['cusname']} {$cus['surname']}</option>";
        }
        $customerdrop .= "</select>";
        #########################################################
        ##################[ get Bank accounts ]##################
        $bankaccs = "<select name='bankid[{$i}]'>";
        db_connect();
        $sql = "SELECT * FROM bankacct WHERE btype != 'int' AND div = '" . USER_DIV . "' ORDER BY accname,bankname";
        $banks = db_exec($sql) or errDie("Unable to get bank accounts information.");
        $numrows = pg_numrows($banks);
        if (empty($numrows)) {
            return "\n\t\t\t\t<li class='err'> There are no accounts held at the selected Bank.\n\t\t\t\t<p>\n\t\t\t\t<input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct Selection'>";
        }
        while ($acc = pg_fetch_array($banks)) {
            $sel = fsel($bankid[$i] == $acc["bankid"]);
            $bankaccs .= "<option {$sel} value='{$acc['bankid']}'>{$acc['accname']} - {$acc['bankname']} ({$acc['acctype']})</option>";
        }
        if (isset($_GET['cash'])) {
            $sel = fsel($bankid[$i] == $acc["bankid"]);
            $bankaccs .= "<option {$sel} value='0'>Receive Cash</option>";
        }
        $bankaccs .= "</select>";
        ##########################################################
        $setamt[$i] = sprint($setamt[$i]);
        $get_vatcodes = "SELECT * FROM vatcodes ORDER BY code";
        $run_vatcodes = db_exec($get_vatcodes) or errDie("Unable to get vat code information.");
        if (pg_numrows($run_vatcodes) < 1) {
            $setvatcode_drop = "<input type='hidden' name='setvatcode[{$i}]' value=''>";
        } else {
            $setvatcode_drop = "<select name='setvatcode[{$i}]'>";
            while ($vcarr = pg_fetch_array($run_vatcodes)) {
                if ($setvatcode[$i] == $vcarr['id']) {
                    $setvatcode_drop .= "<option value='{$vcarr['id']}' selected>{$vcarr['code']} {$vcarr['description']}</option>";
                } else {
                    $setvatcode_drop .= "<option value='{$vcarr['id']}'>{$vcarr['code']} {$vcarr['description']}</option>";
                }
            }
            $setvatcode_drop .= "</select>";
        }
        $listing .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$customerdrop}</td>\n\t\t\t\t<td>{$bankaccs}</td>\n\t\t\t\t<td>" . mkDateSelecta("date", $i, $date_year[$i], $date_month[$i], $date_day[$i]) . "</td>\n\t\t\t\t<td><textarea cols='25' rows='2' name='descript[{$i}]'>{$descript[$i]}</textarea></td>\n\t\t\t\t<td><input type='text' name='reference[{$i}]' value='{$reference[$i]}'></td>\n\t\t\t\t<td><input type='text' name='cheqnum[{$i}]' value='{$cheqnum[$i]}'></td>\n\t\t\t\t<td nowrap>" . CUR . " <input type='text' name='amt[{$i}]' size='7' value='{$amt[$i]}'></td>\n\t\t\t\t<td nowrap>" . CUR . " <input type='text' name='setamt[{$i}]' size='7' value='{$setamt[$i]}'></td>\n\t\t\t\t<td nowrap>\n\t\t\t\t\t{$setvatcode_drop} <br>\n\t\t\t\t\t<input type='radio' name='setvat[{$i}]' value='inc' checked='yes'> VAT Inclusive <br>\n\t\t\t\t\t<input type='radio' name='setvat[{$i}]' value='novat'> No VAT\n\t\t\t\t</td>\n\t\t\t</tr>";
    }
    $listing .= "\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td colspan='6' align='right'><b>Total:</b></td>\n\t\t\t<td align='right'>" . CUR . " " . sprint(array_sum($amt)) . "</td>\n\t\t\t<td colspan='2'></td>\n\t\t</tr>";
    #set method option
    if (!isset($all)) {
        $all = "0";
    }
    //	$as1 = "";
    //	$as2 = "";
    //	$as3 = "";
    //	if ($all == 0) {
    //		$as1 = "selected";
    //	} else if($all == 1) {
    //		$as2 = "selected";
    //	} else if ($all == 2) {
    //		$as3 = "selected";
    //	}
    //	$alls = "
    //			<select name='all'>
    //				<option value='0' $as1>Auto</option>
    //				<option value='1' $as2>Allocate To Age Analysis</option>
    //				<option value='2' $as3>Allocate To Each invoice</option>
    //			</select>";
    //		<tr>
    //			<th colspan='2'>Receive Method</th>
    //		</tr>
    //		<tr class='".bg_class()."'>
    //			<td>Allocation</td>
    //			<td>$alls</td>
    //		</tr>
    // layout
    $add = "\n\t\t<h3>New Multiple Receipts</h3>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t{$ex}\n\t\t\t<input type='hidden' name='rec_amount' value='{$rec_amount}'>\n\t\t\t<input type='hidden' name='key' value='alloc'>\n\t\t\t<input type='hidden' name='cusid' value='{$cusid}'>\n\t\t\t<input type='hidden' name='all' value='0'>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<td colspan='9'><li class='err'>NOTE: This functionality will automatically allocate any amount received to the oldest unpaid/partially paid recorded invoice.</li></td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<th colspan='9'>Receipt Details</th>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Customer</th>\n\t\t\t\t<th>Bank Account / Cash</th>\n\t\t\t\t<th>Date</th>\n\t\t\t\t<th>Description</th>\n\t\t\t\t<th>Reference</th>\n\t\t\t\t<th>Cheque Number</th>\n\t\t\t\t<th>Amount</th>\n\t\t\t\t<th>Settlement Amount</th>\n\t\t\t\t<th>Settlement VAT</th>\n\t\t\t</tr>\n\t\t\t{$listing}\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<td><input type='submit' name='another' value='Add Another'></td>\n\t\t\t\t<td valign='center' align='right'><input type='submit' value='Allocate >'></td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t</form>\n\t\t</table>\n\t\t<a name='bottom'>\n\t\t{$jump_bot}" . mkQuickLinks(ql("trans-new.php", "Journal Transactions"), ql("../customers-view.php", "View Customers"));
    return $add;
}
function customize($_POST)
{
    extract($_POST);
    $fields = array();
    $fields["heading_1"] = COMP_NAME;
    $fields["heading_2"] = date("d/m/Y");
    $fields["heading_3"] = "Income Statement";
    $fields["heading_4"] = "Prepared by: " . USER_NAME;
    $fields["viewview"] = "core";
    $fields["month_from"] = (int) date("m");
    $fields["month_to"] = (int) date("m");
    $fields["this_year_this_month"] = true;
    $fields["last_year_same_month"] = true;
    $fields["this_year_year_to_date"] = true;
    $fields["last_year_year_to_date"] = true;
    $fields["budget"] = true;
    $fields["this_year_budget"] = true;
    $fields["zero_balance"] = "";
    $fields["naccount"] = "";
    foreach ($fields as $var_name => $value) {
        if (!isset(${$var_name})) {
            ${$var_name} = $value;
        }
    }
    $qry = new dbSelect("year", "core", grp(m("where", "closed='y'"), m("order", "yrname ASC")));
    $qry->run();
    if (PRD_STATE == "py") {
        $curyear = PYR_NAME;
    } else {
        $curyear = YR_NAME;
    }
    $year_sel = "\n\t<select name='viewyear'>\n\t\t<option value='core'>" . $curyear . " (Current)</option>";
    while ($row = $qry->fetch_array()) {
        $sel = fsel($viewyear == $row["yrdb"]);
        $year_sel .= "<option {$sel} value='{$row['yrdb']}'>{$row['yrname']}</option>";
    }
    $year_sel .= "\n\t</select>";
    /*$months_from = "<select name='month_from'>";
    	// Retrive month names
    	for ($i = 1; $i <= 12; $i++) {
    		if ($month_from == $i) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    		$months_from .= "<option value='$i' $selected>".getMonthName($i)."</option>";
    	}
    	$months_from .= "</select>";*/
    $months_to = finMonList("month_to", $month_to, true);
    // Retrieve list of accounts for the account dropdown
    db_conn("core");
    $sql = "SELECT * FROM accounts WHERE acctype='I' OR acctype='E' ORDER BY accname,topacc ASC";
    $acc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts information from Cubit.");
    /*
    	// Accounts dropdown output
    	$acc_sel = "<select name='naccount' style='width: 200px'>
    		<option value='0'>Please select</option>";
    	while ($acc_data = pg_fetch_array($acc_rslt)) {
    		if ($naccount == $acc_data["accid"]) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    
    		$acc_sel .= "<option value='$acc_data[accid]' $selected>$acc_data[accname]</option>";
    	}
    	$acc_sel .= "</select>";
    
    	// Retrieve saved accounts from Cubit
    	db_conn("cubit");
    	$sql = "SELECT * FROM saved_is_accounts";
    	$sisacc_rslt = db_exec($sql) or errDie("Unable to retrieve saved income statement accounts from Cubit");
    
    	if (!pg_num_rows($sisacc_rslt)) {
    		$accounts_out = "
    		<tr class='bg-odd'>
    			<td>No accounts have been selected, ALL accounts will be displayed</td>
    		</tr>";
    	} else {
    		$accounts_out = "";
    	}
    
    	$i = 0;
    	while ($sisacc_data = pg_fetch_array($sisacc_rslt)) {
    		// Alternate the background colour
    		$i++;
    
    		if (isset($rem[$sisacc_data["id"]])) {
    			$checked = "checked";
    		} else {
    			$checked = "";
    		}
    
    		$accounts_out .= "
    		<tr class='".bg_class()."'>
    			<td>$sisacc_data[accname]</td>
    			<td><input type='checkbox' name='rem[$sisacc_data[id]]' value='$sisacc_data[id]' $checked></td>
    		</tr>";
    	}*/
    $accounts_out = "";
    //------------------------------------------------------------------------
    if (isset($last_year_same_month) && $last_year_same_month) {
        $lysm = "checked";
    } else {
        $lysm = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_year_to_date) && $this_year_year_to_date) {
        $tyytd = "checked";
    } else {
        $tyytd = "";
    }
    //------------------------------------------------------------------------
    if (isset($last_year_year_to_date) && $last_year_year_to_date) {
        $lyytd = "checked";
    } else {
        $lyytd = "";
    }
    //------------------------------------------------------------------------
    if (isset($budget) && $budget) {
        $budget = "checked";
    } else {
        $budget = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_budget) && $this_year_budget) {
        $tybudget = "checked";
    } else {
        $tybudget = "";
    }
    // Layout
    $OUTPUT = "<h3>Income Statement</h3>\n\t<form method='post' action='" . SELF . "'>\n\t<input type='hidden' name='key' value='display' />\n\t<input type='hidden' name='acc_view' value='sel'>\n\t<input type='hidden' name='customized' value='true'>\n\t<table border='0' cellpadding='0' cellspacing='0'>\n\t\t<tr>\n\t\t\t<th colspan=2><h3>Customise<h3></th>\n\t\t</tr>\n\n\t\t<tr><td valign='top'>\n\t\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' style='margin: 0px; width: 300px'>\n\t\t\t<tr>\n\t\t\t\t<th colspan=2>Headings</th>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>Heading 1</td>\n\t\t\t\t<td><input type=text name='heading_1' value='{$heading_1}' style='width: 100%'></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td>Heading 2</td>\n\t\t\t\t<td><input type=text name='heading_2' value='{$heading_2}' style='width: 100%'></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>Heading 3</td>\n\t\t\t\t<td><input type=text name='heading_3' value='{$heading_3}' style='width: 100%'></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td width='0%'>Heading 4</td>\n\t\t\t\t<td><input type=text name='heading_4' value='{$heading_4}' style='width: 100%'></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th colspan=2>Display</th>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>Last Year - Same Month</td>\n\t\t\t\t<td><input type='checkbox' name='last_year_same_month' value='true' {$lysm} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td>This Year - To Month</td>\n\t\t\t\t<td><input type='checkbox' name='this_year_year_to_date' value='true' {$tyytd} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>Last Year - Year To Date</td>\n\t\t\t\t<td><input type='checkbox' name='last_year_year_to_date' value='true' {$lyytd} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td>Month Budget</td>\n\t\t\t\t<td><input type='checkbox' name='budget' value='true' {$budget} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td>This Year Budget To Month</td>\n\t\t\t\t<td><input type='checkbox' name='this_year_budget' value='true' {$tybudget} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-even'>\n\t\t\t\t<td>Zero Balances</td>\n\t\t\t\t<td><input type='checkbox' name='zero_balance' value='checked' {$zero_balance} \\></td>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td colspan='2'>\n\t\t\t\t\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t\t\t\t<tr class='bg-odd'>\n\t\t\t\t\t\t<td>Year</td>\n\t\t\t\t\t\t<td align='center'>{$year_sel}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>Month</td>\n\t\t\t\t\t\t<td nowrap>{$months_to}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' style='margin: 0px; width: 300px'>\n\t\t\t<!--<tr>\n\t\t\t\t<th colspan='2'>Add Account</th>\n\t\t\t</tr>\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td align='center'>\$acc_sel</td>\n\t\t\t\t<td align='center'><input type='submit' name='key' value='Add'></td>\n\t\t\t</tr>//-->\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><input type='submit' value='Display' style='width: 100%; font-weight: bold;'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t</td>\n\n\t\t<!--<td valign='top'>\n\t\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='250px'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'>Accounts</th>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t{$accounts_out}\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td align='center'><input type='submit' name='key' value='Remove Selected'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t</td>//-->\n\t\t</tr>\n\t</table>\n\t</form>";
    return $OUTPUT;
}
function enter($errors = "")
{
    global $_POST;
    extract($_POST);
    require_lib("validate");
    $v = new validate();
    $fields["search_cus"] = "";
    $fields["assetid"] = "";
    $fields["cusnum"] = "";
    $fields["serno"] = "";
    $fields["description"] = "";
    $fields["conditions"] = "";
    $fields["notes"] = "";
    $fields["ex_year"] = date("Y");
    $fields["ex_month"] = date("m");
    $fields["ex_day"] = date("d");
    foreach ($fields as $var_name => $value) {
        if (!isset(${$var_name})) {
            ${$var_name} = $value;
        }
    }
    if (empty($conditions)) {
        // Retrieve the workshop conditions from Cubit.
        db_conn("cubit");
        $sql = "SELECT value FROM workshop_settings WHERE div='" . USER_DIV . "' AND setting='workshop_conditions'";
        $wssRslt = db_exec($sql) or errDie("Unable to retrieve workshop settings from Cubit.");
        $conditions = pg_fetch_result($wssRslt, 0);
    }
    if (isset($notes)) {
        $v->isOk($notes, "string", 1, 1024, "Invalid notes.");
    } else {
        $notes = "";
    }
    // Stock code dropdown
    $stkdn = "\n\t<select name='assetid' style='width:180px'>\n\t  <option value='0'>Please select</th>";
    $sql = "SELECT * FROM cubit.assets WHERE div='" . USER_DIV . "' ORDER BY des ASC";
    $stkRslt = db_exec($sql) or errDie("Unable to retrieve the stock from Cubit.");
    $asset_id = 0;
    while ($stkData = pg_fetch_array($stkRslt)) {
        $selected = fsel($asset_id == $stkData["id"]);
        $stkdn .= "<option value='{$stkData['id']}' {$selected}>{$stkData['des']} ({$stkData['serial']})</option>";
    }
    $stkdn .= "</select>";
    // Customer dropdown
    $cusdn = "<select name='cusnum' style='width:180px'>";
    db_conn("cubit");
    $sql = "SELECT * FROM customers WHERE surname LIKE '%{$search_cus}%' AND div='" . USER_DIV . "' ORDER BY surname ASC";
    $cusRslt = db_exec($sql) or errDie("Unable to retrieve customers from Cubit.");
    if (pg_num_rows($cusRslt) == 0) {
        $cusdn .= "<option value='0'>No customers found</option>";
    }
    while ($cusData = pg_fetch_array($cusRslt)) {
        if ($cusnum == $cusData["cusnum"]) {
            $selected = "selected";
        } else {
            $selected = "";
        }
        $cusdn .= "<option value='{$cusData['cusnum']}' {$selected}>{$cusData['surname']} {$cusData['init']}</option>";
    }
    $cusdn .= "</select>";
    $OUTPUT = "<h3>Add to workshop</h3>\n\t{$errors}\n\t<form method=post action='" . SELF . "' name='frm_ws'>\n\t<input type=hidden name=key value='confirm'>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t  <tr>\n\t    <th colspan=2>Add</th>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>" . REQ . "Customer</td>\n\t    <td>\n\t      <center><input type='button' value='Search' onClick='popupSized(\"customers-view.php?action=select&" . frmupdate_make("text", "frm_ws", "cusnum", "cusnum_only") . "\", \"workshop_custsearch\", 800, 400);'></center><br>\n\t      {$cusdn}\n\t    </td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>" . REQ . " Asset</td>\n\t    <td>{$stkdn}</td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t  \t<td>Expected Date</td>\n\t  \t<td>" . mkDateSelect("ex", $ex_year, $ex_month, $ex_day) . "</td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>" . REQ . "Description</td>\n\t    <td><input type=text name=description value='{$description}' style='width:180px'></td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>" . REQ . "Workshop Conditions</td>\n\t    <td><textarea name=conditions rows=5 style='width:180px'>{$conditions}</textarea></td>\n\t  </tr>\n\t  <tr class='" . bg_class() . "'>\n\t    <td>Notes</td>\n\t    <td><textarea name=notes rows=5 style='width:180px'>{$notes}</textarea></td>\n\t  </tr>\n\t  <tr>\n\t    <td colspan=2 align=right>\n\t      <input type=submit value='Confirm &raquo'>\n\t    </td>\n\t  </tr>\n\t</table>";
    return $OUTPUT;
}
Ejemplo n.º 7
0
function enter($_GET, $errors = "")
{
    extract($_REQUEST);
    extract($_GET);
    //	$fields =
    $id += 0;
    db_connect();
    $Sl = "SELECT * FROM assets WHERE id='{$id}' LIMIT 1";
    $Ri = db_exec($Sl);
    $data = pg_fetch_array($Ri);
    extract($data);
    #process date
    $date_arr = explode("-", $date);
    $date_year = $date_arr[0];
    $date_month = $date_arr[1];
    $date_day = $date_arr[2];
    $qty = $serial2;
    $seryn = "yes";
    if ($nonserial == "1") {
        $seryn = "no";
    }
    $fields = array();
    //	$fields["grpid"] = 0;
    //	$fields["seryn"] = "yes";
    //	$fields["qty"] = "1";
    //	$fields["serial"] = "";
    //	$fields["serial2"] = "";
    //	$fields["locat"] = "";
    //	$fields["des"] = "";
    //	$fields["method"] = "add";
    //	$fields["date_day"] = date("d");
    //	$fields["date_month"] = date("m");
    //	$fields["date_year"] = date("Y");
    //	$fields["amount"] = "0.00";
    //	$fields["dep_perc"] = 0;
    //	$fields["dep_month"] = "no";
    $fields["svdate_day"] = date("d");
    $fields["svdate_month"] = date("m");
    $fields["svdate_year"] = date("Y");
    $fields["sv_desc"] = "";
    $fields["details"] = "";
    //	$fields["type_id"] = 0;
    $fields["units"] = "0";
    extract($fields, EXTR_SKIP);
    if ($dep_month == "yes") {
        $dm_yes = "checked";
        $dm_no = "";
    } else {
        $dm_yes = "";
        $dm_no = "checked";
    }
    if (isset($method) && $method == "purch") {
        $meth_purch = "checked";
        $meth_add = "";
    } else {
        $meth_purch = "";
        $meth_add = "checked";
    }
    db_connect();
    $grps = "<select name='grpid' style='width: 135'>";
    $sql = "SELECT * FROM assetgrp WHERE div = '" . USER_DIV . "' ORDER BY grpname ASC";
    $grpRslt = db_exec($sql);
    if (pg_numrows($grpRslt) < 1) {
        return "\r\n\t\t\t\t<li>There are no Asset Groups in Cubit.</li><br>" . mkQuickLinks(ql("assetgrp-new.php", "Add Asset Group"), ql("assetgrp-view.php", "View Asset Groups"));
    } else {
        while ($grp = pg_fetch_array($grpRslt)) {
            $sel = fsel($grpid == $grp["grpid"]);
            $grps .= "<option {$sel} value='{$grp['grpid']}'>{$grp['grpname']}</option>";
        }
    }
    $grps .= "</select>";
    $sql = "SELECT * FROM cubit.asset_types ORDER BY name ASC";
    $type_rslt = db_exec($sql) or errDie("Unable to retrieve asset type.");
    $type_sel = "<select name='type_id' style='width: 135'>";
    $type_sel .= "<option value='0'>[None]</option>";
    while ($type_data = pg_fetch_array($type_rslt)) {
        $sel = fsel($type_id == $type_data["id"]);
        $type_sel .= "<option value='{$type_data['id']}' {$sel}>{$type_data['name']}</option>";
    }
    $type_sel .= "</select>";
    if ($seryn == "yes") {
        $div_qty_style = "visibility: hidden;";
        $div_serial_style = "";
    } else {
        $div_serial_style = "visibility: hidden;";
        $div_qty_style = "";
    }
    $display_piclist = "";
    $display_iframe = "";
    #check if this cust has any pics ...
    if (isset($id) and strlen($id) > 0) {
        #editing customer ... show frame if we have pics
        $get_pics = "SELECT * FROM display_images WHERE type = 'asset' AND ident_id = '{$id}' LIMIT 1";
        $run_pics = db_exec($get_pics) or errDie("Unable to get customer images information.");
        if (pg_numrows($run_pics) < 1) {
            #no pics for this customer
            $display_iframe = "";
        } else {
            #compile listing for customer
            $get_piclist = "SELECT * FROM display_images WHERE type = 'asset' AND ident_id = '{$id}'";
            $run_piclist = db_exec($get_piclist) or errDie("Unable to get customer images information.");
            if (pg_numrows($run_piclist) < 1) {
                #wth .. pic went missing somewhere ...
                #so nothing
            } else {
                $display_piclist = "\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td colspan='2'>\r\n\t\t\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<th>Picture Name</th>\r\n\t\t\t\t\t\t\t\t\t<th>View</th>\r\n\t\t\t\t\t\t\t\t\t<th>Remove</th>\r\n\t\t\t\t\t\t\t\t</tr>";
                while ($arr = pg_fetch_array($run_piclist)) {
                    $display_piclist .= "\r\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t\t\t<td>{$arr['image_name']}</td>\r\n\t\t\t\t\t\t\t\t\t<td><a target='iframe1' href='view_image.php?picid={$arr['id']}'>View</a></td>\r\n\t\t\t\t\t\t\t\t\t<td><input type='checkbox' name='rempicid[{$arr['id']}]' value='yes'></td>\r\n\t\t\t\t\t\t\t\t</tr>";
                    #at least 1 picture for this customer
                    $display_iframe = "<tr><td colspan='2'><iframe name='iframe1' width='200' height='260' scrolling='false' marginwidth='0' marginheight='0' frameborder='0' src='view_image.php?picid={$arr['id']}'></iframe></td></tr>";
                }
                $display_piclist .= "\r\n\t\t\t\t\t\t\t</table>\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            }
        }
    }
    $OUT = "\r\n\t\t<script>\r\n\t\t\tfunction seryn_update(obj) {\r\n\t\t\t\tif (obj.value == 'yes') {\r\n\t\t\t\t\tgetObject('div_serial').style.visibility = 'visible';\r\n\t\t\t\t\tgetObject('div_qty').style.visibility = 'hidden';\r\n\t\t\t\t} else {\r\n\t\t\t\t\tgetObject('div_serial').style.visibility = 'hidden';\r\n\t\t\t\t\tgetObject('div_qty').style.visibility = 'visible';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t</script>\r\n\t\t<h3>New Asset</h3>\r\n\t\t<form action='" . SELF . "' method='POST'>\r\n\t\t<table cellpadding='0' cellspacing='0'>\r\n\t\t\t<tr valign='top'>\r\n\t\t\t\t<td>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td colspan='2'>{$errors}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<input type='hidden' name='key' value='confirm'>\r\n\t\t\t\t\t\t<input type='hidden' name='id' value='{$id}'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'>Asset Details</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>" . REQ . "Select Group</td>\r\n\t\t\t\t\t\t\t<td>{$grps}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Select Type</td>\r\n\t\t\t\t\t\t\t<td>{$type_sel}</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>" . REQ . "Location</td>\r\n\t\t\t\t\t\t\t<td><input type='text' size='20' name='locat' value='{$locat}'></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>" . REQ . "Description</td>\r\n\t\t\t\t\t\t\t<td><input type='text' size='20' name='des' value='{$des}'></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Details</td>\r\n\t\t\t\t\t\t\t<td><textarea name='details' cols='30' rows='4'>{$details}</textarea></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Billing Requirement Ratio (Units)</td>\r\n\t\t\t\t\t\t\t<td><input type='text' name='units' value='{$units}' /></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Percentage of Yearly Depreciation</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input type='text' size='2' name='dep_perc' value='{$dep_perc}' maxlength='2' />%\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Auto Monthly Depreciation</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\tYes <input type='radio' name='dep_month' value='yes' {$dm_yes} />\r\n\t\t\t\t\t\t\t\tNo <input type='radio' name='dep_month' value='no' {$dm_no} />\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan=2>Bought</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t \t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t \t\t<td>" . REQ . "Date</td>\r\n\t\t\t\t\t \t\t<td>" . mkDateSelect("date", $date_year, $date_month, $date_day) . "</td>\r\n\t\t\t\t\t \t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>" . REQ . "Amount</td>\r\n\t\t\t\t\t\t\t<td>" . CUR . "<input type='text' size='20' name='amount' value='{$amount}'></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'>Servicing</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Add New Service</td>\r\n\t\t\t\t\t\t\t<td><input type='checkbox' name='set_service' value='yes'></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Service Date</td>\r\n\t\t\t\t\t\t\t<td>" . mkDateSelect("svdate", $svdate_year, $svdate_month, $svdate_day) . "</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Service Description</td>\r\n\t\t\t\t\t\t\t<td><input type='text' name='sv_desc' value='{$sv_desc}' /></td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<th colspan='2'>Serial Number/Quantity</th>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t<td>Has Serial Number?</td>\r\n\t\t\t\t\t\t\t<td>\r\n\t\t\t\t\t\t\t\t<input onclick='seryn_update(this);' type='radio' name='seryn' value='yes' " . fcheck($seryn != "no") . "> Yes\r\n\t\t\t\t\t\t\t\t<input onclick='seryn_update(this);' type='radio' name='seryn' value='no' " . fcheck($seryn == "no") . "> No\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td colspan='2' style='margin: 0px; padding: 0px;'>\r\n\t\t\t\t\t\t\t\t<div id='div_qty' style='{$div_qty_style}'>\r\n\t\t\t\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\r\n\t\t\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t\t\t\t\t<td>Quantity</td>\r\n\t\t\t\t\t\t\t\t\t\t\t<td><input type='text' name='qty' value='{$serial2}'></td>\r\n\t\t\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t\t</table>\r\n\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t\t<div id='div_serial' style='{$div_serial_style}'>\r\n\t\t\t\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='100%'>\r\n\t\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t\t\t\t<td>" . REQ . " Serial Number</td>\r\n\t\t\t\t\t\t\t\t\t\t<td><input type='text' size='20' name='serial' value='{$serial}'></td>\r\n\t\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t\t\t\t<td>2nd Serial Number</td>\r\n\t\t\t\t\t\t\t\t\t\t<td><input type='text' size='20' name='serial2' value='{$serial2}'></td>\r\n\t\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t\t</table>\r\n\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t\t<td>\r\n\t\t\t\t\t<table " . TMPL_tblDfts . ">\r\n\t\t\t\t\t\t{$display_iframe}\r\n\t\t\t\t\t</table>\r\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t\t{$display_piclist}\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t\t<tr>\r\n\t\t\t\t<td valign='bottom' colspan='2' align='right'>\r\n\t\t\t\t\t<input type='submit' value='Confirm &raquo;'>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t</table>\r\n\t\t<p>\r\n\t\t<table border='0' cellpadding='2' cellspacing='1'>\r\n\t\t\t<tr>\r\n\t\t\t\t<th>Quick Links</th>\r\n\t\t\t</tr>\r\n\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t<td><a href='asset-view.php'>View Assets</a></td>\r\n\t\t\t</tr>\r\n\t\t\t<script>document.write(getQuicklinkSpecial());</script>\r\n\t\t</table>";
    return $OUT;
}
function acdetails($_GET)
{
    # get vars
    extract($_GET);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($invid, "num", 1, 20, "Invalid Invoice number.");
    if (isset($ctyp) && $ctyp == 's') {
        $v->isOk($cusnum, "num", 1, 20, "Invalid customer number.");
    } elseif (isset($ctyp) && $ctyp == 'c') {
        $v->isOk($deptid, "num", 1, 20, "Invalid Department.");
    }
    # display errors, if any
    if ($v->isError()) {
        $err = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $confirm = "{$err}<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    # Get Invoice info
    db_connect();
    $sql = "SELECT * FROM nons_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
    $invRslt = db_exec($sql) or errDie("Unable to get invoices information");
    if (pg_numrows($invRslt) < 1) {
        return "<i class='err'>Not Found</i>";
    }
    $inv = pg_fetch_array($invRslt);
    $details = "";
    if ($ctyp == 's') {
        $sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'";
        $custRslt = db_exec($sql) or errDie("Unable to view customer");
        $cust = pg_fetch_array($custRslt);
        $details = "\r\n\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t<tr><th colspan='2'> Customer Details </th></tr>\r\n\t\t\t<input type='hidden' name='cusnum' value={$cusnum}>\r\n\t\t\t<tr class='bg-odd'><td>Customer</td><td valign='center'>{$cust['cusname']} {$cust['surname']}</td></tr>\r\n\t\t\t<tr class='bg-even'><td>Customer Address</td><td valign='center'><pre>{$cust['addr1']}</pre></td></tr>\r\n\t\t\t<tr class='bg-odd'><td>Customer VAT Number</td><td valign='center'>{$cust['vatnum']}</td></tr>\r\n\t\t\t<tr class='bg-even'><td>Customer Order number</td><td valign='center'>{$inv['cordno']}</td></tr>\r\n\t\t</table>";
    } elseif ($ctyp == 'ac') {
        // 		db_conn("exten");
        // 		$sql = "SELECT * FROM departments WHERE deptid = '$deptid'";
        // 		$deptRslt = db_exec ($sql) or errDie ("Unable to view customers");
        // 		$dept = pg_fetch_array($deptRslt);
        $details = "\r\n\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t<tr><th colspan='2'> Customer Details </th></tr>\r\n\t\t\t<input type='hidden' name='deptid' value='{$deptid}'>\r\n\t\t\t<tr class='bg-odd'><td>Customer</td><td valign='center'>{$inv['cusname']} </td></tr>\r\n\t\t\t<tr class='bg-even'><td>Customer Address</td><td valign='center'><pre>{$inv['cusaddr']}</pre></td></tr>\r\n\t\t\t<tr class='bg-odd'><td>Customer VAT Number</td><td valign='center'>{$inv['cusvatno']}</td></tr>\r\n\t\t\t<tr class='bg-even'><td>Customer Order number</td><td valign='center'>{$inv['cordno']}</td></tr>\r\n\t\t";
    }
    $stkacc = "";
    core_connect();
    $sql = "SELECT * FROM accounts WHERE div = '" . USER_DIV . "' ORDER BY accname ASC";
    $accRslt = db_exec($sql);
    if (pg_numrows($accRslt) < 1) {
        return "<li>There are No accounts in Cubit.";
    }
    while ($acc = pg_fetch_array($accRslt)) {
        $stkacc .= "<option value='{$acc['accid']}'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</option>";
    }
    $stkacc .= "</select>";
    $details .= "<tr class='bg-even'><td>Select Account</td><td valign='center'><select name='accountc'>{$stkacc}</select></td></tr>\r\n\t</table>";
    /* --- Start Products Display --- */
    # Products layout
    $products = "\r\n\t<table " . TMPL_tblDflts . " width='100%'>\r\n\t<tr>\r\n\t\t<th width='5%'>#</th>\r\n\t\t<th width='55%'>DESCRIPTION</th>\r\n\t\t<th width='10%'>QTY</th>\r\n\t\t<th width='10%'>UNIT PRICE</th>\r\n\t\t<th width='10%'>AMOUNT</th>\r\n\t\t<th width='10%'>ACCOUNT</th>\r\n\t<tr>";
    # get selected stock in this Invoice
    db_connect();
    $sql = "SELECT * FROM nons_inv_items  WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
    $stkdRslt = db_exec($sql);
    $i = 0;
    while ($stkd = pg_fetch_array($stkdRslt)) {
        $i++;
        db_conn('cubit');
        $Sl = "SELECT * FROM vatcodes WHERE id='{$stkd['vatex']}'";
        $Ri = db_exec($Sl);
        $vd = pg_fetch_array($Ri);
        if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
            $showvat = FALSE;
        }
        $stkacc = "<select name='stkaccs[{$stkd['id']}]'>";
        core_connect();
        $sql = "SELECT * FROM accounts WHERE div = '" . USER_DIV . "' ORDER BY accname ASC";
        $accRslt = db_exec($sql);
        if (pg_numrows($accRslt) < 1) {
            return "<li>There are No accounts in Cubit.";
        }
        while ($acc = pg_fetch_array($accRslt)) {
            $sel = fsel($stkd["accid"] == $acc["accid"]);
            $stkacc .= "<option {$sel} value='{$acc['accid']}'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</option>";
        }
        $stkacc .= "</select>";
        # put in product
        $products .= "\r\n\t\t<tr class='bg-odd'>\r\n\t\t\t<td align='center'>{$i}</td>\r\n\t\t\t<td>{$stkd['description']}</td>\r\n\t\t\t<td>{$stkd['qty']}</td>\r\n\t\t\t<td>{$stkd['unitcost']}</td>\r\n\t\t\t<td>" . CUR . " {$stkd['amt']}</td>\r\n\t\t\t<td " . ass("Select the account you wish to Credit") . ">{$stkacc}</td>\r\n\t\t</tr>";
    }
    $products .= "</table>";
    /* --- Start Some calculations --- */
    # Get subtotal
    $SUBTOT = sprint($inv['subtot']);
    # Get Total
    $TOTAL = sprint($inv['total']);
    # Get vat
    $VAT = sprint($inv['vat']);
    /* --- End Some calculations --- */
    # format date
    list($syear, $smon, $sday) = explode("-", $inv['odate']);
    if (!isset($showvat)) {
        $showvat = TRUE;
    }
    if ($showvat == TRUE) {
        $vat14 = AT14;
    } else {
        $vat14 = "";
    }
    /* -- Final Layout -- */
    $details = "<center><h3>Non-Stock Invoice Details</h3>\r\n\t<form action='" . SELF . "' method=post name=form>\r\n\t<input type=hidden name=key value=cconfirm>\r\n\t<input type=hidden name=invid value={$invid}>\r\n\t<input type=hidden name=ctyp value={$ctyp}>\r\n\t<table " . TMPL_tblDflts . " width='95%'>\r\n\t<tr><td valign=top>\r\n\t\t{$details}\r\n\t</td><td valign=top align=right>\r\n\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t<tr><th colspan=2> Non-Stock Invoice Details </th></tr>\r\n\t\t\t<tr class='bg-odd'><td>Non-Stock Invoice No.</td><td valign=center>T {$inv['invid']}</td></tr>\r\n\t\t\t<tr class='bg-even'><td>Proforma Inv No.</td><td valign=center>{$inv['docref']}</td></tr>\r\n\t\t\t<tr class='bg-odd'><td>Date</td><td valign=center>{$sday}-{$smon}-{$syear}</td></tr>\r\n\t\t\t<tr class='bg-even'><td>VAT Inclusive</td><td valign=center>{$inv['chrgvat']}</td></tr>\r\n\t\t\t<tr class='bg-odd'><td>Terms</td><td valign=center>{$inv['terms']} Days</td></tr>\r\n\t\t</table>\r\n\t</td></tr>\r\n\t<tr><td><br></td></tr>\r\n\t<tr><td colspan=2>\r\n\t{$products}\r\n\t</td></tr>\r\n\t<tr><td>\r\n\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t<tr><th width=40%>Quick Links</th><th width=45%>Remarks</th><td rowspan=5 valign=top width=15%><br></td></tr>\r\n\t\t\t<tr class='bg-odd'><td align='center'><a href='nons-invoice-new.php'>New Non-Stock Invoices</a></td><td class='bg-odd' rowspan=4 align=center valign=top>" . nl2br($inv['remarks']) . "</td></tr>\r\n\t\t\t<tr class='bg-odd'><td align='center'><a href='nons-invoice-view.php'>View Non-Stock Invoices</a></td></tr>\r\n\t\t\t<script>document.write(getQuicklinkSpecial());</script>\r\n\t\t</table>\r\n\t</td><td align=right>\r\n\t\t<table " . TMPL_tblDflts . " width=80%>\r\n\t\t\t<tr class='bg-odd'><td>SUBTOTAL</td><td align=right>" . CUR . " {$inv['subtot']}</td></tr>\r\n\t\t\t<tr class='bg-odd'><td>VAT {$vat14}</td><td align=right>" . CUR . " {$inv['vat']}</td></tr>\r\n\t\t\t<tr class='bg-even'><th>GRAND TOTAL</th><td align=right>" . CUR . " {$inv['total']}</td></tr>\r\n\t\t</table>\r\n\t</td></tr>\r\n\t<tr><td align=right><input type=submit value='Confirm &raquo'></td></tr>\r\n\t</table></form>\r\n\t</center>";
    return $details;
}
Ejemplo n.º 9
0
function slctAcc($_POST)
{
    # get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($type, "string", 1, 3, "Invalid category type.");
    $v->isOk($tab, "string", 1, 14, "Invalid category type.");
    $v->isOk($catid, "string", 1, 50, "Invalid category Id/name.");
    $v->isOk($payname, "string", 1, 255, "Invalid Salary payment name to be linked.");
    # 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;
    }
    $pacc = gethook("accnum", "salesacc", "name", $payname);
    $slctAcc = "<h3>Select Account to Link to : {$payname}</h3>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<form action='" . SELF . "' method=post>\n\t\t<input type=hidden name=key value=confirm>\n\t\t<input type=hidden name='type' value='{$type}'>\n\t\t<input type=hidden name='tab' value='{$tab}'>\n\t\t<input type=hidden name='catid' value='{$catid}'>\n\t\t<input type=hidden name='payname' value='{$payname}'>\n\t\t<tr><th>Field</th><th>Value</th></tr>\n\t\t<tr class='bg-odd'><td>Account Type</td><td>{$tab}</td></tr>\n\t\t<tr class='bg-even'><td>Account Name</td><td><select name=accnum>";
    $type = strtoupper($type);
    core_connect();
    $sql = "SELECT * FROM accounts WHERE catid='{$catid}' AND acctype ='{$type}' AND div = '" . USER_DIV . "'";
    $accRslt = db_exec($sql);
    $numrows = pg_numrows($accRslt);
    if (empty($numrows)) {
        return "<li>ERROR : There are no accounts in the category selected.";
    }
    while ($acc = pg_fetch_array($accRslt)) {
        $sel = fsel($acc["accid"] == $pacc);
        $slctAcc .= "<option {$sel} value='{$acc['accid']}'>{$acc['accname']}</option>";
    }
    $slctAcc .= "</select></td></tr>\n<tr><td align=right><input type=button value='&laquo Back' onClick='javascript:history.back()'></td><td align=right><input type=submit value='Add Link &raquo'></td></tr>\n<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=100>\n<tr><th>Quick Links</th></tr>\n<script>document.write(getQuicklinkSpecial());</script>\n</tr>\n</table>\n\n</form>\n</table>\n";
    return $slctAcc;
}
Ejemplo n.º 10
0
function customize($_POST)
{
    extract($_POST);
    $fields = array();
    $fields["account"] = 0;
    $fields["heading_1"] = COMP_NAME;
    $fields["heading_2"] = date("d/m/Y");
    $fields["heading_3"] = "Balance Sheet";
    $fields["heading_4"] = "Prepared by: " . USER_NAME;
    $fields["viewyear"] = "core";
    $fields["month_from"] = date("m");
    $fields["month_to"] = date("m");
    $fields["capital_employed_out"] = "Capital Employed";
    $fields["employment_of_capital_out"] = "Employment of Capital";
    $fields["period"] = substr(PRD_DB, 2);
    $fields["month"] = date("m");
    $fields["zero_balance"] = "";
    foreach ($fields as $var_name => $value) {
        if (!isset(${$var_name})) {
            ${$var_name} = $value;
        }
    }
    $qry = new dbSelect("year", "core", grp(m("where", "closed='y'"), m("order", "yrname ASC")));
    $qry->run();
    if (PRD_STATE == "py") {
        $curyear = PYR_NAME;
    } else {
        $curyear = YR_NAME;
    }
    $year_sel = "\n\t<select name='viewyear'>\n\t\t<option value='core'>" . $curyear . " (Current)</option>";
    while ($row = $qry->fetch_array()) {
        $sel = fsel($viewyear == $row["yrdb"]);
        $year_sel .= "<option {$sel} value='{$row['yrdb']}'>{$row['yrname']}</option>";
    }
    $year_sel .= "\n\t</select>";
    // Retrieve list of accounts for the account dropdown
    db_conn("core");
    $sql = "SELECT * FROM accounts WHERE acctype='B' ORDER BY accname ASC";
    $acc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts information from Cubit.");
    // Accounts dropdown output
    $acc_sel = "<select name='account' style='width: 200px'>\n\t\t<option value='0'>Please select</option>";
    while ($acc_data = pg_fetch_array($acc_rslt)) {
        if ($account == $acc_data["accid"]) {
            $selected = "selected";
        } else {
            $selected = "";
        }
        $acc_sel .= "<option value='{$acc_data['accid']}' {$selected}>{$acc_data['accname']}</option>";
    }
    $acc_sel .= "</select>";
    // Accounts list
    db_conn("cubit");
    $sql = "SELECT * FROM saved_bs_accounts";
    $sbsacc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts list from Cubit.");
    /*// the accounts list
    	$acc_list = "<tr>
    		<th colspan='4'>Accounts</th>
    	</tr>";
    
    	// has any accounts been added?
    	if (!pg_num_rows($sbsacc_rslt)) {
    		$acc_list .= "<tr class='bg-odd'>
    			<td>No accounts have been added, ALL balance accounts will be displayed.</td>
    		</tr>";
    	}
    
    	$i = 0;
    	while ($sbsacc_data = pg_fetch_array($sbsacc_rslt)) {
    		$i++;
    
    		if (empty($sbsacc_data["toptype"])) {
    			db_conn("core");
    			$sql = "SELECT toptype FROM accounts WHERE accid='$sbsacc_data[accid]'";
    			$rslt = db_exec($sql) or errDie("Unable to retrieve trial balance information from Cubit.");
    			$acc_toptype = pg_fetch_result($rslt, 0);
    		} else {
    			$acc_toptype = $sbsacc_data["toptype"];
    		}
    
    		$categories_sel = "<select name='toptype[$sbsacc_data[accid]]'>";
    		foreach ($ar_cats as $toptype=>$description) {
    			if ($acc_toptype == $toptype) {
    				$selected = "selected";
    			} else {
    				$selected = "";
    			}
    			$categories_sel .= "<option value='$toptype' $selected>$description</option>";
    		}
    		$categories_sel .= "</select>";
    
    		// has any of the checkboxes been checked?
    		if (isset($rem[$sbsacc_data["accid"]])) {
    			$checked = "checked";
    		} else {
    			$checked = "";
    		}
    
    		$acc_list .= "<tr class='".bg_class()."'>
    			<td>$sbsacc_data[accname]</td>
    			<td>$categories_sel</td>
    			<td><a href='#' onclick='openwindow(\"".SELF."?key=note_view&accid=$sbsacc_data[accid]\")'>Note</a></td>
    			<td><input type='checkbox' name='rem[$sbsacc_data[accid]]' value='$sbsacc_data[accid]' $checked></td>
    		</tr>";
    	}
    	$acc_list .= "<tr>
    		<td colspan='3' align='center'>
    			<input type='submit' name='key' value='Remove Selected'>
    			<input type='submit' name='key' value='Update'>
    		</td>
    	</tr>";*/
    $acc_list = "";
    // Period dropdown
    /*$month_frm_sel = "<select name='month_from'>";
    	for ($i = 1; $i <= 12; $i++) {
    		if ($month_from == $i) {
    			$selected = "selected";
    		} else {
    			$selected = "";
    		}
    		$month_frm_sel .= "<option value='$i' $selected>".getMonthName($i)."</option>";
    	}
    	$month_frm_sel .= "</select>";*/
    // Period dropdown
    $month_to_sel = finMonList("month_to", $month_to, true);
    //------------------------------------------------------------------------
    if (isset($last_year_same_month) && $last_year_same_month) {
        $lysm = "checked";
    } else {
        $lysm = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_year_to_date) && $this_year_year_to_date) {
        $tyytd = "checked";
    } else {
        $tyytd = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_movement_to_date) && $this_year_movement_to_date) {
        $tymtd = "checked";
    } else {
        $tymtd = "";
    }
    //------------------------------------------------------------------------
    if (isset($last_year_year_to_date) && $last_year_year_to_date) {
        $lyytd = "checked";
    } else {
        $lyytd = "";
    }
    //------------------------------------------------------------------------
    if (isset($budget) && $budget) {
        $budget = "checked";
    } else {
        $budget = "";
    }
    //------------------------------------------------------------------------
    if (isset($this_year_budget) && $this_year_budget) {
        $tybudget = "checked";
    } else {
        $tybudget = "";
    }
    // Layout
    $OUTPUT = "\n\t\t<h3>Balance Sheet</h3>\n\t\t<form method='POST' action='" . SELF . "'>\n\t\t\t<input type='hidden' name='key' value='display' />\n\t\t\t<input type='hidden' name='customized' value='true' />\n\t\t<table border='0' cellpadding='0' cellspacing='0'>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'><h3>Customise</h3></th>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>Headings</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Heading 1</td>\n\t\t\t\t\t\t\t<td><input type='text' name='heading_1' value='{$heading_1}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Heading 2</td>\n\t\t\t\t\t\t\t<td><input type='text' name='heading_2' value='{$heading_2}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Heading 3</td>\n\t\t\t\t\t\t\t<td><input type='text' name='heading_3' value='{$heading_3}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Heading 4</td>\n\t\t\t\t\t\t\t<td><input type='text' name='heading_4' value='{$heading_4}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Capital Employed</td>\n\t\t\t\t\t\t\t<td><input type='text' name='capital_employed_out' value='{$capital_employed_out}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Employment of Capital</td>\n\t\t\t\t\t\t\t<td><input type='text' name='employment_of_capital_out' value='{$employment_of_capital_out}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<table " . TMPL_tblDflts . " style='margin: 0px; width: 300px'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>Display</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Last Year - Selected Month</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='last_year_same_month' value='true' {$lysm} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>This Year - Movement To Selected Month</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='this_year_movement_to_date' value='true' {$tymtd} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>This Year - To Selected Month</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='this_year_year_to_date' value='true' {$tyytd} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Last Year - Year End</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='last_year_year_to_date' value='true' {$lyytd} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Selected Month Budget</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='budget' value='true' {$budget} \\></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<!--<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>This Year Budget To Month</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='this_year_budget' value='true' {$tybudget} \\></td>\n\t\t\t\t\t\t</tr>//-->\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Zero Balances</td>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='zero_balance' value='checked' {$zero_balance}></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<table " . TMPL_tblDflts . " style='margin: 0px; width: 300px'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Year</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td align='center'>{$year_sel}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Month</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td align='center'>{$month_to_sel}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t<table " . TMPL_tblDflts . " style='margin: 0px; width: 300px'>\n\t\t\t\t\t\t<!--<tr>\n\t\t\t\t\t\t\t<th>Add Account</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td align='center'>\$acc_sel<input type='submit' name='key' value='Add'></td>\n\t\t\t\t\t\t</tr>//-->\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td><input type='submit' value='Display &raquo' style='width: 100%; font-weight: bold'></td>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<!--<td valign='top'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t{$acc_list}\n\t\t\t\t\t</table>\n\t\t\t\t</td>//-->\n\t\t\t</tr>\n\t\t</table>\n\t\t</form>";
    return $OUTPUT;
}