public function submitmanagerAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserFullname = $auth->getStorage()->read()->userfullname;
         $loginuserEmail = $auth->getStorage()->read()->emailaddress;
         $loginUserEmpId = $auth->getStorage()->read()->employeeId;
     }
     $post_values = $this->getRequest()->getPost();
     $result = array('status' => 'fail', 'msg' => 'Something went wrong, please try again.');
     $questions = '';
     if (count($post_values) > 0) {
         $appraisal_id = $post_values['appraisal_id'];
         $manager_id = $post_values['manager_id'];
         if ($appraisal_id != '' && $manager_id != '') {
             $appraisal_id = sapp_Global::_decrypt($appraisal_id);
             $manager_id = sapp_Global::_decrypt($manager_id);
             $trDb = Zend_Db_Table::getDefaultAdapter();
             $trDb->beginTransaction();
             try {
                 $app_init_model = new Default_Model_Appraisalinit();
                 $appraisalPrivMainModel = new Default_Model_Appraisalqsmain();
                 $qsdataArr = $appraisalPrivMainModel->getAppraisalQuestionsMain($appraisal_id);
                 if (!empty($qsdataArr)) {
                     foreach ($qsdataArr as $qs) {
                         if (!empty($qs['manager_qs'])) {
                             $questions .= $qs['manager_qs'] . ',';
                         }
                     }
                     $questions = rtrim($questions, ',');
                 }
                 $questions = implode(',', array_keys(array_flip(explode(',', $questions))));
                 $submit_manager = $app_init_model->submitmanager($appraisal_id, $manager_id);
                 sapp_PerformanceHelper::update_QsParmas_Allemps($questions, '');
                 /*
                  *   Logs Storing
                  */
                 $actionflag = '';
                 $tableid = '';
                 $menuID = APPRAISAL_MANAGER;
                 $actionflag = 1;
                 sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
                 /*
                  *  Logs storing ends
                  */
                 //to get initialization details using appraisal Id for Business Unit,Department,To Year
                 $appraisalratingsmodel = new Default_Model_Appraisalratings();
                 $appraisal_details = $appraisalratingsmodel->getappdata($appraisal_id);
                 if (!empty($appraisal_details)) {
                     $bunit = $appraisal_details['unitname'];
                     $dept = $appraisal_details['deptname'];
                     $to_year = $appraisal_details['to_year'];
                 }
                 /** Start
                  * Sending Mails to employees
                  */
                 $appraisalconfigmodel = new Default_Model_Appraisalconfig();
                 $app_manager_model = new Default_Model_Appraisalmanager();
                 $getBunit_dept = $app_manager_model->getBunitDept($appraisal_id);
                 if (!empty($getBunit_dept)) {
                     $unitID = $getBunit_dept['businessunit_id'];
                     $deptID = $getBunit_dept['department_id'];
                 }
                 $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($unitID, $deptID);
                 $dept_str = $dept == '' ? " " : "and <b>{$dept}</b> department";
                 $emp_id_str = $loginuserRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})";
                 $empArr = array();
                 if (!empty($employeeDetailsArr)) {
                     $empArrList = '';
                     foreach ($employeeDetailsArr as $emp) {
                         array_push($empArr, $emp['emailaddress']);
                     }
                 }
                 // Sending mail to HR
                 $options['subject'] = APPLICATION_NAME . ': Manager Appraisal Submitted.';
                 $options['header'] = 'Performance Appraisal : Manager Appraisal ' . $to_year;
                 $options['toEmail'] = $loginuserEmail;
                 $options['bcc'] = $empArr;
                 $options['toEmail'] = $loginuserEmail;
                 $options['toName'] = $loginuserFullname;
                 $options['message'] = "<div style='padding: 0; text-align: left; font-size:14px; font-family:Arial, Helvetica, sans-serif;'>\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span style='color:#3b3b3b;'>Hi,</span><br />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 0 0;color:#3b3b3b;'> " . $loginuserFullname . $emp_id_str . " has submitted the Manager appraisal form for the year <b>{$to_year}</b> for <b>{$bunit}</b> business unit {$dept_str} </div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 10px 0;'>Please <a href=" . BASE_URL . " target='_blank' style='color:#b3512f;'>click here</a> to login  to your <b>" . APPLICATION_NAME . "</b> account and check the details.</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div> ";
                 $mail_id = sapp_Global::_sendEmail($options);
                 /**
                  * End
                  */
                 $trDb->commit();
                 $result['status'] = 'success';
                 $result['msg'] = "Submitted successfully";
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Initialization Submitted successfully. "));
             } catch (Exception $e) {
                 $trDb->rollBack();
                 $result['status'] = 'error';
                 $result['msg'] = $e->getMessage();
             }
         }
     }
     $this->_helper->json($result);
 }
 public function save($feedforwardInitForm)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginUserEmpId = $auth->getStorage()->read()->employeeId;
         $loginUserfullname = $auth->getStorage()->read()->userfullname;
     }
     $feedforwardInitModel = new Default_Model_Feedforwardinit();
     $msgarray = array();
     $check_array = array();
     $appraisal_id = '';
     $id = $this->_request->getParam('id');
     $appraisal_mode = $this->_request->getParam('appraisal_mode');
     $ff_due_date = sapp_Global::change_date($this->_request->getParam('ff_due_date'), 'database');
     $employee_name_view = $this->_request->getParam('employee_name_view');
     $enable_to = $this->_request->getParam('enable_to');
     $initialize_status = $this->_request->getParam('initialize_status');
     $status = $this->_request->getParam('status');
     $x_init_status = $this->_request->getParam('x_init_status');
     $check = $this->_request->getParam('check');
     $empcmnt = $this->_request->getParam('empcmnt');
     if ($empcmnt) {
         $empcmnt_keys = array_keys($empcmnt);
     } else {
         $empcmnt_keys = array();
     }
     if (sizeof($check) > 0) {
         foreach ($check as $qid) {
             if (in_array($qid, $empcmnt_keys)) {
                 $check_array[$qid] = array('EC' => 1, 'ER' => 1);
             } else {
                 $check_array[$qid] = array('EC' => 0, 'ER' => 1);
             }
         }
     }
     if (!empty($enable_to)) {
         if (in_array(1, $enable_to)) {
             $enable_to = 1;
         } else {
             $enable_to = 0;
         }
     }
     if ($x_init_status != 1) {
         if ($feedforwardInitForm->isValid($this->_request->getPost())) {
             try {
                 $data = array('ff_due_date' => $ff_due_date, 'employee_name_view' => $employee_name_view, 'enable_to' => $enable_to, 'status' => $status, 'initialize_status' => $initialize_status, 'questions' => $check != '' ? implode(',', $check) : NULL, 'qs_privileges' => count($check_array) > 0 ? json_encode($check_array, true) : NULL, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 if ($id != '') {
                     $where = array('id=?' => $id);
                     $actionflag = 2;
                     $appraisal_id = $this->_request->getParam('appraisal_id');
                 } else {
                     $appraisalinitmodel = new Default_Model_Appraisalinit();
                     $appData = $appraisalinitmodel->getappdata_forview($appraisal_mode);
                     $data['pa_configured_id'] = $appData['id'];
                     $data['businessunit_id'] = $appData['businessunit_id'];
                     $data['department_id'] = $appData['department_id'];
                     $data['ff_mode'] = $appData['appraisal_mode'];
                     $data['ff_period'] = $appData['appraisal_period'];
                     $data['ff_from_year'] = $appData['from_year'];
                     $data['ff_to_year'] = $appData['to_year'];
                     $data['appraisal_id'] = $appraisal_mode;
                     $data['createdby_role'] = $loginuserRole;
                     $data['createdby_group'] = $loginuserGroup;
                     $data['createdby'] = $loginUserId;
                     $data['createddate'] = gmdate("Y-m-d H:i:s");
                     $data['isactive'] = 1;
                     $where = '';
                     $actionflag = 1;
                     $appraisal_id = $appraisal_mode;
                 }
                 $Id = $feedforwardInitModel->SaveorUpdateFeedforwardInitData($data, $where);
                 if ($Id == 'update') {
                     $tableid = $id;
                     $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Initialization updated successfully."));
                 } else {
                     $tableid = $Id;
                     $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Initialization added successfully."));
                 }
                 if ($initialize_status == 1) {
                     sapp_PerformanceHelper::update_QsParmas_Allemps($data['questions'], '');
                     $this->ffinitialize($appraisal_id, $tableid, $enable_to, $check);
                 }
                 $this->_redirect('feedforwardinit');
             } catch (Exception $e) {
                 $msgarray['appraisal_mode'] = "Something went wrong, please try again.";
                 return $msgarray;
             }
         } else {
             $messages = $feedforwardInitForm->getMessages();
             foreach ($messages as $key => $val) {
                 foreach ($val as $key2 => $val2) {
                     $msgarray[$key] = $val2;
                     break;
                 }
             }
             $msgarray['check_array'] = $check_array;
             return $msgarray;
         }
     } else {
         $data = array('status' => $status, 'ff_due_date' => $ff_due_date);
         $where = array('id=?' => $id);
         $Id = $feedforwardInitModel->SaveorUpdateFeedforwardInitData($data, $where);
         if ($status == 2) {
             if ($Id == 'update') {
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Initialization closed successfully."));
                 $this->_redirect('feedforwardinit');
             }
         } else {
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Initialization updated successfully."));
             $this->_redirect('feedforwardinit');
         }
     }
 }
 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';
     }
 }
예제 #4
0
 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);
         $loginUserEmpId = $auth->getStorage()->read()->employeeId;
         $loginUserfullname = $auth->getStorage()->read()->userfullname;
     }
     $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();
     $app_manager_model = new Default_Model_Appraisalmanager();
     $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);
             $con = $app_init_model->SaveorUpdateAppraisalInitData($initdata, $initwhere);
             if ($appraisaldata['enable_step'] == 2) {
                 /**
                  * 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
                          */
                     }
                 }
             }
             /*
              *   Logs Storing
              */
             if ($con == 'update') {
                 $actionflag = 2;
             } else {
                 $actionflag = 1;
             }
             $tableid = '';
             $menuID = INITIALIZE_APPRAISAL;
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             /*
              *  Logs storing ends
              */
             /**
              * Sending mails to HR,Super Admin,Management,(managers OR employees) based on enable step.
              */
             $appraisalratingsmodel = new Default_Model_Appraisalratings();
             //to get initialization details using appraisal Id for Business Unit,Department,To Year
             $appraisal_details = $appraisalratingsmodel->getappdata($appraisalid);
             if (!empty($appraisal_details)) {
                 $businessUnit = $appraisal_details['businessunit_id'];
                 $department = $appraisal_details['deptid'];
                 $bunit = $appraisal_details['unitname'];
                 $dept = $appraisal_details['deptname'];
                 $to_year = $appraisal_details['to_year'];
                 $appraisalconfigmodel = new Default_Model_Appraisalconfig();
                 if ($department != '') {
                     $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, $department);
                 } else {
                     $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, '');
                 }
                 $dept_str = $dept == '' ? " " : "and department <b>{$dept}</b> ";
                 $emp_id_str = $loginuserRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})";
                 //Preparing Employee array for Bcc
                 $empArr = array();
                 if (!empty($employeeDetailsArr)) {
                     $empArrList = '';
                     foreach ($employeeDetailsArr as $emp) {
                         array_push($empArr, $emp['emailaddress']);
                     }
                 }
                 $mail_str = $appraisaldata['enable_step'] == 1 ? 'to managers' : 'to employees';
                 $empmgrArr = array();
                 if ($appraisaldata['enable_step'] == 1) {
                     $getLine1ManagerId = $appraisalPrivMainModel->getLine1ManagerIdMain($appraisalid);
                     foreach ($getLine1ManagerId as $mgr) {
                         array_push($empmgrArr, $mgr['emailaddress']);
                     }
                 } else {
                     $empIdArr = array();
                     $empIdList = '';
                     $employeeidArr = $appraisalPrivMainModel->getemployeeIDs($appraisalid);
                     //fetching Employee Ids
                     if (!empty($employeeidArr)) {
                         foreach ($employeeidArr as $emp) {
                             array_push($empIdArr, $emp['employee_id']);
                         }
                         $empIdList = implode(',', $empIdArr);
                         //Preparing Employee Id List
                         $empDetailsArr = $app_manager_model->getUserDetailsByEmpID($empIdList);
                         //Fetching employee details
                         if (!empty($empDetailsArr)) {
                             foreach ($empDetailsArr as $emp) {
                                 array_push($empmgrArr, $emp['emailaddress']);
                                 //preparing Bcc array
                             }
                         }
                     }
                 }
                 $totalArr = array_merge($empArr, $empmgrArr);
                 //Sending mail to Super admin
                 $options['subject'] = APPLICATION_NAME . ': Performance Appraisal Initialization';
                 $options['header'] = 'Performance Appraisal Initialization : ' . $to_year;
                 $options['toEmail'] = SUPERADMIN_EMAIL;
                 $options['toName'] = 'Super Admin';
                 $options['bcc'] = $totalArr;
                 $options['message'] = "<div style='padding: 0; text-align: left; font-size:14px; font-family:Arial, Helvetica, sans-serif;'>\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span style='color:#3b3b3b;'>Hi,</span><br />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>Performance appraisal has been initialized {$mail_str} for the year <b>{$to_year}</b> for business unit <b>{$bunit}</b>  {$dept_str} by " . $loginUserfullname . $emp_id_str . " </div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 10px 0;'>Please <a href=" . BASE_URL . " target='_blank' style='color:#b3512f;'>click here</a> to login  to your <b>" . APPLICATION_NAME . "</b> account to check the details.</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div> ";
                 $mail_id = sapp_Global::_sendEmail($options);
             }
             if ($appraisaldata['enable_step'] == 2) {
                 $appImpleData = sapp_PerformanceHelper::check_per_implmentation($appraisaldata['businessunit_id'], $appraisaldata['department_id']);
             }
             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';
     }
 }
 public function submitmanagerAction()
 {
     // $auth = Zend_Auth::getInstance();
     // if($auth->hasIdentity())
     // {
     // $loginUserId = $auth->getStorage()->read()->id;
     // $loginuserRole = $auth->getStorage()->read()->emprole;
     // $loginuserGroup = $auth->getStorage()->read()->group_id;
     // }
     $post_values = $this->getRequest()->getPost();
     $result = array('status' => 'fail', 'msg' => 'Something went wrong, please try again.');
     $questions = '';
     if (count($post_values) > 0) {
         $appraisal_id = $post_values['appraisal_id'];
         $manager_id = $post_values['manager_id'];
         if ($appraisal_id != '' && $manager_id != '') {
             $appraisal_id = sapp_Global::_decrypt($appraisal_id);
             $manager_id = sapp_Global::_decrypt($manager_id);
             $trDb = Zend_Db_Table::getDefaultAdapter();
             $trDb->beginTransaction();
             try {
                 // $menumodel = new Default_Model_Menu();
                 // $actionflag = '';
                 // $tableid  = '';
                 $app_init_model = new Default_Model_Appraisalinit();
                 $appraisalPrivMainModel = new Default_Model_Appraisalqsmain();
                 $qsdataArr = $appraisalPrivMainModel->getAppraisalQuestionsMain($appraisal_id);
                 if (!empty($qsdataArr)) {
                     foreach ($qsdataArr as $qs) {
                         if (!empty($qs['manager_qs'])) {
                             $questions .= $qs['manager_qs'] . ',';
                         }
                     }
                     $questions = rtrim($questions, ',');
                 }
                 $questions = implode(',', array_keys(array_flip(explode(',', $questions))));
                 $submit_manager = $app_init_model->submitmanager($appraisal_id, $manager_id);
                 sapp_PerformanceHelper::update_QsParmas_Allemps($questions, '');
                 $trDb->commit();
                 $result['status'] = 'success';
                 $result['msg'] = "Submitted successfully";
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Initialization Submitted successfully. "));
                 /*
                                     $menuidArr = $menumodel->getMenuObjID('/appraisalmanager');
                 					$menuID = $menuidArr[0]['id'];
                 					$result = sapp_Global::logManager($menuID,$actionflag,$loginUserId,$tableid);
                 					/** Start
                 * Sending Mails to employees
                 */
                 /* $app_manager_model = new Default_Model_Appraisalmanager();
                 	       $employeeDetailsArr = $app_manager_model->getUserDetailsByID($businessUnit,'');
                 			
                 			 
                 			// Sending mail to others
                 			if(!empty($employeeDetailsArr))
                 			{
                 				foreach($employeeDetailsArr as $emp)
                 				{
                 					$options['subject'] = APPLICATION_NAME.': Performance Appraisal Settings Added.';
                                              $options['header'] = 'Performance Appraisal Configuration';
                                              $options['toEmail'] = $emp['emailaddress'];  
                                              $options['toName'] = $emp['userfullname'];
                                              $options['message'] = 'Dear '.$emp['userfullname'].', performance appraisal configuration '.$msg_add_update;
                                             // $mail_id =  sapp_Global::_sendEmail($options); 
                 				}
                 			}
                 			*/
                 /**
                  * End
                  */
             } catch (Exception $e) {
                 $trDb->rollBack();
                 $result['status'] = 'error';
                 $result['msg'] = $e->getMessage();
             }
         }
     }
     $this->_helper->json($result);
 }