List of usage examples for org.joda.time LocalDate getDayOfWeek
public int getDayOfWeek()
From source file:com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningServiceImp.java
License:Open Source License
public DayPlanning findDayPlanning(WeeklyPlanning planning, LocalDate date) { int dayOfWeek = date.getDayOfWeek(); switch (dayOfWeek) { case 1:/* www .j a v a 2s. c o m*/ return findDayWithName(planning, "monday"); case 2: return findDayWithName(planning, "tuesday"); case 3: return findDayWithName(planning, "wednesday"); case 4: return findDayWithName(planning, "thursday"); case 5: return findDayWithName(planning, "friday"); case 6: return findDayWithName(planning, "saturday"); case 7: return findDayWithName(planning, "sunday"); default: return findDayWithName(planning, "null"); } }
From source file:com.axelor.apps.hr.service.timesheet.TimesheetServiceImp.java
License:Open Source License
@Override public Timesheet generateLines(Timesheet timesheet) throws AxelorException { if (timesheet.getFromGenerationDate() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_FROM_DATE)), IException.CONFIGURATION_ERROR); }/*w w w . ja v a2 s . com*/ if (timesheet.getToGenerationDate() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_TO_DATE)), IException.CONFIGURATION_ERROR); } if (timesheet.getProduct() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_PRODUCT)), IException.CONFIGURATION_ERROR); } if (timesheet.getUser().getEmployee() == null) { throw new AxelorException( String.format(I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), timesheet.getUser().getName()), IException.CONFIGURATION_ERROR); } WeeklyPlanning planning = timesheet.getUser().getEmployee().getPlanning(); if (planning == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), timesheet.getUser().getName()), IException.CONFIGURATION_ERROR); } List<DayPlanning> dayPlanningList = planning.getWeekDays(); LocalDate fromDate = timesheet.getFromGenerationDate(); LocalDate toDate = timesheet.getToGenerationDate(); Map<Integer, String> correspMap = new HashMap<Integer, String>(); correspMap.put(1, "monday"); correspMap.put(2, "tuesday"); correspMap.put(3, "wednesday"); correspMap.put(4, "thursday"); correspMap.put(5, "friday"); correspMap.put(6, "saturday"); correspMap.put(7, "sunday"); List<LeaveRequest> leaveList = LeaveRequestRepository.of(LeaveRequest.class).all() .filter("self.user = ?1 AND (self.statusSelect = 2 OR self.statusSelect = 3)", timesheet.getUser()) .fetch(); while (!fromDate.isAfter(toDate)) { DayPlanning dayPlanningCurr = new DayPlanning(); for (DayPlanning dayPlanning : dayPlanningList) { if (dayPlanning.getName().equals(correspMap.get(fromDate.getDayOfWeek()))) { dayPlanningCurr = dayPlanning; break; } } if (dayPlanningCurr.getMorningFrom() != null || dayPlanningCurr.getMorningTo() != null || dayPlanningCurr.getAfternoonFrom() != null || dayPlanningCurr.getAfternoonTo() != null) { boolean noLeave = true; if (leaveList != null) { for (LeaveRequest leave : leaveList) { if ((leave.getDateFrom().isBefore(fromDate) && leave.getDateTo().isAfter(fromDate)) || leave.getDateFrom().isEqual(fromDate) || leave.getDateTo().isEqual(fromDate)) { noLeave = false; break; } } } if (noLeave) { TimesheetLine timesheetLine = new TimesheetLine(); timesheetLine.setDate(fromDate); timesheetLine.setUser(timesheet.getUser()); timesheetLine.setProjectTask(timesheet.getProjectTask()); timesheetLine.setVisibleDuration(timesheet.getLogTime()); timesheetLine.setDurationStored(employeeService.getDurationHours(timesheet.getLogTime())); timesheetLine.setProduct(timesheet.getProduct()); timesheet.addTimesheetLineListItem(timesheetLine); } } fromDate = fromDate.plusDays(1); } return timesheet; }
From source file:com.axelor.apps.hr.service.timesheet.TimesheetServiceImpl.java
License:Open Source License
@Override public Timesheet generateLines(Timesheet timesheet, LocalDate fromGenerationDate, LocalDate toGenerationDate, BigDecimal logTime, ProjectTask projectTask, Product product) throws AxelorException { User user = timesheet.getUser();//from w ww .j av a 2 s . c o m Employee employee = user.getEmployee(); if (fromGenerationDate == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_FROM_DATE)), IException.MISSING_FIELD); } if (toGenerationDate == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_TO_DATE)), IException.MISSING_FIELD); } if (product == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_PRODUCT)), IException.MISSING_FIELD); } if (employee == null) { throw new AxelorException( String.format(I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName()), IException.CONFIGURATION_ERROR); } WeeklyPlanning planning = user.getEmployee().getPlanning(); if (planning == null) { throw new AxelorException( String.format(I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), user.getName()), IException.CONFIGURATION_ERROR); } List<DayPlanning> dayPlanningList = planning.getWeekDays(); LocalDate fromDate = fromGenerationDate; LocalDate toDate = toGenerationDate; Map<Integer, String> correspMap = new HashMap<Integer, String>(); correspMap.put(1, "monday"); correspMap.put(2, "tuesday"); correspMap.put(3, "wednesday"); correspMap.put(4, "thursday"); correspMap.put(5, "friday"); correspMap.put(6, "saturday"); correspMap.put(7, "sunday"); //Leaving list List<LeaveRequest> leaveList = LeaveRequestRepository.of(LeaveRequest.class).all() .filter("self.user = ?1 AND (self.statusSelect = 2 OR self.statusSelect = 3)", user).fetch(); //Public holidays list List<PublicHolidayDay> publicHolidayList = employee.getPublicHolidayPlanning().getPublicHolidayDayList(); while (!fromDate.isAfter(toDate)) { DayPlanning dayPlanningCurr = new DayPlanning(); for (DayPlanning dayPlanning : dayPlanningList) { if (dayPlanning.getName().equals(correspMap.get(fromDate.getDayOfWeek()))) { dayPlanningCurr = dayPlanning; break; } } if (dayPlanningCurr.getMorningFrom() != null || dayPlanningCurr.getMorningTo() != null || dayPlanningCurr.getAfternoonFrom() != null || dayPlanningCurr.getAfternoonTo() != null) { /*Check if the day is not a leaving day */ boolean noLeave = true; if (leaveList != null) { for (LeaveRequest leave : leaveList) { if ((leave.getFromDate().isBefore(fromDate) && leave.getToDate().isAfter(fromDate)) || leave.getFromDate().isEqual(fromDate) || leave.getToDate().isEqual(fromDate)) { noLeave = false; break; } } } /*Check if the day is not a public holiday */ boolean noPublicHoliday = true; if (publicHolidayList != null) { for (PublicHolidayDay publicHoliday : publicHolidayList) { if (publicHoliday.getDate().isEqual(fromDate)) { noPublicHoliday = false; break; } } } if (noLeave && noPublicHoliday) { TimesheetLine timesheetLine = createTimesheetLine(projectTask, product, user, fromDate, timesheet, employeeService.getUserDuration(logTime, employee.getDailyWorkHours(), true), ""); timesheetLine.setVisibleDuration(logTime); } } fromDate = fromDate.plusDays(1); } return timesheet; }
From source file:com.gst.portfolio.calendar.domain.Calendar.java
License:Apache License
public Map<String, Object> updateStartDateAndDerivedFeilds(final LocalDate newMeetingStartDate) { final Map<String, Object> actualChanges = new LinkedHashMap<>(9); final LocalDate currentDate = DateUtils.getLocalDateOfTenant(); if (newMeetingStartDate.isBefore(currentDate)) { final String defaultUserMessage = "New meeting effective from date cannot be in past"; throw new CalendarDateException("new.start.date.cannot.be.in.past", defaultUserMessage, newMeetingStartDate, getStartDateLocalDate()); } else if (isStartDateAfter(newMeetingStartDate) && isStartDateBeforeOrEqual(currentDate)) { // new meeting date should be on or after start date or current // date//from w ww . j ava 2s.co m final String defaultUserMessage = "New meeting effective from date cannot be a date before existing meeting start date"; throw new CalendarDateException("new.start.date.before.existing.date", defaultUserMessage, newMeetingStartDate, getStartDateLocalDate()); } else { actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.START_DATE.getValue(), newMeetingStartDate.toString()); this.startDate = newMeetingStartDate.toDate(); /* * If meeting start date is changed then there is possibilities of * recurring day may change, so derive the recurring day and update * it if it is changed. For weekly type is weekday and for monthly * type it is day of the month */ CalendarFrequencyType calendarFrequencyType = CalendarUtils.getFrequency(this.recurrence); Integer interval = CalendarUtils.getInterval(this.recurrence); Integer repeatsOnDay = null; /* * Repeats on day, need to derive based on the start date */ if (calendarFrequencyType.isWeekly()) { repeatsOnDay = newMeetingStartDate.getDayOfWeek(); } else if (calendarFrequencyType.isMonthly()) { repeatsOnDay = newMeetingStartDate.getDayOfMonth(); } // TODO cover other recurrence also this.recurrence = constructRecurrence(calendarFrequencyType, interval, repeatsOnDay, null); } return actualChanges; }
From source file:com.gst.portfolio.calendar.domain.Calendar.java
License:Apache License
public void updateStartAndEndDate(final LocalDate startDate, final LocalDate endDate) { final CalendarFrequencyType frequencyType = CalendarUtils.getFrequency(this.recurrence); final Integer interval = new Integer(CalendarUtils.getInterval(this.recurrence)); final String newRecurrence = Calendar.constructRecurrence(frequencyType, interval, startDate.getDayOfWeek(), null);//from ww w. j a va 2 s. c o m this.recurrence = newRecurrence; this.startDate = startDate.toDate(); this.endDate = endDate.toDate(); }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java
License:Apache License
private LocalDate adjustToNthWeekDay(LocalDate dueRepaymentPeriodDate, int nthDay, int dayOfWeek) { // adjust date to start of month dueRepaymentPeriodDate = dueRepaymentPeriodDate.withDayOfMonth(1); // adjust date to next week if current day is past specified day of // week.// w w w . j a v a 2 s . co m if (dueRepaymentPeriodDate.getDayOfWeek() > dayOfWeek) { dueRepaymentPeriodDate = dueRepaymentPeriodDate.plusWeeks(1); } // adjust date to specified date of week dueRepaymentPeriodDate = dueRepaymentPeriodDate.withDayOfWeek(dayOfWeek); // adjust to specified nth week day dueRepaymentPeriodDate = dueRepaymentPeriodDate.plusWeeks(nthDay - 1); return dueRepaymentPeriodDate; }
From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java
License:Apache License
private CalendarInstance createCalendarForSameAsRepayment(final Integer repaymentEvery, final PeriodFrequencyType repaymentPeriodFrequencyType, final LocalDate expectedDisbursementDate) { final Integer recalculationFrequencyNthDay = null; final Integer repeatsOnDay = expectedDisbursementDate.getDayOfWeek(); CalendarInstance restCalendarInstance = createInterestRecalculationCalendarInstance( expectedDisbursementDate, repaymentEvery, CalendarFrequencyType.from(repaymentPeriodFrequencyType), recalculationFrequencyNthDay, repeatsOnDay); return restCalendarInstance; }
From source file:com.gst.portfolio.loanaccount.service.LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
private void createCalendar(final Loan loan, LocalDate calendarStartDate, Integer recalculationFrequencyNthDay, final Integer repeatsOnDay, final RecalculationFrequencyType recalculationFrequencyType, Integer frequency, CalendarEntityType calendarEntityType, final String title) { CalendarFrequencyType calendarFrequencyType = CalendarFrequencyType.INVALID; Integer updatedRepeatsOnDay = repeatsOnDay; switch (recalculationFrequencyType) { case DAILY:/*from w w w . ja va2 s . co m*/ calendarFrequencyType = CalendarFrequencyType.DAILY; break; case MONTHLY: calendarFrequencyType = CalendarFrequencyType.MONTHLY; break; case SAME_AS_REPAYMENT_PERIOD: frequency = loan.repaymentScheduleDetail().getRepayEvery(); calendarFrequencyType = CalendarFrequencyType .from(loan.repaymentScheduleDetail().getRepaymentPeriodFrequencyType()); calendarStartDate = loan.getExpectedDisbursedOnLocalDate(); if (updatedRepeatsOnDay == null) { updatedRepeatsOnDay = calendarStartDate.getDayOfWeek(); } break; case WEEKLY: calendarFrequencyType = CalendarFrequencyType.WEEKLY; break; default: break; } final Calendar calendar = Calendar.createRepeatingCalendar(title, calendarStartDate, CalendarType.COLLECTION.getValue(), calendarFrequencyType, frequency, updatedRepeatsOnDay, recalculationFrequencyNthDay); final CalendarInstance calendarInstance = CalendarInstance.from(calendar, loan.loanInterestRecalculationDetails().getId(), calendarEntityType.getValue()); this.calendarInstanceRepository.save(calendarInstance); }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
private SavingsAccountCharge(final SavingsAccount savingsAccount, final Charge chargeDefinition, final BigDecimal amount, final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation, final LocalDate dueDate, final boolean status, MonthDay feeOnMonthDay, final Integer feeInterval) { this.savingsAccount = savingsAccount; this.charge = chargeDefinition; this.penaltyCharge = chargeDefinition.isPenalty(); this.chargeTime = (chargeTime == null) ? chargeDefinition.getChargeTimeType() : chargeTime.getValue(); if (isOnSpecifiedDueDate()) { if (dueDate == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); }/*from w ww . jav a 2s . c o m*/ } if (isAnnualFee() || isMonthlyFee()) { feeOnMonthDay = (feeOnMonthDay == null) ? chargeDefinition.getFeeOnMonthDay() : feeOnMonthDay; if (feeOnMonthDay == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); } this.feeOnMonth = feeOnMonthDay.getMonthOfYear(); this.feeOnDay = feeOnMonthDay.getDayOfMonth(); } else if (isWeeklyFee()) { if (dueDate == null) { final String defaultUserMessage = "Savings Account charge is missing due date."; throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge", dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(), chargeDefinition.getName()); } /** * For Weekly fee feeOnDay is ISO standard day of the week. * Monday=1, Tuesday=2 */ this.feeOnDay = dueDate.getDayOfWeek(); } else { this.feeOnDay = null; this.feeOnMonth = null; this.feeInterval = null; } if (isMonthlyFee() || isWeeklyFee()) { this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval; } this.dueDate = (dueDate == null) ? null : dueDate.toDate(); this.chargeCalculation = chargeDefinition.getChargeCalculation(); if (chargeCalculation != null) { this.chargeCalculation = chargeCalculation.getValue(); } BigDecimal chargeAmount = chargeDefinition.getAmount(); if (amount != null) { chargeAmount = amount; } final BigDecimal transactionAmount = new BigDecimal(0); populateDerivedFields(transactionAmount, chargeAmount); if (this.isWithdrawalFee() || this.isSavingsNoActivity()) { this.amountOutstanding = BigDecimal.ZERO; } this.paid = determineIfFullyPaid(); this.status = status; }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
public void update(final BigDecimal amount, final LocalDate dueDate, final MonthDay feeOnMonthDay, final Integer feeInterval) { final BigDecimal transactionAmount = BigDecimal.ZERO; if (dueDate != null) { this.dueDate = dueDate.toDate(); if (isWeeklyFee()) { this.feeOnDay = dueDate.getDayOfWeek(); }/*w ww . jav a 2 s . co m*/ } if (feeOnMonthDay != null) { this.feeOnMonth = feeOnMonthDay.getMonthOfYear(); this.feeOnDay = feeOnMonthDay.getDayOfMonth(); } if (feeInterval != null) { this.feeInterval = feeInterval; } if (amount != null) { switch (ChargeCalculationType.fromInt(this.chargeCalculation)) { case INVALID: break; case FLAT: this.amount = amount; break; case PERCENT_OF_AMOUNT: this.percentage = amount; this.amountPercentageAppliedTo = transactionAmount; this.amount = percentageOf(this.amountPercentageAppliedTo, this.percentage); this.amountOutstanding = calculateOutstanding(); break; case PERCENT_OF_AMOUNT_AND_INTEREST: this.percentage = amount; this.amount = null; this.amountPercentageAppliedTo = null; this.amountOutstanding = null; break; case PERCENT_OF_INTEREST: this.percentage = amount; this.amount = null; this.amountPercentageAppliedTo = null; this.amountOutstanding = null; break; } } }