<?php



function get_salary_component_value(&$salary, $record_type, $process_code, $employee, $payroll_run, $nopay_days =0, $nopay_reference_days_factor = 30)
{
    $employee_code = $employee['employee_code'];
    $payroll_days_factor = 1;
    
    if($record_type == SCT_GROUP_ADDITIONS || $record_type == SCT_GROUP_DEDUCTIONS){
        $employee_or_group = $employee['salary_group_id'];
    }
    else{
        $employee_or_group = $employee_code;
    }
    $my_row = select_salary_component($record_type, $process_code, $employee_or_group, $payroll_run);
    if($my_row == null){
//        return 0;
        return array("calculated_value" => 0, "full_value" => 0);
    }
   
    //---------------------------
    $applicable_start_date = $applicable_end_date = '';
    $applicable_days = get_payroll_calculation_applicable_values($payroll_run, $employee, 
                                                $my_row, $nopay_days, 
                                                $applicable_start_date, $applicable_end_date, $payroll_days_factor,
                                                $nopay_reference_days_factor);
    if($applicable_days == 0){
//        return 0;
        return array("calculated_value" => 0, "full_value" => 0);
    }
    //-----------------------------
    
    $salary_component_result = get_salary_component_calculation_result($salary, $employee_code, $payroll_run['id'], $my_row, $payroll_days_factor, "V");
    $salary_component_value = $salary_component_result[0];
    $comment = $salary_component_result[1];
    
    if($my_row['calculation_type'] == "V"){
        $full_value = $my_row['amount'];
    }
    else{
        $full_value = $salary_component_value;
    }
    
    if($my_row['deduction'] == 1){
        $salary_component_value = -$salary_component_value;
        $full_value = -$full_value;
    }
    
    if($my_row['calculation_type'] == "V" && $my_row['full_amount']){
        $salary_value = $full_value;
    }
    else{
        $salary_value = $salary_component_value;
    }
    insert_payroll_run_detail($payroll_run['id'], $employee_code, $process_code, $salary_value, $comment);
    
    // Calculated value depends on the $my_row['full_amount'] setting
    return array("calculated_value" => $salary_value, "full_value" => $full_value);
    
}




?>
