Example usage for org.joda.time LocalDate plusDays

List of usage examples for org.joda.time LocalDate plusDays

Introduction

In this page you can find the example usage for org.joda.time LocalDate plusDays.

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:com.axelor.apps.crm.service.TargetService.java

License:Open Source License

public LocalDate getNextDate(int periodTypeSelect, LocalDate date) {

    switch (periodTypeSelect) {
    case ITarget.NONE:
        return date;
    case ITarget.MONTHLY:
        return date.plusMonths(1);
    case ITarget.WEEKLY:
        return date.plusWeeks(1);
    case ITarget.DAILY:
        return date.plusDays(1);

    default:/*from   www . j a  v a2 s .c  o m*/
        return date;
    }
}

From source file:com.axelor.apps.hr.service.leave.LeaveService.java

License:Open Source License

public BigDecimal computeDuration(LeaveRequest leave) throws AxelorException {
    if (leave.getDateFrom() != null && leave.getDateTo() != null) {
        Employee employee = leave.getUser().getEmployee();
        if (employee == null) {
            throw new AxelorException(
                    String.format(I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), leave.getUser().getName()),
                    IException.CONFIGURATION_ERROR);
        }//from w  w w . j a  v a2 s .  c o  m

        WeeklyPlanning weeklyPlanning = employee.getPlanning();
        if (weeklyPlanning == null) {
            HRConfig conf = leave.getCompany().getHrConfig();
            if (conf != null) {
                weeklyPlanning = conf.getWeeklyPlanning();
            }
        }
        if (weeklyPlanning == null) {
            throw new AxelorException(
                    String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName()),
                    IException.CONFIGURATION_ERROR);
        }
        PublicHolidayPlanning publicHolidayPlanning = employee.getPublicHolidayPlanning();
        if (publicHolidayPlanning == null) {
            HRConfig conf = leave.getCompany().getHrConfig();
            if (conf != null) {
                publicHolidayPlanning = conf.getPublicHolidayPlanning();
            }
        }
        if (publicHolidayPlanning == null) {
            throw new AxelorException(
                    String.format(I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY), employee.getName()),
                    IException.CONFIGURATION_ERROR);
        }

        BigDecimal duration = BigDecimal.ZERO;

        duration = duration.add(new BigDecimal(this.computeStartDateWithSelect(leave.getDateFrom(),
                leave.getStartOnSelect(), weeklyPlanning)));
        LocalDate itDate = new LocalDate(leave.getDateFrom().plusDays(1));

        while (!itDate.isEqual(leave.getDateTo()) && !itDate.isAfter(leave.getDateTo())) {
            duration = duration
                    .add(new BigDecimal(weeklyPlanningService.workingDayValue(weeklyPlanning, itDate)));
            itDate = itDate.plusDays(1);
        }

        if (!leave.getDateFrom().isEqual(leave.getDateTo())) {
            duration = duration.add(new BigDecimal(
                    this.computeEndDateWithSelect(leave.getDateTo(), leave.getEndOnSelect(), weeklyPlanning)));
        }

        duration = duration.subtract(Beans.get(PublicHolidayService.class).computePublicHolidayDays(
                leave.getDateFrom(), leave.getDateTo(), weeklyPlanning, publicHolidayPlanning));
        return duration;
    } else {
        return BigDecimal.ZERO;
    }
}

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)));
    }// w  w w.  j  av a  2  s  . com
    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.hr.service.PayrollPreparationService.java

License:Open Source License

public BigDecimal computeWorkingDaysNumber(PayrollPreparation payrollPreparation,
        List<PayrollLeave> payrollLeaveList) {
    LocalDate fromDate = new LocalDate(payrollPreparation.getYearPeriod(), payrollPreparation.getMonthSelect(),
            1);//from ww w.j  a  va2  s .  c om
    LocalDate toDate = new LocalDate(fromDate);
    toDate = toDate.dayOfMonth().withMaximumValue();
    LocalDate itDate = new LocalDate(fromDate);
    BigDecimal workingDays = BigDecimal.ZERO;
    while (!itDate.isAfter(toDate)) {
        workingDays = workingDays.add(new BigDecimal(
                weeklyPlanningService.workingDayValue(payrollPreparation.getEmployee().getPlanning(), itDate)));
        itDate = itDate.plusDays(1);
    }
    if (payrollLeaveList != null) {
        for (PayrollLeave payrollLeave : payrollLeaveList) {
            workingDays = workingDays.subtract(payrollLeave.getDuration());
        }
    }

    return workingDays;
}

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);
    }//from w  ww .  j  a v  a  2  s .c o m
    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();/*  ww w  . java2s  .co 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.axelor.apps.project.service.ProjectPlanningService.java

License:Open Source License

public static String getNameForColumns(int year, int week, int day) {
    LocalDate date = new LocalDate().withYear(year).withWeekOfWeekyear(week).withDayOfWeek(1);
    LocalDate newDate = date.plusDays(day - 1);
    return " " + Integer.toString(newDate.getDayOfMonth()) + "/" + Integer.toString(newDate.getMonthOfYear());
}

From source file:com.axelor.apps.tool.date.DateTool.java

License:Open Source License

/**
 * Calculer la date de la prochaine occurence d'un vnement suivant le calcul suivant :
 * Supprimer autant de fois que possible la frquence en mois  la date vise 
 * tout en tant suprieure  la date de dbut 
 * /*from ww w .  j  a  va 2 s  . c  o m*/
 * @param startDate
 *          La date de dbut
 *            
 * @param goalDate
 *          La date vise
 * 
 * @param frequencyInMonth
 *          Nombre de mois reprsentant la frquence de l'vnement           
 */
public static LocalDate nextOccurency(LocalDate startDate, LocalDate goalDate, int frequencyInMonth) {

    if (frequencyInMonth == 0) {

        LOG.debug("La frquence ne doit pas etre gale  0.");

        return null;

    } else {

        if (startDate == null && goalDate == null) {
            return null;
        } else {
            if (startDate.isAfter(goalDate)) {
                return goalDate;
            }
            return minusMonths(goalDate, days360MonthsBetween(startDate.plusDays(1), goalDate.minusDays(1))
                    / frequencyInMonth * frequencyInMonth);
        }
    }
}

From source file:com.axelor.apps.tool.date.DateTool.java

License:Open Source License

public static LocalDate minusMonths(LocalDate date, int nbMonths) {

    return date.plusDays(1).minusMonths(nbMonths).minusDays(1);

}

From source file:com.axelor.apps.tool.date.DateTool.java

License:Open Source License

public static LocalDate plusMonths(LocalDate date, int nbMonths) {

    return date.plusDays(1).plusMonths(nbMonths).minusDays(1);

}