public function validateconfigAction($from_year = 0, $to_year = 0, $bunit = 0, $dept_id = 0, $dept_flag = 0, $mode = 0, $call_flag = 0, $is_edit = 0, $appraisal_id = 0, $existing_period = '')
 {
     //if ajax call(to year on change)
     if ($call_flag == 0) {
         $from_year = $this->_getParam('from_year', null);
         $to_year = $this->_getParam('to_year', null);
         $bunit = $this->_getParam('bunit', null);
         $dept_id = $this->_getParam('dept_id', null);
         $dept_flag = $this->_getParam('flag', null);
         $mode = $this->_getParam('mode', null);
         $is_edit = $this->_getParam('is_edit', null);
         $appraisal_id = $this->_getParam('appraisal_id', null);
         $existing_period = $this->_getParam('existing_period', null);
     }
     $dept = isset($dept_flag) && $dept_flag == 0 ? $dept_id : 0;
     $app_init_model = new Default_Model_Appraisalinit();
     $exist_appraisal = $app_init_model->checkappadmin($bunit, $dept_id);
     $json_status = 'fail';
     $json_msg_str = '';
     $json_app_mode = '';
     $json_app_period = 0;
     $json_app_disp_period = '';
     $json_is_exist = 0;
     $json_rating_type = '';
     $existing_app_flag = $app_init_model->getexistingperformanceappflag($bunit, $from_year, $to_year);
     $app_flag_diff = 0;
     if (isset($existing_app_flag) && $existing_app_flag != $dept_flag) {
         $app_flag_diff++;
     }
     if ($is_edit == 1) {
         //get the data for the appraisal based on id to compare from year, to year and period
         $appraisal_data = $app_init_model->getConfigData($appraisal_id);
         $appr_from_year = isset($appraisal_data[0]['from_year']) ? $appraisal_data[0]['from_year'] : 0;
         $appr_to_year = isset($appraisal_data[0]['to_year']) ? $appraisal_data[0]['to_year'] : 0;
         $appr_mode = isset($appraisal_data[0]['appraisal_mode']) ? $appraisal_data[0]['appraisal_mode'] : '';
         $appr_period = isset($appraisal_data[0]['appraisal_period']) ? $appraisal_data[0]['appraisal_period'] : 0;
         $appraisal_ratings = isset($appraisal_data[0]['appraisal_ratings']) ? $appraisal_data[0]['appraisal_ratings'] : 0;
         $actual_appr_period = $this->period_helper($appr_mode, $appr_period);
         if ($from_year == $appr_from_year && $to_year == $appr_to_year && $existing_period == $actual_appr_period) {
             if ($call_flag == 0) {
                 $this->_helper->json(array('status' => 'success', 'msg_str' => $json_msg_str, 'app_mode' => $appr_mode, 'app_period' => $appr_period, 'app_disp_period' => $actual_appr_period, 'is_exist' => 1, 'rating_type' => $appraisal_ratings));
                 return;
             } else {
                 return 'success';
             }
         }
     }
     if ((!$exist_appraisal || $is_edit == 1) && $app_flag_diff == 0) {
         //get the existing appraisal data using business unit
         $appraisal_data = array();
         $json_status = 'success';
         // $json_mode = '';
         $appraisal_data = $app_init_model->getAppraisalPeriodOnBuDept($bunit, $dept, $from_year, $to_year, 'AND');
         $year_diff_exist = 0;
         if (empty($appraisal_data)) {
             $appraisal_data_diff = array();
             //calculate the difference between toyear and from year
             // if(is_numeric($from_year) && is_numeric($to_year))
             // {
             $year_diff = $to_year - $from_year;
             // }
             //if year difference is 0
             if ($year_diff == 0) {
                 //check with from year or to year
                 $appraisal_data_diff = $app_init_model->getAppraisalPeriodOnBuDept($bunit, $dept, $from_year, $to_year, 'OR');
                 if (!empty($appraisal_data_diff)) {
                     $year_diff_exist++;
                 }
             } else {
                 if ($year_diff == 1) {
                     //check with from year or (to year - 1)
                     $to_in_year = $to_year - 1;
                     $appraisal_data_diff = $app_init_model->getAppraisalPeriodOnBuDept($bunit, $dept, $from_year, $to_in_year, 'AND');
                     if (!empty($appraisal_data_diff)) {
                         $year_diff_exist++;
                     }
                 }
             }
             // if($year_diff_exist == 0 && $dept_flag == 0)
             // {
             // $appraisal_data = $app_init_model->getAppraisalPeriodOnBuDept($bunit,$dept,$from_year,$to_year,'AND',1);
             // }
         }
         $exist_flag = 0;
         $exist_str = '';
         if (!$year_diff_exist) {
             if (!empty($appraisal_data)) {
                 foreach ($appraisal_data as $app_data) {
                     $appraisal_mode = !empty($app_data['appraisal_mode']) ? $app_data['appraisal_mode'] : '';
                     $appraisal_period = !empty($app_data['appraisal_period']) ? $app_data['appraisal_period'] : 0;
                     // $appraisal_id = !empty($app_data['id'])?$app_data['id']:0;
                     switch ($appraisal_mode) {
                         case 'Quarterly':
                             if ($appraisal_period <= 4) {
                                 $exist_flag++;
                                 // $exist_str .= $appraisal_id.',';
                             }
                             break;
                         case 'Half-yearly':
                             if ($appraisal_period <= 2) {
                                 $exist_flag++;
                                 // $exist_str .= $appraisal_id.',';
                             }
                             break;
                         case 'Yearly':
                             if ($appraisal_period <= 1) {
                                 $exist_flag++;
                                 // $exist_str .= $appraisal_id.',';
                             }
                             break;
                     }
                 }
                 if ($exist_flag > 0) {
                     // $json_status = 'fail';
                     $exist_dept_flag = isset($appraisal_data[0]['performance_app_flag']) ? $appraisal_data[0]['performance_app_flag'] : '';
                     //if existing
                     // $json_app_mode = '';
                     // $json_app_period = 0;
                     if ($dept_flag == $exist_dept_flag) {
                         $appraisal_mode = isset($appraisal_data[0]['appraisal_mode']) ? $appraisal_data[0]['appraisal_mode'] : '';
                         $appraisal_period = isset($appraisal_data[0]['appraisal_period']) ? $appraisal_data[0]['appraisal_period'] : 0;
                         $appraisal_rating_type = isset($appraisal_data[0]['appraisal_ratings']) ? $appraisal_data[0]['appraisal_ratings'] : '';
                         $json_status = 'success';
                         switch ($appraisal_mode) {
                             case 'Quarterly':
                                 if ($appraisal_period <= 4) {
                                     $appraisal_period++;
                                     if ($appraisal_period > 4) {
                                         $json_status = 'fail';
                                     }
                                 }
                                 break;
                             case 'Half-yearly':
                                 if ($appraisal_period <= 2) {
                                     $appraisal_period++;
                                     if ($appraisal_period > 2) {
                                         $json_status = 'fail';
                                     }
                                 }
                                 break;
                             case 'Yearly':
                                 if ($appraisal_period <= 1) {
                                     $appraisal_period++;
                                     if ($appraisal_period > 1) {
                                         $json_status = 'fail';
                                     }
                                 }
                                 break;
                         }
                         if ($json_status == 'fail') {
                             $json_msg_str = 'Appraisal is completed for the selected years.';
                         } else {
                             $json_app_period = $appraisal_period;
                             $json_app_mode = $appraisal_mode;
                             $json_app_disp_period = $this->period_helper($json_app_mode, $json_app_period);
                             $json_rating_type = $appraisal_rating_type;
                         }
                         $json_is_exist = 1;
                     } else {
                         $json_status = 'fail';
                         $json_msg_str = 'Appraisal is already configured ' . ($exist_dept_flag == 1 ? 'business unit' : 'department') . ' wise.';
                         $json_app_mode = '';
                         $json_app_period = 1;
                     }
                 } else {
                     $json_status = 'success';
                     $json_msg_str = '';
                     $json_app_mode = '';
                     $json_app_period = 1;
                 }
             } else {
                 $json_status = 'success';
                 $json_msg_str = '';
                 $json_app_mode = '';
                 $json_app_period = 1;
             }
         } else {
             $json_status = 'fail';
             $json_msg_str = 'Please select valid year range.';
             $json_app_mode = '';
             $json_app_period = 0;
         }
     } else {
         $json_msg_str = 'Appraisal already exist.';
     }
     // echo 'status '.$json_status.' msg_str '.$json_msg_str.' app_mode '.$json_app_mode.' app_period '.$json_app_period.' is_exist '.$json_is_exist;
     // die();
     if ($call_flag == 0) {
         $this->_helper->json(array('status' => $json_status, 'msg_str' => $json_msg_str, 'app_mode' => $json_app_mode, 'app_period' => $json_app_period, 'app_disp_period' => $json_app_disp_period, 'is_exist' => $json_is_exist, 'rating_type' => $json_rating_type));
     } else {
         return $json_status;
     }
 }