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


function add_salary_component_grouping_details($list_value_id,
                            $print_ref, $print_seq){
	                
    $updated_by = $_SESSION['wa_current_user']->user;
    $updated_on = date('Y-m-d H:i:s');
     	
    $sql = "INSERT INTO ".TB_PREF."salary_component_grouping(
                        component_id, 
                        component_group_id, print_seq,
                        updated_by, updated_on)
            VALUES(".db_escape($list_value_id)."," 
                    .db_escape($print_ref).", ".db_escape($print_seq).", "
                    .db_escape($updated_by).", ".db_escape($updated_on).")";
	
	db_query($sql,"Calculation sequence could not be updated");		
}

function get_salary_component_grouping_details()
{  	
        $sql = "SELECT 
                    lv.id, lv.list_code, lc.list_name, lv.value_code, lv.value_name comp_name, lv.value_description,
                    gn.id salary_group_id,gn.value_name salary_group_name, scg.print_seq 
                FROM ".TB_PREF."list_values lv 
                        INNER JOIN ".TB_PREF."lists lc ON 
                                    lv.list_code = lc.list_code 
                        LEFT JOIN ".TB_PREF."salary_component_grouping scg ON
                                    scg.component_id = lv.id  
                        LEFT JOIN ".TB_PREF."list_values gn ON
                                    scg.component_group_id = gn.id  
                WHERE lv.list_code IN ('COMPANY_ADDITION_SALARY_COMP', 
                                    'COMPANY_DEDUCTION_SALARY_COMP', 
                                    'GROUP_ADDITION_SALARY_COMP', 
                                    'GROUP_DEDUCTION_SALARY_COMP',
                                    'EMPLOYEE_ADDITION_SALARY_COMP',
                                    'EMPLOYEE_DEDUCTION_SALARY_COMP',
                                    'EMPLOYEE_ALLOWANCES_OVER_USAGE',
                                    'ATTENDANCE_ALLOWANCES',
                                    'WORKTIME_DEFICITS',
                                    'PERFORMANCE_RATE_INCENTIVES',
                                    'PERFORMANCE_VALUE_INCENTIVES',
                                    'MOBILE_ALLOWANCES_OVER_USAGE')  
                ORDER BY gn.value_name, scg.print_seq, lv.value_name ";
                
	return db_query($sql,"Calculation sequences could not be retreived");
}

//function get_calculation_seq_detail($selected_id)
//{
//	$sql = "SELECT *    
//		FROM "
//                    .TB_PREF."payroll_calculation_seq    
//                WHERE 
//                    id = ".db_escape($selected_id);	
//	
//	$result = db_query($sql,"Calculation sequence detail could not be retreived");
//        return db_fetch($result);
//}


function delete_salary_component_grouping_details()
{
	$sql = "DELETE FROM ".TB_PREF."salary_component_grouping " ;   
                
	
	db_query($sql,"Salary Component Grouping details could not be deleted");

}

?>