<?php


function all_departments_new_and_resigned_employees_graph_display(&$pg, $company_code, $from_month_display_order, $to_month_display_order)
{
    all_departments_new_and_resigned_employees_graph_set_values($pg, $company_code, $from_month_display_order, $to_month_display_order);

    $random_id = 'adneeg_'.$company_code."_".$from_month_display_order."_".time();
    
    $pg->axis_value_names_angle = -30;
    
    $data = array();
    $data['title'] = "Recruitmets and Resignations";
    $data['x_axis_name'] = "Departments";
    $data['y_axis_name'] = "Count";
    $data['graph1_name'] = "Resignations";
    $data['graph2_name'] = "Recruitments";
    $data['graph3_name'] = "";
    
    
    //echo "<a href='".$path_to_root."/admin/dashboard_uda_level_1.php?month_id=".$month_id."&division_code=UDA_0001&level=".$level."'>";
    display_graph($pg, $data, 1, $random_id);
//    source_graphic($today, $title, , $pg, "Target", _("Achievement"), 1, $random_id, "Trend");
    //echo "</a>";
}


function all_departments_new_and_resigned_employees_graph_set_values(&$pg, $group_company_code, $from_month_display_order, $to_month_display_order) 
{

    if($group_company_code == "SAW"){
        $company_codes_in = "'SAW', 'SAWC', 'LPS'"; 
    }
    elseif($group_company_code == "VEE"){
        $company_codes_in = "'VEE', 'VEEC'"; 
    }
        
    $title = "";
    
//    $salary_components_in = "'TAKEHOME_BASIC',
//                    'BASIC_SALARY',
//                    'BRA_1',
//                    'BRA_2',
//                    'INCENTIVE',
//                    'BANKING_INCENTIVE_II',
//                    'BANKING_INCENTIVE',
//                    'BANKING_INCENTIVE_I',
//                    'VEHICLE_REIMBURSEMEN',
//                    'FUEL_ALLOWANCES',
//                    'MEAL_REIMBURSEMENT',
//                    'SITE_EXPENSES',
//                    'TRAVELLING_ALLOWANCE',
//                    'SPECIAL_PAYMENT',
//
//                    'INCENTIVE_ARREARS',
//                    'FUEL_REIMBURSEMENT_T',
//                    'MEAL_REIMBURSEMENT_T',
//                    'COMMISSION',
//                    'SAVINGS_COMMISSION',
//                    'DRIVING_ALLOWANCE',
//                    'SPECIAL_ATTENDANCE',
//                    'SPECIAL_PAYMENT1',
//                    'ATTENDANCE_INCENTIVE',
//                    'POWDER_COATING_ALL',      
//                    'EPF 12%',
//                    'ETF 3%',
//                    'OT_TOTAL '";
        $resigned_employee_in = SCVT_DEPARTMENT_RESIGNATIONS_COUNT;
        $new_employee_in = SCVT_DEPARTMENT_RECRUITMENT_COUNT;
        
//        $result = get_group_company_all_list_values($company_code, 'DEPARTMENTS');        
//        $result = get_summary_payrolls_departments($month_id, $company_codes_in, $salary_components_in);
        $result = get_group_company_all_list_values($group_company_code, 'DEPARTMENTS', "'Y'");
        
        $data = array();
        while ($myrow = db_fetch($result)) {
            $department = get_group_company_list_value($group_company_code, 'DEPARTMENTS', $myrow['value_code']);
            $name = $department["value_name"];
                
                $department_codes_in = "'".$myrow['value_code']."'";     
                $resignations = get_summary_payrolls_month_range_department_total($company_codes_in, $department_codes_in, $resigned_employee_in, $from_month_display_order, $to_month_display_order);
                
                $recruitments = get_summary_payrolls_month_range_department_total($company_codes_in, $department_codes_in, $new_employee_in, $from_month_display_order, $to_month_display_order);
                

//                $pg->y[$i] = $resignations;
//                $pg->z[$i] = $recruitments;
                
//                $recruitments = rand(0, 10);
                $line = array("name" =>$name, "resignations" => $resignations, "recruitments" => $recruitments);
                $data[] = $line;
        }
        
        array_multisort(array_column($data, "recruitments"), SORT_DESC, $data);

        $i = 0;
        foreach ($data as $value) {
            if ($pg != null) {
                $pg->x[$i] = $value['name'];
                
                $pg->y[$i] = $value['resignations'];
                $pg->z[$i] = $value['recruitments'];
                
                $pg->colour_type[$i] = set_bar_colour_type($value['recruitments']);
            }
            
            
            $i++;
        }
        
        return $title;

}



