<?php
/**********************************************************************
***********************************************************************/
function update_hold_salary($selected, $payroll_run_id, $hold_salary, $comment)
{
    $user = $_SESSION['wa_current_user']->user;
    $date = date('Y-m-d H:i:s');
    
    if($selected != '')
    {
        $sql = "UPDATE ".TB_PREF."hold_salary 
                SET
                    payroll_run_id = ".db_escape($payroll_run_id).",
                    hold_salary = ".db_escape($hold_salary).",
                    comment=".db_escape($comment).",
                    updated_by = ".db_escape($user).",
                    updated_on = ".db_escape($date)."
                WHERE 
                    id = ".db_escape($selected);
        
        db_query($sql, "Selected Hold Salary could not be updated");
    }
}

function add_hold_salary($employee_code, $payroll_run_id, $hold_salary, $comment)
{
    $user = $_SESSION['wa_current_user']->user;
    $date = date('Y-m-d H:i:s');
    
        $sql = "INSERT INTO ".TB_PREF."hold_salary
                        (employee_code, 
                        payroll_run_id, hold_salary, 
                        comment, 
                        created_by, created_on) 
                VALUES
                        (".db_escape($employee_code).","
                        .db_escape($payroll_run_id).",".db_escape($hold_salary).","
                        .db_escape($comment).","
                        .db_escape($user).",".db_escape($date).")";
        
        db_query($sql, "Hold Salary could not be added");    
}
////
function delete_hold_salary($id)
{
	$sql="DELETE FROM ".TB_PREF."hold_salary 
                    WHERE 
                        id=".db_escape($id);

	db_query($sql,"Selected Hold Salary could not be deleted");
}
////
function get_hold_salary($id)
{
	$sql="SELECT * FROM ".TB_PREF."hold_salary 
                WHERE 
                    id=".db_escape($id);

	$result = db_query($sql,"Selected Hold Salary could not be retrieved");
	return db_fetch($result);
}

function get_all_hold_salaries($employee_code) {
    $sql = "SELECT hs.*,
                    pr.description payroll_run
        FROM ".TB_PREF."hold_salary hs, 
                ".TB_PREF."payroll_runs pr
        WHERE 
            hs.payroll_run_id = pr.id AND 
            hs.employee_code = ".  db_escape($employee_code);
        
    return  db_query($sql, "Could not get hold salaries");
}
?>