Example #1
0
 public function manageEmployeeLeavesAction()
 {
     $userId = $this->_getParam('id');
     $model1 = new Application_Model_User();
     $model = $model1->find($userId);
     if (false === $model) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/employees'));
     }
     $this->view->user = $model;
     $request = $this->getRequest();
     $form = new Application_Form_UserLeaveAccount();
     if ($request->isPost()) {
         $options = $request->getPost();
         if ($form->isValid($options)) {
             $options['userId'] = $userId;
             $model = new Application_Model_UserLeaveAccount($options);
             $id = $model->save();
             if ($id) {
                 $this->_flashMessenger->addMessage(array('success' => 'User leave account has been successfully crided/debited!'));
                 $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/manage-employee-leaves/id/' . $userId));
             } else {
                 $this->_flashMessenger->addMessage(array('error' => 'Failed to credit/debit the user leave account!'));
                 $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/manage-employee-leaves/id/' . $userId));
             }
             $form->reset();
         } else {
             $form->reset();
             $form->populate($options);
         }
     }
     $this->view->form = $form;
 }
Example #2
0
 public function getLeaveBalance($userId = null)
 {
     if (is_null($userId)) {
         $userId = $this->getId();
     }
     $userLeaveAccount = new Application_Model_UserLeaveAccount();
     $leaveType = new Application_Model_LeaveType();
     $leaveType = $leaveType->fetchAll();
     foreach ($leaveType as $lt) {
         //current financial year 20011-04-01 00:00:00 to 2012-03-31 00:00:00
         $credited = $userLeaveAccount->getBalanceLeave($lt->getId(), 'credit', $userId);
         $debited = $userLeaveAccount->getBalanceLeave($lt->getId(), 'debit', $userId);
         $balance = $credited - $debited;
         $arrLaveBalance[] = array("id" => $lt->getId(), "title" => $lt->getTitle(), "debited" => $debited, "credited" => $credited, "balance" => $balance);
     }
     return $arrLaveBalance;
 }