<?php

function display_reopen_salary_adjustment_additions() {
    global $payroll_approval_statuses;
    
    display_heading('Salary Additions');
    
    start_table(TABLESTYLE, "width=80%");

        $th = array(_("Id"), _("Employee Code"), _("Employee Name"), _("Created On"), _("Type"), _("Amount"), _("Due Date"), _("Comment"), _("Status"), _("Select"));
        table_header($th);
        
        $k = 0;
        $result = get_approved_salary_additions();
            while ($myrow = db_fetch($result)) {
                alt_table_row_color($k);
                    label_cell($myrow["id"], "align=center");
                    label_cell($myrow["employee_code"], "align=center");
                    label_cells('',$myrow["initials"]." ".$myrow["last_name"]." (".$myrow["first_name"].")");
                    label_cell(sql2date($myrow["created_on"]),"align=center");
                    label_cells('',$myrow["type_name"],"align=center");
                    qty_cell($myrow["amount"], false, 2);
                    label_cell(sql2date($myrow["due_date"]),"align=center");
                    label_cells('',$myrow["comments"]);
                    label_cell($payroll_approval_statuses[$myrow["status_code"]],"align=center");
                    check_cells('', 'selected_'.$myrow["rec_id"],0, false, false,"align=center");
                end_row();
            }

    end_table(2);
}

function display_reopen_salary_adjustment_deductions() {
    global $payroll_approval_statuses;
    
    display_heading('Salary Deductions');

    start_table(TABLESTYLE, "width=80%");

        $th = array(_("Id"), _("Employee Code"), _("Employee Name"), _("Created On"), _("Type"), _("Amount"), _("Due Date"), _("Comment"), _("Status"), _("Select"));
        table_header($th);

        $k = 0; //row colour counter
        $result = get_approved_salary_deductions();
            while ($myrow = db_fetch($result)) {
                alt_table_row_color($k);
                    label_cell($myrow["id"], "align=center");
                    label_cell($myrow["employee_code"], "align=center");
                    label_cells('',$myrow["initials"]." ".$myrow["last_name"]." (".$myrow["first_name"].")");
                    label_cell(sql2date($myrow["created_on"]),"align=center");
                    label_cells('',$myrow["type_name"],"align=center");
                    qty_cell($myrow["amount"], false, 2);
                    label_cell(sql2date($myrow["due_date"]),"align=center");
                    label_cells('',$myrow["comments"]);
                    label_cell($payroll_approval_statuses[$myrow["status_code"]],"align=center");
                    check_cells('', 'selected_'.$myrow["rec_id"],0, false, false,"align=center");
                end_row();
            }

    end_table(2);    
}

function display_reopen_salary_adjustment_advances() {
    global $payroll_approval_statuses;

    display_heading('Salary Advances');
    
    start_table(TABLESTYLE, "width=80%");

        $th = array(_("Id"), _("Employee Code"), _("Employee Name"), _("Created On"), _("Type"), _("Amount"), _("Date Date"), _("Comment"), _("Status"), _("Select"));
        table_header($th);

        $k = 0; //row colour counter
        $result = get_approved_salary_advances();
            while ($myrow = db_fetch($result)) {
                alt_table_row_color($k);
                    label_cell($myrow["id"], "align=center");
                    label_cell($myrow["employee_code"], "align=center");
                    label_cells('',$myrow["initials"]." ".$myrow["last_name"]." (".$myrow["first_name"].")");
                    label_cell(sql2date($myrow["created_on"]),"align=center");
                    label_cells('',$myrow["type_name"],"align=center");
                    qty_cell($myrow["amount"], false, 2);
                    label_cell(sql2date($myrow["due_date"]),"align=center");
                    label_cells('',$myrow["comments"]);
                    label_cell($payroll_approval_statuses[$myrow["status_code"]],"align=center");
                    check_cells('', 'selected_'.$myrow["rec_id"],0, false, false,"align=center");
                end_row();
            }

    end_table(2);
}

function reopen_salary_adjustments($id, $employee_code, $type_name) {
    $status_code = 'U';
    $approval_status_array = array("'A'", "'L'");
    
    $type = substr($id,0,1);
    $row_id = substr($id,1);
    
        if ($type == "A") {
            $af_row = approve_salary_addition($row_id, $status_code, $approval_status_array);
        } elseif($type == "D") {
            $af_row = approve_salary_deduction($row_id, $status_code, $approval_status_array);
        } elseif($type == "V") {
            $af_row = approve_salary_advance($row_id, $status_code, $approval_status_array);
        }
        
        if ($af_row != 1) {
            $employee_name = get_employee_formatted_long_name($employee_code);
            return array('success' => false, 'message' => "Could not reopen employee $employee_name $type_name.");
        } else {
            return array('success' => true, 'message' => "");
        }
}

?>