/**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $trimmedValue = trim($value);
     $pattern = $this->getOption('date_format');
     if (empty($pattern)) {
         $pattern = sfContext::getInstance()->getUser()->getDateFormat();
     }
     $required = $this->getOption('required');
     $isDefaultValue = strcasecmp(str_replace('yyyy', 'yy', $trimmedValue), get_datepicker_date_format($pattern)) == 0;
     if ($trimmedValue == '' || $isDefaultValue) {
         if (!$required) {
             // If not required and empty or the format pattern, return valid
             return null;
         } else {
             throw new sfValidatorError($this, 'required');
         }
     }
     $localizationService = new LocalizationService();
     $result = $localizationService->convertPHPFormatDateToISOFormatDate($pattern, $trimmedValue);
     $valid = $result == "Invalid date" ? false : true;
     if (!$valid) {
         throw new sfValidatorError($this, 'bad_format', array('value' => $value, 'date_format' => $this->getOption('date_format_error') ? $this->getOption('date_format_error') : get_datepicker_date_format($pattern)));
     }
     return $result;
 }
 protected function getFormDefaults()
 {
     $defaults = $this->form->getDefaults();
     // Form defaults are in the user date format, convert to standard date format
     $pattern = sfContext::getInstance()->getUser()->getDateFormat();
     $localizationService = new LocalizationService();
     $defaults['date']['from'] = $localizationService->convertPHPFormatDateToISOFormatDate($pattern, $defaults['date']['from']);
     $defaults['date']['to'] = $localizationService->convertPHPFormatDateToISOFormatDate($pattern, $defaults['date']['to']);
     return $defaults;
 }
 protected function getDefaultFilters()
 {
     $filters = $this->form->getDefaults();
     // Form defaults are in the user date format, convert to standard date format
     $pattern = sfContext::getInstance()->getUser()->getDateFormat();
     $localizationService = new LocalizationService();
     $filters['date']['from'] = $localizationService->convertPHPFormatDateToISOFormatDate($pattern, $filters['date']['from']);
     $filters['date']['to'] = $localizationService->convertPHPFormatDateToISOFormatDate($pattern, $filters['date']['to']);
     $employee = array('empId' => $this->getUser()->getAttribute('auth.empNumber'));
     $filters['employee'] = $employee;
     return $filters;
 }
 public function execute($filterChain)
 {
     $languages = $this->getContext()->getRequest()->getLanguages();
     $userCulture = $this->getConfigService()->getAdminLocalizationDefaultLanguage();
     $localizationService = new LocalizationService();
     $languageToSet = !empty($languages[0]) && $this->getConfigService()->getAdminLocalizationUseBrowserLanguage() == "Yes" && key_exists($languages[0], $localizationService->getSupportedLanguageListFromYML()) ? $languages[0] : $userCulture;
     $datePattern = $this->getContext()->getUser()->getDateFormat();
     $datePattern = isset($datePattern) ? $datePattern : $this->getConfigService()->getAdminLocalizationDefaultDateFormat();
     $user = $this->getContext()->getUser();
     $user->setCulture($languageToSet);
     $user->setDateFormat($datePattern);
     // Execute next filter in filter chain
     $filterChain->execute();
 }
 protected function getDate($value)
 {
     $date = null;
     $valid = false;
     $trimmedValue = trim($value);
     $pattern = $this->getOption('date_format');
     // check date format
     if (is_string($value) && !empty($pattern)) {
         $localizationService = new LocalizationService();
         $result = $localizationService->convertPHPFormatDateToISOFormatDate($pattern, $trimmedValue);
         if ($result != "Invalid date") {
             $date = $result;
             $valid = true;
         }
     }
     return $date;
 }
示例#6
0
 /**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $date = null;
     $valid = false;
     $trimmedValue = trim($value);
     $pattern = $this->getOption('date_format');
     // If not required and empty or the format pattern, return valid.
     if (!$this->getOption('required') && ($trimmedValue == '' || strcasecmp(str_replace('yyyy', 'yy', $trimmedValue), get_datepicker_date_format($pattern)) == 0)) {
         return null;
     }
     $localizationService = new LocalizationService();
     $result = $localizationService->convertPHPFormatDateToISOFormatDate($pattern, $trimmedValue);
     $valid = $result == "Invalid date" ? false : true;
     if (!$valid) {
         throw new sfValidatorError($this, 'bad_format', array('value' => $value, 'date_format' => $this->getOption('date_format_error') ? $this->getOption('date_format_error') : get_datepicker_date_format($pattern)));
     }
     return $result;
 }
 protected function getEmployeeEntitlement($parameters)
 {
     $localizationService = new LocalizationService();
     $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat();
     $fromDate = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $parameters['fd']);
     $toDate = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $parameters['td']);
     $leaveEntitlementSearchParameterHolder = new LeaveEntitlementSearchParameterHolder();
     $leaveEntitlementSearchParameterHolder->setEmpNumber($parameters['empId']);
     $leaveEntitlementSearchParameterHolder->setFromDate($fromDate);
     $leaveEntitlementSearchParameterHolder->setLeaveTypeId($parameters['lt']);
     $leaveEntitlementSearchParameterHolder->setToDate($toDate);
     $entitlementList = $this->getEntitlementService()->searchLeaveEntitlements($leaveEntitlementSearchParameterHolder);
     $oldValue = 0;
     $newValue = $parameters['ent'];
     foreach ($entitlementList as $existingEntitlement) {
         $oldValue += $existingEntitlement->getNoOfDays();
     }
     return array($oldValue, $newValue + $oldValue);
 }
 /**
  * Get leave balance for given leave type
  * Request parameters:
  * *) leaveType: Leave Type ID
  * *) empNumber: (optional) employee number. If not present, currently
  *               logged in employee is used.
  * 
  * @param sfWebRequest $request
  */
 public function execute($request)
 {
     sfConfig::set('sf_web_debug', false);
     sfConfig::set('sf_debug', false);
     $leaveTypeId = $request->getParameter('leaveType');
     $empNumber = $request->getParameter('empNumber');
     $user = $this->getUser();
     $loggedEmpNumber = $user->getAttribute('auth.empNumber');
     $allowed = false;
     if (empty($empNumber)) {
         $empNumber = $loggedEmpNumber;
         $allowed = true;
     } else {
         $manager = $this->getContext()->getUserRoleManager();
         if ($manager->isEntityAccessible('Employee', $empNumber)) {
             $allowed = true;
         } else {
             $allowed = $loggedEmpNumber == $empNumber;
         }
     }
     $response = $this->getResponse();
     $response->setHttpHeader('Expires', '0');
     $response->setHttpHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
     $response->setHttpHeader("Cache-Control", "private", false);
     if ($allowed) {
         $localizationService = new LocalizationService();
         $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat();
         $startDateTimeStamp = strtotime($localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $request->getParameter("startDate")));
         if ($startDateTimeStamp) {
             $leavePeriod = $this->getLeavePeriodService()->getLeavePeriod($startDateTimeStamp);
         } else {
             $leavePeriod = $this->getLeavePeriodService()->getCurrentLeavePeriod();
         }
         $balance = '--';
         if ($leavePeriod instanceof LeavePeriod) {
             $balance = $this->getLeaveEntitlementService()->getLeaveBalance($empNumber, $leaveTypeId, $leavePeriod->getLeavePeriodId());
         }
         echo json_encode($balance);
     }
     return sfView::NONE;
 }
示例#9
0
 /**
  * this is used to make language list from supported_languages.yml
  * @return <type>
  */
 public function getLanguages()
 {
     $localizationService = new LocalizationService();
     return $localizationService->getSupportedLanguageListFromYML();
 }
示例#10
0
 protected function getReviewSearchClues($request, $suffix = '')
 {
     $clues = array();
     $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat();
     $localizationService = new LocalizationService();
     if ($request instanceof sfWebRequest) {
         $clues['from'] = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $request->getParameter('txtPeriodFromDate' . $suffix));
         $clues['to'] = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $request->getParameter('txtPeriodToDate' . $suffix));
         $clues['due'] = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $request->getParameter('txtDueDate' . $suffix));
         $clues['jobCode'] = $request->getParameter('txtJobTitleCode' . $suffix);
         $clues['divisionId'] = $request->getParameter('txtSubDivisionId' . $suffix);
         $clues['empName'] = $request->getParameter('txtEmpName' . $suffix);
         $clues['empId'] = empty($clues['empName']) ? 0 : $request->getParameter('hdnEmpId' . $suffix);
         $clues['reviewerName'] = $request->getParameter('txtReviewerName' . $suffix);
         $clues['reviewerId'] = empty($clues['reviewerName']) ? 0 : $request->getParameter('hdnReviewerId' . $suffix);
         $clues['pageNo'] = $request->getParameter('hdnPageNo' . $suffix);
     } elseif ($request instanceof PerformanceReview) {
         $clues['from'] = $request->getPeriodFrom();
         $clues['to'] = $request->getPeriodTo();
         $clues['due'] = $request->getDueDate();
         $clues['jobCode'] = $request->getJobTitleCode();
         $clues['divisionId'] = $request->getSubDivisionId();
         $clues['empName'] = $request->getEmployee()->getFirstName() . " " . $request->getEmployee()->getLastName();
         $clues['empId'] = $request->getEmployeeId();
         $clues['reviewerName'] = $request->getReviewer()->getFirstName() . " " . $request->getReviewer()->getLastName();
         $clues['reviewerId'] = $request->getReviewerId();
         $clues['id'] = $request->getId();
     }
     return $clues;
 }
 public function execute($request)
 {
     $this->_checkAuthentication();
     $this->editmode = null;
     $this->userObj = $this->getContext()->getUser()->getAttribute('user');
     $this->employeeId = $this->userObj->getEmployeeNumber();
     $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_OUT);
     $actionableStatesList = $this->userObj->getActionableAttendanceStates($actions);
     $timeZoneOffset = $this->userObj->getUserTimeZoneOffset();
     $timeStampDiff = $timeZoneOffset * 3600 - date('Z');
     $this->currentDate = date('Y-m-d', time() + $timeStampDiff);
     $this->currentTime = date('H:i', time() + $timeStampDiff);
     $this->timezone = $timeZoneOffset * 3600;
     $localizationService = new LocalizationService();
     $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat();
     if ($this->getUser()->hasFlash('templateMessage')) {
         list($messageType, $message) = $this->getUser()->getFlash('templateMessage');
         $this->getUser()->setFlash($messageType, $message);
     }
     $attendanceRecord = $this->getAttendanceService()->getLastPunchRecord($this->employeeId, $actionableStatesList);
     if (is_null($attendanceRecord)) {
         $this->allowedActions = $this->userObj->getAllowedActions(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL);
     } else {
         $this->redirect("attendance/punchOut");
     }
     $this->punchInTime = null;
     $this->punchInUtcTime = null;
     $this->punchInNote = null;
     $this->actionPunchOut = null;
     $this->form = new AttendanceForm();
     $this->actionPunchIn = $this->getActionName();
     $this->attendanceFormToImplementCsrfToken = new AttendanceFormToImplementCsrfToken();
     if ($request->isMethod('post')) {
         $accessFlowStateMachineService = new AccessFlowStateMachineService();
         $attendanceRecord = new AttendanceRecord();
         $attendanceRecord->setEmployeeId($this->employeeId);
         if (!in_array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_TIME, $this->allowedActions)) {
             $this->attendanceFormToImplementCsrfToken->bind($request->getParameter('attendance'));
             if ($this->attendanceFormToImplementCsrfToken->isValid()) {
                 $punchInDate = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $this->request->getParameter('date'));
                 $punchIntime = $this->request->getParameter('time');
                 $punchInNote = $this->request->getParameter('note');
                 $timeZoneOffset = $this->request->getParameter('timeZone');
                 $nextState = $this->userObj->getNextState(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL, WorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_IN);
                 $punchIndateTime = strtotime($punchInDate . " " . $punchIntime);
                 $attendanceRecord = $this->setAttendanceRecord($attendanceRecord, $nextState, date('Y-m-d H:i', $punchIndateTime - $timeZoneOffset), date('Y-m-d H:i', $punchIndateTime), $timeZoneOffset / 3600, $punchInNote);
                 $this->redirect("attendance/punchOut");
             }
         } else {
             $this->form->bind($request->getParameter('attendance'));
             if ($this->form->isValid()) {
                 $punchInDate = $this->form->getValue('date');
                 $punchIntime = $this->form->getValue('time');
                 $punchInNote = $this->form->getValue('note');
                 $timeZoneOffset = $this->request->getParameter('timeZone');
                 $punchInEditModeTime = mktime(date('H', strtotime($punchIntime)), date('i', strtotime($punchIntime)), 0, date('m', strtotime($punchInDate)), date('d', strtotime($punchInDate)), date('Y', strtotime($punchInDate)));
                 $nextState = $this->userObj->getNextState(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL, WorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_IN);
                 $attendanceRecord = $this->setAttendanceRecord($attendanceRecord, $nextState, date('Y-m-d H:i', $punchInEditModeTime - $timeZoneOffset), date('Y-m-d H:i', $punchInEditModeTime), $timeZoneOffset / 3600, $punchInNote);
                 $this->redirect("attendance/punchOut");
             }
         }
     }
     $this->setTemplate("punchTime");
 }
 public function execute($request)
 {
     $this->_checkAuthentication();
     /* For highlighting corresponding menu item */
     $request->setParameter('initialActionName', 'punchIn');
     $userRoleManager = $this->getContext()->getUserRoleManager();
     $inputDatePattern = $this->getUser()->getDateFormat();
     $this->employeeId = $this->getUser()->getEmployeeNumber();
     $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_OUT);
     $actionableStatesList = $userRoleManager->getActionableStates(WorkflowStateMachine::FLOW_ATTENDANCE, $actions, array(), array(), array('Employee' => $this->employeeId));
     $timeZoneOffset = $this->getUser()->getUserTimeZoneOffset();
     $timeStampDiff = $timeZoneOffset * 3600 - date('Z');
     $this->currentDate = date('Y-m-d', time() + $timeStampDiff);
     $this->currentTime = date('H:i', time() + $timeStampDiff);
     $localizationService = new LocalizationService();
     $this->timezone = $timeZoneOffset * 3600;
     $attendanceRecord = $this->getAttendanceService()->getLastPunchRecord($this->employeeId, $actionableStatesList);
     if (is_null($attendanceRecord)) {
         $this->getUser()->setFlash('success', __(TopLevelMessages::SAVE_SUCCESS));
         $this->redirect("attendance/punchIn");
     }
     $tempPunchInTime = $attendanceRecord->getPunchInUserTime();
     $this->recordId = $attendanceRecord->getId();
     $this->actionPunchIn = null;
     $this->editmode = null;
     $this->punchInTime = date('Y-m-d H:i', strtotime($tempPunchInTime));
     $this->punchInUtcTime = date('Y-m-d H:i', strtotime($attendanceRecord->getPunchInUtcTime()));
     $this->punchInNote = $attendanceRecord->getPunchInNote();
     $this->form = new AttendanceForm();
     $this->attendanceFormToImplementCsrfToken = new AttendanceFormToImplementCsrfToken();
     $this->actionPunchOut = $this->getActionName();
     $allowedWorkflowItems = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_ATTENDANCE, $attendanceRecord->getState(), array(), array(), array('Employee' => $this->employeeId));
     $this->allowedActions = array_keys($allowedWorkflowItems);
     if ($request->isMethod('post')) {
         if (!in_array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_TIME, $this->allowedActions)) {
             $this->attendanceFormToImplementCsrfToken->bind($request->getParameter('attendance'));
             if ($this->attendanceFormToImplementCsrfToken->isValid()) {
                 $punchOutDate = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $this->request->getParameter('date'));
                 $punchOutTime = $this->request->getParameter('time');
                 $punchOutNote = $this->request->getParameter('note');
                 $timeZoneOffset = $this->request->getParameter('timeZone');
                 $punchOutAction = $allowedWorkflowItems[PluginWorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_OUT];
                 $nextState = $punchOutAction->getResultingState();
                 $punchOutdateTime = strtotime($punchOutDate . " " . $punchOutTime);
                 if ($this->isCurrantTimeValid($timeZoneOffset, $punchOutdateTime)) {
                     $attendanceRecord = $this->setAttendanceRecord($attendanceRecord, $nextState, date('Y-m-d H:i', $punchOutdateTime - $timeZoneOffset), date('Y-m-d H:i', $punchOutdateTime), $timeZoneOffset / 3600, $punchOutNote);
                     $this->getUser()->setFlash('templateMessage', array('success', __(TopLevelMessages::SAVE_SUCCESS)));
                     $this->redirect('attendance/punchIn');
                 } else {
                     $this->getUser()->setFlash('warning', __(TopLevelMessages::VALIDATION_FAILED));
                     $this->redirect($request->getReferer());
                 }
             }
         } else {
             $this->form->bind($request->getParameter('attendance'));
             if ($this->form->isValid()) {
                 $punchOutTime = $this->form->getValue('time');
                 $punchOutNote = $this->form->getValue('note');
                 $punchOutDate = $this->form->getValue('date');
                 $timeZoneOffset = $this->request->getParameter('timeZone');
                 $punchOutEditModeTime = mktime(date('H', strtotime($punchOutTime)), date('i', strtotime($punchOutTime)), 0, date('m', strtotime($punchOutDate)), date('d', strtotime($punchOutDate)), date('Y', strtotime($punchOutDate)));
                 $punchOutAction = $allowedWorkflowItems[PluginWorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_OUT];
                 $nextState = $punchOutAction->getResultingState();
                 $attendanceRecord = $this->setAttendanceRecord($attendanceRecord, $nextState, date('Y-m-d H:i', $punchOutEditModeTime - $timeZoneOffset), date('Y-m-d H:i', $punchOutEditModeTime), $timeZoneOffset / 3600, $punchOutNote);
                 $this->getUser()->setFlash('templateMessage', array('success', __(TopLevelMessages::SAVE_SUCCESS)));
                 $this->redirect('attendance/punchIn');
             }
         }
     }
     $this->setTemplate("punchTime");
 }
 protected function _getStandardDate($localizedDate)
 {
     $localizationService = new LocalizationService();
     $format = sfContext::getInstance()->getUser()->getDateFormat();
     $trimmedValue = trim($localizedDate);
     $result = $localizationService->convertPHPFormatDateToISOFormatDate($format, $trimmedValue);
     return $result;
 }
 /**
  * Get leave balance for given leave type
  * Request parameters:
  * *) leaveType: Leave Type ID
  * *) empNumber: (optional) employee number. If not present, currently
  *               logged in employee is used.
  * 
  * @param sfWebRequest $request
  */
 public function execute($request)
 {
     sfConfig::set('sf_web_debug', false);
     sfConfig::set('sf_debug', false);
     $leaveTypeId = $request->getParameter('leaveType');
     $empNumber = $request->getParameter('empNumber');
     $user = $this->getUser();
     $loggedEmpNumber = $user->getAttribute('auth.empNumber');
     $allowed = false;
     if (empty($empNumber)) {
         $empNumber = $loggedEmpNumber;
         $allowed = true;
     } else {
         $manager = $this->getContext()->getUserRoleManager();
         if ($manager->isEntityAccessible('Employee', $empNumber)) {
             $allowed = true;
         } else {
             $allowed = $loggedEmpNumber == $empNumber;
         }
     }
     $response = $this->getResponse();
     $response->setHttpHeader('Expires', '0');
     $response->setHttpHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
     $response->setHttpHeader("Cache-Control", "private", false);
     $balance = '--';
     if ($allowed) {
         $localizationService = new LocalizationService();
         $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat();
         $startDate = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $request->getParameter("startDate"));
         $startDateTimeStamp = strtotime($startDate);
         // If not start date, show balance as of today
         if (!$startDateTimeStamp) {
             $startDate = date('Y-m-d');
         }
         $endDate = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $request->getParameter("endDate"));
         $endDateTimeStamp = strtotime($endDate);
         $leaveByPeriods = array();
         if ($endDateTimeStamp && $endDateTimeStamp > $startDateTimeStamp) {
             $leaveParameterObject = $this->getLeaveParameterObject($empNumber, $leaveTypeId, $startDate, $endDate);
             $leaveDays = $this->getLeaveApplicationService()->createLeaveObjectListForAppliedRange($leaveParameterObject);
             $holidays = array(Leave::LEAVE_STATUS_LEAVE_WEEKEND, Leave::LEAVE_STATUS_LEAVE_HOLIDAY);
             $currentLeavePeriod = $this->getLeavePeriod($startDate, $empNumber, $leaveTypeId);
             $leavePeriodNdx = 0;
             $leaveByPeriods[$leavePeriodNdx] = array('period' => $currentLeavePeriod, 'balance' => false, 'days' => array());
             foreach ($leaveDays as $k => $leave) {
                 $leaveDate = $leave->getDate();
                 // Get next leave period if request spans leave periods.
                 if (strtotime($leaveDate) > strtotime($leaveByPeriods[$leavePeriodNdx]['period'][1])) {
                     $currentLeavePeriod = $this->getLeavePeriod($leaveDate, $empNumber, $leaveTypeId);
                     $leavePeriodNdx++;
                     $leaveByPeriods[$leavePeriodNdx] = array('period' => $currentLeavePeriod, 'balance' => false, 'days' => array());
                 }
                 $localizedDate = set_datepicker_date_format($leaveDate);
                 if (in_array($leave->getStatus(), $holidays)) {
                     $leaveByPeriods[$leavePeriodNdx]['days'][$localizedDate] = array('length' => 0, 'balance' => false, 'desc' => ucfirst(strtolower($leave->getTextLeaveStatus())));
                 } else {
                     $leaveByPeriods[$leavePeriodNdx]['days'][$localizedDate] = array('length' => 1, 'balance' => false, 'desc' => '');
                 }
             }
         }
         // If request spans leave periods
         $negativeBalance = false;
         if (count($leaveByPeriods) > 0) {
             foreach ($leaveByPeriods as $i => $leavePeriod) {
                 $leaveBalanceObj = $this->getLeaveEntitlementService()->getLeaveBalance($empNumber, $leaveTypeId, $leavePeriod['period'][0], $leavePeriod['period'][1]);
                 $leaveByPeriods[$i]['balance'] = $leaveBalanceObj;
                 $leaveBalance = $leaveBalanceObj->getBalance();
                 $days = $leavePeriod['days'];
                 foreach ($days as $date => $leaveDateData) {
                     $leaveDateLength = $leaveDateData['length'];
                     if ($leaveDateLength > 0) {
                         $leaveBalance -= $leaveDateLength;
                         $leaveByPeriods[$i]['days'][$date]['balance'] = $leaveBalance;
                     }
                 }
                 if ($leaveBalance < 0) {
                     $negativeBalance = true;
                 }
                 // localize data
                 $leaveByPeriods[$i]['period'][0] = set_datepicker_date_format($leaveByPeriods[$i]['period'][0]);
                 $leaveByPeriods[$i]['period'][1] = set_datepicker_date_format($leaveByPeriods[$i]['period'][1]);
             }
             $result = array('multiperiod' => true, 'negative' => $negativeBalance, 'data' => $leaveByPeriods);
         }
         if (count($leaveByPeriods) == 0 || count($leaveByPeriods) == 1 && !$negativeBalance) {
             $balance = $this->getLeaveEntitlementService()->getLeaveBalance($empNumber, $leaveTypeId, $startDate);
             $asAtDate = set_datepicker_date_format($startDate);
             $result = array('multiperiod' => false, 'balance' => $balance, 'asAtDate' => $asAtDate);
         }
         echo json_encode($result);
     }
     return sfView::NONE;
 }