List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:com.axelor.apps.crm.web.EventController.java
License:Open Source License
@Transactional public void generateRecurrentEvents(ActionRequest request, ActionResponse response) throws AxelorException { Long eventId = new Long(request.getContext().get("_idEvent").toString()); Event event = eventRepo.find(eventId); RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class); RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class); conf = confRepo.save(conf);/*w w w .j av a 2 s . c om*/ event.setRecurrenceConfiguration(conf); event = eventRepo.save(event); if (request.getContext().get("recurrenceType") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE)), IException.CONFIGURATION_ERROR); } int recurrenceType = new Integer(request.getContext().get("recurrenceType").toString()); if (request.getContext().get("periodicity") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } int periodicity = new Integer(request.getContext().get("periodicity").toString()); if (periodicity < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } boolean monday = (boolean) request.getContext().get("monday"); boolean tuesday = (boolean) request.getContext().get("tuesday"); boolean wednesday = (boolean) request.getContext().get("wednesday"); boolean thursday = (boolean) request.getContext().get("thursday"); boolean friday = (boolean) request.getContext().get("friday"); boolean saturday = (boolean) request.getContext().get("saturday"); boolean sunday = (boolean) request.getContext().get("sunday"); Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>(); if (recurrenceType == 2) { daysMap.put(DateTimeConstants.MONDAY, monday); daysMap.put(DateTimeConstants.TUESDAY, tuesday); daysMap.put(DateTimeConstants.WEDNESDAY, wednesday); daysMap.put(DateTimeConstants.THURSDAY, thursday); daysMap.put(DateTimeConstants.FRIDAY, friday); daysMap.put(DateTimeConstants.SATURDAY, saturday); daysMap.put(DateTimeConstants.SUNDAY, sunday); for (Integer day : daysMap.keySet()) { if (daysMap.get(day)) { daysCheckedMap.put(day, daysMap.get(day)); } } if (daysMap.isEmpty()) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED)), IException.CONFIGURATION_ERROR); } } int monthRepeatType = new Integer(request.getContext().get("monthRepeatType").toString()); int endType = new Integer(request.getContext().get("endType").toString()); int repetitionsNumber = 0; if (endType == 1) { if (request.getContext().get("repetitionsNumber") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } repetitionsNumber = new Integer(request.getContext().get("repetitionsNumber").toString()); if (repetitionsNumber < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } } LocalDate endDate = new LocalDate(); if (endType == 2) { if (request.getContext().get("endDate") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } endDate = new LocalDate(request.getContext().get("endDate").toString()); if (endDate.isBefore(event.getStartDateTime()) && endDate.isEqual(event.getStartDateTime())) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } } switch (recurrenceType) { case 1: eventService.addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate); break; case 2: eventService.addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap); break; case 3: eventService.addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType); break; case 4: eventService.addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate); break; default: break; } response.setCanClose(true); response.setReload(true); }
From source file:com.axelor.apps.crm.web.EventController.java
License:Open Source License
@Transactional public void changeAll(ActionRequest request, ActionResponse response) throws AxelorException { Long eventId = new Long(request.getContext().get("_idEvent").toString()); Event event = eventRepo.find(eventId); Event child = eventRepo.all().filter("self.parentEvent.id = ?1", event.getId()).fetchOne(); Event parent = event.getParentEvent(); child.setParentEvent(null);/*w ww .j ava 2 s .c om*/ Event eventDeleted = child; child = eventRepo.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne(); while (child != null) { child.setParentEvent(null); eventRepo.remove(eventDeleted); eventDeleted = child; child = eventRepo.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne(); } while (parent != null) { Event nextParent = parent.getParentEvent(); eventRepo.remove(parent); parent = nextParent; } RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class); RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class); conf = confRepo.save(conf); event.setRecurrenceConfiguration(conf); event = eventRepo.save(event); if (conf.getRecurrenceType() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE)), IException.CONFIGURATION_ERROR); } int recurrenceType = conf.getRecurrenceType(); if (conf.getPeriodicity() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } int periodicity = conf.getPeriodicity(); if (periodicity < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } boolean monday = conf.getMonday(); boolean tuesday = conf.getTuesday(); boolean wednesday = conf.getWednesday(); boolean thursday = conf.getThursday(); boolean friday = conf.getFriday(); boolean saturday = conf.getSaturday(); boolean sunday = conf.getSunday(); Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>(); if (recurrenceType == 2) { daysMap.put(DateTimeConstants.MONDAY, monday); daysMap.put(DateTimeConstants.TUESDAY, tuesday); daysMap.put(DateTimeConstants.WEDNESDAY, wednesday); daysMap.put(DateTimeConstants.THURSDAY, thursday); daysMap.put(DateTimeConstants.FRIDAY, friday); daysMap.put(DateTimeConstants.SATURDAY, saturday); daysMap.put(DateTimeConstants.SUNDAY, sunday); for (Integer day : daysMap.keySet()) { if (daysMap.get(day)) { daysCheckedMap.put(day, daysMap.get(day)); } } if (daysMap.isEmpty()) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED)), IException.CONFIGURATION_ERROR); } } int monthRepeatType = conf.getMonthRepeatType(); int endType = conf.getEndType(); int repetitionsNumber = 0; if (endType == 1) { if (conf.getRepetitionsNumber() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } repetitionsNumber = conf.getRepetitionsNumber(); if (repetitionsNumber < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } } LocalDate endDate = new LocalDate(); if (endType == 2) { if (conf.getEndDate() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } endDate = new LocalDate(conf.getEndDate()); if (endDate.isBefore(event.getStartDateTime()) && endDate.isEqual(event.getStartDateTime())) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } } switch (recurrenceType) { case 1: eventService.addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate); break; case 2: eventService.addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap); break; case 3: eventService.addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType); break; case 4: eventService.addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate); break; default: break; } response.setCanClose(true); response.setReload(true); }
From source file:com.axelor.apps.hr.service.leave.LeaveService.java
License:Open Source License
public BigDecimal computeLeaveDaysByLeaveRequest(LocalDate fromDate, LocalDate toDate, LeaveRequest leaveRequest, Employee employee) throws AxelorException { BigDecimal leaveDays = BigDecimal.ZERO; WeeklyPlanning weeklyPlanning = employee.getPlanning(); if (leaveRequest.getDateFrom().equals(fromDate)) { leaveDays = leaveDays.add(new BigDecimal( this.computeStartDateWithSelect(fromDate, leaveRequest.getStartOnSelect(), weeklyPlanning))); }/*from www . ja va2 s .c om*/ if (leaveRequest.getDateTo().equals(toDate)) { leaveDays = leaveDays.add(new BigDecimal( this.computeEndDateWithSelect(toDate, leaveRequest.getEndOnSelect(), weeklyPlanning))); } LocalDate itDate = new LocalDate(fromDate); if (fromDate.isBefore(leaveRequest.getDateFrom()) || fromDate.equals(leaveRequest.getDateFrom())) { itDate = new LocalDate(leaveRequest.getDateFrom().plusDays(1)); } while (!itDate.isEqual(leaveRequest.getDateTo()) && !itDate.isAfter(toDate)) { leaveDays = leaveDays .add(new BigDecimal(weeklyPlanningService.workingDayValue(weeklyPlanning, itDate))); if (publicHolidayService.checkPublicHolidayDay(itDate, employee)) { leaveDays = leaveDays.subtract(BigDecimal.ONE); } itDate = itDate.plusDays(1); } return leaveDays; }
From source file:com.axelor.apps.supplychain.service.BudgetSupplychainService.java
License:Open Source License
@Override public List<BudgetLine> updateLines(Budget budget) { if (budget.getBudgetLineList() != null && !budget.getBudgetLineList().isEmpty()) { for (BudgetLine budgetLine : budget.getBudgetLineList()) { budgetLine.setAmountCommitted(BigDecimal.ZERO); budgetLine.setAmountRealized(BigDecimal.ZERO); }//from w ww .ja v a2s . c o m List<BudgetDistribution> budgetDistributionList = null; budgetDistributionList = Beans.get(BudgetDistributionRepository.class).all().filter( "self.budget.id = ?1 AND (self.purchaseOrderLine.purchaseOrder.statusSelect = ?2 OR self.purchaseOrderLine.purchaseOrder.statusSelect = ?3)", budget.getId(), IPurchaseOrder.STATUS_VALIDATED, IPurchaseOrder.STATUS_FINISHED).fetch(); for (BudgetDistribution budgetDistribution : budgetDistributionList) { LocalDate orderDate = budgetDistribution.getPurchaseOrderLine().getPurchaseOrder().getOrderDate(); if (orderDate != null) { for (BudgetLine budgetLine : budget.getBudgetLineList()) { LocalDate fromDate = budgetLine.getFromDate(); LocalDate toDate = budgetLine.getToDate(); if ((fromDate.isBefore(orderDate) || fromDate.isEqual(orderDate)) && (toDate.isAfter(orderDate) || toDate.isEqual(orderDate))) { budgetLine.setAmountCommitted( budgetLine.getAmountCommitted().add(budgetDistribution.getAmount())); break; } } } } budgetDistributionList = Beans.get(BudgetDistributionRepository.class).all().filter( "self.budget.id = ?1 AND (self.invoiceLine.invoice.statusSelect = ?2 OR self.invoiceLine.invoice.statusSelect = ?3)", budget.getId(), InvoiceRepository.STATUS_VALIDATED, InvoiceRepository.STATUS_VENTILATED) .fetch(); for (BudgetDistribution budgetDistribution : budgetDistributionList) { LocalDate orderDate = budgetDistribution.getInvoiceLine().getInvoice().getInvoiceDate(); if (orderDate != null) { for (BudgetLine budgetLine : budget.getBudgetLineList()) { LocalDate fromDate = budgetLine.getFromDate(); LocalDate toDate = budgetLine.getToDate(); if ((fromDate.isBefore(orderDate) || fromDate.isEqual(orderDate)) && (toDate.isAfter(orderDate) || toDate.isEqual(orderDate))) { budgetLine.setAmountRealized( budgetLine.getAmountRealized().add(budgetDistribution.getAmount())); break; } } } } } return budget.getBudgetLineList(); }
From source file:com.axelor.apps.supplychain.service.MrpServiceImpl.java
License:Open Source License
public boolean isBeforeEndDate(LocalDate maturityDate) { if (maturityDate != null && !maturityDate.isBefore(today) && (mrp.getEndDate() == null || !maturityDate.isAfter(mrp.getEndDate()))) { return true; }/* w w w.j av a2s . c o m*/ return false; }
From source file:com.axelor.apps.tool.date.DateTool.java
License:Open Source License
public static int daysBetween(LocalDate date1, LocalDate date2, boolean days360) { int days = 0; if (days360) { if (date1.isBefore(date2)) { days = days360Between(date1, date2); } else {/*from w w w.j a va2s . com*/ days = -days360Between(date2, date1); } } else { days = daysBetween(date1, date2); } LOG.debug("Nombre de jour entre {} - {} (mois de 30 jours ? {}) : {}", new Object[] { date1, date2, days360, days }); return days; }
From source file:com.axelor.apps.tool.date.DateTool.java
License:Open Source License
private static int daysBetween(LocalDate date1, LocalDate date2) { if (date2.isBefore(date1)) { return Days.daysBetween(date1, date2).getDays() - 1; } else {/*from ww w . ja va 2 s . co m*/ return Days.daysBetween(date1, date2).getDays() + 1; } }
From source file:com.axelor.apps.tool.date.DateTool.java
License:Open Source License
public static int days360MonthsBetween(LocalDate startDate, LocalDate endDate) { if (startDate.isBefore(endDate)) { return days360Between(startDate, endDate) / 30; } else {//from ww w. j a va 2 s .com return -days360Between(endDate, startDate) / 30; } }
From source file:com.axelor.apps.tool.date.DateTool.java
License:Open Source License
public static boolean isProrata(LocalDate dateFrame1, LocalDate dateFrame2, LocalDate date1, LocalDate date2) { if (date2 == null && (date1.isBefore(dateFrame2) || date1.isEqual(dateFrame2))) { return true; } else if (date2 == null) { return false; }//ww w .j ava2 s. c o m if (((date1.isAfter(dateFrame1) || date1.isEqual(dateFrame1)) && (date1.isBefore(dateFrame2) || date1.isEqual(dateFrame2))) || ((date2.isAfter(dateFrame1) || date2.isEqual(dateFrame1)) && (date2.isBefore(dateFrame2) || date2.isEqual(dateFrame2))) || (date1.isBefore(dateFrame1) && date2.isAfter(dateFrame2))) { return true; } return false; }
From source file:com.axelor.apps.tool.date.DateTool.java
License:Open Source License
public static boolean isBetween(LocalDate dateFrame1, LocalDate dateFrame2, LocalDate date) { if (dateFrame2 == null && (date.isAfter(dateFrame1) || date.isEqual(dateFrame1))) { return true; } else if (dateFrame2 != null && (date.isAfter(dateFrame1) || date.isEqual(dateFrame1)) && (date.isBefore(dateFrame2) || date.isEqual(dateFrame2))) { return true; } else {//w w w.j a va 2 s . c o m return false; } }