public function editAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $id = $this->getRequest()->getParam('id');
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $appraisalinitform = new Default_Form_Appraisalinit();
     $appraisalinitform->submit->setLabel('Update');
     try {
         if ($id) {
             if (is_numeric($id) && $id > 0) {
                 $appraisalinitmodel = new Default_Model_Appraisalinit();
                 $data = $appraisalinitmodel->getConfigData($id);
                 if (!empty($data)) {
                     $empSummaryModel = new Default_Model_Employee();
                     $empData = $empSummaryModel->getEmp_from_summary($loginUserId);
                     $appraisalinitform->businessunit_name->setValue($empData['businessunit_name']);
                     $appraisalinitform->department_name->setValue($empData['department_name']);
                     $employmentstatusModel = new Default_Model_Employmentstatus();
                     $employmentStatusData = $employmentstatusModel->getempstatusActivelist();
                     if (!empty($employmentStatusData)) {
                         foreach ($employmentStatusData as $employmentStatusres) {
                             $appraisalinitform->eligibility->addMultiOption($employmentStatusres['workcodename'], $employmentStatusres['statusname']);
                         }
                     }
                     $data = $data[0];
                     $appraisalinitform->populate($data);
                     $appraisalinitform->setAttrib('action', DOMAIN . 'appraisalinit/edit/id/' . $id);
                     $this->view->data = $data;
                 } else {
                     $this->view->ermsg = 'norecord';
                 }
             } else {
                 $this->view->ermsg = 'norecord';
             }
         } else {
             $this->view->ermsg = '';
         }
     } catch (Exception $e) {
         $this->view->ermsg = 'nodata';
     }
     $this->view->eligibility_value = $data['eligibility'];
     $this->view->form = $appraisalinitform;
     if ($this->getRequest()->getPost()) {
         $result = $this->save($appraisalinitform);
         $this->view->msgarray = $result;
     }
     $this->render('form');
 }
 /**
  ** displays previous emp appraisals based on emp id,
  ** on click of individual emp record in heat map report
  **/
 public function previousappraisalsAction($empId = "")
 {
     try {
         if (empty($empId)) {
             $empId = $this->_request->getParam('id');
         }
         /** 
          ** 1. get employee details
          **/
         $empModel = new Default_Model_Employee();
         $employeeDetails = $empModel->getEmp_from_summary($empId);
         /** 
          ** 2. get employee appraisal details
          **/
         $empAppraisalModel = new Default_Model_Appraisalemployeeratings();
         $empAppraisalDetails = $empAppraisalModel->getEmpAppraisalData($empId);
         /** 
          ** 3. display employee graph
          **/
         /** 
          ** 4. By default, display latest appraisal ratings and questions
          **/
         $this->view->employeeData = $employeeDetails;
         $this->view->empAppraisalDetails = $empAppraisalDetails;
     } catch (Exception $e) {
         print_r($e);
     }
 }
 public function getindividualempdetailsAction()
 {
     $employeeModel = new Default_Model_Employee();
     $userid = $this->_request->getParam('userid', null);
     $userdetails = $employeeModel->getEmp_from_summary($userid);
     $this->view->userdetails = $userdetails;
 }
 public function displaymanagersAction()
 {
     $ajaxContext = $this->_helper->getHelper('AjaxContext');
     $ajaxContext->addActionContext('displaymanagers', 'html')->initContext();
     $line1_data = array();
     $line_managers = array();
     $type = $this->_getParam('type', null);
     $levels = $this->_getParam('levels', null);
     $init_id = $this->_getParam('init_id', null);
     $line1_id = $this->_getParam('line1_id', null);
     $context = $this->_getParam('context', 'add');
     $employeeid = $this->_getParam('employeeid');
     $app_levels = 1;
     $app_init_model = new Default_Model_Appraisalinit();
     $appEmpRatingsModel = new Default_Model_Appraisalemployeeratings();
     $init_data = $app_init_model->getConfigData($init_id);
     if (count($init_data) > 0) {
         $init_data = $init_data[0];
     }
     $managers = $app_init_model->getRepManagers_new($type, $init_id, $init_data);
     if ($context == 'edit') {
         $emp_model = new Default_Model_Employee();
         $line1_data = $emp_model->getEmp_from_summary($line1_id);
         $line_managers = $app_init_model->getLineManagers_new($init_id, $employeeid);
         $line_managers = array_filter($line_managers);
     }
     $appEmpRatingsData = $appEmpRatingsModel->getSelectedAppraisalData_notused($init_id, $employeeid);
     if (!empty($appEmpRatingsData)) {
         if ($appEmpRatingsData['appstatus'] != 1) {
             $app_levels = $appEmpRatingsData['appstatus'] - 1;
         }
     }
     $this->view->levels = $levels;
     $this->view->managers = $managers;
     $this->view->init_id = $init_id;
     $this->view->context = $context;
     $this->view->line1_data = $line1_data;
     $this->view->line_managers = $line_managers;
     $this->view->line1_id = $line1_id;
     $this->view->app_levels = $app_levels;
     $this->render('displaymanagers');
 }
 /**
  * 
  */
 public function viewAction()
 {
     $request_form = new Default_Form_Servicerequest();
     $id = $this->_getParam('id', null);
     $grid_type = $this->_getParam('t', null);
     $status_value = $this->_getParam('v', null);
     $req_msg = "";
     try {
         if ($id != '' && $grid_type != '') {
             $grid_type = sapp_Global::_decrypt($grid_type);
             $sd_req_model = new Default_Model_Servicerequests();
             $grid_type_arr = $sd_req_model->getGridtypearr();
             if (is_numeric($id) && $id > 0 && is_numeric($grid_type) && $grid_type > 0 && array_key_exists($grid_type, $grid_type_arr)) {
                 $auth = Zend_Auth::getInstance();
                 if ($auth->hasIdentity()) {
                     $loginUserId = $auth->getStorage()->read()->id;
                     $loginuserRole = $auth->getStorage()->read()->emprole;
                     $loginuserGroup = $auth->getStorage()->read()->group_id;
                     $login_bu = $auth->getStorage()->read()->businessunit_id;
                     $login_dept = $auth->getStorage()->read()->department_id;
                 }
                 $data = $sd_req_model->getRequestById($id);
                 if (!empty($data)) {
                     $approver_level = "view";
                     if (($grid_type_arr[$grid_type] == 'rept_app' || $grid_type_arr[$grid_type] == 'approver') && $data['status'] == 'To management approve') {
                         $approver_level = $sd_req_model->getApproverLevel($loginUserId, $id);
                     }
                     $canTicketEscalate = $sd_req_model->canTicketEscalate($loginUserId, $id);
                     $ticketFeedbackRating = $sd_req_model->isFeedbackProvided($id);
                     $request_Admins = $sd_req_model->getRequestAdmins($id);
                     $request_history = $sd_req_model->getRequestHistory($id);
                     $requester_length = 5;
                     $requester_history = $sd_req_model->getLastRequests($id, $data['raised_by'], $requester_length);
                     $emp_model = new Default_Model_Employee();
                     $service_conf_model = new Default_Model_Servicedeskconf();
                     $raised_by_details = $emp_model->getEmp_from_summary($data['raised_by']);
                     $other_approvers = $emp_model->get_Other_Approvers();
                     $app_data = $sd_req_model->getApprovers($data['service_desk_conf_id'], "config");
                     $app_details = $emp_model->getEmployeeDetails(implode(',', $app_data));
                     foreach ($app_data as $key => $value) {
                         $app_names[$key] = $app_details[$value];
                     }
                     $conf_data = $service_conf_model->getServiceDeskConfbyID($data['service_desk_conf_id']);
                     $exec_data = $emp_model->getEmployeeDetails($conf_data[0]['request_recievers']);
                     $this->view->id = $id;
                     $this->view->data = $data;
                     $this->view->grid_type = $grid_type_arr[$grid_type];
                     $this->view->grid_type_arr = $sd_req_model->getGridtypearr_rev();
                     $this->view->status_value = $status_value;
                     $this->view->approver_level = $approver_level;
                     $this->view->canTicketEscalate = $canTicketEscalate;
                     $this->view->ticketFeedbackRating = $ticketFeedbackRating;
                     $this->view->loginUserId = $loginUserId;
                     $this->view->request_Admins = $request_Admins;
                     $this->view->request_history = $request_history;
                     $this->view->requester_history = $requester_history;
                     $this->view->requester_length = $requester_length;
                     $this->view->raised_by_details = $raised_by_details;
                     $this->view->other_approvers = $other_approvers;
                     $this->view->app_names = $app_names;
                     $this->view->exec_data = $exec_data;
                     if ($this->getRequest()->getPost()) {
                         $trDb = Zend_Db_Table::getDefaultAdapter();
                         // starting transaction
                         $trDb->beginTransaction();
                         try {
                             $req_id = $this->_getParam('hid_reqid', null);
                             $hid_status = $this->_getParam('hid_status', null);
                             $request_action = $this->_getParam('request_action', null);
                             $request_comments = trim($this->_getParam('request_comments', null));
                             //email stuff ------------Start
                             $sEmailData = $sd_req_model->getRequestDataForEmail($id);
                             $summary_data = $sd_req_model->getDataSummary($id);
                             $stoEmailAddress2 = $sd_req_model->getEmailAddress($sEmailData['raised_by']);
                             //mail for requester
                             $stoEmailAddress4 = $sd_req_model->getEmailAddress($sEmailData['executor_id']);
                             //mail for executor
                             $stoEmailAddress3 = constant('ITSUPPORT_0');
                             //$stoEmailAddress3 = $this->getSupportTeamEmailID($sEmailData['service_desk_conf_id']);  //mail for support group
                             $sMailSubject = sprintf("%s - %s - %s - %s", $sEmailData['ticket_number'], $sEmailData['service_desk_name'], $sEmailData['service_request_name'], $hid_status);
                             $smessage = "The below service request status has been changed to " . $hid_status;
                             $this->mail_helper_action($sMailSubject, $smessage, $summary_data, $stoEmailAddress2);
                             $this->mail_helper_action($sMailSubject, $smessage, $summary_data, $stoEmailAddress3);
                             $this->mail_helper_action($sMailSubject, $smessage, $summary_data, $stoEmailAddress4);
                             //email stuff ------------End
                             switch ($hid_status) {
                                 case "Cancelled":
                                     $save_data = array('status' => 'Cancelled', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     $req_msg['success'] = "Request cancelled successfully.";
                                     //mailto: Requester, Supportgroup
                                     break;
                                 case "Duplicate":
                                     if ($request_action != '' && $request_comments != '') {
                                         $save_data = array('status' => 'Duplicate', 'executor_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     }
                                     $req_msg['success'] = "Request marked as duplicate.";
                                     break;
                                 case "Need more Info":
                                     if ($request_action != '' && $request_comments != '') {
                                         $save_data = array('status' => 'Need more Info', 'executor_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     }
                                     $req_msg['success'] = "Request need more information from requester.";
                                     break;
                                 case "Other Approval":
                                     $otherapproverid = trim($this->_getParam('idothermanagerapprover_action', null));
                                     $save_data = array('status' => 'To manager approve', 'executor_comments' => trim($request_comments), 'reporting_manager_id' => $otherapproverid, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     $req_msg['success'] = "Request is waiting for approval.";
                                     $stoEmailAddress1 = $sd_req_model->getEmailAddress($otherapproverid);
                                     $this->mail_helper_action($sMailSubject, $smessage, $summary_data, $stoEmailAddress1);
                                     break;
                                 case "In progress":
                                     if ($request_action != '' && $request_comments != '') {
                                         $save_data = array('status' => 'In progress', 'executor_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     }
                                     $req_msg['success'] = "Request is in progress.";
                                     break;
                                 case "Closed":
                                     if ($request_action != '' && $request_comments != '') {
                                         $save_data = array('status' => 'Closed', 'executor_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     }
                                     $req_msg['success'] = "Request closed successfully.";
                                     break;
                                 case "Request Rejected":
                                     if ($request_action != '' && $request_comments != '') {
                                         $save_data = array('status' => 'Rejected', 'executor_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     }
                                     $req_msg['success'] = "Request is rejected.";
                                     break;
                                 case "Approved":
                                     $save_data = array('status' => 'Manager approved', 'reporting_manager_status' => 'Approve', 'reporting_manager_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     $req_msg['success'] = "Request is approved.";
                                     break;
                                 case "Rejected":
                                     $save_data = array('status' => 'Manager rejected', 'reporting_manager_status' => 'Reject', 'reporting_manager_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     $req_msg['success'] = "Request is rejected.";
                                     break;
                                 case "escalate":
                                     $save_data = array('modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     $req_msg['success'] = "Request escalated sucessfully.";
                                     break;
                                 case "submitfeedback":
                                     $save_data = array('feedback_comments' => trim($request_comments), 'feedback_rating' => trim($request_action), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                     $req_msg['success'] = "Feedback sucessfully submitted.";
                                     break;
                                 default:
                                     //echo "do nothing";
                                     $req_msg['success'] = "Request status " . $hid_status;
                             }
                             $sd_result = "";
                             if ($hid_status == "submitfeedback") {
                                 $sd_result = $sd_req_model->SaveorUpdateRequestData($save_data, 'id = ' . $id);
                             } else {
                                 if ($data['status'] != 'Closed' && $data['status'] != 'Rejected') {
                                     $sd_result = $sd_req_model->SaveorUpdateRequestData($save_data, 'id = ' . $id);
                                 }
                             }
                             //start of saving history
                             $reqh_model = new Default_Model_Requesthistory();
                             $reqh_data = array('request_id' => $id, 'description' => ucfirst($req_msg['success']), 'emp_id' => $loginUserId, 'emp_name' => ucfirst($auth->getStorage()->read()->userfullname), 'emp_profileimg' => $auth->getStorage()->read()->profileimg, 'createdby' => $loginUserId, 'modifiedby' => $loginUserId, 'comments' => trim($request_comments), 'isactive' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                             if ($sd_result == 'update') {
                                 $reqh_model->SaveorUpdateRhistory($reqh_data, '');
                                 //end of saving history
                                 //$this->send_req_mails($id);
                                 //$req_msg['success'] = "Request " . ($request_action == 'Approve' ? "closed" : "rejected") . " successfully.";
                             } else {
                                 $req_msg['error'] = "Some thing went wrong, please try again.";
                             }
                             $result = sapp_Global::logManager(SERVICEDESK, 2, $loginUserId, $id);
                             $trDb->commit();
                             $this->_helper->getHelper("FlashMessenger")->addMessage(array($req_msg));
                             $this->_redirect('servicerequests/index/t/' . sapp_Global::_encrypt($grid_type) . ($status_value != '' ? "/v/" . $status_value : ""));
                         } catch (Exception $ex) {
                             $trDb->rollBack();
                             $msgarray['executor_comments'] = "Something went wrong, please try again.";
                         }
                     }
                 } else {
                     $this->view->ermsg = 'norecord';
                 }
             } else {
                 $this->view->ermsg = 'norecord';
             }
         } else {
             $this->view->ermsg = 'norecord';
         }
     } catch (Exception $e) {
         $this->view->ermsg = 'nodata';
     }
     $this->view->action_name = $this->getRequest()->getActionName();
 }
 public function viewAction()
 {
     $request_form = new Default_Form_Servicerequest();
     $id = $this->_getParam('id', null);
     $grid_type = $this->_getParam('t', null);
     $status_value = $this->_getParam('v', null);
     $req_msg = "";
     try {
         if ($id != '' && $grid_type != '') {
             $grid_type = sapp_Global::_decrypt($grid_type);
             $sd_req_model = new Default_Model_Servicerequests();
             $grid_type_arr = $sd_req_model->getGridtypearr();
             if (is_numeric($id) && $id > 0 && is_numeric($grid_type) && $grid_type > 0 && array_key_exists($grid_type, $grid_type_arr)) {
                 $auth = Zend_Auth::getInstance();
                 if ($auth->hasIdentity()) {
                     $loginUserId = $auth->getStorage()->read()->id;
                     $loginuserRole = $auth->getStorage()->read()->emprole;
                     $loginuserGroup = $auth->getStorage()->read()->group_id;
                     $login_bu = $auth->getStorage()->read()->businessunit_id;
                     $login_dept = $auth->getStorage()->read()->department_id;
                 }
                 $data = $sd_req_model->getRequestById($id);
                 if (!empty($data)) {
                     $approver_level = "view";
                     if (($grid_type_arr[$grid_type] == 'rept_app' || $grid_type_arr[$grid_type] == 'approver') && $data['status'] == 'To management approve') {
                         $approver_level = $sd_req_model->getApproverLevel($loginUserId, $id);
                     }
                     $request_history = $sd_req_model->getRequestHistory($id);
                     $emp_model = new Default_Model_Employee();
                     $service_conf_model = new Default_Model_Servicedeskconf();
                     $raised_by_details = $emp_model->getEmp_from_summary($data['raised_by']);
                     $app_data = $sd_req_model->getApprovers($data['service_desk_conf_id'], "config");
                     $app_details = $emp_model->getEmployeeDetails(implode(',', $app_data));
                     foreach ($app_data as $key => $value) {
                         $app_names[$key] = $app_details[$value];
                     }
                     $conf_data = $service_conf_model->getServiceDeskConfbyID($data['service_desk_conf_id']);
                     $exec_data = $emp_model->getEmployeeDetails($conf_data[0]['request_recievers']);
                     $this->view->id = $id;
                     $this->view->data = $data;
                     $this->view->grid_type = $grid_type_arr[$grid_type];
                     $this->view->grid_type_arr = $sd_req_model->getGridtypearr_rev();
                     $this->view->status_value = $status_value;
                     $this->view->approver_level = $approver_level;
                     $this->view->loginUserId = $loginUserId;
                     $this->view->request_history = $request_history;
                     $this->view->raised_by_details = $raised_by_details;
                     $this->view->app_names = $app_names;
                     $this->view->exec_data = $exec_data;
                     if ($this->getRequest()->getPost()) {
                         $trDb = Zend_Db_Table::getDefaultAdapter();
                         // starting transaction
                         $trDb->beginTransaction();
                         try {
                             $req_id = $this->_getParam('hid_reqid', null);
                             $hid_status = $this->_getParam('hid_status', null);
                             if ($hid_status != '' && $hid_status == 'Cancelled') {
                                 $save_data = array('status' => $hid_status, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                 $sd_req_model->SaveorUpdateRequestData($save_data, 'id = ' . $id);
                                 //start of saving history
                                 $reqh_model = new Default_Model_Requesthistory();
                                 $reqh_data = array('request_id' => $id, 'description' => ucfirst($data['service_desk_name']) . " Request has been cancelled by ", 'emp_id' => $loginUserId, 'emp_name' => ucfirst($data['raised_by_name']), 'emp_profileimg' => $auth->getStorage()->read()->profileimg, 'createdby' => $loginUserId, 'modifiedby' => $loginUserId, 'isactive' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                 $reqh_model->SaveorUpdateRhistory($reqh_data, '');
                                 //end of saving history
                                 $req_msg['success'] = "Request cancelled successfully.";
                             } else {
                                 if ($hid_status != '' && $hid_status == 'To management approve') {
                                     $hid_app_pos = $this->_getParam('hid_app_pos', null);
                                     $hid_max_app = $this->_getParam('hid_max_app', null);
                                     if ($hid_app_pos == '' && $hid_max_app == '') {
                                         $request_comments = trim($this->_getParam('request_comments', null));
                                         if ($request_comments != '') {
                                             $save_data = array('status' => "To management approve", 'to_mgmt_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                             $save_data = $save_data + $app_data;
                                             $sd_result = "";
                                             if ($data['status'] == 'Open') {
                                                 $sd_result = $sd_req_model->SaveorUpdateRequestData($save_data, 'status = "Open" and id = ' . $id);
                                             }
                                             //start of saving history
                                             $reqh_model = new Default_Model_Requesthistory();
                                             $reqh_data = array('request_id' => $id, 'description' => ucfirst($data['service_desk_name']) . " Request has been sent for management approval by ", 'emp_id' => $loginUserId, 'emp_name' => ucfirst($auth->getStorage()->read()->userfullname), 'emp_profileimg' => $auth->getStorage()->read()->profileimg, 'createdby' => $loginUserId, 'modifiedby' => $loginUserId, 'comments' => trim($request_comments), 'isactive' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                             if ($sd_result == 'update') {
                                                 $reqh_model->SaveorUpdateRhistory($reqh_data, '');
                                                 //end of saving history
                                                 $this->send_req_mails($id);
                                                 $req_msg['success'] = "Request sent for management approval successfully.";
                                             } else {
                                                 $req_msg['error'] = "Some thing went wrong, please try again.";
                                             }
                                         }
                                     } else {
                                         $request_comments = trim($this->_getParam('request_comments', null));
                                         $request_action = $this->_getParam('request_action', null);
                                         if ($request_comments != '' && $request_action != '') {
                                             $save_data = array('approver_status_' . $approver_level['app_pos'] => $request_action, 'modifiedby' => $loginUserId, 'approver_' . $approver_level['app_pos'] . '_comments' => trim($request_comments), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                             if ($request_action == 'Reject') {
                                                 $save_data['status'] = 'Management rejected';
                                             }
                                             if ($approver_level['app_pos'] == $approver_level['max_app']) {
                                                 $save_data['status'] = $request_action == 'Approve' ? "Management approved" : "Management rejected";
                                             }
                                             $sd_req_model->SaveorUpdateRequestData($save_data, 'id = ' . $id);
                                             //start of saving history
                                             $reqh_model = new Default_Model_Requesthistory();
                                             $reqh_data = array('request_id' => $id, 'description' => ucfirst($data['service_desk_name']) . " Request has been " . ($request_action == 'Approve' ? "approved" : "rejected") . " by ", 'emp_id' => $loginUserId, 'emp_name' => ucfirst($auth->getStorage()->read()->userfullname), 'emp_profileimg' => $auth->getStorage()->read()->profileimg, 'createdby' => $loginUserId, 'modifiedby' => $loginUserId, 'comments' => trim($request_comments), 'isactive' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                             $reqh_model->SaveorUpdateRhistory($reqh_data, '');
                                             //end of saving history
                                             $this->send_req_mails($id);
                                             $req_msg['success'] = "Request " . ($request_action == 'Approve' ? "approved" : "rejected") . " successfully.";
                                         }
                                     }
                                 } else {
                                     if ($hid_status != '' && $hid_status == 'To manager approve') {
                                         if ($loginUserId == $data['reporting_manager_id']) {
                                             $request_action = $this->_getParam('request_action', null);
                                             $request_comments = trim($this->_getParam('request_comments', null));
                                             if ($request_action != '' && $request_comments != '') {
                                                 $save_data = array('status' => $request_action == 'Approve' ? "Manager approved" : "Manager rejected", 'reporting_manager_status' => $request_action, 'reporting_manager_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                                 $sd_req_model->SaveorUpdateRequestData($save_data, 'id = ' . $id);
                                                 //start of saving history
                                                 $reqh_model = new Default_Model_Requesthistory();
                                                 $reqh_data = array('request_id' => $id, 'description' => ucfirst($data['service_desk_name']) . " Request has been " . ($request_action == 'Approve' ? "approved" : "rejected") . " by reporting manager ", 'emp_id' => $loginUserId, 'emp_name' => ucfirst($auth->getStorage()->read()->userfullname), 'emp_profileimg' => $auth->getStorage()->read()->profileimg, 'createdby' => $loginUserId, 'modifiedby' => $loginUserId, 'isactive' => 1, 'comments' => trim($request_comments), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                                 $reqh_model->SaveorUpdateRhistory($reqh_data, '');
                                                 //end of saving history
                                                 $this->send_req_mails($id);
                                                 $req_msg['success'] = "Request " . ($request_action == 'Approve' ? "approved" : "rejected") . " successfully.";
                                             }
                                         } else {
                                             $request_comments = trim($this->_getParam('request_comments', null));
                                             if ($request_comments != '') {
                                                 $save_data = array('status' => "To manager approve", 'to_manager_comments' => trim($request_comments), 'reporting_manager_id' => $raised_by_details['reporting_manager'], 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                                 $sd_result = "";
                                                 if ($data['status'] == 'Open') {
                                                     $sd_result = $sd_req_model->SaveorUpdateRequestData($save_data, 'status = "Open" and id = ' . $id);
                                                 }
                                                 //start of saving history
                                                 $reqh_model = new Default_Model_Requesthistory();
                                                 $reqh_data = array('request_id' => $id, 'description' => ucfirst($data['service_desk_name']) . " Request has been sent for manager approval by ", 'emp_id' => $loginUserId, 'emp_name' => ucfirst($auth->getStorage()->read()->userfullname), 'emp_profileimg' => $auth->getStorage()->read()->profileimg, 'createdby' => $loginUserId, 'modifiedby' => $loginUserId, 'comments' => trim($request_comments), 'isactive' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                                 if ($sd_result == 'update') {
                                                     $reqh_model->SaveorUpdateRhistory($reqh_data, '');
                                                     //end of saving history
                                                     $this->send_req_mails($id);
                                                     $req_msg['success'] = "Request sent for manager approval successfully.";
                                                 } else {
                                                     $req_msg['error'] = "Some thing went wrong, please try again.";
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($hid_status != '' && $hid_status == 'Closed') {
                                             $request_action = $this->_getParam('request_action', null);
                                             $request_comments = trim($this->_getParam('request_comments', null));
                                             if ($request_action != '' && $request_comments != '') {
                                                 $save_data = array('status' => $request_action == 'Approve' ? "Closed" : "Rejected", 'executor_comments' => trim($request_comments), 'executor_id' => $loginUserId, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                                 $sd_result = "";
                                                 if ($data['status'] != 'Closed' && $data['status'] != 'Rejected') {
                                                     $sd_result = $sd_req_model->SaveorUpdateRequestData($save_data, 'id = ' . $id);
                                                 }
                                                 //start of saving history
                                                 $reqh_model = new Default_Model_Requesthistory();
                                                 $reqh_data = array('request_id' => $id, 'description' => ucfirst($data['service_desk_name']) . " Request has been " . ($request_action == 'Approve' ? "closed" : "rejected") . " by ", 'emp_id' => $loginUserId, 'emp_name' => ucfirst($auth->getStorage()->read()->userfullname), 'emp_profileimg' => $auth->getStorage()->read()->profileimg, 'createdby' => $loginUserId, 'modifiedby' => $loginUserId, 'comments' => trim($request_comments), 'isactive' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                                 if ($sd_result == 'update') {
                                                     $reqh_model->SaveorUpdateRhistory($reqh_data, '');
                                                     //end of saving history
                                                     $this->send_req_mails($id);
                                                     $req_msg['success'] = "Request " . ($request_action == 'Approve' ? "closed" : "rejected") . " successfully.";
                                                 } else {
                                                     $req_msg['error'] = "Some thing went wrong, please try again.";
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             $result = sapp_Global::logManager(SERVICEDESK, 2, $loginUserId, $id);
                             $trDb->commit();
                             $this->_helper->getHelper("FlashMessenger")->addMessage(array($req_msg));
                             $this->_redirect('servicerequests/index/t/' . sapp_Global::_encrypt($grid_type) . ($status_value != '' ? "/v/" . $status_value : ""));
                         } catch (Exception $ex) {
                             $trDb->rollBack();
                             $msgarray['executor_comments'] = "Something went wrong, please try again.";
                         }
                     }
                 } else {
                     $this->view->ermsg = 'norecord';
                 }
             } else {
                 $this->view->ermsg = 'norecord';
             }
         } else {
             $this->view->ermsg = 'norecord';
         }
     } catch (Exception $e) {
         $this->view->ermsg = 'nodata';
     }
     $this->view->action_name = $this->getRequest()->getActionName();
 }
 public function editAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $businessunit_id = $auth->getStorage()->read()->businessunit_id;
         $department_id = $auth->getStorage()->read()->department_id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $this->view->loginuserRole = $loginuserRole;
     $this->view->loginuserGroup = $loginuserGroup;
     $id = $this->getRequest()->getParam('id');
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $appraisalinitform = new Default_Form_Appraisalinit();
     $app_rating_model = new Default_Model_Appraisalratings();
     $appraisalinitform->submit->setLabel('Update');
     $disable_arr = array();
     $ratings = '';
     $eligibilityvalue = '';
     $ratingsflag = 'false';
     $data = array();
     try {
         if ($id != '') {
             if (is_numeric($id) && $id > 0) {
                 $appraisalinitmodel = new Default_Model_Appraisalinit();
                 $checkRatingsExists = $app_rating_model->getAppraisalRatingsbyInitId($id);
                 if (!empty($checkRatingsExists)) {
                     $ratingsflag = 'true';
                 }
                 $this->view->ratingsflag = $ratingsflag;
                 $data = $appraisalinitmodel->getConfigData($id);
                 if (!empty($data)) {
                     $data = $data[0];
                     $performance_app_flag = isset($data['performance_app_flag']) ? $data['performance_app_flag'] : '';
                     $this->view->performance_app_flag = $performance_app_flag;
                     $app_rating_type = isset($data['appraisal_ratings']) ? $data['appraisal_ratings'] : 0;
                     $this->view->init_id = $id;
                     if ($data['initialize_status'] == 1) {
                         $this->appraisalinitialized($data);
                     } else {
                         if ($loginuserRole != SUPERADMINROLE && $loginuserGroup != MANAGEMENT_GROUP) {
                             // $appImpleData = sapp_PerformanceHelper::check_per_implmentation($businessunit_id, $department_id);
                             $empSummaryModel = new Default_Model_Employee();
                             $empData = $empSummaryModel->getEmp_from_summary($loginUserId);
                             $appraisalinitform->businessunit_name->setValue($empData['businessunit_name']);
                             if ($performance_app_flag == 0) {
                                 $appraisalinitform->department_name->setValue($empData['department_name']);
                             } else {
                                 $appraisalinitform->removeElement("department_name");
                             }
                         } else {
                             // $appImpleData = sapp_PerformanceHelper::check_per_implmentation($data['businessunit_id'], $data['department_id']);
                             $businessunits = $appraisalinitmodel->getbusinnessunits_admin($data['businessunit_id']);
                             $this->view->businessunits = $businessunits;
                             $dept_model = new Default_Model_Departments();
                             if ($performance_app_flag == 0) {
                                 $dept_data = $dept_model->getParicularDepartmentId($data['department_id']);
                                 if (count($dept_data) > 0) {
                                     $dept_data = $dept_data[0];
                                     $appraisalinitform->department_id->addMultiOption($dept_data['id'], $dept_data['deptname']);
                                 }
                             }
                         }
                         // $this->view->imple_data = $appImpleData;
                         $employmentstatusModel = new Default_Model_Employmentstatus();
                         $employmentStatusData = $employmentstatusModel->getempstatusActivelist();
                         if (!empty($employmentStatusData)) {
                             foreach ($employmentStatusData as $employmentStatusres) {
                                 $appraisalinitform->eligibility->addMultiOption($employmentStatusres['workcodename'], $employmentStatusres['statusname']);
                                 $appraisalinitform->eligibility_hidden->addMultiOption($employmentStatusres['workcodename'], $employmentStatusres['statusname']);
                                 $eligibilityvalue .= $employmentStatusres['workcodename'] . ',';
                             }
                             $eligibilityvalue = rtrim($eligibilityvalue, ',');
                         }
                         $category_model = new Default_Model_Appraisalcategory();
                         $category_data = $category_model->getAppraisalCategorysData();
                         foreach ($category_data as $cdata) {
                             $appraisalinitform->category_id->addMultiOption($cdata['id'], $cdata['category_name']);
                         }
                         // Set default values for 'To Year' field
                         $following_year = $data["from_year"] + 1;
                         $appraisalinitform->to_year->addMultiOptions(array($data["from_year"] => $data["from_year"], $following_year => $following_year));
                         $appraisalinitform->populate($data);
                         // if($appImpleData['appraisal_ratings'] == 1)
                         // if($app_rating_type == 1)
                         // $ratings = '1-5';
                         // else
                         // $ratings = '1-10';
                         $appraisalinitform->appraisal_ratings->setValue($app_rating_type);
                         if ($eligibilityvalue != '') {
                             $appraisalinitform->eligibility_value->setValue($eligibilityvalue);
                         }
                         $appraisalinitform->setAttrib('action', BASE_URL . 'appraisalinit/edit/id/' . $id);
                         $appraisalinitform->eligibilityflag->setValue('1');
                         $appraisalinitform->eligibility_hidden->setAttrib("disabled", "disabled");
                         /*$cnt = $appraisalinitmodel->check_delete($id);
                           if($cnt > 0)
                           {
                               $disable_arr[] = "management_appraisal"; 
                           }*/
                         if ($data['enable_step'] == 2) {
                             $appraisalinitform->enable_step->removeMultiOption(1);
                         }
                         $this->view->period_disp = $this->period_helper($data['appraisal_mode'], $data['appraisal_period']);
                         $this->view->data = $data;
                         $this->view->category_id_value = $data['category_id'];
                         $this->view->businessunit_id = $businessunit_id;
                         $this->view->employmentStatusData = $employmentStatusData;
                         $this->view->eligibilityvalue = $eligibilityvalue;
                     }
                 } else {
                     $this->view->ermsg = 'norecord';
                 }
             } else {
                 $this->view->ermsg = 'norecord';
             }
         } else {
             $this->view->ermsg = '';
         }
     } catch (Exception $e) {
         $this->view->ermsg = 'nodata';
     }
     $this->view->eligibility_value = isset($data['eligibility']) ? $data['eligibility'] : '';
     $this->view->form = $appraisalinitform;
     if ($this->getRequest()->getPost()) {
         $result = $this->save($appraisalinitform, $is_edit = 1);
         $this->view->msgarray = $result;
     }
     //$this->view->disable_arr = $disable_arr;
     if (!empty($data) && $data['initialize_status'] == 1) {
         $this->render('edit');
     } else {
         $this->render('form');
     }
 }
 public function viewAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserbusinessunit_id = $auth->getStorage()->read()->businessunit_id;
     }
     $objName = 'addemployeeleaves';
     $id = $this->getRequest()->getParam('id');
     $msgarray = array();
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     try {
         if ($id && is_numeric($id) && $id > 0) {
             $addemployeeleavesModel = new Default_Model_Addemployeeleaves();
             $addEmpLeavesForm = new Default_Form_addemployeeleaves();
             $employeeleavesModel = new Default_Model_Employeeleaves();
             $empModel = new Default_Model_Employee();
             $currentYearData = $employeeleavesModel->getsingleEmployeeleaveData($id);
             $permission = sapp_Global::_checkprivileges(176, $loginuserGroup, $loginuserRole, 'edit');
             $this->view->editpermission = $permission;
             $empDetails = $empModel->getEmp_from_summary($id);
             if (!empty($empDetails)) {
                 $addEmpLeavesForm->businessunit_id->setValue($empDetails['businessunit_id']);
                 $addEmpLeavesForm->department_id->setValue($empDetails['department_id']);
                 $addEmpLeavesForm->user_id->setValue($empDetails['user_id']);
                 $addEmpLeavesForm->leave_limit->setAttrib("disabled", "disabled");
                 if (!empty($currentYearData)) {
                     $addEmpLeavesForm->leave_limit->setValue($currentYearData[0]['emp_leave_limit']);
                 }
                 $addEmpLeavesForm->alloted_year->setValue(date('Y'));
                 $this->view->form = $addEmpLeavesForm;
                 $this->view->empdetails = $empDetails;
                 $this->view->msgarray = $msgarray;
                 $this->view->ermsg = '';
                 $this->view->controllername = $objName;
                 $this->view->id = $id;
             } else {
                 $this->view->ermsg = "norows";
             }
         } else {
             $this->view->ermsg = "norows";
         }
     } catch (Exception $e) {
         $this->view->ermsg = "norows";
     }
 }