/// <summary> /// (1) checks if remaining vacation days of employee suffice, /// (2) sets lock period flag if appropriate, /// (3) sets vacation period overlap flag if appropriate /// </summary> /// <param name="VacationRequest"> a vacation request, passed by reference</param> /// <returns></returns> public Boolean Validate(VacationRequest VacationRequest) { Boolean result = false; ///<remarks> this value must be numeric</remarks> //checks remaining vacation days DBQuery dbq = new DBQuery(); int remainingVacationDays = dbq.SelectRemainingVacationDays(VacationRequest.getEmployeeID()); // determine working days in vacation request int vacationWorkingDays = VacationRequest.DetermineWorkingDaysInVacationRequest(VacationRequest); // only proceed if time period of vacation request contains working days if (vacationWorkingDays > 0) { VacationRequest.setNetVacationDays(vacationWorkingDays); // Check VacationRequest overlap with others already existing VacationRequests of Requester without state "canceled" var VRList = dbq.SelectUncanceledEmployeeVacationRequestInTimePeriod(VacationRequest, VacationRequest.getEmployeeID()); Boolean overlap = false; Boolean insufficientRemainingVacationDays = false; if (VRList.Count > 0) { overlap = true; ErrorState.ErrorStateInstance.setError(ErrorState.OVERLAP_WITH_OWN_VACATION_REQUEST); } if (remainingVacationDays < vacationWorkingDays) { insufficientRemainingVacationDays = true; ErrorState.ErrorStateInstance.setError(ErrorState.INSUFFICIENT_REMAINING_VACATION_DAYS); } // if requester has enough remaining Vacation Days AND no submitted vacation request(s) in this time period, go ahead if (!insufficientRemainingVacationDays && !overlap) { TimePeriodOverlapCheck check = new TimePeriodOverlapCheck(VacationRequest); //check lock period if (!check.Validate(TimePeriodOverlapCheck.CHECK_CATEGORY_LOCK_PERIOD)) { //overlap existing VacationRequest.setVacationLockPeriodNote(true); } //check overlap period with Deputy if (!check.Validate(TimePeriodOverlapCheck.CHECK_CATEGORY_VACATION_OVERLAP_PERIOD)) { //overlap existing VacationRequest.setVacationPeriodOverlapNote(true); } if (VacationRequest.getVacationStartDate() < DateTime.Now) { //if VacationRequestEndDate is in past the new Processingstatus is: agreed, so the decision of the DivisionManager is the next step VacationRequest.setVacationRequestProcessingState(VacationRequestProcessingState.agreed); } result = true; } } else { ErrorState.ErrorStateInstance.setError(ErrorState.ZERO_NET_VACATION_DAYS_IN_VACATION_REQUEST); } return result; }