コード例 #1
0
function process($_POST, $err = "")
{
    global $PRDMON;
    extract($_POST);
    # validate input
    require_lib("validate");
    $v = new validate();
    $proc_date = mkdate($proc_year, $proc_month, $proc_day);
    $v->isOk($empnum, "num", 1, 20, "Invalid employee number.");
    $v->isOk($MON, "num", 1, 2, "Invalid month.");
    $v->isOk($proc_date, "date", 1, 1, "Invalid date selected.");
    $salyr = getYearOfEmpMon($MON);
    $curyr = getActiveFinYear();
    if ($salyr > $curyr || $salyr == $curyr && $MON > $PRDMON[12]) {
        $v->addError("", "Cannot do transaction in future financial year. You need\n\t\t\tto close your year first before you can continue.");
    }
    # display errors, if any
    if ($v->isError()) {
        return slctEmployee($v->genErrors());
        return $confirmCust;
    }
    # CHECK IF THIS DATE IS IN THE BLOCKED RANGE
    $blocked_date_from = getCSetting("BLOCKED_FROM");
    $blocked_date_to = getCSetting("BLOCKED_TO");
    if (strtotime($proc_date) >= strtotime($blocked_date_from) and strtotime($proc_date) <= 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>";
    }
    // first check if all the selected employees with EFT pay types have banking information
    // and their id numbers are valid
    $emp_err = array();
    $emp_nam = array();
    /* previously selected to remove this employee from process */
    if (isset($rememp[$empnum])) {
        unset($emps[$empnum]);
        continue;
    }
    db_connect();
    $sql = "\n\t\t\tSELECT fnames, sname, paytype, bankname, bankaccno, idnum, flag, hiredate, payprd \n\t\t\tFROM employees \n\t\t\tWHERE div='" . USER_DIV . "' AND empnum='{$empnum}'";
    $rslt = db_exec($sql) or errDie("error checking employee payment types.");
    $e_info = pg_fetch_array($rslt);
    /* if the employee's pay period doesn't match the selected button, don't
    			include employee in checklist */
    if (isset($d) && $e_info["payprd"] != "d") {
        continue;
    } else {
        if (isset($w) && $e_info["payprd"] != "w") {
            continue;
        } else {
            if (isset($b) && $e_info["payprd"] != "f") {
                continue;
            } else {
                if (isset($m) && $e_info["payprd"] != "m") {
                    continue;
                }
            }
        }
    }
    $empnum += 0;
    $emp_err[$empnum] = 0;
    $emp_nam[$empnum] = "{$e_info['fnames']} {$e_info['sname']}";
    if ($e_info["paytype"] == "EFT" && (empty($e_info["bankname"]) || empty($e_info["bankaccno"]))) {
        $emp_err[$empnum] |= 0x1;
    }
    if (!empty($e_info["idnum"])) {
        $bd_year = substr($e_info["idnum"], 0, 2);
        $bd_month = substr($e_info["idnum"], 2, 2);
        $bd_day = substr($e_info["idnum"], 4, 2);
        if (!checkdate($bd_month, $bd_day, $bd_year)) {
            $emp_err[$empnum] |= 0x2;
        }
    }
    if ($e_info["flag"] == "2.5EMP") {
        $emp_err[$empnum] |= 0x4;
        $special_error = 0x1;
    }
    if ($e_info["flag"] == "272PREVEMP") {
        $emp_err[$empnum] |= 0x4;
        $special_error = 0x2;
    }
    /* check hiredate after process date */
    explodeDate($e_info["hiredate"], $hd_year, $hd_month, $hd_day);
    $MONempyear = getYearOfEmpMon($MON);
    if ($hd_year > $MONempyear || $hd_year == $MONempyear && $hd_month > $MON) {
        $emp_err[$empnum] |= 0x8;
    }
    // list the employee information problems
    if (array_sum($emp_err) > 0) {
        $out = "<h3>Process Salaries</h3>\n\t\t\t<form method='POST' action='" . SELF . "'>";
        foreach ($_POST as $key => $value) {
            if (is_array($value)) {
                foreach ($value as $akey => $avalue) {
                    $out .= "<input type='hidden' name='{$key}" . "[{$akey}]' value='{$avalue}'>";
                }
            } else {
                $out .= "<input type='hidden' name='{$key}' value='{$value}'>";
            }
        }
        if (isset($special_error)) {
            switch ($special_error) {
                case 0x1:
                    $out .= "\n\t\t\t\t\t<li class='err'><strong>NOTICE:</strong> Due to changes in employee functionality from Cubit 2.5 to Cubit 2.6 <br>\n\t\t\t\t\t\tyou need to edit your employees' salary/deduction/allowance information</li>\n\t\t\t\t\t\t<br />";
                    break;
                case 0x2:
                    $out .= "\n\t\t\t\t\t<li class='err'><strong>NOTICE:</strong> Due to the changes from Cubit 2.71 to Cubit 2.72 you should first update your employee's\n\t\t\t\t\t\tprevious employment information in the employee edit form.</li>\n\t\t\t\t\t\t<br />";
                    break;
            }
        }
        $out .= "\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='3' class='err'>There are problems with the employee.<br />\n\t\t\t\t\t\tPlease edit the information first.<br /><br />\n\t\t\t\t\t\tClick the 'Done' button when ready to proceed.</td>\n\t\t\t\t</tr>";
        $out .= "\n\t\t\t<tr>\n\t\t\t\t<th>Name</th>\n\t\t\t\t<th>Message</th>\n\t\t\t</tr>";
        $i = 0;
        foreach ($emp_err as $e_empnum => $err_val) {
            $out .= "\n\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t<h1></h1>\n\t\t\t\t\t<th>{$emp_nam[$e_empnum]}</td>";
            if ($err_val & 0x4) {
                $specerr_msg = "(See above notice for this employee)";
            } else {
                $specerr_msg = "";
            }
            if ($err_val & 0x1 && $err_val & 0x2) {
                $out .= "<td class='err'>Banking info and ID number {$specerr_msg}</td>";
            } else {
                if ($err_val & 0x1) {
                    $out .= "<td class='err'>Banking info {$specerr_msg}</td>";
                } else {
                    if ($err_val & 0x2) {
                        $out .= "<td class='err'>ID number {$specerr_msg}</td>";
                    } else {
                        if ($err_val & 0x8) {
                            $out .= "<td class='err'>Employee was not employed in the period requested {$specerr_msg}</td>";
                        } else {
                            $out .= "<td>Employee Info Correct {$specerr_msg}</td>";
                        }
                    }
                }
            }
            if ($err_val && !($err_val == 0x8)) {
                $out .= "<td class='err'><a target='_blank' href='../admin-employee-edit.php?empnum={$e_empnum}'>Edit Employee</a></td>";
            }
            $out .= "\n\t\t\t</tr>";
        }
        $out .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='3' align='right'><input type='submit' value='Done' /></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</form>";
        return $out;
    }
    # Get employee details
    db_conn('cubit');
    $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 ($myEmp["flag"] == "2.5EMP") {
        $OUTPUT = "\n\t\t\t<h3>Process Employee Salary</h3>\n\t\t\t<li class='err'>\n\t\t\t\tDue to the changes from Cubit 2.5 to Cubit 2.6.1 you should first update your employee's\n\t\t\t\tsalary/deduction/allowance information in the employee edit form.\n\t\t\t\tClick <a href='../admin-employee-edit.php?empnum={$empnum}'>here</a> to do so.\n\t\t\t</li>";
        return $OUTPUT;
    }
    if (!empty($idnum)) {
        $bd_year = substr($myEmp["idnum"], 0, 2);
        $bd_month = substr($myEmp["idnum"], 2, 2);
        $bd_day = substr($myEmp["idnum"], 4, 2);
        if (!checkdate($bd_month, $bd_day, $bd_year)) {
            $OUTPUT = "\n\t\t\t<h3>Process Employee Salary</h3>\n\t\t\t<li class='err'>\n\t\t\t\tSelected employee does not have a valid id number and therefore his age cannot be\n\t\t\t\tcalculated.<br>\n\t\t\t\tPlease update this information in the employee <a href='../admin-employee-edit.php?empnum={$empnum}'>edit</a> form.\n\t\t\t</li>";
            return $OUTPUT;
        }
    }
    /* check for flag notices */
    if ($myEmp["flag"] == "272PREVEMP") {
        $OUTPUT = "\n\t\t<h3>Process Employee Salary</h3>\n\t\t<li class='err'>\n\t\t\tDue to the changes from Cubit 2.71 to Cubit 2.72 you should first update your employee's\n\t\t\tprevious employment information in the employee edit form.\n\t\t\tClick <a href='../admin-employee-edit.php?empnum={$empnum}'>here</a> to do so.\n\t\t</li>";
    }
    /* check if hiredate after process date */
    explodeDate($myEmp["hiredate"], $hd_year, $hd_month, $hd_day);
    if ($hd_year > getYearOfEmpMon($MON) || $hd_year == getYearOfEmpMon($MON) && $hd_month > $MON) {
        return slctEmployee("<li class='err'>Employee was not employed in the period\n\t\t\trequested.</li>");
    }
    if ($myEmp["paytype"] == "EFT" && (empty($myEmp["bankname"]) || empty($myEmp["bankaccno"]))) {
        return "Employee banking information not entered.<br>\n\t\t\tClick <a href='../admin-employee-edit.php?empnum={$empnum}'>here</a> employee banking information.";
    }
    $grossal = $myEmp["basic_sal"] + $myEmp["commission"] + $myEmp["bonus"];
    $yy = date("Y");
    $mm = $MON;
    $mm += 0;
    if ($myEmp['payprd'] == "m") {
        $Sl = "SELECT * FROM salpaid WHERE empnum='{$empnum}' AND month='{$mm}' AND cyear='" . EMP_YEAR . "'";
        $Ri = db_exec($Sl);
        $paid = pg_num_rows($Ri);
        $Sl = "SELECT * FROM salr WHERE empnum='{$empnum}' AND month='{$mm}' AND cyear='" . EMP_YEAR . "'";
        $Ri = db_exec($Sl);
        $upaid = pg_num_rows($Ri);
        $upaid += 0;
        $paid -= $upaid;
    }
    if (isset($paid) && $paid > 0) {
        return slctEmployee("<li class='err'>You have already processed a salary for that period.</li>");
    }
    /* calculate basic salary divisors and multipliers
     * used for calculating deductions/allowances/etc. when the
     * salary type and payment period differs in length
     */
    switch ($myEmp["saltyp"]) {
        case "h":
            $divisor = 1;
            switch ($myEmp["payprd"]) {
                case "d":
                    $multiplier = $myEmp["hpweek"] / 5;
                    break;
                case "w":
                    $multiplier = $myEmp["hpweek"];
                    break;
                case "f":
                    $multiplier = $myEmp["hpweek"] * 2;
                    break;
                case "m":
                    $multiplier = $myEmp["hpweek"] * 52 / 12;
                    break;
            }
            break;
        case "m":
            $divisor = 1;
            switch ($myEmp["payprd"]) {
                case "d":
                    $multiplier = 12 / (5 * 52);
                    break;
                case "w":
                    $multiplier = 12 / 52;
                    break;
                case "f":
                    $multiplier = 12 / 26;
                    break;
                case "m":
                    $multiplier = 1;
                    break;
            }
            break;
        case "w":
            $divisor = 52 / 12;
            switch ($myEmp["payprd"]) {
                case "d":
                    $multiplier = 1 / 5;
                    break;
                case "w":
                    $multiplier = 1;
                    break;
                case "f":
                    $multiplier = 2;
                    break;
                case "m":
                    $multiplier = 52 / 12;
                    break;
            }
            break;
        case "f":
            $divisor = 26 / 12;
            switch ($myEmp["payprd"]) {
                case "d":
                    $multiplier = 1 / 10;
                    break;
                case "w":
                    $multiplier = 1 / 2;
                    break;
                case "f":
                    $multiplier = 1;
                    break;
                case "m":
                    $multiplier = 26 / 12;
                    break;
            }
            break;
    }
    # fringe benefits
    $fringes = "";
    $i = 0;
    $sql = "SELECT * FROM fringebens WHERE div = '" . USER_DIV . "' ORDER BY fringeben";
    $rslt = db_exec($sql) or errDie("Unable to select allowances from database.");
    if (pg_num_rows($rslt) < 1) {
        $fringes = "<tr><td class='" . bg_class() . "' colspan='2' align='center'>None found in database.</td></tr>\n";
    } else {
        while ($myFringe = pg_fetch_array($rslt)) {
            # check if employee has allowance
            $sql = "SELECT * FROM empfringe WHERE fringeid='{$myFringe['id']}' AND empnum='{$myEmp['empnum']}' AND div = '" . USER_DIV . "'";
            $empRslt = db_exec($sql) or errDie("Unable to retrieve fringe benefit info from database.");
            if (pg_numrows($empRslt) > 0) {
                $empFringe = pg_fetch_array($empRslt);
                if (substr($empFringe["type"], 0, 4) == "Perc") {
                    $empFringe["amount"] = sprint($myEmp["basic_sal"] * ($empFringe["amount"] / 100) / $divisor);
                } else {
                    $empFringe['amount'] = sprint($empFringe['amount'] / $divisor);
                }
                $grossal += $empFringe["amount"];
                $tmp_fringeaccs = $empFringe["accid"];
                $tmp_fringebens = $empFringe["amount"];
            } else {
                $tmp_fringeaccs = "0";
                $tmp_fringebens = "0.00";
            }
            $fringes .= "\n\t\t\t<input type='hidden' name='fringeid[]' value='{$myFringe['id']}'>\n\t\t\t<input type='hidden' name='fringename[]' value='{$myFringe['fringeben']}'>\n\t\t\t<input type='hidden' name='fringeaccs[]' value='{$tmp_fringeaccs}'>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$myFringe['fringeben']}</td>\n\t\t\t\t<td align='center'>" . CUR . "<input type='text' size='10' name='fringebens[]' value='{$tmp_fringebens}'></td>\n\t\t\t</tr>";
            $i++;
        }
    }
    # get allowances
    $allowances = "";
    $i = 0;
    $sql = "SELECT * FROM allowances WHERE div = '" . USER_DIV . "' ORDER BY allowance";
    $allowRslt = db_exec($sql) or errDie("Unable to select allowances from database.");
    if (pg_numrows($allowRslt) < 1) {
        $allowances = "<tr><td class='" . bg_class() . "' colspan='2' align='center'>None found in database.</td></tr>\n";
    } else {
        while ($myAllow = pg_fetch_array($allowRslt)) {
            # check if employee has allowance
            $sql = "SELECT * FROM empallow WHERE allowid='{$myAllow['id']}' AND empnum='{$myEmp['empnum']}' AND div = '" . USER_DIV . "'";
            $empAllowRslt = db_exec($sql) or errDie("Unable to select allowance info from database.");
            if (pg_numrows($empAllowRslt) > 0) {
                $myEmpAllow = pg_fetch_array($empAllowRslt);
                if (substr($myEmpAllow["type"], 0, 4) == "Perc") {
                    $myEmpAllow["amount"] = sprint($myEmp["basic_sal"] * ($myEmpAllow["amount"] / 100) / $divisor);
                } else {
                    $myEmpAllow['amount'] = sprint($myEmpAllow['amount'] / $divisor);
                }
                $grossal += $myEmpAllow["amount"];
                $tmp_allowaccs = $myEmpAllow["accid"];
                $tmp_allowances = $myEmpAllow["amount"];
            } else {
                $tmp_allowaccs = $myAllow["accid"];
                $tmp_allowances = "0.00";
            }
            $allowances .= "\n\t\t\t<input type='hidden' size='10' name='allowid[]' value='{$myAllow['id']}'>\n\t\t\t<input type='hidden' size='30' name='allowname[]' value='{$myAllow['allowance']}'>\n\t\t\t<input type='hidden' size='10' name='allowtax[]' value='{$myAllow['add']}'>\n\t\t\t<input type='hidden' name='allowaccs[]' value='{$tmp_allowaccs}'>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$myAllow['allowance']}</td>\n\t\t\t\t<td align='center'>" . CUR . " <input type='text' size='10' name='allowances[]' value='{$tmp_allowances}'></td>\n\t\t\t</tr>";
            $i++;
        }
    }
    $subsistence = "";
    $subslst = new dbSelect("subsistence", "cubit", array("where" => "div='" . USER_DIV . "'", "order" => "name"));
    $subslst->run();
    $subs_int = false;
    if ($subslst->num_rows() > 0) {
        $i = 0;
        $subsistence .= "\n\t\t<tr><td colspan='10'>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<th>Name</th>\n\t\t\t<th>Amount</th>\n\t\t\t<th>Days</th>\n\t\t\t<th></th>\n\t\t</tr>";
        $empsubs = new dbSelect("emp_subsistence", "cubit");
        while ($subs = $subslst->fetch_array()) {
            $sid = $subs["id"];
            $empsubs->setOpt(array("where" => wgrp(m("empnum", $empnum), m("subid", $sid))));
            $empsubs->run();
            if ($empsubs->num_rows() <= 0) {
                $si["amount"] = "0.00";
                $si["days"] = "0";
                $si["accid"] = $subs["accid"];
            } else {
                $si = $empsubs->fetch_array();
            }
            if ($subs["in_republic"] != "yes") {
                $subs_int = true;
            }
            $subsistence .= "\n\t\t\t<input type='hidden' name='subsname[{$sid}]' value='{$subs['name']}'>\n\t\t\t<input type='hidden' name='subsacc[{$sid}]' value='{$si['accid']}'>\n\t\t\t<input type='hidden' name='subsrep[{$sid}]' value='{$subs['in_republic']}'>\n\t\t\t<input type='hidden' name='subsmeal[{$sid}]' value='{$subs['meals']}'>\n\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t<td>{$subs['name']}</td>\n\t\t\t\t<td>" . CUR . " <input type='text' name='subsamt[{$sid}]' value='{$si['amount']}'></td>\n\t\t\t\t<td><input type='text' name='subsdays[{$sid}]' value='{$si['days']}'></td>\n\t\t\t</tr>";
        }
        if ($subs_int) {
            $subsistence .= "\n\t\t\t\t<input type='hidden' name='subs_exch' value='1'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='3'><li class='err'>Please calculate the rand amount prior to completing the amount above.</li></td>\n\t\t\t\t</tr>";
            // 			<tr bgcolor='".bgcolor($i)."'>
            // 				<td colspan='2'>Exchange (ZAR-USD):</td>
            // 				<td><input type='text' name='subs_exch' value='".xrate_get("USD")."'></td>
            // 			</tr>";
        }
        $subsistence .= "\n\t\t\t</table>\n\t\t\t</td></tr>";
    }
    # Deductions
    $deductions = "";
    $i = 0;
    $sql = "SELECT * FROM salded WHERE div = '" . USER_DIV . "' ORDER BY deduction";
    $deductRslt = db_exec($sql) or errDie("Unable to select deductions from database.");
    if (pg_numrows($deductRslt) < 1) {
        $deductions = "<tr><td class='" . bg_class() . "' colspan='2' align='center'>None found in database.</td></tr>\n";
    } else {
        while ($myDeduct = pg_fetch_array($deductRslt)) {
            # check if employee has deduction
            $sql = "SELECT * FROM empdeduct WHERE dedid='{$myDeduct['id']}' AND empnum='{$myEmp['empnum']}' AND div = '" . USER_DIV . "'";
            $empDeductRslt = db_exec($sql) or errDie("Unable to select Deduction info from database.");
            if (pg_numrows($empDeductRslt) > 0) {
                $myEmpDeduct = pg_fetch_array($empDeductRslt);
                if ($myEmpDeduct["grosdeduct"] == "y") {
                    $deductions_msg = "(Deducted from Gross Salary)";
                    $sal_calcfrom = $grossal;
                } else {
                    $deductions_msg = "";
                    $sal_calcfrom = $myEmp['basic_sal'];
                }
                if ($myEmpDeduct['type'] == "Amount") {
                    $myEmpDeduct['amount'] = sprint($myEmpDeduct['amount'] / $divisor);
                } else {
                    $myEmpDeduct['amount'] = sprint($sal_calcfrom * $myEmpDeduct['amount'] / 100 / $divisor);
                }
                // calculate employer contribution to deduction
                if ($myEmpDeduct["employer_type"] == "Amount") {
                    $myEmpDeduct["employer_amount"] = sprint($myEmpDeduct["employer_amount"] / $divisor);
                } else {
                    $myEmpDeduct["employer_amount"] = sprint($myEmpDeduct["amount"] * $myEmpDeduct["employer_amount"] / 100 / $divisor);
                }
                $tmp_deductions = $myEmpDeduct["amount"];
                $tmp_dedaccs = $myEmpDeduct["accid"];
                $tmp_emp_ded = $myEmpDeduct["employer_amount"];
                $tmp_grosdeduct = $myEmpDeduct["grosdeduct"];
            } else {
                $tmp_deductions = "0.00";
                $tmp_emp_ded = "0.00";
                $tmp_dedaccs = $myDeduct["accid"] != 0 ? $myDeduct["accid"] : $myDeduct["expaccid"];
                $tmp_grosdeduct = "n";
                $deductions_msg = "";
            }
            # check if we should be using deductions
            if ($myEmp['emp_usescales'] == "1" and $myDeduct['type'] == "Percentage") {
                # check if this deduction has scales
                $get_scales = "SELECT * FROM salded_scales WHERE saldedid = '{$myDeduct['id']}' LIMIT 1";
                $run_scales = db_exec($get_scales) or errDie("Unable to get deduction scale information.");
                if (pg_numrows($run_scales) > 0) {
                    # scales exist
                    $get_perc = "\n\t\t\t\t\t\tSELECT * FROM salded_scales \n\t\t\t\t\t\tWHERE scale_from <= '{$myEmp['basic_sal']}' AND scale_to >= '{$myEmp['basic_sal']}' AND saldedid = '{$myDeduct['id']}' \n\t\t\t\t\t\tLIMIT 1";
                    $run_perc = db_exec($get_perc) or errDie("Unable to get deduction scale information.");
                    if (pg_numrows($run_perc) > 0) {
                        # found a matching scale for this scaled duduction for a customer using scales ....
                        $scale_arr = pg_fetch_array($run_perc);
                        $tmp_deductions = sprint($myEmp['basic_sal'] / 100 * $scale_arr['scale_amount']);
                    }
                }
            }
            $deductions .= "\n\t\t\t\t<input type='hidden' size='10' name='employer_deductions[]' value='{$tmp_emp_ded}'>\n\t\t\t\t<input type='hidden' size='10' name='deducttax[]' value='{$myDeduct['add']}'>\n\t\t\t\t<input type='hidden' name='grosdeduct[]' value='{$tmp_grosdeduct}'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$myDeduct['deduction']} {$deductions_msg}</td>\n\t\t\t\t\t<td align='center'>\n\t\t\t\t\t\t" . CUR . "<input type='hidden' size='10' name='deductid[]' value='{$myDeduct['id']}'>\n\t\t\t\t\t\t<input type='hidden' size='30' name='deductname[]' value='{$myDeduct['deduction']}'>\n\t\t\t\t\t\t<input type='text' size='10' name='deductions[]' value='{$tmp_deductions}'>\n\t\t\t\t\t\t<input type='hidden' name='dedaccs[]' value='{$tmp_dedaccs}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
            $i++;
        }
    }
    $deductions .= "";
    $salarr = array("m" => "Per Month", "w" => "Per Week", "f" => "Fortnightly", "h" => "Per Hour");
    $salnarr = array("d" => "Day(s)", "h" => "Hour(s)");
    $saltype = $salarr[$myEmp['saltyp']];
    db_conn('cubit');
    $Sl = "SELECT * FROM bankacct WHERE btype != 'int' AND div = '" . USER_DIV . "' ORDER BY accname ASC";
    $Ry = db_exec($Sl) or errDie("Unable to get bank account.");
    if (pg_numrows($Ry) < 1) {
        return "<li class='err'> There are no bank accounts found in Cubit.\n\t\t<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct Selection'>";
    }
    $banks = "<select name='accid'>";
    while ($acc = pg_fetch_array($Ry)) {
        $banks .= "<option value='{$acc['bankid']}'>{$acc['accname']} ({$acc['acctype']})</option>";
    }
    $banks .= "</select>";
    $myEmp['loaninstall'] += 0;
    if ($myEmp['paytype'] == "Cash") {
        $paydetails = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='2'>Employee paid cash</td>\n\t\t\t</tr>\n\t\t\t<input type='hidden' name='accid' value='0'>";
    } elseif ($myEmp['paytype'] == "Ledger Account") {
        db_conn('core');
        $Sl = "SELECT accid,accname FROM accounts ORDER BY accname";
        $Ri = db_exec($Sl);
        $accounts = "<select name='account'>\n\t\t\t<option value='#'>Select Account</option>";
        while ($ad = pg_fetch_array($Ri)) {
            if (isset($account) && $account == $ad['accid']) {
                $sel = "selected";
            } else {
                $sel = "";
            }
            $accounts .= "<option value='{$ad['accid']}'>{$ad['accname']}</option>";
        }
        $accounts .= "</select>";
        $paydetails = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Ledger Account for payment</td>\n\t\t\t\t<td>{$accounts}</td>\n\t\t\t</tr>\n\t\t\t<input type='hidden' name='accid' value='0'>";
    } else {
        $paydetails = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Bank Account</td>\n\t\t\t\t<td valign='center'>{$banks}</td>\n\t\t\t</tr>";
    }
    $h1 = "";
    $h2 = "";
    $db = array("comp_pension" => $myEmp["comp_pension"], "emp_pension" => $myEmp["emp_pension"], "comp_provident" => $myEmp["comp_provident"], "emp_provident" => $myEmp["emp_provident"], "comp_uif" => $myEmp["comp_uif"], "emp_uif" => $myEmp["emp_uif"], "comp_other" => $myEmp["comp_other"], "emp_other" => $myEmp["emp_other"]);
    if (isset($basic_sal)) {
        $myEmp['basic_sal'] = $basic_sal;
        $myEmp['all_travel'] = $all_travel;
        $myEmp['bonus'] = $bonus;
        $myEmp['commission'] = $commission;
        $myEmp['abonus'] = $abonus;
        $myEmp['loaninstall'] = $loaninstall;
        $myEmp['comp_pension'] = $comp_pension;
        $myEmp['emp_pension'] = $emp_pension;
        $myEmp["comp_provident"] = $comp_provident;
        $myEmp["emp_provident"] = $emp_provident;
        //$myEmp["comp_uif"] = $comp_uif;
        //$myEmp["emp_uif"] = $emp_uif;
        $myEmp["comp_other"] = $comp_other;
        $myEmp["emp_other"] = $emp_other;
        $myEmp['comp_medical'] = $comp_medical;
        $myEmp['emp_medical'] = $emp_medical;
        $myEmp['comp_ret'] = $comp_ret;
        $myEmp['emp_ret'] = $emp_ret;
        $h1 = $novert;
        $h2 = $hovert;
    } else {
        if ($myEmp["payprd"] == "w" || $myEmp["payprd"] == "f") {
            $tmpmon = date("j");
            $daycount = date("t");
            $dayweek = date("D");
            if (strtolower($dayweek) == $myEmp["payprd_day"] && $day + 7 > $daycount) {
                $process_comp_deductions = true;
            } else {
                $process_comp_deductions = false;
            }
        } else {
            $process_comp_deductions = true;
        }
        $effective_basicsal = $myEmp["basic_sal"] * $multiplier;
        /* we only changing basic sal for non hourly employees,
        			because for hourly employees we change the hours ($mutli)  */
        if ($myEmp["saltyp"] != "h") {
            $myEmp["basic_sal"] *= $multiplier;
        }
        if ($myEmp["loaninstall"] > $myEmp["loanamt"]) {
            $myEmp["loaninstall"] = $myEmp["loanamt"];
        }
        $myEmp["emp_pension"] = sprint($effective_basicsal * ($myEmp["emp_pension"] / 100));
        $myEmp["comp_pension"] = sprint($effective_basicsal * ($myEmp["comp_pension"] / 100));
        $myEmp["emp_provident"] = sprint($effective_basicsal * ($myEmp["emp_provident"] / 100));
        $myEmp["comp_provident"] = sprint($effective_basicsal * ($myEmp["comp_provident"] / 100));
        $myEmp["emp_medical"] = sprint($myEmp["emp_medical"] / $divisor);
        $myEmp["comp_medical"] = sprint($myEmp["comp_medical"] / $divisor);
        $myEmp["emp_ret"] = sprint($myEmp["emp_ret"] / $divisor);
        $myEmp["comp_ret"] = sprint($myEmp["comp_ret"] / $divisor);
        $myEmp["loaninstall"] = sprint($myEmp["loaninstall"] / $divisor);
        $myEmp["all_travel"] = sprint($myEmp["all_travel"] / $divisor);
        if (isset($myEmp["loandate"]) and strlen($myEmp["loandate"]) > 0) {
            explodeDate($myEmp["loandate"], $loana_year, $loana_month, $loana_day);
            if ($loana_year > $salyr || $loana_year == $salyr && $loana_month > $MON) {
                $myEmp["loanint"] = 0;
                $myEmp["loaninstall"] = 0;
            }
        }
    }
    if (!isset($multi)) {
        $multi = $myEmp["saltyp"] == "h" ? $multiplier : 1;
    }
    $multi = round($multi);
    if ($myEmp['saltyp'] == 'd' || $myEmp['saltyp'] == 'h') {
        $salntype = $salnarr[$myEmp['saltyp']];
        $multi_show = "x <input type='text' size='3' name='multi' value='{$multi}'> {$salntype}";
    } else {
        $multi_show = "<input type='hidden' name='multi' value='{$multi}'>";
        $saltype = "";
    }
    /*	db_conn('cubit');
    	$sql = "SELECT value FROM settings WHERE constant='UIF_MAX'";
    	$percrslt = db_exec($sql);
    	$perc = pg_fetch_array($percrslt);
    	$uifmax = $perc['value'];
    
    	if ( $myEmp["emp_uif"] > $uifmax ) {
    		$myEmp["emp_uif"] = $uifmax;
    	}
    	if ( $myEmp["comp_uif"] > $uifmax ) {
    		$myEmp["comp_uif"] = $uifmax;
    	}
    */
    $Sl = "SELECT * FROM cubit.rbs ORDER BY name";
    $Ri = db_exec($Sl) or errDie("Unable to get data.");
    $i = 0;
    $rt = "";
    if (pg_num_rows($Ri) > 0) {
        while ($td = pg_fetch_array($Ri)) {
            if (!isset($rbsa[$td['id']])) {
                $rbsa[$td['id']] = "";
            }
            $rt .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><input type='hidden' name='rbs[{$td['id']}]' value='{$td['id']}'>{$td['name']}</td>\n\t\t\t\t\t<td>" . CUR . " <input type='text' size='10' name='rbsa[{$td['id']}]' value='" . $rbsa[$td['id']] . "' class=right></td>\n\t\t\t\t</tr>";
            $i++;
        }
    } else {
        $rt .= "<tr class='" . bg_class() . "'><td colspan='2' align='center'>There are no reimbursements</td></tr>";
    }
    if ($myEmp['payprd'] == "w") {
        $weekends = "";
        $weeks = "\n\t\t<select name='week'>";
        $stdate = mktime(0, 0, 0, $MON, 1, DATE_YEAR);
        $endate = mktime(0, 0, 0, $MON, DATE_DAYS, DATE_YEAR);
        $i = 1;
        while ($stdate <= $endate) {
            if (date("w", $stdate) == 5) {
                $weekends .= "<input type='hidden' name='weekends[{$i}]' value='" . date("j", $stdate) . "' />";
                if (isset($week) && $week == $i) {
                    $sel = "selected";
                } else {
                    $sel = "";
                }
                $weeks .= "<option {$sel} value='{$i}'>Week {$i} (" . date("j M", $stdate) . ")</option>";
                ++$i;
            }
            /* next day */
            $stdate += 24 * 60 * 60;
        }
        /*<option value='1'>Week 1</option>
        		<option value='2'>Week 2</option>
        		<option value='3'>Week 3</option>
        		<option value='4'>Week 4</option>
        		<option value='5'>Week 5</option>*/
        $weeks .= "\n\t\t</select>";
        $row = "{$weekends}<tr class='" . bg_class() . "'><td>Period</td><td>{$weeks}</td></tr>";
    } elseif ($myEmp['payprd'] == "f") {
        $weekends = "";
        $weeks = "\n\t\t<select name='week'>";
        $i = 1;
        /* find first friday of tax year */
        $stdate = mktime(0, 0, 0, 3, 1, getYearOfEmpMon(3));
        while (date("w", $stdate) != 5) {
            $stdate = mktime(0, 0, 0, 3, ++$i, getYearOfEmpMon(3));
        }
        // hack: go one week back so the +14 increases are easier
        $stdate -= 7 * 24 * 3600;
        /* end on the last day of the selected month */
        $endate = mktime(0, 0, 0, $MON + 1, 0, getYearOfEmpMon($MON));
        /* count weeks from start of tax year */
        $i = 1;
        $c = 0;
        while ($stdate <= $endate) {
            if (date("m", $stdate) == $MON && date("Y", $stdate) == getYearOfEmpMon($MON)) {
                $c += 2;
                $cd = $c - 1 . "-{$c}";
                $weekends .= "<input type='hidden' name='weekends[{$i}]' value='" . date("j", $stdate) . "' />";
                if (isset($week) && $week == $i) {
                    $sel = "selected";
                } else {
                    $sel = "";
                }
                $weeks .= "<option {$sel} value='{$i}'>Week {$cd} (" . date("j M", $stdate) . ")</option>";
                ++$i;
            }
            /* next day */
            $stdate += 24 * 60 * 60 * 14;
        }
        /*<option value='1'>Week 1</option>
        		<option value='2'>Week 2</option>
        		<option value='3'>Week 3</option>
        		<option value='4'>Week 4</option>
        		<option value='5'>Week 5</option>*/
        $weeks .= "\n\t\t</select>";
        $row = "{$weekends}<tr class='" . bg_class() . "'><td>Period</td><td>{$weeks}</td></tr>";
    } else {
        if ($myEmp["payprd"] == "d") {
            $x = date("t", mktime(0, 0, 0, $MON, 1, getYearOfFinMon($MON)));
            $MONstr = getMonthNameS($MON);
            if (!isset($pday)) {
                $pday = $proc_day;
            }
            $days = "<select name='pday'>";
            for ($i = 1; $i <= $x; ++$i) {
                if ($i == $pday) {
                    $sel = "selected='t'";
                } else {
                    $sel = "";
                }
                $days .= "<option {$sel} value='{$i}'>{$i} {$MONstr}</option>";
            }
            $days .= "</select>";
            $row = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Day for Payment</td>\n\t\t\t\t<td>{$days}</td>\n\t\t\t</tr>";
        } else {
            $weeks = "";
            $row = "<input type='hidden' name='week' value='0'>";
        }
    }
    if (!isset($abonus) && $myEmp["sal_bonus_month"] == $MON) {
        $abonus = $myEmp["sal_bonus"];
    } else {
        if (!isset($abonus)) {
            $abonus = 0;
        }
    }
    if ($myEmp["payprd"] == "m" || $myEmp["payprd"] == "h") {
        // count the amount of weekdays in this month
        $workdays = 0;
        for ($i = 1; $i <= date("t", mktime(0, 0, 0, $MON, 1, date("Y"))); ++$i) {
            $wd = date("w", mktime(0, 0, 0, $MON, $i, date("Y")));
            if ($wd != 0 && $wd != 6) {
                ++$workdays;
            }
        }
        // hours per day calculation
        $hpd = $myEmp["hpweek"] / 5;
        if (!isset($wh_total)) {
            $wh_total = $workdays * $hpd;
        }
        if (!isset($wh_actual)) {
            $wh_actual = $wh_total;
        }
    }
    if ($myEmp["payprd"] == "w") {
        if (!isset($wh_total)) {
            $wh_total = $myEmp["hpweek"];
        }
        if (!isset($wh_actual)) {
            $wh_actual = $wh_total;
        }
    }
    if ($myEmp["payprd"] == "f") {
        if (!isset($wh_total)) {
            $wh_total = $myEmp["hpweek"] * 2;
        }
        if (!isset($wh_actual)) {
            $wh_actual = $wh_total;
        }
    }
    $js_workhours = "\n\t<script>\n\t\tsf = document.getElementById('salfrm');\n\n\t\tf_sal\t\t= sf.elements['basic_sal'];\n\t\tf_whtot\t\t= sf.elements['wh_total'];\n\t\tf_whact\t\t= sf.elements['wh_actual'];\n\t\tf_cpension\t= sf.elements['comp_pension'];\n\t\tf_epension \t= sf.elements['emp_pension'];\n\t\tf_cprov\t\t= sf.elements['comp_provident'];\n\t\tf_eprov\t\t= sf.elements['emp_provident'];\n\t\t//f_cuif\t= sf.elements['comp_uif'];\n\t\t//f_euif\t= sf.elements['emp_uif'];\n\t\tf_cother\t= sf.elements['comp_other'];\n\t\tf_eother\t= sf.elements['emp_other'];\n\n\t\tdb_cpension\t= " . $db["comp_pension"] . ";\n\t\tdb_epension\t= " . $db["emp_pension"] . ";\n\t\tdb_cprov\t= " . $db["comp_provident"] . ";\n\t\tdb_eprov\t= " . $db["emp_provident"] . ";\n\t\t//db_cuif\t= " . $db["comp_uif"] . ";\n\t\t//db_euif\t= " . $db["emp_uif"] . ";\n\t\tdb_cother\t= " . $db["comp_other"] . ";\n\t\tdb_eother\t= " . $db["emp_other"] . ";\n\n\t\tval_sal \t\t= -1;\n\n\t\t// changing the workhours\n\t\tfunction workhours() {\n\t\t\tif ( val_sal < 0 ) val_sal = parseFloat(f_sal.value);\n\n\t\t\tval_whtot\t= parseFloat(f_whtot.value);\n\t\t\tval_whact\t= parseFloat(f_whact.value);\n\n\t\t\tif ( val_whtot >= val_whact ) {\n\t\t\t\tp = val_whact / val_whtot;\n\n\t\t\t\t// calculate the new basic salary\n\t\t\t\tx = val_sal * p;\n\t\t\t\tx = x.toFixed(2);\n\t\t\t\tf_sal.value = x;\n\n\t\t\t\t// calculate the new values\n\t\t\t\tval_cpension \t= x * db_cpension / 100;\n\t\t\t\tval_epension \t= x * db_epension / 100;\n\t\t\t\tval_cprov\t\t= x * db_cprov / 100;\n\t\t\t\tval_eprov\t\t= x * db_eprov / 100;\n\t\t\t\t//val_cuif\t\t= x * db_cuif / 100;\n\t\t\t\t//val_euif\t\t= x * db_euif / 100;\n\t\t\t\tval_cother\t\t= x * db_cother / 100;\n\t\t\t\tval_eother\t\t= x * db_eother / 100;\n\n\t\t\t\tval_cpension \t= val_cpension.toFixed(2);\n\t\t\t\tval_epension \t= val_epension.toFixed(2);\n\t\t\t\tval_cprov \t\t= val_cprov.toFixed(2);\n\t\t\t\tval_eprov\t\t= val_eprov.toFixed(2);\n\t\t\t\t//val_cuif\t\t= val_cuif.toFixed(2);\n\t\t\t\t//val_euif\t\t= val_euif.toFixed(2);\n\t\t\t\tval_cother\t\t= val_cother.toFixed(2);\n\t\t\t\tval_eother\t\t= val_eother.toFixed(2);\n\n\t\t\t\tf_cpension.value\t= val_cpension;\n\t\t\t\tf_epension.value \t= val_epension;\n\t\t\t\tf_cprov.value \t\t= val_cprov;\n\t\t\t\tf_eprov.value\t\t= val_eprov;\n\t\t\t\t//f_cuif.value\t\t= val_cuif;\n\t\t\t\t//f_euif.value\t\t= val_euif;\n\t\t\t\tf_cother.value\t\t= val_cother;\n\t\t\t\tf_eother.value\t\t= val_eother;\n\t\t\t}\n\t\t}\n\n\t\tfunction changedfield() {\n\t\t\tval_whtot\t= parseFloat(f_whtot.value);\n\t\t\tval_whact\t= parseFloat(f_whact.value);\n\n\t\t\tp = val_whtot / val_whact;\n\n\t\t\tval_sal = parseFloat(f_sal.value) * p;\n\t\t\tval_sal = val_sal.toFixed(2);\n\t\t}\n\t</script>";
    vsprint($myEmp["basic_sal"]);
    /* payprd message */
    $dispmsg = getCSetting("EMP_SALMSG");
    if (strpos($dispmsg, $myEmp["payprd"]) === false) {
        $payprd_msg_ch = "";
    } else {
        $payprd_msg_ch = "checked='t'";
    }
    $payprd_msg = get_payprdmsg($myEmp["payprd"]);
    /* print payslip on/off */
    $printslip = getCSetting("EMP_PRINTSLIP");
    $process = "\n\t<script>\n\t\tfunction update_salmsg(obj) {\n\t\t\tajaxRequest('payprdmsg.php', 'payprd_msg', AJAX_SET,\n\t\t\t\t'payprd={$myEmp['payprd']}&newval=' + obj.checked);\n\t\t}\n\t</script>\n\t<h3>Process Salary for {$myEmp['sname']}, {$myEmp['fnames']}</h3>\n\t<li class='err'>NOTE that Cubit is configured to compute employees' tax\n\t\tduring the employees' tax year that<br />\n\t\tstarts in March and ends in February,\n\t\tirrespective of the employer's financial year end.</li>\n\t<br />\n\t<form action='" . SELF . "' method='POST' id='salfrm'>\n\t\t<input type='hidden' name='key' value='confirm' />\n\t\t<input type='hidden' name='empnum' value='{$empnum}' />\n\t\t<input type='hidden' name='MON' value='{$MON}' />\n\t\t<input type='hidden' name='proc_day' value='{$proc_day}' />\n\t\t<input type='hidden' name='proc_month' value='{$proc_month}' />\n\t\t<input type='hidden' name='proc_year' value='{$proc_year}' />\n\t\t<input type='hidden' name='day' value='{$proc_day}' />\n\t\t<input type='hidden' name='mon' value='{$proc_month}' />\n\t\t<input type='hidden' name='year' value='{$proc_year}' />\n\t\t<input type='hidden' name='saltyp' value='{$myEmp['saltyp']}' />\n\t\t<input type='hidden' name='loanint' value='{$myEmp['loanint']}' />\n\t\t<input type='hidden' name='process_comp_deductions' value='{$process_comp_deductions}' />\n\t\t<input type='hidden' name='divisor' value='{$divisor}' />\n\t<table " . TMPL_tblDflts . " width='500'>\n\t\t<tr>\n\t\t\t<td id='payprd_msg'>{$payprd_msg}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th align='right'>Salary Help Message: <input type='checkbox' onclick='update_salmsg(this);' name='payprd_dispmsg' {$payprd_msg_ch} /></th>\n\t\t</tr>\n\t</table>\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<td><input type='submit' name='back' value='&laquo; Correction'></td>\n\t\t\t<td align='right'><input type='submit' value='Confirm &raquo;'></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan='2'>{$err}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan='2'>Salary Details for the Pay Period</th>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap='t'>Print Salary Advice</td>\n\t\t\t<td>\n\t\t\t<select name='printslip'>\n\t\t\t\t<option value='y' " . ($printslip != "n" ? "selected='t'" : "") . ">Yes</option>\n\t\t\t\t<option value='n' " . ($printslip == "n" ? "selected='t'" : "") . ">No</option>\n\t\t\t</select>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Basic salary</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='basic_sal' value='{$myEmp['basic_sal']}' class=right onChange='changedfield();'> {$saltype} {$multi_show}</td>\n\t\t</tr>";
    if ($myEmp["payprd"] == "d") {
        $process .= "\n\t\t\t<input type='hidden' name='wh_total' value='1'>\n\t\t\t<input type='hidden' name='wh_actual' value='1'>";
    } else {
        $process .= "\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Total Work Hours:</td>\n\t\t\t<td><input type='text' size='10' name='wh_total' value='{$wh_total}' class='right' onChange='workhours();'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Actual Hours Worked:</td>\n\t\t\t<td><input type='text' size='10' name='wh_actual' value='{$wh_actual}' class='right' onChange='workhours();'></td>\n\t\t</tr>";
    }
    if (!isset($annual)) {
        $annual = "";
    }
    $process .= "\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Normal Overtime</td>\n\t\t\t<td nowrap><input type='text' size='5' name='novert' value='{$h1}' class='right'> Hrs</td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Public Holiday Overtime</td>\n\t\t\t<td nowrap><input type='text' size='5' name='hovert' value='{$h2}' class='right'> Hrs</td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<!--<td>Special Bonus/Additional Salary</td>-->\n\t\t\t<td>Annual Bonus</td>\n\t\t\t<td>" . CUR . " <input type='text' size='10' name='abonus' value='{$abonus}' class='right'></td>\n\t\t\t<!--<td rowspan='2' class='err'>An amount entered here (Special Bonus/Additional\n\t\t\t\tSalary) will be treated as a recurring bonus/payment per pay period for PAYE\n\t\t\t\tpurposes, the amount will not be treated as an annual payment. If the\n\t\t\t\tamount paid as a bonus is a once off/annual payment please use the\n\t\t\t\tBonus(Annual Payments) option. In other cases PAYE has to be manually\n\t\t\t\tadjusted <u>per directive</u> from SARS when processing salary.\n\t\t\t</td>-->\n\t\t</tr>\n\t\t<input type='hidden' name='annual' value='0' />\n\t\t<!--<tr class='" . bg_class() . "'>\n\t\t\t<td>Bonus(Annual/Once Off Payments)</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='annual' value='{$annual}' class='right'></td>\n\t\t</tr>-->\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Commission</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='commission' value='{$myEmp['commission']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Low or interest-free loan installment</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='loaninstall' value='{$myEmp['loaninstall']}' class='right'></td>\n\t\t\t<td class='err'>In the event that the employee repays more than the installment -\n\t\t\t\tenter that amount, plus interest that is remitted, here.\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Travel Allowance</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='all_travel' value='{$myEmp['all_travel']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Pension: Company Contribution</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='comp_pension' value='{$myEmp['comp_pension']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Pension: Employee Deduction</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='emp_pension' value='{$myEmp['emp_pension']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Provident: Company Contribution</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='comp_provident' value='{$myEmp['comp_provident']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Provident: Employee Deduction</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='emp_provident' value='{$myEmp['emp_provident']}' class='right'></td>\n\t\t</tr>\n\t\t<!--\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>UIF: Company Contribution</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='comp_uif' value='{$myEmp['comp_uif']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>UIF: Employee Deduction</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='emp_uif' value='{$myEmp['emp_uif']}' class='right'></td>\n\t\t</tr>\n\t\t//-->\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Retirement Annuity: Company Contribution</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='comp_ret' value='{$myEmp['comp_ret']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Retirement Annuity: Employee Deduction</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='emp_ret' value='{$myEmp['emp_ret']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Medical Contribution: Company</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='comp_medical' value='{$myEmp['comp_medical']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Medical Contribution: Employee</td>\n\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='emp_medical' value='{$myEmp['emp_medical']}' class='right'></td>\n\t\t</tr>\n\t\t<input type=hidden name='comp_other' value='0'>\n\t\t<input type=hidden name='emp_other' value='0'>\n\t\t<!--\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Other: Company Contribution</td>\n\t\t\t<td>" . CUR . " <input type='text' size='10' name='comp_other' value='{$myEmp['comp_other']}' class='right'></td>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Other: Employee Deduction</td>\n\t\t\t<td>" . CUR . " <input type='text' size='10' name='emp_other' value='{$myEmp['emp_other']}' class='right'></td>\n\t\t</tr>\n\t\t//-->\n\t\t{$paydetails}\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>Override PAYE <input type='checkbox' name='mpaye'></td>\n\t\t\t<td>" . CUR . " <input type='text' size='10' name='mpaye_amount'></td>\n\t\t</tr>\n\t\t{$row}\n\t\t<tr><th colspan='2'>Fringe Benefits</th></tr>\n\t\t{$fringes}\n\t\t<tr><th colspan='2'>Allowances</th></tr>\n\t\t{$allowances}\n\t\t<tr><th colspan='2'>Subsistence Allowances</th></tr>\n\t\t{$subsistence}\n\t\t<tr><th colspan='2'>Deductions</th></tr>\n\t\t{$deductions}\n\t\t{$rt}\n\t\t<tr>\n\t\t\t<td><input type='submit' name='back' value='&laquo; Correction'></td>\n\t\t\t<td align='right'><input type='submit' value='Confirm &raquo;'></td>\n\t\t</tr>\n\t\t</form>\n\t\t{$js_workhours}\n\t\t</table>";
    return $process;
}
コード例 #2
0
function process($_POST)
{
    extract($_POST);
    if (isset($btn_correction)) {
        return slctEmployee();
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($empnum, "num", 1, 20, "Invalid employee number.");
    $v->isOk($MON, "num", 1, 2, "Invalid month.");
    global $PRDMON, $MONPRD;
    $yr = getYearOfEmpMon($MON);
    $curyr = getActiveFinYear();
    if ($yr > $curyr || $yr == $curyr && $MON > $PRDMON[12]) {
        $v->addError("", "Cannot do transaction in future financial year. You need\n\t\t\tto close your year first before you can continue.");
    }
    if ($v->isError()) {
        return slctEmployee($v->genErrors());
        return $confirmCust;
    }
    # Get employee details
    global $global_empnum;
    $global_empnum = $empnum;
    db_conn('cubit');
    $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 ($myEmp["flag"] == "2.5EMP") {
        $OUTPUT = "\n\t\t\t<h3>Process Employee Salary</h3>\n\t\t\t<li class='err'>\n\t\t\t\tDue to the changes from Cubit 2.5 to Cubit 2.6.1 you should first update your employee's\n\t\t\t\tsalary/deduction/allowance information in the employee edit form.\n\t\t\t\tClick <a href='../admin-employee-edit.php?empnum={$empnum}'>here</a> to do so.\n\t\t\t</li>";
        return $OUTPUT;
    }
    if (!empty($idnum)) {
        $bd_year = substr($myEmp["idnum"], 0, 2);
        $bd_month = substr($myEmp["idnum"], 2, 2);
        $bd_day = substr($myEmp["idnum"], 4, 2);
        if (!checkdate($bd_month, $bd_day, $bd_year)) {
            $OUTPUT = "\n\t\t\t\t<h3>Process Employee Salary</h3>\n\t\t\t\t<li class='err'>\n\t\t\t\t\tSelected employee does not have a valid id number and therefore his age cannot be\n\t\t\t\t\tcalculated.<br>\n\t\t\t\t\tPlease update this information in the employee <a href='../admin-employee-edit.php?empnum={$empnum}'>edit</a> form.\n\t\t\t\t</li>";
            return $OUTPUT;
        }
    }
    if ($myEmp["paytype"] == "EFT" && (empty($myEmp["bankname"]) || empty($myEmp["bankaccno"]))) {
        return "Employee banking information not entered.<br>\n\t\t\tClick <a href='../admin-employee-edit.php?empnum={$empnum}'>here</a> employee banking information.";
    }
    $grossal = $myEmp["basic_sal"] + $myEmp["commission"] + $myEmp["bonus"];
    $yy = date("Y");
    $mm = $MON;
    $mm += 0;
    if ($myEmp['payprd'] == "m") {
        $Sl = "SELECT * FROM salpaid WHERE empnum='{$empnum}' AND month='{$mm}' AND cyear='" . EMP_YEAR . "'";
        $Ri = db_exec($Sl);
        $paid = pg_num_rows($Ri);
        $Sl = "SELECT * FROM salr WHERE empnum='{$empnum}' AND month='{$mm}' AND cyear='" . EMP_YEAR . "'";
        $Ri = db_exec($Sl);
        $upaid = pg_num_rows($Ri);
        $upaid += 0;
        $paid -= $upaid;
    } else {
        $yy = date("Y");
        $mm = $MON;
        $mm += 0;
        $Sl = "SELECT * FROM salpaid WHERE empnum='{$empnum}' AND month='{$mm}' AND week='{$week}' AND cyear='" . EMP_YEAR . "'";
        $Ri = db_exec($Sl);
        $paid = pg_num_rows($Ri);
        $Sl = "SELECT * FROM salr WHERE empnum='{$empnum}' AND month='{$mm}' AND week='{$week}' AND cyear='" . EMP_YEAR . "'";
        $Ri = db_exec($Sl);
        $upaid = pg_num_rows($Ri);
        $upaid += 0;
        $paid -= $upaid;
    }
    if (empty($paid)) {
        return slctPrd("<li class='err'>You have not processed a salary for that period.</li>");
    }
    /* calculate basic salary divisors and multipliers
     * used for calculating deductions/allowances/etc. when the
     * salary type and payment period differs in length
     */
    switch ($myEmp["saltyp"]) {
        case "h":
            $divisor = 1;
            switch ($myEmp["payprd"]) {
                case "d":
                    $multiplier = $myEmp["hpweek"] / 5;
                    break;
                case "w":
                    $multiplier = $myEmp["hpweek"];
                    break;
                case "f":
                    $multiplier = $myEmp["hpweek"] * 2;
                    break;
                case "m":
                    $multiplier = $myEmp["hpweek"] * 52 / 12;
                    break;
            }
            break;
        case "m":
            $divisor = 1;
            switch ($myEmp["payprd"]) {
                case "d":
                    $multiplier = 12 / (5 * 52);
                    break;
                case "w":
                    $multiplier = 12 / 52;
                    break;
                case "f":
                    $multiplier = 12 / 26;
                    break;
                case "m":
                    $multiplier = 1;
                    break;
            }
            break;
        case "w":
            $divisor = 52 / 12;
            switch ($myEmp["payprd"]) {
                case "d":
                    $multiplier = 1 / 5;
                    break;
                case "w":
                    $multiplier = 1;
                    break;
                case "f":
                    $multiplier = 2;
                    break;
                case "m":
                    $multiplier = 52 / 12;
                    break;
            }
            break;
        case "f":
            $divisor = 26 / 12;
            switch ($myEmp["payprd"]) {
                case "d":
                    $multiplier = 1 / 10;
                    break;
                case "w":
                    $multiplier = 1 / 2;
                    break;
                case "f":
                    $multiplier = 1;
                    break;
                case "m":
                    $multiplier = 26 / 12;
                    break;
            }
            break;
    }
    /* BEGIN: retrieve/populate amounts to reverse */
    switch ($myEmp["payprd"]) {
        case "m":
            $spw = "true";
            break;
        case "d":
            $spw = "week='{$pday}'";
            break;
        case "f":
        case "w":
            $spw = "week='{$week}'";
            break;
    }
    /* previous salary entries in salpaid/salr */
    $vals = array("paye", "hours", "salrate", "comm", "bonus", "novert", "hovert");
    $prevsal = array();
    /* FP: CALCULATE PREVIOUS */
    /* previous salary entries in emp_(inc|com|ded|frin) */
    foreach ($vals as $vn) {
        /* process */
        $sql = "SELECT sum({$vn}) FROM salpaid WHERE empnum='{$empnum}' AND ({$spw}) AND month='{$MON}' and cyear='" . EMP_YEAR . "'";
        $rslt = db_exec($sql) or errDie("Unable to get paye");
        $prevsal[$vn] = pg_fetch_result($rslt, 0, 0);
        /* reverse */
        $sql = "SELECT sum({$vn}) FROM salr WHERE empnum='{$empnum}' AND ({$spw}) AND month='{$MON}' and cyear='" . EMP_YEAR . "'";
        $rslt = db_exec($sql) or errDie("Unable to get paye");
        $prevsal[$vn] -= pg_fetch_result($rslt, 0, 0);
        vsprint($prevsal[$vn]);
    }
    //do we want to include overtime in the reversal? ... yes plz ...
    $h1 = $prevsal['novert'];
    $h2 = $prevsal['hovert'];
    //FP use this to go though tables and get info to reverse (bonus etc)
    $vals = array("emp_ded" => array("DEDP" => "emp_pension", "DEDV" => "emp_provident", "UIFE" => "emp_uif", "DEDR" => "emp_ret", "DEDA" => "myEmp[fringe_car1_contrib]", "DEDB" => "myEmp[fringe_car2_contrib]", "DEDM" => "emp_medical", "DEDO" => "emp_other"), "emp_com" => array("COMP" => "comp_pension", "COMV" => "comp_provident", "UIFC" => "comp_uif", "COMR" => "comp_ret", "COMM" => "comp_medical", "COMO" => "comp_other", "SDL" => "sdl"), "emp_frin" => array());
    foreach ($vals as $table => $pd) {
        foreach ($pd as $code => $vn) {
            /* process */
            $sql = "\n\t\t\t\tSELECT sum(amount) \n\t\t\t\tFROM {$table} \n\t\t\t\tWHERE emp='{$empnum}' AND type='{$code}' AND ({$spw}) AND period='{$MON}' AND year='" . EMP_YEAR . "' LIMIT 1";
            $rslt = db_exec($sql) or errDie("Unable to get paye");
            if (strlen(pg_fetch_result($rslt, 0, 0)) > 0) {
                $prevsal[$vn] = pg_fetch_result($rslt, 0, 0);
            } else {
                $prevsal[$vn] = "0.00";
            }
        }
    }
    /* END: retrieve/populate amounts to reverse */
    # fringe benefits
    $fringes = "";
    $i = 0;
    $sql = "SELECT * FROM fringebens WHERE div = '" . USER_DIV . "' ORDER BY fringeben";
    $rslt = db_exec($sql) or errDie("Unable to select allowances from database.");
    if (pg_num_rows($rslt) < 1) {
        $fringes = "\n\t\t\t<tr>\n\t\t\t\t<td class='" . bg_class() . "' colspan='2' align='center'>None found in database.</td>\n\t\t\t</tr>\n";
    } else {
        while ($myFringe = pg_fetch_array($rslt)) {
            # check if employee has allowance
            $sql = "SELECT * FROM empfringe WHERE fringeid='{$myFringe['id']}' AND empnum='{$myEmp['empnum']}' AND div = '" . USER_DIV . "'";
            $empRslt = db_exec($sql) or errDie("Unable to retrieve fringe benefit info from database.");
            if (pg_numrows($empRslt) > 0) {
                $empFringe = pg_fetch_array($empRslt);
                $sql = "SELECT sum(amount) FROM cubit.emp_frin WHERE emp='{$empnum}' AND type='{$myFringe['id']}' AND ({$spw}) AND period='{$MON}' AND year='" . EMP_YEAR . "'";
                $amtRslt = db_exec($sql);
                $empFringe["amount"] = pg_fetch_result($amtRslt, 0, 0);
                //				if ( substr($empFringe["type"], 0, 4) == "Perc" ) {
                //					$empFringe["amount"] = sprint($myEmp["basic_sal"] * ($empFringe["amount"]/100) / $divisor);
                //				} else {
                //					$empFringe['amount'] = sprint($empFringe['amount'] / $divisor);
                //				}
                $grossal += $empFringe["amount"];
                $tmp_fringeaccs = $empFringe["accid"];
                $tmp_fringebens = $empFringe["amount"];
            } else {
                $tmp_fringeaccs = "0";
                $tmp_fringebens = "0.00";
            }
            $fringes .= "\n\t\t\t\t<input type='hidden' name='fringeid[]' value='{$myFringe['id']}'>\n\t\t\t\t<input type='hidden' name='fringename[]' value='{$myFringe['fringeben']}'>\n\t\t\t\t<input type='hidden' name='fringeaccs[]' value='{$tmp_fringeaccs}'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$myFringe['fringeben']}</td>\n\t\t\t\t\t<td align='center'>\n\t\t\t\t\t\t" . CUR . " {$tmp_fringebens}\n\t\t\t\t\t\t<input type='hidden' size=10 name='fringebens[]' value='{$tmp_fringebens}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
            $i++;
        }
    }
    # get allowances
    $allowances = "";
    $i = 0;
    $sql = "SELECT * FROM allowances WHERE div = '" . USER_DIV . "' ORDER BY allowance";
    $allowRslt = db_exec($sql) or errDie("Unable to select allowances from database.");
    if (pg_numrows($allowRslt) < 1) {
        $allowances = "<tr><td class='" . bg_class() . "' colspan='2' align='center'>None found in database.</td></tr>\n";
    } else {
        while ($myAllow = pg_fetch_array($allowRslt)) {
            # check if employee has allowance
            $sql = "SELECT * FROM empallow WHERE allowid='{$myAllow['id']}' AND empnum='{$myEmp['empnum']}' AND div = '" . USER_DIV . "'";
            $empAllowRslt = db_exec($sql) or errDie("Unable to select allowance info from database.");
            if (pg_numrows($empAllowRslt) > 0) {
                $myEmpAllow = pg_fetch_array($empAllowRslt);
                $sql = "SELECT sum(amount) FROM cubit.emp_inc WHERE emp='{$empnum}' AND type='{$myAllow['id']}' AND ex != 'SUBS' AND ({$spw}) AND period='{$MON}' AND year='" . EMP_YEAR . "'";
                $amtRslt = db_exec($sql);
                $myEmpAllow["amount"] = pg_fetch_result($amtRslt, 0, 0);
                //				if ( substr($myEmpAllow["type"], 0, 4) == "Perc" ) {
                //					$myEmpAllow["amount"] = sprint($myEmp["basic_sal"] * ($myEmpAllow["amount"]/100) / $divisor);
                //				} else {
                //					$myEmpAllow['amount'] = sprint($myEmpAllow['amount'] / $divisor);
                //				}
                $grossal += $myEmpAllow["amount"];
                $tmp_allowaccs = $myEmpAllow["accid"];
                $tmp_allowances = $myEmpAllow["amount"];
            } else {
                $tmp_allowaccs = $myAllow["accid"];
                $tmp_allowances = "0.00";
            }
            $allowances .= "\n\t\t\t\t<input type='hidden' size='10' name='allowid[]' value='{$myAllow['id']}'>\n\t\t\t\t<input type='hidden' size='30' name='allowname[]' value='{$myAllow['allowance']}'>\n\t\t\t\t<input type='hidden' size='10' name='allowtax[]' value='{$myAllow['add']}'>\n\t\t\t\t<input type='hidden' name='allowaccs[]' value='{$tmp_allowaccs}'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$myAllow['allowance']}</td>\n\t\t\t\t\t<td align='center'>" . CUR . " {$tmp_allowances}<input type='hidden' size='10' name='allowances[]' value='{$tmp_allowances}'></td>\n\t\t\t\t</tr>";
            $i++;
        }
    }
    $subsistence = "";
    $subslst = new dbSelect("subsistence", "cubit", array("where" => "div='" . USER_DIV . "'", "order" => "name"));
    $subslst->run();
    $subs_int = false;
    if ($subslst->num_rows() > 0) {
        $i = 0;
        $subsistence .= "\n\t\t\t<tr>\n\t\t\t\t<td colspan='10'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Name</th>\n\t\t\t\t\t\t\t<th>Amount</th>\n\t\t\t\t\t\t\t<th>Days</th>\n\t\t\t\t\t\t</tr>";
        $empsubs = new dbSelect("emp_subsistence", "cubit");
        while ($subs = $subslst->fetch_array()) {
            $sid = $subs["id"];
            $empsubs->setOpt(array("where" => "empnum='{$empnum}' AND subid='{$sid}'"));
            $empsubs->run();
            if ($empsubs->num_rows() <= 0) {
                $si["amount"] = "0.00";
                $si["days"] = "0";
                $si["accid"] = $subs["accid"];
            } else {
                $si = $empsubs->fetch_array();
            }
            if ($subs["in_republic"] != "yes") {
                $subs_int = true;
            }
            $subsistence .= "\n\t\t\t\t<input type='hidden' name='subsname[{$sid}]' value='{$subs['name']}'>\n\t\t\t\t<input type='hidden' name='subsacc[{$sid}]' value='{$si['accid']}'>\n\t\t\t\t<input type='hidden' name='subsrep[{$sid}]' value='{$subs['in_republic']}'>\n\t\t\t\t<input type='hidden' name='subsmeal[{$sid}]' value='{$subs['meals']}'>\n\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t<td>{$subs['name']}</td>\n\t\t\t\t\t<td>" . CUR . " {$si['amount']}<input type='hidden' name='subsamt[{$sid}]' value='{$si['amount']}'></td>\n\t\t\t\t\t<td>{$si['days']}<input type='hidden' name='subsdays[{$sid}]' value='{$si['days']}'></td>\n\t\t\t\t</tr>";
        }
        if ($subs_int) {
            $subsistence .= "\n\t\t\t\t<input type='hidden' name='subs_exch' value='1'>\n\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t<td colspan='3'><li class='err'>Please calculate the rand amount prior to completing the amount above.</li></td\n\t\t\t\t</tr>";
            // 				<tr bgcolor='".bgcolor($i)."'>
            // 					<td colspan='2'>Exchange (ZAR-USD):</td>
            // 					<td>".xrate_get("USD")."<input type='hidden' name='subs_exch' value='".xrate_get("USD")."'></td>
            // 				</tr>";
        }
        $subsistence .= "\n\t\t\t</table>\n\t\t\t</td></tr>";
    }
    # Deductions
    $deductions = "";
    $i = 0;
    $sql = "SELECT * FROM salded WHERE div = '" . USER_DIV . "' ORDER BY deduction";
    $deductRslt = db_exec($sql) or errDie("Unable to select deductions from database.");
    if (pg_numrows($deductRslt) < 1) {
        $deductions = "\n\t\t\t<tr>\n\t\t\t\t<td class='" . bg_class() . "' colspan='2' align='center'>None found in database.</td>\n\t\t\t</tr>\n";
    } else {
        while ($myDeduct = pg_fetch_array($deductRslt)) {
            # check if employee has deduction
            $sql = "SELECT * FROM empdeduct WHERE dedid='{$myDeduct['id']}' AND empnum='{$myEmp['empnum']}' AND div = '" . USER_DIV . "'";
            $empDeductRslt = db_exec($sql) or errDie("Unable to select Deduction info from database.");
            if (pg_numrows($empDeductRslt) > 0) {
                $myEmpDeduct = pg_fetch_array($empDeductRslt);
                if ($myEmpDeduct["grosdeduct"] == "y") {
                    $deductions_msg = "(Deducted from Gross Salary)";
                    $sal_calcfrom = $grossal;
                } else {
                    $deductions_msg = "";
                    $sal_calcfrom = $myEmp['basic_sal'];
                }
                $sql = "SELECT sum(amount) FROM cubit.emp_ded WHERE emp='{$empnum}' AND type='{$myDeduct['id']}' AND ({$spw}) AND period='{$MON}' AND year='" . EMP_YEAR . "'";
                $amtRslt = db_exec($sql);
                $myEmpDeduct['amount'] = pg_fetch_result($amtRslt, 0, 0);
                //if ($myEmpDeduct['type'] == "Amount") {
                //	$myEmpDeduct['amount'] = sprint($myEmpDeduct['amount'] / $divisor);
                //} else {
                //	$myEmpDeduct['amount'] = sprint($sal_calcfrom*$myEmpDeduct['amount']/100 / $divisor);
                //}
                // calculate employer contribution to deduction
                $sql = "SELECT sum(amount) FROM cubit.emp_com WHERE emp='{$empnum}' AND type='{$myDeduct['id']}' AND ({$spw}) AND period='{$MON}' AND year='" . EMP_YEAR . "'";
                $amtRslt = db_exec($sql);
                $myEmpDeduct["employer_amount"] = pg_fetch_result($amtRslt, 0, 0);
                //if ( $myEmpDeduct["employer_type"] == "Amount" ) {
                //	$myEmpDeduct["employer_amount"] = sprint($myEmpDeduct["employer_amount"] / $divisor);
                //} else {
                //	$myEmpDeduct["employer_amount"] = sprint($myEmpDeduct["amount"] * $myEmpDeduct["employer_amount"] / 100 / $divisor);
                //}
                $tmp_deductions = $myEmpDeduct["amount"];
                $tmp_dedaccs = $myEmpDeduct["accid"];
                $tmp_emp_ded = $myEmpDeduct["employer_amount"];
                $tmp_grosdeduct = $myEmpDeduct["grosdeduct"];
            } else {
                #employee may have R0.00 entered into deduction fields ....
                #in which case no db entries will exist ... manually check these vars here ...
                $sql = "SELECT sum(amount) FROM cubit.emp_ded WHERE emp='{$empnum}' AND type='{$myDeduct['id']}' AND ({$spw}) AND period='{$MON}' AND year='" . EMP_YEAR . "'";
                $runsql = db_exec($sql) or errDie("Unable to get employee deduction information.");
                if (pg_numrows($runsql) > 0) {
                    $myEmpDeduct['amount'] = pg_fetch_result($runsql, 0, 0);
                    $sql2 = "SELECT * FROM cubit.salded WHERE id = '{$myDeduct['id']}'";
                    $run_sql2 = db_exec($sql2) or errDie("Unable to get employee deductions information");
                    if (pg_numrows($run_sql2) > 0) {
                        $darr = pg_fetch_array($run_sql2);
                        $tmp_dedaccs = $darr["accid"];
                    } else {
                        $tmp_dedaccs = $myEmpDeduct["accid"];
                    }
                    $sql = "SELECT sum(amount) FROM cubit.emp_com WHERE emp='{$empnum}' AND type='{$myDeduct['id']}' AND ({$spw}) AND period='{$MON}' AND year='" . EMP_YEAR . "'";
                    $amtRslt = db_exec($sql);
                    $myEmpDeduct["employer_amount"] = pg_fetch_result($amtRslt, 0, 0);
                    $tmp_deductions = $myEmpDeduct["amount"];
                    $tmp_emp_ded = $myEmpDeduct["employer_amount"];
                    $tmp_grosdeduct = $myEmpDeduct["grosdeduct"];
                } else {
                    $tmp_deductions = "0.00";
                    $tmp_emp_ded = "0.00";
                    $tmp_dedaccs = $myDeduct["accid"] != 0 ? $myDeduct["accid"] : $myDeduct["expaccid"];
                    $tmp_grosdeduct = "n";
                    $deductions_msg = "";
                }
            }
            $deductions .= "\n\t\t\t\t<input type='hidden' size='10' name='employer_deductions[]' value='{$tmp_emp_ded}'>\n\t\t\t\t<input type='hidden' size='10' name='deducttax[]' value='{$myDeduct['add']}'>\n\t\t\t\t<input type='hidden' name='grosdeduct[]' value='{$tmp_grosdeduct}'>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$myDeduct['deduction']} {$deductions_msg}</td>\n\t\t\t\t\t<td align='center'>\n\t\t\t\t\t\t" . CUR . " {$tmp_deductions}\n\t\t\t\t\t\t<input type='hidden' size='10' name='deductid[]' value='{$myDeduct['id']}'>\n\t\t\t\t\t\t<input type='hidden' size='30' name='deductname[]' value='{$myDeduct['deduction']}'>\n\t\t\t\t\t\t<input type='hidden' size='10' name='deductions[]' value='{$tmp_deductions}'>\n\t\t\t\t\t\t<input type='hidden' name='dedaccs[]' value='{$tmp_dedaccs}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
            $i++;
        }
    }
    $deductions .= "";
    /* get loan installment for applicable month */
    db_conn("cubit");
    $sql = "SELECT * FROM emp_loaninstallments WHERE empnum='{$empnum}' AND fmonth='{$mm}' AND fyear='" . EMP_YEAR . "' LIMIT 1";
    $rslt = db_exec($sql) or errDie("Error reading possible loan installment information.");
    if (pg_num_rows($rslt) > 0) {
        $loandata = pg_fetch_array($rslt);
        $myEmp["loaninstall"] = $loandata["installment"];
        $tm_loaninstall = $loandata["installment"];
        $fringe_loan = $loandata["fringe"];
        $loanint = $loandata["interest"];
        $loaninstall_date = $loandata["fdate"];
        $loaninstall_prd = $loandata["fperiod"];
    } else {
        $myEmp['loaninstall'] = "0.00";
        $tm_loaninstall = "0.00";
        $fringe_loan = "0.00";
        $loanint = "0.00";
        $loaninstall_date = "0000-00-00";
        $loaninstall_prd = "0";
    }
    $salarr = array("m" => "Per Month", "w" => "Per Week", "f" => "Fortnightly", "h" => "Per Hour");
    $salnarr = array("d" => "Day(s)", "h" => "Hour(s)");
    $saltype = $salarr[$myEmp['saltyp']];
    $multi = round($prevsal["hours"]);
    if ($myEmp['saltyp'] == 'd' || $myEmp['saltyp'] == 'h') {
        $salntype = $salnarr[$myEmp['saltyp']];
        $multi_show = "x <input type='hidden' size='3' name='multi' value='{$multi}'>{$multi} {$salntype}";
    } else {
        $multi_show = "<input type='hidden' name='multi' value='{$multi}'>";
        $saltype = "";
    }
    db_conn('cubit');
    $Sl = "SELECT * FROM bankacct WHERE btype != 'int' AND div = '" . USER_DIV . "' ORDER BY accname ASC";
    $Ry = db_exec($Sl) or errDie("Unable to get bank account.");
    if (pg_numrows($Ry) < 1) {
        return "<li class='err'> There are no bank accounts found in Cubit.</li>\n\t\t<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct Selection'>";
    }
    $banks = "<select name='accid'>";
    while ($acc = pg_fetch_array($Ry)) {
        $banks .= "<option value='{$acc['bankid']}'>{$acc['accname']} ({$acc['acctype']})</option>";
    }
    $banks .= "</select>";
    $myEmp['loaninstall'] += 0;
    if ($myEmp['paytype'] == "Cash") {
        $paydetails = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='2'>Employee paid cash</td>\n\t\t\t</tr>\n\t\t\t<input type='hidden' name='accid' value='0'>";
    } else {
        if ($myEmp['paytype'] == "Ledger Account") {
            db_conn('core');
            $Sl = "SELECT accid,accname FROM accounts ORDER BY accname";
            $Ri = db_exec($Sl);
            $accounts = "\n\t\t\t<select name='account'>\n\t\t\t\t<option value='#'>Select Account</option>";
            while ($ad = pg_fetch_array($Ri)) {
                if (isset($account) && $account == $ad['accid']) {
                    $sel = "selected";
                } else {
                    $sel = "";
                }
                $accounts .= "<option value='{$ad['accid']}'>{$ad['accname']}</option>";
            }
            $accounts .= "</select>";
            $paydetails = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Ledger Account for payment</td>\n\t\t\t\t<td>{$accounts}</td>\n\t\t\t</tr>\n\t\t\t<input type='hidden' name='accid' value='0'>";
        } else {
            $paydetails = "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Bank Account</td>\n\t\t\t\t<td valign='center'>{$banks}</td>\n\t\t\t</tr>";
        }
    }
    //	$h1 = "";
    //	$h2 = "";
    $db = array("comp_pension" => $myEmp["comp_pension"], "emp_pension" => $myEmp["emp_pension"], "comp_provident" => $myEmp["comp_provident"], "emp_provident" => $myEmp["emp_provident"], "comp_uif" => $myEmp["comp_uif"], "emp_uif" => $myEmp["emp_uif"], "comp_other" => $myEmp["comp_other"], "emp_other" => $myEmp["emp_other"]);
    if (isset($basic_sal)) {
        $myEmp['basic_sal'] = $basic_sal;
        $myEmp['all_travel'] = $all_travel;
        $myEmp['bonus'] = $bonus;
        $myEmp['commission'] = $commission;
        $myEmp['abonus'] = $abonus;
        $myEmp['loaninstall'] = $loaninstall;
        $myEmp['comp_pension'] = $comp_pension;
        $myEmp['emp_pension'] = $emp_pension;
        $myEmp["comp_provident"] = $comp_provident;
        $myEmp["emp_provident"] = $emp_provident;
        //$myEmp["comp_uif"] = $comp_uif;
        //$myEmp["emp_uif"] = $emp_uif;
        $myEmp["comp_other"] = $comp_other;
        $myEmp["emp_other"] = $emp_other;
        $myEmp['comp_medical'] = $comp_medical;
        $myEmp['emp_medical'] = $emp_medical;
        $myEmp['comp_ret'] = $comp_ret;
        $myEmp['emp_ret'] = $emp_ret;
        //		$h1 = $novert;
        //		$h2 = $hovert;
    } else {
        //$day = date("d");
        //$mon = date("m");
        //$year = date("Y");
        if ($myEmp["payprd"] == "w" || $myEmp["payprd"] == "f") {
            $tmpmon = date("j");
            $daycount = date("t");
            $dayweek = date("D");
            if (strtolower($dayweek) == $myEmp["payprd_day"] && $date_day + 7 > $daycount) {
                $process_comp_deductions = true;
            } else {
                $process_comp_deductions = false;
            }
        } else {
            $process_comp_deductions = true;
        }
        $effective_basicsal = $myEmp["basic_sal"] * $multiplier;
        /* we only changing basic sal for non hourly employees,
        			because for hourly employees we change the hours ($mutli)  */
        if ($myEmp["saltyp"] != "h") {
            $myEmp["basic_sal"] *= $multiplier;
        }
        $myEmp["emp_pension"] = sprint($effective_basicsal * ($myEmp["emp_pension"] / 100));
        $myEmp["comp_pension"] = sprint($effective_basicsal * ($myEmp["comp_pension"] / 100));
        $myEmp["emp_provident"] = sprint($effective_basicsal * ($myEmp["emp_provident"] / 100));
        $myEmp["comp_provident"] = sprint($effective_basicsal * ($myEmp["comp_provident"] / 100));
        $myEmp["emp_medical"] = sprint($myEmp["emp_medical"] / $divisor);
        $myEmp["comp_medical"] = sprint($myEmp["comp_medical"] / $divisor);
        $myEmp["emp_ret"] = sprint($myEmp["emp_ret"] / $divisor);
        $myEmp["comp_ret"] = sprint($myEmp["comp_ret"] / $divisor);
        $myEmp["loaninstall"] = sprint($myEmp["loaninstall"] / $divisor);
        $myEmp["all_travel"] = sprint($myEmp["all_travel"] / $divisor);
        if (!isset($salyr)) {
            $salyr = "";
        }
        explodeDate($myEmp["loandate"], $loana_year, $loana_month, $loana_day);
        if ($loana_year > $salyr || $loana_year == $salyr && $loana_month > $MON) {
            $myEmp["loanint"] = 0;
            $myEmp["loaninstall"] = 0;
        }
    }
    /*	db_conn('cubit');
    	$sql = "SELECT value FROM settings WHERE constant='UIF_MAX'";
    	$percrslt = db_exec($sql);
    	$perc = pg_fetch_array($percrslt);
    	$uifmax = $perc['value'];
    
    	if ( $myEmp["emp_uif"] > $uifmax ) {
    	$myEmp["emp_uif"] = $uifmax;
    	}
    	if ( $myEmp["comp_uif"] > $uifmax ) {
    	$myEmp["comp_uif"] = $uifmax;
    	}
    	*/
    $rt = "<tr><th colspan='2'>Reimbursements</th></tr>";
    $Sl = "SELECT * FROM cubit.rbs ORDER BY name";
    $Ri = db_exec($Sl) or errDie("Unable to get data.");
    $i = 0;
    if (pg_num_rows($Ri) > 0) {
        while ($td = pg_fetch_array($Ri)) {
            if (!isset($rbsa[$td['id']])) {
                $rbsa[$td['id']] = "";
            }
            $rt .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><input type='hidden' name='rbs[{$td['id']}]' value='{$td['id']}'>{$td['name']}</td>\n\t\t\t\t\t<td>" . CUR . " " . $rbsa[$td['id']] . "<input type='hidden' size='10' name='rbsa[{$td['id']}]' value='" . $rbsa[$td['id']] . "' class=right></td>\n\t\t\t\t</tr>";
            $i++;
        }
    } else {
        $rt .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td colspan='2' align='center'>There are no reimbursements</td>\n\t\t\t</tr>";
    }
    if (!isset($annual) && $myEmp["sal_bonus_month"] == $MON) {
        $annual = $myEmp["sal_bonus"];
    } else {
        if (!isset($annual)) {
            $annual = 0;
        }
    }
    if ($myEmp["payprd"] == "m" || $myEmp["payprd"] == "d") {
        // count the amount of weekdays in this month
        $workdays = 0;
        for ($i = 1; $i <= date("t", mktime(0, 0, 0, $MON, 1, date("Y"))); ++$i) {
            $wd = date("w", mktime(0, 0, 0, $MON, $i, date("Y")));
            if ($wd != 0 && $wd != 6) {
                ++$workdays;
            }
        }
        // hours per day calculation
        $hpd = $myEmp["hpweek"] / 5;
        if (!isset($wh_total)) {
            $wh_total = $workdays * $hpd;
        }
        if (!isset($wh_actual)) {
            $wh_actual = $wh_total;
        }
    }
    if ($myEmp["payprd"] == "w") {
        if (!isset($wh_total)) {
            $wh_total = $myEmp["hpweek"];
        }
        if (!isset($wh_actual)) {
            $wh_actual = $wh_total;
        }
    }
    if ($myEmp["payprd"] == "f") {
        if (!isset($wh_total)) {
            $wh_total = $myEmp["hpweek"] * 2;
        }
        if (!isset($wh_actual)) {
            $wh_actual = $wh_total;
        }
    }
    $js_workhours = "\n\t\t<script>\n\t\t\tsf = document.getElementById('salfrm');\n\n\t\t\tf_sal\t\t= sf.elements['basic_sal'];\n\t\t\tf_whtot\t\t= sf.elements['wh_total'];\n\t\t\tf_whact\t\t= sf.elements['wh_actual'];\n\t\t\tf_cpension\t= sf.elements['comp_pension'];\n\t\t\tf_epension \t= sf.elements['emp_pension'];\n\t\t\tf_cprov\t\t= sf.elements['comp_provident'];\n\t\t\tf_eprov\t\t= sf.elements['emp_provident'];\n\t\t\t//f_cuif\t= sf.elements['comp_uif'];\n\t\t\t//f_euif\t= sf.elements['emp_uif'];\n\t\t\tf_cother\t= sf.elements['comp_other'];\n\t\t\tf_eother\t= sf.elements['emp_other'];\n\n\t\t\tdb_cpension\t= " . $db["comp_pension"] . ";\n\t\t\tdb_epension\t= " . $db["emp_pension"] . ";\n\t\t\tdb_cprov\t= " . $db["comp_provident"] . ";\n\t\t\tdb_eprov\t= " . $db["emp_provident"] . ";\n\t\t\t//db_cuif\t= " . $db["comp_uif"] . ";\n\t\t\t//db_euif\t= " . $db["emp_uif"] . ";\n\t\t\tdb_cother\t= " . $db["comp_other"] . ";\n\t\t\tdb_eother\t= " . $db["emp_other"] . ";\n\n\t\t\tval_sal \t\t= -1;\n\n\t\t\t// changing the workhours\n\t\t\tfunction workhours() {\n\t\t\t\tif ( val_sal < 0 ) val_sal = parseFloat(f_sal.value);\n\n\t\t\t\tval_whtot\t= parseFloat(f_whtot.value);\n\t\t\t\tval_whact\t= parseFloat(f_whact.value);\n\n\t\t\t\tif ( val_whtot >= val_whact ) {\n\t\t\t\t\tp = val_whact / val_whtot;\n\n\t\t\t\t\t// calculate the new basic salary\n\t\t\t\t\tx = val_sal * p;\n\t\t\t\t\tx = x.toFixed(2);\n\t\t\t\t\tf_sal.value = x;\n\n\t\t\t\t\t// calculate the new values\n\t\t\t\t\tval_cpension \t\t= x * db_cpension / 100;\n\t\t\t\t\tval_epension \t\t= x * db_epension / 100;\n\t\t\t\t\tval_cprov\t\t= x * db_cprov / 100;\n\t\t\t\t\tval_eprov\t\t= x * db_eprov / 100;\n\t\t\t\t\t//val_cuif\t\t= x * db_cuif / 100;\n\t\t\t\t\t//val_euif\t\t= x * db_euif / 100;\n\t\t\t\t\tval_cother\t\t= x * db_cother / 100;\n\t\t\t\t\tval_eother\t\t= x * db_eother / 100;\n\n\t\t\t\t\tval_cpension \t\t= val_cpension.toFixed(2);\n\t\t\t\t\tval_epension \t\t= val_epension.toFixed(2);\n\t\t\t\t\tval_cprov \t\t= val_cprov.toFixed(2);\n\t\t\t\t\tval_eprov\t\t= val_eprov.toFixed(2);\n\t\t\t\t\t//val_cuif\t\t= val_cuif.toFixed(2);\n\t\t\t\t\t//val_euif\t\t= val_euif.toFixed(2);\n\t\t\t\t\tval_cother\t\t= val_cother.toFixed(2);\n\t\t\t\t\tval_eother\t\t= val_eother.toFixed(2);\n\n\t\t\t\t\tf_cpension.value\t= val_cpension;\n\t\t\t\t\tf_epension.value \t= val_epension;\n\t\t\t\t\tf_cprov.value \t\t= val_cprov;\n\t\t\t\t\tf_eprov.value\t\t= val_eprov;\n\t\t\t\t\t//f_cuif.value\t\t= val_cuif;\n\t\t\t\t\t//f_euif.value\t\t= val_euif;\n\t\t\t\t\tf_cother.value\t\t= val_cother;\n\t\t\t\t\tf_eother.value\t\t= val_eother;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction changedfield() {\n\t\t\t\tval_whtot\t= parseFloat(f_whtot.value);\n\t\t\t\tval_whact\t= parseFloat(f_whact.value);\n\n\t\t\t\tp = val_whtot / val_whact;\n\n\t\t\t\tval_sal = parseFloat(f_sal.value) * p;\n\t\t\t\tval_sal = val_sal.toFixed(2);\n\t\t\t}\n\t\t</script>";
    $process = "\n\t\t<h3>Reverse Salary for {$myEmp['sname']}, {$myEmp['fnames']}</h3>\n\t\t<form action='" . SELF . "' method='POST' id='salfrm'>\n\t\t<table " . TMPL_tblDflts . ">\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'><input type='submit' value='Confirm &raquo;'></td>\n\t\t\t</tr>\n\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t<input type='hidden' name='empnum' value='{$empnum}'>\n\t\t\t<input type='hidden' name='MON' value='{$MON}'>\n\t\t\t<input type='hidden' name='date_day' value='{$date_day}' />\n\t\t\t<input type='hidden' name='date_month' value='{$date_month}' />\n\t\t\t<input type='hidden' name='date_year' value='{$date_year}' />\n\t\t\t<input type='hidden' name='day' value='{$date_day}' />\n\t\t\t<input type='hidden' name='mon' value='{$date_month}' />\n\t\t\t<input type='hidden' name='year' value='{$date_year}' />\n\t\t\t<input type='hidden' name='saltyp' value='{$myEmp['saltyp']}'>\n\t\t\t<input type='hidden' name='process_comp_deductions' value='{$process_comp_deductions}'>\n\t\t\t<input type='hidden' name='divisor' value='{$divisor}'>";
    if ($myEmp["saltyp"] == "h") {
        $process .= "<li class='err'>Please remember to enter the amount of hours you wish to reverse the salary for.</li>";
    }
    vsprint($myEmp["basic_sal"]);
    if (!isset($week)) {
        $week = "0";
    }
    if (!isset($pday)) {
        $pday = "0";
    }
    $weekpday = "\n\t\t<input type='hidden' name='week' value='{$week}'/>\n\t\t<input type='hidden' name='pday' value='{$pday}' />";
    $process .= "\n\t\t<tr>\n\t\t\t<th colspan='2'>Salary Details</th>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td nowrap>Basic salary</td>\n\t\t\t<td nowrap>" . CUR . " <input type='hidden' size='10' name='basic_sal' value='{$prevsal['salrate']}' class='right' onChange='changedfield();'> {$prevsal['salrate']} {$saltype} {$multi_show}</td>\n\t\t</tr>";
    if ($myEmp["payprd"] == "d") {
        $process .= "\n\t\t\t<input type='hidden' name='wh_total' value='1'>\n\t\t\t<input type='hidden' name='wh_actual' value='1'>";
    } else {
        $process .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Total Work Hours:</td>\n\t\t\t\t<td><input type='hidden' size='10' name='wh_total' value='{$wh_total}' class='right' onChange='workhours();'>{$wh_total}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Actual Hours Worked:</td>\n\t\t\t\t<td><input type='hidden' size='10' name='wh_actual' value='{$wh_actual}' class='right' onChange='workhours();'>{$wh_actual}</td>\n\t\t\t</tr>";
    }
    $process .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Normal Overtime</td>\n\t\t\t\t<td><input type='hidden' size='5' name='novert' value='{$h1}' class='right'>{$h1} Hrs</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Public Holiday Overtime</td>\n\t\t\t\t<td><input type='hidden' size='5' name='hovert' value='{$h2}' class='right'>{$h2} Hrs</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<!--<td>Special Bonus/Additional Salary</td>-->\n\t\t\t\t<td>Annual Bonus</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' name='bonus' value='0' class='right'><input type='hidden' name='abonus' value='{$prevsal['bonus']}' class='right'>{$prevsal['bonus']}</td>\n\t\t\t\t<!--<td rowspan='2' class='err'>An amount entered here (Special Bonus/Additional\n\t\t\t\t\tSalary) will be treated as a recurring bonus/payment per pay period for PAYE\n\t\t\t\t\tpurposes, the amount will not be treated as an annual payment. If the\n\t\t\t\t\tamount paid as a bonus is a once off/annual payment please use the\n\t\t\t\t\tBonus(Annual Payments) option. In other cases PAYE has to be manually\n\t\t\t\t\tadjusted <u>per directive</u> from SARS when processing salary.\n\t\t\t\t</td>-->\n\t\t\t</tr>\n\t\t\t<input type='hidden' name='annual' value='0' />\n\t\t\t<!--<tr class='" . bg_class() . "'>\n\t\t\t\t<td>Bonus(Annual/Once Off Payments)</td>\n\t\t\t\t<td nowrap>" . CUR . " <input type='text' size='10' name='annual' value='{$annual}' class='right'></td>\n\t\t\t</tr>-->\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Commission</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='commission' value='{$prevsal['comm']}' class='right'>{$prevsal['comm']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Low or interest-free loan</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size=10 name=loaninstall value='{$tm_loaninstall}' class=right>{$tm_loaninstall}</td>\n\t\t\t\t<input type='hidden' name='fringe_loan' value='{$fringe_loan}'>\n\t\t\t\t<input type='hidden' name='loanint' value='{$loanint}'>\n\t\t\t\t<input type='hidden' name='loaninstall_date' value='{$loaninstall_date}'>\n\t\t\t\t<input type='hidden' name='loaninstall_prd' value='{$loaninstall_prd}'>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Travel Allowance</td>\n\t\t\t\t<td>R <input type='hidden' size='10' name='all_travel' value='{$myEmp['all_travel']}' class='right'>{$myEmp['all_travel']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Pension: Company Contribution</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='comp_pension' value='{$prevsal['comp_pension']}' class='right'>{$prevsal['comp_pension']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Pension: Employee Deduction</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='emp_pension' value='{$prevsal['emp_pension']}' class='right'>{$prevsal['emp_pension']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Provident: Company Contribution</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='comp_provident' value='{$prevsal['comp_provident']}' class='right'>{$prevsal['comp_provident']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Provident: Employee Deduction</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='emp_provident' value='{$prevsal['emp_provident']}' class='right'>{$prevsal['emp_provident']}</td>\n\t\t\t</tr>\n\t\t\t<!--\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>UIF: Company Contribution</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='comp_uif' value='{$prevsal['comp_uif']}' class='right'>{$prevsal['comp_uif']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>UIF: Employee Deduction</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='emp_uif' value='{$prevsal['emp_uif']}' class='right'>{$prevsal['comp_uif']}</td>\n\t\t\t</tr>\n\t\t\t//-->\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Retirement Annuity: Company Contribution</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='comp_ret' value='{$prevsal['comp_ret']}' class='right'>{$prevsal['comp_ret']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Retirement Annuity: Employee Deduction</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='emp_ret' value='{$prevsal['emp_ret']}' class='right'>{$prevsal['emp_ret']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Medical Contribution: Company</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='comp_medical' value='{$prevsal['comp_medical']}' class='right'>{$prevsal['comp_medical']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Medical Contribution: Employee</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='emp_medical' value='{$prevsal['emp_medical']}' class='right'>{$prevsal['emp_medical']}</td>\n\t\t\t</tr>\n\t\t\t<input type='hidden' name='comp_other' value='0'>\n\t\t\t<input type='hidden' name='emp_other' value='0'>\n\t\t\t<!--\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Other: Company Contribution</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='comp_other' value='{$prevsal['comp_other']}' class='right'>{$prevsal['comp_other']}</td>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td nowrap>Other: Employee Deduction</td>\n\t\t\t\t<td>" . CUR . " <input type='hidden' size='10' name='emp_other' value='{$prevsal['emp_other']}' class='right'>{$prevsal['emp_other']}</td>\n\t\t\t</tr>\n\t\t\t//-->\n\t\t\t{$paydetails}\n\t\t\t<input type='hidden' name='mpaye' value='1' />\n\t\t\t<input type='hidden' size=10 value='" . sprint($prevsal["paye"]) . "' name='mpaye_amount' />\n\t\t\t<tr><th colspan='2'>Fringe Benefits</th></tr>\n\t\t\t{$fringes}\n\t\t\t<tr><th colspan='2'>Allowances</th></tr>\n\t\t\t{$allowances}\n\t\t\t<tr><th colspan='2'>Subsistence Allowances</th></tr>\n\t\t\t{$subsistence}\n\t\t\t<tr><th colspan='2'>Deductions</th></tr>\n\t\t\t{$deductions}\n\t\t\t<tr><th colspan='2'>Reimbursements</th></tr>\n\t\t\t{$rt}\n\t\t\t{$weekpday}\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'><input type='submit' value='Confirm &raquo;'></td>\n\t\t\t</tr>\n\t\t\t{$js_workhours}\n\t\t</table>\n\t\t</form>";
    return $process;
}
コード例 #3
0
function enter($_POST, $err = "")
{
    extract($_POST);
    global $PRDMON, $MONPRD;
    $salyr = getYearOfEmpMon($month);
    $curyr = getActiveFinYear();
    if ($salyr > $curyr || $salyr == $curyr && $month > $PRDMON[12]) {
        header("Location: ../admin-employee-view.php?err=Cannot do transaction in future financial year. You need to close your year first before you can continue.&" . array2get($_POST));
        exit;
    }
    if (!isset($emps) || !is_array($emps)) {
        header("Location: ../admin-employee-view.php?err=Please select at least one employee.");
        exit;
    }
    // first check if all the selected employees with EFT pay types have banking information
    // and their id numbers are valid
    $emp_err = array();
    $emp_nam = array();
    foreach ($emps as $e_empnum => $e_val) {
        /* previously selected to remove this employee from process */
        if (isset($rememp[$e_empnum])) {
            unset($emps[$e_empnum]);
            continue;
        }
        $sql = "\n\t\t\tSELECT fnames, sname, paytype, bankname, bankaccno, idnum, flag, hiredate, payprd \n\t\t\tFROM employees \n\t\t\tWHERE div='" . USER_DIV . "' AND empnum='{$e_empnum}'";
        $rslt = db_exec($sql) or errDie("error checking employee payment types.");
        $e_info = pg_fetch_array($rslt);
        /* if the employee's pay period doesn't match the selected button, don't
        			include employee in checklist */
        if (isset($d) && $e_info["payprd"] != "d") {
            continue;
        } else {
            if (isset($w) && $e_info["payprd"] != "w") {
                continue;
            } else {
                if (isset($b) && $e_info["payprd"] != "f") {
                    continue;
                } else {
                    if (isset($m) && $e_info["payprd"] != "m") {
                        continue;
                    }
                }
            }
        }
        $e_empnum += 0;
        $emp_err[$e_empnum] = 0;
        $emp_nam[$e_empnum] = "{$e_info['fnames']} {$e_info['sname']}";
        if ($e_info["paytype"] == "EFT" && (empty($e_info["bankname"]) || empty($e_info["bankaccno"]))) {
            $emp_err[$e_empnum] |= 0x1;
        }
        if (!empty($e_info["idnum"])) {
            $bd_year = substr($e_info["idnum"], 0, 2);
            $bd_month = substr($e_info["idnum"], 2, 2);
            $bd_day = substr($e_info["idnum"], 4, 2);
            if (!checkdate($bd_month, $bd_day, $bd_year)) {
                $emp_err[$e_empnum] |= 0x2;
            }
        }
        if ($e_info["flag"] == "2.5EMP") {
            $emp_err[$e_empnum] |= 0x4;
            $special_error = 0x1;
        }
        if ($e_info["flag"] == "272PREVEMP") {
            $emp_err[$e_empnum] |= 0x4;
            $special_error = 0x2;
        }
        /* check hiredate after process date */
        explodeDate($e_info["hiredate"], $hd_year, $hd_month, $hd_day);
        $MONempyear = getYearOfEmpMon($month);
        if ($hd_year > $MONempyear || $hd_year == $MONempyear && $hd_month > $month) {
            $emp_err[$e_empnum] |= 0x8;
        }
    }
    // list the employee information problems
    if (array_sum($emp_err) > 0) {
        $out = "\n\t\t\t<h3>Batch Salaries</h3>\n\t\t\t\t<form method='POST' action='" . SELF . "'>";
        foreach ($_POST as $key => $value) {
            if (is_array($value)) {
                foreach ($value as $akey => $avalue) {
                    $out .= "<input type='hidden' name='{$key}" . "[{$akey}]' value='{$avalue}'>";
                }
            } else {
                $out .= "<input type='hidden' name='{$key}' value='{$value}'>";
            }
        }
        if (isset($special_error)) {
            switch ($special_error) {
                case 0x1:
                    $out .= "\n\t\t\t\t\t<li class='err'><strong>NOTICE:</strong> Due to changes in employee functionality from Cubit 2.5 to Cubit 2.6 <br>\n\t\t\t\t\t\tyou need to edit your employees' salary/deduction/allowance information</li>\n\t\t\t\t\t\t<br />";
                    break;
                case 0x2:
                    $out .= "\n\t\t\t\t\t<li class='err'><strong>NOTICE:</strong> Due to the changes from Cubit 2.71 to Cubit 2.72 you should first update your employee's\n\t\t\t\t\t\tprevious employment information in the employee edit form.</li>\n\t\t\t\t\t\t<br />";
                    break;
            }
        }
        $out .= "\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='3' class='err'>There are problems with the following employees.<br />\n\t\t\t\t\t\tEdit their information or to remove an employee from the process select\n\t\t\t\t\t\tthe checkbox next to employee's name.<br /><br />\n\t\t\t\t\t\tClick the 'Done' button when ready to proceed.</td>\n\t\t\t\t</tr>";
        $out .= "\n\t\t\t<tr>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t<th>Name</th>\n\t\t\t\t<th>Message</th>\n\t\t\t</tr>";
        $i = 0;
        foreach ($emp_err as $e_empnum => $err_val) {
            $out .= "\n\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t<td><input type='checkbox' name='rememp[{$e_empnum}]' /></td>\n\t\t\t\t\t<th>{$emp_nam[$e_empnum]}</td>";
            if ($err_val & 0x4) {
                $specerr_msg = "(See above notice for this employee)";
            } else {
                $specerr_msg = "";
            }
            if ($err_val & 0x1 && $err_val & 0x2) {
                $out .= "<td class='err'>Banking info and ID number {$specerr_msg}</td>";
            } else {
                if ($err_val & 0x1) {
                    $out .= "<td class='err'>Banking info {$specerr_msg}</td>";
                } else {
                    if ($err_val & 0x2) {
                        $out .= "<td class='err'>ID number {$specerr_msg}</td>";
                    } else {
                        if ($err_val & 0x8) {
                            $out .= "<td class='err'>Employee was not employed in the period\n\t\t\t\t\trequested {$specerr_msg}</td>";
                        } else {
                            $out .= "<td>Employee Info Correct {$specerr_msg}</td>";
                        }
                    }
                }
            }
            if ($err_val && !($err_val == 0x8)) {
                $out .= "<td class='err'><a target='_blank' href='../admin-employee-edit.php?empnum={$e_empnum}'>Edit Employee</a></td>";
            }
            $out .= "</tr>";
        }
        $out .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='3' align='right'><input type='submit' value='Done' /></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</form>";
        return $out;
    }
    if (!isset($date_day)) {
        $date_day = date("d");
        $date_month = date("m");
        $date_year = date("Y");
    }
    if (!isset($date_month)) {
        $date_month = date("m");
    }
    /* make week/day selections */
    if (isset($w)) {
        $weekends = "";
        $weeks = "<select name='week'>";
        $stdate = mktime(0, 0, 0, $month, 1, DATE_YEAR);
        $endate = mktime(0, 0, 0, $month, DATE_DAYS, DATE_YEAR);
        $i = 1;
        while ($stdate <= $endate) {
            if (date("w", $stdate) == 5) {
                $weekends .= "<input type='hidden' name='weekends[{$i}]' value='" . date("j", $stdate) . "' />";
                if (isset($week) && $week == $i) {
                    $sel = "selected";
                } else {
                    $sel = "";
                }
                $weeks .= "<option {$sel} value='{$i}'>Week {$i} (" . date("j M", $stdate) . ")</option>";
                ++$i;
            }
            /* next day */
            $stdate += 24 * 60 * 60;
        }
        /*<option value='1'>Week 1</option>
        		<option value='2'>Week 2</option>
        		<option value='3'>Week 3</option>
        		<option value='4'>Week 4</option>
        		<option value='5'>Week 5</option>*/
        $weeks .= "</select>";
        $weeks = "\n\t\t\t<th>Week</th>\n\t\t\t<td>{$weekends}{$weeks}</td>\n\t\t\t<td class='err'>Period salaries are processed for</td>";
    } else {
        if (isset($b)) {
            $weekends = "";
            $weeks = "<select name='week'>";
            $i = 1;
            /* find first friday of tax year */
            $stdate = mktime(0, 0, 0, 3, 1, getYearOfEmpMon(3));
            while (date("w", $stdate) != 5) {
                $stdate = mktime(0, 0, 0, 3, ++$i, getYearOfEmpMon(3));
            }
            // hack: go one week back so the +14 increases are easier
            $stdate -= 7 * 24 * 3600;
            /* end on the last day of the selected month */
            $endate = mktime(0, 0, 0, $month + 1, 0, getYearOfEmpMon($month));
            /* count weeks from start of tax year */
            $i = 1;
            $c = 0;
            while ($stdate <= $endate) {
                if (date("m", $stdate) == $month && date("Y", $stdate) == getYearOfEmpMon($month)) {
                    $c += 2;
                    $cd = $c - 1 . "-{$c}";
                    $weekends .= "<input type='hidden' name='weekends[{$i}]' value='" . date("j", $stdate) . "' />";
                    if (isset($week) && $week == $i) {
                        $sel = "selected";
                    } else {
                        $sel = "";
                    }
                    $weeks .= "<option {$sel} value='{$i}'>Week {$cd} (" . date("j M", $stdate) . ")</option>";
                    ++$i;
                }
                /* next day */
                $stdate += 24 * 60 * 60 * 14;
            }
            /*<option value='1'>Week 1</option>
            		<option value='2'>Week 2</option>
            		<option value='3'>Week 3</option>
            		<option value='4'>Week 4</option>
            		<option value='5'>Week 5</option>*/
            $weeks .= "\n\t\t</select>";
            $weeks = "\n\t\t\t<th>Week</th>\n\t\t\t<td>{$weekends}{$weeks}</td>\n\t\t\t<td class='err'>Period salaries are processed for</td>";
        } else {
            if (isset($d)) {
                $x = date("t", mktime(0, 0, 0, $month, 1, getYearOfFinMon($month)));
                $MONstr = getMonthNameS($month);
                if (!isset($proc_day)) {
                    $proc_day = 0;
                }
                if (!isset($pday)) {
                    $pday = $proc_day;
                }
                $days = "<select name='pday'>";
                for ($i = 1; $i <= $x; ++$i) {
                    if ($i == $pday) {
                        $sel = "selected='t'";
                    } else {
                        $sel = "";
                    }
                    $days .= "<option {$sel} value='{$i}'>{$i} {$MONstr}</option>";
                }
                $days .= "</select>";
                $weeks = "\n\t\t\t<th>Day for Payment</th>\n\t\t\t<td>{$days}</td>\n\t\t\t<td class='err'>Period salaries are processed for</td>";
            } else {
                $weeks = "<input type='hidden' name='week' value='0'>";
            }
        }
    }
    /* payprd message */
    if (isset($d)) {
        $cpayprd = "d";
    } else {
        if (isset($w)) {
            $cpayprd = "w";
        } else {
            if (isset($b)) {
                $cpayprd = "f";
            } else {
                if (isset($m)) {
                    $cpayprd = "m";
                } else {
                    invalid_use("Invalid payment type selected.");
                }
            }
        }
    }
    $dispmsg = getCSetting("EMP_SALMSG");
    if (strpos($dispmsg, $cpayprd) === false) {
        $payprd_msg_ch = "";
    } else {
        $payprd_msg_ch = "checked='t'";
    }
    $payprd_msg = get_payprdmsg($cpayprd);
    /* print payslip on/off */
    $printslip = getCSetting("EMP_PRINTSLIP");
    $out = "\n\t\t<script>\n\t\t\tfunction update_salmsg(obj) {\n\t\t\t\tajaxRequest('payprdmsg.php', 'payprd_msg', AJAX_SET,'payprd={$cpayprd}&newval=' + obj.checked);\n\t\t\t}\n\t\t</script>\n\t\t<form action='" . SELF . "' method='POST' id='salfrm'>\n\t\t\t<input type='hidden' name='key' value='confirm' />\n\t\t\t<input type='hidden' name='month' value='{$month}' />\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<td colspan='9'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td><h3>Processing Batch Salaries</h3></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<li class='err'>NOTE that Cubit is configured to compute employees' tax\n\t\t\t\t\t\t\t\t\tduring the employees' tax year that<br />\n\t\t\t\t\t\t\t\t\tstarts in March and ends in February,\n\t\t\t\t\t\t\t\t\tirrespective of the employer's financial year end.</li>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td id='payprd_msg' colspan='2'>{$payprd_msg}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th align='right'>Salary Help Message: <input type='checkbox' onclick='update_salmsg(this);' name='payprd_dispmsg' {$payprd_msg_ch} /></th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='6' valign='top' rowspan='2'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t{$weeks}\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<th>Processing Date:</th>\n\t\t\t\t\t\t<td nowrap>" . mkDateSelect("date", $date_year, $date_month, $date_day) . "</td>\n\t\t\t\t\t\t<td colspan='2' class='err'>Date used by Cubit for the ledgers.</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<th nowrap='t'>Print Salary Advice</th\n\t\t\t\t\t\t<td>\n\t\t\t\t\t\t<select name='printslip'>\n\t\t\t\t\t\t\t<option value='y' " . ($printslip != "n" ? "selected='t'" : "") . ">Yes</option>\n\t\t\t\t\t\t\t<option value='n' " . ($printslip == "n" ? "selected='t'" : "") . ">No</option>\n\t\t\t\t\t\t</select>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td colspan='3' align='right' nowrap='t'>\n\t\t\t\t\t<input type='submit' name='btn_back' value='&laquo; Correction'>\n\t\t\t\t\t<input type='submit' value='Confirm &raquo;'>\n\t\t\t\t</td>\n\t\t\t\t<td colspan='10' align='right' nowrap='t'>\n\t\t\t\t\t<input type='submit' name='btn_back' value='&laquo; Correction'>\n\t\t\t\t\t<input type='submit' value='Confirm &raquo;'>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<!--<td align='center' colspan='3' class='err'>An amount entered here (Special Bonus/Additional\n\t\t\t\t\tSalary) will be treated as a recurring bonus/payment per pay period for PAYE\n\t\t\t\t\tpurposes, the amount will not be treated as an annual payment. If the\n\t\t\t\t\tamount paid as a bonus is a once off/annual payment please use the\n\t\t\t\t\tBonus(Annual Payments) option. In other cases PAYE has to be manually\n\t\t\t\t\tadjusted <u>per directive</u> from SARS when processing salary.</td>-->\n\t\t\t\t<td colspan='3'>&nbsp;</td>\n\t\t\t\t<td colspan='3' class='err'><strong>LOAN NOTE:</strong><br />In the event that the employee repays more than the installment -\n\t\t\t\t\tenter that amount, plus interest that is remitted, in the \"Loan Repayment\" field below.\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='10'>{$err}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Nr.</th>\n\t\t\t\t<th>Name</th>\n\t\t\t\t<th>Remuneration</th>";
    if (!isset($d)) {
        $out .= "\n\t\t\t<th>Total Work Hours</th>\n\t\t\t<th>Actual Hours Worked</th>";
    }
    $out .= "\n\t\t\t<th>Normal Overtime</th>\n\t\t\t<th>Public Holiday Overtime</th>\n\t\t\t<th>Annual Bonus</th>\n\t\t\t<!--\n\t\t\t<th>Special Bonus/Additional Salary</th>\n\t\t\t<th>Annual/Once Off Bonus</th>\n\t\t\t-->\n\t\t\t<th>Commission</th>\n\t\t\t<th>Travel Allowance</th>\n\t\t\t<th>Loan Repayment</th>\n\t\t\t<th>Pension: Company Contribution</th>\n\t\t\t<th>Pension: Employee Deduction</th>\n\t\t\t<th>Provident: Company Contribution</th>\n\t\t\t<th>Provident: Employee Deduction</th>\n\t\t\t<!--\n\t\t\t<th>UIF: Company Contribution</th>\n\t\t\t<th>UIF: Employee Deduction</th>\n\t\t\t//-->\n\t\t\t<th>Retirement Annuity: Company Contribution</th>\n\t\t\t<th>Retirement Annuity: Employee Deduction</th>\n\t\t\t<th>Medical Contribution: Company</th>\n\t\t\t<th>Medical Contribution: Employee</th>\n\t\t\t<!--\n\t\t\t<th>Other: Company Contribution</th>\n\t\t\t<th>Other: Employee Deduction</th>\n\t\t\t//-->\n\t\t\t<th>Method of Payment</th>\n\t \t\t<th>Override PAYE</th>\n\t \t\t<th>Fringe Ben.</th>\n\t \t\t<th>Allowances</th>\n\t \t\t<th>Subsistence</th>\n\t \t\t<th>Deductions</th>\n\t \t\t<th>Reimbursements</th>\n\t\t</tr>";
    db_conn('cubit');
    $i = 0;
    $Sl = "SELECT * FROM employees WHERE div='" . USER_DIV . "' ORDER BY sname,fnames";
    $Ri = db_exec($Sl) or errDie("Unable to get data.");
    $jsbonus_clear = array();
    $uif_calc = array();
    $jsbonus = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array(), 6 => array(), 7 => array(), 8 => array(), 9 => array(), 10 => array(), 11 => array(), 12 => array());
    $js_workhours_fields = "";
    $subs_int = false;
    // whether there are internation subsistence allowances
    $counter = 0;
    while ($data = pg_fetch_array($Ri)) {
        if ($counter == 8) {
            #show headings...
            $out .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Nr.</th>\n\t\t\t\t\t<th>Name</th>\n\t\t\t\t\t<th>Remuneration</th>";
            if (!isset($d)) {
                $out .= "\n\t\t\t\t\t<th>Total Work Hours</th>\n\t\t\t\t\t<th>Actual Hours Worked</th>";
            }
            $out .= "\n\t\t\t\t\t<th>Normal Overtime</th>\n\t\t\t\t\t<th>Public Holiday Overtime</th>\n\t\t\t\t\t<th>Annual Bonus</th>\n\t\t\t\t\t<!--\n\t\t\t\t\t<th>Special Bonus/Additional Salary</th>\n\t\t\t\t\t<th>Annual/Once Off Bonus</th>\n\t\t\t\t\t-->\n\t\t\t\t\t<th>Commission</th>\n\t\t\t\t\t<th>Travel Allowance</th>\n\t\t\t\t\t<th>Loan Repayment</th>\n\t\t\t\t\t<th>Pension: Company Contribution</th>\n\t\t\t\t\t<th>Pension: Employee Deduction</th>\n\t\t\t\t\t<th>Provident: Company Contribution</th>\n\t\t\t\t\t<th>Provident: Employee Deduction</th>\n\t\t\t\t\t<!--\n\t\t\t\t\t<th>UIF: Company Contribution</th>\n\t\t\t\t\t<th>UIF: Employee Deduction</th>\n\t\t\t\t\t//-->\n\t\t\t\t\t<th>Retirement Annuity: Company Contribution</th>\n\t\t\t\t\t<th>Retirement Annuity: Employee Deduction</th>\n\t\t\t\t\t<th>Medical Contribution: Company</th>\n\t\t\t\t\t<th>Medical Contribution: Employee</th>\n\t\t\t\t\t<!--\n\t\t\t\t\t<th>Other: Company Contribution</th>\n\t\t\t\t\t<th>Other: Employee Deduction</th>\n\t\t\t\t\t//-->\n\t\t\t\t\t<th>Method of Payment</th>\n\t\t\t \t\t<th>Override PAYE</th>\n\t\t\t \t\t<th>Fringe Ben.</th>\n\t\t\t \t\t<th>Allowances</th>\n\t\t\t \t\t<th>Subsistence</th>\n\t\t\t \t\t<th>Deductions</th>\n\t\t\t \t\t<th>Reimbursements</th>\n\t\t\t\t</tr>";
            $counter = 0;
        }
        $counter++;
        if (!isset($emps[$data['empnum']])) {
            continue;
        }
        $bgcolor = bgcolorc($i);
        $send = "";
        $grossal = $data["basic_sal"] + $data["commission"] + $data["all_travel"] / 2 + $data["bonus"];
        if (isset($d)) {
            $send = "<input type='hidden' name='d' value=''>";
            if ($data['payprd'] != "d") {
                continue;
            }
        } elseif (isset($w)) {
            $send = "<input type='hidden' name='w' value=''>";
            if ($data['payprd'] != "w") {
                continue;
            }
        } elseif (isset($m)) {
            $send = "<input type='hidden' name='m' value=''>";
            if ($data['payprd'] != "m") {
                continue;
            }
        } elseif (isset($b)) {
            $send = "<input type='hidden' name='b' value=''>";
            if ($data['payprd'] != "f") {
                continue;
            }
        } else {
            continue;
        }
        /* set employee id */
        $id = $data['empnum'];
        /* calculate basic salary divisors and multipliers
         * used for calculating deductions/allowances/etc. when the
         * salary type and payment period differs in length
         */
        switch ($data["saltyp"]) {
            case "h":
                $divisor = 1;
                switch ($data["payprd"]) {
                    case "d":
                        $multiplier = $data["hpweek"] / 5;
                        break;
                    case "w":
                        $multiplier = $data["hpweek"];
                        break;
                    case "f":
                        $multiplier = $data["hpweek"] * 2;
                        break;
                    case "m":
                        $multiplier = $data["hpweek"] * 52 / 12;
                        break;
                }
                break;
            case "m":
                $divisor = 1;
                switch ($data["payprd"]) {
                    case "d":
                        $multiplier = 12 / (5 * 52);
                        break;
                    case "w":
                        $multiplier = 12 / 52;
                        break;
                    case "f":
                        $multiplier = 12 / 26;
                        break;
                    case "m":
                        $multiplier = 1;
                        break;
                }
                break;
            case "w":
                $divisor = 52 / 12;
                switch ($data["payprd"]) {
                    case "d":
                        $multiplier = 1 / 5;
                        break;
                    case "w":
                        $multiplier = 1;
                        break;
                    case "f":
                        $multiplier = 2;
                        break;
                    case "m":
                        $multiplier = 52 / 12;
                        break;
                }
                break;
            case "f":
                $divisor = 26 / 12;
                switch ($data["payprd"]) {
                    case "d":
                        $multiplier = 1 / 10;
                        break;
                    case "w":
                        $multiplier = 1 / 2;
                        break;
                    case "f":
                        $multiplier = 1;
                        break;
                    case "m":
                        $multiplier = 26 / 12;
                        break;
                }
                break;
        }
        $bon_month = round($data["sal_bonus_month"]);
        $jsbonus_clear[] = "document.getElementById('salfrm').elements['bonus[{$id}]'].value='0.00';";
        $jsbonus[$bon_month][] = "document.getElementById('salfrm').elements['bonus[{$id}]'].value = '{$data['sal_bonus']}';";
        /*		$uif_calc[] = "
        			tmp_calc = parseFloat(document.getElementById('salfrm').elements['basic_sal[$id]'].value)
        				+ parseFloat(document.getElementById('salfrm').elements['annual[$id]'].value)
        				+ parseFloat(document.getElementById('salfrm').elements['all_travel[$id]'].value);
        			tmp_calc_emp = tmp_calc * $data[emp_uif] / 100;
        			tmp_calc_comp = tmp_calc * $data[comp_uif] / 100;
        			tmp_calc_emp = tmp_calc_emp.toFixed(2);
        			tmp_calc_comp = tmp_calc_comp.toFixed(2);
        			document.getElementById('salfrm').elements['emp_uif[$id]'].value = tmp_calc_emp;
        			document.getElementById('salfrm').elements['comp_uif[$id]'].value = tmp_calc_comp;";*/
        $db = array("comp_pension" => $data["comp_pension"], "emp_pension" => $data["emp_pension"], "comp_provident" => $data["comp_provident"], "emp_provident" => $data["emp_provident"], "comp_uif" => $data["comp_uif"], "emp_uif" => $data["emp_uif"], "comp_other" => $data["comp_other"], "emp_other" => $data["emp_other"]);
        if (isset($basic_sal[$id])) {
            $data['basic_sal'] = $basic_sal[$id];
            $data['bonus'] = $bonus[$id];
            $data['commission'] = $commission[$id];
            $date['abonus'] = $abonus[$id];
            $data['all_travel'] = $all_travel[$id];
            $data['loaninstall'] = $loaninstall[$id];
            $data['comp_pension'] = $comp_pension[$id];
            $data['emp_pension'] = $emp_pension[$id];
            $data['comp_provident'] = $comp_provident[$id];
            $data['emp_provident'] = $emp_provident[$id];
            //$data['comp_uif']=$comp_uif[$id];
            //$data['emp_uif']=$emp_uif[$id];
            $data['comp_ret'] = $comp_ret[$id];
            $data['emp_ret'] = $emp_ret[$id];
            $data['comp_medical'] = $comp_medical[$id];
            $data['emp_medical'] = $emp_medical[$id];
            $data['comp_other'] = $comp_other[$id];
            $data['emp_other'] = $emp_other[$id];
        } else {
            if ($data["sal_bonus_month"] == $month) {
                $annual[$id] = sprint($data["sal_bonus"]);
            } else {
                $annual[$id] = "0.00";
            }
            $novert[$id] = "";
            $hovert[$id] = "";
            $mpaye_amount[$id] = "";
            if ($data["payprd"] == "w" || $data["payprd"] == "f") {
                $tmpmon = date("j");
                $daycount = date("t");
                $dayweek = date("D");
                if (strtolower($dayweek) == $data["payprd_day"] && $date_day + 7 > $daycount) {
                    $process_comp_deductions = true;
                } else {
                    $process_comp_deductions = false;
                }
            } else {
                $process_comp_deductions = true;
            }
            //$data["emp_uif"] = sprint(($data["basic_sal"] + $data["all_travel"]) * ($data["emp_uif"]/100));
            $effective_basicsal = $data["basic_sal"] * $multiplier;
            /* we only changing basic sal for non hourly employees,
            			because for hourly employees we change the hours ($mutli)  */
            if ($data["saltyp"] != "h") {
                $data["basic_sal"] *= $multiplier;
            }
            if ($data["loaninstall"] > $data["loanamt"]) {
                $data["loaninstall"] = $data["loanamt"];
            }
            $data["comp_pension"] = sprint($effective_basicsal * ($data["comp_pension"] / 100));
            $data["comp_provident"] = sprint($effective_basicsal * ($data["comp_provident"] / 100));
            $data["emp_pension"] = sprint($effective_basicsal * ($data["emp_pension"] / 100));
            $data["emp_provident"] = sprint($effective_basicsal * ($data["emp_provident"] / 100));
            $data["emp_medical"] = sprint($data["emp_medical"] / $divisor);
            $data["comp_medical"] = sprint($data["comp_medical"] / $divisor);
            $data["emp_ret"] = sprint($data["emp_ret"] / $divisor);
            $data["comp_ret"] = sprint($data["comp_ret"] / $divisor);
            $data["loaninstall"] = sprint($data["loaninstall"] / $divisor);
            $data["all_travel"] = sprint($data["all_travel"] / $divisor);
            explodeDate($data["loandate"], $loana_year, $loana_month, $loana_day);
            if ($loana_year > $salyr || $loana_year == $salyr && $loana_month > $month) {
                $data["loanint"] = 0;
                $data["loaninstall"] = 0;
            }
        }
        if ($data['paytype'] == "Cash") {
            $paydetails = "Cash\n\t\t\t<input type='hidden' name='accid[{$id}]' value='0'>";
        } elseif ($data['paytype'] == "Ledger Account") {
            db_conn('core');
            $Sl = "SELECT accid,accname FROM accounts ORDER BY accname";
            $Rl = db_exec($Sl);
            $accounts = "<select name='account[{$id}]'>";
            while ($ad = pg_fetch_array($Rl)) {
                if (isset($account[$id]) && $account[$id] == $ad['accid']) {
                    $sel = "selected";
                } else {
                    $sel = "";
                }
                $accounts .= "<option value='{$ad['accid']}' {$sel}>{$ad['accname']}</option>";
            }
            $accounts .= "</select>";
            $paydetails = "{$accounts}\n\t\t\t\t<input type='hidden' name='accid[{$id}]' value='0'>";
        } else {
            db_conn('cubit');
            $Sl = "SELECT * FROM bankacct WHERE btype != 'int' AND div = '" . USER_DIV . "' ORDER BY accname ASC";
            $Ry = db_exec($Sl) or errDie("Unable to get bank account.");
            if (pg_numrows($Ry) < 1) {
                return "<li class='err'> There are no bank accounts found in Cubit.\n\t\t\t\t<p><input type='button' onClick='JavaScript:history.back();' value='&laquo; Correct Selection'>";
            }
            $banks = "<select name='accid[{$id}]'>";
            while ($acc = pg_fetch_array($Ry)) {
                $banks .= "<option value='{$acc['bankid']}'>{$acc['accname']} ({$acc['acctype']})</option>";
            }
            $banks .= "</select>";
            $paydetails = "{$banks}";
        }
        # fringe benefits
        $i = 0;
        db_conn("cubit");
        $sql = "SELECT * FROM fringebens WHERE div = '" . USER_DIV . "' ORDER BY fringeben";
        $rslt = db_exec($sql) or errDie("Unable to select fringe benefits from database.");
        if (pg_num_rows($rslt) < 1) {
            $fringes = "<table " . TMPL_tblDflts . ">";
            $fringes .= "<tr><td class='" . bg_class() . "' colspan='2' align='center'>None found in database.</td></tr>";
            $fringes .= "</table>";
        } else {
            $fringes = "<table " . TMPL_tblDflts . ">";
            while ($myFringe = pg_fetch_array($rslt)) {
                # check if employee has allowance
                $sql = "SELECT * FROM empfringe WHERE fringeid='{$myFringe['id']}' AND empnum='{$data['empnum']}' AND div = '" . USER_DIV . "'";
                $empRslt = db_exec($sql) or errDie("Unable to retrieve fringe benefit info from database.");
                if (pg_numrows($empRslt) > 0) {
                    $empFringe = pg_fetch_array($empRslt);
                    if (substr($empFringe["type"], 0, 4) == "Perc") {
                        $empFringe["amount"] = sprint($data["basic_sal"] * ($empFringe["amount"] / 100) / $divisor);
                    } else {
                        $empFringe['amount'] = sprint($empFringe['amount'] / $divisor);
                    }
                    $grossal += $empFringe["amount"];
                    $tmp_fringeaccs = $empFringe["accid"];
                    $tmp_fringebens = $empFringe["amount"];
                } else {
                    $tmp_fringeaccs = "0";
                    $tmp_fringebens = "0.00";
                }
                $fringes .= "\n\t\t\t\t\t<input type='hidden' name='fringeaccs[{$id}][]' value='{$tmp_fringeaccs}'>\n\t\t\t\t\t<input type='hidden' name='fringeid[{$id}][]' value='{$myFringe['id']}'>\n\t\t\t\t\t<input type='hidden' name='fringename[{$id}][]' value='{$myFringe['fringeben']}'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>{$myFringe['fringeben']}</td>\n\t\t\t\t\t\t<td>" . CUR . "</td>\n\t\t\t\t\t\t<td><input type='text' size='10' name='fringebens[{$id}][]' value='{$tmp_fringebens}'></td>\n\t\t\t\t\t</tr>";
                $i++;
            }
            $fringes .= "</table>";
        }
        # get allowances
        $i = 0;
        db_conn('cubit');
        $sql = "SELECT * FROM allowances WHERE div = '" . USER_DIV . "' ORDER BY allowance";
        $allowRslt = db_exec($sql) or errDie("Unable to select allowances from database.");
        if (pg_numrows($allowRslt) < 1) {
            $allowances = "<table " . TMPL_tblDflts . ">";
            $allowances .= "<tr><td>None</td></tr>";
            $allowances .= "</table>";
        } else {
            $allowances = "<table " . TMPL_tblDflts . ">";
            while ($myAllow = pg_fetch_array($allowRslt)) {
                # check if employee has allowance
                $sql = "SELECT * FROM empallow WHERE allowid='{$myAllow['id']}' AND empnum='{$data['empnum']}' AND div = '" . USER_DIV . "'";
                $empAllowRslt = db_exec($sql) or errDie("Unable to select allowance info from database.");
                if (pg_numrows($empAllowRslt) > 0) {
                    $dataAllow = pg_fetch_array($empAllowRslt);
                    $dataAllow['amount'] = sprint($dataAllow['amount'] / $divisor);
                    $grossal += $dataAllow["amount"];
                    $tmp_allowaccs = $dataAllow["accid"];
                    $tmp_allowances = $dataAllow["amount"];
                } else {
                    $tmp_allowaccs = $myAllow["accid"];
                    $tmp_allowances = "0.00";
                }
                $allowances .= "\n\t\t\t\t\t<input type='hidden' name='allowid[{$id}][]' value='{$myAllow['id']}'>\n\t\t\t\t\t<input type='hidden' name='allowname[{$id}][]' value='{$myAllow['allowance']}'>\n\t\t\t\t\t<input type='hidden' name='allowtax[{$id}][]' value='{$myAllow['add']}'>\n\t\t\t\t\t<input type='hidden' name='allowaccs[{$id}][]' value='{$tmp_allowaccs}'>\n\t\t\t\t\t<tr><td>{$myAllow['allowance']}</td>\n\t\t\t\t\t\t<td>" . CUR . "</td>\n\t\t\t\t\t\t<td><input type='text' size='10' name='allowances[{$id}][]' value='{$tmp_allowances}'></td>\n\t\t\t\t\t</tr>";
                $i++;
            }
            $allowances .= "</table>";
        }
        $subsistence = "";
        $subslst = new dbSelect("subsistence", "cubit", array("where" => "div='" . USER_DIV . "'", "order" => "name"));
        $subslst->run();
        if ($subslst->num_rows() > 0) {
            $i = 0;
            $subsistence .= "\n\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Name</th>\n\t\t\t\t\t\t<th>Amount</th>\n\t\t\t\t\t\t<th>Days</th>\n\t\t\t\t\t</tr>";
            $empsubs = new dbSelect("emp_subsistence", "cubit");
            while ($subs = $subslst->fetch_array()) {
                $sid = $subs["id"];
                $empsubs->setOpt(array("where" => "empnum='{$data['empnum']}' AND subid='{$sid}'"));
                $empsubs->run();
                if ($empsubs->num_rows() <= 0) {
                    $si["amount"] = "0.00";
                    $si["days"] = "0";
                    $si["accid"] = $subs["accid"];
                } else {
                    $si = $empsubs->fetch_array();
                }
                if ($subs["in_republic"] != "yes") {
                    $subs_int = true;
                }
                $subsistence .= "\n\t\t\t\t\t<input type='hidden' name='subsname[{$id}][{$sid}]' value='{$subs['name']}'>\n\t\t\t\t\t<input type='hidden' name='subsacc[{$id}][{$sid}]' value='{$si['accid']}'>\n\t\t\t\t\t<input type='hidden' name='subsrep[{$id}][{$sid}]' value='{$subs['in_republic']}'>\n\t\t\t\t\t<input type='hidden' name='subsmeal[{$id}][{$sid}]' value='{$subs['meals']}'>\n\t\t\t\t\t<tr bgcolor='" . bgcolor($i) . "'>\n\t\t\t\t\t\t<td>{$subs['name']}</td>\n\t\t\t\t\t\t<td nowrap>" . CUR . " <input type='text' size='5' name='subsamt[{$id}][{$sid}]' value='{$si['amount']}'></td>\n\t\t\t\t\t\t<td><input type='text' size='2' name='subsdays[{$id}][{$sid}]' value='{$si['days']}'></td>\n\t\t\t\t\t</tr>";
            }
            $subsistence .= "\n\t\t\t\t</table>";
        }
        # Deductions
        $i = 0;
        db_conn('cubit');
        $sql = "SELECT * FROM salded WHERE div = '" . USER_DIV . "' ORDER BY deduction";
        $deductRslt = db_exec($sql) or errDie("Unable to select deductions from database.");
        if (pg_numrows($deductRslt) < 1) {
            $deductions = "<table " . TMPL_tblDflts . ">";
            $deductions .= "<tr><td>None</td></tr>";
            $deductions .= "</table>";
        } else {
            $deductions = "<table " . TMPL_tblDflts . ">";
            while ($myDeduct = pg_fetch_array($deductRslt)) {
                # check if employee has deduction
                $sql = "SELECT * FROM empdeduct WHERE dedid='{$myDeduct['id']}' AND empnum='{$data['empnum']}' AND div = '" . USER_DIV . "'";
                $empDeductRslt = db_exec($sql) or errDie("Unable to select Deduction info from database.");
                if (pg_numrows($empDeductRslt) > 0) {
                    $dataDeduct = pg_fetch_array($empDeductRslt);
                    if ($dataDeduct["grosdeduct"] == "y") {
                        $deductions_msg = "(Before PAYE)";
                        $sal_calcfrom = $grossal;
                    } else {
                        $deductions_msg = "";
                        $sal_calcfrom = $data["basic_sal"];
                    }
                    if ($dataDeduct['type'] == "Amount") {
                        $dataDeduct['amount'] = sprint($dataDeduct['amount'] / $divisor);
                    } else {
                        $dataDeduct['amount'] = sprint($sal_calcfrom * $dataDeduct['amount'] / 100 / $divisor);
                    }
                    // calculate employer contribution to deduction
                    if ($dataDeduct["employer_type"] == "Amount") {
                        $dataDeduct["employer_amount"] = sprint($dataDeduct["employer_amount"] / $divisor);
                    } else {
                        $dataDeduct["employer_amount"] = sprint($dataDeduct["amount"] * $dataDeduct["employer_amount"] / 100 / $divisor);
                    }
                    $tmp_deductions = $dataDeduct["amount"];
                    $tmp_dedaccs = $dataDeduct["accid"];
                    $tmp_emp_ded = $dataDeduct["employer_amount"];
                } else {
                    $tmp_deductions = "0.00";
                    $tmp_emp_ded = "0.00";
                    $tmp_dedaccs = $myDeduct["accid"] != 0 ? $myDeduct["accid"] : $myDeduct["expaccid"];
                    $deductions_msg = "";
                }
                # check if we should be using deductions
                if ($data['emp_usescales'] == "1" and $myDeduct['type'] == "Percentage") {
                    # check if this deduction has scales
                    $get_scales = "SELECT * FROM salded_scales WHERE saldedid = '{$myDeduct['id']}' LIMIT 1";
                    $run_scales = db_exec($get_scales) or errDie("Unable to get deduction scale information.");
                    if (pg_numrows($run_scales) > 0) {
                        # scales exist
                        $get_perc = "\n\t\t\t\t\t\t\tSELECT * FROM salded_scales \n\t\t\t\t\t\t\tWHERE scale_from <= '{$data['basic_sal']}' AND scale_to >= '{$data['basic_sal']}' AND saldedid = '{$myDeduct['id']}' \n\t\t\t\t\t\t\tLIMIT 1";
                        $run_perc = db_exec($get_perc) or errDie("Unable to get deduction scale information.");
                        if (pg_numrows($run_perc) > 0) {
                            # found a matching scale for this scaled duduction for a customer using scales ....
                            $scale_arr = pg_fetch_array($run_perc);
                            $tmp_deductions = sprint($data['basic_sal'] / 100 * $scale_arr['scale_amount']);
                        }
                    }
                }
                $deductions .= "\n\t\t\t\t\t<input type='hidden' size='10' name='deductid[{$id}][]' value='{$myDeduct['id']}'>\n\t\t\t\t\t<input type='hidden' size='30' name='deductname[{$id}][]' value='{$myDeduct['deduction']}'>\n\t\t\t\t\t<input type='hidden' size='10' name='deducttax[{$id}][]' value='{$myDeduct['add']}'>\n\t\t\t\t\t<input type='hidden' name='dedaccs[{$id}][]' value='{$tmp_dedaccs}'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>{$myDeduct['deduction']} {$deductions_msg}</td>\n\t\t\t\t\t\t<td>" . CUR . "</td>\n\t\t\t\t\t\t<td><input type='text' size='10' name='deductions[{$id}][]' value='{$tmp_deductions}'></td>\n\t\t\t\t\t\t<td>" . CUR . "</td>\n\t\t\t\t\t\t<td><input type='hidden' size='10' name='employer_deductions[{$id}][]' value='{$tmp_emp_ded}'></td>\n\t\t\t\t\t</tr>";
                $i++;
            }
            $deductions .= "</table>";
        }
        $rt = "";
        db_conn('cubit');
        $Sl = "SELECT * FROM rbs ORDER BY name";
        $Rl = db_exec($Sl) or errDie("Unable to get data.");
        $i = 0;
        if (pg_num_rows($Rl) > 0) {
            $rt = "<table " . TMPL_tblDflts . ">";
            while ($td = pg_fetch_array($Rl)) {
                if (!isset($rbsa[$id][$td['id']])) {
                    $rbsa[$id][$td['id']] = "";
                }
                $rt .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td><input type='hidden' name='rbs[{$id}][{$td['id']}]' value='{$td['id']}'>{$td['name']}</td>\n\t\t\t\t\t\t<td>" . CUR . "</td>\n\t\t\t\t\t\t<td><input type='text' size='10' name='rbsa[{$id}][{$td['id']}]' value='" . $rbsa[$id][$td['id']] . "' class='right'></td>\n\t\t\t\t\t</tr>";
                $i++;
            }
            $rt .= "</table>";
        } else {
            $rt .= "None";
        }
        $salarr = array("m" => "Per Month", "w" => "Per Week", "f" => "Fortnightly", "h" => "Per Hour");
        $salnarr = array("d" => "Day(s)", "h" => "Hour(s)");
        $saltype = $salarr[$data['saltyp']];
        if (!isset($multi[$id])) {
            $multi[$id] = $data["saltyp"] == "h" ? $multiplier : 1;
        }
        $multi[$id] = round($multi[$id]);
        if ($data['saltyp'] == 'd' || $data['saltyp'] == 'h') {
            $salntype = $salnarr[$data['saltyp']];
            $multi_show = "x <input type='text' size='3' name='multi[{$id}]' value='{$multi[$id]}'> {$salntype}";
        } else {
            $multi_show = "<input type='hidden' name='multi[{$id}]' value='{$multi[$id]}'>";
            $saltype = "";
        }
        if (isset($mpaye[$id])) {
            $ch = "checked=yes";
        } else {
            $ch = "";
        }
        if ($data["payprd"] == "m" || $data["payprd"] == "d") {
            // count the amount of weekdays in this month
            $workdays = 0;
            for ($i = 1; $i <= date("t", mktime(0, 0, 0, $month, 1, date("Y"))); ++$i) {
                $wd = date("w", mktime(0, 0, 0, $month, $i, date("Y")));
                if ($wd != 0 && $wd != 6) {
                    ++$workdays;
                }
            }
            // hours per day calculation
            $hpd = $data["hpweek"] / 5;
            if (!isset($wh_total[$id])) {
                $wh_total[$id] = $workdays * $hpd;
            }
            if (!isset($wh_actual[$id])) {
                $wh_actual[$id] = $wh_total[$id];
            }
        }
        if ($data["payprd"] == "w") {
            if (!isset($wh_total[$id])) {
                $wh_total[$id] = $data["hpweek"];
            }
            if (!isset($wh_actual[$id])) {
                $wh_actual[$id] = $wh_total[$id];
            }
        }
        if ($data["payprd"] == "f") {
            if (!isset($wh_total[$id])) {
                $wh_total[$id] = $data["hpweek"] * 2;
            }
            if (!isset($wh_actual[$id])) {
                $wh_actual[$id] = $wh_total[$id];
            }
        }
        $js_workhours_fields .= "\n\t\t\t<script>\n\t\t\t\tf_sal[{$id}]\t\t= sf.elements['basic_sal[{$id}]'];\n\t\t\t\tf_salbonus[{$id}] = sf.elements['sal_bonus[{$id}]'];\n\t\t\t\tf_whtot[{$id}]\t= sf.elements['wh_total[{$id}]'];\n\t\t\t\tf_whact[{$id}]\t= sf.elements['wh_actual[{$id}]'];\n\t\t\t\tf_cpension[{$id}]\t= sf.elements['comp_pension[{$id}]'];\n\t\t\t\tf_epension[{$id}] = sf.elements['emp_pension[{$id}]'];\n\t\t\t\tf_cprov[{$id}]\t= sf.elements['comp_provident[{$id}]'];\n\t\t\t\tf_eprov[{$id}]\t= sf.elements['emp_provident[{$id}]'];\n\t\t\t\t//f_cuif[{$id}]\t\t= sf.elements['comp_uif[{$id}]'];\n\t\t\t\t//f_euif[{$id}]\t\t= sf.elements['emp_uif[{$id}]'];\n\t\t\t\tf_cother[{$id}]\t= sf.elements['comp_other[{$id}]'];\n\t\t\t\tf_eother[{$id}]\t= sf.elements['emp_other[{$id}]'];\n\n\t\t\t\tdb_cpension[{$id}]\t= " . $db["comp_pension"] . ";\n\t\t\t\tdb_epension[{$id}]\t= " . $db["emp_pension"] . ";\n\t\t\t\tdb_cprov[{$id}]\t\t= " . $db["comp_provident"] . ";\n\t\t\t\tdb_eprov[{$id}]\t\t= " . $db["emp_provident"] . ";\n\t\t\t\t//db_cuif[{$id}]\t\t= " . $db["comp_uif"] . ";\n\t\t\t\t//db_euif[{$id}]\t\t= " . $db["emp_uif"] . ";\n\t\t\t\tdb_cother[{$id}]\t= " . $db["comp_other"] . ";\n\t\t\t\tdb_eother[{$id}]\t= " . $db["emp_other"] . ";\n\n\t\t\t\tval_sal[{$id}] = -1;\n\t\t\t</script>";
        vsprint($data["basic_sal"]);
        $out .= "\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<input type='hidden' name='emps[{$id}]' value='{$id}'>\n\t\t\t\t<input type='hidden' name='saltyp[{$id}]' value='{$data['saltyp']}'>\n\t\t\t\t<input type='hidden' name='process_comp_deductions[{$id}]' value='{$process_comp_deductions}'>\n\t\t\t\t<input type='hidden' name='divisor[{$id}]' value='{$divisor}'>\n\t\t\t\t<td nowrap>{$data['enum']}</td>\n\t\t\t\t<td>{$data['sname']}, {$data['fnames']}</td>\n\t\t\t\t<td nowrap><input type='text' size='8' name='basic_sal[{$id}]' value='{$data['basic_sal']}' class='right' onChange='changedfield({$id});'>{$saltype} {$multi_show}</td>";
        if (isset($d)) {
            $out .= "\n\t\t\t\t<input type='hidden' name='wh_total' value='1'>\n\t\t\t\t<input type='hidden' name='wh_actual' value='1'>";
        } else {
            $out .= "\n\t\t\t\t<td nowrap><input type='text' size='10' name='wh_total[{$id}]' value='{$wh_total[$id]}' class='right' onChange='workhours({$id});'></td>\n\t\t\t\t<td nowrap><input type='text' size='10' name='wh_actual[{$id}]' value='{$wh_actual[$id]}' class='right' onChange='workhours({$id});'></td>";
        }
        if (!isset($abonus[$id])) {
            $abonus = 0;
        }
        $out .= "\n\t\t\t\t<td nowrap><input type='text' size='5' name='novert[{$id}]' value='{$novert[$id]}' class='right'> Hrs</td>\n\t\t\t\t<td nowrap><input type='text' size='5' name='hovert[{$id}]' value='{$hovert[$id]}' class='right'> Hrs</td>\n\t\t\t\t<td nowrap><input type='hidden' size='8' name='bonus[{$id}]' value='0' class='right'><input type='text' size='8' name='abonus[{$id}]' value='{$abonus[$id]}' class='right'></td>\n\t\t\t\t<input type='hidden' name='annual[{$id}]' value='0' />\n\t\t\t\t<!--<td nowrap><input type='text' size='8' name='annual[{$id}]' value='{$annual[$id]}' class='right'></td>-->\n\t\t\t\t<td nowrap><input type='text' size='8' name='commission[{$id}]' value='{$data['commission']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='all_travel[{$id}]' value='{$data['all_travel']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='loaninstall[{$id}]' value='{$data['loaninstall']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='comp_pension[{$id}]' value='{$data['comp_pension']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='emp_pension[{$id}]' value='{$data['emp_pension']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='comp_provident[{$id}]' value='{$data['comp_provident']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='emp_provident[{$id}]' value='{$data['emp_provident']}' class='right'></td>\n\t\t\t\t<!--\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='comp_uif[{$id}]' value='{$data['comp_uif']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='emp_uif[{$id}]' value='{$data['emp_uif']}' class='right'></td>\n\t\t\t\t//-->\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='comp_ret[{$id}]' value='{$data['comp_ret']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='emp_ret[{$id}]' value='{$data['emp_ret']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='comp_medical[{$id}]' value='{$data['comp_medical']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='emp_medical[{$id}]' value='{$data['emp_medical']}' class='right'></td>\n\t\t\t\t<input type=hidden name='comp_other[{$id}]' value='0'>\n\t\t\t\t<input type=hidden name='emp_other[{$id}]' value='0'>\n\t\t\t\t<!--\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='comp_other[{$id}]' value='{$data['comp_other']}' class='right'></td>\n\t\t\t\t<td nowrap>R<input type='text' size='8' name='emp_other[{$id}]' value='{$data['emp_other']}' class='right'></td>\n\t\t\t\t//-->\n\t\t\t\t<td>{$paydetails}</td>\n\t\t\t\t<td>\n\t\t\t\t\t<table>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td><input type='checkbox' name='mpaye[{$id}]' {$ch}></td>\n\t\t\t\t\t\t\t<td><input type='text' size='8' name='mpaye_amount[{$id}]' value='{$mpaye_amount[$id]}'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td>{$fringes}</td>\n\t\t\t\t<td>{$allowances}</td>\n\t\t\t\t<td>{$subsistence}<!--%%EXCHANGE%%--></td>\n\t\t\t\t<td>{$deductions}</td>\n\t\t\t\t<td>{$rt}</td>\n\t\t\t</tr>";
    }
    if (!isset($id)) {
        header("Location: ../admin-employee-view.php?err=Please select at least one employee.");
        exit;
    }
    // replace the exchange rate place holder with the exchange rate form field
    if ($subs_int) {
        $exch = "\n\t\t\t<input type='hidden' name='subs_exch' value='1'>\n\t\t\t<li class='err'>Please calculate the rand amount prior to completing the amount above.</li>";
        // 			<tr class='".bg_class()."'>
        // 				<th class='".bg_class()."'>Exchange (ZAR-USD):</th>
        // 				<td><input type='text' name='subs_exch' value='".xrate_get("USD")."'></td>
        // 			</tr>";
        $out = str_replace("<!--%%EXCHANGE%%-->", $exch, $out);
    }
    $out .= "\n\t\t\t<tr><td><br></td></tr>\n\t\t\t{$send}\n\t\t\t<tr>\n\t\t\t\t<td colspan='9' align='right' nowrap='t'>\n\t\t\t\t\t<input type='submit' name='btn_back' value='&laquo; Correction'>\n\t\t\t\t\t<input type='submit' value='Confirm &raquo;'>\n\t\t\t\t</td>\n\t\t\t\t<td colspan='10' align='right' nowrap='t'>\n\t\t\t\t\t<input type='submit' name='btn_back' value='&laquo; Correction'>\n\t\t\t\t\t<input type='submit' value='Confirm &raquo;'>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t</form>\n\t\t<script>\n\t\t\tfunction monthchange(mondd) {\n\t\t\t\t" . implode("\n", $jsbonus_clear) . "\n\t\t\t\tswitch ( mondd.value ) {\n\t\t\t\tcase '1':\n\t\t\t\t\t" . implode("\n", $jsbonus[1]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '2':\n\t\t\t\t\t" . implode("\n", $jsbonus[2]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '3':\n\t\t\t\t\t" . implode("\n", $jsbonus[3]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '4':\n\t\t\t\t\t" . implode("\n", $jsbonus[4]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '5':\n\t\t\t\t\t" . implode("\n", $jsbonus[5]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '6':\n\t\t\t\t\t" . implode("\n", $jsbonus[6]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '7':\n\t\t\t\t\t" . implode("\n", $jsbonus[7]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '8':\n\t\t\t\t\t" . implode("\n", $jsbonus[8]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '9':\n\t\t\t\t\t" . implode("\n", $jsbonus[9]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '10':\n\t\t\t\t\t" . implode("\n", $jsbonus[10]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '11':\n\t\t\t\t\t" . implode("\n", $jsbonus[11]) . "\n\t\t\t\t\tbreak;\n\t\t\t\tcase '12':\n\t\t\t\t\t" . implode("\n", $jsbonus[12]) . "\n\t\t\t\t\tbreak;\n\t\t\t\t}";
    //".implode("\n", $uif_calc)."
    $out .= "\n\t\t\t}\n\t\t</script>\n\t\t<script>\n\t\t\tsf = document.getElementById('salfrm');\n\t\t\tf_sal = new Array();\n\t\t\tf_salbonus = new Array();\n\t\t\tf_whtot = new Array();\n\t\t\tf_whact = new Array();\n\t\t\tf_cpension = new Array();\n\t\t\tf_epension = new Array();\n\t\t\tf_cprov = new Array();\n\t\t\tf_eprov = new Array();\n\t\t\t//f_cuif = new Array();\n\t\t\t//f_euif = new Array();\n\t\t\tf_cother = new Array();\n\t\t\tf_eother = new Array();\n\n\t\t\tdb_cpension = new Array();\n\t\t\tdb_epension = new Array();\n\t\t\tdb_cprov = new Array();\n\t\t\tdb_eprov = new Array();\n\t\t\t//db_cuif = new Array();\n\t\t\t//db_euif = new Array();\n\t\t\tdb_cother = new Array();\n\t\t\tdb_eother = new Array();\n\n\t\t\tval_sal = new Array();\n\t\t</script>\n \t\t{$js_workhours_fields}\n\t\t<script>\n\t\t\t// changing the workhours\n\t\t\tfunction workhours(id) {\n\t\t\t\tif ( val_sal[id] < 0 ) val_sal[id] = parseFloat(f_sal[id].value);\n\n\t\t\t\tval_whtot\t= parseFloat(f_whtot[id].value);\n\t\t\t\tval_whact\t= parseFloat(f_whact[id].value);\n\n\t\t\t\tif ( val_whtot >= val_whact ) {\n\t\t\t\t\tp = val_whact / val_whtot;\n\n\t\t\t\t\t// calculate the new basic salary\n\t\t\t\t\tx = val_sal[id] * p;\n\t\t\t\t\tx = x.toFixed(2);\n\t\t\t\t\tf_sal[id].value = x;\n\n\t\t\t\t\t// calculate the new values\n\t\t\t\t\tval_cpension \t= x * db_cpension[id] / 100;\n\t\t\t\t\tval_epension \t= x * db_epension[id] / 100;\n\t\t\t\t\tval_cprov\t\t= x * db_cprov[id] / 100;\n\t\t\t\t\tval_eprov\t\t= x * db_eprov[id] / 100;\n\t\t\t\t\t//val_cuif\t\t= x * db_cuif[id] / 100;\n\t\t\t\t\t//val_euif\t\t= x * db_euif[id] / 100;\n\t\t\t\t\tval_cother\t\t= x * db_cother[id] / 100;\n\t\t\t\t\tval_eother\t\t= x * db_eother[id] / 100;\n\n\t\t\t\t\tval_cpension \t= val_cpension.toFixed(2);\n\t\t\t\t\tval_epension \t= val_epension.toFixed(2);\n\t\t\t\t\tval_cprov \t\t= val_cprov.toFixed(2);\n\t\t\t\t\tval_eprov\t\t= val_eprov.toFixed(2);\n\t\t\t\t\t//val_cuif\t\t= val_cuif.toFixed(2);\n\t\t\t\t\t//val_euif\t\t= val_euif.toFixed(2);\n\t\t\t\t\tval_cother\t\t= val_cother.toFixed(2);\n\t\t\t\t\tval_eother\t\t= val_eother.toFixed(2);\n\n\t\t\t\t\tf_cpension[id].value\t= val_cpension;\n\t\t\t\t\tf_epension[id].value \t= val_epension;\n\t\t\t\t\tf_cprov[id].value \t\t= val_cprov;\n\t\t\t\t\tf_eprov[id].value\t\t= val_eprov;\n\t\t\t\t\t//f_cuif[id].value\t\t= val_cuif;\n\t\t\t\t\t//f_euif[id].value\t\t= val_euif;\n\t\t\t\t\tf_cother[id].value\t\t= val_cother;\n\t\t\t\t\tf_eother[id].value\t\t= val_eother;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction changedfield(id) {\n\t\t\t\tval_whtot\t= parseFloat(f_whtot[id].value);\n\t\t\t\tval_whact\t= parseFloat(f_whact[id].value);\n\n\t\t\t\tp = val_whtot / val_whact;\n\n\t\t\t\tval_sal[id] = parseFloat(f_sal[id].value) * p;\n\t\t\t\tval_sal[id] = val_sal[id].toFixed(2);\n\t\t\t}\n\n\t\t\tmonthchange(document.getElementById('salfrm').elements['month']);\n\t\t</script>";
    return $out;
}
コード例 #4
0
/**
 * writes a transaction into the general ledger
 *
 * @param string $ttype transaction type to record
 * @param int $dtacc debit account id
 * @param int $ctacc credit account id
 * @param string $date
 * @param int $refnum
 * @param float $amount
 * @param float $vat vat amount
 * @param string $details description for ledger entry
 */
function recordtrans($ttype, $dtacc, $ctacc, $date, $refnum, $amount, $vat, $details, $iid = '0')
{
    global $MONPRD, $PRDMON;
    $amount = sprint($amount);
    //	if($amount<0.01) {
    //		return;
    //	}
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($ctacc, "num", 1, 50, "Invalid Account to be Credited ({$ctacc}) for transaction \"{$details}\".");
    $v->isOk($dtacc, "num", 1, 50, "Invalid Account to be Debited ({$dtacc}) for transaction \"{$details}\".");
    $v->isOk($date, "date", 1, 14, "Invalid date for transaction \"{$details}\".");
    $v->isOk($refnum, "num", 1, 50, "Invalid reference number for transaction \"{$details}\".");
    $v->isOk($amount, "float", 1, 40, "Invalid amount {$amount} for transaction \"{$details}\".");
    $details = str_replace(":", " ", $details);
    $detailscheck = str_replace("|", "", $details);
    $v->isOk($detailscheck, "string", 0, 2048, "Invalid Details [{$details}].");
    # Date format
    $date = explode("-", $date);
    // $day ,$mon , $year
    if (checkdate($date[1], $date[0], $date[2])) {
        $mon = $date[1];
        $yr = $date[2];
        $date = "{$date['2']}-{$date['1']}-{$date['0']}";
        // $year, $mon, $day
    } elseif (checkdate($date[1], $date[2], $date[0])) {
        $mon = $date[1];
        $yr = $date[0];
        $date = "{$date['0']}-{$date['1']}-{$date['2']}";
    } else {
        $v->addError("", "Invalid date for transaction. " . (DEBUG > 0 ? "\"{$details}\"" : ""));
    }
    if (isset($yr)) {
        $curyr = getActiveFinYear();
        if ($yr > $curyr || $yr == $curyr && $mon > $PRDMON[12]) {
            $v->addError("", "Cannot do transaction in future financial year. " . (DEBUG > 0 ? "\"{$details}\"" : ""));
        }
    }
    if (floatval($amount) == floatval(0)) {
        return;
    }
    if ($v->isError()) {
        $OUTPUT = $v->genErrors();
        $OUTPUT .= "<p><input type='button' onclick='javascript:history.back();' value='&laquo; Correct submission'></p>";
        pglib_transaction("ROLLBACK");
        require "template.php";
    }
    if (!accExist($dtacc) and $dtacc != "0" and $dtacc != "1" and $dtacc != "9999") {
        $dtacc = getErrAcc();
        $details = $details . " - Debit account was not found, transaction has been posted to error account.";
    }
    if (!accExist($ctacc) and $ctacc != "0" and $ctacc != "1" and $ctacc != "9999") {
        $ctacc = getErrAcc();
        $details = $details . " - Credit account was not found, transaction has been posted to error account.";
    }
    # Get account information
    $dacc = getAcc($dtacc);
    $cacc = getAcc($ctacc);
    $sdate = date("Y-m-d");
    list($PRD_DB, $PRD_NAME) = getPRD($date);
    list($CUR_PRD_DB, $CUR_PRD_NAME) = getPRD(date("Y-m-d"));
    if ($vat != "0") {
        $vat = sprint($vat);
    }
    # Insert the records into the transect table
    //if (PRD_STATE != "py") {
    db_conn("exten");
    $sql = "INSERT INTO tranreplay(ttype,debitacc,creditacc,tdate,refno,amount,vat,details,iid)\n\t\t\tVALUES('{$ttype}', '{$dtacc}', '{$ctacc}','{$date}', '{$refnum}', '{$amount}','{$vat}', '{$details}','{$iid}')";
    $transRslt = db_exec($sql) or errDie("Unable to insert Transaction  details to database", SELF);
    //}
}