예제 #1
0
 public function editAction()
 {
     $popConfigPermission = array();
     $auth = Zend_Auth::getInstance();
     $report_opt = array();
     $role_datap = array();
     $empGroup = "";
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     if (sapp_Global::_checkprivileges(PREFIX, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'prefix');
     }
     if (sapp_Global::_checkprivileges(PREFIX, $loginuserGroup, $loginuserRole, 'edit') == 'Yes') {
         array_push($popConfigPermission, 'identitycodes');
     }
     if (sapp_Global::_checkprivileges(EMPLOYMENTSTATUS, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'empstatus');
     }
     if (sapp_Global::_checkprivileges(JOBTITLES, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'jobtitles');
     }
     if (sapp_Global::_checkprivileges(POSITIONS, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'position');
     }
     $this->view->popConfigPermission = $popConfigPermission;
     $id = (int) $this->getRequest()->getParam('id');
     $id = abs($id);
     if ($id == '') {
         $id = $loginUserId;
     }
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $employeeform = new Default_Form_employee();
     $appEmpRatingsModel = new Default_Model_Appraisalemployeeratings();
     $performanceflag = 'true';
     $ff_flag = 'true';
     try {
         if ($id != '' && is_numeric($id) && $id > 0 && $id != $loginUserId) {
             $appEmpRatingsData = $appEmpRatingsModel->getSelfAppraisalDataByEmpID($id);
             if (sizeof($appEmpRatingsData) > 0 && $appEmpRatingsData[0]['status'] == 1) {
                 $performanceflag = 'false';
             }
             $ffEmpRatingsData = $appEmpRatingsModel->getFeedforwardDataByEmpID($id);
             if (sizeof($ffEmpRatingsData) > 0 && $ffEmpRatingsData[0]['status'] == 1) {
                 $ff_flag = 'false';
             }
             if ($performanceflag == 'true' && $ff_flag == 'true') {
                 $employeeModal = new Default_Model_Employee();
                 $usersModel = new Default_Model_Users();
                 $employmentstatusModel = new Default_Model_Employmentstatus();
                 $busineesUnitModel = new Default_Model_Businessunits();
                 $deptModel = new Default_Model_Departments();
                 $role_model = new Default_Model_Roles();
                 $user_model = new Default_Model_Usermanagement();
                 $candidate_model = new Default_Model_Candidatedetails();
                 $jobtitlesModel = new Default_Model_Jobtitles();
                 $positionsmodel = new Default_Model_Positions();
                 $prefixModel = new Default_Model_Prefix();
                 $data = array();
                 $empDeptId = "";
                 $empRoleId = "";
                 $data = $employeeModal->getsingleEmployeeData($id);
                 if ($data == 'norows') {
                     $this->view->rowexist = "norows";
                 } else {
                     if (!empty($data)) {
                         $this->view->rowexist = "rows";
                         $employeeform->submit->setLabel('Update');
                         $data = $data[0];
                         /* Earlier code to fetch employee details */
                         $employeeData = $employeeModal->getsingleEmployeeData($id);
                         if (empty($data['modeofentry'])) {
                             $data['modeofentry'] = 'Direct';
                         }
                         if ($data['is_orghead'] == 1) {
                             $roles_arr = $role_model->getRolesList_EMP('orghead');
                             if (sizeof($roles_arr) > 0) {
                                 $employeeform->emprole->addMultiOptions(array('' => 'Select Role') + $roles_arr);
                             }
                         } else {
                             $roles_arr = $role_model->getRolesList_EMP();
                             if (sizeof($roles_arr) > 0) {
                                 $employeeform->emprole->addMultiOptions(array('' => 'Select Role') + $roles_arr);
                             }
                         }
                         $referedby_options = $user_model->getRefferedByForUsers();
                         $employmentStatusData = $employmentstatusModel->getempstatuslist();
                         if (sizeof($employmentStatusData) > 0) {
                             $employeeform->emp_status_id->addMultiOption('', 'Select Employment Status');
                             foreach ($employmentStatusData as $employmentStatusres) {
                                 $employeeform->emp_status_id->addMultiOption($employmentStatusres['workcodename'], $employmentStatusres['statusname']);
                             }
                         }
                         $businessunitData = $busineesUnitModel->getDeparmentList();
                         if (sizeof($businessunitData) > 0) {
                             $employeeform->businessunit_id->addMultiOption('0', 'No Business Unit');
                             foreach ($businessunitData as $businessunitres) {
                                 $employeeform->businessunit_id->addMultiOption($businessunitres['id'], $businessunitres['unitname']);
                             }
                         }
                         $departmentsData = $deptModel->getDepartmentList($data['businessunit_id']);
                         if (sizeof($departmentsData) > 0) {
                             $employeeform->department_id->addMultiOption('', 'Select Department');
                             foreach ($departmentsData as $departmentsres) {
                                 $employeeform->department_id->addMultiOption($departmentsres['id'], $departmentsres['deptname']);
                             }
                         }
                         $jobtitleData = $jobtitlesModel->getJobTitleList();
                         if (sizeof($jobtitleData) > 0) {
                             $employeeform->jobtitle_id->addMultiOption('', 'Select Job Title');
                             foreach ($jobtitleData as $jobtitleres) {
                                 $employeeform->jobtitle_id->addMultiOption($jobtitleres['id'], $jobtitleres['jobtitlename']);
                             }
                         }
                         $positionlistArr = $positionsmodel->getPositionList($data['jobtitle_id']);
                         if (sizeof($positionlistArr) > 0) {
                             $employeeform->position_id->addMultiOption('', 'Select Position');
                             foreach ($positionlistArr as $positionlistres) {
                                 $employeeform->position_id->addMultiOption($positionlistres['id'], $positionlistres['positionname']);
                             }
                         }
                         $prefixData = $prefixModel->getPrefixList();
                         if (!empty($prefixData)) {
                             foreach ($prefixData as $prefixres) {
                                 $employeeform->prefix_id->addMultiOption($prefixres['id'], $prefixres['prefix']);
                             }
                         }
                         $employeeform->populate($data);
                         $employeeform->setDefault('user_id', $data['user_id']);
                         $employeeform->setDefault('emp_status_id', $data['emp_status_id']);
                         $employeeform->setDefault('businessunit_id', $data['businessunit_id']);
                         $employeeform->setDefault('jobtitle_id', $data['jobtitle_id']);
                         $employeeform->setDefault('department_id', $data['department_id']);
                         $employeeform->setDefault('position_id', $data['position_id']);
                         $employeeform->setDefault('prefix_id', $data['prefix_id']);
                         //$employeeform->setDefault('emprole',$data['emprole']."_".MANAGEMENT_GROUP);
                         $employeeform->setDefault('emprole', $data['emprole']);
                         $date_of_joining = sapp_Global::change_date($data['date_of_joining'], 'view');
                         $employeeform->date_of_joining->setValue($date_of_joining);
                         if ($data['date_of_leaving'] != '' && $data['date_of_leaving'] != '0000-00-00') {
                             $date_of_leaving = sapp_Global::change_date($data['date_of_leaving'], 'view');
                             $employeeform->date_of_leaving->setValue($date_of_leaving);
                         }
                         //echo $data['modeofentry']; die;
                         if ($data['modeofentry'] != 'Direct') {
                             //$employeeform->rccandidatename->setValue($data['userfullname']);
                             $employeeform->rccandidatename->addMultiOption($data['rccandidatename'], $data['userfullname']);
                         }
                         if (sizeof($referedby_options) > 0 && $data['candidatereferredby'] != '' && $data['candidatereferredby'] != 0) {
                             $employeeform->candidatereferredby->addMultiOption($referedby_options[$data['candidatereferredby']], $referedby_options[$data['candidatereferredby']]);
                             //$employeeform->candidatereferredby->setValue($referedby_options[$data['candidatereferredby']]);
                         }
                         if ($data['rccandidatename'] != '' && $data['rccandidatename'] != 0) {
                             $cand_data = $candidate_model->getCandidateById($data['rccandidatename']);
                             $data['requisition_code'] = $cand_data['requisition_code'];
                         }
                         $role_data = $role_model->getRoleDataById($data['emprole']);
                         $employeeform->emprole->setValue($data['emprole'] . "_" . $role_data['group_id']);
                         $employeeform->setAttrib('action', BASE_URL . 'employee/edit/id/' . $id);
                         $reportingManagerData = $usersModel->getReportingManagerList_employees($data['department_id'], $data['id'], $role_data['group_id']);
                         $empDeptId = isset($_POST['department_id']) ? $_POST['department_id'] : $data['department_id'];
                         if (isset($_POST['emprole']) && $_POST['emprole'] != '') {
                             $role_split = preg_split('/_/', $_POST['emprole']);
                             $empRoleId = $role_split[0];
                         } else {
                             $empRoleId = $data['emprole'];
                         }
                         if (isset($empDeptId) && $empDeptId != '' && isset($empRoleId) && $empRoleId != '') {
                             try {
                                 $role_datap = $role_model->getRoleDataById($empRoleId);
                                 $reportingManagerData = $usersModel->getReportingManagerList_employees($empDeptId, $data['id'], $role_datap['group_id']);
                             } catch (Exception $e) {
                                 $reportingManagerData = array();
                             }
                         }
                         if (!empty($reportingManagerData)) {
                             $report_opt = $reportingManagerData;
                         }
                         $employeeform->setDefault('reporting_manager', $data['reporting_manager']);
                         $this->view->id = $id;
                         $this->view->form = $employeeform;
                         $this->view->employeedata = !empty($employeeData) ? $employeeData[0] : "";
                         $this->view->messages = $this->_helper->flashMessenger->getMessages();
                         $this->view->data = $data;
                         if ($data['is_orghead'] == 1) {
                             $employeeform->removeElement('businessunit_id');
                             $employeeform->removeElement('reporting_manager');
                             $employeeform->removeElement('department_id');
                             $employeeform->removeElement('emp_status_id');
                             $employeeform->removeElement('date_of_leaving');
                             //$employeeform->removeElement('emprole');
                         }
                     }
                 }
                 $this->view->report_opt = $report_opt;
             } else {
                 $this->editappraisal($id, $performanceflag, $ff_flag);
             }
         } else {
             $this->view->rowexist = "norows";
         }
         if ($this->getRequest()->getPost()) {
             $result = $this->save($employeeform);
             $this->view->msgarray = $result;
             $employeeform->modeofentry->setValue($data['modeofentry']);
             $employeeform->other_modeofentry->setValue($data['other_modeofentry']);
             if ($data['modeofentry'] != 'Direct') {
                 $employeeform->rccandidatename->setValue($data['userfullname']);
             }
             if (sizeof($referedby_options) > 0 && $data['candidatereferredby'] != '' && $data['candidatereferredby'] != 0) {
                 $employeeform->candidatereferredby->setValue($referedby_options[$data['candidatereferredby']]);
             }
         }
     } catch (Exception $e) {
         $this->view->rowexist = "norows";
     }
 }