<?php
/**********************************************************************
***********************************************************************/

function add_salary_function_detail($salary_function_id,$seq_no, $plus_minus,$salary_component_id, $full_value)
{
        $created_by = $_SESSION['wa_current_user']->user;
        $created_on = date('Y-m-d H:i:s');
        
        
	$sql = "INSERT INTO ".TB_PREF."salary_functions_details (
                    salary_function_id, seq_no, 
                    minus,componant_id,
                    full_value,
                    created_by, created_on) 
                VALUES (" .db_escape($salary_function_id).", ".db_escape($seq_no).", "
                    .db_escape($plus_minus).", ".db_escape($salary_component_id).", "
                    .db_escape($full_value).", "
                    .db_escape($created_by).", ".db_escape($created_on).")";
        
        db_query($sql,"Salary function detail could not be added");
        
        return db_insert_id();

}


function update_salary_function_detail($rec_id, $seq_no, $plus_minus,$salary_component_id, $full_value)
{

         $updated_by = $_SESSION['wa_current_user']->user;
         $updated_on = date('Y-m-d H:i:s');

        $sql = "UPDATE ".TB_PREF."salary_functions_details 
                SET 
                    seq_no=".db_escape($seq_no).",
                    minus=".db_escape($plus_minus).",
                    componant_id=".db_escape($salary_component_id).",
                    full_value=".db_escape($full_value).",
                    updated_by=".db_escape($updated_by).",
                    updated_on=".db_escape($updated_on)." 
                WHERE id=".db_escape($rec_id);

        db_query($sql,"Salary function detail could not be updated");
        
        return db_num_affected_rows();
}

function delete_salary_function_detail($rec_id)
{
        $sql = "DELETE FROM ".TB_PREF."salary_functions_details  
                WHERE id=".db_escape($rec_id);

        db_query($sql,"Salary function detail could not be deleted");
        
        return db_num_affected_rows();
}

function get_salay_function_detail_line($selected_id)
{
    $sql = "SELECT ou.*  
            FROM " 
                .TB_PREF."salary_functions_details ou 
            WHERE ou.id = ".db_escape($selected_id);
  

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


function get_salary_functions_details($salary_function_id)
{
    $sql = "SELECT sf.*,
                sct.list_name component_type_name,  
                sc.value_code componant_code,
                sc.value_name componant_name
            FROM " 
                .TB_PREF."salary_functions_details sf, "
                .TB_PREF."lists sct, "
                .TB_PREF."list_values sc                    
            WHERE sf.salary_function_id = ".db_escape($salary_function_id)." AND 
                sct.list_code = sc.list_code AND 
                sf.componant_id = sc.id 
            ORDER BY sc.id";
  

    return db_query($sql, "Salary functions details could not be retrieved");
}





?>