<?php



function get_attendance_allowance_value($record_type, $process_code, $employee, $payroll_run)
{
    $employee_code = $employee['employee_code'];
    $payroll_days_factor = 1;
    
    $my_row = select_salary_component($record_type, $process_code, $employee_code, $payroll_run);
    if($my_row == null){
        return 0;
    }
   
    //---------------------------
//    $applicable_start_date = $applicable_end_date = '';
//    $applicable_days = get_payroll_calculation_applicable_values($payroll_run, $employee, 
//                                                $my_row['effective_date'], $my_row['end_date'], 
//                                                $applicable_start_date, $applicable_end_date, $payroll_days_factor);       
//    
//    if($applicable_days == 0){
//        return;
//    }
    
    //-----------------------------
    
    $no_of_valid_records = get_total_granted_attendance_days($payroll_run['id'], $employee_code, $process_code);

    if($no_of_valid_records > 0){
        $salary_component_result = get_salary_component_calculation_result($employee_code, $payroll_run['id'], $my_row, $payroll_days_factor, "S", $no_of_valid_records);
        $salary_component_value = $salary_component_result[0];
        if($salary_component_result[1] == ''){
            $comment = $no_of_valid_records." days";
        }
        else{
            $comment = $salary_component_result[1];
        }
    } 
    else{
        $salary_component_value = 0;
        $comment = '';
    }
    
    if($my_row['deduction'] == 1){
        $salary_component_value = -$salary_component_value;
    }
    
    insert_payroll_run_detail($payroll_run['id'], $employee_code, $process_code, $salary_component_value, $comment);
    
    return array("calculated_value" => $salary_component_value, "full_value" => $salary_component_value);
    
}


function get_total_granted_attendance_days($payroll_run_id, $employee_code, $process_code)
{ 
    $attendance_days_count = select_approved_attendance_records_summary($payroll_run_id, $employee_code, $process_code);
    if(!$attendance_days_count){
        $no_of_valid_records = 0;
    }
    else{
        $no_of_valid_records = $attendance_days_count['granted_days'];
        update_calculated_attendance_allowance_summary_record_status($attendance_days_count['id'], "L", $payroll_run_id);
    }
    
    return $no_of_valid_records;
}




?>
