Ejemplo n.º 1
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     if (Session::token() == Input::get('_token')) {
         $response = array('status' => 'fail', 'msg' => 'unauthorized Action');
     }
     try {
         $month = Input::get('qter');
         if ($month <= 3 && $month >= 1) {
             $q = Leave::whereBetween('date', array('2016-01-01', '2016-03-31'))->where('agent_ID', '=', Input::get('agent'))->count();
         } else {
             if ($month <= 4 && $month >= 6) {
                 $q = Leave::whereBetween('date', array('2016-04-01', '2016-06-30'))->where('agent_ID', '=', Input::get('agent'))->count();
             } else {
                 if ($month <= 7 && $month >= 9) {
                     $q = Leave::whereBetween('date', array('2016-07-01', '2016-09-30'))->where('agent_ID', '=', Input::get('agent'))->count();
                 } else {
                     if ($month <= 10 && $month >= 12) {
                         $q = Leave::whereBetween('date', array('2016-10-01', '2016-12-31'))->where('agent_ID', '=', Input::get('agent'))->count();
                     }
                 }
             }
         }
         $fullyBooked = Leave::where('date', '=', Input::get('date'))->count();
         $agent = Leave::where('date', '=', Input::get('date'))->where('agent_ID', '=', Input::get('agent'))->count();
         $monthMax = Leave::where('date', 'like', Input::get('month') . '%')->where('agent_ID', '=', Input::get('agent'))->count();
         $maxLeave = Leave::where('agent_ID', '=', Input::get('agent'))->count();
         if ($fullyBooked >= 1) {
             $response = array('status' => 'Error', 'msg' => 'Sorry!! This day is fully Booked..Please select another day');
         } else {
             if ($agent >= 1) {
                 $response = array('status' => 'Error', 'msg' => 'You have already booked this day!!');
             } else {
                 if ($q >= 5) {
                     $response = array('status' => 'Error', 'msg' => 'You\'re Not allowed to go for more than 5 days leave in three months.. please see your Team lead in case you want an extra leave for this quota');
                 } else {
                     if ($monthMax >= 5) {
                         $response = array('status' => 'Error', 'msg' => 'Sorry! You can only take 5 leave days in a month!!');
                     } else {
                         if ($maxLeave >= 21) {
                             $response = array('status' => 'Error', 'msg' => 'Sorry! You have exhausted your leave days for this Year(21 max allowed)');
                         } else {
                             $leave = new Leave();
                             $leave->date = Input::get('date');
                             $leave->agent_ID = Input::get('agent');
                             $leave->save();
                             $response = array('status' => 'success', 'msg' => 'leave day successfully booked');
                         }
                     }
                 }
             }
         }
     } catch (\Illuminate\Database\Eloquent\MassAssignmentException $e) {
         $response = array('status' => 'Error', 'msg' => 'mass assignment not allowed!!');
     } catch (Illuminate\Database\QueryException $e) {
         $response = array('status' => 'Error', 'msg' => $e);
     }
     return Response::json($response);
 }
Ejemplo n.º 2
0
 /**
  * Pares delete data in the UI form
  *
  * @param mixed $postArr
  * @return Leave[]
  */
 public function parseDeleteData($postArr)
 {
     $objLeave = null;
     for ($i = 0; $i < count($postArr['cmbStatus']); $i++) {
         if ($postArr['cmbStatus'][$i] == 0) {
             $tmpObj = new Leave();
             $tmpObj->setLeaveId($postArr['id'][$i]);
             $objLeave[] = $tmpObj;
         }
     }
     return $objLeave;
 }
Ejemplo n.º 3
0
 function updatestatusAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $formvalues = $this->_getAllParams();
     debugMessage($formvalues);
     $session = SessionWrapper::getInstance();
     $this->_translate = Zend_Registry::get("translate");
     $formvalues['id'] = $id = $formvalues['id'];
     $formvalues['dateapproved'] = date("Y-m-d H:i:s", strtotime('now'));
     $formvalues['approvedbyid'] = $session->getVar('userid');
     // debugMessage($formvalues);
     $leave = new Leave();
     $leave->populate($id);
     $leave->setStatus($formvalues['status']);
     $leave->setDateApproved(DEFAULT_DATETIME);
     $leave->setApprovedByID($session->getVar('userid'));
     if (!isArrayKeyAnEmptyString('reason', $formvalues)) {
         $leave->setReason("<br/>Rejected with remarks: " . $formvalues['reason']);
     }
     try {
         $leave->save();
         $leave->afterApprove($formvalues['status']);
         $session->setVar(SUCCESS_MESSAGE, $this->_translate->translate($formvalues[SUCCESS_MESSAGE]));
     } catch (Exception $e) {
         // debugMessage('error '.$e->getMessage());
         $session->setVar(ERROR_MESSAGE, $e->getMessage());
     }
     // exit();
     $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS]));
 }
Ejemplo n.º 4
0
 public function saveLeave(Leave $leave)
 {
     try {
         if ($leave->getLeaveId() == '') {
             $idGenService = new IDGeneratorService();
             $idGenService->setEntity($leave);
             $leave->setLeaveId($idGenService->getNextID());
         }
         $leave->save();
         return true;
     } catch (Exception $e) {
         throw new DaoException($e->getMessage());
     }
 }
Ejemplo n.º 5
0
 /**
  * Pares delete data in the UI form
  *
  * @param mixed $postArr
  * @return Leave[]
  */
 public function parseDeleteData($postArr)
 {
     $objLeave = null;
     if (isset($postArr['cmbStatus'])) {
         for ($i = 0; $i < count($postArr['cmbStatus']); $i++) {
             $tmpObj = new Leave();
             $tmpObj->setLeaveId($postArr['id'][$i]);
             $tmpObj->setLeaveComments($postArr['txtComment'][$i]);
             $tmpObj->setEmployeeId($postArr['txtEmployeeId'][$i]);
             $tmpObj->setLeaveStatus($postArr['cmbStatus'][$i]);
             $tmpObj->setLeaveRequestId($postArr['txtLeaveRequestId'][$i]);
             $objLeave[] = $tmpObj;
         }
     }
     return $objLeave;
 }
Ejemplo n.º 6
0
 public function configure()
 {
     $widgets = array();
     $labels = array();
     $validators = array();
     $defaults = array();
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18N', 'OrangeDate'));
     $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat();
     // From and To Date
     $widgets['calFromDate'] = new ohrmWidgetDatePickerNew(array(), array('id' => 'calFromDate'));
     $labels['calFromDate'] = __('From');
     $widgets['calToDate'] = new ohrmWidgetDatePickerNew(array(), array('id' => 'calToDate'));
     $labels['calToDate'] = __('To');
     // Set default from/to to current leave period.
     $leavePeriod = $this->getLeavePeriodService()->getCurrentLeavePeriod();
     $defaults['calFromDate'] = set_datepicker_date_format($leavePeriod->getStartDate());
     $endDateString = date('Y-m-d', strtotime($leavePeriod->getEndDate() . " +1 year"));
     $endDate = new DateTime($endDateString);
     $toDate = $endDate->format("Y-m-d");
     $defaults['calToDate'] = set_datepicker_date_format($toDate);
     $validators['calFromDate'] = new ohrmDateValidator(array('date_format' => $inputDatePattern, 'required' => false), array('invalid' => 'Date format should be' . $inputDatePattern));
     $validators['calToDate'] = new ohrmDateValidator(array('date_format' => $inputDatePattern, 'required' => false), array('invalid' => 'Date format should be' . $inputDatePattern));
     // Leave Statuses
     $leaveStatusChoices = Leave::getStatusTextList();
     if ($this->mode == self::MODE_MY_LEAVE_LIST) {
         $defaultStatuses = array_keys($leaveStatusChoices);
     } else {
         $defaultStatuses = array(Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL);
     }
     $widgets['chkSearchFilter'] = new ohrmWidgetCheckboxGroup(array('choices' => $leaveStatusChoices, 'show_all_option' => true, 'default' => $defaultStatuses));
     $labels['chkSearchFilter'] = 'Show Leave with Status';
     $defaults['chkSearchFilter'] = $defaultStatuses;
     $validators['chkSearchFilter'] = new sfValidatorChoice(array('choices' => array_keys($leaveStatusChoices), 'required' => false, 'multiple' => true));
     if ($this->mode != self::MODE_MY_LEAVE_LIST) {
         $requiredPermissions = array(BasicUserRoleManager::PERMISSION_TYPE_ACTION => array('view_leave_list'));
         $widgets['txtEmployee'] = new ohrmWidgetEmployeeNameAutoFill(array('employeeList' => $this->getEmployeeList(), 'requiredPermissions' => $requiredPermissions));
         $labels['txtEmployee'] = __('Employee');
         $validators['txtEmployee'] = new ohrmValidatorEmployeeNameAutoFill();
         $widgets['cmbSubunit'] = new ohrmWidgetSubUnitDropDown();
         $labels['cmbSubunit'] = __('Sub Unit');
         $subUnitChoices = $widgets['cmbSubunit']->getValidValues();
         $validators['cmbSubunit'] = new sfValidatorChoice(array('choices' => $subUnitChoices, 'required' => false));
         // TODO check cmbWithTerminated if searching for terminated employee
         $widgets['cmbWithTerminated'] = new sfWidgetFormInputCheckbox(array('value_attribute_value' => 'on'));
         $labels['cmbWithTerminated'] = __('Include Past Employees');
         $validators['cmbWithTerminated'] = new sfValidatorBoolean(array('true_values' => array('on'), 'required' => false));
     }
     $this->setWidgets($widgets);
     $this->getWidgetSchema()->setLabels($labels);
     $this->setvalidators($validators);
     $this->setDefaults($defaults);
     $this->getWidgetSchema()->setNameFormat('leaveList[%s]');
     sfWidgetFormSchemaFormatterBreakTags::setNoOfColumns(1);
     $this->getWidgetSchema()->setFormFormatterName('BreakTags');
     // Validate that if both from and to date are given, form date is before to date.
     $this->getValidatorSchema()->setPostValidator(new ohrmValidatorSchemaCompare('calFromDate', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'calToDate', array('throw_global_error' => true, 'skip_if_one_empty' => true), array('invalid' => 'The from date ("%left_field%") must be before the to date ("%right_field%")')));
 }
 public function index($request, $response)
 {
     if (Auth::check()) {
         ///$user = User::where('id', Auth::user()->id)->firstOrFail();
         $leaves = Leave::where('user_id', Auth::user()->id)->get();
         return $this->view('dashboard/index', ['leaves' => $leaves]);
     } else {
         return $response->redirect('/login', $code = 302);
     }
 }
Ejemplo n.º 8
0
 /**
  * When leave is saved, we want to handle it manually
  * so that we can track who changed it, and what they
  * changed it to. 
  */
 public function saveAction()
 {
     try {
         $model = $this->byId();
         if (!$model) {
             throw new Exception("Failed to communicate");
         }
         $params = $this->filterParams();
         $model = $this->userService->updateLeave($model, $params['days']);
     } catch (InvalidModelException $ime) {
         $this->flash($ime->getMessages());
         $this->log->debug($ime->getTraceAsString(), Zend_Log::ERR);
         $model = new Leave();
         $model->bind($this->_getAllParams());
         $this->editAction($model);
         return;
     }
     $this->onModelSaved($model);
 }
Ejemplo n.º 9
0
 public function approve($request, $response)
 {
     if (Auth::isAdmin()) {
         $leave = Leave::findOrFail($request->id);
         $leave->active_token = true;
         $leave->save();
         return $response->redirect('/dashboard/leave/index', $code = 302);
     } else {
         return $response->redirect('/dashboard/leave/index', $code = 302);
     }
 }
 public function getLeaveBreakdown()
 {
     $this->_fetchLeave();
     $statusStrings = array();
     foreach ($this->statusCounter as $status => $count) {
         if (!is_null($status)) {
             $statusStrings[] = __(ucwords(strtolower(Leave::getTextForLeaveStatus($status)))) . "(" . number_format($count, 2) . ")";
         }
     }
     return implode(', ', $statusStrings);
 }
Ejemplo n.º 11
0
 public function testStoreLeaveTaken()
 {
     $checkStoreTaken = new Leave();
     $checkStoreTaken->setLeaveLengthDays(10);
     $checkStoreTaken->setLeaveDate("2007-10-12");
     $checkStoreTaken->setLeaveTypeId("LTY012");
     $checkStoreTaken->setEmployeeId(18);
     $this->assertTrue($checkStoreTaken->storeLeaveTaken());
 }
Ejemplo n.º 12
0
 /**
  * Fetches the leaves of the leave request in the object
  *
  */
 private function _preFetchLeaves()
 {
     $leaveObj = new Leave();
     $leaveRequestObj = $this->getLeaveRequestObj();
     $leaveObjs = $leaveObj->retrieveLeave($leaveRequestObj->getLeaveRequestId());
     $this->setLeaveObjs($leaveObjs);
 }
 public function displayDefineHolidays($modifier = "specific", $edit = false)
 {
     $this->_authenticateViewHoliday();
     $record = null;
     if ($edit) {
         $holidayObj = new Holidays();
         $record = $holidayObj->fetchHoliday($this->getId());
     }
     switch ($modifier) {
         case "specific":
             $holiday = new Holidays();
             $record['holidayList'] = $holiday->listHolidays();
             $path = "/templates/leave/specificHolidaysDefine.php";
             break;
         case "weekend":
             $path = "/templates/leave/weekendHolidaysDefine.php";
             $weekendsObj = new Weekends();
             $record = $weekendsObj->fetchWeek();
             break;
     }
     $record['rights'] = $_SESSION['localRights'];
     $record['changeWeekends'] = Leave::isLeaveTableEmpty();
     $template = new TemplateMerger($record, $path);
     $modifier = $edit;
     $template->display($modifier);
 }
 /**
  * Returns leave status based on weekend and holiday
  * 
  * If weekend, returns Leave::LEAVE_STATUS_LEAVE_WEEKEND
  * If holiday, returns Leave::LEAVE_STATUS_LEAVE_HOLIDAY
  * Else, returns LEAVE_STATUS_LEAVE_PENDING_APPROVAL
  * 
  * @param $isWeekend boolean
  * @param $isHoliday boolean
  * @param $leaveDate string 
  * @return status
  * 
  * @todo Check usage of $leaveDate
  * 
  */
 public function getLeaveRequestStatus($isWeekend, $isHoliday, $leaveDate, LeaveParameterObject $leaveAssignmentData)
 {
     $status = null;
     if ($isWeekend) {
         $status = Leave::LEAVE_STATUS_LEAVE_WEEKEND;
     }
     if ($isHoliday) {
         $status = Leave::LEAVE_STATUS_LEAVE_HOLIDAY;
     }
     if (is_null($status)) {
         $workFlowItem = $this->getWorkflowItemForApplyAction($leaveAssignmentData);
         if (!is_null($workFlowItem)) {
             $status = Leave::getLeaveStatusForText($workFlowItem->getResultingState());
         } else {
             $status = Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL;
         }
     }
     return $status;
 }
Ejemplo n.º 15
0
 public function getLeaveRequestActions($request, $loggedInEmpNumber)
 {
     $actions = array();
     if (!$request->isStatusDiffer()) {
         $includeRoles = array();
         $excludeRoles = array();
         $userRoleManager = $this->getUserRoleManager();
         $empNumber = $request->getEmpNumber();
         // If looking at own leave request, only consider ESS role
         if ($empNumber == $loggedInEmpNumber && ($userRoleManager->essRightsToOwnWorkflow() || !$userRoleManager->isEntityAccessible('Employee', $empNumber))) {
             $includeRoles = array('ESS');
         }
         $leaveTypeDeleted = $request->getLeaveType()->getDeleted();
         $status = Leave::getTextForLeaveStatus($request->getLeaveStatusId());
         if ($leaveTypeDeleted) {
             $status = Leave::LEAVE_STATUS_LEAVE_TYPE_DELETED_TEXT . ' ' . $status;
         }
         $workFlowItems = $userRoleManager->getAllowedActions(WorkflowStateMachine::FLOW_LEAVE, $status, $excludeRoles, $includeRoles, array('Employee' => $empNumber));
         foreach ($workFlowItems as $item) {
             $name = $item->getAction();
             $actions[$item->getId()] = ucfirst(strtolower($name));
         }
     }
     return $actions;
 }
 /**
  * 
  * Get Leave array
  * @param LeaveParameterObject $leaveAssignmentData
  * @return array
  */
 public function createLeaveObjectListForAppliedRange(LeaveParameterObject $leaveAssignmentData)
 {
     $leaveList = array();
     $from = strtotime($leaveAssignmentData->getFromDate());
     $to = strtotime($leaveAssignmentData->getToDate());
     for ($timeStamp = $from; $timeStamp <= $to; $timeStamp = $this->incDate($timeStamp)) {
         $leave = new Leave();
         $leaveDate = date('Y-m-d', $timeStamp);
         $isWeekend = $this->isWeekend($leaveDate, $leaveAssignmentData);
         $isHoliday = $this->isHoliday($leaveDate, $leaveAssignmentData);
         $isHalfday = $this->isHalfDay($leaveDate, $leaveAssignmentData);
         $isHalfDayHoliday = $this->isHalfdayHoliday($leaveDate, $leaveAssignmentData);
         $leave->setLeaveDate($leaveDate);
         $leave->setLeaveComments($leaveAssignmentData->getComment());
         $leave->setLeaveLengthDays($this->calculateDateDeference($leaveAssignmentData, $isWeekend, $isHoliday, $isHalfday, $isHalfDayHoliday));
         $leave->setStartTime($leaveAssignmentData->getFromTime() != '' ? $leaveAssignmentData->getFromTime() : '00:00');
         $leave->setEndTime($leaveAssignmentData->getToTime() != '' ? $leaveAssignmentData->getToTime() : '00:00');
         $leave->setLeaveLengthHours($this->calculateTimeDeference($leaveAssignmentData, $isWeekend, $isHoliday, $isHalfday, $isHalfDayHoliday));
         $leave->setLeaveStatus($this->getLeaveRequestStatus($isWeekend, $isHoliday, $leaveDate));
         array_push($leaveList, $leave);
     }
     return $leaveList;
 }
Ejemplo n.º 17
0
 public function isAuthorizedPersonForLeave(){
     $id = $_GET['id'];
     $rtn = $this->isSUorAdmin();
     if(!$rtn){
         $model=Leave::model()->findByPk($id);
         if($model!==null){
             $rtn = (!Yii::app()->user->isGuest && Yii::app()->user->person->id === $model->person_id);
         }else{
             $rtn = false;
         }
     }
     return $rtn;
 }
Ejemplo n.º 18
0
 public function changeLeaveStatus(Leave $leave, $entitlementChanges, $removeLinkedEntitlements = false)
 {
     $conn = Doctrine_Manager::connection();
     $conn->beginTransaction();
     try {
         if ($removeLinkedEntitlements) {
             $leaveId = $leave->getId();
             $stmt = $conn->prepare("UPDATE ohrm_leave_leave_entitlement le LEFT JOIN ohrm_leave_entitlement e " . "on e.id = le.entitlement_id " . "SET e.days_used = IF(e.days_used<le.length_days,0,e.days_used - le.length_days) " . "WHERE le.leave_id = ?");
             $stmt->execute(array($leaveId));
             Doctrine_Query::create()->delete()->from('LeaveLeaveEntitlement l')->where('l.leave_id = ?', $leaveId)->execute();
         }
         $leave->save();
         if (isset($entitlementChanges['change'])) {
             // TODO: Need to update days_used here
             // Also need to check if we need to delete all entitlements or only have changes
             $changes = $entitlementChanges['change'];
             foreach ($changes as $leaveId => $change) {
                 $updateSql = '';
                 $idList = '';
                 $separator = '';
                 foreach ($change as $entitlementId => $length) {
                     $idList .= $separator . $entitlementId;
                     $updateSql .= sprintf(' WHEN e.id = %d THEN e.days_used + %f', $entitlementId, $length);
                     $separator = ',';
                     $entitlementAssignment = Doctrine_Query::create()->from('LeaveLeaveEntitlement l')->where('l.leave_id = ?', $leaveId)->andWhere('l.entitlement_id = ?', $entitlementId)->fetchOne();
                     if ($entitlementAssignment === false) {
                         $entitlementAssignment = new LeaveLeaveEntitlement();
                         $entitlementAssignment->setLeaveId($leaveId);
                         $entitlementAssignment->setEntitlementId($entitlementId);
                         $entitlementAssignment->setLengthDays($length);
                     } else {
                         $entitlementAssignment->setLengthDays($entitlementAssignment->getLengthDays() + $length);
                     }
                     $entitlementAssignment->save();
                 }
                 if ($updateSql != '') {
                     $query = "UPDATE ohrm_leave_entitlement e " . "SET e.days_used = CASE " . $updateSql . " END " . sprintf(" WHERE e.id IN (%s)", $idList);
                     $conn->execute($query);
                 }
             }
         }
         $conn->commit();
         return true;
     } catch (DaoException $e) {
         $conn->rollback();
         throw new DaoException($e->getMessage(), 0, $e);
     }
 }
 /**
  * @param $filterLeaveStatus array Array of leave statuses to include. If set, only
  *                                 leaves with these statuses are returned.
  * @param $fromDate Date Start date to search
  * @param $toDate Date End date to search
  */
 protected function _buildObjArr($result, $supervisor = false, $filterLeaveStatus = null, $fromDate = null, $toDate = null)
 {
     $objArr = null;
     while ($row = mysql_fetch_row($result)) {
         $tmpLeaveRequestArr = new LeaveRequests();
         $tmpLeaveRequestArr->setLeaveTypeName($row[0]);
         $tmpLeaveRequestArr->setLeaveRequestId($row[1]);
         $tmpLeave = new Leave();
         $tmpLeaveArr = $tmpLeave->retrieveLeave($row[1]);
         $noOfDays = 0;
         $hours = 0;
         if (isset($tmpLeaveArr) && !empty($tmpLeaveArr)) {
             $totalLeaves = count($tmpLeaveArr);
             $tmpLeaveRequestArr->setLeaveFromDate($tmpLeaveArr[0]->getLeaveDate());
             if (isset($filterLeaveStatus)) {
                 if (in_array($tmpLeaveArr[0]->getLeaveStatus(), $filterLeaveStatus)) {
                     $noOfDays = $tmpLeaveArr[0]->getLeaveLengthDays();
                     $hours = $tmpLeaveArr[0]->getLeaveLengthHours();
                 }
             } else {
                 $noOfDays = $tmpLeaveArr[0]->getLeaveLengthDays();
                 $hours = $tmpLeaveArr[0]->getLeaveLengthHours();
             }
             if ($tmpLeaveArr[0]->getStartTime() != null && $tmpLeaveArr[0]->getEndTime() != null) {
                 $tmpLeaveRequestArr->setStartTime($tmpLeaveArr[0]->getStartTime());
                 $tmpLeaveRequestArr->setEndTime($tmpLeaveArr[0]->getEndTime());
             }
             if ($totalLeaves > 1) {
                 $tmpLeaveRequestArr->setLeaveToDate($tmpLeaveArr[$totalLeaves - 1]->getLeaveDate());
                 $status = $tmpLeaveArr[0]->getLeaveStatus();
                 $comments = $tmpLeaveArr[0]->getLeaveComments();
                 $commentsDiffer = false;
                 for ($i = 1; $i < $totalLeaves; $i++) {
                     if ($tmpLeaveArr[$i]->getLeaveLengthHours() > 0) {
                         if (isset($filterLeaveStatus)) {
                             if (in_array($tmpLeaveArr[$i]->getLeaveStatus(), $filterLeaveStatus)) {
                                 $noOfDays += $tmpLeaveArr[$i]->getLeaveLengthDays();
                                 $hours += $tmpLeaveArr[$i]->getLeaveLengthHours();
                             }
                         } else {
                             $noOfDays += $tmpLeaveArr[$i]->getLeaveLengthDays();
                             $hours += $tmpLeaveArr[$i]->getLeaveLengthHours();
                         }
                         if ($status != $tmpLeaveArr[$i]->getLeaveStatus()) {
                             $status = self::LEAVEREQUESTS_MULTIPLESTATUSES;
                         }
                     }
                     if ($comments != $tmpLeaveArr[$i]->getLeaveComments()) {
                         $commentsDiffer = true;
                     }
                 }
                 $tmpLeaveRequestArr->setLeaveComments($comments);
                 $tmpLeaveRequestArr->setCommentsDiffer($commentsDiffer);
                 $tmpLeaveRequestArr->setLeaveStatus($status);
             } else {
                 $tmpLeaveRequestArr->setLeaveStatus($tmpLeaveArr[0]->getLeaveStatus());
                 $tmpLeaveRequestArr->setLeaveComments($tmpLeaveArr[0]->getLeaveComments());
             }
             $tmpLeaveRequestArr->setNoDays(number_format($noOfDays, 2));
             $tmpLeaveRequestArr->setLeaveLengthHours(number_format($hours, 2));
             /* Check that at least one leave in the list contains a status in
              * $filterLeaveStatus.
              */
             $skip = false;
             if (isset($filterLeaveStatus)) {
                 $skip = true;
                 for ($i = 0; $i < $totalLeaves; $i++) {
                     if (in_array($tmpLeaveArr[$i]->getLeaveStatus(), $filterLeaveStatus)) {
                         $skip = false;
                         break;
                     }
                 }
             } else {
                 if ($supervisor && $tmpLeaveRequestArr->getLeaveStatus() == self::LEAVE_STATUS_LEAVE_TAKEN) {
                     $skip = true;
                 }
             }
             // Find the leave requets for the given data range
             if (isset($toDate) && !$skip) {
                 $endDate = $tmpLeaveRequestArr->getLeaveToDate();
                 if (empty($endDate)) {
                     $endDate = $tmpLeaveRequestArr->getLeaveFromDate();
                 } else {
                     $endDate = $tmpLeaveRequestArr->getLeaveToDate();
                 }
                 if (strtotime($endDate) >= strtotime($fromDate) && strtotime($tmpLeaveRequestArr->getLeaveFromDate()) <= strtotime($toDate)) {
                     $skip = false;
                 } else {
                     $skip = true;
                 }
             }
             if (!$skip) {
                 if ($supervisor) {
                     $tmpLeaveRequestArr->setEmployeeName("{$row[2]} {$row[4]}");
                     $tmpLeaveRequestArr->setEmployeeId($row[3]);
                 }
                 $objArr[] = $tmpLeaveRequestArr;
             }
         }
     }
     return $objArr;
 }
Ejemplo n.º 20
0
 public function leaveList($empID)
 {
     require_once FCPATH . "application/controllers/Leave.php";
     $leave = new Leave();
     $leave->getList($empID);
 }
 public function testHandleLeaveStatusChangeOneEntitlementExtra()
 {
     $empNumber = 1;
     $leaveType = 2;
     $leave1 = new Leave();
     $leave1->fromArray(array('id' => NULL, 'date' => '2012-09-11', 'length_days' => 1));
     $leave2 = new Leave();
     $leave2->fromArray(array('id' => NULL, 'date' => '2012-09-12', 'length_days' => 1));
     $leaveDates = array($leave1, $leave2);
     $entitlement1 = new LeaveEntitlement();
     $entitlement1->fromArray(array('id' => 6, 'emp_number' => 1, 'no_of_days' => 4, 'days_used' => 1, 'leave_type_id' => 2, 'from_date' => '2012-09-10', 'to_date' => '2012-09-14', 'credited_date' => '2012-05-01', 'note' => 'Created by Unit test', 'entitlement_type' => LeaveEntitlement::ENTITLEMENT_TYPE_ADD, 'deleted' => 0));
     $entitlements = array($entitlement1);
     $mockService = $this->getMock('LeaveEntitlementService', array('getValidLeaveEntitlements'));
     $mockService->expects($this->once())->method('getValidLeaveEntitlements')->with($empNumber, $leaveType, '2012-09-11', '2012-09-12', 'from_date', 'ASC')->will($this->returnValue($entitlements));
     $this->strategy->setLeaveEntitlementService($mockService);
     // Apply, $allowNoEntitlements = false
     $results = $this->strategy->handleLeaveCreate($empNumber, $leaveType, $leaveDates);
     $expected = array('current' => array('2012-09-11' => array(6 => 1), '2012-09-12' => array(6 => 1)), 'change' => array());
     $this->assertEquals($expected, $results);
 }
Ejemplo n.º 22
0
 /**
  * Wrpper to edit holidays
  *
  * @param unknown_type $modifier
  */
 public function editHoliday($modifier = "specific")
 {
     $this->_authenticateViewHoliday();
     switch ($modifier) {
         case "specific":
             $objLeave = $this->getObjLeave();
             $this->getObjLeave()->edit();
             Leave::updateLeavesForDate($objLeave->getDate(), $objLeave->getLength());
             break;
         case "weekend":
             $this->getObjLeave()->editDay();
             break;
     }
 }
 public function defineWorkflowParameter()
 {
     global $xoopsUser;
     switch ($this->window_workflow) {
         case "LEAVE":
             include_once "../hr/class/Leave.php";
             $lev = new Leave();
             $lev->leave_id = $this->primarykey_value;
             $lev->person_id = $this->person_id;
             $lev->window_workflow = $this->window_workflow;
             return $lev->defineWorkflowParameter();
             break;
         case "GENERCLAIM":
             include_once "../hr/class/Generalclaim.php";
             $gen = new Generalclaim();
             $gen->generalclaim_id = $this->primarykey_value;
             $gen->person_id = $this->person_id;
             $gen->window_workflow = $this->window_workflow;
             return $gen->defineWorkflowParameter();
             break;
         case "MEDICCLAIM":
             include_once "../hr/class/Medicalclaim.php";
             $me = new Medicalclaim();
             $me->medicalclaim_id = $this->primarykey_value;
             $me->person_id = $this->person_id;
             $me->window_workflow = $this->window_workflow;
             return $me->defineWorkflowParameter();
             break;
         case "OVERCLAIM":
             include_once "../hr/class/Overtimeclaim.php";
             $ov = new Overtimeclaim_id();
             $ov->overtimeclaim_id = $this->primarykey_value;
             $ov->person_id = $this->person_id;
             $ov->window_workflow = $this->window_workflow;
             return $ov->defineWorkflowParameter();
             break;
         case "TRAVECLAIM":
             include_once "../hr/class/Travellingclaim.php";
             $tr = new Travellingclaim();
             $tr->travellingclaim_id = $this->primarykey_value;
             $tr->person_id = $this->person_id;
             $tr->window_workflow = $this->window_workflow;
             return $tr->defineWorkflowParameter();
             break;
         case "LEAVEADJ":
             include_once "../hr/class/Leaveadjustment.php";
             $led = new Leaveadjustment();
             $led->leaveadjustment_id = $this->primarykey_value;
             $led->person_id = $this->person_id;
             $led->window_workflow = $this->window_workflow;
             return $led->defineWorkflowParameter();
             break;
         default:
             break;
     }
     //        $uid = $xoopsUser->getVar('uid');
     //        /* start define hod */
     //        include_once "../hr/class/Employee.php";
     //        $emp = new Employee();
     //
     //        $hod_uid = $emp->getSupervisorEmployeeID($uid);
     //        /* end */
     //      return $parameter_array = array(
     //                                '{own_uid}'=>$uid,
     //                                '{hod_uid}'=>$hod_uid,
     //                                '{email_list}'=>'',
     //                                '{sms_list}'=>'',
     //                                '{bypassapprove}'=>false
     //                                    );
 }
Ejemplo n.º 24
0
 public function testIsLeaveTableEmpty()
 {
     $result = Leave::isLeaveTableEmpty();
     $this->assertFalse($result);
 }
Ejemplo n.º 25
0
 public function defineWorkflowParameter()
 {
     //        /* start define hod */
     //        include_once "../hr/class/Employee.php";
     //        $emp = new Employee();
     //
     switch ($this->window_workflow) {
         case "LEAVE":
             include_once "../hr/class/Leave.php";
             $lev = new Leave();
             $lev->leave_id = $this->primarykey_value;
             $lev->person_id = $this->person_id;
             $lev->window_workflow = $this->window_workflow;
             return $lev->defineWorkflowParameter();
             break;
         case "GENERCLAIM":
             include_once "../hr/class/Generalclaim.php";
             $gen = new Generalclaim();
             $gen->generalclaim_id = $this->primarykey_value;
             $gen->person_id = $this->person_id;
             $gen->window_workflow = $this->window_workflow;
             return $gen->defineWorkflowParameter();
             break;
         case "MEDICCLAIM":
             include_once "../hr/class/Medicalclaim.php";
             $me = new Medicalclaim();
             $me->medicalclaim_id = $this->primarykey_value;
             $me->person_id = $this->person_id;
             $me->window_workflow = $this->window_workflow;
             return $me->defineWorkflowParameter();
             break;
         case "OVERCLAIM":
             include_once "../hr/class/Overtimeclaim.php";
             $ov = new Overtimeclaim();
             $ov->overtimeclaim_id = $this->primarykey_value;
             $ov->person_id = $this->person_id;
             $ov->window_workflow = $this->window_workflow;
             return $ov->defineWorkflowParameter();
             break;
         case "TRAVECLAIM":
             include_once "../hr/class/Travellingclaim.php";
             $tr = new Travellingclaim();
             $tr->travellingclaim_id = $this->primarykey_value;
             $tr->person_id = $this->person_id;
             $tr->window_workflow = $this->window_workflow;
             return $tr->defineWorkflowParameter();
             break;
         case "LEAVEADJ":
             include_once "../hr/class/Leaveadjustment.php";
             $led = new Leaveadjustment();
             $led->leaveadjustment_id = $this->primarykey_value;
             $led->person_id = $this->person_id;
             $led->window_workflow = $this->window_workflow;
             return $led->defineWorkflowParameter();
             break;
         default:
             break;
     }
 }
Ejemplo n.º 26
0
 protected function compareLeave(Leave $expected, Leave $result)
 {
     $this->assertTrue($result instanceof Leave);
     $expectedId = $expected->getId();
     if (!empty($expectedId)) {
         $this->assertEquals($expectedId, $result->getId());
     } else {
         $leaveId = $result->getId();
         $this->assertTrue(!empty($leaveId));
     }
     $this->assertEquals($expected->getLeaveTypeId(), $result->getLeaveTypeId());
     $this->assertEquals($expected->getDate(), $result->getDate());
     $this->assertEquals($expected->getEmpNumber(), $result->getEmpNumber());
     $this->assertEquals($expected->getComments(), $result->getComments());
     $this->assertEquals($expected->getLengthHours(), $result->getLengthHours());
     $this->assertEquals($expected->getLengthDays(), $result->getLengthDays());
     $this->assertEquals($expected->getStatus(), $result->getStatus());
     $this->assertEquals($expected->getLeaveRequestId(), $result->getLeaveRequestId());
 }
Ejemplo n.º 27
0
                     $update = array('paternity_leave' => '');
                     DB::table('employee_summary')->where('employee_id', $employeeId)->whereBetween('daydate', $leaveDateArr)->update($update);
                     //Leave Without Pay
                 } elseif ('leave without Pay' === strtolower($leave->nature_of_leave)) {
                     $update = array('leave_without_pay' => '');
                     DB::table('employee_summary')->where('employee_id', $employeeId)->whereBetween('daydate', $leaveDateArr)->update($update);
                 }
             }
         }
     }
     return Redirect::route('adminHumanResource');
 } else {
     //Mulitple check
     //Code here
     foreach ($data["check"] as $check) {
         $leave = Leave::whereIn('id', $data["check"])->first();
         $employeeId = $leave->employee_id;
         $leaveSetting = DB::table('leave_setting')->where('employee_id', $employeeId)->get();
         $data["action"] = (int) $data["action"];
         if ($data["action"] === 1 && -1 === (int) $leave->status || $data["action"] === 1 && 0 === (int) $leave->status) {
             //Aprroved
             if (0 !== (int) $leaveSetting[0]->leave_credits) {
                 $leaveBalance = $leaveSetting[0]->leave_balance -= 1;
                 DB::table('leave_setting')->where('employee_id', $employeeId)->update(array('leave_balance' => $leaveBalance));
                 DB::table('leave')->where('id', $leave->id)->update(array('status' => 1));
             }
         }
         if ($data["action"] === 0 && -1 === (int) $leave->status) {
             //Denied
             if ($leaveSetting[0]->leave_balance <= (int) $leaveSetting[0]->leave_credits) {
                 /*$leaveBalance = $leaveSetting[0]->leave_balance;
 public function testGetLeaveActions()
 {
     $loggedInEmpNumber = 4;
     $leave = new Leave();
     $leave->setStatus(Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL);
     $leave->setEmpNumber(5);
     $approveAction = new WorkflowStateMachine();
     $approveAction->fromArray(array('id' => 2, 'workflow' => 'leave', 'state' => 'PENDING APPROVAL', 'role' => 'ADMIN', 'action' => 'APPROVE', 'resulting_state' => 'SCHEDULED', 'roles_to_notify' => '', 'priority' => 0));
     $cancelAction = new WorkflowStateMachine();
     $cancelAction->fromArray(array('id' => 3, 'workflow' => 'leave', 'state' => 'PENDING APPROVAL', 'role' => 'ADMIN', 'action' => 'CANCEL', 'resulting_state' => 'CANCELLED', 'roles_to_notify' => '', 'priority' => 0));
     $rejectAction = new WorkflowStateMachine();
     $rejectAction->fromArray(array('id' => 5, 'workflow' => 'leave', 'state' => 'PENDING APPROVAL', 'role' => 'ADMIN', 'action' => 'REJECT', 'resulting_state' => 'REJECTED', 'roles_to_notify' => '', 'priority' => 0));
     $actions = array($approveAction, $cancelAction, $rejectAction);
     $userManager = $this->getMock('BasicUserRoleManager', array('getAllowedActions'));
     $userManager->expects($this->any())->method('getAllowedActions')->with(WorkflowStateMachine::FLOW_LEAVE, $leave->getTextLeaveStatus(), array(), array())->will($this->returnValue($actions));
     $this->leaveRequestService->setUserRoleManager($userManager);
     $result = $this->leaveRequestService->getLeaveActions($leave, $loggedInEmpNumber);
     $this->verifyLeaveActions($actions, $result);
 }
 /**
  * Overrides _buildObjArr of LeaveQuota
  * Builds the Leave Summary from the resource
  *
  * @param resource $result
  * @return Array[][] LeaveSummary
  * @access protected
  * @author S.H.Mohanjith
  *
  */
 protected function _buildObjArr($result)
 {
     $leaveObj = new Leave();
     $leaveObj->setEmployeeId($this->getEmployeeId());
     $objArr = null;
     $leveTypeObj = new LeaveType();
     $leaveTypes = $leveTypeObj->fetchLeaveTypes(true);
     $objLeaveType = new LeaveType();
     if (is_array($leaveTypes)) {
         foreach ($leaveTypes as $leaveType) {
             $tmpLeaveSummary = new LeaveSummary();
             $tmpLeaveSummary->setLeaveTypeId($leaveType->getLeaveTypeId());
             $tmpLeaveSummary->setLeaveTypeName($leaveType->getLeaveTypeName());
             $tmpLeaveSummary->setNoOfDaysAllotted(0);
             $taken = $leaveObj->countLeave($tmpLeaveSummary->getLeaveTypeId(), $this->getYear());
             $tmpLeaveSummary->setLeaveTaken($taken);
             $tmpLeaveSummary->setLeaveAvailable(0);
             $tmpLeaveSummary->setYear($this->getYear());
             $tmpLeaveSummary->setLeaveTypeAvailable($leaveType->getLeaveTypeAvailable());
             if ($tmpLeaveSummary->getLeaveTypeAvailable() == $objLeaveType->availableStatusFlag || $tmpLeaveSummary->getLeaveTaken() > 0) {
                 $leaveTypeList[$leaveType->getLeaveTypeId()] = $tmpLeaveSummary;
             }
         }
         $objLeaveType = new LeaveType();
         while ($row = mysql_fetch_row($result)) {
             if (isset($leaveTypeList[$row[1]])) {
                 $tmpLeaveSummary = $leaveTypeList[$row[1]];
                 $leaveTypeAvailable = $tmpLeaveSummary->getLeaveTypeAvailable();
                 $tmpLeaveSummary->setNoOfDaysAllotted($row[3]);
                 $taken = $tmpLeaveSummary->getLeaveTaken();
                 $alloted = $tmpLeaveSummary->getNoOfDaysAllotted();
                 $tmpLeaveSummary->setLeaveAvailable($alloted - $taken);
                 $leaveTypeList[$row[1]] = $tmpLeaveSummary;
             }
         }
         if (isset($leaveTypeList)) {
             $objArr = $leaveTypeList;
             sort($objArr);
         }
     }
     return $objArr;
 }
Ejemplo n.º 30
0
 /**
  * Get Leave
  * @return Leave
  */
 public function createLeaveObjectListForAppliedRange()
 {
     $posts = $this->getValues();
     $leaveList = array();
     $from = strtotime($posts['txtFromDate']);
     $to = strtotime($posts['txtToDate']);
     for ($timeStamp = $from; $timeStamp <= $to; $timeStamp = $this->incDate($timeStamp)) {
         $leave = new Leave();
         $leaveDate = date('Y-m-d', $timeStamp);
         $isWeekend = $this->isWeekend($leaveDate);
         $isHoliday = $this->isHoliday($leaveDate);
         $isHalfday = $this->isHalfDay($leaveDate);
         $isHalfDayHoliday = $this->isHalfdayHoliday($leaveDate);
         $leave->setLeaveDate($leaveDate);
         $leave->setLeaveComments($posts['txtComment']);
         $leave->setLeaveLengthDays($this->calculateDateDeference($isWeekend, $isHoliday, $isHalfday, $isHalfDayHoliday));
         $leave->setStartTime($posts['txtFromTime'] != '' ? $posts['txtFromTime'] : '00:00');
         $leave->setEndTime($posts['txtToTime'] != '' ? $posts['txtToTime'] : '00:00');
         $leave->setLeaveLengthHours($this->calculateTimeDeference($isWeekend, $isHoliday, $isHalfday, $isHalfDayHoliday));
         $leave->setLeaveStatus($this->getLeaveRequestStatus($isWeekend, $isHoliday));
         array_push($leaveList, $leave);
     }
     return $leaveList;
 }