Exemplo n.º 1
0
 public function savemngrorghierarchyAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $app_init_model = new Default_Model_Appraisalinit();
     $ques_temp_model = new Default_Model_Appraisalqstemp();
     $ques_org_model = new Default_Model_Appraisalqsmain();
     $app_rating_model = new Default_Model_Appraisalratings();
     // $init_id = $this->_getParam('init_id',null);
     $init_param = $this->_getParam('i', null);
     $init_id = sapp_Global::_decrypt($init_param);
     $init_data = $app_init_model->getConfigData($init_id);
     if (count($init_data) > 0) {
         $init_data = $init_data[0];
     }
     $this->view->init_id = $init_id;
     $this->view->init_data = $init_data;
     $this->view->msg_arr = array();
     $ratingsflag = 'false';
     $checkRatingsExists = $app_rating_model->getAppraisalRatingsbyInitId($init_id);
     if (!empty($checkRatingsExists)) {
         $ratingsflag = 'true';
     }
     $red_result = "";
     $type_arr = array('line' => 1, 'report' => 2);
     $trDb = Zend_Db_Table::getDefaultAdapter();
     //get manager ids as comma seperated string
     $manager_ids = $this->_getParam('mid', null);
     //break the manager ids into array
     $mngr_ids_array = explode(',', $manager_ids);
     $get_managers_data = array();
     $get_managers_data = $app_init_model->getManagers_report($init_id);
     $final_managers_data = array();
     //get the managers data and build an array with manager id as key
     if (isset($get_managers_data) && count($get_managers_data) > 0) {
         foreach ($get_managers_data as $data) {
             $mngr_id = isset($data['user_id']) ? $data['user_id'] : 0;
             $final_managers_data[$mngr_id] = $data;
         }
     }
     if (isset($mngr_ids_array) && count($mngr_ids_array) > 0) {
         $choose_option = 'report';
         foreach ($mngr_ids_array as $mngr) {
             $tot_ids = array();
             $context = 'add';
             $content = array();
             $content = $app_init_model->getdisplayacontentreportacc($init_id, $mngr);
             if ($context == 'add') {
                 $init_sdata = array('manager_level_type' => $type_arr[$choose_option]);
                 $app_result = array();
                 $app_result = $app_init_model->SaveorUpdateAppraisalInitData($init_sdata, " id = " . $init_id);
                 $qresult = '';
                 if ($app_result === 'update') {
                     if (count($content) > 0) {
                         foreach ($content as $cont) {
                             if (is_numeric($cont['user_id'])) {
                                 array_push($tot_ids, $cont['user_id']);
                             }
                         }
                     }
                     $line_str_arr = array();
                     $line_str_arr['line_manager_1'] = $mngr;
                     if (count($tot_ids) > 0) {
                         foreach ($tot_ids as $emp_id) {
                             $qdata = array('pa_initialization_id' => $init_id, 'manager_levels' => 1, 'employee_id' => $emp_id, 'module_flag' => 1, 'createdby' => $loginUserId, 'createdby_role' => $loginuserRole, 'createdby_group' => $loginuserGroup, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                             $qdata = array_merge($qdata, $line_str_arr);
                             if ($init_data['initialize_status'] == 1) {
                                 $qresult = $ques_org_model->SaveorUpdatePrivilegeData($qdata, '');
                             } else {
                                 $qresult = $ques_temp_model->SaveorUpdateData($qdata, '');
                             }
                         }
                     }
                 }
                 if ($qresult !== '' && $app_result !== '') {
                     $red_result = 'saved';
                 }
                 $message = "Appraisal process updated successfully";
             }
         }
         if ($red_result === 'saved') {
             $message = "Appraisal process updated successfully";
             $this->_helper->FlashMessenger()->setNamespace('conf_success')->addMessage($message);
             $this->_redirect('appraisalinit/confmanagers/i/' . sapp_Global::_encrypt($init_id));
         }
     }
     $this->view->ratingsflag = $ratingsflag;
     $this->render('configuremanagers');
 }
 public function initialize($appraisalid, $initflag)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserArr = array('loginuserid' => $loginUserId, 'loginuserrole' => $loginuserRole, 'loginusergroup' => $loginuserGroup);
     }
     $appraisalQsModel = new Default_Model_Appraisalquestions();
     $appraisalQsTmpModel = new Default_Model_Appraisalqstemp();
     $app_init_model = new Default_Model_Appraisalinit();
     $appraisalPrivTempModel = new Default_Model_Appraisalqstemp();
     $appraisalPrivMainModel = new Default_Model_Appraisalqsmain();
     $appraisalempratingsmodel = new Default_Model_Appraisalemployeeratings();
     $usersmodel = new Default_Model_Users();
     $departmentsmodel = new Default_Model_Departments();
     $announcementsModel = new Default_Model_Announcements();
     $deptids = '';
     $questions = '';
     $title = 'Performance Appraisal';
     $description = 'Performance appraisal initialized';
     $trDb = Zend_Db_Table::getDefaultAdapter();
     $trDb->beginTransaction();
     try {
         $data = $app_init_model->getConfigData($appraisalid);
         $appraisaldata = $data[0];
         $qsdataArr = $appraisalPrivTempModel->getAppraisalQuestions($appraisalid);
         if (!empty($qsdataArr)) {
             foreach ($qsdataArr as $qs) {
                 $questions .= $qs['hr_qs'] . ',';
             }
             $questions = rtrim($questions, ',');
         }
         $questions = implode(',', array_keys(array_flip(explode(',', $questions))));
         $initdata = array('initialize_status' => 2, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
         $initwhere = array('id=?' => $appraisalid);
         if ($initflag == 1) {
             $initdata['initialize_status'] = 1;
             $insertQstable = $appraisalQsModel->insertQsData($appraisalid, $loginuserArr);
             $updateTmptable = $appraisalPrivTempModel->updateQsTempData($appraisalid, $loginuserArr);
             $app_init_model->SaveorUpdateAppraisalInitData($initdata, $initwhere);
             /**
              * Sending mails to managers OR employees based on enable step.
              */
             if ($appraisaldata['enable_step'] == 1) {
                 /**
                  * Start 
                  * Sending Mails to Managers if enabled to managers
                  */
                 $getLine1ManagerId = $appraisalPrivMainModel->getLine1ManagerIdMain($appraisalid);
                 if (!empty($getLine1ManagerId)) {
                     foreach ($getLine1ManagerId as $val) {
                         $options['subject'] = APPLICATION_NAME . ': Appraisal process initiated';
                         $options['header'] = 'Performance Appraisal';
                         $options['toEmail'] = $val['emailaddress'];
                         $options['toName'] = $val['userfullname'];
                         $options['message'] = 'Dear ' . $val['userfullname'] . ', Appraisal process initiated';
                         $options['cron'] = 'yes';
                         //  sapp_Global::_sendEmail($options);
                     }
                 }
                 /**
                  * Mail to performance appraisal group
                  */
                 if (defined('PER_APPRAISAL_' . $appraisaldata['businessunit_id']) && $appraisaldata['businessunit_id'] != '') {
                     $options['subject'] = APPLICATION_NAME . ': Appraisal process initiated to managers.';
                     $options['header'] = 'Performance Appraisal';
                     $options['toEmail'] = constant('PER_APPRAISAL_' . $appraisaldata['businessunit_id']);
                     $options['toName'] = 'Performance Appraisal';
                     $options['message'] = 'Appraisal process initiated to managers.';
                     $options['cron'] = 'yes';
                     // sapp_Global::_sendEmail($options);
                 }
                 /**
                  * End
                  */
             } else {
                 /**
                  * Start 
                  * Inserting or Updating employee ratings table when enabled to employees
                  * If record exists then updating else inserting
                  */
                 $employeeidArr = $appraisalPrivMainModel->getemployeeIDs($appraisalid);
                 if (!empty($employeeidArr)) {
                     foreach ($employeeidArr as $emp) {
                         $emprating_Arr = array('pa_initialization_id' => $appraisalid, 'employee_id' => $emp['employee_id'], 'line_manager_1' => $emp['line_manager_1'] != '' ? $emp['line_manager_1'] : NULL, 'line_manager_2' => $emp['line_manager_2'] != '' ? $emp['line_manager_2'] : NULL, 'line_manager_3' => $emp['line_manager_3'] != '' ? $emp['line_manager_3'] : NULL, 'line_manager_4' => $emp['line_manager_4'] != '' ? $emp['line_manager_4'] : NULL, 'line_manager_5' => $emp['line_manager_5'] != '' ? $emp['line_manager_5'] : NULL, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                         $employeeexistArr = $appraisalempratingsmodel->checkEmployeeExists($appraisalid, $emp['employee_id']);
                         if ($employeeexistArr[0]['empcount'] > 0) {
                             $qwhere = " employee_id = '" . $emp['employee_id'] . "' and pa_initialization_id='" . $appraisalid . "' and isactive=1";
                         } else {
                             $emprating_Arr['createdby'] = $loginUserId;
                             $emprating_Arr['createdby_role'] = $loginuserRole;
                             $emprating_Arr['createdby_group'] = $loginuserGroup;
                             $emprating_Arr['createddate'] = gmdate("Y-m-d H:i:s");
                             $qwhere = '';
                         }
                         $appraisalempratingsmodel->SaveorUpdateAppraisalSkillsData($emprating_Arr, $qwhere);
                         /**
                          * End
                          */
                         /** Start
                          * Sending Mails to employees
                          */
                         $employeeDetailsArr = $usersmodel->getUserDetailsByID($emp['employee_id'], '');
                         if (!empty($employeeDetailsArr)) {
                             $options['subject'] = APPLICATION_NAME . ': Appraisal process initiated';
                             $options['header'] = 'Performance Appraisal';
                             $options['toEmail'] = $employeeDetailsArr[0]['emailaddress'];
                             $options['toName'] = $employeeDetailsArr[0]['userfullname'];
                             $options['message'] = 'Dear ' . $employeeDetailsArr[0]['userfullname'] . ', Appraisal process initiated';
                             $options['cron'] = 'yes';
                             // sapp_Global::_sendEmail($options);
                         }
                         /**
                          * End
                          */
                     }
                 }
                 /**
                  * Mail to performance appraisal group
                  */
                 if (defined('PER_APPRAISAL_' . $appraisaldata['businessunit_id']) && $appraisaldata['businessunit_id'] != '') {
                     $options['subject'] = APPLICATION_NAME . ': Appraisal process initiated to employees.';
                     $options['header'] = 'Performance Appraisal';
                     $options['toEmail'] = constant('PER_APPRAISAL_' . $appraisaldata['businessunit_id']);
                     $options['toName'] = 'Performance Appraisal';
                     $options['message'] = 'Appraisal process initiated to employees.';
                     $options['cron'] = 'yes';
                     //  sapp_Global::_sendEmail($options);
                 }
                 /**
                  * End
                  */
             }
             /**
              * End Sending Mails and updating emp ratings table
              */
             if ($appraisaldata['enable_step'] == 2) {
                 $appImpleData = sapp_PerformanceHelper::check_per_implmentation($appraisaldata['businessunit_id'], $appraisaldata['department_id']);
                 /** Start
                  * Announecements
                  */
                 if ($appImpleData['performance_app_flag'] == 1) {
                     $deptArr = $departmentsmodel->getAllDeptsForUnit($appraisaldata['businessunit_id']);
                     if (!empty($deptArr)) {
                         foreach ($deptArr as $dept) {
                             $deptids .= $dept['id'] . ',';
                         }
                         $deptids = rtrim($deptids, ',');
                     }
                 } else {
                     $deptids = $appraisaldata['department_id'];
                 }
                 /*	$announcement_arr = array(
                                               'businessunit_id' => $appraisaldata['businessunit_id']!=''?$appraisaldata['businessunit_id']:NULL,
                                               'department_id' => $deptids!=''?$deptids:NULL,
                                               'title' => $title,
                                               'description' => $description,
                                               'attachments' => NULL,
                                               'status' => 2,
                                               'isactive' => 1,
                 			'createdby' => $loginUserId,
                 						'createdby_role'=>$loginuserRole,
                 			'createdby_group'=>$loginuserGroup,
                                               'modifiedby' => $loginUserId,
                 						'modifiedby_role'=>$loginuserRole,
                 			'modifiedby_group'=>$loginuserGroup,
                 			'createddate'=>gmdate("Y-m-d H:i:s"),
                                               'modifieddate'=>gmdate("Y-m-d H:i:s")
                                   			);
                                   			
                                   	$Id = $announcementsModel->SaveorUpdateAnnouncementsData($announcement_arr, '');		*/
                 /**
                  * End
                  */
             }
             sapp_PerformanceHelper::update_QsParmas_Allemps($questions, $appraisaldata['category_id']);
         } else {
             $app_init_model->SaveorUpdateAppraisalInitData($initdata, $initwhere);
         }
         $trDb->commit();
         if ($initflag == 1) {
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => 'Appraisal initialized successfully'));
         } else {
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => 'Appraisal configurations are saved to be initialized later'));
         }
         return 'success';
     } catch (Exception $e) {
         $trDb->rollBack();
         return 'error';
     }
 }