コード例 #1
0
function show_report($_POST)
{
    extract($_POST);
    if (!isset($employee) or strlen($employee) < 1) {
        return "Invalid use of module.";
    }
    db_connect();
    $get_employee = "SELECT * FROM employees WHERE empnum = '{$employee}' LIMIT 1";
    $run_employee = db_exec($get_employee) or errDie("Unable to get employees information.");
    if (pg_numrows($run_employee) < 1) {
        return "Invalid Employee Selected.";
    } else {
        $earr = pg_fetch_array($run_employee);
        //extract($earr);
    }
    $finstartdate = mkdate(getYearOfFinPrd(1) - 1, $PRDMON[1], 1);
    $finenddate = mkldate(getYearOfFinPrd(12) - 1, $PRDMON[12]);
    db_connect();
    #get all leave for this employee
    $get_leave = "SELECT * FROM empleave WHERE empnum = '{$earr['empnum']}' AND startdate > '{$finstartdate}' AND enddate < '{$finenddate}'";
    $run_leave = db_exec($get_leave) or errDie("Unable to get employee leave information.");
    if (pg_numrows($run_leave) < 1) {
        $listing = "Employee did not apply for leave during the previous financial year.";
    } else {
        $total_leave_days = 0;
        $listing = "\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Leave Start Date</th>\n\t\t\t\t\t<th>Leave End Date</th>\n\t\t\t\t\t<th>Approved By</th>\n\t\t\t\t\t<th>Working Days</th>\n\t\t\t\t\t<th>Non Working Days</th>\n\t\t\t\t\t<th>Leave Type</th>\n\t\t\t\t</tr>\n\t\t\t";
        while ($larr = pg_fetch_array($run_leave)) {
            $total_leave_days = $total_leave_days + $larr['workingdays'];
            $listing .= "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td>{$larr['startdate']}</td>\n\t\t\t\t\t\t<td>{$larr['enddate']}</td>\n\t\t\t\t\t\t<td>{$larr['approvedby']}</td>\n\t\t\t\t\t\t<td>{$larr['workingdays']}</td>\n\t\t\t\t\t\t<td>{$larr['nonworking']}</td>\n\t\t\t\t\t\t<td>{$larr['type']}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t";
        }
        $total_cost = $earr['basic_sal_annum'] / (52 * 5) * $total_leave_days;
    }
    $display = "\n\t\t\t<h2>Calculate Value Of Employee Leave</h2>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t\t<input type='hidden' name='key' value='xls'>\n\t\t\t\t<input type='hidden' name='employee' value='{$employee}'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan='2'>Details</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Employee:</td>\n\t\t\t\t\t<td>{$earr['fnames']} {$earr['sname']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Amount Of Annual Leave Days:</td>\n\t\t\t\t\t<td>{$earr['stdlea']}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Total Days Leave Taken</td>\n\t\t\t\t\t<td>{$total_leave_days}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>Total Cost Of Employee Leave</td>\n\t\t\t\t\t<td>" . CUR . " {$total_cost}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t{$listing}\n\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan='4'><input type='submit' name='xls' value='Export to spreadsheet'></td>\n\t\t\t\t</tr>\n\t\t\t</form>\n\t\t\t</table>\n\t\t";
    return $display;
}
コード例 #2
0
function get_period()
{
    global $PRDMON;
    $finstartdate = mkdate(getYearOfFinPrd(1), $PRDMON[1], 1);
    $finenddate = mkldate(getYearOfFinPrd(12), $PRDMON[12]);
    db_connect();
    #get vat period setting
    $get_set = "SELECT * FROM settings WHERE label = 'VAT Period' LIMIT 1";
    $run_set = db_exec($get_set) or errDie("Unable to get vat period information.");
    if (pg_numrows($run_set) < 1) {
        return "\n\t\t\t<li class='err'>Please Set VAT Period Setting Before Continuing.</li>\n\t\t\t<p>\n\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td><a href='../vat_period_setting.php'>Set VAT Period</a></td>\n\t\t\t\t</tr>\n\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t</table>";
    } else {
        $sarr = pg_fetch_array($run_set);
        $periodlength = $sarr['value'];
        $b = 1;
        $period_drop = "<select name='period'>";
        for ($x = 1; $b < 12; $x = $x + $periodlength) {
            $b = $b + $periodlength;
            #make sure we dont cross the 12 period limit
            if ($b > 12) {
                #set period to the last
                $dob = $b - 12;
                $b = 12;
                #make sure we get the last month (the -1 makes us lose 1)
                //				$PRDMON[$b] = $PRDMON[$b] +1;
            } else {
                $dob = $b;
            }
            $start = date("Y-m-d", mktime(0, 0, 0, $PRDMON[$x], 1, getYearOfFinPrd($x)));
            $end = date("Y-m-d", mktime(0, 0, 0, $PRDMON[$dob], 0, getYearOfFinPrd($b)));
            $period_drop .= "<option value='{$start}|{$end}'>{$start} - {$end}</option>";
        }
        $period_drop .= "</select>";
    }
    #generate the periods dropdown based on vat period setting.
    $display = "\n\t\t<h2>Select VAT Period For Report</h2>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t\t<input type='hidden' name='key' value='confirm'>\n\t\t\t<tr>\n\t\t\t\t<td><li class='err'>NOTE: Pre Generated Values Are The Cubit Recommened Values. </li></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td><li class='err'>However these values may be changed at will.</li></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Period</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>{$period_drop}</td>\n\t\t\t</tr>\n\t\t\t<tr><td></td></tr>\n\t\t\t<tr>\n\t\t\t\t<th>Name For Report</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><input type='text' name='returnname' value='" . date("Y-m-d") . " Report'></td>\n\t\t\t</tr>\n\t\t\t<tr><td></td></tr>\n\t\t\t<tr>\n\t\t\t\t<td align='right'><input type='submit' value='Next'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>";
    return $display;
}
コード例 #3
0
function display($_POST)
{
    extract($_POST);
    global $PRDMON;
    #determine the date range based on period selection
    if (isset($year_to_process)) {
        switch ($year_to_process) {
            case "active":
                $fdate_year = getYearOfFinPrd(1);
                $fdate_month = $PRDMON[1];
                $fdate_day = "1";
                $tdate_year = getYearOfFinPrd(12);
                $tdate_month = $PRDMON[12];
                $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year));
                break;
            case "previous":
                $fdate_year = getYearOfFinPrd(1) - 1;
                $fdate_month = $PRDMON[1];
                $fdate_day = "1";
                $tdate_year = getYearOfFinPrd(12) - 1;
                $tdate_month = $PRDMON[12];
                $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year));
                break;
            default:
                $fdate_year = getYearOfFinPrd(1);
                $fdate_month = "03";
                $fdate_day = "01";
                $tdate_year = getYearOfFinPrd(12);
                $tdate_month = "02";
                $tdate_day = date("d", mktime(0, 0, 0, 3, 0, $tdate_year));
        }
    }
    // -----------------------------------------------------------------------
    // Sanity checks
    // -----------------------------------------------------------------------
    require_lib("validate");
    $v = new validate();
    // Does this employee number actually exist
    db_conn("cubit");
    $sql = "SELECT * FROM employees WHERE empnum='" . (int) $empnum . "' AND div='" . USER_DIV . "'";
    $empinf_rslt = db_exec($sql) or errDie("Unable to retrieve employee number from Cubit.");
    if (pg_num_rows($empinf_rslt) == 0) {
        $v->addError(0, "Employee number not found in Cubit.");
    }
    $v->isOk($fdate_month, "num", 1, 2, "Invalid from date (month)");
    $v->isOk($fdate_year, "num", 4, 4, "Invalid from date (year)");
    $v->isOk($tdate_month, "num", 1, 2, "Invalid to date (month)");
    $v->isOk($tdate_year, "num", 4, 4, "Invalid to date (year)");
    if ($fdate_month > 12) {
        $v->addError(0, "Invalid from date (month)");
    }
    if ($fdate_year < 1970 || $fdate_year > 2050) {
        $v->addError(0, "Invalid from date (year)");
    }
    if ($tdate_month > 12) {
        $v->addError(0, "Invalid to date (month)");
    }
    if ($tdate_year < 1970 || $tdate_year > 2050) {
        $v->addError(0, "Invalid to date (year)");
    }
    if ($fdate_day > getDaysInMonth((int) $fdate_month, $fdate_year)) {
        $v->addError(0, "Invalid from date (day)");
    }
    if ($tdate_day > getDaysInMonth((int) $tdate_month, $tdate_year)) {
        $v->addError(0, "Invalid to date (day)");
    }
    $from_time = mktime(0, 0, 0, $fdate_day, $fdate_month, $fdate_year);
    $to_time = mktime(0, 0, 0, $tdate_day, $tdate_month, $tdate_year);
    if ($from_time > $to_time) {
        $v->addError(0, "Invalid date range specified.");
    }
    // Return the errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>{$e['msg']}</li>";
        }
        return slct($confirm);
    }
    $from_date = "{$fdate_year}-{$fdate_month}-{$fdate_day}";
    $to_date = "{$tdate_year}-{$tdate_month}-{$tdate_day}";
    $gross_taxable_annual_payments = 0.0;
    $gross_non_taxable_income = 0.0;
    $gross_retirement_funding_income = 0.0;
    $gross_non_retirement_funding_income = 0.0;
    $gross_remuneration = 0.0;
    db_conn("cubit");
    $sql = "SELECT * FROM compinfo";
    $compinfo_rslt = db_exec($sql) or errDie("Unable to retrieve company information from Cubit.");
    $compinfo = pg_fetch_array($compinfo_rslt);
    db_conn("cubit");
    $sql = "SELECT * FROM employees WHERE empnum='{$empnum}'";
    $empinfo_rslt = db_exec($sql) or errDie("Unable to retrieve employee information from Cubit.");
    $empinfo = pg_fetch_array($empinfo_rslt);
    $header_out = "<b>Employees tax certificate</b>";
    $employer_trading_name_out = array(array("<b>Trading or other name:</b> {$compinfo['compname']}"));
    $employer_irp5_number_out = array(array("<b>IRP 5 number:</b> {$irp5_number}"));
    $employer_reference_number_out = array(array("<b>Reference number:</b> {$empinfo['taxref']}"));
    $employer_tax_year_out = array(array("<b>Tax year:</b> " . ($fdate_year + 1)));
    $employer_diplomatic_indemnity_out = array(array("<b>Diplomatic indemnity:</b> {$compinfo['diplomatic_indemnity']}"));
    $employer_business_address_out = array(array("<b>Employer business address:</b>"), array("{$compinfo['addr1']}"), array("{$compinfo['addr2']}"), array("{$compinfo['addr3']}"));
    $employer_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$compinfo['addr4']}"));
    $employer_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right"));
    // Extract the employee's birth date from her id number
    $bd_year = 1900 + substr($empinfo["idnum"], 0, 2);
    $bd_month = substr($empinfo["idnum"], 2, 2);
    $bd_day = substr($empinfo["idnum"], 4, 2);
    // Period employed from
    // strip out the dashes from the date
    $prd_employed_frm = explode("-", $empinfo["hiredate"]);
    $prd_employed_frm = implode($prd_employed_frm);
    // Period employed to
    if (empty($empinfo["firedate"])) {
        $prd_employed_to = getFinYear() . "0228";
    } else {
        $prd_employed_to = explode("-", $firedate);
        $prd_employed_to = implode("", $prd_employed_to);
    }
    $employee_nature_out = array(array("<b>Nature of Person:</b> {$empinfo['nature']}"));
    $employee_surname_out = array(array("<b>Employee surname or trading name:</b> {$empinfo['sname']}"));
    $employee_first_names_out = array(array("<b>First two names:</b> {$empinfo['fnames']}"));
    $fnames = explode(" ", $empinfo["fnames"]);
    $initials = "";
    foreach ($fnames as $name) {
        $initials .= strtoupper($name[0]);
    }
    $employee_initials_out = array(array("<b>Initials:</b> {$initials}"));
    $employee_identity_number_out = array(array("<b>Identity number:</b> {$empinfo['idnum']}"));
    $employee_passport_number_out = array(array("<b>Passport number:</b> {$empinfo['passport_number']}"));
    $employee_date_of_birth_out = array(array("<b>Date of birth:</b> {$bd_year}-{$bd_month}-{$bd_day}"));
    $employee_cc_number_out = array(array("<b>Company/CC/Trust number:</b> {$empinfo['cc_number']}"));
    $employee_tax_number_out = array(array("<b>Income Tax number:</b> {$empinfo['tax_number']}"));
    $employee_residential_out = array(array("<b>Employees residential address:</b>"), array("{$empinfo['res1']}"), array("{$empinfo['res2']}"), array("{$empinfo['res3']}"));
    $employee_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$empinfo['res4']}"));
    $employee_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right"));
    $employee_number_out = array(array("<b>Employee Number:</b> {$empinfo['empnum']}"));
    $tax_prd_employed_frm_out = array(array("<b>Period employed from:</b> {$prd_employed_frm}"));
    $tax_prd_employed_to_out = array(array("<b>Period employed to:</b> {$prd_employed_to}"));
    $tax_over_deduction_out = array(array("<b>Voluntary over-deduction:</b> {$over_deduction}"));
    switch ($empinfo["payprd"]) {
        case "m":
            $pay_periods = 12;
            break;
        case "f":
            $pay_periods = 24;
            break;
        case "w":
            $pay_periods = 48;
            break;
    }
    $tax_prd_in_year_out = array(array("<b>Pay periods in year:</b> {$pay_periods}"));
    if ($year_to_process == "active") {
        $cyear = EMP_YEAR;
    } else {
        $cyear = EMP_YEAR - 1;
    }
    db_conn("cubit");
    $sql = "SELECT * FROM emp_inc WHERE emp='{$empinfo['empnum']}' AND description='Basic Salary' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve the number of periods worked from Cubit.");
    $pay_periods_worked = pg_num_rows($rslt);
    $tax_prd_worked_out = array(array("<b>Number of periods worked:</b> {$pay_periods_worked}"));
    $tax_fixed_rate_income_out = array(array("<b>Fixed rate income:</b> {$empinfo['fixed_rate']}"));
    $tax_directive_number_out = array(array("<b>Directive number:</b> {$directive_number}"));
    // Income sources --------------------------------------------------------
    $income_sources_out = array();
    $income_taxable_total = 0;
    $income_commission_total = 0;
    $income_bonus_total = 0;
    $income_reimburse_total = 0;
    $income_travelallowance_total = 0;
    $income_subsis_total = 0;
    $income_otherallowance_total = 0;
    $deduction_motorcar_total = 0;
    $deduction_medical_total = 0;
    //	$deduction_medicalaid_total = 0;
    db_conn("cubit");
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Basic Salary' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_taxable_total += $empinc_data["amount"];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3601", "<b>DESCRIPTION</b>" => "Income Taxable", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_taxable_total);
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Bonus' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_bonus_total += $empinc_data["amount"];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3605", "<b>DESCRIPTION</b>" => "Bonus", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_bonus_total);
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Commission' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_commission_total += $empinc_data["amount"];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3606", "<b>DESCRIPTION</b>" => "Commission", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_commission_total);
    #handle travel allowances ....
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description = 'Travel Allowance' AND type = 'INCT' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_travelallowance_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3701", "<b>DESCRIPTION</b>" => "Travel Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_travelallowance_total);
    #handle reimbursements ....
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description!='Basic Salary' AND ex = 'RBS' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_reimburse_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3702", "<b>DESCRIPTION</b>" => "Reimbursements", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_reimburse_total);
    #handle subsistance allowances ....
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND ex = 'SUBS' AND type = '2' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_subsis_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3704", "<b>DESCRIPTION</b>" => "Subsistance Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_subsis_total);
    #handle other allowances ....
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND description != 'Travel Allowance' AND ex != 'SUBS' AND ex != 'RBS' AND type = '2' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_otherallowance_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3713", "<b>DESCRIPTION</b>" => "Other Allowances", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_otherallowance_total);
    #handle motorcar DEDUCTIONS in income table ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND (description = 'Motorcar 1 Contribution for Use' OR description = 'Motorcar 2 Contribution for Use') AND (type = 'DEDA' OR type = 'DEDB') AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $deduction_motorcar_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3802", "<b>DESCRIPTION</b>" => "Use Of Motor Vehicle", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_motorcar_total);
    #handle medical DEDUCTIONS in income table ...
    //$sql = "SELECT amount FROM emp_com WHERE emp='$empnum' AND description = 'Medical Contribution' AND type = 'DEDM'";
    $sql = "SELECT amount FROM emp_com WHERE emp='{$empnum}' AND description = 'Medical Contribution' AND type = 'COMM' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $deduction_medical_total += $empinc_data['amount'];
    }
    //"<b>CODE</b>" => "3816",
    $income_sources_out[] = array("<b>CODE</b>" => "3810", "<b>DESCRIPTION</b>" => "Medical Contribution", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_medical_total);
    #handle medical aid DEDUCTIONS in income table ...
    //	$sql = "SELECT amount FROM emp_ded WHERE emp='$empnum' AND description = 'Medical Contribution' AND type = 'DEDM'";
    //	$rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    //	while ($empinc_data = pg_fetch_array($rslt)) {
    //		$deduction_medicalaid_total += $empinc_data['amount'];
    //	}
    //	$income_sources_out[] = array (
    //		"<b>CODE</b>" => "3802",
    //		"<b>DESCRIPTION</b>" => "Medical aid contributions",
    //		"<b>RF IND</b>" => "",
    //		"<b>AMOUNT</b>" => (int)$deduction_medicalaid_total
    //	);
    // old
    //	$sql = "SELECT * FROM emp_inc WHERE emp='$empnum' AND description!='Basic Salary'";
    //	$rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    //	while ($empinc_data = pg_fetch_array($rslt)) {
    //		$income_sources_out[] = array (
    //			"<b>CODE</b>"=>"$empinc_data[code]",
    //			"<b>DESCRIPTION</b>"=>"$empinc_data[description]",
    //			"<b>RF IND</b>"=>"",
    //			"<b>AMOUNT</b>"=>(int)$empinc_data["amount"]
    //		);
    //	}
    if (!empty($nincome_description) || !empty($nincome_amount) && $nincome_code != 0) {
        $income_sources_out[] = array("<b>CODE</b>" => "{$nincome_code}", "<b>DESCRIPTION</b>" => "{$nincome_description}", "<b>RF IND</b>" => "{$nincome_rfind}", "<b>AMOUNT</b>" => (int) $nincome_amount);
    }
    if (isset($income_code)) {
        foreach ($income_code as $id => $value) {
            if ($income_code[$id] != 0) {
                $income_sources_out[] = array("<b>CODE</b>" => "{$income_code[$id]}", "<b>DESCRIPTION</b>" => "{$income_description[$id]}", "<b>RF IND</b>" => "{$income_rfind[$id]}", "<b>AMOUNT</b>" => (int) $income_amount[$id]);
            } else {
                $income_sources_out[] = array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => "");
            }
        }
    }
    $income_sources_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>RF IND</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70));
    // Gross renumeration ----------------------------------------------------
    // Taxable annual payments
    db_conn("cubit");
    $sql = "SELECT * FROM emp_inc WHERE (code='3695' OR code='3601' OR description='Bonus') AND emp = '{$empnum}' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit.");
    while ($emp_inc_data = pg_fetch_array($rslt)) {
        $gross_taxable_annual_payments += $emp_inc_data["amount"];
    }
    db_conn("cubit");
    $sql = "SELECT * FROM emp_income_sources WHERE (code='3695' OR code='3601') AND empnum = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit.");
    while ($emp_income_sources_data = pg_fetch_array($rslt)) {
        $gross_taxable_annual_payments += $emp_income_sources_data["amount"];
    }
    // Non taxable annual payments
    db_conn("cubit");
    $sql = "SELECT * FROM emp_inc WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND emp = '{$empnum}' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit.");
    while ($emp_inc_data = pg_fetch_array($rslt)) {
        $gross_non_taxable_income += $emp_inc_data["amount"];
    }
    db_conn("cubit");
    $sql = "SELECT * FROM emp_income_sources WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND empnum = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit.");
    while ($emp_income_sources_data = pg_fetch_array($rslt)) {
        if ($emp_income_sources_data["rf_ind"] == "Y") {
            $gross_non_taxable_income += $emp_income_sources_data["amount"];
        }
    }
    // Gross retirement funding income
    db_conn("cubit");
    $sql = "SELECT emp_pension, emp_ret FROM employees WHERE empnum='{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve gross retrirement funding from Cubit.");
    $emp_data = pg_fetch_array($rslt);
    // RF IND
    $rfind_y = 0;
    if (isset($income_rfind)) {
        foreach ($income_rfind as $id => $value) {
            if ($income_rfind[$id] == "Y") {
                $rfind_y += $income_amount[$id];
            }
        }
    }
    //wth emp_pension is a PERCENTAGE, not some amount to add
    //	$gross_retirement_funding_income += $emp_data["emp_pension"] + $emp_data["emp_ret"] + $rfind_y;
    $gross_retirement_funding_income += $gross_taxable_annual_payments / 100 * $emp_data["emp_pension"] + $emp_data["emp_ret"] + $rfind_y;
    // Gross non retirement funding income
    db_conn("cubit");
    $sql = "SELECT * FROM emp_inc WHERE ((code != '3601' AND code != '3603' AND code != '3604' AND code != '3610' AND code != '3615') OR description = 'Basic Salary') AND emp = '{$empnum}' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit.");
    // RF IND
    $rfind_n = 0;
    if (isset($income_rfind)) {
        foreach ($income_rfind as $id => $value) {
            if ($income_rfind[$id] == "N") {
                $rfind_n += $income_amount[$id];
            }
        }
    }
    while ($emp_inc_data = pg_fetch_array($rslt)) {
        $gross_non_retirement_funding_income += $emp_inc_data["amount"] + $rfind_n;
    }
    db_conn("cubit");
    $sql = "SELECT * FROM emp_income_sources WHERE (code != '3601' AND code != '3603' AND code != '3604' AND code != '3610' AND code!='3615') AND empnum = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit.");
    while ($emp_income_sources_data = pg_fetch_array($rslt)) {
        if ($emp_income_sources_data["rf_ind"] == "N") {
            $gross_non_retirement_funding_income += $emp_income_sources_data["amount"];
        }
    }
    // Gross Remuneration
    $gross_remuneration = $gross_retirement_funding_income + $gross_non_retirement_funding_income;
    $gross_remuneration_out = array(array("<b>CODE</b>" => "3695", "<b>DESCRIPTION</b>" => "GROSS TAXABLE ANNUAL PAYMENTS", "<b>AMOUNT</b>" => (int) $gross_taxable_annual_payments), array("<b>CODE</b>" => "3696", "<b>DESCRIPTION</b>" => "GROSS NON-TAXABLE INCOME", "<b>AMOUNT</b>" => (int) $gross_non_taxable_income), array("<b>CODE</b>" => "3697", "<b>DESCRIPTION</b>" => "GROSS RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_retirement_funding_income), array("<b>CODE</b>" => "3698", "<b>DESCRIPTION</b>" => "GROSS NON-RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_non_retirement_funding_income), array("<b>CODE</b>" => "3699", "<b>DESCRIPTION</b>" => "GROSS REMUNERATION", "<b>AMOUNT</b>" => (int) $gross_remuneration));
    $gross_remuneration_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70));
    // Deductions ------------------------------------------------------------
    $deductions_out = array();
    $deduction_pension_total = 0;
    $deduction_provident_total = 0;
    $deduction_medicalaid_total = 0;
    $deduction_medical_total2 = 0;
    $deduction_retirementann_total = 0;
    $deduction_premiumpol_total = 0;
    db_conn("cubit");
    $sql = "SELECT * FROM emp_deductions WHERE empnum='{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($ded_data = pg_fetch_array($rslt)) {
        $deductions_out[] = array("<b>CODE</b>" => "{$ded_data['code']}", "<b>DESCRIPTION</b>" => "{$ded_data['description']}", "<b>CLEARANCE NO</b>" => "{$ded_data['clearance_no']}", "<b>AMOUNT</b>" => (int) $ded_data["amount"]);
    }
    #handle pension deduction ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Pension' AND type = 'DEDP' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($empded_data = pg_fetch_array($rslt)) {
        $deduction_pension_total += $empded_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4001", "<b>DESCRIPTION</b>" => "Current pension fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_pension_total);
    #handle provident deduction ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Provident' AND type = 'DEDV' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($empded_data = pg_fetch_array($rslt)) {
        $deduction_provident_total += $empded_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4003", "<b>DESCRIPTION</b>" => "Current provident fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_provident_total);
    #handle medical DEDUCTIONS in income table ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Medical Contribution' AND type = 'DEDM' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $deduction_medical_total2 += $empinc_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4005", "<b>DESCRIPTION</b>" => "Medical Contribution", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_medical_total2);
    #handle retirement annuity deduction ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Retirement Annuity Fund' AND type = 'DEDR' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($empded_data = pg_fetch_array($rslt)) {
        $deduction_retirementann_total += $empded_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4006", "<b>DESCRIPTION</b>" => "Current retirement annuity fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_retirementann_total);
    $sql = "SELECT * FROM emp_ded WHERE emp='{$empnum}' AND description!='UIF' AND description!='SDL' AND description!='PAYE' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($empded_data = pg_fetch_array($rslt)) {
        $deduction_premiumpol_total += $empded_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4018", "<b>DESCRIPTION</b>" => "Premiums paid on loss of income policies", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_premiumpol_total);
    //old all encapsulating search ... only first to description checks were orginal ...
    //	$sql = "SELECT * FROM emp_ded WHERE emp='$empnum' AND description!='UIF' AND description!='SDL' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund'";
    //	$rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    //	while ($empded_data = pg_fetch_array($rslt)) {
    //		if ($empded_data["type"] != "PAYE") {
    //			$deductions_out[] = array (
    //				"<b>CODE</b>"=>"$empded_data[code]",
    //				"<b>DESCRIPTION</b>"=>"$empded_data[description]",
    //				"<b>CLEARANCE NO</b>"=>"",
    //				"<b>AMOUNT</b>"=>(int)$empded_data["amount"]
    //			);
    //		}
    //	}
    // cant just remove whatever deductions is on system if they havent actually been applied to salary (ie. salary processed)
    // this value will come from same place as the rest of the income/deductions ... wth
    //	db_conn("cubit");
    //	$sql = "SELECT * FROM empdeduct WHERE empnum='$empnum'";
    //	$empded_rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.'");
    //
    //	while ($empded_data = pg_fetch_array($empded_rslt)) {
    //		db_conn("cubit");
    //		$sql = "SELECT deduction, code FROM salded WHERE id='$empded_data[dedid]' AND deduction!='UIF'";
    //		$rslt = db_exec($sql) or errDie("Unable to retrieve deduction information from Cubit.");
    //		$ded_data = pg_fetch_array($rslt);
    //
    //		$deductions_out[] = array (
    //			"<b>CODE</b>"=>"$ded_data[code]",
    //			"<b>DESCRIPTION</b>"=>"$ded_data[deduction]",
    //			"<b>CLEARANCE NO</b>"=>"$empded_data[clearance_no]",
    //			"<b>AMOUNT</b>"=>(int)$empded_data["amount"], 2
    //		);
    //	}
    if (!isset($deductions_out[0])) {
        $deductions_out = array(array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => ""));
    }
    $deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>CLEARANCE NO</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70));
    // Employees Tax deductions-----------------------------------------------
    $tax_amt = 0;
    // Retrieve PAYE amount from Cubit
    db_conn("cubit");
    $sql = "SELECT * FROM emp_ded WHERE type='PAYE' AND emp = '{$empnum}' AND year = '{$cyear}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve PAYE deductions from Cubit");
    $paye_amount = 0;
    while ($empded_data = pg_fetch_array($rslt)) {
        // add 375 to site if salary, -375 if reverse salary
        $tax_amt += 375 * ($empded_data["amount"] > 0 ? 1 : -1);
        $paye_amount += $empded_data["amount"];
    }
    if ($tax_amt > $paye_amount) {
        $tax_amt = $paye_amount;
        $paye_amount = 0;
    } else {
        $paye_amount -= $tax_amt;
    }
    $tax_deductions_amount = $paye_amount + $tax_amt;
    $employees_tax_deductions_out = array(array("<b>CODE</b>" => "4101", "<b>DESCRIPTION</b>" => "STANDARD INCOME TAX ON EMPLOYEES-SITE", "<b>AMOUNT</b>" => sprint($tax_amt, 2)), array("<b>CODE</b>" => "4102", "<b>DESCRIPTION</b>" => "PAY AS YOU EARN - PAYE", "<b>AMOUNT</b>" => sprint($paye_amount, 2)), array("<b>CODE</b>" => "4103", "<b>DESCRIPTION</b>" => "TOTAL EMPLOYEES TAX", "<b>AMOUNT</b>" => sprint($tax_deductions_amount, 2)));
    $employees_tax_deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70));
    // -----------------------------------------------------------------------
    // Do the actual rendering of the pdf
    // -----------------------------------------------------------------------
    $pdf =& new Cezpdf();
    global $set_mainFont;
    $pdf->selectFont($set_mainFont);
    $pdf->addInfo("Title", "IRP 5 for {$empinfo['fnames']} {$empinfo['sname']}");
    $pdf->addInfo("Author", USER_NAME);
    $irp5_pos = drawText(&$pdf, "<b>IRP 5</b>", 14, 520 - $pdf->getTextWidth(14, "<b>IRP 5</b>"), 0);
    $header_pos = drawText(&$pdf, $header_out, 12, 520 - $pdf->getTextWidth(12, $header_out), $irp5_pos['y'] + 14);
    // Employer information --------------------------------------------------
    $employer_information_head = drawText(&$pdf, "<b>EMPLOYER INFORMATION</b>", 8, 0, $irp5_pos['y'] + 14);
    $employer_trading_name_pos = drawTable2(&$pdf, $employer_trading_name_out, 0, $employer_information_head['y'] + 2, 520, 1);
    $employer_irp5_number_pos = drawTable2(&$pdf, $employer_irp5_number_out, 0, $employer_trading_name_pos['y'], 260, 1);
    $employer_reference_number_pos = drawTable2(&$pdf, $employer_reference_number_out, 0, $employer_irp5_number_pos['y'], 260, 1);
    $employer_tax_year_pos = drawTable2(&$pdf, $employer_tax_year_out, 0, $employer_reference_number_pos['y'], 260, 1);
    $employer_diplomatic_indemnity_pos = drawTable2(&$pdf, $employer_diplomatic_indemnity_out, 0, $employer_tax_year_pos['y'], 260, 1);
    $employer_business_address_pos = drawTable2(&$pdf, $employer_business_address_out, $employer_irp5_number_pos['x'] + 20, $employer_trading_name_pos['y'], 240, 4);
    $employer_postal_code_pos = drawTable2(&$pdf, $employer_postal_code_out, $employer_irp5_number_pos['x'] + 20, $employer_business_address_pos['y'], 240, 1, $employer_postal_code_cols);
    // Employee information --------------------------------------------------
    $employee_information_head = drawText(&$pdf, "<b>EMPLOYEE INFORMATION</b>", 8, 0, $employer_postal_code_pos['y'] + 15);
    $employee_nature_pos = drawTable2(&$pdf, $employee_nature_out, 0, $employee_information_head['y'], 100, 1);
    $employee_surname_pos = drawTable2(&$pdf, $employee_surname_out, $employee_nature_pos['x'] + 20, $employee_information_head['y'], 400, 1);
    $employee_first_names_pos = drawTable2(&$pdf, $employee_first_names_out, 0, $employee_nature_pos['y'], 400, 1);
    $employee_initials_pos = drawTable2(&$pdf, $employee_initials_out, $employee_first_names_pos['x'] + 20, $employee_nature_pos['y'], 100, 1);
    $employee_identity_number_pos = drawTable2(&$pdf, $employee_identity_number_out, 0, $employee_first_names_pos['y'], 260, 1);
    $employee_residential_pos = drawTable2(&$pdf, $employee_residential_out, $employee_identity_number_pos['x'] + 20, $employee_first_names_pos['y'], 240, 4);
    $employee_postal_code_pos = drawTable2(&$pdf, $employee_postal_code_out, $employee_identity_number_pos['x'] + 20, $employee_residential_pos['y'], 240, 1, $employee_postal_code_cols);
    $employee_number_pos = drawTable2(&$pdf, $employee_number_out, $employee_identity_number_pos['x'] + 20, $employee_postal_code_pos['y'], 240, 1);
    $employee_passport_number_pos = drawTable2(&$pdf, $employee_passport_number_out, 0, $employee_identity_number_pos['y'], 260, 1);
    $employee_date_of_birth_pos = drawTable2(&$pdf, $employee_date_of_birth_out, 0, $employee_passport_number_pos['y'], 260, 1);
    $employee_cc_number_pos = drawTable2(&$pdf, $employee_cc_number_out, 0, $employee_date_of_birth_pos['y'], 260, 1);
    $employee_tax_number_pos = drawTable2(&$pdf, $employee_tax_number_out, 0, $employee_cc_number_pos['y'], 260, 1);
    // Tax calculation information -------------------------------------------
    $tax_calculation_head = drawText(&$pdf, "<b>TAX CALCULATION INFORMATION</b>", 8, 0, $employee_number_pos['y'] + 15);
    $tax_prd_employed_frm_pos = drawTable2(&$pdf, $tax_prd_employed_frm_out, 0, $tax_calculation_head['y'], 160, 1);
    $tax_prd_employed_to_pos = drawTable2(&$pdf, $tax_prd_employed_to_out, $tax_prd_employed_frm_pos['x'] + 20, $tax_calculation_head['y'], 160, 1);
    $tax_over_deduction_pos = drawTable2(&$pdf, $tax_over_deduction_out, $tax_prd_employed_to_pos['x'] + 20, $tax_calculation_head['y'], 160, 1);
    $tax_prd_in_year_pos = drawTable2(&$pdf, $tax_prd_in_year_out, 0, $tax_prd_employed_frm_pos['y'], 115, 1);
    $tax_prd_worked_pos = drawTable2(&$pdf, $tax_prd_worked_out, $tax_prd_in_year_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1);
    $tax_fixed_rate_income_pos = drawTable2(&$pdf, $tax_fixed_rate_income_out, $tax_prd_worked_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1);
    $tax_directive_number_pos = drawTable2(&$pdf, $tax_directive_number_out, $tax_fixed_rate_income_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1);
    // Income sources --------------------------------------------------------
    $income_sources_head = drawText(&$pdf, "<b>INCOME SOURCE</b>", 8, 0, $tax_prd_in_year_pos['y'] + 15);
    $income_sources_pos = drawTable2(&$pdf, $income_sources_out, 0, $income_sources_head['y'] + 2, 520, 20, $income_sources_cols, 1);
    $gross_remuneration_head = drawText(&$pdf, "<b>GROSS REMUNERATION</b>", 8, 0, $income_sources_pos['y'] + 15);
    $gross_remuneration_pos = drawTable2(&$pdf, $gross_remuneration_out, 0, $gross_remuneration_head['y'] + 2, 520, 5, $gross_remuneration_cols, 1);
    $deductions_head = drawText(&$pdf, "<b>DEDUCTIONS</b>", 8, 0, $gross_remuneration_pos['y'] + 15);
    $deductions_pos = drawTable2(&$pdf, $deductions_out, 0, $deductions_head['y'] + 2, 520, 15, $deductions_cols, 1);
    $employees_tax_deductions_head = drawText(&$pdf, "<b>EMPLOYEES TAX DEDUCTIONS</b>", 8, 0, $deductions_pos['y'] + 15);
    $employees_tax_deductions_pos = drawTable2(&$pdf, $employees_tax_deductions_out, 0, $employees_tax_deductions_head['y'] + 2, 520, 3, $employees_tax_deductions_cols, 1);
    // Footer note -----------------------------------------------------------
    $certificate_attatch = drawText(&$pdf, "Attach this certificate to your income tax return or retain it. / ", 6, 0, $employees_tax_deductions_pos['y'] + 10);
    $pdf->ezStream();
}
コード例 #4
0
function display($_POST)
{
    extract($_POST);
    global $PRDMON;
    #determine the date range based on period selection
    if (isset($year_to_process)) {
        switch ($year_to_process) {
            case "active":
                $fdate_year = getYearOfFinPrd(1);
                $fdate_month = $PRDMON[1];
                $fdate_day = "1";
                $tdate_year = getYearOfFinPrd(12);
                $tdate_month = $PRDMON[12];
                $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year));
                break;
            case "previous":
                $fdate_year = getYearOfFinPrd(1) - 1;
                $fdate_month = $PRDMON[1];
                $fdate_day = "1";
                $tdate_year = getYearOfFinPrd(12) - 1;
                $tdate_month = $PRDMON[12];
                $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year));
                break;
            default:
                $fdate_year = getYearOfFinPrd(1);
                $fdate_month = "03";
                $fdate_day = "01";
                $tdate_year = getYearOfFinPrd(12);
                $tdate_month = "02";
                $tdate_day = date("d", mktime(0, 0, 0, 3, 0, $tdate_year));
        }
    }
    // -----------------------------------------------------------------------
    // Sanity checks
    // -----------------------------------------------------------------------
    require_lib("validate");
    $v = new validate();
    // Does this employee number actually exist
    db_conn("cubit");
    $sql = "SELECT * FROM employees WHERE empnum='" . (int) $empnum . "' AND div='" . USER_DIV . "'";
    $empinf_rslt = db_exec($sql) or errDie("Unable to retrieve employee number from Cubit.");
    if (pg_num_rows($empinf_rslt) == 0) {
        $v->addError(0, "Employee number not found in Cubit.");
    }
    $v->isOk($fdate_month, "num", 1, 2, "Invalid from date (month)");
    $v->isOk($fdate_year, "num", 4, 4, "Invalid from date (year)");
    $v->isOk($tdate_month, "num", 1, 2, "Invalid to date (month)");
    $v->isOk($tdate_year, "num", 4, 4, "Invalid to date (year)");
    if ($fdate_month > 12) {
        $v->addError(0, "Invalid from date (month)");
    }
    if ($fdate_year < 1970 || $fdate_year > 2050) {
        $v->addError(0, "Invalid from date (year)");
    }
    if ($tdate_month > 12) {
        $v->addError(0, "Invalid to date (month)");
    }
    if ($tdate_year < 1970 || $tdate_year > 2050) {
        $v->addError(0, "Invalid to date (year)");
    }
    if ($fdate_day > getDaysInMonth((int) $fdate_month, $fdate_year)) {
        $v->addError(0, "Invalid from date (day)");
    }
    if ($tdate_day > getDaysInMonth((int) $tdate_month, $tdate_year)) {
        $v->addError(0, "Invalid to date (day)");
    }
    $from_time = mktime(0, 0, 0, $fdate_day, $fdate_month, $fdate_year);
    $to_time = mktime(0, 0, 0, $tdate_day, $tdate_month, $tdate_year);
    if ($from_time > $to_time) {
        $v->addError(0, "Invalid date range specified.");
    }
    if (isset($income_code)) {
        foreach ($income_code as $id => $value) {
            $v->isOk($income_code[$id], "numeric", 1, 4, "Invalid income code.");
            $v->isOk($income_description[$id], "string", 1, 80, "Invalid income description.");
            $v->isOk($income_rfind[$id], "string", 1, 30, "Invalid RF IND.");
            $v->isOk($income_amount[$id], "float", 1, 9, "Invalid income amount.");
        }
    }
    // Return the errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>{$e['msg']}</li>";
        }
        return slct($confirm);
    }
    $from_date = "{$fdate_year}-{$fdate_month}-{$fdate_day}";
    $to_date = "{$tdate_year}-{$tdate_month}-{$tdate_day}";
    $gross_taxable_annual_payments = 0.0;
    $gross_non_taxable_income = 0.0;
    $gross_retirement_funding_income = 0.0;
    $gross_non_retirement_funding_income = 0.0;
    $gross_remuneration = 0.0;
    db_conn("cubit");
    $sql = "SELECT * FROM compinfo";
    $compinfo_rslt = db_exec($sql) or errDie("Unable to retrieve company information from Cubit.");
    $compinfo = pg_fetch_array($compinfo_rslt);
    db_conn("cubit");
    $sql = "SELECT * FROM employees WHERE empnum='{$empnum}'";
    $empinfo_rslt = db_exec($sql) or errDie("Unable to retrieve employee information from Cubit.");
    $empinfo = pg_fetch_array($empinfo_rslt);
    $header_out = "<b>Return of payment for work & services from which no employees tax was deducted</b>";
    $employer_trading_name_out = array(array("<b>Trading or other name:</b> {$compinfo['compname']}"));
    $employer_irp5_number_out = array(array("<b>IT 3(a) number:</b> {$irp5_number}"));
    $employer_reference_number_out = array(array("<b>Reference number:</b> {$empinfo['taxref']}"));
    $employer_tax_year_out = array(array("<b>Tax year:</b> {$fdate_year}"));
    $employer_diplomatic_indemnity_out = array(array("<b>Diplomatic indemnity:</b> {$compinfo['diplomatic_indemnity']}"));
    $employer_business_address_out = array(array("<b>Employer business address:</b>"), array("{$compinfo['addr1']}"), array("{$compinfo['addr2']}"), array("{$compinfo['addr3']}"));
    $employer_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$compinfo['addr4']}"));
    $employer_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right"));
    // Extract the employee's birth date from her id number
    $bd_year = 1900 + substr($empinfo["idnum"], 0, 2);
    $bd_month = substr($empinfo["idnum"], 2, 2);
    $bd_day = substr($empinfo["idnum"], 4, 2);
    $employee_nature_out = array(array("<b>Nature of Person:</b> {$empinfo['nature']}"));
    $employee_surname_out = array(array("<b>Employee surname or trading name:</b> {$empinfo['sname']}"));
    $employee_first_names_out = array(array("<b>First two names:</b> {$empinfo['fnames']}"));
    $fnames = explode(" ", $empinfo["fnames"]);
    $initials = "";
    foreach ($fnames as $name) {
        $initials .= strtoupper($name[0]);
    }
    $employee_initials_out = array(array("<b>Initials:</b> {$initials}"));
    $employee_identity_number_out = array(array("<b>Identity number:</b> {$empinfo['idnum']}"));
    $employee_passport_number_out = array(array("<b>Passport number:</b> {$empinfo['passport_number']}"));
    $employee_date_of_birth_out = array(array("<b>Date of birth:</b> {$bd_year}-{$bd_month}-{$bd_day}"));
    $employee_cc_number_out = array(array("<b>Company/CC/Trust number:</b> {$empinfo['cc_number']}"));
    $employee_tax_number_out = array(array("<b>Income Tax number:</b> {$empinfo['tax_number']}"));
    $employee_residential_out = array(array("<b>Employees residential address:</b>"), array("{$empinfo['res1']}"), array("{$empinfo['res2']}"), array("{$empinfo['res3']}"));
    $employee_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$empinfo['res4']}"));
    $employee_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right"));
    $employee_number_out = array(array("<b>Employee Number:</b> {$empinfo['empnum']}"));
    $tax_prd_employed_frm_out = array(array("<b>Period employed from:</b> {$prd_employed_frm}"));
    $tax_prd_employed_to_out = array(array("<b>Period employed to:</b> {$prd_employed_to}"));
    $tax_directive_number_out = array(array("<b>Directive number:</b> {$directive_number}"));
    // Income sources --------------------------------------------------------
    $income_sources_out = array();
    $income_taxable_total = 0;
    $income_reimburse_total = 0;
    $income_travelallowance_total = 0;
    $income_subsis_total = 0;
    $income_otherallowance_total = 0;
    $deduction_motorcar_total = 0;
    db_conn("cubit");
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Basic Salary'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_taxable_total += $empinc_data["amount"];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3601", "<b>DESCRIPTION</b>" => "Income Taxable", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_taxable_total);
    #handle travel allowances ....
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description = 'Travel Allowance' AND type = 'INCT'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_travelallowance_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3701", "<b>DESCRIPTION</b>" => "Travel Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_travelallowance_total);
    #handle reimbursements ....
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description!='Basic Salary' AND ex = 'RBS'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_reimburse_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3702", "<b>DESCRIPTION</b>" => "Reimbursements", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_reimburse_total);
    #handle subsistance allowances ....
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND ex = 'SUBS' AND type = '2'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_subsis_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3704", "<b>DESCRIPTION</b>" => "Subsistance Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_subsis_total);
    #handle other allowances ....
    $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND description != 'Travel Allowance' AND ex != 'SUBS' AND ex != 'RBS' AND type = '2'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $income_otherallowance_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3713", "<b>DESCRIPTION</b>" => "Other Allowances", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_otherallowance_total);
    #handle motorcar DEDUCTIONS in income table ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND (description = 'Motorcar 1 Contribution for Use' OR description = 'Motorcar 2 Contribution for Use') AND (type = 'DEDA' OR type = 'DEDB')";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit.");
    while ($empinc_data = pg_fetch_array($rslt)) {
        $deduction_motorcar_total += $empinc_data['amount'];
    }
    $income_sources_out[] = array("<b>CODE</b>" => "3802", "<b>DESCRIPTION</b>" => "Use Of Motor Vehicle", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_motorcar_total);
    if (!empty($nincome_code) || !empty($nincome_description) || !empty($nincome_rfind) || !empty($nincome_amount)) {
        $income_sources_out[] = array("<b>CODE</b>" => "{$nincome_code}", "<b>DESCRIPTION</b>" => "{$nincome_description}", "<b>RF IND</b>" => "{$nincome_rfind}", "<b>AMOUNT</b>" => (int) $nincome_amount);
    }
    if (isset($income_code)) {
        foreach ($income_code as $id => $value) {
            if ($income_code[$id] != 0) {
                $income_sources_out[] = array("<b>CODE</b>" => "{$income_code[$id]}", "<b>DESCRIPTION</b>" => "{$income_description[$id]}", "<b>RF IND</b>" => "{$income_rfind[$id]}", "<b>AMOUNT</b>" => (int) $income_amount[$id]);
            } else {
                $income_sources_out[] = array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => "");
            }
        }
    }
    $income_sources_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>RF IND</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70));
    // Gross renumeration ----------------------------------------------------
    // Taxable annual payments
    db_conn("cubit");
    $sql = "SELECT * FROM emp_inc WHERE code='3695' AND emp = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit.");
    while ($emp_inc_data = pg_fetch_array($rslt)) {
        $gross_taxable_annual_payments += $emp_inc_data["amount"];
    }
    db_conn("cubit");
    $sql = "SELECT * FROM emp_income_sources WHERE code='3695' AND empnum = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit.");
    while ($emp_income_sources_data = pg_fetch_array($rslt)) {
        $gross_taxable_annual_payments += $emp_income_sources_data["amount"];
    }
    // Non taxable annual payments
    db_conn("cubit");
    $sql = "SELECT * FROM emp_inc WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND emp = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit.");
    while ($emp_inc_data = pg_fetch_array($rslt)) {
        $gross_non_taxable_income += $emp_inc_data["amount"];
    }
    db_conn("cubit");
    $sql = "SELECT * FROM emp_income_sources WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND empnum = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit.");
    while ($emp_income_sources_data = pg_fetch_array($rslt)) {
        $gross_non_taxable_income += $emp_income_sources_data["amount"];
    }
    // Gross retirement funding income
    db_conn("cubit");
    $sql = "SELECT emp_pension, emp_ret FROM employees WHERE empnum='{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve gross retrirement funding from Cubit.");
    $emp_data = pg_fetch_array($rslt);
    $gross_retirement_funding_income += $gross_non_taxable_income / 100 * $emp_data["emp_pension"] + $emp_data["emp_ret"];
    // Gross non retirement funding income
    db_conn("cubit");
    $sql = "SELECT * FROM emp_inc WHERE (code!='3603' OR code!='3604' OR code!='3610' OR code!='3615') AND emp = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit.");
    while ($emp_inc_data = pg_fetch_array($rslt)) {
        $gross_non_retirement_funding_income += $emp_inc_data["amount"];
    }
    db_conn("cubit");
    $sql = "SELECT * FROM emp_income_sources WHERE (code != '3603' OR code != '3604' OR code != '3610' OR code != '3615') AND empnum = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit.");
    while ($emp_income_sources_data = pg_fetch_array($rslt)) {
        $gross_non_retirement_funding_income += $emp_income_sources_data["amount"];
    }
    // Gross Remuneration
    $gross_remuneration = $gross_retirement_funding_income + $gross_non_retirement_funding_income;
    $gross_remuneration_out = array(array("<b>CODE</b>" => "3696", "<b>DESCRIPTION</b>" => "GROSS NON-TAXABLE INCOME", "<b>AMOUNT</b>" => (int) $gross_non_taxable_income), array("<b>CODE</b>" => "3697", "<b>DESCRIPTION</b>" => "GROSS RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_retirement_funding_income), array("<b>CODE</b>" => "3698", "<b>DESCRIPTION</b>" => "GROSS NON-RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_non_retirement_funding_income), array("<b>CODE</b>" => "3699", "<b>DESCRIPTION</b>" => "GROSS REMUNERATION", "<b>AMOUNT</b>" => (int) $gross_remuneration));
    $gross_remuneration_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70));
    // Deductions ------------------------------------------------------------
    $deductions_out = array();
    $deduction_pension_total = 0;
    $deduction_provident_total = 0;
    $deduction_medicalaid_total = 0;
    $deduction_retirementann_total = 0;
    $deduction_premiumpol_total = 0;
    db_conn("cubit");
    #handle pension deduction ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Pension' AND type = 'DEDP'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($empded_data = pg_fetch_array($rslt)) {
        $deduction_pension_total += $empded_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4001", "<b>DESCRIPTION</b>" => "Current pension fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_pension_total);
    #handle provident deduction ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Provident' AND type = 'DEDV'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($empded_data = pg_fetch_array($rslt)) {
        $deduction_provident_total += $empded_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4003", "<b>DESCRIPTION</b>" => "Current provident fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_provident_total);
    #handle retirement annuity deduction ...
    $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Retirement Annuity Fund' AND type = 'DEDR'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($empded_data = pg_fetch_array($rslt)) {
        $deduction_retirementann_total += $empded_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4006", "<b>DESCRIPTION</b>" => "Current retirement annuity fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_retirementann_total);
    $sql = "SELECT * FROM emp_ded WHERE emp='{$empnum}' AND description!='UIF' AND description!='SDL' AND description!='PAYE' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.");
    while ($empded_data = pg_fetch_array($rslt)) {
        $deduction_premiumpol_total += $empded_data['amount'];
    }
    $deductions_out[] = array("<b>CODE</b>" => "4018", "<b>DESCRIPTION</b>" => "Premiums paid on loss of income policies", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_premiumpol_total);
    //	db_conn("cubit");
    //	$sql = "SELECT * FROM empdeduct WHERE empnum='$empnum'";
    //	$empded_rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.'");
    //
    //	while ($empded_data = pg_fetch_array($empded_rslt)) {
    //		db_conn("cubit");
    //		$sql = "SELECT deduction, code FROM salded WHERE id='$empded_data[dedid]'";
    //		$rslt = db_exec($sql) or errDie("Unable to retrieve deduction information from Cubit.");
    //		$ded_data = pg_fetch_array($rslt);
    //
    //		$deductions_out[] = array (
    //			"<b>CODE</b>"=>"$ded_data[code]",
    //			"<b>DESCRIPTION</b>"=>"$ded_data[deduction]",
    //			"<b>CLEARANCE NO</b>"=>"$empded_data[clearance_no]",
    //			"<b>AMOUNT</b>"=>(int)$empded_data["amount"], 2
    //		);
    //	}
    if (!isset($deductions_out[0])) {
        $deductions_out = array(array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => ""));
    }
    $deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>CLEARANCE NO</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70));
    // Employees Tax deductions-----------------------------------------------
    $site_amount = 0;
    // Retrieve PAYE amount from Cubit
    db_conn("cubit");
    $sql = "SELECT * FROM emp_ded WHERE type='PAYE' AND emp = '{$empnum}'";
    $rslt = db_exec($sql) or errDie("Unable to retrieve PAYE deductions from Cubit");
    $paye_amount = 0;
    while ($empded_data = pg_fetch_array($rslt)) {
        $paye_amount += $empded_data["amount"];
    }
    // Total tax deductions
    $tax_deductions_amount = $site_amount + $paye_amount;
    $non_deduction_of_tax_out = array(array("<b>CODE</b>" => "01", "<b>DESCRIPTION</b>" => "DIRECTORS REMUNERATION - PRIVATE COMPANY / CC"), array("<b>CODE</b>" => "02", "<b>DESCRIPTION</b>" => "LESS THAN THE TAX THRESHOLD"), array("<b>CODE</b>" => "03", "<b>DESCRIPTION</b>" => "INDEPENDENT CONTRACTOR"), array("<b>CODE</b>" => "04", "<b>DESCRIPTION</b>" => "NON TAXABLE EARNINGS"));
    $non_deduction_of_tax_cols = array("<b>CODE</b>" => array("width" => 40));
    if (!isset($reason_code)) {
        $reason_code = "";
    }
    $reason_out = array(array("{$reason_code}"));
    // -----------------------------------------------------------------------
    // Do the actual rendering of the pdf
    // -----------------------------------------------------------------------
    $pdf =& new Cezpdf();
    global $set_mainFont;
    $pdf->selectFont($set_mainFont);
    $pdf->addInfo("Title", "IT 3(a) for {$empinfo['fnames']} {$empinfo['sname']}");
    $pdf->addInfo("Author", USER_NAME);
    $irp5_pos = drawText(&$pdf, "<b>IT 3(a)</b>", 14, 520 - $pdf->getTextWidth(14, "<b>IT 3(a)</b>"), 0);
    $header_pos = drawText(&$pdf, $header_out, 10, 520 - $pdf->getTextWidth(10, $header_out), $irp5_pos['y'] + 14);
    // Employer information --------------------------------------------------
    $employer_information_head = drawText(&$pdf, "<b>EMPLOYER INFORMATION</b>", 8, 0, $irp5_pos['y'] + 14);
    $employer_trading_name_pos = drawTable2(&$pdf, $employer_trading_name_out, 0, $employer_information_head['y'] + 2, 520, 1);
    $employer_irp5_number_pos = drawTable2(&$pdf, $employer_irp5_number_out, 0, $employer_trading_name_pos['y'], 260, 1);
    $employer_reference_number_pos = drawTable2(&$pdf, $employer_reference_number_out, 0, $employer_irp5_number_pos['y'], 260, 1);
    $employer_tax_year_pos = drawTable2(&$pdf, $employer_tax_year_out, 0, $employer_reference_number_pos['y'], 260, 1);
    $employer_diplomatic_indemnity_pos = drawTable2(&$pdf, $employer_diplomatic_indemnity_out, 0, $employer_tax_year_pos['y'], 260, 1);
    $employer_business_address_pos = drawTable2(&$pdf, $employer_business_address_out, $employer_irp5_number_pos['x'] + 20, $employer_trading_name_pos['y'], 240, 4);
    $employer_postal_code_pos = drawTable2(&$pdf, $employer_postal_code_out, $employer_irp5_number_pos['x'] + 20, $employer_business_address_pos['y'], 240, 1, $employer_postal_code_cols);
    // Employee information --------------------------------------------------
    $employee_information_head = drawText(&$pdf, "<b>EMPLOYEE INFORMATION</b>", 8, 0, $employer_postal_code_pos['y'] + 15);
    $employee_nature_pos = drawTable2(&$pdf, $employee_nature_out, 0, $employee_information_head['y'], 100, 1);
    $employee_surname_pos = drawTable2(&$pdf, $employee_surname_out, $employee_nature_pos['x'] + 20, $employee_information_head['y'], 400, 1);
    $employee_first_names_pos = drawTable2(&$pdf, $employee_first_names_out, 0, $employee_nature_pos['y'], 400, 1);
    $employee_initials_pos = drawTable2(&$pdf, $employee_initials_out, $employee_first_names_pos['x'] + 20, $employee_nature_pos['y'], 100, 1);
    $employee_identity_number_pos = drawTable2(&$pdf, $employee_identity_number_out, 0, $employee_first_names_pos['y'], 260, 1);
    $employee_residential_pos = drawTable2(&$pdf, $employee_residential_out, $employee_identity_number_pos['x'] + 20, $employee_first_names_pos['y'], 240, 4);
    $employee_postal_code_pos = drawTable2(&$pdf, $employee_postal_code_out, $employee_identity_number_pos['x'] + 20, $employee_residential_pos['y'], 240, 1, $employee_postal_code_cols);
    $employee_number_pos = drawTable2(&$pdf, $employee_number_out, $employee_identity_number_pos['x'] + 20, $employee_postal_code_pos['y'], 240, 1);
    $employee_passport_number_pos = drawTable2(&$pdf, $employee_passport_number_out, 0, $employee_identity_number_pos['y'], 260, 1);
    $employee_date_of_birth_pos = drawTable2(&$pdf, $employee_date_of_birth_out, 0, $employee_passport_number_pos['y'], 260, 1);
    $employee_cc_number_pos = drawTable2(&$pdf, $employee_cc_number_out, 0, $employee_date_of_birth_pos['y'], 260, 1);
    $employee_tax_number_pos = drawTable2(&$pdf, $employee_tax_number_out, 0, $employee_cc_number_pos['y'], 260, 1);
    // Tax calculation information -------------------------------------------
    $tax_calculation_head = drawText(&$pdf, "<b>TAX CALCULATION INFORMATION</b>", 8, 0, $employee_number_pos['y'] + 15);
    $tax_prd_employed_frm_pos = drawTable2(&$pdf, $tax_prd_employed_frm_out, 0, $tax_calculation_head['y'], 160, 1);
    $tax_prd_employed_to_pos = drawTable2(&$pdf, $tax_prd_employed_to_out, $tax_prd_employed_frm_pos['x'] + 20, $tax_calculation_head['y'], 160, 1);
    drawTable2(&$pdf, $tax_directive_number_out, $tax_prd_employed_to_pos['x'] + 20, $tax_calculation_head['y'], 160, 1);
    // Income sources --------------------------------------------------------
    $income_sources_head = drawText(&$pdf, "<b>INCOME SOURCE</b>", 8, 0, $tax_prd_employed_frm_pos['y'] + 15);
    $income_sources_pos = drawTable2(&$pdf, $income_sources_out, 0, $income_sources_head['y'] + 2, 520, 20, $income_sources_cols, 1);
    $gross_remuneration_head = drawText(&$pdf, "<b>GROSS REMUNERATION</b>", 8, 0, $income_sources_pos['y'] + 15);
    $gross_remuneration_pos = drawTable2(&$pdf, $gross_remuneration_out, 0, $gross_remuneration_head['y'] + 2, 520, 4, $gross_remuneration_cols, 1);
    $deductions_head = drawText(&$pdf, "<b>DEDUCTIONS</b>", 8, 0, $gross_remuneration_pos['y'] + 15);
    $deductions_pos = drawTable2(&$pdf, $deductions_out, 0, $deductions_head['y'] + 2, 520, 15, $deductions_cols, 1);
    $non_deduction_of_tax_head = drawText(&$pdf, "<b>REASON FOR NON DEDUCTION OF EMPLOYEES TAX MUST BE STATED</b>", 8, 0, $deductions_pos['y'] + 15);
    $non_deduction_of_tax_pos = drawTable2(&$pdf, $non_deduction_of_tax_out, 0, $non_deduction_of_tax_head['y'] + 2, 420, 4, $non_deduction_of_tax_cols, 1);
    $reason_text = drawText(&$pdf, "<b>Reason Code</b>", 7, $non_deduction_of_tax_pos['x'] + 10, $non_deduction_of_tax_pos['y']);
    $reason_pos = drawTable2(&$pdf, $reason_out, $reason_text['x'] + 15, $non_deduction_of_tax_pos['y'] - 10, 40, 1);
    // Footer note -----------------------------------------------------------
    $certificate_attatch = drawText(&$pdf, "Attach this copy to your form IT 3", 6, 0, $non_deduction_of_tax_pos['y'] + 10);
    $pdf->ezStream();
}