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



function get_salary_total_configurations($payroll_id)
{       
        $sql = 	"SELECT lv.id, 
                        lv.value_name salary_total_name, 
                        lv.value_code salary_total_code,
                        stc.salary_function_id,
                        stc.salary_total,
                        stc.full_value,
                        sfn.value_name salary_function_name
                FROM ".TB_PREF."list_values lv
                      LEFT JOIN ".TB_PREF."salary_total_configuration stc ON 
                            lv.value_code = stc.salary_total AND stc.payroll_id = ". db_escape($payroll_id)."
                      LEFT JOIN ".TB_PREF."list_values sfn ON 
                            stc.salary_function_id = sfn.id 
                      LEFT JOIN ".TB_PREF."payroll_calculation_seq pcs ON 
                            lv.value_code = pcs.process_code 
                WHERE lv.list_code = 'SALARY_TOTALS' AND 
                        pcs.payroll_id = ". db_escape($payroll_id)." 
                ORDER BY pcs.seq_no, lv.value_name, lv.value_code";
        
       	$result = db_query($sql,"Could not retrieve unapproved salary additions");	
        
        return $result;
}




function delete_salary_configuration_info($payroll_id)
{
        $sql = "DELETE FROM ".TB_PREF."salary_total_configuration WHERE payroll_id =". db_escape($payroll_id);
	
	db_query($sql,"Could not delete the configuration details");	
        
        return db_num_affected_rows();		
}

function add_salary_configuration_info($payroll_id, $salary_total,$salary_function, $full_value)
{
	$added_by = $_SESSION['wa_current_user']->user;
        $added_on = date('Y-m-d H:i:s');
        
        $sql = "INSERT INTO ".TB_PREF."salary_total_configuration (
                    payroll_id, salary_total, 
                    salary_function_id, full_value,
                    created_by, created_on) 
                VALUES (" .db_escape($payroll_id).", ".db_escape($salary_total).", "
                    .db_escape($salary_function).", ".db_escape($full_value).", "
                    .db_escape($added_by).", ".db_escape($added_on).")";
	
	db_query($sql,"Could not add salary salary configuration");	
        
        return db_num_affected_rows();		
}

function get_salary_function_id($code)
{
     $sql = 	"SELECT lv.id
                 FROM ".TB_PREF."list_values lv
                 WHERE lv.value_code =".db_escape($code)." AND lv.list_code='SALARY_FUNCTIONS' ";
        
       	$result = db_query($sql,"Could not retrieve unapproved salary additions");	
        
        return db_fetch($result);
    
}


function get_salary_total_configuration_detail($payroll_id, $salary_total_code)
{       
        $sql = 	"SELECT *  
                FROM ".TB_PREF."salary_total_configuration 
                WHERE payroll_id =".db_escape($payroll_id)." AND salary_total =".db_escape($salary_total_code);
        
       	$result = db_query($sql,"Could not get_salary_total_configuration_details");	
        
        return db_fetch($result);
}
?>