コード例 #1
0
 /**
  * This action is used for adding/updating data.
  * @parameters
  * @param $id  =  id of requisition.
  *
  * @return Zend_Form.
  */
 public function editAction()
 {
     $id = $this->getRequest()->getParam('id', null);
     $auth = Zend_Auth::getInstance();
     $data = array();
     $data_m = array();
     $ipreporting_idData = array();
     $ipreporting_ids = array();
     $technicalskills_all = array();
     $technicalskills_selected = array();
     $nontechnicalskills_all = array();
     $nontechnicalskills_selected = array();
     $job_title_permission = NULL;
     if ($auth->hasIdentity()) {
         $sess_vals = $auth->getStorage()->read();
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $job_title_permission = sapp_Global::_checkprivileges(JOBTITLES, $loginuserGroup, $loginuserRole, 'add');
     //$positions_permission = sapp_Global::_checkprivileges(POSITIONS, $loginuserGroup, $loginuserRole, 'add');
     $emp_status_permission = sapp_Global::_checkprivileges(EMPLOYMENTSTATUS, $loginuserGroup, $loginuserRole, 'add');
     $form = new Default_Form_Requisition();
     $requi_model = new Default_Model_Requisition();
     $usersModel = new Default_Model_Users();
     $user_model = new Default_Model_Usermanagement();
     $ipreporting_idData = $requi_model->getAllEmployees();
     $ipreporting_ids = $requi_model->getRequisitionInterviewPanelIDs($id);
     $technicalskills_all = $requi_model->getAllActiveTechnicalSkills();
     $technicalskills_selected = $requi_model->getRequisitionSkillIDs($id, "Technical");
     $nontechnicalskills_all = $requi_model->getAllActiveNonTechnicalSkills();
     $nontechnicalskills_selected = $requi_model->getRequisitionSkillIDs($id, "Non-Technical");
     $form->setAttrib('action', DOMAIN . 'requisition/edit/id/' . $id);
     $form->submit->setLabel('Update');
     $edit_flag = '';
     $edit_order = '';
     $approver1_opt = array();
     $approver2_opt = array();
     $reportingManagerData = array();
     $hrexecutivesData = array();
     try {
         if ($id > 0 && is_numeric($id)) {
             $id = abs($id);
             //$data['id'] = $id;
             $data = $requi_model->getRequisitionForEdit($id, $loginUserId);
             //$data['requ_jd'] = "<span title='" . htmlentities(trim($data['requ_jd']), ENT_QUOTES, "UTF-8") . "'><a href='" . DOMAIN . 'requisition/download/id/' . $id . "'>" . $data['requ_jd'] . "</a></span>";
             $getempId = $requi_model->getrequisitionDataonid($id);
             if (!empty($getempId['billable_empname'])) {
                 $getdatampname = $requi_model->getEmployeeNameonId($getempId['billable_empname']);
             }
             $aflag = $data['aflag'];
             if ($aflag == "approver") {
                 $aorder = 1;
             }
             //$aorder = $data['aorder'];
             if (!empty($data) && $data['req_status'] == 'Initiated') {
                 if ($loginuserGroup != MANAGEMENT_GROUP || $loginuserGroup == MANAGEMENT_GROUP || $loginuserGroup == '') {
                     if ($aflag == 'approver' && $data['appstatus' . $aorder] == 'Initiated') {
                         $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                         $business_units_list = $requi_model->getBusinessUnitsList();
                         $data['bunit_name'] = $business_units_list[$data['businessunit_id']];
                         $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                         $data['dept_name'] = $departments_list[$data['department_id']];
                         $job_data = $requi_model->getJobTitleList();
                         if (isset($job_data[$data['jobtitle']])) {
                             $data['jtitle_name'] = $job_data[$data['jobtitle']];
                         } else {
                             $data['jtitle_name'] = 'Select Job Title';
                         }
                         //                            $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                         //                            $data['position_name'] = $pos_data[$data['position_id']];
                         $emptype_options = $requi_model->getStatusOptionsForRequi();
                         if (isset($emptype_options[$data['emp_type']])) {
                             $data['emptype_name'] = $emptype_options[$data['emp_type']];
                         } else {
                             $data['emptype_name'] = 'Select Employment Status';
                         }
                         $report_manager_data = $user_model->getUserDataById($data['reporting_id']);
                         $data['mngrname'] = $report_manager_data['userfullname'];
                         $form->req_status->addMultiOptions(array('0' => 'Select status', '2' => 'Approved', '3' => 'Rejected'));
                         $form->req_status->setRequired(true)->addErrorMessage('Please select the status.');
                         $form->req_status->addFilter('Int')->addValidator('NotEmpty', true, array('integer', 'zero'));
                         $elements = $form->getElements();
                         if (count($elements) > 0) {
                             foreach ($elements as $key => $element) {
                                 if ($key != 'req_status') {
                                     $element->setRequired(false);
                                 }
                             }
                         }
                         if ($data['approver1'] != '') {
                             $app1_opt = $user_model->getUserDataById($data['approver1']);
                             $data_m['approver1'] = $app1_opt['userfullname'];
                         }
                         if ($data['approver2'] != '') {
                             $app2_opt = $user_model->getUserDataById($data['approver2']);
                             $data_m['approver2'] = $app2_opt['userfullname'];
                         }
                     } else {
                         $edit_flag = 'no';
                         if (in_array('Approved', array($data['appstatus1'], $data['appstatus2'], $data['appstatus3']))) {
                             $edit_flag = 'yes';
                         }
                         if ($edit_flag == 'yes') {
                             $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                             $business_units_list = $requi_model->getBusinessUnitsList();
                             $data['bunit_name'] = $business_units_list[$data['businessunit_id']];
                             $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                             $data['dept_name'] = $departments_list[$data['department_id']];
                             $job_data = $requi_model->getJobTitleList();
                             if (isset($job_data[$data['jobtitle']])) {
                                 $data['jtitle_name'] = $job_data[$data['jobtitle']];
                             } else {
                                 $data['jtitle_name'] = 'Select Job Title';
                             }
                             //                                $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                             //                                $data['position_name'] = $pos_data[$data['position_id']];
                             $emptype_options = $requi_model->getStatusOptionsForRequi();
                             if (isset($emptype_options[$data['emp_type']])) {
                                 $data['emptype_name'] = $emptype_options[$data['emp_type']];
                             } else {
                                 $data['emptype_name'] = 'Select Employment Status';
                             }
                             $report_manager_data = $user_model->getUserDataById($data['reporting_id']);
                             $data['mngrname'] = $report_manager_data['userfullname'];
                             $elements = $form->getElements();
                             if (count($elements) > 0) {
                                 foreach ($elements as $key => $element) {
                                     $element->setRequired(false);
                                 }
                             }
                             if ($data['appstatus1'] == 'Approved') {
                                 $edit_order = 1;
                                 $app1_opt = $user_model->getUserDataById($data['approver1']);
                                 $data_m['approver1'] = $app1_opt['userfullname'];
                                 $report_manager_options = $requi_model->getapprovers($data['reporting_id'], $data['department_id']);
                                 $form->setDefault('approver1', $data['approver1']);
                             }
                         } else {
                             #$form->setDefault('requ_jd', $data['requ_jd']);
                             $business_units_list = $requi_model->getBusinessUnitsList();
                             $form->business_unit->addMultiOptions(array('' => 'Select Business Unit') + $business_units_list);
                             $form->setDefault('business_unit', $data['businessunit_id']);
                             $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                             $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                             $form->setDefault('department', $data['department_id']);
                             $job_data = $requi_model->getJobTitleList();
                             $form->jobtitle->addMultiOptions(array('' => 'Select Job Title') + $job_data);
                             $form->setDefault('jobtitle', $data['jobtitle']);
                             //                                $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                             //                                $form->position_id->addMultiOptions(array('' => 'Select Position') + $pos_data);
                             //                                $form->setDefault('position_id', $data['position_id']);
                             $emptype_options = $requi_model->getStatusOptionsForRequi();
                             $form->emp_type->addMultiOptions(array('' => 'Select Employment Status') + $emptype_options);
                             $form->technology->addMultiOptions(array('' => 'Select Technology') + $requi_model->getTechnologySkillIDName());
                             $form->setDefault('technology', $data['technology']);
                             $form->setDefault('reporting_id', $data['reporting_id']);
                             $form->billablefor->addMultiOptions(array('' => 'Select Billable Type', 'New' => 'New', 'Replacement' => 'Replacement', 'Backup' => 'Backup'));
                             $form->setDefault('billablefor', $getempId['billable_for']);
                             $form->setDefault('requ_jd', $getempId['upload_jd']);
                             $form->requ_jd->setRequired(false);
                             //$form->requisition_code->setValue($ipreporting_ids);
                             //$form->ipreporting_id->addMultiOptions(array('' => 'Select Technical Panel') + $ipreporting_idData);
                             //$form->ipreporting_id->setValue($data['requisition_code']);
                             //$form->ipreporting_id->setMultiOptions($ipreporting_ids);
                             $form->req_status->addMultiOptions(array('1' => 'Initiated'));
                             if ($loginuserGroup == HR_GROUP || $loginuserGroup == '' || $loginuserGroup == MANAGEMENT_GROUP) {
                                 if ($loginuserGroup == '') {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', $loginUserId, '', $data['department_id'], 'requisition');
                                 } else {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', '', '', $data['department_id'], 'requisition');
                                 }
                                 if ($loginuserGroup == HR_GROUP || $loginuserGroup == '' || $loginuserGroup == MANAGEMENT_GROUP) {
                                     if ($loginuserGroup == '') {
                                         $getEmployeelistonBunit = $requi_model->getEmployeelistonBunit('', $data['business_unit'], 'requisition');
                                     } else {
                                         $getEmployeelistonBunit = $requi_model->getEmployeelistonBunit('', $data['business_unit'], 'requisition');
                                     }
                                     //for hr,management
                                     $re_arr = array();
                                 }
                                 if (isset($_POST['business_unit']) && $_POST['business_unit'] != '') {
                                     $departments_list = $requi_model->getDepartmentList($_POST['business_unit']);
                                     $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                                 }
                                 if (isset($_POST['department']) && $_POST['department'] != '') {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', $loginUserId, '', $_POST['department'], 'requisition');
                                 }
                                 $form->reporting_id->addMultiOptions(array('' => 'Select Reporting Manager') + $reportingManagerData);
                                 $form->setDefault('reporting_id', $data['reporting_id']);
                                 $form->setDefault('req_status', $data['req_status']);
                                 $form->req_status->setAttrib("disabled", "disabled");
                                 if ($loginuserGroup == HR_GROUP) {
                                     $departments_list = $requi_model->getDepartmentList($sess_vals->businessunit_id);
                                     $data_m['bunit_data']['id'] = $sess_vals->businessunit_id;
                                     $data_m['bunit_data']['name'] = $business_units_list[$sess_vals->businessunit_id];
                                     $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                                 }
                             } else {
                                 //for managers login
                                 $report_manager_options = $user_model->getUserDataById($data['reporting_id']);
                                 $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                                 $data_m['manager_data']['id'] = $data['reporting_id'];
                                 $data_m['manager_data']['name'] = $report_manager_options['userfullname'];
                                 $data_m['bunit_data']['id'] = $data['businessunit_id'];
                                 $data_m['bunit_data']['name'] = $business_units_list[$data['businessunit_id']];
                                 $data_m['dept_data']['id'] = $data['department_id'];
                                 $data_m['dept_data']['name'] = $departments_list[$data['department_id']];
                                 $form->setDefault('reporting_id', $data['reporting_id']);
                                 $form->setDefault('req_status', $data['req_status']);
                                 $form->req_status->setAttrib("disabled", "disabled");
                             }
                             $hrexecutivesData = $requi_model->getHRExecutives();
                             //start of approvers options
                             $approver_opt = $requi_model->getapprovers($data['reporting_id'], $data['department_id']);
                             $app1_opt = array();
                             if (count($approver_opt) > 0 && count($_POST) == 0) {
                                 foreach ($approver_opt as $app1) {
                                     $approver1_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                 }
                             }
                             //end of approvers options
                             foreach ($data as $key => $val) {
                                 $data[$key] = htmlentities(addslashes($val), ENT_QUOTES, "UTF-8");
                             }
                             $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                             $form->populate($data);
                             if (isset($_POST['business_unit']) && $_POST['business_unit'] != '') {
                                 $departments_list = $requi_model->getDepartmentList($_POST['business_unit']);
                                 $form->department->clearMultiOptions();
                                 $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                             }
                             //                                if (isset($_POST['jobtitle']) && $_POST['jobtitle'] != '') {
                             //                                    $pos_data = $requi_model->getPositionOptions($_POST['jobtitle']);
                             //                                    $form->position_id->clearMultiOptions();
                             //                                    $form->position_id->addMultiOptions(array('' => 'Select Position') + $pos_data);
                             //                                }
                             if (isset($_POST['reporting_id']) && $_POST['reporting_id'] != '') {
                                 $app1_data = $requi_model->getapprovers($_POST['reporting_id'], $_POST['department']);
                                 $app1_opt = array();
                                 if (count($app1_data) > 0) {
                                     foreach ($app1_data as $app1) {
                                         $app1_opt[$app1['id']] = ucwords($app1['name']);
                                         $approver1_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                     }
                                     $form->reporting_id->setValue($_POST['reporting_id']);
                                 }
                             }
                         }
                     }
                     //end of else of aflag.
                     $this->view->loginuserGroup = $loginuserGroup;
                     $this->view->form = $form;
                     $this->view->data = $data;
                     $this->view->data_m = $data_m;
                     $this->view->aflag = $aflag;
                     $this->view->aorder = $aorder;
                     $this->view->edit_flag = $edit_flag;
                     $this->view->edit_order = $edit_order;
                     $this->view->reportingManagerData = $reportingManagerData;
                     $this->view->hrexecutivesData = $hrexecutivesData;
                     $this->view->approver1_opt = $approver1_opt;
                     $this->view->approver2_opt = $approver2_opt;
                     $this->view->ipreporting_idData = $ipreporting_idData;
                     $this->view->ipreporting_ids = $ipreporting_ids;
                     $this->view->technicalskills_all = $technicalskills_all;
                     $this->view->technicalskills_selected = $technicalskills_selected;
                     $this->view->nontechnicalskills_all = $nontechnicalskills_all;
                     $this->view->nontechnicalskills_selected = $nontechnicalskills_selected;
                     $this->view->getEmployeelistonBunit = $getEmployeelistonBunit;
                     $this->view->getempId = $getempId;
                     $this->view->getdatampname = $getdatampname;
                     if ($this->getRequest()->getPost()) {
                         $result = $this->save($form, $data);
                         $this->view->msgarray = $result;
                         $this->view->messages = $result;
                     }
                     $this->view->ermsg = '';
                 } else {
                     $this->view->nodata = 'nodata';
                 }
             } else {
                 $this->view->nodata = 'nodata';
             }
         } else {
             $this->view->nodata = 'nodata';
         }
         // To check whether to display Employment Status configuration link or not
         $employmentstatusmodel = new Default_Model_Employmentstatus();
         $activeEmploymentStatusArr = $employmentstatusmodel->getEmploymentStatuslist();
         $this->view->job_title_permission = $job_title_permission;
         $this->view->positions_permission = $positions_permission;
         $this->view->emp_status_permission = $emp_status_permission;
     } catch (Exception $e) {
         $this->view->nodata = 'nodata';
     }
 }