function show_report($_POST)
{
    extract($_POST);
    if (!isset($employee) or strlen($employee) < 1) {
        return "Invalid use of module.";
    }
    db_connect();
    $get_employee = "SELECT * FROM employees WHERE empnum = '{$employee}' LIMIT 1";
    $run_employee = db_exec($get_employee) or errDie("Unable to get employees information.");
    if (pg_numrows($run_employee) < 1) {
        return "Invalid Employee Selected.";
    } else {
        $earr = pg_fetch_array($run_employee);
        //extract($earr);
    }
    $finstartdate = mkdate(getYearOfFinPrd(1) - 1, $PRDMON[1], 1);
    $finenddate = mkldate(getYearOfFinPrd(12) - 1, $PRDMON[12]);
    db_connect();
    #get all leave for this employee
    $get_leave = "SELECT * FROM empleave WHERE empnum = '{$earr['empnum']}' AND startdate > '{$finstartdate}' AND enddate < '{$finenddate}'";
    $run_leave = db_exec($get_leave) or errDie("Unable to get employee leave information.");
    if (pg_numrows($run_leave) < 1) {
        $listing = "Employee did not apply for leave during the previous financial year.";
    } else {
        $total_leave_days = 0;
        $listing = "\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Leave Start Date</th>\n\t\t\t\t\t<th>Leave End Date</th>\n\t\t\t\t\t<th>Approved By</th>\n\t\t\t\t\t<th>Working Days</th>\n\t\t\t\t\t<th>Non Working Days</th>\n\t\t\t\t\t<th>Leave Type</th>\n\t\t\t\t</tr>\n\t\t\t";
        while ($larr = pg_fetch_array($run_leave)) {
            $total_leave_days = $total_leave_days + $larr['workingdays'];
            $listing .= "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>{$larr['startdate']}</td>\n\t\t\t\t\t\t<td>{$larr['enddate']}</td>\n\t\t\t\t\t\t<td>{$larr['approvedby']}</td>\n\t\t\t\t\t\t<td>{$larr['workingdays']}</td>\n\t\t\t\t\t\t<td>{$larr['nonworking']}</td>\n\t\t\t\t\t\t<td>{$larr['type']}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t";
        }
        $total_cost = $earr['basic_sal_annum'] / (52 * 5) * $total_leave_days;
    }
    $display = "\n\t\t\t<h2>Calculate Value Of Employee Leave</h2>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t\t<input type='hidden' name='key' value='xls'>\n\t\t\t\t<input type='hidden' name='employee' value='{$employee}'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Details</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Employee:</td>\n\t\t\t\t\t<td>{$earr['fnames']} {$earr['sname']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Amount Of Annual Leave Days:</td>\n\t\t\t\t\t<td>{$earr['stdlea']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Total Days Leave Taken</td>\n\t\t\t\t\t<td>{$total_leave_days}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Total Cost Of Employee Leave</td>\n\t\t\t\t\t<td>" . CUR . " {$total_cost}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t{$listing}\n\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='4'><input type='submit' name='xls' value='Export to spreadsheet'></td>\n\t\t\t\t</tr>\n\t\t\t</form>\n\t\t\t</table>\n\t\t";
    return $display;
}
function write($frm)
{
    extract($_REQUEST);
    if ($frm->validate("write")) {
        return confirm($frm);
    }
    pglib_transaction("BEGIN");
    db_conn('cubit');
    $user = USER_NAME;
    $Sql = "SELECT * FROM assets WHERE (dep_month='yes' AND remaction IS NULL)";
    $Rslt = db_exec($Sql) or errDie("Unable to access database.");
    $cc = "";
    $todate = mkdate($date_year, $date_month, $date_day);
    $ttime = mktimefd($todate);
    $refnum = getrefnum($todate);
    while ($led = pg_fetch_array($Rslt)) {
        if (empty($led["autodepr_date"])) {
            $led["autodepr_date"] = $led["date"];
        }
        explodeDate($led["autodepr_date"], $date_year, $date_month, $date_day);
        $ftime = mktime(0, 0, 0, $date_month, $date_day, $date_year);
        $depmonths = 0;
        while ($ftime < $ttime) {
            ++$depmonths;
            $ftime = mktime(0, 0, 0, $date_month + $depmonths, $date_day, $date_year);
        }
        if ($depmonths == 0) {
            continue;
        }
        $depperc = $led["dep_perc"];
        $ml_perc = $depperc * ($depmonths % 12 / 12);
        $years = ($depmonths - $depmonths % 12) / 12;
        $baseamt = $led["amount"] - $led["accdep"];
        $depamt = 0;
        /* yearly depreciations */
        for ($i = 1; $i <= $years; ++$i) {
            $depamt += ($baseamt - $depamt) * ($depperc / 100);
        }
        /* monthly depreciation */
        $depamt += ($baseamt - $depamt) * ($ml_perc / 100);
        $sql = "SELECT * FROM assetgrp WHERE grpid = '{$led['grpid']}' AND div = '" . USER_DIV . "'";
        $grpRslt = db_exec($sql);
        $grp = pg_fetch_array($grpRslt);
        writetrans($grp['depacc'], $grp['accdacc'], $todate, $refnum, $depamt, "{$led['des']} Depreciation");
        db_connect();
        $sql = "UPDATE assets SET accdep = (accdep + '{$depamt}'), autodepr_date='{$todate}'\r\n\t\t\t\tWHERE (id='{$led['id']}' AND div = '" . USER_DIV . "')";
        db_exec($sql) or errdie("Could not update assets table.");
        $snetval = $baseamt - $depamt;
        $sdate = date("Y-m-d");
        $sql = "INSERT INTO assetledger(assetid, asset, date, depamt, netval, div) \r\n\t\t\t\tVALUES ('{$led['id']}', '{$led['des']}', '{$todate}', '{$depamt}', '{$snetval}', '" . USER_DIV . "')";
        db_exec($sql) or errdie("Could not write to asset ledger.");
        $cc .= "CostCenter('ct', 'Asset Depreciation', '{$todate}', '{$led['des']} Depreciation', '{$depamt}', '');";
    }
    pglib_transaction("COMMIT");
    $write = "\r\n\t<script> \r\n\t{$cc}\r\n\t</script>\r\n\t<table " . TMPL_tblDflts . " width='50%'>\r\n\t\t<tr>\r\n\t\t\t<th>Auto Asset Depreciation</th>\r\n\t\t</tr>\r\n\t\t<tr class='datacell'>\r\n\t\t\t<td>Asset Depreciation has calculated and recorded.</td>\r\n\t\t</tr>\r\n\t</table>";
    return $write;
}
Example #3
0
function getWvListe()
{
    $ret = array();
    $mailcnt = 0;
    //Mails holen
    $mail = holeMailHeader($_SESSION["loginCRM"], $_SESSION['MailFlag']);
    if ($mail) {
        foreach ($mail as $col) {
            $ret[] = array('Type' => "M", 'Status' => $col["Gelesen"], 'cause' => $col["Betreff"], 'Initdate' => $col["Datum"], 'ID' => $col["Nr"], 'IniUser' => htmlspecialchars($col["Abs"]), 'Art' => "E", 'End' => 0);
            $mailcnt++;
        }
    }
    //Termine holen
    $termine = getTermin(date("d"), date("m"), date("Y"), "T", $_SESSION["loginCRM"]);
    //Wiedervorlagen holen
    $wvl = getWvl($_SESSION["loginCRM"]);
    if ($termine && $wvl) {
        $wvl = array_merge($termine, $wvl);
    } else {
        if ($termine) {
            $wvl = $termine;
        }
    }
    $nunD = date("Y-m-d 00:00:00");
    $nunT = date("Y-m-d H:i");
    if ($wvl) {
        foreach ($wvl as $col) {
            if ($col["finishdate"] || $col["stoptag"]) {
                if ($col["finishdate"] != "" && $col["finishdate"] < $nunD || $col["stoptag"] != "" && $col["stoptag"] . " " . $col["stopzeit"] < $nunT) {
                    $end = 3;
                } else {
                    $end = 2;
                }
                $datum = mkdate($col["finishdate"] ? $col["finishdate"] : $col["stoptag"] . " " . $col["stopzeit"] . ":00");
            } else {
                if ($col["trans_module"]) {
                    $datum = mkdate($col["initdate"] . " 00:00:00");
                } else {
                    $datum = mkdate($col["initdate"] ? $col["initdate"] : $col["starttag"] . " " . $col["startzeit"] . ":00");
                }
                $end = 1;
            }
            if ($col["status"] == "F") {
                $Art = "F";
            } else {
                if ($col["starttag"]) {
                    $Art = "T";
                } else {
                    $Art = "D";
                }
            }
            $ret[] = array('Type' => $col["kontakt"] ? $col["kontakt"] : "X", 'Status' => $col["status"] ? $col["status"] : "-", 'cause' => $col["cause"], 'Initdate' => $datum, 'ID' => $col["id"], 'IniUser' => $col["ename"] ? $col["ename"] : $col["employee"], 'Art' => $Art, 'End' => $end);
        }
    }
    echo json_encode($ret);
}
function show_notes($_POST)
{
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($from_day, "num", 1, 2, "Invalid Invoice From Date day.");
    $v->isOk($from_month, "num", 1, 2, "Invalid Invoice From Date month.");
    $v->isOk($from_year, "num", 1, 5, "Invalid Invoice From Date year.");
    $v->isOk($to_day, "num", 1, 2, "Invalid Invoice To Date day.");
    $v->isOk($to_month, "num", 1, 2, "Invalid Invoice To Date month.");
    $v->isOk($to_year, "num", 1, 5, "Invalid Invoice To Date year.");
    $fromdate = mkdate($from_year, $from_month, $from_day);
    $todate = mkdate($to_year, $to_month, $to_day);
    $v->isOk($fromdate, "date", 1, 1, "Invalid From Date.");
    $v->isOk($todate, "date", 1, 1, "Invalid To Date.");
    # display errors, if any
    if ($v->isError()) {
        $err = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        return get_filter($_POST, $err);
    }
    $listing = "\n\t\t<tr>\n\t\t\t<th>Customer</th>\n\t\t\t<th>Credit Note No.</th>\n\t\t\t<th>Ref.</th>\n\t\t\t<th>Date</th>\n\t\t\t<th>Amount</th>\n\t\t\t<th>Stock Returned</th>\n\t\t\t<th>Options</th>\n\t\t</tr>";
    db_connect();
    $get_sql = "SELECT * FROM credit_notes WHERE tdate >= '{$fromdate}' AND tdate <= '{$todate}'";
    $run_get = db_exec($get_sql) or errDie("Unable to get credit note information.");
    if (pg_numrows($run_get) < 1) {
        $listing .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='7'>No Credit Notes Found.</td>\n\t\t\t</tr>";
    } else {
        while ($carr = pg_fetch_array($run_get)) {
            $get_cust = "SELECT surname FROM customers WHERE cusnum = '{$carr['cusnum']}'";
            $run_cust = db_exec($get_cust) or errDie("Unable to get customer information.");
            if (pg_numrows($run_cust) < 1) {
                $cusname = "";
            } else {
                $cusname = pg_fetch_result($run_cust, 0, 0);
            }
            if (isset($carr['used_stock']) and $carr['used_stock'] == "1") {
                $showstockused = "Yes";
            } else {
                $showstockused = "No";
            }
            $listing .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$cusname}</td>\n\t\t\t\t\t<td>g{$carr['creditnote_num']}</td>\n\t\t\t\t\t<td>{$carr['refnum']}</td>\n\t\t\t\t\t<td>{$carr['tdate']}</td>\n\t\t\t\t\t<td>" . CUR . " {$carr['totamt']}</td>\n\t\t\t\t\t<td>{$showstockused}</td>\n\t\t\t\t\t<td><a href='credit-note-print.php?id={$carr['id']}'>Print</a></td>\n\t\t\t\t</tr>";
        }
    }
    $display = "\n\t\t<h2>Listing Of Credit Notes</h2>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t{$listing}\n\t\t</table>";
    return $display;
}
function get_period()
{
    global $PRDMON;
    $finstartdate = mkdate(getYearOfFinPrd(1), $PRDMON[1], 1);
    $finenddate = mkldate(getYearOfFinPrd(12), $PRDMON[12]);
    db_connect();
    #get vat period setting
    $get_set = "SELECT * FROM settings WHERE label = 'VAT Period' LIMIT 1";
    $run_set = db_exec($get_set) or errDie("Unable to get vat period information.");
    if (pg_numrows($run_set) < 1) {
        return "\n\t\t\t<li class='err'>Please Set VAT Period Setting Before Continuing.</li>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='../vat_period_setting.php'>Set VAT Period</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t</table>";
    } else {
        $sarr = pg_fetch_array($run_set);
        $periodlength = $sarr['value'];
        $b = 1;
        $period_drop = "<select name='period'>";
        for ($x = 1; $b < 12; $x = $x + $periodlength) {
            $b = $b + $periodlength;
            #make sure we dont cross the 12 period limit
            if ($b > 12) {
                #set period to the last
                $dob = $b - 12;
                $b = 12;
                #make sure we get the last month (the -1 makes us lose 1)
                //				$PRDMON[$b] = $PRDMON[$b] +1;
            } else {
                $dob = $b;
            }
            $start = date("Y-m-d", mktime(0, 0, 0, $PRDMON[$x], 1, getYearOfFinPrd($x)));
            $end = date("Y-m-d", mktime(0, 0, 0, $PRDMON[$dob], 0, getYearOfFinPrd($b)));
            $period_drop .= "<option value='{$start}|{$end}'>{$start} - {$end}</option>";
        }
        $period_drop .= "</select>";
    }
    #generate the periods dropdown based on vat period setting.
    $display = "\n\t\t<h2>Select VAT Period For Report</h2>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t<tr>\n\t\t\t\t<td><li class='err'>NOTE: Pre Generated Values Are The Cubit Recommened Values. </li></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td><li class='err'>However these values may be changed at will.</li></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Period</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$period_drop}</td>\n\t\t\t</tr>\n\t\t\t<tr><td></td></tr>\n\t\t\t<tr>\n\t\t\t\t<th>Name For Report</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><input type='text' name='returnname' value='" . date("Y-m-d") . " Report'></td>\n\t\t\t</tr>\n\t\t\t<tr><td></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td align='right'><input type='submit' value='Next'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>";
    return $display;
}
Example #6
0
             $number++;
             $startnow += $config[forum_show_postspp];
         } else {
             $started++;
             $number = "1";
             $startnow = "0";
         }
         $threadid = $thread[id];
         eval("\$inc[showpp] .= \"" . gettemplate("forum.showpp.posts.num") . "\";");
     }
 }
 unset($started, $number, $startnow, $countposts);
 if ($thread[last_posttime]) {
     $lastdate = mkdate($thread[last_posttime]);
 } else {
     $lastdate = mkdate($thread[settime]);
 }
 if ($thread[last_posttime] <= $login[last_forum_read]) {
     if ($threadcolor % 2 == "0") {
         $csstyle = "2";
     } else {
         $csstyle = "1";
     }
 } else {
     if ($threadcolor % 2 == "0") {
         $csstyle = "4";
     } else {
         $csstyle = "3";
     }
 }
 eval("\$incf[threadbit] .= \"" . gettemplate("forum.board.thread.bit") . "\";");
Example #7
0
 function show()
 {
     global $set, $db, $apx, $html;
     //Suche durchführen
     if ($_REQUEST['item'] && ($_REQUEST['title'] || $_REQUEST['text']) || $_REQUEST['secid'] || $_REQUEST['catid'] || $_REQUEST['userid']) {
         $where = '';
         $_REQUEST['secid'] = (int) $_REQUEST['secid'];
         $_REQUEST['catid'] = (int) $_REQUEST['catid'];
         $_REQUEST['userid'] = (int) $_REQUEST['userid'];
         //Suche wird ausgeführt...
         if ($_REQUEST['title']) {
             $sc[] = "title LIKE '%" . addslashes_like($_REQUEST['item']) . "%'";
         }
         if ($_REQUEST['text']) {
             $sc[] = "text LIKE '%" . addslashes_like($_REQUEST['item']) . "%'";
         }
         if (is_array($sc)) {
             $where .= ' AND ( ' . implode(' OR ', $sc) . ' )';
         }
         //Sektion
         if (!$apx->session->get('section') && $_REQUEST['secid']) {
             $where .= " AND ( secid LIKE '%|" . $_REQUEST['secid'] . "|%' OR secid='all' ) ";
         }
         //Kategorie
         if ($_REQUEST['catid']) {
             $where .= " AND catid='" . $_REQUEST['catid'] . "' ";
         }
         //Benutzer
         if ($_REQUEST['userid']) {
             $where .= " AND userid='" . $_REQUEST['userid'] . "' ";
         }
         $data = $db->fetch("SELECT id FROM " . PRE . "_content WHERE 1 " . $where);
         $ids = get_ids($data, 'id');
         $ids[] = -1;
         $searchid = saveSearchResult('admin_content', $ids, array('title' => $_REQUEST['title'], 'text' => $_REQUEST['text'], 'item' => $_REQUEST['item'], 'catid' => $_REQUEST['catid'], 'secid' => $_REQUEST['secid'], 'userid' => $_REQUEST['userid']));
         header("HTTP/1.1 301 Moved Permanently");
         header('Location: action.php?action=content.show&searchid=' . $searchid);
         return;
     }
     //Vorgaben
     $_REQUEST['title'] = 1;
     $_REQUEST['text'] = 1;
     quicklink('content.add');
     $orderdef[0] = 'time';
     $orderdef['title'] = array('a.title', 'ASC', 'COL_TITLE');
     $orderdef['user'] = array('b.username', 'ASC', 'COL_USER');
     $orderdef['time'] = array('a.time', 'DESC', 'COL_ADDTIME');
     $orderdef['lastchange'] = array('a.lastchange', 'DESC', 'COL_LASTCHANGE');
     $orderdef['hits'] = array('a.hits', 'DESC', 'COL_HITS');
     $col[] = array('', 1, 'align="center"');
     $col[] = array('COL_TITLE', 50, 'class="title"');
     $col[] = array('COL_USER', 20, 'align="center"');
     $col[] = array('COL_LASTCHANGE', 20, 'align="center"');
     $col[] = array('COL_HITS', 10, 'align="center"');
     //Suchergebnis?
     $resultFilter = '';
     if ($_REQUEST['searchid']) {
         $searchRes = getSearchResult('admin_content', $_REQUEST['searchid']);
         if ($searchRes) {
             list($resultIds, $resultMeta) = $searchRes;
             $_REQUEST['item'] = $resultMeta['item'];
             $_REQUEST['title'] = $resultMeta['title'];
             $_REQUEST['text'] = $resultMeta['text'];
             $_REQUEST['catid'] = $resultMeta['catid'];
             $_REQUEST['secid'] = $resultMeta['secid'];
             $_REQUEST['userid'] = $resultMeta['userid'];
             $resultFilter = " AND a.id IN (" . implode(', ', $resultIds) . ")";
         } else {
             $_REQUEST['searchid'] = '';
         }
     }
     //Sektionen auflisten
     $seclist = '';
     if (is_array($apx->sections) && count($apx->sections)) {
         foreach ($apx->sections as $res) {
             $seclist .= '<option value="' . $res['id'] . '"' . iif($_REQUEST['secid'] == $res['id'], ' selected="selected"') . '>' . replace($res['title']) . '</option>';
         }
     }
     //Kategorien auflisten
     $catlist = '';
     $data = $set['content']['groups'];
     if (count($data)) {
         foreach ($data as $id => $title) {
             $catlist .= '<option value="' . $id . '"' . iif($_REQUEST['catid'] == $id, ' selected="selected"') . '>' . replace($title) . '</option>';
         }
     }
     //Benutzer auflisten
     $userlist = '';
     $data = $db->fetch("SELECT b.userid,b.username FROM " . PRE . "_content AS a LEFT JOIN " . PRE . "_user AS b USING (userid) WHERE a.userid!=0 GROUP BY userid ORDER BY username ASC");
     if (count($data)) {
         foreach ($data as $res) {
             $userlist .= '<option value="' . $res['userid'] . '"' . iif($_REQUEST['userid'] == $res['userid'], ' selected="selected"') . '>' . replace($res['username']) . '</option>';
         }
     }
     $apx->tmpl->assign('ITEM', compatible_hsc($_REQUEST['item']));
     $apx->tmpl->assign('STITLE', (int) $_REQUEST['title']);
     $apx->tmpl->assign('STEXT', (int) $_REQUEST['text']);
     $apx->tmpl->assign('SECLIST', $seclist);
     $apx->tmpl->assign('CATLIST', $catlist);
     $apx->tmpl->assign('USERLIST', $userlist);
     $apx->tmpl->assign('EXTENDED', $searchRes);
     $apx->tmpl->parse('search');
     list($count) = $db->first("SELECT count(id) FROM " . PRE . "_content AS a WHERE 1 " . $resultFilter . section_filter());
     pages('action.php?action=content.show&amp;sortby=' . $_REQUEST['sortby'] . iif($_REQUEST['searchid'], '&amp;searchid=' . $_REQUEST['searchid']), $count);
     $data = $db->fetch("SELECT a.id,a.secid,a.title,a.lastchange,a.allowcoms,a.allowrating,a.active,a.hits,b.userid,b.username FROM " . PRE . "_content AS a LEFT JOIN " . PRE . "_user AS b USING(userid) WHERE 1 " . $resultFilter . section_filter(true, 'a.secid') . " " . getorder($orderdef) . getlimit());
     if (count($data)) {
         foreach ($data as $res) {
             ++$i;
             if ($res['active']) {
                 $tabledata[$i]['COL1'] = '<img src="design/greendot.gif" alt="' . $apx->lang->get('CORE_ACTIVE') . '" title="' . $apx->lang->get('CORE_ACTIVE') . '" />';
             } else {
                 $tabledata[$i]['COL1'] = '<img src="design/reddot.gif" alt="' . $apx->lang->get('CORE_INACTIVE') . '" title="' . $apx->lang->get('CORE_INACTIVE') . '" />';
             }
             $title = $res['title'];
             $title = strip_tags($title);
             //$title=str_replace('=>','»',$title);
             $title = str_replace('->', '»', $title);
             $title = shorttext($title, 40);
             $title = replace($title);
             $temp = explode('->', $res['title']);
             $tmp = unserialize_section($res['secid']);
             $link = mklink('content.php?id=' . $res['id'], 'content,' . $res['id'] . urlformat(array_pop($temp)) . '.html', iif($set['main']['forcesection'], iif(unserialize_section($res['secid']) == array('all'), $apx->section_default, array_shift($tmp)), 0));
             $tabledata[$i]['COL2'] = '<a href="' . $link . '" target="_blank">' . $title . '</a>';
             $tabledata[$i]['COL3'] = replace($res['username']);
             $tabledata[$i]['COL4'] = mkdate($res['lastchange'], '<br />');
             $tabledata[$i]['COL5'] = $res['hits'];
             //Optionen
             if ($apx->user->has_right('content.edit') && ($res['userid'] == $apx->user->info['userid'] || $apx->user->has_spright('content.edit'))) {
                 $tabledata[$i]['OPTIONS'] .= optionHTML('edit.gif', 'content.edit', 'id=' . $res['id'], $apx->lang->get('CORE_EDIT'));
             }
             if ($apx->user->has_right('content.del') && ($res['userid'] == $apx->user->info['userid'] || $apx->user->has_spright('content.del'))) {
                 $tabledata[$i]['OPTIONS'] .= optionHTMLOverlay('del.gif', 'content.del', 'id=' . $res['id'], $apx->lang->get('CORE_DEL'));
             }
             if ($res['active'] && $apx->user->has_right('content.disable') && ($res['userid'] == $apx->user->info['userid'] || $apx->user->has_spright('content.disable'))) {
                 $tabledata[$i]['OPTIONS'] .= optionHTML('disable.gif', 'content.disable', 'id=' . $res['id'] . '&sectoken=' . $apx->session->get('sectoken'), $apx->lang->get('CORE_DISABLE'));
             } elseif (!$res['active'] && $apx->user->has_right('content.enable') && ($res['userid'] == $apx->user->info['userid'] || $apx->user->has_spright('content.enable'))) {
                 $tabledata[$i]['OPTIONS'] .= optionHTML('enable.gif', 'content.enable', 'id=' . $res['id'] . '&sectoken=' . $apx->session->get('sectoken'), $apx->lang->get('CORE_ENABLE'));
             } else {
                 $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
             }
             //Kommentare + Bewertungen
             if ($apx->is_module('comments') || $apx->is_module('ratings')) {
                 $tabledata[$i]['OPTIONS'] .= '&nbsp;';
             }
             if ($apx->is_module('comments')) {
                 list($comments) = $db->first("SELECT count(id) FROM " . PRE . "_comments WHERE ( module='content' AND mid='" . $res['id'] . "' )");
                 if ($comments && ($apx->is_module('comments') && $set['content']['coms']) && $res['allowcoms'] && $apx->user->has_right('comments.show')) {
                     $tabledata[$i]['OPTIONS'] .= optionHTML('comments.gif', 'comments.show', 'module=content&mid=' . $res['id'], $apx->lang->get('COMMENTS') . ' (' . $comments . ')');
                 } else {
                     $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
                 }
             }
             if ($apx->is_module('ratings')) {
                 list($ratings) = $db->first("SELECT count(id) FROM " . PRE . "_ratings WHERE ( module='content' AND mid='" . $res['id'] . "' )");
                 if ($ratings && ($apx->is_module('ratings') && $set['content']['ratings']) && $res['allowrating'] && $apx->user->has_right('ratings.show')) {
                     $tabledata[$i]['OPTIONS'] .= optionHTML('ratings.gif', 'ratings.show', 'module=content&mid=' . $res['id'], $apx->lang->get('RATINGS') . ' (' . $ratings . ')');
                 } else {
                     $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
                 }
             }
         }
     }
     $apx->tmpl->assign('TABLE', $tabledata);
     $html->table($col);
     orderstr($orderdef, 'action.php?action=content.show' . iif($_REQUEST['searchid'], '&amp;searchid=' . $_REQUEST['searchid']));
     save_index($_SERVER['REQUEST_URI']);
 }
Example #8
0
     if (!($last = mkdate($last))) {
         stdmsg("Error", "Invalid date.");
         stdfoot();
         die;
     }
     $q .= ($q ? "&amp;" : "") . "ls={$last}";
     $lasttype = $_GET['lst'];
     $q .= ($q ? "&amp;" : "") . "lst={$lasttype}";
     if ($lasttype == "0") {
         // For mySQL 4.1.1 or above use instead
         // $where_is .= (isset($where_is)?" AND ":"")."DATE(added) = DATE('$date')";
         $where_is .= (isset($where_is) ? " AND " : "") . "(UNIX_TIMESTAMP(last_access) - UNIX_TIMESTAMP('{$last}')) BETWEEN 0 and 86400";
     } else {
         $where_is .= (isset($where_is) ? " AND " : "") . "u.last_access ";
         if ($lasttype == "3") {
             $last2 = mkdate(trim($_GET['ls2']));
             if ($last2) {
                 $where_is .= " BETWEEN '{$last}' and '{$last2}'";
                 $q .= ($q ? "&amp;" : "") . "ls2={$last2}";
             } else {
                 stdmsg("Error", "The second date is not valid.");
                 stdfoot();
                 die;
             }
         } elseif ($lasttype == "1") {
             $where_is .= "< '{$last}'";
         } elseif ($lasttype == "2") {
             $where_is .= "> '{$last}'";
         }
     }
 }
function recvpayment()
{
    extract($_POST);
    $v = new validate();
    $v->isOk($cusnum, "num", 1, 10, "Invalid customer id.");
    $v->isOk($invid, "num", 1, 10, "Invalid invoice id.");
    $v->isOk($pcc, "float", 1, 40, "Invalid credit card amount.");
    $v->isOk($pcash, "float", 1, 40, "Invalid cash amount.");
    $v->isOk($pcheque, "float", 1, 40, "Invalid cheque amount.");
    $date = mkdate($pinv_year, $pinv_month, $pinv_day);
    $v->isOk($date, "date", 1, 1, "Invalid invoice date.");
    if ($v->isError()) {
        return details($_POST, $v->genErrors());
    }
    $amt = sprint($pcc + $pcash + $pcheque);
    $cus = qryCustomer($cusnum);
    $bank_acc = qryAccountsName("Cash on Hand");
    $OUT = "\n\t<table " . TMPL_tblDflts . ">\n\t<tr>\n\t\t<th colspan='2'>Payment Details</th>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Account</td>\n\t\t<td>{$bank_acc['topacc']}/{$bank_acc['accnum']} {$bank_acc['accname']}</td>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Date</td>\n\t\t<td valign='center'>{$date}</td>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Received from</td>\n\t\t<td valign='center'>{$cus['cusname']} {$cus['surname']}</td>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Description</td>\n\t\t<td valign='center'>POS Payment Received</td>\n\t</tr>\n\t<tr class='" . bg_class() . "'>\n\t\t<td>Amount</td>\n\t\t<td valign='center'>" . CUR . " {$amt}</td>\n\t</tr>\n\t</table>\n\n\t<form method='post' action='" . SELF . "'>\n\t<input type='hidden' name='key' value='recvpayment_write' />\n\t<input type='hidden' name='bank_acc' value='{$bank_acc['accid']}' />\n\t<input type='hidden' name='invid' value='{$invid}' />\n\t<input type='hidden' name='pcc' value='{$pcc}' />\n\t<input type='hidden' name='pcash' value='{$pcash}' />\n\t<input type='hidden' name='pcheque' value='{$pcheque}' />\n\t<input type='hidden' name='amt' value='{$amt}' />\n\t<input type='hidden' name='date' value='{$date}' />\n\t<input type='hidden' name='cusnum' value='{$cusnum}' />\n\t<input type='hidden' name='descript' value='POS Payment Received' />\n\n\t<input type='hidden' name='stkerr' value='{$stkerr}' />\n\t<input type='hidden' name='prev_cusnum' value='{$prev_cusnum}' />\n\t<input type='hidden' name='deptid' value='{$deptid}' />\n\t<input type='hidden' name='telno' value='{$telno}' />\n\t<input type='hidden' name='cordno' value='{$cordno}' />\n\t<input type='hidden' name='bar' value='{$bar}' />\n\t<input type='hidden' name='des' value='{$des}' />\n\t<input type='hidden' name='sel_frm' value='{$sel_frm}' />\n\t<input type='hidden' name='ordno' value='{$ordno}' />\n\t<input type='hidden' name='pinv_day' value='{$pinv_day}' />\n\t<input type='hidden' name='pinv_month' value='{$pinv_month}' />\n\t<input type='hidden' name='pinv_year' value='{$pinv_year}' />\n\t<input type='hidden' name='chrgvat' value='{$chrgvat}' />\n\t<input type='hidden' name='salespn' value='{$salespn}' />\n\t<input type='hidden' name='traddisc' value='{$traddisc}' />\n\t<input type='hidden' name='delchrg' value='{$delchrg}' />\n\t<input type='hidden' name='delvat' value='{$delvat}' />\n\t<input type='hidden' name='user' value='{$user}' />\n\t<input type='hidden' name='SUBTOT' value='{$subtot}' />\n\t<input type='hidden' name='comm' value='{$comm}' />\n\n\t<table " . TMPL_tblDflts . ">";
    // Connect to database
    db_connect();
    $sql = "SELECT invnum,invid,balance,terms,odate FROM invoices\n\t\t\tWHERE cusnum = '{$cusnum}' AND printed = 'y' AND balance>0\n\t\t\t\tAND div = '" . USER_DIV . "'\n\t\t\tORDER BY odate ASC";
    $prnInvRslt = db_exec($sql);
    $i = 0;
    while (($inv = pg_fetch_array($prnInvRslt)) && $amt > 0) {
        if ($i == 0) {
            $OUT .= "\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'>&nbsp;</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><h3>Outstanding Invoices</h3></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Invoice</th>\n\t\t\t\t<th>Outstanding Amount</th>\n\t\t\t\t<th>Terms</th>\n\t\t\t\t<th>Date</th>\n\t\t\t\t<th>Amount</th>\n\t\t\t</tr>";
        }
        $invid = $inv['invid'];
        $val = allocamt($amt, $inv["balance"]);
        $OUT .= "\n\t\t<input type='hidden' name='paidamt[{$invid}]' size=10 value='{$val}'>\n\t\t<input type='hidden' size=20 name=invids[{$invid}] value='{$inv['invid']}'>\n\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t<td>{$inv['invnum']}</td>\n\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t<td>{$inv['terms']} days</td>\n\t\t\t<td>{$inv['odate']}</td>\n\t\t\t<td>" . CUR . " {$val}</td>\n\t\t</tr>";
    }
    $sql = "SELECT invnum,invid,balance,sdate as odate FROM nons_invoices\n\t\t\tWHERE cusid='{$cusnum}' AND done='y' AND balance>0\n\t\t\t\tAND div='" . USER_DIV . "'\n\t\t\tORDER BY odate ASC";
    $prnInvRslt = db_exec($sql);
    while (($inv = pg_fetch_array($prnInvRslt)) && $amt > 0) {
        if ($i == 0) {
            $OUT .= "\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'>&nbsp;</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><h3>Outstanding Non-Stock Invoices</h3></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Invoice</th>\n\t\t\t\t<th>Outstanding Amount</th>\n\t\t\t\t<th></th>\n\t\t\t\t<th>Date</th>\n\t\t\t\t<th>Amount</th>\n\t\t\t</tr>";
        }
        $invid = $inv['invid'];
        $val = allocamt($amt, $inv["balance"]);
        $OUT .= "\n\t\t\t\t<input type='hidden' name='paidamt[{$invid}]' value='{$val}'>\n\t\t\t\t<input type='hidden' name='itype[{$invid}]' value='Yes'>\n\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t<td><input type='hidden' size='20' name='invids[{$invid}]' value='{$inv['invid']}'>{$inv['invnum']}</td>\n\t\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td>{$inv['odate']}</td>\n\t\t\t\t\t<td>" . CUR . " {$val}</td>\n\t\t\t\t</tr>";
    }
    $amt = sprint($amt);
    /* pos invoices */
    $sqls = array();
    for ($i = 1; $i <= 12; ++$i) {
        $sqls[] = "SELECT invnum,invid,balance,odate FROM \"{$i}\".pinvoices\n\t\t\t\t\tWHERE cusnum='{$cusnum}' AND done='y' AND balance>0\n\t\t\t\t\t\tAND div='" . USER_DIV . "'";
    }
    $sql = implode(" UNION ", $sqls);
    $prnInvRslt = db_exec($sql);
    if (pg_numrows($prnInvRslt) > 0) {
        $OUT .= "\n\t\t<tr>\n\t\t\t<td colspan='2'><br></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan='2'><h3>Outstanding POS Invoices</h3></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th>Invoice</th>\n\t\t\t<th>Outstanding Amount</th>\n\t\t\t<th></th>\n\t\t\t<th>Date</th>\n\t\t\t<th>Amount</th>\n\t\t</tr>";
        $i = 0;
        while ($inv = pg_fetch_array($prnInvRslt)) {
            $invid = $inv['invid'];
            $val = allocamt($amt, $inv["balance"]);
            $OUT .= "\n\t\t\t<input type='hidden' size='20' name='invids[{$invid}]' value='{$inv['invid']}'>\n\t\t\t<input type='hidden' name='paidamt[{$invid}]' size=10 value='{$val}'>\n\t\t\t<input type='hidden' name='ptype[{$invid}]' value='YnYn'>\n\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t<td>{$inv['invnum']}</td>\n\t\t\t\t<td>" . CUR . " {$inv['balance']}</td>\n\t\t\t\t<td></td>\n\t\t\t\t<td>{$inv['odate']}</td>\n\t\t\t\t<td>" . CUR . " {$val}</td>\n\t\t\t</tr>";
        }
    }
    if ($amt > 0) {
        /* START OPEN ITEMS */
        $ox = "";
        $sql = "SELECT * FROM cubit.open_stmnt WHERE balance>0 AND cusnum='{$cusnum}'\n\t\t\t\t\tAND type!='Invoice' AND type!='Non-Stock Invoice'\n\t\t\t\t\tAND type!='Interest on Outstanding balance'\n\t\t\t\tORDER BY date";
        $rslt = db_exec($sql) or errDie("Unable to get open items.");
        $open_out = $amt;
        $i = 0;
        while ($od = pg_fetch_array($rslt)) {
            if ($open_out == 0) {
                continue;
            }
            $oid = $od['id'];
            if ($open_out >= $od['balance']) {
                $open_amount[$oid] = $od['balance'];
                $open_out = sprint($open_out - $od['balance']);
                $ox .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><input type='hidden' size='20' name='open[{$oid}]' value='{$oid}'>{$od['type']}</td>\n\t\t\t\t\t<td>" . CUR . " {$od['balance']}</td>\n\t\t\t\t\t<td>{$od['date']}</td>\n\t\t\t\t\t<td><input type='hidden' name='open_amount[{$oid}]' value='{$open_amount[$oid]}'>" . CUR . " {$open_amount[$oid]}</td>\n\t\t\t\t</tr>";
            } elseif ($open_out < $od['balance']) {
                $open_amount[$oid] = $open_out;
                $open_out = 0;
                $ox .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><input type='hidden' size='20' name='open[{$oid}]' value='{$od['id']}'>{$od['type']}</td>\n\t\t\t\t\t<td>" . CUR . " {$od['balance']}</td>\n\t\t\t\t\t<td>{$od['date']}</td>\n\t\t\t\t\t<td><input type='hidden' name='open_amount[{$oid}]' value='{$open_amount[$oid]}'>" . CUR . " {$open_amount[$oid]}</td>\n\t\t\t\t</tr>";
            }
            $i++;
        }
        if (open()) {
            $OUT .= "\n\t\t\t" . TBL_BR . "\n\t\t\t<input type='hidden' name='bout' value='{$amt}'>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><h3>Outstanding Transactions</h3></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Description</th>\n\t\t\t\t<th>Outstanding Amount</th>\n\t\t\t\t<th>Date</th>\n\t\t\t\t<th>Amount</th>\n\t\t\t</tr>";
            $OUT .= $ox;
            $bout = $amt;
            $amt = $open_out;
            if ($amt > 0) {
                $OUT .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td colspan='4'><b>A general transaction will credit the client's account with " . CUR . " {$amt}</b></td>\n\t\t\t\t</tr>";
            }
            //$amt=$bout;
        } else {
            $OUT .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='4'><b>A general transaction will credit the client's account with " . CUR . " {$amt} </b></td>\n\t\t\t</tr>";
        }
    }
    $OUT .= "\n\t<input type='hidden' name='out' value='{$amt}' />\n\t<tr>\n\t\t<td colspan='5' align='right'>\n\t\t\t<input type='submit' name='btn_back' value='&laquo; Correction' />\n\t\t\t<input type='submit' value='Record Payment' />\n\t\t</td>\n\t</table>";
    return $OUT;
}
Example #10
0
 function profile()
 {
     global $set, $apx, $tmpl, $db, $user;
     if (!$_REQUEST['id']) {
         die('missing ID!');
     }
     $res = $db->first("SELECT a.userid,a.username,a.email,a.reg_time,a.reg_email,a.lastactive,b.name FROM " . PRE . "_user AS a LEFT JOIN " . PRE . "_user_groups AS b USING(groupid) WHERE a.userid='" . $_REQUEST['id'] . "'");
     $apx->tmpl->assign('USERID', $res['userid']);
     $apx->tmpl->assign('USERNAME', replace($res['username']));
     $apx->tmpl->assign('REGDATE', mkdate($res['reg_time']));
     $apx->tmpl->assign('REGEMAIL', replace($res['reg_email']));
     $apx->tmpl->assign('EMAIL', replace($res['email']));
     $apx->tmpl->assign('LASTACTIVE', mkdate($res['lastactive']));
     $apx->tmpl->assign('GROUPNAME', replace($res['name']));
     $apx->tmpl->parse('profile');
 }
function write($_POST)
{
    # Get vars
    extract($_POST);
    if (isset($noduty)) {
        $_POST["noduty"] = "yes";
    } else {
        $exd = "";
    }
    # Validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($letters, "string", 0, 5, "Invalid First 3 Letters.");
    $v->isOk($supid, "num", 1, 20, "Please Select Supplier.");
    $v->isOk($terms, "num", 1, 5, "Invalid terms days.");
    $v->isOk($ipur_day, "num", 1, 2, "Invalid Date day.");
    $v->isOk($ipur_month, "num", 1, 2, "Invalid Date month.");
    $v->isOk($ipur_year, "num", 1, 5, "Invalid Date year.");
    $v->isOk($del_day, "num", 1, 2, "Invalid Delivery Date day.");
    $v->isOk($del_month, "num", 1, 2, "Invalid Delivery Date month.");
    $v->isOk($del_year, "num", 1, 5, "Invalid Delivery Date year.");
    //$v->isOk ($curr, "string", 1, 20, "Invalid Foreign currency.");
    $v->isOk($xrate, "float", 1, 20, "Invalid Exchange Rate.");
    $v->isOk($tax, "float", 0, 20, "Invalid Tax.");
    $v->isOk($shipchrg, "float", 0, 20, "Invalid Shipping Charges.");
    $v->isOk($remarks, "string", 0, 255, "Invalid Remarks.");
    $pdate = mkdate($ipur_year, $ipur_month, $ipur_day);
    $v->isOk($pdate, "date", 1, 1, "Invalid purchase date.");
    $ddate = mkdate($del_year, $del_month, $del_day);
    $v->isOk($ddate, "date", 1, 1, "Invalid delivery date.");
    # Used to generate errors
    $error = "asa@";
    # Check quantities
    if (isset($qtys)) {
        foreach ($qtys as $keys => $qty) {
            $v->isOk($qty, "float", 1, 15, "Invalid Quantity for product number : <b>" . ($keys + 1) . "</b>");
            $v->isOk($unitcost[$keys], "float", 0, 20, "Invalid Unit Price for product number : <b>" . ($keys + 1) . "</b>.");
            $v->isOk($cunitcost[$keys], "float", 0, 20, "Invalid Foreign currency Unit Price for product number : <b>" . ($keys + 1) . "</b>.");
            $v->isOk($duty[$keys], "float", 0, 20, "Invalid Duty Charges for product number : <b>" . ($keys + 1) . "</b>.");
            $v->isOk($dutyp[$keys], "float", 0, 20, "Invalid Duty Charges Percentage for product number : <b>" . ($keys + 1) . "</b>.");
            if ($qty < 1) {
                $v->isOk($qty, "num", 0, 0, "Error : Item Quantity must be at least one. Product number : <b>" . ($keys + 1) . "</b>");
            }
            # Nasty Zeros
            $unitcost[$keys] += 0;
            $cunitcost[$keys] += 0;
            $duty[$keys] += 0;
            $dutyp[$keys] += 0;
        }
    }
    # Check whids
    if (isset($whids)) {
        foreach ($whids as $keys => $whid) {
            $v->isOk($whid, "num", 1, 10, "Invalid Store number, please enter all details.");
        }
    }
    # Check stkids
    if (isset($stkids)) {
        foreach ($stkids as $keys => $stkid) {
            $v->isOk($stkid, "num", 1, 10, "Invalid Stock number, please enter all details.");
        }
    }
    # Check amt
    if (isset($amt)) {
        foreach ($amt as $keys => $amount) {
            $v->isOk($amount, "float", 1, 20, "Invalid Amount, please enter all details.");
        }
    }
    # Display errors, if any
    $err = "";
    if ($v->isError()) {
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $_POST['done'] = "";
        return details($_POST, $err);
    }
    # Get Order info
    db_connect();
    $sql = "SELECT * FROM purch_int WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $purRslt = db_exec($sql) or errDie("Unable to get Order information");
    if (pg_numrows($purRslt) < 1) {
        return "<li>- Order Not Found</li>";
    }
    $pur = pg_fetch_array($purRslt);
    # check if Order has been printed
    if ($pur['received'] == "y") {
        $error = "<li class='err'> Error : Order number <b>{$purid}</b> has already been received.</li>";
        $error .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $error;
    }
    # Get selected customer info
    db_connect();
    $sql = "SELECT * FROM suppliers WHERE supid = '{$supid}' AND div = '" . USER_DIV . "'";
    $supRslt = db_exec($sql) or errDie("Unable to get customer information");
    if (pg_numrows($supRslt) < 1) {
        // code here
    } else {
        $sup = pg_fetch_array($supRslt);
    }
    $pur['deptid'] = $sup['deptid'];
    # If supplier was just selected/changed, get the following
    if ($pur['supid'] != $supid) {
        $xrate = getRate($sup['fcid']);
    }
    # currency
    $currs = getSymbol($sup['fcid']);
    $curr = $currs['symbol'];
    # get department
    db_conn("exten");
    $sql = "SELECT * FROM departments WHERE deptid = '{$pur['deptid']}' AND div = '" . USER_DIV . "'";
    $deptRslt = db_exec($sql);
    if (pg_numrows($deptRslt) < 1) {
        $dept['deptname'] = "<i class='err'>Not Found</i>";
    } else {
        $dept = pg_fetch_array($deptRslt);
    }
    # fix those nasty zeros
    $xrate += 0;
    if ($xrate == 0) {
        $xrate = 1;
    }
    $shipchrg += 0;
    $tax += 0;
    # insert Order to DB
    db_connect();
    # begin updating
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    /* -- Start remove old items -- */
    # get selected stock in this Order
    $sql = "SELECT * FROM purint_items  WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
    $stktRslt = db_exec($sql);
    while ($stkt = pg_fetch_array($stktRslt)) {
        # update stock(ordered - qty)
        $sql = "UPDATE stock SET ordered = (ordered - '{$stkt['qty']}')  WHERE stkid = '{$stkt['stkid']}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF);
    }
    # remove old items
    $sql = "DELETE FROM purint_items WHERE purid='{$purid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update Order items in Cubit.", SELF);
    /* -- End remove old items -- */
    if (isset($qtys)) {
        foreach ($qtys as $keys => $value) {
            if (isset($remprod)) {
                if (in_array($keys, $remprod)) {
                    # skip product (wonder if $keys still align)
                    $amt[$keys] = 0;
                    continue;
                } else {
                    # get selamt from selected stock
                    $sql = "SELECT * FROM stock WHERE stkid = '{$stkids[$keys]}' AND div = '" . USER_DIV . "'";
                    $stkRslt = db_exec($sql);
                    $stk = pg_fetch_array($stkRslt);
                    # Calculate the unitcost
                    if ($cunitcost[$keys] > 0) {
                        $unitcost[$keys] = round($cunitcost[$keys] * $xrate, 2);
                    } else {
                        $cunitcost[$keys] = round($unitcost[$keys] / $xrate, 2);
                    }
                    # Calculate the duty amount
                    if ($duty[$keys] < 1) {
                        if ($dutyp[$keys] > 0) {
                            $duty[$keys] = round($dutyp[$keys] / 100 * $cunitcost[$keys] / $xrate, 2);
                        }
                    } else {
                        if ($unitcost[$keys] > 0) {
                            $dutyp[$keys] = round($duty[$keys] * 100 / $cunitcost[$keys] * $xrate, 2);
                        } else {
                            $dutyp[$keys] = 0;
                        }
                    }
                    # Calculate amount
                    $amt[$keys] = $qtys[$keys] * $cunitcost[$keys] + $duty[$keys];
                    # insert Order items
                    $sql = "INSERT INTO purint_items(purid, whid, stkid, qty, unitcost, cunitcost, duty, dutyp, amt, ddate, recved, div) VALUES('{$purid}', '{$whids[$keys]}', '{$stkids[$keys]}', '{$qtys[$keys]}', '{$unitcost[$keys]}', '{$cunitcost[$keys]}', '{$duty[$keys]}', '{$dutyp[$keys]}', '{$amt[$keys]}', '{$ddate}', 'n', '" . USER_DIV . "')";
                    $rslt = db_exec($sql) or errDie("Unable to insert Order items to Cubit.", SELF);
                    # update stock(ordered + qty)
                    $sql = "UPDATE stock SET ordered = (ordered + '{$qtys[$keys]}') WHERE stkid = '{$stkids[$keys]}' AND div = '" . USER_DIV . "'";
                    $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF);
                }
            } else {
                # Get csprice from selected stock
                $sql = "SELECT * FROM stock WHERE stkid = '{$stkids[$keys]}' AND div = '" . USER_DIV . "'";
                $stkRslt = db_exec($sql);
                $stk = pg_fetch_array($stkRslt);
                # Calculate the unitcost
                if ($cunitcost[$keys] > 0) {
                    $unitcost[$keys] = round($cunitcost[$keys] * $xrate, 2);
                } else {
                    $cunitcost[$keys] = round($unitcost[$keys] / $xrate, 2);
                }
                # Calculate the duty amount
                if ($duty[$keys] < 1) {
                    if ($dutyp[$keys] > 0) {
                        $duty[$keys] = round($dutyp[$keys] / 100 * $unitcost[$keys] / $xrate, 2);
                    }
                } else {
                    if ($unitcost[$keys] > 0) {
                        $dutyp[$keys] = round($duty[$keys] * 100 / $unitcost[$keys] * $xrate, 2);
                    } else {
                        $dutyp[$keys] = 0;
                    }
                }
                # Calculate amount
                $amt[$keys] = $qtys[$keys] * $cunitcost[$keys] + $duty[$keys];
                # Insert Order items
                $sql = "\n\t\t\t\t\tINSERT INTO purint_items (\n\t\t\t\t\t\tpurid, whid, stkid, qty, unitcost, \n\t\t\t\t\t\tcunitcost, duty, dutyp, amt, ddate, recved, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$purid}', '{$whids[$keys]}', '{$stkids[$keys]}', '{$qtys[$keys]}', '{$unitcost[$keys]}', \n\t\t\t\t\t\t'{$cunitcost[$keys]}', '{$duty[$keys]}', '{$dutyp[$keys]}', '{$amt[$keys]}', '{$ddate}', 'n', '" . USER_DIV . "'\n\t\t\t\t\t)";
                $rslt = db_exec($sql) or errDie("Unable to insert Order items to Cubit.", SELF);
                # Update stock(ordered + qty)
                $sql = "UPDATE stock SET ordered = (ordered + '{$qtys[$keys]}') WHERE stkid = '{$stkids[$keys]}' AND div = '" . USER_DIV . "'";
                $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF);
            }
            # Everything is set place done button
            $_POST["done"] = "&nbsp; | &nbsp;<input name='doneBtn' type='submit' value='Done'>\n\t\t\t&nbsp; | &nbsp;<input type='submit' name='donePrnt' value='Done, Print and make another'>";
        }
    } else {
        $_POST["done"] = "";
    }
    /* --- Clac --- */
    # Calculate subtot
    if (isset($amt)) {
        $SUBTOT = array_sum($amt);
    } else {
        $SUBTOT = 0.0;
    }
    # shipchrg is in for curr
    $fshipchrg = $shipchrg;
    // $shipchrg = ($shipchrg * $xrate);
    # total
    $TOTAL = sprint($SUBTOT + $shipchrg + $tax);
    # total Duty
    if (isset($duty)) {
        $dutytot = sprint(array_sum($duty));
    } else {
        $dutytot = "0.00";
    }
    # Local Totals
    $LTOTAL = sprint($TOTAL * $xrate);
    $LSUBTOT = sprint($SUBTOT * $xrate);
    /* --- End Clac --- */
    # Insert Order to DB
    $sql = "\n\t\tUPDATE purch_int \n\t\tSET supid = '{$supid}', supaddr = '{$sup['supaddr']}', terms = '{$terms}', pdate = '{$pdate}', ddate = '{$ddate}',\n\t\t\tfcid = '{$sup['fcid']}', currency = '{$curr}', curr = '{$curr}', tax = '{$tax}', xrate = '{$xrate}', \n\t\t\tfshipchrg = '{$fshipchrg}', shipchrg = '{$shipchrg}', duty = '{$dutytot}', subtot = '{$SUBTOT}',\n\t\t\ttotal = '{$TOTAL}', balance = '{$TOTAL}', fsubtot = '{$LSUBTOT}', fbalance = '{$LTOTAL}', remarks = '{$remarks}',\n\t\t\tjobnum='{$delvat}', deptid = '{$dept['deptid']}' \n\t\tWHERE purid = '{$purid}'";
    $rslt = db_exec($sql) or errDie("Unable to update Order in Cubit.", SELF);
    # Commit updating
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    $lastid = pglib_lastid("purch_int", "purid");
    // Was Done, Print and make another selected
    if (isset($donePrnt)) {
        $sql = "UPDATE purch_int SET done='y' WHERE purid='{$purid}' AND div='" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update Order status in Cubit.");
        $OUTPUT = "<script>printer('purch-int-det.php?purid={$lastid}');move('purch-int-new.php');</script>";
        return $OUTPUT;
    }
    if (!isset($doneBtn)) {
        return details($_POST);
    } else {
        # Insert Order to DB
        $sql = "UPDATE purch_int SET done = 'y' WHERE purid = '{$purid}' AND div = '" . USER_DIV . "'";
        $rslt = db_exec($sql) or errDie("Unable to update Order status in Cubit.", SELF);
        // Final Laytout
        $write = "\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>New International Order</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Order from Supplier <b>{$sup['supname']}</b> has been recorded.</td>\n\t\t\t\t\t<td><a href='purch-int-det.php?purid={$lastid}'>Print Order</a></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='purch-int-view.php'>View International Orders</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t</table>";
        return $write;
    }
}
function update($_POST)
{
    extract($_POST);
    $collect_ar = array();
    if (!empty($client_collect)) {
        $collect_ar[] = "Client Collect";
    }
    if (!empty($collect)) {
        $collect_ar[] = "Collect";
    }
    if (!empty($deliver)) {
        $collect_ar[] = "Deliver";
    }
    $collection = implode(", ", $collect_ar);
    // 	if ((in_array("Collect", $collect_ar) && in_array("Client Collect", $collect_ar))
    // 		|| (count($collect_ar) == 3)) {
    // 		return "<li class='err'>Invalid collection options selected.</li>";
    // 	}
    if (count($collect_ar) > 1 && in_array("Client Collect", $collect_ar)) {
        return "<li class='err'>Invalid collection options selected.</li>";
    }
    $temp_assets = explode(",", $temp_assets);
    pglib_transaction("BEGIN");
    if (isset($nhalf_day) && $nhalf_day == "checked") {
        $nhalf_day = 1;
    } else {
        $nhalf_day = 0;
    }
    if (isset($nweekends) && $nweekends == "checked") {
        $nweekends = 1;
    } else {
        $nweekends = 0;
    }
    $sql = "UPDATE hire.hire_invoices SET comm='{$comm}' WHERE invid='{$invid}'";
    $comm_rslt = db_exec($sql) or errDie("Unable to retrieve invoice.");
    foreach ($temp_assets as $key => $value) {
        $sql = "SELECT * FROM cubit.assets WHERE id='{$key}'";
        $asset_rslt = db_exec($sql) or errDie("Unable to retrieve asset.");
        $asset_data = pg_fetch_array($asset_rslt);
    }
    if (isset($amount)) {
        foreach ($amount as $key => $value) {
            // 			if (empty($monthly)) {
            // 				$amount[$key] = "";
            // 			}
            if (!user_is_admin(USER_ID)) {
                $amount[$key] = "";
            }
            if (!isset($half_day[$key]) || empty($half_day[$key])) {
                $half_day[$key] = 0;
            }
            if (!isset($weekends[$key]) || empty($weekends[$key])) {
                $weekends[$key] = 0;
            } else {
                $weekends[$key] = 1;
            }
            if (empty($amount[$key]) && $amount != "0") {
                if ($basis[$key] == "per_day") {
                    $hifrm = "{$mfrm_year[$key]}-{$mfrm_month[$key]}-{$mfrm_day[$key]}";
                    $hito = "{$mto_year[$key]}-{$mto_month[$key]}-{$mto_day[$key]}";
                    $hours = "0";
                    /* calculate amount */
                    $ftime = getDTEpoch("{$hifrm} 0:00:00");
                    $ttime = getDTEpoch("{$hito} 0:00:00");
                    $days = 0;
                    $weeks = 0;
                    while ($ftime <= $ttime) {
                        if (date("w", $ftime) == 0 && isset($weekends[$key]) && $weekends[$key]) {
                            $days += 0.6;
                        } else {
                            ++$days;
                        }
                        $ftime += 24 * 60 * 60;
                    }
                    if (is_numeric($rain_days[$key])) {
                        $days -= $rain_days[$key];
                    }
                    $timeunits = $days;
                } else {
                    if ($basis[$key] == "per_hour") {
                        $hifrm = $hito = mkdate($pinv_year, $pinv_month, $pinv_day);
                        $timeunits = $hours;
                        $weeks = 0;
                        if (empty($hours) || !is_numeric($hours)) {
                            return "\r\n\t\t\t\t\t\t\t<li class='err'>\r\n\t\t\t\t\t\t\t\t<b>ERROR</b>: Invalid amount of hours.\r\n\t\t\t\t\t\t\t</li>";
                        }
                    } else {
                        if ($nbasis == "per_week") {
                            $nhifrm = $nhito = mkdate($pinv_year, $pinv_month, $pinv_day);
                            $timeunits = $weeks;
                            $hours = 0;
                            if (empty($weeks) || !is_numeric($weeks)) {
                                return "\r\n\t\t\t\t\t\t\t<li class='err'>\r\n\t\t\t\t\t\t\t\t<b>ERROR</b>: Invalid amount of weeks.\r\n\t\t\t\t\t\t\t</li>";
                            }
                        }
                    }
                }
                if ($half_day[$key]) {
                    $amount[$key] = $qty[$key] * $timeunits * (basisPrice($cusnum, $asset_id[$key], $basis[$key]) * $qty[$key]) - basisPrice($cusnum, $asset_id[$key], $basis[$key]) * $qty[$key] + basisPrice($cusnum, $asset_id[$key], $basis[$key]) * $qty[$key] / 2;
                } else {
                    $amount[$key] = $qty[$key] * $timeunits * basisPrice($cusnum, $asset_id[$key], $basis[$key]);
                }
            }
            if ($amount[$key] == 0) {
                $amount[$key] = 0;
                $blank_amount = 1;
            } else {
                $blank_amount = 0;
            }
            $sql = "UPDATE hire.hire_invitems SET amt='{$amount[$key]}',\r\n\t\t\t\t\t\thalf_day='{$half_day[$key]}', weekends='{$weekends[$key]}'\r\n\t\t\t\t\tWHERE id='{$key}'";
            db_exec($sql) or errDie("Unable to update item amount.");
            $sql = "UPDATE hire.reprint_invitems SET amt='{$amount[$key]}',\r\n\t\t\t\t\t\thalf_day='{$half_day[$key]}', weekends='{$weekends[$key]}'\r\n\t\t\t\t\tWHERE item_id='{$key}'";
            db_exec($sql) or errDie("Unable to update return item amount.");
            if ($blank_amount) {
                $amount[$key] = "";
            }
            //$hifrm = "$hifrm_year[$key]-$hifrm_month[$key]-$hifrm_day[$key]";
            //$hito = "$hito_year[$key]-$hito_month[$key]-$hito_day[$key]";
            if (!isset($remove[$key])) {
                $sql = "SELECT basis FROM hire.hire_invitems WHERE id='{$key}'";
                $item_rslt = db_exec($sql) or errDie("Unable to retrieve basis.");
                $mbasis = pg_fetch_result($item_rslt, 0);
                /* determine time units */
                if ($mbasis == "per_day") {
                    $mfrm = mkdate($mfrm_year[$key], $mfrm_month[$key], $mfrm_day[$key]);
                    $mto = mkdate($mto_year[$key], $mto_month[$key], $mto_day[$key]);
                    /* calculate amount */
                    $ftime = mktime(0, 0, 0, $mfrm_month[$key], $mfrm_day[$key], $mfrm_year[$key]);
                    $ttime = mktime(0, 0, 0, $mto_month[$key], $mto_day[$key], $mto_year[$key]);
                    $days = 0;
                    if (empty($weeks)) {
                        $weeks = 0;
                    }
                    if (empty($hours)) {
                        $hours = 0;
                    }
                    while ($ftime <= $ttime) {
                        if (date("w", $ftime) == 0 && isset($weekends[$key]) && $weekends[$key]) {
                            $days += 0.6;
                        } else {
                            ++$days;
                        }
                        $ftime += 24 * 60 * 60;
                    }
                    $timeunits = $days;
                    $sql = "UPDATE hire.hire_invitems\r\n\t\t\t\t\t\t\tSET from_date='{$mfrm}', to_date='{$mto}'\r\n\t\t\t\t\t\t\tWHERE id='{$key}'";
                    db_exec($sql) or errDie("Unable to update items.");
                    $sql = "UPDATE hire.reprint_invitems\r\n\t\t\t\t\t\t\tSET from_date='{$mfrm}', to_date='{$mto}'\r\n\t\t\t\t\t\t\tWHERE item_id='{$key}'";
                    db_exec($sql) or errDie("Unable to update reprint items.");
                }
            } else {
                // Delete the old items
                $sql = "DELETE FROM hire.hire_invitems WHERE id='{$key}'";
                db_exec($sql) or errDie("Unable to remove old items.");
                $sql = "DELETE FROM hire.reprint_invitems WHERE item_id='{$key}'";
                db_exec($sql) or errDie("Unable to remove old reprint items.");
                //.Remove if the item has been hired as well
                $sql = "DELETE FROM hire.assets_hired WHERE item_id='{$key}'";
                db_exec($sql) or errDie("Unable to remove items from hired log.");
            }
        }
    }
    $sql = "SELECT * FROM hire.hire_invoices WHERE invid='{$invid}'";
    $hi_rslt = db_exec($sql) or errDie("Unable to retrieve invoice.");
    $invb = pg_fetch_array($hi_rslt);
    // Insert new items
    if ($nasset_id != "0" || $nbasis != "0") {
        if ($nasset_id == "0") {
            return "<li class='err'><b>ERROR</b>: No asset selected.</li>";
        }
        /* get asset id */
        list($serialqty, $nasset_id) = explode(":", $nasset_id);
        /* disabled items don't get passed through */
        if ($serialqty == "s" || !isset($nqty)) {
            $nqty = "1";
        } else {
            $sql = "SELECT serial2 FROM cubit.assets WHERE id='{$nasset_id}'";
            $dqty_rslt = db_exec($sql) or errDie("Unable to retrieve assets.");
            $dqty = pg_fetch_result($dqty_rslt, 0);
            if ($dqty - $nqty < 0) {
                return "<li class='err'><b>ERROR</b>: Invalid quantity. Only &nbsp; <b>{$dqty}</b> &nbsp; available.</li>";
            }
        }
        if (empty($nqty) || !is_numeric($nqty)) {
            return "<li class='err'><b>ERROR</b>: Invalid quantity</li>";
        }
        /* determine time units */
        if ($nbasis == "per_day") {
            $nhifrm = mkdate($nhifrm_year, $nhifrm_month, $nhifrm_day);
            $nhito = mkdate($nhito_year, $nhito_month, $nhito_day);
            $hours = "0";
            /* calculate amount */
            $ftime = mktime(0, 0, 0, $nhifrm_month, $nhifrm_day, $nhifrm_year);
            $ttime = mktime(0, 0, 0, $nhito_month, $nhito_day, $nhito_year);
            $days = 0;
            $weeks = 0;
            while ($ftime <= $ttime) {
                if (date("w", $ftime) == 0 && isset($nweekends) && $nweekends) {
                    $days += 0.6;
                } else {
                    ++$days;
                }
                $ftime += 24 * 60 * 60;
            }
            $timeunits = $days;
        } else {
            if ($nbasis == "per_hour") {
                $nhifrm = $nhito = mkdate($pinv_year, $pinv_month, $pinv_day);
                $timeunits = $hours;
                $weeks = 0;
                if (empty($hours) || !is_numeric($hours)) {
                    return "<li class='err'><b>ERROR</b>: Invalid amount of hours.</li>";
                }
            } else {
                if ($nbasis == "per_week") {
                    $nhifrm = $nhito = mkdate($pinv_year, $pinv_month, $pinv_day);
                    $timeunits = $weeks;
                    $hours = 0;
                    if (empty($weeks) || !is_numeric($weeks)) {
                        return "<li class='err'><b>ERROR</b>: Invalid amount of weeks.</li>";
                    }
                } else {
                    return "<li class='err'><b>ERROR</b>: No basis selected.</li>";
                }
            }
        }
        /* calculate amount according to hire settings, quantity and time units */
        if ($nhalf_day) {
            $camt = $nqty * $timeunits * basisPrice($cusnum, $nasset_id, $nbasis) - basisPrice($cusnum, $nasset_id, $nbasis) + basisPrice($cusnum, $nasset_id, $nbasis) / 2;
        } else {
            $camt = $nqty * $timeunits * basisPrice($cusnum, $nasset_id, $nbasis);
        }
        /* insert item */
        $sql = "SELECT asset_id FROM hire.hire_invitems WHERE invid='{$invid}' AND asset_id='{$nasset_id}'";
        $asset_rslt = db_exec($sql) or errDie("Unable to retrieve assets.");
        // No duplicate assets
        if (!pg_num_rows($asset_rslt)) {
            if (isHired($nasset_id)) {
                return "\r\n\t\t\t\t<li class='err'>\r\n\t\t\t\t\t<b>ERROR</b>: Asset has already hired out.\r\n\t\t\t\t</li>";
            }
            $sql = "\r\n\t\t\t\tINSERT INTO hire.hire_invitems (\r\n\t\t\t\t\tinvid, asset_id, qty, amt, from_date, to_date, basis, hours, weeks, \r\n\t\t\t\t\tcollection, half_day, weekends\r\n\t\t\t\t) VALUES (\r\n\t\t\t\t\t'{$invid}', '{$nasset_id}', '{$nqty}', '{$camt}', '{$nhifrm}', '{$nhito}', '{$nbasis}', '{$hours}', '{$weeks}', \r\n\t\t\t\t\t'{$collection}', '{$nhalf_day}', '{$nweekends}'\r\n\t\t\t\t)";
            db_exec($sql) or errDie("Unable to create new invoice item.");
            $item_id = pglib_lastid("hire.hire_invitems", "id");
            $sql = "\r\n\t\t\t\tINSERT INTO hire.reprint_invitems (\r\n\t\t\t\t\tinvid, asset_id, qty, amt, from_date, to_date, basis, hours, weeks, \r\n\t\t\t\t\tcollection, half_day, weekends, item_id\r\n\t\t\t\t) VALUES (\r\n\t\t\t\t\t'{$invid}', '{$nasset_id}', '{$nqty}', '{$camt}', '{$nhifrm}', '{$nhito}', '{$nbasis}', '{$hours}', '{$weeks}', \r\n\t\t\t\t\t'{$collection}', '{$nhalf_day}', '{$nweekends}', '{$item_id}'\r\n\t\t\t\t)";
            db_exec($sql) or errDie("Unable to create reprint invoice item.");
        }
    }
    if ($monthly == "true") {
        $sql = "DELETE FROM hire.monthly_invitems WHERE invid='{$invid}'";
        db_exec($sql) or errDie("Unable to remove monthly items.");
    } else {
        $sql = "SELECT * FROM hire.hire_invitems WHERE invid='{$invid}'";
        $mii_rslt = db_exec($sql) or errDie("Unable to retrieve inv items.");
        $sql = "DELETE FROM hire.monthly_invitems WHERE invid='{$invid}'";
        db_exec($sql) or errDie("Unable to remove monthly items.");
        while ($item = pg_fetch_array($mii_rslt)) {
            $sql = "\r\n\t\t\t\tINSERT INTO hire.monthly_invitems (\r\n\t\t\t\t\tinvid, asset_id, qty, amt, from_date, to_date, \r\n\t\t\t\t\tbasis, hours, weeks, collection, half_day, \r\n\t\t\t\t\tweekends, item_id\r\n\t\t\t\t) VALUES (\r\n\t\t\t\t\t'{$item['invid']}', '{$item['asset_id']}', '{$item['qty']}', '{$item['amt']}', '{$item['from_date']}', '{$item['to_date']}', \r\n\t\t\t\t\t'{$item['basis']}', '{$item['hours']}', '{$item['weeks']}', '{$item['collection']}', '{$item['half_day']}', \r\n\t\t\t\t\t'{$item['weekends']}', '{$item['id']}'\r\n\t\t\t\t)";
            db_exec($sql) or errDie("Unable to create monthly items.");
        }
    }
    $sql = "SELECT * FROM hire.reprint_invoices WHERE invid='{$invid}'";
    $ri_rslt = db_exec($sql) or errDie("Unable to retrieve reprints.");
    // Create a new entry, or update
    if (pg_num_rows($ri_rslt)) {
        $sql = "\r\n\t\t\tUPDATE hire.reprint_invoices \r\n\t\t\tSET deptid='{$invb['deptid']}', cusnum='{$invb['cusnum']}', deptname='{$invb['deptname']}', cusacc='{$invb['cusacc']}', \r\n\t\t\t\tcusname='{$invb['cusname']}', surname='{$invb['surname']}', cusaddr='{$invb['cusaddr']}', cusvatno='{$invb['cusvatno']}', \r\n\t\t\t\tcordno='{$invb['cordno']}', ordno='{$invb['ordno']}', chrgvat='{$invb['chrgvat']}', terms='{$invb['terms']}', \r\n\t\t\t\ttraddisc='{$invb['traddisc']}', salespn='{$invb['salespn']}', odate='{$invb['odate']}', delchrg='{$invb['delchrg']}', \r\n\t\t\t\tsubtot='{$invb['subtot']}', vat='{$invb['vat']}', total='{$invb['total']}', balance='{$invb['balance']}', \r\n\t\t\t\tcomm='{$invb['comm']}', printed='{$invb['printed']}', done='{$invb['done']}', div='{$invb['div']}', \r\n\t\t\t\tusername='******'username']}', rounding='{$invb['rounding']}', delvat='{$invb['delvat']}', vatnum='{$invb['vatnum']}', \r\n\t\t\t\tpcash='{$invb['pcash']}', pcheque='{$invb['pcheque']}', pcc='{$invb['pcc']}', pcredit='{$invb['pcredit']}' \r\n\t\t\tWHERE invid='{$invid}'";
        db_exec($sql) or errDie("Unable to update reprint.");
    } else {
        $sql = "\r\n\t\t\tINSERT INTO hire.reprint_invoices(\r\n\t\t\t\tinvid, invnum, deptid, cusnum, deptname, cusacc, \r\n\t\t\t\tcusname, surname, cusaddr, cusvatno, cordno, ordno, \r\n\t\t\t\tchrgvat, terms, traddisc, salespn, odate, delchrg, \r\n\t\t\t\tsubtot, vat, total, balance, comm, printed, done, div, \r\n\t\t\t\tusername, rounding, delvat, vatnum, pcash, pcheque, \r\n\t\t\t\tpcc, pcredit\r\n\t\t\t) VALUES (\r\n\t\t\t\t'{$invid}', '{$invb['invnum']}', '{$invb['deptid']}', '{$invb['cusnum']}', '{$invb['deptname']}', '{$invb['cusacc']}', \r\n\t\t\t\t'{$invb['cusname']}', '{$invb['surname']}', '{$invb['cusaddr']}', '{$invb['cusvatno']}', '{$invb['cordno']}', '{$invb['ordno']}', \r\n\t\t\t\t'{$invb['chrgvat']}', '{$invb['terms']}', '{$invb['traddisc']}', '{$invb['salespn']}', '{$invb['odate']}', '{$invb['delchrg']}', \r\n\t\t\t\t'{$invb['subtot']}', '{$invb['vat']}' , '{$invb['total']}', '{$invb['balance']}', '{$invb['comm']}', 'y', 'y', '" . USER_DIV . "', \r\n\t\t\t\t'" . USER_NAME . "', '{$invb['rounding']}', '{$invb['delvat']}', '{$invb['vatnum']}', '{$invb['pcash']}', '{$invb['pcheque']}', \r\n\t\t\t\t'{$invb['pcc']}', '{$invb['pcredit']}'\r\n\t\t\t)";
        db_exec($sql) or errDie("Unable to add reprint.");
    }
    $sql = "SELECT * FROM hire.monthly_invoices\r\n\t\t\tWHERE invid='{$invid}' OR invnum='{$invb['invnum']}'";
    $mi_rslt = db_exec($sql) or errDie("Unable to retrieve monthly.");
    // Should we create a new entry
    if (pg_num_rows($mi_rslt)) {
        $sql = "\r\n\t\t\tUPDATE hire.monthly_invoices \r\n\t\t\tSET deptid='{$invb['deptid']}', cusnum='{$invb['cusnum']}', deptname='{$invb['deptname']}', cusacc='{$invb['cusacc']}', \r\n\t\t\t\tcusname='{$invb['cusname']}', surname='{$invb['surname']}', cusaddr='{$invb['cusaddr']}', cusvatno='{$invb['cusvatno']}', \r\n\t\t\t\tcordno='{$invb['cordno']}', ordno='{$invb['ordno']}', chrgvat='{$invb['chrgvat']}', terms='{$invb['terms']}', \r\n\t\t\t\ttraddisc='{$invb['traddisc']}', salespn='{$invb['salespn']}', odate='{$invb['odate']}', delchrg='{$invb['delchrg']}', \r\n\t\t\t\tsubtot='{$invb['subtot']}', vat='{$invb['vat']}', total='{$invb['total']}', balance='{$invb['balance']}', \r\n\t\t\t\tcomm='{$invb['comm']}', printed='{$invb['printed']}', done='{$invb['done']}', div='{$invb['div']}', \r\n\t\t\t\tusername='******'username']}', rounding='{$invb['rounding']}', delvat='{$invb['delvat']}', vatnum='{$invb['vatnum']}', \r\n\t\t\t\tpcash='{$invb['pcash']}', pcheque='{$invb['pcheque']}', pcc='{$invb['pcc']}', pcredit='{$invb['pcredit']}', \r\n\t\t\t\thire_invid='{$invid}' \r\n\t\t\tWHERE invid='{$invb['invid']}'";
    } elseif (empty($monthly)) {
        $sql = "\r\n\t\t\t\tINSERT INTO hire.monthly_invoices (\r\n\t\t\t\t\tinvid, invnum, deptid, cusnum, deptname, cusacc, \r\n\t\t\t\t\tcusname, surname, cusaddr, cusvatno, cordno, \r\n\t\t\t\t\tordno, chrgvat, terms, traddisc, salespn, odate, \r\n\t\t\t\t\tdelchrg, subtot, vat, total, balance, comm, \r\n\t\t\t\t\tprinted, done, div, username, rounding, delvat, vatnum, \r\n\t\t\t\t\tpcash, pcheque, pcc, pcredit, invoiced_month, hire_invid\r\n\t\t\t\t) VALUES (\r\n\t\t\t\t\t'{$invid}', '{$invb['invnum']}', '{$invb['deptid']}', '{$invb['cusnum']}', '{$invb['deptname']}', '{$invb['cusacc']}', \r\n\t\t\t\t\t'{$invb['cusname']}', '{$invb['surname']}', '{$invb['cusaddr']}', '{$invb['cusvatno']}', '{$invb['cordno']}', \r\n\t\t\t\t\t'{$invb['ordno']}', '{$invb['chrgvat']}', '{$invb['terms']}', '{$invb['traddisc']}', '{$invb['salespn']}', '{$invb['odate']}', \r\n\t\t\t\t\t'{$invb['delchrg']}', '{$invb['subtot']}', '{$invb['vat']}' , '{$invb['total']}', '{$invb['balance']}', '{$invb['comm']}', \r\n\t\t\t\t\t'y', 'y', '" . USER_DIV . "', '" . USER_NAME . "', '{$invb['rounding']}', '{$invb['delvat']}', '{$invb['vatnum']}', \r\n\t\t\t\t\t'{$invb['pcash']}', '{$invb['pcheque']}', '{$invb['pcc']}', '{$invb['pcredit']}', '" . date("m") . "', '{$invid}'\r\n\t\t\t\t)";
    }
    db_exec($sql) or errDie("Unable to store monthly invoice.");
    pglib_transaction("COMMIT");
    if (isset($upBtn)) {
        if ($upBtn == "Return") {
            return returnHire();
        } elseif ($upBtn == "Invoice") {
            return invoiceHire();
        }
    }
    return false;
}
Example #13
0
<?php

if (!preg_match("/index.php/", $REQUEST_URI)) {
    die("Direct Open not allowed.");
}
if ($login[id]) {
    $lastvisit = mkdate($login[last_avtiv]);
    if ($tab[forum_post]) {
        list($newforum) = $db->query("SELECT COUNT(id) FROM {$tab['forum_post']} WHERE settime>='{$login['last_forum_read']}' AND aut_id<>'{$login['id']}'");
    } else {
        $newforum = "N/A";
    }
    if ($tab[pm]) {
        list($unreadpms) = $db->query("SELECT COUNT(id) FROM {$tab['pm']} WHERE inbox='1' AND toid='{$login['id']}' AND view='0'");
    } else {
        $unreadpms = "N/A";
    }
    if ($login[rate_count]) {
        $rating = mkstatus($login[rate_points], $login[rate_count]);
        $rount_number = round($login[rate_points] / $login[rate_count], 4);
    }
    if (!$login[upload_allow]) {
        $upload_paths = "---";
    } else {
        $ftpq = $db->query_str("SELECT * FROM {$tab['upload_access']} WHERE userid='{$login['id']}'");
        while ($set = $db->fetch_array($ftpq)) {
            $upload_path[] = $set[path];
        }
        if (is_array($upload_path)) {
            $upload_paths = implode("<br>", $upload_path);
        }
Example #14
0
 function show()
 {
     global $set, $db, $apx, $html;
     quicklink('poll.add');
     $orderdef[0] = 'addtime';
     $orderdef['question'] = array('question', 'ASC', 'COL_QUESTION');
     $orderdef['addtime'] = array('addtime', 'DESC', 'COL_ADDTIME');
     $orderdef['starttime'] = array('starttime', 'DESC', 'COL_STARTTIME');
     $orderdef['endtime'] = array('endtime', 'DESC', 'COL_ENDTIME');
     $col[] = array('', 1, 'align="center"');
     $col[] = array('COL_QUESTION', 60, 'class="title"');
     $col[] = array('COL_STARTTIME', 20, 'align="center"');
     $col[] = array('COL_ENDTIME', 20, 'align="center"');
     list($count) = $db->first("SELECT count(id) FROM " . PRE . "_poll");
     pages('action.php?action=poll.show&amp;sortby=' . $_REQUEST['sortby'], $count);
     $data = $db->fetch("SELECT id,secid,question,addtime,starttime,endtime,days,allowcoms FROM " . PRE . "_poll " . getorder($orderdef) . getlimit());
     if (count($data)) {
         foreach ($data as $res) {
             ++$i;
             if (!$res['starttime']) {
                 $tabledata[$i]['COL1'] = '<img src="design/reddot.gif" alt="' . $apx->lang->get('CORE_INACTIVE') . '" title="' . $apx->lang->get('CORE_INACTIVE') . '" />';
             } elseif ($res['endtime'] < time()) {
                 $tabledata[$i]['COL1'] = '<img src="design/greendotcross.gif" alt="' . $apx->lang->get('CORE_INACTIVE') . '" title="' . $apx->lang->get('CORE_INACTIVE') . '" />';
             } elseif ($res['starttime'] > time()) {
                 $tabledata[$i]['COL1'] = '<img src="design/greendotwait.gif" alt="' . $apx->lang->get('CORE_ACTIVE') . '" title="' . $apx->lang->get('CORE_ACTIVE') . '" />';
             } else {
                 $tabledata[$i]['COL1'] = '<img src="design/greendot.gif" alt="' . $apx->lang->get('CORE_ACTIVE') . '" title="' . $apx->lang->get('CORE_ACTIVE') . '" />';
             }
             $tmp = unserialize_section($res['secid']);
             $question = shorttext(strip_tags($res['question']), 60);
             $link = mklink('poll.php?id=' . $res['id'], 'poll,' . $res['id'] . urlformat($res['question']) . '.html', iif($set['main']['forcesection'], iif(unserialize_section($res['secid']) == array('all'), $apx->section_default, array_shift($tmp)), 0));
             $tabledata[$i]['COL2'] = '<a href="' . $link . '" target="_blank">' . $question . '</a>';
             if ($res['starttime']) {
                 $tabledata[$i]['COL3'] = mkdate($res['starttime'], '<br />');
             }
             if ($res['starttime']) {
                 $tabledata[$i]['COL4'] = mkdate($res['starttime'] + $res['days'] * 24 * 3600, '<br />');
             }
             //Optionen
             if ($apx->user->has_right('poll.edit')) {
                 $tabledata[$i]['OPTIONS'] .= optionHTML('edit.gif', 'poll.edit', 'id=' . $res['id'], $apx->lang->get('CORE_EDIT'));
             } else {
                 $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
             }
             if ($apx->user->has_right('poll.del')) {
                 $tabledata[$i]['OPTIONS'] .= optionHTMLOverlay('del.gif', 'poll.del', 'id=' . $res['id'], $apx->lang->get('CORE_DEL'));
             } else {
                 $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
             }
             if ((!$res['starttime'] || $res['endtime'] < time()) && $apx->user->has_right('poll.enable')) {
                 $tabledata[$i]['OPTIONS'] .= optionHTMLOverlay('enable.gif', 'poll.enable', 'id=' . $res['id'], $apx->lang->get('CORE_ENABLE'));
             } elseif ($res['starttime'] && $apx->user->has_right('poll.disable')) {
                 $tabledata[$i]['OPTIONS'] .= optionHTMLOverlay('disable.gif', 'poll.disable', 'id=' . $res['id'], $apx->lang->get('CORE_DISABLE'));
             } else {
                 $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
             }
             //Kommentare
             if ($apx->is_module('comments')) {
                 $tabledata[$i]['OPTIONS'] .= '&nbsp;';
                 list($comments) = $db->first("SELECT count(mid) FROM " . PRE . "_comments WHERE ( module='poll' AND mid='" . $res['id'] . "' )");
                 if ($comments && ($apx->is_module('comments') && $set['poll']['coms']) && $res['allowcoms'] && $apx->user->has_right('comments.show')) {
                     $tabledata[$i]['OPTIONS'] .= optionHTML('comments.gif', 'comments.show', 'module=poll&mid=' . $res['id'], $apx->lang->get('COMMENTS'));
                 } else {
                     $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
                 }
             }
         }
     }
     $apx->tmpl->assign('TABLE', $tabledata);
     $html->table($col);
     orderstr($orderdef, 'action.php?action=poll.show');
     save_index($_SERVER['REQUEST_URI']);
 }
function write($_POST)
{
    # get vars
    extract($_POST);
    // prevent from updating
    if (isset($cusnum) && customer_overdue($cusnum)) {
        return details($_POST);
    }
    db_conn('cubit');
    if (isset($printsales)) {
        $Sl = "SELECT * FROM settings WHERE constant='SALES'";
        $Ri = db_exec($Sl) or errDie("Unable to get settings.");
        if (pg_num_rows($Ri) < 1) {
            $Sl = "INSERT INTO settings (constant,value,div) VALUES ('SALES','Yes','" . USER_DIV . "')";
            $Ri = db_exec($Sl);
        } else {
            $Sl = "UPDATE settings SET value='Yes' WHERE constant='SALES' AND div='" . USER_DIV . "'";
            $Ri = db_exec($Sl);
        }
    } else {
        $Sl = "UPDATE settings SET value='No' WHERE constant='SALES' AND div='" . USER_DIV . "'";
        $Ri = db_exec($Sl);
    }
    if (!isset($bodydata)) {
        $bodydata = "";
    }
    if (!isset($counter)) {
        $counter = "";
    }
    $bodydata = str_replace("'", "", $bodydata);
    $bodydata = str_replace("  ", " ", $bodydata);
    $bodydata = str_replace("&nbsp;&nbsp;", " ", $bodydata);
    $bodydata = str_replace(" &nbsp;", " ", $bodydata);
    $bodydata = str_replace("&nbsp; ", " ", $bodydata);
    $des[$counter] = $bodydata;
    # validate input
    require_lib("validate");
    $v = new validate();
    if (empty($ninv_year)) {
        list($ninv_year, $ninv_month, $ninv_day) = date("Y-m-d");
    }
    $odate = mkdate($ninv_year, $ninv_month, $ninv_day);
    $v->isOk($odate, "date", 1, 1, "Invalid Date.");
    # used to generate errors
    $error = "asa@";
    // check the invoice details
    $v->isOK($cusname, "string", 1, 100, "Invalid customer name");
    $v->isOK($cusaddr, "string", 0, 400, "Invalid customer address");
    $v->isOK($cusvatno, "string", 0, 50, "Invalid customer vat number");
    $v->isOK($docref, "string", 0, 20, "Invalid Document Reference No.");
    $v->isOK($cordno, "string", 0, 20, "Invalid Customer Order Number.");
    if ($chrgvat != "yes" && $chrgvat != "no" && $chrgvat != "none") {
        $v->addError($chrgvat, "Invalid vat option");
    }
    # check quantities
    if (isset($qtys)) {
        foreach ($qtys as $keys => $qty) {
            $v->isOk($qty, "float", 1, 10, "Invalid Quantity for product number : <b>" . ($keys + 1) . "</b>");
            $v->isOk($unitcost[$keys], "float", 1, 20, "Invalid Unit Price for product number : <b>" . ($keys + 1) . "</b>.");
            //		$v->isOk ($des[$keys], "url", 1, 255, "Invalid Description.");
            if ($qty <= 0) {
                $v->isOk($qty, "num", 0, 0, "Error : Item Quantity can't be zero or less. Product number: <b>" . ($keys + 1) . "</b>");
            }
        }
    }
    # check amt
    if (isset($amt)) {
        foreach ($amt as $keys => $amount) {
            $v->isOk($amount, "float", 1, 16, "Invalid Amount, please enter all details.");
        }
    }
    # display errors, if any
    $err = "";
    if ($v->isError()) {
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $_POST['done'] = "";
        return details($_POST, $err);
    }
    # Get purchase info
    db_connect();
    $sql = "SELECT * FROM nons_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
    $invRslt = db_exec($sql) or errDie("Unable to get purchase information");
    if (pg_numrows($invRslt) < 1) {
        return "<li>- Invoice Not Found</li>";
    }
    $inv = pg_fetch_array($invRslt);
    $inv['chrgvat'] = $chrgvat;
    # check if purchase has been printed
    if ($inv['done'] == "y") {
        $error = "<li class='err'> Error : Invoice number <b>{$invid}</b> has already been printed.";
        $error .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $error;
    }
    $vatamount = 0;
    $showvat = TRUE;
    # insert purchase to DB
    db_conn("cubit");
    # begin updating
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    /* -- Start remove old items -- */
    # remove old items
    $sql = "DELETE FROM nons_inv_items WHERE invid='{$invid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice items in Cubit.", SELF);
    /* -- End remove old items -- */
    $taxex = 0;
    if (isset($qtys)) {
        foreach ($qtys as $keys => $value) {
            if (isset($remprod)) {
                if (in_array($keys, $remprod)) {
                    # skip product (wonder if $keys still align)
                    $amt[$keys] = 0;
                    continue;
                } else {
                    # Calculate amount
                    $amt[$keys] = $qtys[$keys] * $unitcost[$keys];
                    if (!isset($vatcodes[$keys])) {
                        $vatcodes[$keys] = 0;
                    }
                    db_connect();
                    $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcodes[$keys]}'";
                    $Ri = db_exec($Sl);
                    // 					if(pg_num_rows($Ri)<1) {
                    // 						return "Please select the vatcode for all your stock.";
                    // 					}
                    $vd = pg_fetch_array($Ri);
                    if ($vd['zero'] == "Yes") {
                        $excluding = "y";
                    } else {
                        $excluding = "";
                    }
                    if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
                        $showvat = FALSE;
                    }
                    $vr = vatcalc($amt[$keys], $inv['chrgvat'], $excluding, 0, $vd['vat_amount']);
                    $vrs = explode("|", $vr);
                    $ivat = $vrs[0];
                    $iamount = $vrs[1];
                    $vatamount += $ivat;
                    $vate = 'n';
                    if (isset($vatex) && in_array($keys, $vatex) || $vd['zero'] == "Yes") {
                        $taxex += $amt[$keys];
                        $vate = 'y';
                    }
                    $vate = $vatcodes[$keys];
                    # insert purchase items
                    $sql = "\n\t\t\t\t\t\tINSERT INTO nons_inv_items (\n\t\t\t\t\t\t\tinvid, qty, amt, unitcost, description, vatex, div\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t'{$invid}', '{$qtys[$keys]}', '{$amt[$keys]}', '{$unitcost[$keys]}', '{$des[$keys]}', '{$vate}', '" . USER_DIV . "'\n\t\t\t\t\t\t)";
                    $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF);
                }
            } else {
                # Calculate amount
                $amt[$keys] = $qtys[$keys] * $unitcost[$keys];
                if (!isset($vatcodes[$keys])) {
                    $vatcodes[$keys] = 0;
                }
                $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcodes[$keys]}'";
                $Ri = db_exec($Sl);
                // 				if(pg_num_rows($Ri) < 1) {
                // 					return "Please select the vatcode for all your stock.";
                // 				}
                $vd = pg_fetch_array($Ri);
                if ($vd['zero'] == "Yes") {
                    $excluding = "y";
                } else {
                    $excluding = "";
                }
                if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
                    $showvat = FALSE;
                }
                $vr = vatcalc($amt[$keys], $inv['chrgvat'], $excluding, 0, $vd['vat_amount']);
                $vrs = explode("|", $vr);
                $ivat = $vrs[0];
                $iamount = $vrs[1];
                $vatamount += $ivat;
                $vate = 'n';
                if (isset($vatex) && in_array($keys, $vatex) || $vd['zero'] == "Yes") {
                    $taxex += $amt[$keys];
                    $vate = 'y';
                }
                $vate = $vatcodes[$keys];
                db_connect();
                # insert purchase items
                $sql = "\n\t\t\t\t\tINSERT INTO nons_inv_items (\n\t\t\t\t\t\tinvid, qty, amt, unitcost, description, vatex, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$invid}', '{$qtys[$keys]}', '{$amt[$keys]}', '{$unitcost[$keys]}', '{$des[$keys]}', '{$vate}', '" . USER_DIV . "'\n\t\t\t\t\t)";
                $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF);
            }
            # everything is set place done button
            $_POST["done"] = " | <input name='doneBtn' type='submit' value='Done'>| <input name='print' type='submit' value='Process'>";
        }
    } else {
        $_POST["done"] = "";
    }
    $_POST['showvat'] = $showvat;
    /* --- ----------- Clac --------------------- */
    ##----------------------NEW----------------------
    $sub = 0.0;
    if (isset($amt)) {
        $sub = sprint(array_sum($amt));
    }
    $VATP = TAX_VAT;
    if ($chrgvat == "no") {
        $subtotal = sprint($sub);
        $subtotal = sprint($subtotal);
        // 		$VAT=sprint(($subtotal-$taxex)*$VATP/100);
        $VAT = $vatamount;
        $SUBTOT = $sub;
        $TOTAL = sprint($subtotal + $VAT);
    } elseif ($chrgvat == "yes") {
        $subtotal = sprint($sub);
        $subtotal = sprint($subtotal);
        // 		$VAT=sprint(($subtotal-$taxex)*$VATP/(100+$VATP));
        $VAT = $vatamount;
        $SUBTOT = sprint($sub);
        $TOTAL = sprint($subtotal);
    } else {
        $subtotal = sprint($sub);
        $traddiscmt = sprint($subtotal);
        $subtotal = sprint($subtotal);
        $VAT = sprint(0);
        $SUBTOT = $sub;
        $TOTAL = $subtotal;
    }
    /* --- ----------- Clac --------------------- */
    ##----------------------END----------------------
    /* --- Clac ---
    	# calculate subtot
    	if( isset($amt) ){
    		$SUBTOT = array_sum($amt);
    	}else{
    		$SUBTOT = 0.00;
    	}
    
    	$SUBTOT -= $taxex;
    
    	$VATP = TAX_VAT;
    	if($chrgvat == "no"){
    		$SUBTOT = $SUBTOT;
    	}elseif($chrgvat == "yes"){
    		$SUBTOT = sprint(($SUBTOT * 100)/(100 + $VATP));
    	}else{
    		$SUBTOT = ($SUBTOT);
    	}
    
    	if($chrgvat != "none"){
    		$VAT = sprint($SUBTOT * ($VATP/100));
    	}else{
    		$VAT = 0;
    	}
    
    	$TOTAL = sprint($SUBTOT + $VAT + $taxex);
    	$SUBTOT += $taxex;
    
    	/* --- End Clac --- */
    $salespn = remval($salespn);
    if (!isset($bankid)) {
        if (isset($cusnum) and strlen($cusnum) > 0) {
            #get bankid from customer info
            $get_cbank = "SELECT bankid FROM customers WHERE cusnum = '{$cusnum}' LIMIT 1";
            $run_cbank = db_exec($get_cbank) or errDie("Unable to get bank information for customer.");
            if (pg_numrows($run_cbank) > 0) {
                $bankid = pg_fetch_result($run_cbank, 0, 0);
            } else {
                $bankid = "2";
            }
        } else {
            $bankid = "2";
        }
    }
    # insert purchase to DB
    $sql = "\n\t\tUPDATE nons_invoices \n\t\tSET salespn='{$salespn}', cusname = '{$cusname}', cusaddr = '{$cusaddr}', \n\t\t\tcusvatno = '{$cusvatno}', cordno = '{$cordno}', docref = '{$docref}', \n\t\t\tchrgvat = '{$chrgvat}', odate = '{$odate}', terms = '{$terms}', \n\t\t\tsubtot = '{$SUBTOT}', vat = '{$VAT}', total = '{$TOTAL}', \n\t\t\tremarks = '{$remarks}', bankid = '{$bankid}' \n\t\tWHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
    # commit updating
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    if (isset($print)) {
        $OUTPUT = "<script>printer('nons-invoice-print.php?invid={$invid}');move('nons-invoice-new.php');</script>";
        require "template.php";
    }
    if (!isset($doneBtn)) {
        return details($_POST);
    } else {
        //$rslt = db_exec($sql) or errDie("Unable to update invoices status in Cubit.$sql",SELF);
        # Final Laytout
        $write = "\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>New Non-Stock Invoices</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Non-Stock Invoices for Customer <b>{$cusname}</b> has been recorded.</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='nons-invoice-view.php'>View Non-Stock Invoices</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t</table>";
        return $write;
    }
}
function confirm($_POST)
{
    extract($_POST);
    if (isset($back)) {
        return view();
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($bankid, "num", 1, 20, "Invalid Bank ID.");
    foreach ($amount as $key => $value) {
        //	if($amount[$key] > 0){
        # check all vars
        $v->isOk($to[$key], "string", 0, 255, "Invalid receipient/depositor.");
        $v->isOk($trantype[$key], "string", 1, 20, "Invalid transaction type.");
        $v->isOk($descript[$key], "string", 0, 255, "Invalid description.");
        $v->isOk($ref[$key], "string", 0, 255, "Invalid reference <b>[{$key}]</b>.");
        $v->isOk($cheqnum[$key], "num", 0, 20, "Invalid cheque number <b>[{$key}]</b>.");
        $v->isOk($amount[$key], "float", 0, 8, "Invalid amount <b>[{$key}]</b>.");
        $v->isOk($chrgvat[$key], "string", 1, 4, "Invalid VAT option.");
        $v->isOk($accinv[$key], "num", 1, 20, "Invalid account involved <b>[{$key}]</b>.");
        if (empty($amount[$key])) {
            unset($amount[$key]);
        }
        # put date together and check
        $date[$key] = mkdate($o_year[$key], $o_month[$key], $o_day[$key]);
        $v->isOk($date[$key], "date", 1, 1, "Invalid date <b>[{$key}]</b>.");
        //	}
    }
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        return enter($_POST, $confirm);
        $confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    # Get bank acc details
    $bankRslt = get("cubit", "*", "bankacct", "bankid", $bankid);
    $bank = pg_fetch_array($bankRslt);
    # Layout
    $confirm = "\n\t\t<center>\n\t\t<h3>Type in Bank Statement</h3>\n\t\t<h4>Confirm entry</h4>\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='write'>\n\t\t\t<input type='hidden' name='bankid' value='{$bankid}'>\n\t\t\t<input type='hidden' name='number' value='{$number}'>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center' colspan='4'>Bank Account : <b>({$bank['accnum']}) {$bank['accname']}</b></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Date</th>\n\t\t\t\t<th>Paid to/Received from</th>\n\t\t\t\t<th>Transaction type</th>\n\t\t\t\t<th>Transaction 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>Transaction Amount</th>\n\t\t\t\t<th>VAT</th>\n\t\t\t\t<th>VAT Code</th>\n\t\t\t\t<th>Contra Account</th>\n\t\t\t</tr>";
    # Display the trans
    $trans = "";
    foreach ($amount as $key => $value) {
        if ($amount[$key] > 0) {
            # get account name
            $accRslt = get("core", "accname,topacc,accnum", "accounts", "accid", $accinv[$key]);
            $acc = pg_fetch_array($accRslt);
            $vd = qryVatcode($vatcode[$key]);
            if ($vd["zero"] == "Yes") {
                $chrgvat[$key] = "no";
            }
            $vatp = $vd["vat_amount"];
            $totamt = $amount[$key];
            if ($chrgvat[$key] == "exc") {
                $vat = sprint($vatp / 100 * $amount[$key]);
                $totamt += $vat;
                $vatin = CUR . " <input type='text' size='6' name='vat[{$key}]' value='{$vat}' />";
            } elseif ($chrgvat[$key] == "inc") {
                $vat = sprint($amount[$key] / (100 + $vatp) * $vatp);
                $vatin = CUR . " <input type='text' size='6' name='vat[{$key}]' value='{$vat}' />";
            } else {
                $vat = "No VAT";
                $vatd = "{$vat}";
                $vatin = "No VAT";
            }
            # alternate bgcolor
            $bgColor = bgcolorc($key);
            vsprint($totamt);
            $trans .= "\n\t\t\t\t<input type='hidden' size='2' name='date[{$key}]' value='{$date[$key]}' />\n\t\t\t\t<input type='hidden' name='to[{$key}]' value='{$to[$key]}' />\n\t\t\t\t<input type='hidden' name='trantype[{$key}]' value='{$trantype[$key]}' />\n\t\t\t\t<input type='hidden' name='descript[{$key}]' value='{$descript[$key]}' />\n\t\t\t\t<input type='hidden' name='ref[{$key}]' value='{$ref[$key]}' />\n\t\t\t\t<input type='hidden' name='cheqnum[{$key}]' value='{$cheqnum[$key]}' />\n\t\t\t\t<input type='hidden' name='amount[{$key}]' value='{$amount[$key]}' />\n\t\t\t\t<input type='hidden' name='chrgvat[{$key}]' value='{$chrgvat[$key]}' />\n\t\t\t\t<input type='hidden' name='vatcode[{$key}]' value='{$vatcode[$key]}' />\n\t\t\t\t<input type='hidden' name='accinv[{$key}]' value='{$accinv[$key]}' />\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td align='center'>{$date[$key]}</td>\n\t\t\t\t\t<td align='center'>{$to[$key]}</td>\n\t\t\t\t\t<td align='center'>{$trantype[$key]}</td>\n\t\t\t\t\t<td align='center'>{$descript[$key]}</td>\n\t\t\t\t\t<td align='center'>{$ref[$key]}</td>\n\t\t\t\t\t<td align='center'>{$cheqnum[$key]}</td>\n\t\t\t\t\t<td align='center' nowrap='t'>" . CUR . " {$totamt}</td></td>\n\t\t\t\t\t<td align='center' nowrap='t'>{$vatin}</td>\n\t\t\t\t\t<td align='center'>{$vd['code']}</td>\n\t\t\t\t\t<td align='center'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td></td>\n\t\t\t\t</tr>";
        }
    }
    if (strlen($trans) < 5) {
        $err = "<li class='err'> - Please enter full transaction details";
        return enter($_POST, $err);
    }
    $confirm .= "\n\t\t\t{$trans}\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td align='right'><input type='submit' name='batch' value='Add to Batch &raquo'></td>\n\t\t\t</tr>\n\t\t\t<tr><td><br></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td><input type='submit' name='back' value='&laquo; Correction'></td>\n\t\t\t\t<td align='right' colspan='4'><input type='submit' value='Write &raquo'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>" . mkQuickLinks();
    return $confirm;
}
Example #17
0
        if (!mysql_num_rows($comquery)) {
            eval("\$inc[combit] = \"" . gettemplate("news.comment.nocoms") . "\";");
        }
    }
    eval("\$inc[action] = \"" . gettemplate("news.admin.comment") . "\";");
}
############################
if ($adminaction == "shownewsdetails") {
    $news = $db->query("SELECT * FROM {$tab['news']} WHERE id='{$newsid}'");
    if (!$news) {
        eval("\$inc[action] = \"" . gettemplate("news.edit.fail.wrongnewsid") . "\";");
    } else {
        $aut = getuser($news[autid]);
        $news[text] = htmlspecialchars($news[text]);
        $news[text] = str_replace("\n", "<br>", $news[text]);
        $news[date] = mkdate($news[date]);
        $news[activated] ? $activ = "inactivate" : ($activ = "activate");
        $news[blocked] ? $block = "unblock" : ($block = "block");
        eval("\$subactioncontrol = \"" . gettemplate("news.edit.subactions") . "\";");
        eval("\$inc[action] = \"" . gettemplate("news.edit.selectsubaction") . "\";");
    }
}
############################
if ($adminaction == "news_select") {
    $newsquery = $db->query_str("SELECT * FROM {$tab['news']} ORDER BY date DESC");
    while ($news = $db->fetch_array($newsquery)) {
        unset($blocked, $activated);
        if (!$news[title]) {
            $news[title] = "----";
        }
        if ($news[blocked]) {
function write($_POST)
{
    #get vars
    extract($_POST);
    #only process details if we are not changing the customer
    if (isset($customer_select) and isset($old_customer_select) and $customer_select != $old_customer_select) {
        return details($_POST);
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $sdate = mkdate($nquo_year, $nquo_month, $nquo_day);
    $v->isOk($sdate, "date", 1, 1, "Invalid Date.");
    # used to generate errors
    $error = "asa@";
    // check the quote details
    $v->isOK($cusname, "string", 1, 100, "Invalid customer name");
    $v->isOK($cusaddr, "string", 0, 100, "Invalid customer address");
    $v->isOK($cusvatno, "string", 0, 50, "Invalid customer vat number");
    if ($chrgvat != "yes" && $chrgvat != "no" && $chrgvat != "none") {
        $v->addError($chrgvat, "Invalid vat option");
    }
    if (!isset($bodydata)) {
        $bodydata = "";
    }
    $bodydata = str_replace("'", "", $bodydata);
    //$bodydata = str_replace("<br>","",$bodydata);
    $bodydata = str_replace("  ", " ", $bodydata);
    $bodydata = str_replace("&nbsp;&nbsp;", " ", $bodydata);
    $bodydata = str_replace(" &nbsp;", " ", $bodydata);
    $bodydata = str_replace("&nbsp; ", " ", $bodydata);
    //[key] was $counter ... but it wasnt set ??
    $des[] = $bodydata;
    # check quantities
    if (isset($qtys)) {
        foreach ($qtys as $keys => $qty) {
            $v->isOk($qty, "num", 1, 10, "Invalid Quantity for product number : <b>" . ($keys + 1) . "</b>");
            $v->isOk($unitcost[$keys], "float", 1, 20, "Invalid Unit Price for product number : <b>" . ($keys + 1) . "</b>.");
            //			$v->isOk ($des[$keys], "url", 1, 255, "Invalid Description.");
            if ($qty < 1) {
                $v->isOk($qty, "num", 0, 0, "Error : Item Quantity must be at least one. Product number : <b>" . ($keys + 1) . "</b>");
            }
        }
    }
    # check amt
    if (isset($amt)) {
        foreach ($amt as $keys => $amount) {
            $v->isOk($amount, "float", 1, 20, "Invalid Amount, please enter all details.");
        }
    }
    # display errors, if any
    $err = "";
    if ($v->isError()) {
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $err .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        $_POST['done'] = "";
        return details($_POST, $err);
    }
    # Get purchase info
    db_connect();
    $sql = "SELECT * FROM nons_invoices WHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
    $invRslt = db_exec($sql) or errDie("Unable to get purchase information");
    if (pg_numrows($invRslt) < 1) {
        return "<li>- invoices Not Found</li>";
    }
    $inv = pg_fetch_array($invRslt);
    $inv['chrgvat'] = $chrgvat;
    # check if purchase has been printed
    if ($inv['done'] == "y") {
        $error = "<li class='err'> Error : quote number <b>{$invid}</b> has already been printed.</li>";
        $error .= "<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $error;
    }
    $vatamount = 0;
    $showvat = TRUE;
    # begin updating
    pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
    db_connect();
    /* -- Start remove old items -- */
    # remove old items
    $sql = "DELETE FROM nons_inv_items WHERE invid='{$invid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update quote items in Cubit.", SELF);
    $taxex = 0;
    /* -- End remove old items -- */
    if (isset($qtys)) {
        foreach ($qtys as $keys => $value) {
            if (isset($remprod) && in_array($keys, $remprod)) {
            } else {
                # Calculate amount
                $amt[$keys] = $qtys[$keys] * $unitcost[$keys];
                if (!isset($vatcodes[$keys])) {
                    $vatcodes[$keys] = 0;
                }
                $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcodes[$keys]}'";
                $Ri = db_exec($Sl);
                // 				if(pg_num_rows($Ri)<1) {
                // 					return "Please select the vatcode for all your stock.";
                // 				}
                $vd = pg_fetch_array($Ri);
                if ($vd['zero'] == "Yes") {
                    $excluding = "y";
                } else {
                    $excluding = "";
                }
                if (TAX_VAT != $vd['vat_amount'] and $vd['vat_amount'] != "0.00") {
                    $showvat = FALSE;
                }
                $vr = vatcalc($amt[$keys], $inv['chrgvat'], $excluding, 0, $vd['vat_amount']);
                $vrs = explode("|", $vr);
                $ivat = $vrs[0];
                $iamount = $vrs[1];
                $vatamount += $ivat;
                $vate = 'n';
                if (isset($vatex) && in_array($keys, $vatex) || $vd['zero'] == "Yes") {
                    $taxex += $amt[$keys];
                    $vate = 'y';
                }
                $vate = $vatcodes[$keys];
                # insert purchase items
                $sql = "\n\t\t\t\t\tINSERT INTO nons_inv_items (\n\t\t\t\t\t\tinvid, qty, amt, unitcost, description, vatex, div\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$invid}', '{$qtys[$keys]}', '{$amt[$keys]}', '{$unitcost[$keys]}', '{$des[$keys]}','{$vate}',  '" . USER_DIV . "'\n\t\t\t\t\t)";
                $rslt = db_exec($sql) or errDie("Unable to insert quote items to Cubit.", SELF);
            }
            # everything is set place done button
            $_POST["done"] = " | <input name='doneBtn' type='submit' value='Done'>";
        }
    } else {
        $_POST["done"] = "";
    }
    $_POST['showvat'] = $showvat;
    /* --- ----------- Clac --------------------- */
    ##----------------------NEW----------------------
    $sub = 0.0;
    if (isset($amt)) {
        $sub = sprint(array_sum($amt));
    }
    $VATP = TAX_VAT;
    if ($chrgvat == "no") {
        $subtotal = sprint($sub);
        $subtotal = sprint($subtotal);
        //		$VAT=sprint(($subtotal-$taxex)*$VATP/100);
        $VAT = $vatamount;
        $SUBTOT = $sub;
        $TOTAL = sprint($subtotal + $VAT);
    } elseif ($chrgvat == "yes") {
        $subtotal = sprint($sub);
        $subtotal = sprint($subtotal);
        //	$VAT=sprint(($subtotal-$taxex)*$VATP/(100+$VATP));
        $VAT = $vatamount;
        $SUBTOT = sprint($sub - $vatamount);
        $TOTAL = sprint($subtotal);
    } else {
        $subtotal = sprint($sub);
        $traddiscmt = sprint($subtotal);
        $subtotal = sprint($subtotal);
        $VAT = sprint(0);
        $SUBTOT = $sub;
        $TOTAL = $subtotal;
    }
    /* --- ----------- Clac --------------------- */
    ##----------------------END----------------------
    /* --- Clac ---
    	# calculate subtot
    	if( isset($amt) ){
    		$SUBTOT = array_sum($amt);
    	}else{
    		$SUBTOT = 0.00;
    	}
    
    	$VATP = TAX_VAT;
    	if($chrgvat == "no"){
    		$SUBTOT = $SUBTOT;
    	}elseif($chrgvat == "yes"){
    		$SUBTOT = sprint(($SUBTOT * 100)/(100 + $VATP));
    	}else{
    		$SUBTOT = ($SUBTOT);
    	}
    
    	if($chrgvat != "none"){
    		$VAT = sprint($SUBTOT * ($VATP/100));
    	}else{
    		$VAT = 0;
    	}
    
    	$TOTAL = sprint($SUBTOT + $VAT);
    
    	/*# if vat is not included
    	$VATP = TAX_VAT;
    	if($chrgvat == "yes"){
    		$SUBTOT = sprintf("%0.2f", $TOTAL * 100 / (100 + $VATP) );
    	} elseif($chrgvat == "no") {
    		$SUBTOT = $TOTAL;
    		$TOTAL = sprintf("%0.2f", $TOTAL * (100 + $VATP) /100 );
    	}else{
    		$SUBTOT = $TOTAL;
    	}
    
    	// compute the sub total (total - vat), done this way because the specified price already includes vat
    	$VAT = $TOTAL - $SUBTOT;
    
    	/* --- End Clac --- */
    $ncdate = "{$ncdate_year}-{$ncdate_month}-{$ncdate_day}";
    if (!isset($lead)) {
        $lead = "";
    }
    # insert purchase to DB
    $sql = "\n\t\t\tUPDATE nons_invoices \n\t\t\tSET cusname = '{$cusname}', cusaddr = '{$cusaddr}', cusvatno = '{$cusvatno}', chrgvat = '{$chrgvat}', odate = '{$sdate}', \n\t\t\t\tsubtot = '{$SUBTOT}', vat = '{$VAT}', total = '{$TOTAL}', remarks = '{$remarks}', lead = '{$lead}', ncdate = '{$ncdate}' \n\t\t\tWHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to update quote in Cubit.", SELF);
    # commit updating
    pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF);
    if (!isset($doneBtn)) {
        return details($_POST);
    } else {
        $rslt = db_exec($sql) or errDie("Unable to update invoices status in Cubit.", SELF);
        #add lead
        if (isset($lead) and $lead == "yes") {
            db_conn("crm");
            $sql = "\n\t\t\t\tINSERT INTO leads (\n\t\t\t\t\tsurname, date, by, con, div, supp_id, cust_id, lead_source, birthdate, reports_to_id, assigned_to, \n\t\t\t\t\tassigned_to_id, account_id, gender, website, salespid, ncdate, team_id, dept_id, tell, hadd, ref\n\t\t\t\t) VALUES (\n\t\t\t\t\t'{$cusname}', 'now', '" . USER_NAME . "', 'No', '" . USER_DIV . "', '0', '0', '0', 'now', '0', '" . USER_NAME . "', \n\t\t\t\t\t'0', '0', 'Male', 'http://', '0', '{$ncdate}', '0', '0', '', '{$cusaddr}', ''\n\t\t\t\t)";
            $rslt = db_exec($sql) or errDie("Unable to add lead to database.");
            $lead_id = pglib_lastid("leads", "id");
        }
        // Final Laytout
        $write = "\n\t\t\t<script>\n\t\t\t\tprinter('nons-quote-print.php?invid={$invid}');\n\t\t\t</script>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>New Non-Stock Quotes</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Non-Stock Quotes for Customer <b>{$cusname}</b> has been recorded.</td>\n\t\t\t\t\t<td><input type='button' onClick=\"printer('nons-quote-print.php?invid={$invid}');\" value='Print Quote'></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='nons-quote-view.php'>View Non-Stock Quotes</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='main.php'>Main Menu</a></td>\n\t\t\t\t</tr>\n\t\t\t</table>";
        return $write;
        // 		return "
        // 			<script>
        // 				printer('nons-quote-print.php?invid=$invid');
        // 				document.location='nons-multiline-quote-new.php';
        // 			</script>";
    }
}
Example #19
0
              <?php 
}
?>
            </select>
            <select name="month">
              <?php 
for ($i = 1; $i <= 12; $i++) {
    ?>
              <option value="<?php 
    echo sprintf("%02d", $i);
    ?>
" <?php 
    echo set_select('month', sprintf("%02d", $i), isset($month) && $month == sprintf("%02d", $i) ? TRUE : FALSE);
    ?>
><?php 
    echo date('M', mkdate(2010, $i, 1));
    ?>
</option>
              <?php 
}
?>
            </select>
            <select name="year">
              <?php 
for ($i = date('Y', time()); $i <= date('Y', time() + 60 * 60 * 24 * 365 * 3); $i++) {
    ?>
              <option value="<?php 
    echo $i;
    ?>
" <?php 
    echo set_select('year', $i, isset($year) && $year == $i ? TRUE : FALSE);
function printInvoice()
{
    extract($_POST);
    require_lib("validate");
    $v = new validate();
    $v->isOk($from_day, "num", 1, 2, "Invalid from Date day.");
    $v->isOk($from_month, "num", 1, 2, "Invalid from Date month.");
    $v->isOk($from_year, "num", 1, 4, "Invalid from Date Year.");
    $v->isOk($to_day, "num", 1, 2, "Invalid to Date day.");
    $v->isOk($to_month, "num", 1, 2, "Invalid to Date month.");
    $v->isOk($to_year, "num", 1, 4, "Invalid to Date Year.");
    $fromdate = mkdate($from_year, $from_month, $from_day);
    $todate = mkdate($to_year, $to_month, $to_day);
    $v->isOk($fromdate, "date", 1, 1, "Invalid from date.");
    $v->isOk($todate, "date", 1, 1, "Invalid to date.");
    if ($v->isError()) {
        $err = $v->genErrors();
        return $err;
    }
    # Set up table to display in
    $printOrd = "\r\n\t\t<center>\r\n\t\t<h3>View Incomplete Non-Stock Invoices</h3>\r\n\t\t<table " . TMPL_tblDflts . ">\r\n\t\t<form action='invoice-proc.php' method='GET'>\r\n\t\t\t<tr>\r\n\t\t\t\t<th>Invoice Num</th>\r\n\t\t\t\t<th>Proforma Inv No.</th>\r\n\t\t\t\t<th>Invoice Date</th>\r\n\t\t\t\t<th>Customer</th>\r\n\t\t\t\t<th>Total</th>\r\n\t\t\t\t<th colspan='2'>Options</th>\r\n\t\t\t</tr>";
    # connect to database
    db_connect();
    # Query server
    $i = 0;
    $tot_subtot = 0;
    $tot_total = 0;
    $cust_search = "";
    if (isset($customer) and $customer != "0") {
        $cust_search = "AND cusname = '{$customer}'";
    }
    $sql = "SELECT * FROM nons_invoices WHERE typ = 'inv' AND sdate >= '{$fromdate}' \tAND sdate <= '{$todate}' AND div = '" . USER_DIV . "' AND done = 'n' {$cust_search} ORDER BY invnum";
    $nonstksRslt = db_exec($sql) or errDie("Unable to retrieve invoices from database.");
    if (pg_numrows($nonstksRslt) < 1) {
        return "<li class='err'> There are no incomplete non stock invoices found.</li>";
    }
    while ($nonstks = pg_fetch_array($nonstksRslt)) {
        # date format
        $date = explode("-", $nonstks['sdate']);
        $date = $date[2] . "-" . $date[1] . "-" . $date[0];
        // compute the totals
        if ($nonstks["xrate"] == 0.0) {
            $tot_subtot += $nonstks["subtot"];
            $tot_total += $nonstks["total"];
        } else {
            $tot_subtot += $nonstks["subtot"] * $nonstks["xrate"];
            $tot_total += $nonstks["total"] * $nonstks["xrate"];
        }
        # calculate the Sub-Total
        if ($nonstks['invnum'] == 0) {
            $nonstks['invnum'] = $nonstks['invid'];
        }
        if (isset($nonstks['multiline']) and $nonstks['multiline'] == "yes") {
            $edit = "nons-multiline-invoice-new.php";
        } else {
            $edit = "nons-invoice-new.php";
        }
        $cur = CUR;
        $printOrd .= "\r\n\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t<td>{$nonstks['invnum']}</td>\r\n\t\t\t\t<td>{$nonstks['docref']}</td>\r\n\t\t\t\t<td>{$date}</td>\r\n\t\t\t\t<td>{$nonstks['cusname']}</td>\r\n\t\t\t\t<td align='right'>{$cur} {$nonstks['total']}</td>\r\n\t\t\t\t<td><a href='{$edit}?invid={$nonstks['invid']}&cont=1'>Continue</a></td>\r\n\t\t\t</tr>";
        $i++;
    }
    $tot_total = sprint($tot_total);
    $printOrd .= "\r\n\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t<td colspan='4'>Totals</td>\r\n\t\t\t\t<td align='right'>" . CUR . " {$tot_total}</td>\r\n\t\t\t</tr>\r\n\t\t</table>";
    return $printOrd;
}
function confirm($_POST)
{
    # Get vars
    extract($_POST);
    if (isset($back)) {
        header("Location: cashbook-entry.php");
        exit;
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($bankid, "num", 1, 30, "Invalid Bank Account.");
    $v->isOk($o_day, "num", 1, 2, "Invalid Date day.");
    $v->isOk($o_month, "num", 1, 2, "Invalid Date month.");
    $v->isOk($o_year, "num", 1, 4, "Invalid Date Year.");
    $v->isOk($name, "string", 1, 255, "Invalid Person/Business paid to/received from.");
    $v->isOk($descript, "string", 0, 255, "Invalid Description.");
    $v->isOk($reference, "string", 0, 255, "Invalid Description.");
    $v->isOk($cheqnum, "num", 0, 30, "Invalid Cheque number.");
    $v->isOk($amount, "float", 1, 10, "Invalid amount.");
    $v->isOk($chrgvat, "string", 1, 4, "Invalid vat option.");
    $v->isOk($accinv, "num", 1, 20, "Invalid Account involved.");
    $date = mkdate($o_year, $o_month, $o_day);
    $v->isOk($date, "date", 1, 1, "Invalid date.");
    if ($v->isError()) {
        $err = $v->genErrors();
        return $err . add($_POST);
    }
    # Start rattling vat
    $totamt = $amount;
    vsprint($vat);
    if ($vatcode != $orig_vatcode || $amount != $orig_amount || $chrgvat != $orig_chrgvat) {
        db_conn('cubit');
        $Sl = "SELECT * FROM vatcodes WHERE id='{$vatcode}'";
        $Ri = db_exec($Sl) or errDie("Unable to get vat codes");
        $vd = pg_fetch_array($Ri);
        $vatp = $vd['vat_amount'];
        if ($chrgvat == "exc") {
            $vat = sprint($vatp / 100 * $amount);
        } else {
            if ($chrgvat == "inc") {
                $vat = sprint($amount * $vatp / ($vatp + 100));
            } else {
                $vat = 0;
            }
        }
    }
    if ($chrgvat == "exc") {
        $totamt += $vat;
        $vatin = CUR . "<input type='text' name='vat' value='{$vat}' />";
    } else {
        if ($chrgvat == "inc") {
            $vatin = CUR . "<input type='text' name='vat' value='{$vat}' />";
        } else {
            $vatin = "No VAT";
        }
    }
    $OUT = "\n\t\t\t<center>\n\t\t\t<h3>Edit Bank Receipt</h3>\n\t\t\t<h4>Confirm entry (Please check the details)</h4>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t\t<input type='hidden' name='key' value='write' />\n\t\t\t\t<input type='hidden' name='id' value='{$id}' />\n\t\t\t\t<input type='hidden' name='bankid' value='{$bankid}' />\n\t\t\t\t<input type='hidden' name='date' value='{$date}' />\n\t\t\t\t<input type='hidden' name='name' value='{$name}' />\n\t\t\t\t<input type='hidden' name='descript' value='{$descript}' />\n\t\t\t\t<input type='hidden' name='reference' value='{$reference}' />\n\t\t\t\t<input type='hidden' name='cheqnum' value='{$cheqnum}' />\n\t\t\t\t<input type='hidden' name='amount' value='{$amount}' />\n\t\t\t\t<input type='hidden' name='chrgvat' value='{$chrgvat}' />\n\t\t\t\t<input type='hidden' name='accinv' value='{$accinv}' />\n\t\t\t\t<input type='hidden' name='vatcode' value='{$vatcode}' />";
    # Get bank account name
    db_connect();
    $sql = "SELECT accname,bankname FROM bankacct WHERE bankid = '{$bankid}' AND div = '" . USER_DIV . "'";
    $bankRslt = db_exec($sql);
    $bank = pg_fetch_array($bankRslt);
    # get hook account number
    core_connect();
    $sql = "SELECT * FROM bankacc WHERE accid = '{$bankid}' AND div = '" . USER_DIV . "'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve bank account link from Cubit", SELF);
    # check if link exists
    if (pg_numrows($rslt) < 1) {
        return "<li class=err> ERROR : The bank account that you selected doesn't appear to have an account linked to it.";
    }
    $banklnk = pg_fetch_array($rslt);
    # Get bank balance
    $sql = "SELECT (debit - credit) as bal FROM trial_bal WHERE period='" . getPRDDB($date) . "' AND accid = '{$banklnk['accnum']}' AND div = '" . USER_DIV . "'";
    $brslt = db_exec($sql) or errDie("Unable to retrieve bank account link from Cubit", SELF);
    $bal = pg_fetch_array($brslt);
    $accRslt = get("core", "accname,topacc,accnum", "accounts", "accid", $accinv);
    $accnt = pg_fetch_array($accRslt);
    $OUT .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Field</th>\n\t\t\t\t\t\t<th>Value</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Account</td>\n\t\t\t\t\t\t<td>{$bank['accname']} - {$bank['bankname']}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Account Balance</td>\n\t\t\t\t\t\t<td>" . CUR . " {$bal['bal']}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Date</td>\n\t\t\t\t\t\t<td valign='center'>{$date}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Received from</td>\n\t\t\t\t\t\t<td valign='center'>{$name}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Description</td>\n\t\t\t\t\t\t<td valign='center'>{$descript}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Reference</td>\n\t\t\t\t\t\t<td valign='center'>{$reference}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Cheque Number</td>\n\t\t\t\t\t\t<td valign='center'>{$cheqnum}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>Amount</td>\n\t\t\t\t\t\t<td valign='center'>" . CUR . " " . sprint($totamt) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='bg-odd'>\n\t\t\t\t\t\t<td>VAT </td>\n\t\t\t\t\t\t<td>{$vatin}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='bg-even'>\n\t\t\t\t\t\t<td>Ledger Account Received from</td>\n\t\t\t\t\t\t<td valign='center'>{$accnt['topacc']}/{$accnt['accnum']} - {$accnt['accname']}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t \t" . TBL_BR . "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t\t\t<td align='right'><input type='submit' value='Write &raquo'></td>\n\t\t\t\t\t</tr>\n\t\t\t\t</form>\n\t\t\t\t</table>" . mkQuickLinks();
    return $OUT;
}
function is_LastDayOfWeek($y, $m, $d)
{
    // 翌週の同曜日が翌月ならば最終と判断
    $x = mkdate($y, $m, $d, 7);
    if ($m == $x['m']) {
        return 0;
    }
    return 1;
}
Example #23
0
 function show()
 {
     global $set, $db, $apx, $html;
     quicklink('banner.add');
     //Gruppen-Auswahl
     $_REQUEST['gid'] = (int) $_REQUEST['gid'];
     $groupdata = array();
     foreach ($set['banner']['groups'] as $id => $title) {
         $groupdata[] = array('ID' => $id, 'TITLE' => compatible_hsc($title), 'SELECTED' => $_REQUEST['gid'] == $id);
     }
     $apx->tmpl->assign('GROUP', $groupdata);
     $apx->tmpl->parse('show_choose');
     $orderdef[0] = 'partner';
     $orderdef['partner'] = array('partner', 'ASC', 'COL_PARTNER');
     $orderdef['views'] = array('views', 'ASC', 'COL_VIEWS');
     $orderdef['group'] = array('a.group', 'ASC', 'COL_GROUP');
     $col[] = array('', 1, '');
     $col[] = array('COL_PARTNER', 40, 'class="title"');
     $col[] = array('COL_PERIOD', 25, 'align="center"');
     $col[] = array('COL_VIEWS', 15, 'align="center"');
     $col[] = array('COL_GROUP', 20, 'align="center"');
     list($count) = $db->first("SELECT count(id) FROM " . PRE . "_banner WHERE 1 " . iif($_REQUEST['gid'], "AND `group`=" . $_REQUEST['gid']));
     pages('action.php?action=banner.show&amp;sortby=' . $_REQUEST['sortby'] . iif($_REQUEST['gid'], '&amp;gid=' . $_REQUEST['gid']), $count);
     $data = $db->fetch("SELECT * FROM " . PRE . "_banner AS a WHERE 1 " . iif($_REQUEST['gid'], "AND `group`=" . $_REQUEST['gid']) . getorder($orderdef) . getlimit());
     if (count($data)) {
         foreach ($data as $res) {
             ++$i;
             if (!$res['starttime']) {
                 $tabledata[$i]['COL1'] = '<img src="design/reddot.gif" alt="' . $apx->lang->get('CORE_INACTIVE') . '" title="' . $apx->lang->get('CORE_INACTIVE') . '" />';
             } elseif ($res['endtime'] < time()) {
                 $tabledata[$i]['COL1'] = '<img src="design/greendotcross.gif" alt="' . $apx->lang->get('CORE_INACTIVE') . '" title="' . $apx->lang->get('CORE_INACTIVE') . '" />';
             } elseif ($res['starttime'] > time()) {
                 $tabledata[$i]['COL1'] = '<img src="design/greendotwait.gif" alt="' . $apx->lang->get('CORE_ACTIVE') . '" title="' . $apx->lang->get('CORE_ACTIVE') . '" />';
             } else {
                 $tabledata[$i]['COL1'] = '<img src="design/greendot.gif" alt="' . $apx->lang->get('CORE_ACTIVE') . '" title="' . $apx->lang->get('CORE_ACTIVE') . '" />';
             }
             $period = '';
             if ($res['starttime']) {
                 $period = $apx->lang->get('FROM') . ': ' . mkdate($res['starttime']);
                 if ($res['endtime'] != 3000000000) {
                     $period .= '<br />' . $apx->lang->get('TILL') . ': ' . mkdate($res['endtime']);
                 }
             }
             $tabledata[$i]['COL2'] = replace($res['partner']);
             $tabledata[$i]['COL3'] = $period;
             $tabledata[$i]['COL4'] = number_format($res['views'], 0, '', '.') . iif($res['limit'], ' / ' . number_format($res['limit'], 0, '', '.'));
             $tabledata[$i]['COL5'] = $set['banner']['groups'][$res['group']];
             //Limit erreicht?
             if ($res['limit'] && $res['views'] >= $res['limit']) {
                 $tabledata[$i]['COL4'] = '<span style="color:red;">' . $tabledata[$i]['COL4'] . '</span>';
             }
             //Optionen
             if ($apx->user->has_right('banner.edit')) {
                 $tabledata[$i]['OPTIONS'] .= optionHTML('edit.gif', 'banner.edit', 'id=' . $res['id'], $apx->lang->get('CORE_EDIT'));
             } else {
                 $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
             }
             if ($apx->user->has_right('banner.del')) {
                 $tabledata[$i]['OPTIONS'] .= optionHTMLOverlay('del.gif', 'banner.del', 'id=' . $res['id'], $apx->lang->get('CORE_DEL'));
             } else {
                 $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
             }
             if ((!$res['starttime'] || $res['endtime'] < time()) && $apx->user->has_right('banner.enable')) {
                 $tabledata[$i]['OPTIONS'] .= optionHTMLOverlay('enable.gif', 'banner.enable', 'id=' . $res['id'], $apx->lang->get('CORE_ENABLE'));
             } elseif ($res['starttime'] && $apx->user->has_right('banner.disable')) {
                 $tabledata[$i]['OPTIONS'] .= optionHTMLOverlay('disable.gif', 'banner.disable', 'id=' . $res['id'], $apx->lang->get('CORE_DISABLE'));
             } else {
                 $tabledata[$i]['OPTIONS'] .= '<img src="design/ispace.gif" alt="" />';
             }
         }
     }
     $apx->tmpl->assign('TABLE', $tabledata);
     $html->table($col);
     orderstr($orderdef, "action.php?action=banner.show");
     save_index($_SERVER['REQUEST_URI']);
 }
function update($_POST)
{
    extract($_POST);
    $collect_ar = array();
    if (!empty($client_collect)) {
        $collect_ar[] = "Client Collect";
    }
    if (!empty($collect)) {
        $collect_ar[] = "Collect";
    }
    if (!empty($deliver)) {
        $collect_ar[] = "Deliver";
    }
    $collection = implode(", ", $collect_ar);
    // 	if ((in_array("Collect", $collect_ar) && in_array("Client Collect", $collect_ar))
    // 		|| (count($collect_ar) == 3)) {
    // 		return "<li class='err'>Invalid collection options selected.</li>";
    // 	}
    if (count($collect_ar) > 1 && in_array("Client Collect", $collect_ar)) {
        return "<li class='err'>Invalid collection options selected.</li>";
    }
    $temp_assets = explode(",", $temp_assets);
    pglib_transaction("BEGIN");
    // Stock Sales
    if (isset($snremove) && is_array($snremove)) {
        foreach ($snremove as $id => $value) {
            $sql = "DELETE FROM hire.hire_stock_items WHERE id='{$id}'";
            db_exec($sql) or errDie("Unable to remove stock item.");
        }
    }
    if (isset($snstock) && $snstock > 0) {
        if (!is_numeric($snqty)) {
            $snqty = 1;
        }
        #get vatperc for this item
        $get_vatp = "SELECT vat_amount FROM vatcodes WHERE id = '{$snvatcode}' LIMIT 1";
        $run_vatp = db_exec($get_vatp) or errDie("Unable to get vat code information.");
        if (pg_numrows($run_vatp) < 1) {
            $vatperc = 0;
        } else {
            $vatperc = pg_fetch_result($run_vatp, 0, 0);
        }
        //		$sql = "SELECT selamt FROM cubit.stock WHERE stkid='$snstock'";
        //		$price_rslt = db_exec($sql) or errDie("Unable to retrieve price.");
        //		$price = pg_fetch_result($price_rslt, 0);
        $price = get_excl_stock($snstock) * $snqty;
        $excl_price = get_excl_stock($snstock) * $snqty;
        $vatamount = sprint($excl_price / 100 * $vatperc);
        $price += 0;
        $price += sprint($excl_price / 100 * $vatperc);
        $snamt = $price * $snqty;
        #hack, because stores functionality isnt working ...
        $get_store = "SELECT whid FROM stock WHERE stkid = '{$snstock}' LIMIT 1";
        $run_store = db_exec($get_store) or errDie("Unable to get stock store information.");
        $snstore = pg_fetch_result($run_store, 0, 0);
        $sql = "\r\n\t\t\tINSERT INTO hire.hire_stock_items (\r\n\t\t\t\twhid, invid, stkid, qty, vatcode, unitcost, \r\n\t\t\t\tamount, excl_amount, vatamount\r\n\t\t\t) VALUES (\r\n\t\t\t\t'{$snstore}', '{$invid}', '{$snstock}', '{$snqty}', '{$snvatcode}', '" . sprint($price / $snqty) . "', \r\n\t\t\t\t'" . sprint($snamt / $snqty) . "', '{$excl_price}', '{$vatamount}'\r\n\t\t\t)";
        db_exec($sql) or errDie("Unable to add stock.");
        $sql = "UPDATE cubit.stock SET alloc=(alloc+'{$snqty}') WHERE stkid='{$snstock}'";
        db_exec($sql) or errDie("Unable to update stock allocation.");
    }
    if (isset($nhalf_day) && $nhalf_day == "checked") {
        $nhalf_day = 1;
    } else {
        $nhalf_day = 0;
    }
    if (isset($nweekends) && $nweekends == "checked") {
        $nweekends = 1;
    } else {
        $nweekends = 0;
    }
    $sql = "UPDATE hire.hire_invoices SET comm='{$comm}' WHERE invid='{$invid}'";
    $comm_rslt = db_exec($sql) or errDie("Unable to retrieve invoice.");
    foreach ($temp_assets as $key => $value) {
        $sql = "SELECT * FROM cubit.assets WHERE id='{$key}'";
        $asset_rslt = db_exec($sql) or errDie("Unable to retrieve asset.");
        $asset_data = pg_fetch_array($asset_rslt);
    }
    if (isset($amount)) {
        foreach ($amount as $key => $value) {
            // 			if (empty($monthly)) {
            // 				$amount[$key] = "";
            // 			}
            #redundant code ... breaks new hire if you click update multiple times (sets item amount = 0 after second update)
            //			if (!user_is_admin(USER_ID)) {
            //				$amount[$key] = "";
            //			}
            if (!isset($half_day[$key]) || empty($half_day[$key])) {
                $half_day[$key] = 0;
            }
            if (!isset($weekends[$key]) || empty($weekends[$key])) {
                $weekends[$key] = 0;
            } else {
                $weekends[$key] = 1;
            }
            if (!isset($total_days[$key]) || empty($total_days[$key])) {
                $epoch_from = strtotime($from_date[$key]);
                $epoch_to = strtotime($to_date[$key]);
                $total_days[$key] = ($epoch_to - $epoch_from) / (60 * 60 * 24) + 1;
                $total_days[$key] = ceil($total_days[$key]);
            }
            $sql = "SELECT qty, total_days, half_day FROM hire.hire_invitems WHERE id='{$key}'";
            $old_rslt = db_exec($sql) or errDie("Unable to retrieve old qty.");
            list($oldqty, $olddays, $oldhalf_day) = pg_fetch_array($old_rslt);
            if (!isset($oldqty)) {
                $oldqty = 1;
            }
            if (!isset($qty[$key])) {
                $oldqty = 1;
                $qty[$key] = 1;
            }
            if ($half_day[$key]) {
                $half_day[$key] = 1;
                $recalc = FALSE;
            } else {
                $half_day[$key] = 0;
            }
            if (empty($amount) && $amount != 0 || $oldqty != $qty[$key] || $olddays != $total_days[$key] || (!isset($amount[$key]) or empty($amount[$key])) || $half_day == 1) {
                if ($basis[$key] == "per_day") {
                    $to_time = strtotime($from_date[$key]) + $total_days[$key] * (60 * 60 * 24);
                    $hifrm = "{$mfrm_year[$key]}-{$mfrm_month[$key]}-{$mfrm_day[$key]}";
                    $hito = date("Y-m-d", $to_time);
                    $hours = "0";
                    /* calculate amount */
                    $ftime = getDTEpoch("{$hifrm} 0:00:00");
                    $ttime = getDTEpoch("{$hito} 0:00:00");
                    $days = 0;
                    $weeks = 0;
                    $months = 0;
                    while ($ftime <= $ttime) {
                        if (date("w", $ftime) == 0 && isset($weekends[$key]) && $weekends[$key]) {
                            $days += 0.6;
                        } else {
                            ++$days;
                        }
                        $ftime += 24 * 60 * 60;
                    }
                    $timeunits = $total_days[$key];
                } else {
                    if ($basis[$key] == "per_hour") {
                        $hifrm = $hito = mkdate($pinv_year, $pinv_month, $pinv_day);
                        $timeunits = $hours;
                        $weeks = 0;
                        $months = 0;
                        if (empty($hours) || !is_numeric($hours)) {
                            return "<li class='err'><b>ERROR</b>: Invalid amount of hours.</li>";
                        }
                    } else {
                        if ($nbasis == "per_week") {
                            $nhifrm = $nhito = mkdate($pinv_year, $pinv_month, $pinv_day);
                            $timeunits = $weeks;
                            $hours = 0;
                            $months = 0;
                            if (empty($weeks) || !is_numeric($weeks)) {
                                return "<li class='err'><b>ERROR</b>: Invalid amount of weeks.</li>";
                            }
                        } else {
                            if ($nbasis == "per_month") {
                                $nhifrm = $nhito = mkDate($pinv_year, $pinv_month, $pinv_day);
                                $timeunits = $months;
                                $weeks = 0;
                                $hours = 0;
                                if (empty($months) || !is_numeric($months)) {
                                    return "<li class='err'><b>ERROR</b>: Invalid amount of months.</li>";
                                }
                            }
                        }
                    }
                }
                if ($half_day[$key]) {
                    //					$amount[$key] = ($qty[$key] * $timeunits * (basisPrice($cusnum, $asset_id[$key], $basis[$key]) * $qty[$key]) - (basisPrice($cusnum, $asset_id[$key], $basis[$key]) * $qty[$key]) + ((basisPrice($cusnum, $asset_id[$key], $basis[$key]) * $qty[$key])) / halfday_rate());
                    $amount[$key] = sprint($qty[$key] * ($timeunits * basisPrice($cusnum, $asset_id[$key], $basis[$key]) - basisPrice($cusnum, $asset_id[$key], $basis[$key]) + basisPrice($cusnum, $asset_id[$key], $basis[$key]) / halfday_rate()));
                } else {
                    $amount[$key] = $qty[$key] * $timeunits * basisPrice($cusnum, $asset_id[$key], $basis[$key]);
                }
            }
            if ($amount[$key] == 0) {
                $amount[$key] = 0;
                $blank_amount = 1;
            } else {
                $blank_amount = 0;
            }
            $sql = "\r\n\t\t\t\tUPDATE hire.hire_invitems \r\n\t\t\t\tSET amt='{$amount[$key]}', half_day='{$half_day[$key]}', weekends='{$weekends[$key]}', \r\n\t\t\t\t\ttotal_days='{$total_days[$key]}', qty='{$qty[$key]}' \r\n\t\t\t\tWHERE id='{$key}'";
            db_exec($sql) or errDie("Unable to update item amount.");
            $sql = "\r\n\t\t\t\tUPDATE hire.reprint_invitems \r\n\t\t\t\tSET amt='{$amount[$key]}', half_day='{$half_day[$key]}', weekends='{$weekends[$key]}' \r\n\t\t\t\tWHERE item_id='{$key}'";
            db_exec($sql) or errDie("Unable to update return item amount.");
            if ($blank_amount) {
                $amount[$key] = "";
            }
            //$hifrm = "$hifrm_year[$key]-$hifrm_month[$key]-$hifrm_day[$key]";
            //$hito = "$hito_year[$key]-$hito_month[$key]-$hito_day[$key]";
            if (!isset($remove[$key])) {
                $sql = "SELECT basis FROM hire.hire_invitems WHERE id='{$key}'";
                $item_rslt = db_exec($sql) or errDie("Unable to retrieve basis.");
                $mbasis = pg_fetch_result($item_rslt, 0);
                /* determine time units */
                if ($mbasis == "per_day") {
                    $mfrm = mkdate($mfrm_year[$key], $mfrm_month[$key], $mfrm_day[$key]);
                    $mto = mkdate($mto_year[$key], $mto_month[$key], $mto_day[$key]);
                    /* calculate amount */
                    $ftime = mktime(0, 0, 0, $mfrm_month[$key], $mfrm_day[$key], $mfrm_year[$key]);
                    $ttime = mktime(0, 0, 0, $mto_month[$key], $mto_day[$key], $mto_year[$key]);
                    $days = 0;
                    if (empty($weeks)) {
                        $weeks = 0;
                    }
                    if (empty($hours)) {
                        $hours = 0;
                    }
                    if (empty($months)) {
                        $months = 0;
                    }
                    while ($ftime <= $ttime) {
                        if (date("w", $ftime) == 0 && isset($weekends[$key]) && $weekends[$key]) {
                            $days += 0.6;
                        } else {
                            ++$days;
                        }
                        $ftime += 24 * 60 * 60;
                    }
                    $timeunits = $days;
                    $sql = "\r\n\t\t\t\t\t\tUPDATE hire.hire_invitems \r\n\t\t\t\t\t\tSET from_date='{$mfrm}', to_date='{$mto}' \r\n\t\t\t\t\t\tWHERE id='{$key}'";
                    db_exec($sql) or errDie("Unable to update items.");
                    $sql = "\r\n\t\t\t\t\t\tUPDATE hire.reprint_invitems \r\n\t\t\t\t\t\tSET from_date='{$mfrm}', to_date='{$mto}' \r\n\t\t\t\t\t\tWHERE item_id='{$key}'";
                    db_exec($sql) or errDie("Unable to update reprint items.");
                }
            } else {
                // Delete the old items
                $sql = "DELETE FROM hire.hire_invitems WHERE id='{$key}'";
                db_exec($sql) or errDie("Unable to remove old items.");
                $sql = "DELETE FROM hire.reprint_invitems WHERE item_id='{$key}'";
                db_exec($sql) or errDie("Unable to remove old reprint items.");
                //.Remove if the item has been hired as well
                $sql = "DELETE FROM hire.assets_hired WHERE item_id='{$key}'";
                db_exec($sql) or errDie("Unable to remove items from hired log.");
            }
        }
    }
    $sql = "SELECT * FROM hire.hire_invoices WHERE invid='{$invid}'";
    $hi_rslt = db_exec($sql) or errDie("Unable to retrieve invoice.");
    $invb = pg_fetch_array($hi_rslt);
    // Default basis
    if (!empty($nasset_id) && $nbasis == "0") {
        list($serialqty, $tasset_id) = explode(":", $nasset_id);
        $nbasis = default_basis($tasset_id);
    }
    // Insert new items
    if ($nasset_id != "0") {
        if ($nasset_id == "0") {
            return "<li class='err'><b>ERROR</b>: No asset selected.</li>";
        }
        /* get asset id */
        list($serialqty, $nasset_id) = explode(":", $nasset_id);
        /* disabled items don't get passed through */
        if ($serialqty == "s" || !isset($nqty)) {
            $nqty = "1";
        } else {
            $sql = "SELECT serial2 FROM cubit.assets WHERE id='{$nasset_id}'";
            $dqty_rslt = db_exec($sql) or errDie("Unable to retrieve assets.");
            $dqty = pg_fetch_result($dqty_rslt, 0);
            if ($dqty - $nqty < 0) {
                return "<li class='err'><b>ERROR</b>: Invalid quantity. Only &nbsp; <b>{$dqty}</b> &nbsp; available.</li>";
            }
        }
        if (empty($nqty) || !is_numeric($nqty)) {
            return "<li class='err'><b>ERROR</b>: Invalid quantity</li>";
        }
        // Default basis
        if ($nbasis == "0") {
            $nbasis = default_basis($nasset_id);
        }
        /* determine time units */
        if ($nbasis == "per_day") {
            $nhifrm = mkdate($nhifrm_year, $nhifrm_month, $nhifrm_day);
            $nhito = mkdate($nhito_year, $nhito_month, $nhito_day);
            $hours = "0";
            /* calculate amount */
            $ftime = mktime(0, 0, 0, $nhifrm_month, $nhifrm_day, $nhifrm_year);
            $ttime = mktime(0, 0, 0, $nhito_month, $nhito_day, $nhito_year);
            $days = 0;
            $weeks = 0;
            $months = 0;
            while ($ftime <= $ttime) {
                if (date("w", $ftime) == 0 && isset($nweekends) && $nweekends) {
                    $days += 0.6;
                } else {
                    ++$days;
                }
                $ftime += 24 * 60 * 60;
            }
            $timeunits = $days;
        } else {
            if ($nbasis == "per_hour") {
                $nhifrm = $nhito = mkdate($pinv_year, $pinv_month, $pinv_day);
                $timeunits = $hours;
                $weeks = 0;
                $months = 0;
                if (empty($hours) || !is_numeric($hours)) {
                    return "<li class='err'><b>ERROR</b>: Invalid amount of hours.</li>";
                }
            } else {
                if ($nbasis == "per_week") {
                    $nhifrm = $nhito = mkdate($pinv_year, $pinv_month, $pinv_day);
                    $timeunits = $weeks;
                    $hours = 0;
                    $months = 0;
                    if (empty($weeks) || !is_numeric($weeks)) {
                        return "<li class='err'><b>ERROR</b>: Invalid amount of weeks.</li>";
                    }
                } else {
                    if ($nbasis == "per_month") {
                        $nhifrm = $nhito = mkdate($pinv_year, $pinv_month, $pinv_day);
                        $timeunits = $months;
                        $hours = 0;
                        $weeks = 0;
                        if (empty($months) || !is_numeric($months)) {
                            return "<li class='err'><b>ERROR</b>: Invalid amount of months.</li>";
                        }
                    } else {
                        return "<li class='err'><b>ERROR</b>: No basis selected.</li>";
                    }
                }
            }
        }
        /* calculate amount according to hire settings, quantity and time units */
        if ($nhalf_day) {
            $camt = $nqty * $timeunits * basisPrice($cusnum, $nasset_id, $nbasis) - basisPrice($cusnum, $nasset_id, $nbasis) + basisPrice($cusnum, $nasset_id, $nbasis) / halfday_rate();
        } else {
            $camt = $nqty * $timeunits * basisPrice($cusnum, $nasset_id, $nbasis);
        }
        /* insert item */
        $sql = "SELECT asset_id FROM hire.hire_invitems\r\n\t\t\t\tWHERE invid='{$invid}' AND asset_id='{$nasset_id}'";
        $asset_rslt = db_exec($sql) or errDie("Unable to retrieve assets.");
        // No duplicate assets
        if (!pg_num_rows($asset_rslt) || !isSerialized($nasset_id)) {
            if (isHired($nasset_id)) {
                return "\r\n\t\t\t\t<li class='err'>\r\n\t\t\t\t\t<b>ERROR</b>: Asset has already hired out.\r\n\t\t\t\t</li>";
            }
            $sql = "\r\n\t\t\t\tINSERT INTO hire.hire_invitems (\r\n\t\t\t\t\tinvid, asset_id, qty, amt, from_date, to_date, basis, hours, weeks, \r\n\t\t\t\t\tmonths, collection, half_day, weekends\r\n\t\t\t\t) VALUES (\r\n\t\t\t\t\t'{$invid}', '{$nasset_id}', '{$nqty}', '{$camt}', '{$nhifrm}', '{$nhito}', '{$nbasis}', '{$hours}', '{$weeks}', \r\n\t\t\t\t\t'{$months}', '{$collection}', '{$nhalf_day}', '{$nweekends}'\r\n\t\t\t\t)";
            db_exec($sql) or errDie("Unable to create new invoice item.");
            $item_id = pglib_lastid("hire.hire_invitems", "id");
            $sql = "\r\n\t\t\t\tINSERT INTO hire.reprint_invitems (\r\n\t\t\t\t\tinvid, asset_id, qty, amt, from_date, to_date, basis, hours, weeks, \r\n\t\t\t\t\tmonths, collection, half_day, weekends, item_id\r\n\t\t\t\t) VALUES (\r\n\t\t\t\t\t'{$invid}', '{$nasset_id}', '{$nqty}', '{$camt}', '{$nhifrm}', '{$nhito}', '{$nbasis}', '{$hours}', '{$weeks}', \r\n\t\t\t\t\t'{$months}', '{$collection}', '{$nhalf_day}', '{$nweekends}', '{$item_id}'\r\n\t\t\t\t)";
            db_exec($sql) or errDie("Unable to create reprint invoice item.");
        }
    }
    if ($monthly == "true") {
        $sql = "DELETE FROM hire.monthly_invitems WHERE invid='{$invid}'";
        db_exec($sql) or errDie("Unable to remove monthly items.");
    } else {
        $sql = "SELECT * FROM hire.hire_invitems WHERE invid='{$invid}'";
        $mii_rslt = db_exec($sql) or errDie("Unable to retrieve inv items.");
        $sql = "DELETE FROM hire.monthly_invitems WHERE invid='{$invid}'";
        db_exec($sql) or errDie("Unable to remove monthly items.");
        while ($item = pg_fetch_array($mii_rslt)) {
            $sql = "\r\n\t\t\t\tINSERT INTO hire.monthly_invitems (\r\n\t\t\t\t\tinvid, asset_id, qty, amt, from_date, to_date, \r\n\t\t\t\t\tbasis, hours, weeks, months, collection, half_day, \r\n\t\t\t\t\tweekends, item_id, invnum\r\n\t\t\t\t) VALUES (\r\n\t\t\t\t\t'{$item['invid']}', '{$item['asset_id']}', '{$item['qty']}', '{$item['amt']}', '{$item['from_date']}', '{$item['to_date']}', \r\n\t\t\t\t\t'{$item['basis']}', '{$item['hours']}', '{$item['weeks']}', '{$item['months']}', '{$item['collection']}', '{$item['half_day']}',\r\n\t\t\t\t\t'{$item['weekends']}', '{$item['id']}', '{$invb['invnum']}'\r\n\t\t\t\t)";
            db_exec($sql) or errDie("Unable to create monthly items.");
        }
    }
    $sql = "SELECT * FROM hire.reprint_invoices WHERE invid='{$invid}'";
    $ri_rslt = db_exec($sql) or errDie("Unable to retrieve reprints.");
    // Create a new entry, or update
    if (pg_num_rows($ri_rslt)) {
        $sql = "\r\n\t\t\tUPDATE hire.reprint_invoices \r\n\t\t\tSET deptid='{$invb['deptid']}', cusnum='{$invb['cusnum']}', deptname='{$invb['deptname']}', cusacc='{$invb['cusacc']}',\r\n\t\t\t\tcusname='{$invb['cusname']}', surname='{$invb['surname']}', cusaddr='{$invb['cusaddr']}', cusvatno='{$invb['cusvatno']}', \r\n\t\t\t\tcordno='{$invb['cordno']}', ordno='{$invb['ordno']}', chrgvat='{$invb['chrgvat']}', terms='{$invb['terms']}', \r\n\t\t\t\ttraddisc='{$invb['traddisc']}', salespn='{$invb['salespn']}', odate='{$invb['odate']}', delchrg='{$delchrg}', \r\n\t\t\t\tsubtot='{$invb['subtot']}', vat='{$invb['vat']}', total='{$invb['total']}', balance='{$invb['balance']}', \r\n\t\t\t\tcomm='{$invb['comm']}', printed='{$invb['printed']}', done='{$invb['done']}', div='{$invb['div']}', \r\n\t\t\t\tusername='******'username']}', rounding='{$invb['rounding']}', delvat='{$invb['delvat']}', vatnum='{$invb['vatnum']}', \r\n\t\t\t\tpcash='{$invb['pcash']}', pcheque='{$invb['pcheque']}', pcc='{$invb['pcc']}', pcredit='{$invb['pcredit']}' \r\n\t\t\tWHERE invid='{$invid}'";
        db_exec($sql) or errDie("Unable to update reprint.");
    } else {
        $sql = "\r\n\t\t\tINSERT INTO hire.reprint_invoices (\r\n\t\t\t\tinvid, invnum, deptid, cusnum, deptname, cusacc, \r\n\t\t\t\tcusname, surname, cusaddr, cusvatno, cordno, ordno, \r\n\t\t\t\tchrgvat, terms, traddisc, salespn, odate, delchrg, \r\n\t\t\t\tsubtot, vat, total, balance, comm, printed, done, div, \r\n\t\t\t\tusername, rounding, delvat, vatnum, pcash, pcheque, \r\n\t\t\t\tpcc, pcredit\r\n\t\t\t) VALUES (\r\n\t\t\t\t'{$invid}', '{$invb['invnum']}', '{$invb['deptid']}', '{$invb['cusnum']}', '{$invb['deptname']}', '{$invb['cusacc']}', \r\n\t\t\t\t'{$invb['cusname']}', '{$invb['surname']}', '{$invb['cusaddr']}', '{$invb['cusvatno']}', '{$invb['cordno']}', '{$invb['ordno']}',\r\n\t\t\t\t'{$invb['chrgvat']}', '{$invb['terms']}', '{$invb['traddisc']}', '{$invb['salespn']}', '{$invb['odate']}', '{$invb['delchrg']}', \r\n\t\t\t\t'{$invb['subtot']}', '{$invb['vat']}' , '{$invb['total']}', '{$invb['balance']}', '{$invb['comm']}', 'y', 'y', '" . USER_DIV . "', \r\n\t\t\t\t'" . USER_NAME . "', '{$invb['rounding']}', '{$invb['delvat']}', '{$invb['vatnum']}', '{$invb['pcash']}', '{$invb['pcheque']}', \r\n\t\t\t\t'{$invb['pcc']}', '{$invb['pcredit']}'\r\n\t\t\t)";
        db_exec($sql) or errDie("Unable to add reprint.");
    }
    $sql = "SELECT * FROM hire.monthly_invoices WHERE invid='{$invid}' OR invnum='{$invb['invnum']}' AND invnum!=0";
    $mi_rslt = db_exec($sql) or errDie("Unable to retrieve monthly.");
    // Should we create a new entry
    if (pg_num_rows($mi_rslt)) {
        $sql = "\r\n\t\t\tUPDATE hire.monthly_invoices \r\n\t\t\tSET deptid='{$invb['deptid']}', cusnum='{$invb['cusnum']}', deptname='{$invb['deptname']}', cusacc='{$invb['cusacc']}', \r\n\t\t\t\tcusname='{$invb['cusname']}', surname='{$invb['surname']}', cusaddr='{$invb['cusaddr']}', cusvatno='{$invb['cusvatno']}', \r\n\t\t\t\tcordno='{$invb['cordno']}', ordno='{$invb['ordno']}', chrgvat='{$invb['chrgvat']}', terms='{$invb['terms']}', \r\n\t\t\t\ttraddisc='{$invb['traddisc']}', salespn='{$invb['salespn']}', odate='{$invb['odate']}', delchrg='{$invb['delchrg']}', \r\n\t\t\t\tsubtot='{$invb['subtot']}', vat='{$invb['vat']}', total='{$invb['total']}', balance='{$invb['balance']}', \r\n\t\t\t\tcomm='{$invb['comm']}', printed='{$invb['printed']}', done='{$invb['done']}', div='{$invb['div']}', \r\n\t\t\t\tusername='******'username']}', rounding='{$invb['rounding']}', delvat='{$invb['delvat']}', vatnum='{$invb['vatnum']}', \r\n\t\t\t\tpcash='{$invb['pcash']}', pcheque='{$invb['pcheque']}', pcc='{$invb['pcc']}', pcredit='{$invb['pcredit']}', \r\n\t\t\t\thire_invid='{$invid}' \r\n\t\t\tWHERE invid='{$invb['invid']}'";
    } elseif (empty($monthly)) {
        $sql = "\r\n\t\t\t\tINSERT INTO hire.monthly_invoices (\r\n\t\t\t\t\tinvid, invnum, deptid, cusnum, deptname, cusacc, \r\n\t\t\t\t\tcusname, surname, cusaddr, cusvatno, cordno, \r\n\t\t\t\t\tordno, chrgvat, terms, traddisc, salespn, \r\n\t\t\t\t\todate, delchrg, subtot, vat, total, balance, \r\n\t\t\t\t\tcomm, printed, done, div, username, rounding, delvat, \r\n\t\t\t\t\tvatnum, pcash, pcheque, pcc, pcredit, invoiced_month, \r\n\t\t\t\t\thire_invid\r\n\t\t\t\t) VALUES (\r\n\t\t\t\t\t'{$invid}', '{$invb['invnum']}', '{$invb['deptid']}', '{$invb['cusnum']}', '{$invb['deptname']}', '{$invb['cusacc']}', \r\n\t\t\t\t\t'{$invb['cusname']}', '{$invb['surname']}', '{$invb['cusaddr']}', '{$invb['cusvatno']}', '{$invb['cordno']}', \r\n\t\t\t\t\t'{$invb['ordno']}', '{$invb['chrgvat']}', '{$invb['terms']}', '{$invb['traddisc']}', '{$invb['salespn']}', \r\n\t\t\t\t\t'{$invb['odate']}', '{$invb['delchrg']}', '{$invb['subtot']}', '{$invb['vat']}', '{$invb['total']}', '{$invb['balance']}', \r\n\t\t\t\t\t'{$invb['comm']}', 'y', 'y', '" . USER_DIV . "', '" . USER_NAME . "', '{$invb['rounding']}', '{$invb['delvat']}', \r\n\t\t\t\t\t'{$invb['vatnum']}', '{$invb['pcash']}', '{$invb['pcheque']}', '{$invb['pcc']}', '{$invb['pcredit']}', '" . date("m") . "', \r\n\t\t\t\t\t'{$invb['invid']}' \r\n\t\t\t\t)";
    }
    db_exec($sql) or errDie("Unable to store monthly invoice.");
    pglib_transaction("COMMIT");
    if (!isSerialized($nasset_id) && (!isset($_SESSION["ns"]) || !$_SESSION["ns"])) {
        $_SESSION["ns"] = 1;
    } else {
        $_SESSION["ns"] = 0;
    }
    if (isset($upBtn)) {
        if ($upBtn == "Return") {
            return returnHire();
        } elseif ($upBtn == "Invoice") {
            return invoiceHire();
        }
    }
    return false;
}
function confirm($_POST)
{
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($id, "num", 1, 100, "Invalid num.");
    $v->isOk($depamt, "float", 0, 14, "Invalid Depreciation Amount.");
    $v->isOk($depmonths, "num", 0, 3, "Invalid auto depreciation period.");
    $v->isOk("{$depmonths}{$depamt}", "float", 1, 14, "Enter one of Depreciation amount or period.");
    if (!empty($depamt) && $netval < $depamt) {
        $v->isOk("###", "float", 1, 1, "Error : Depreciation amount must not be more than the Net Value.");
    } else {
        if (!empty($depmonths) && $depperc <= 0) {
            $v->addError("###", "Depriaction percentage has to be more than 0 if depreciating by period.");
        }
    }
    $date = mkdate($date_year, $date_month, $date_day);
    $v->isOk($date, "date", 1, 1, "Invalid date.");
    # display errors, if any
    if ($v->isError()) {
        $confirmCust = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirmCust .= "<li class=err>" . $e["msg"];
        }
        return $confirmCust . "</li>" . view_data($_POST);
    }
    db_conn('cubit');
    $user = USER_NAME;
    $Sql = "SELECT * FROM assets WHERE (id='{$id}' AND div = '" . USER_DIV . "')";
    $Rslt = db_exec($Sql) or errDie("Unable to access database.");
    if (pg_numrows($Rslt) < 1) {
        return "Asset not Found";
    }
    $led = pg_fetch_array($Rslt);
    if (empty($depamt)) {
        $ml_perc = $depperc * ($depmonths % 12 / 12);
        $years = ($depmonths - $depmonths % 12) / 12;
        $baseamt = $led["amount"] - $led["accdep"];
        $depamt = 0;
        /* yearly depreciations */
        for ($i = 1; $i <= $years; ++$i) {
            $depamt += ($baseamt - $depamt) * ($depperc / 100);
        }
        /* monthly depreciation */
        $depamt += ($baseamt - $depamt) * ($ml_perc / 100);
    }
    vsprint($depamt);
    # Get group
    $sql = "SELECT * FROM assetgrp WHERE grpid = '{$led['grpid']}' AND div = '" . USER_DIV . "'";
    $grpRslt = db_exec($sql);
    $grp = pg_fetch_array($grpRslt);
    $led['amount'] = sprint($led['amount']);
    $netval = sprint($led['amount'] - $led['accdep']);
    $view_data = "\r\n\t\t\t\t<h3>Asset Depreciation</h3>\r\n\t\t\t\t<h4>Confirm</h4>\r\n\t\t\t\t<form action='" . SELF . "' method='POST'>\r\n\t\t\t\t\t<input type='hidden' name='key' value='write'>\r\n\t\t\t\t\t<input type='hidden' name='id' value='{$id}'>\r\n\t\t\t\t\t<input type='hidden' name='cosamt' value='{$led['amount']}'>\r\n\t\t\t\t\t<input type='hidden' name='depamt' value='{$depamt}'>\r\n\t\t\t\t\t<input type='hidden' name='depmonths' value='{$depmonths}' />\r\n\t\t\t\t\t<input type='hidden' name='depperc' value='{$depperc}' />\r\n\t\t\t\t\t<input type='hidden' name='date' value='{$date}'>\r\n\t\t\t\t\t<input type='hidden' name='date_day' value='{$date_day}'>\r\n\t\t\t\t\t<input type='hidden' name='date_month' value='{$date_month}'>\r\n\t\t\t\t\t<input type='hidden' name='date_year' value='{$date_year}'>\r\n\t\t\t\t<table " . TMPL_tblDflts . ">\r\n\t\t\t\t\t<tr valign='top'>\r\n\t\t\t\t\t\t<td>\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 colspan='2'>Asset Details</th>\r\n\t\t\t\t\t\t\t\t</tr>\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>Group</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$grp['grpname']}</td>\r\n\t\t\t\t\t\t\t\t</tr>\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>Serial Number</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$led['serial']}</td>\r\n\t\t\t\t\t\t\t\t</tr>\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>Location</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$led['locat']}</td>\r\n\t\t\t\t\t\t\t\t</tr>\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>Description</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$led['des']}</td>\r\n\t\t\t\t\t\t\t\t</tr>\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>Date Bought</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$led['bdate']}</td>\r\n\t\t\t\t\t\t\t\t</tr>\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>Cost Amount</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$led['amount']}</td>\r\n\t\t\t\t\t\t\t\t</tr>\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>Net Value</td>\r\n\t\t\t\t\t\t\t\t\t<td><input type='hidden' name='netval' value='{$netval}'>{$netval}</td>\r\n\t\t\t\t\t\t\t\t</tr><tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t\t\t<td>Depreciation Amount</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$depamt}</td>\r\n\t\t\t\t\t\t\t\t</tr>";
    if (!empty($depamt)) {
        $view_data .= "\t\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t\t\t\t\t\t\t<td>Depreciation Period</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$depmonths}</td>\r\n\t\t\t\t\t\t\t\t</tr>";
    }
    $view_data .= "\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>Date</td>\r\n\t\t\t\t\t\t\t\t\t<td>{$date}</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<td><input type='submit' name='back' value='&laquo; Correction'></td>\r\n\t\t\t\t\t\t\t\t\t<td valign='bottom' align='right'><input type='submit' value='Write &raquo;'></td>\r\n\t\t\t\t\t\t\t\t</tr>\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>\r\n\t\t\t\t\t<tr><td><br></td></tr>\r\n\t\t\t\t</table>\r\n\t\t\t\t</form>\r\n\t\t\t\t<p>\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>Quick Links</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><a href='asset-view.php'>View Assets</a></td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\r\n\t\t\t\t</table>";
    return $view_data;
}
function writeLoan($_POST)
{
    # get vars
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($empnum, "num", 1, 20, "Invalid employee number.");
    $v->isOk($loanamt, "float", 1, 10, "Invalid loan amount.");
    $v->isOk($loanint, "float", 1, 5, "Invalid loan interest.");
    $v->isOk($loanperiod, "num", 1, 3, "Invalid payback period.");
    $v->isOk($loaninstall, "float", 1, 10, "Invalid monthly installment.");
    $v->isOk($fringebenefit, "float", 1, 10, "Invalid fringe benefit amount.");
    $v->isOk($lday, "num", 1, 2, "Invalid day.");
    $v->isOk($lmonth, "num", 1, 2, "Invalid month.");
    $v->isOk($lyear, "num", 4, 4, "Invalid year.");
    $v->isOk($accid, "num", 1, 9, "Invalid bank account selected.");
    $v->isOk($account, "num", 1, 9, "Invalid contra account selected.");
    $v->isOk($loan_account, "num", 1, 9, "Invalid loan account selected.");
    $v->isOk($loan_type, "num", 1, 9, "Invalid loan type selected.");
    if (!checkdate($lmonth, $lday, $lyear)) {
        $v->addError("", "Invalid date.");
    }
    if ($account > 0 && isb($account) || isb($loan_account)) {
        $v->addError("", "Main accounts blocked. Please select sub accounts.");
    }
    # display errors, if any
    if ($v->isError()) {
        $confirmCust = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirmCust .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        return enterLoan($confirmCust);
    }
    # get employee details
    db_connect();
    $sql = "SELECT * FROM employees WHERE empnum='{$empnum}' AND div = '" . USER_DIV . "'";
    $empRslt = db_exec($sql) or errDie("Unable to select employees from database.");
    if (pg_numrows($empRslt) < 1) {
        return "Invalid employee ID.";
    }
    $myEmp = pg_fetch_array($empRslt);
    # check for previous loan
    $sql = "SELECT empnum FROM employees WHERE empnum='{$empnum}' AND div = '" . USER_DIV . "' AND gotloan='t'::bool";
    $chkRslt = db_exec($sql) or errDie("Unable to check existing loans for employee.");
    if (pg_numrows($chkRslt) > 0) {
        return "<li class='err'>Loan already exists for employee number: {$myEmp['enum']}.</li>";
    }
    if ($accid > 0) {
        $bankacc = getbankaccid($accid);
    }
    # Debit salaries control acc and credit Bank acc
    $date = date("Y-m-d");
    $ldate = mkdate($lyear, $lmonth, $lday);
    $refnum = getrefnum();
    if ($account > 0) {
        $bankacc = $account;
    }
    //	writetrans($loan_account, $bankacc, $date, $refnum, $loanamt, "Loan granted to employee $myEmp[fnames] $myEmp[sname].");
    if ($accid > 0) {
        # issue bank record
        //		banktrans($accid, "withdrawal", date("d-m-Y"), "$myEmp[fnames] $myEmp[sname]", "Loan granted to employee $myEmp[fnames] $myEmp[sname].", 0, $loanamt, $loan_account);
    }
    $totamount = sprint($loanperiod * $loaninstall);
    $loanint_amt = $totamount - $loanamt;
    # connect to db
    db_connect();
    $ldate = "{$lyear}-{$lmonth}-{$lday}";
    $insert_sql = "\n\t\tINSERT INTO loan_requests (\n\t\t\tempnum, loanamt, loaninstall, loanint, loanperiod, loandate, \n\t\t\tloan_type, div, loan_account, bankacc, date, totamount, \n\t\t\tloanint_amt, fringebenefit, ldate, account, accid\n\t\t) VALUES (\n\t\t\t'{$empnum}', '{$loanamt}', '{$loaninstall}', '{$loanint}', '{$loanperiod}', '{$ldate}', \n\t\t\t'{$loan_type}', '" . USER_DIV . "', '{$loan_account}', '{$bankacc}', '{$date}', '{$totamount}', \n\t\t\t'{$loanint_amt}', '{$fringebenefit}', '{$ldate}', '{$account}', '{$accid}'\n\t\t)";
    $run_insert = db_exec($insert_sql) or errDie("Unable to add loan application request.");
    // 	pglib_transaction("BEGIN");
    //
    // 	$sql = "INSERT INTO emp_loanarchive (empnum, loanamt, loaninstall, loanint, loanperiod,loandate, loan_type, div)
    // 			VALUES('$empnum', '$totamount', '$loaninstall', '$loanint', '$loanperiod', CURRENT_DATE, '$loan_type', '".USER_DIV."')";
    // 	$rslt = db_exec($sql) or errDie("Unable to pre archive loan.");
    //
    // 	$loanid = pglib_lastid('emp_loanarchive', 'id');
    //
    // 	# write to db
    // 	$sql = "UPDATE employees
    // 			SET loanamt='$totamount', loanint='$loanint', loanint_amt='$loanint_amt',
    // 				loanint_unpaid='$loanint_amt', loanperiod='$loanperiod', loaninstall='$loaninstall',
    // 				gotloan='t'::bool, loanpayslip='$loanamt', loanfringe='$fringebenefit', loandate='$ldate',
    // 				expacc_loan='$loan_account', loanamt_tot='$totamount', loanid='$loanid'
    // 			WHERE empnum='$empnum' AND div = '".USER_DIV."'";
    // 	$loanRslt = db_exec ($sql) or errDie ("Unable to add loan to system.", SELF);
    //
    // 	if (pg_cmdtuples ($loanRslt) < 1) {
    // 		return "Unable to add loan to system.";
    // 	}
    //
    // 	pglib_transaction("COMMIT");
    $writeLoan = "\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Loan granted and added to system</th>\n\t\t\t</tr>\n\t\t\t<tr class='datacell'>\n\t\t\t\t<td>New loan application has been successfully added to Cubit.\n\t\t\t\t<a href='../groupware/req_gen.php'>Send</a> an instant message.</td>\n\t\t\t</tr>\n\t\t</table><br>" . mkQuickLinks(ql("loan_apply.php", "Add Loan Application"), ql("loan_apply_view.php", "View Loan Applications"), ql("../admin-employee-add.php", "Add Employee"), ql("../admin-employee-view.php", "View Employees"));
    return $writeLoan;
}
Example #27
0
 function announce()
 {
     global $set, $apx, $db, $html;
     //Aktionen
     if ($_REQUEST['do'] == 'add') {
         return $this->announce_add();
     }
     if ($_REQUEST['do'] == 'edit') {
         return $this->announce_edit();
     }
     if ($_REQUEST['do'] == 'del') {
         return $this->announce_del();
     }
     //Voreinstellung
     if (!$_REQUEST['what']) {
         $_REQUEST['what'] = 'posts';
     }
     echo '<p class="slink">&raquo; <a href="action.php?action=forum.announce&amp;do=add&amp;criteria=' . $_REQUEST['what'] . '">' . $apx->lang->get('ADDANNOUNCE') . '</a></p>';
     $col[] = array('', 0, '');
     $col[] = array('COL_TITLE', 50, 'class="title"');
     $col[] = array('COL_USER', 30, 'align="center"');
     $col[] = array('COL_PUBDATE', 20, 'align="center"');
     $orderdef[0] = 'addtime';
     $orderdef['title'] = array('a.title', 'ASC', 'COL_TITLE');
     $orderdef['username'] = array('b.username', 'ASC', 'COL_USER');
     $orderdef['addtime'] = array('a.starttime', 'DESC', 'SORT_ADDTIME');
     $orderdef['publication'] = array('a.starttime', 'DESC', 'COL_PUBDATE');
     list($count) = $db->first("SELECT count(id) FROM " . PRE . "_forum_announcements WHERE userid!=''");
     pages('action.php?action=forum.announce&amp;sortby=' . $_REQUEST['sortby'], $count);
     $data = $db->fetch("SELECT a.id,a.title,a.userid,a.starttime,a.endtime,b.username FROM " . PRE . "_forum_announcements AS a LEFT JOIN " . PRE . "_user AS b USING(userid) WHERE a.userid!='' " . getorder($orderdef) . getlimit());
     if (count($data)) {
         foreach ($data as $res) {
             ++$i;
             if (!$res['starttime']) {
                 $tabledata[$i]['COL1'] = '<img src="design/reddot.gif" alt="' . $apx->lang->get('CORE_INACTIVE') . '" title="' . $apx->lang->get('CORE_INACTIVE') . '" />';
             } elseif ($res['endtime'] < time()) {
                 $tabledata[$i]['COL1'] = '<img src="design/greendotcross.gif" alt="' . $apx->lang->get('CORE_INACTIVE') . '" title="' . $apx->lang->get('CORE_INACTIVE') . '" />';
             } elseif ($res['starttime'] > time()) {
                 $tabledata[$i]['COL1'] = '<img src="design/greendotwait.gif" alt="' . $apx->lang->get('CORE_ACTIVE') . '" title="' . $apx->lang->get('CORE_ACTIVE') . '" />';
             } else {
                 $tabledata[$i]['COL1'] = '<img src="design/greendot.gif" alt="' . $apx->lang->get('CORE_ACTIVE') . '" title="' . $apx->lang->get('CORE_ACTIVE') . '" />';
             }
             $link = mklink($set['forum']['directory'] . '/announcement.php?id=' . $res['id'], $set['forum']['directory'] . '/announcement,' . $res['id'] . urlformat($res['title']) . '.html');
             $tabledata[$i]['COL2'] = '<a href="' . $link . '" target="_blank">' . replace($res['title']) . '</a>';
             $tabledata[$i]['COL3'] = $res['username'];
             if ($res['starttime']) {
                 $tabledata[$i]['COL4'] = mkdate($res['starttime'], '<br />');
             } else {
                 $tabledata[$i]['COL4'] = '&nbsp;';
             }
             //Optionen
             $tabledata[$i]['OPTIONS'] .= optionHTML('edit.gif', 'forum.announce', 'do=edit&id=' . $res['id'], $apx->lang->get('CORE_EDIT'));
             $tabledata[$i]['OPTIONS'] .= optionHTMLOverlay('del.gif', 'forum.announce', 'do=del&id=' . $res['id'], $apx->lang->get('CORE_DEL'));
         }
     }
     $apx->tmpl->assign('TABLE', $tabledata);
     $html->table($col);
     orderstr($orderdef, 'action.php?action=forum.announce');
     save_index($_SERVER['REQUEST_URI']);
 }
function writeLoan($_POST)
{
    # get vars
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($empnum, "num", 1, 20, "Invalid employee number.");
    $v->isOk($loanid, "num", 1, 20, "Invalid loan ID.");
    $v->isOk($loanamt, "float", 1, 10, "Invalid loan amount.");
    $v->isOk($loanint, "float", 1, 5, "Invalid loan interest.");
    $v->isOk($loanperiod, "num", 1, 3, "Invalid payback period.");
    $v->isOk($loaninstall, "float", 1, 10, "Invalid monthly installment.");
    $v->isOk($fringebenefit, "float", 1, 10, "Invalid fringe benefit amount.");
    $v->isOk($accid, "num", 1, 9, "Invalid bank account selected.");
    $v->isOk($account, "num", 1, 9, "Invalid contra account selected.");
    $v->isOk($loan_account, "num", 1, 9, "Invalid loan account selected.");
    $v->isOk($loan_type, "num", 1, 9, "Invalid loan type selected.");
    $ldate = mkdate($lyear, $lmonth, $lday);
    $v->isOk($ldate, "date", 1, 1, "Invalid loan date.");
    $archdate = mkdate($arch_year, $arch_month, $arch_day);
    $v->isOk($archdate, "date", 1, 1, "Invalid approval/denial date.");
    if (!checkdate($lmonth, $lday, $lyear)) {
        $v->addError("", "Invalid date.");
    }
    if ($account > 0 && isb($account) || isb($loan_account)) {
        $v->addError("", "Main accounts blocked. Please select sub accounts.");
    }
    # display errors, if any
    if ($v->isError()) {
        $confirmCust = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirmCust .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        return enterLoan($confirmCust);
    }
    # CHECK IF THIS DATE IS IN THE BLOCKED RANGE
    $blocked_date_from = getCSetting("BLOCKED_FROM");
    $blocked_date_to = getCSetting("BLOCKED_TO");
    if (strtotime($ldate) >= strtotime($blocked_date_from) and strtotime($ldate) <= strtotime($blocked_date_to) and !user_is_admin(USER_ID)) {
        return "<li class='err'>Period Range Is Blocked. Only an administrator can process entries within this period.</li>";
    }
    # CHECK IF THIS DATE IS IN THE BLOCKED RANGE
    $blocked_date_from = getCSetting("BLOCKED_FROM");
    $blocked_date_to = getCSetting("BLOCKED_TO");
    if (strtotime($archdate) >= strtotime($blocked_date_from) and strtotime($archdate) <= strtotime($blocked_date_to) and !user_is_admin(USER_ID)) {
        return "<li class='err'>Period Range Is Blocked. Only an administrator can process entries within this period.</li>";
    }
    # get employee details
    db_connect();
    $sql = "SELECT * FROM employees WHERE empnum='{$empnum}' AND div = '" . USER_DIV . "'";
    $empRslt = db_exec($sql) or errDie("Unable to select employees from database.");
    if (pg_numrows($empRslt) < 1) {
        return "Invalid employee ID.";
    }
    $myEmp = pg_fetch_array($empRslt);
    if (!isset($deny)) {
        # check for previous loan
        $sql = "SELECT empnum FROM employees WHERE empnum='{$empnum}' AND div = '" . USER_DIV . "' AND gotloan='t'::bool";
        $chkRslt = db_exec($sql) or errDie("Unable to check existing loans for employee.");
        if (pg_numrows($chkRslt) > 0) {
            return "<li class='err'>Loan already exists for employee number: {$empnum}.</li>";
        }
    }
    $date = date("Y-m-d");
    pglib_transaction("BEGIN");
    $totamount = sprint($loanperiod * $loaninstall);
    $loanint_amt = $totamount - $loanamt;
    $sql = "\n\t\tINSERT INTO emp_loanarchive (\n\t\t\tempnum, loanamt, loaninstall, loanint, loanperiod, loandate, archdate, loan_type, \n\t\t\tdiv, status\n\t\t) VALUES (\n\t\t\t'{$empnum}', '{$totamount}', '{$loaninstall}', '{$loanint}', '{$loanperiod}', '{$ldate}', '{$archdate}', '{$loan_type}', \n\t\t\t'" . USER_DIV . "', '" . (isset($deny) ? "D" : "A") . "'\n\t\t)";
    $rslt = db_exec($sql) or errDie("Unable to pre archive loan.");
    $loanaid = pglib_lastid('emp_loanarchive', 'id');
    $rem_sql = "DELETE FROM loan_requests WHERE id = '{$loanid}'";
    $run_rem = db_exec($rem_sql) or errDie("Unable to get loan requests information.");
    if (!isset($deny)) {
        $refnum = getrefnum();
        if ($accid > 0) {
            $bankacc = getbankaccid($accid);
        }
        if ($account > 0) {
            $bankacc = $account;
        }
        writetrans($loan_account, $bankacc, $archdate, $refnum, $loanamt, "Loan granted to employee {$myEmp['fnames']} {$myEmp['sname']}.");
        if ($accid > 0) {
            banktrans($accid, "withdrawal", $archdate, "{$myEmp['fnames']} {$myEmp['sname']}", "Loan granted to employee {$myEmp['fnames']} {$myEmp['sname']}.", 0, $loanamt, $loan_account);
        }
        # write to db
        $sql = "\n\t\t\tUPDATE cubit.employees \n\t\t\tSET loanamt = '{$totamount}', loanint = '{$loanint}', loanint_amt = '{$loanint_amt}', loanint_unpaid = '{$loanint_amt}', \n\t\t\t\tloanperiod = '{$loanperiod}', loaninstall = '{$loaninstall}', gotloan = 't'::bool, loanpayslip = '{$loanamt}', \n\t\t\t\tloanfringe = '{$fringebenefit}', loandate = '{$archdate}', expacc_loan = '{$loan_account}', \n\t\t\t\tloanamt_tot = '{$totamount}', loanid = '{$loanaid}' \n\t\t\tWHERE empnum = '{$empnum}' AND div = '" . USER_DIV . "'";
        $loanRslt = db_exec($sql) or errDie("Unable to add loan to system.", SELF);
        if (pg_cmdtuples($loanRslt) < 1) {
            return "Unable to add loan to system.";
        }
    }
    pglib_transaction("COMMIT");
    $OUT = "<table " . TMPL_tblDflts . ">";
    if (isset($deny)) {
        $OUT .= "\n\t\t\t<tr>\n\t\t\t\t<th>Loan Denied And Request Archived.</th>\n\t\t\t</tr>";
    } else {
        $OUT .= "\n\t\t\t<tr>\n\t\t\t\t<th>Loan Granted And Added To System</th>\n\t\t\t</tr>";
    }
    $OUT .= "\n\t\t<tr class='datacell'>\n\t\t\t<td>Loan information successfully updated.</td>\n\t\t</tr>\n\t\t" . TBL_BR;
    if (!isset($deny)) {
        $OUT .= "\n\t\t\t<tr>\n\t\t\t\t<td><input type='button' onclick=\"document.location='../reporting/loan_approval.php?id={$loanaid}'\" value='Generate Approval Report'></td>\n\t\t\t</tr>";
    }
    $OUT .= "\n\t\t</table><br>" . mkQuickLinks(ql("loan_apply.php", "Add Loan Application"), ql("loan_apply_view.php", "View Loan Applications"), ql("../admin-employee-add.php", "Add Employee"), ql("../admin-employee-view.php", "View Employees"));
    return $OUT;
}
Example #29
0
 unset($j, $incf[boardbit]);
 $boardsquery = $db->query_str("SELECT * FROM {$tab['forum_board']} WHERE is_cat='0' AND parent_boardid='{$cat['id']}' AND visible='1' ORDER BY sort");
 while ($board = $db->fetch_array($boardsquery)) {
     //if(!($j%3) && $j) {eval("\$incf[boardbit] .= \"".gettemplate("forum.index.board.bit.tr")."\";");}
     if ($board[last_postid]) {
         $lastpost = getpost($board[last_postid]);
     } else {
         unset($lastpost[settime]);
     }
     if ($board[board_password] && !checkboardpassword($boardpassword_c["{$board['id']}"], $board)) {
         eval("\$lastposting = \"" . gettemplate("forum.index.board.bit.lastposting.pwd.noaccess") . "\";");
     } else {
         if ($board[last_userid]) {
             $lastuser = getuser($board[last_userid]);
             $last_user_name = mkuser("user_name", $NULL, $lastuser);
             $last_time = mkdate($lastpost[settime]);
             eval("\$lastposting = \"" . gettemplate("forum.index.board.bit.lastposting") . "\";");
         } else {
             eval("\$lastposting = \"" . gettemplate("forum.index.board.bit.nolastposting") . "\";");
         }
     }
     if ($login[id] && $lastpost[settime] >= $login[last_forum_read] && $lastpost[aut_id] != $login[id]) {
         $css_td = "board_td_unread";
         $css_td_font = "board_td_unread_font";
         $css_th = "board_th_unread";
         $css_th_font = "board_th_unread_font";
     } else {
         $css_td = "board_td";
         $css_td_font = "board_td_font";
         $css_th = "board_th";
         $css_th_font = "board_th_font";
Example #30
0
        } elseif ($right[boardid]) {
            $board = getboard($right[boardid]);
            $board = $board[board_name];
        } else {
            $board = "-----";
        }
        eval("\$moderators .= \"" . gettemplate("user.admin.rights.listmoderators.bit") . "\";");
    }
    eval("\$inc[action] = \"" . gettemplate("user.admin.rights") . "\";");
}
#######################################
if ($adminaction == "showuser" || $fail_useredit) {
    $fail = $fail_useredit;
    $form = getuser($userid);
    $form[user_gender] - 2 ? $male = " selected" : ($female = " selected");
    $birthday = mkdate($form[user_birth], "d-m-Y");
    eval("\$inc[action] = \"" . gettemplate("user.admin.edituser") . "\";");
}
#######################################
if ($adminaction == "showusers") {
    if (strtolower($sort) != "desc" && strtolower($sort) != "asc") {
        $sort = "ASC";
    }
    if (strtolower($order) != "user_name" && strtolower($order) != "id") {
        $order = "id";
    }
    if (!$start || !is_numeric($start)) {
        $start = 0;
    }
    if (!$show || !is_numeric($show)) {
        $show = 20;