Example usage for org.joda.time LocalDate isAfter

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

Introduction

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

Prototype

public boolean isAfter(ReadablePartial partial) 

Source Link

Document

Is this partial later than the specified partial.

Usage

From source file:com.axelor.apps.cash.management.service.ForecastRecapService.java

License:Open Source License

public void populateWithSalaries(ForecastRecap forecastRecap) {
    List<Employee> employeeList = new ArrayList<Employee>();
    if (forecastRecap.getBankDetails() != null) {
        employeeList = Beans.get(EmployeeRepository.class).all()
                .filter("self.user.activeCompany = ?1 AND self.bankDetails = ?2", forecastRecap.getCompany(),
                        forecastRecap.getBankDetails())
                .fetch();/*from   w  w w  . j  av  a2  s. c om*/
    } else {
        employeeList = Beans.get(EmployeeRepository.class).all()
                .filter("self.user.activeCompany = ?1", forecastRecap.getCompany()).fetch();
    }
    LocalDate itDate = new LocalDate(forecastRecap.getFromDate());
    while (!itDate.isAfter(forecastRecap.getToDate())) {
        if (itDate.isEqual(new LocalDate(itDate.getYear(), itDate.getMonthOfYear(),
                itDate.dayOfMonth().getMaximumValue()))) {
            for (Employee employee : employeeList) {
                forecastRecap.setCurrentBalance(forecastRecap.getCurrentBalance().subtract(employee
                        .getHourlyRate().multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4)))));
                forecastRecap.addForecastRecapLineListItem(this.createForecastRecapLine(itDate, 2, null,
                        employee.getHourlyRate()
                                .multiply(employee.getWeeklyWorkHours().multiply(new BigDecimal(4))),
                        forecastRecap.getCurrentBalance()));
            }
            itDate = itDate.plusMonths(1);
        } else {
            itDate = new LocalDate(itDate.getYear(), itDate.getMonthOfYear(),
                    itDate.dayOfMonth().getMaximumValue());
        }
    }
}

From source file:com.axelor.apps.cash.management.service.ForecastService.java

License:Open Source License

public void generate(ForecastGenerator forecastGenerator) {
    LocalDate fromDate = forecastGenerator.getFromDate();
    LocalDate toDate = forecastGenerator.getToDate();
    LocalDate itDate = new LocalDate(fromDate);
    LocalDate todayDate = generalService.getTodayDate();

    if (forecastGenerator.getForecastList() != null && !forecastGenerator.getForecastList().isEmpty()) {
        List<Forecast> forecastList = forecastGenerator.getForecastList();
        for (Forecast forecast : forecastList) {
            if (forecast.getRealizedSelect() == ForecastRepository.REALISED_SELECT_NO) {
                forecastList.remove(forecast);
            } else if (forecast.getRealizedSelect() == ForecastRepository.REALISED_SELECT_AUTO
                    && forecast.getEstimatedDate().isAfter(todayDate)) {
                forecastList.remove(forecast);
            }/*from  w ww.  j a  v a 2 s .  c om*/
        }
    }

    while (!itDate.isAfter(toDate)) {
        Forecast forecast = this.createForecast(forecastGenerator.getCompany(),
                forecastGenerator.getBankDetails(), forecastGenerator.getTypeSelect(),
                forecastGenerator.getAmount(), itDate, forecastGenerator.getForecastReason(),
                forecastGenerator.getComments(), forecastGenerator.getRealizedSelect());
        forecastGenerator.addForecastListItem(forecast);
        itDate.plusMonths(forecastGenerator.getPeriodicitySelect());
    }
}

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);
        }// w  w w  .  j a  v  a 2s .  co  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)));
    }/*ww w . jav  a2s .  co m*/
    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);/*w w  w.ja v a2  s .co  m*/
    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);
    }//w  w w.j  a va2 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  w w.  j a v  a 2 s  .com*/
    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 void getTasksForUser(ActionRequest request, ActionResponse response) {
    List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
    try {/*from   w  w  w.  jav  a2s .  c o m*/
        LocalDate todayDate = Beans.get(GeneralService.class).getTodayDate();
        List<ProjectPlanningLine> linesList = Beans.get(ProjectPlanningLineRepository.class).all()
                .filter("self.user.id = ?1 AND self.year >= ?2 AND self.week >= ?3",
                        AuthUtils.getUser().getId(), todayDate.getYear(), todayDate.getWeekOfWeekyear())
                .fetch();

        for (ProjectPlanningLine line : linesList) {
            if (line.getMonday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.MONDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getMonday().toString());
                    dataList.add(map);
                }
            }
            if (line.getTuesday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.TUESDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getTuesday().toString());
                    dataList.add(map);
                }
            }
            if (line.getWednesday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.WEDNESDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getWednesday().toString());
                    dataList.add(map);
                }
            }
            if (line.getThursday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.THURSDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getThursday().toString());
                    dataList.add(map);
                }
            }
            if (line.getFriday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.FRIDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getFriday().toString());
                    dataList.add(map);
                }
            }
            if (line.getSaturday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.SATURDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getSaturday().toString());
                    dataList.add(map);
                }
            }
            if (line.getSunday().compareTo(BigDecimal.ZERO) != 0) {
                LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek())
                        .withDayOfWeek(DateTimeConstants.SUNDAY);
                if (date.isAfter(todayDate) || date.isEqual(todayDate)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("taskId", line.getProjectTask().getId().toString());
                    map.put("name", line.getProjectTask().getFullName());
                    if (line.getProjectTask().getProject() != null) {
                        map.put("projectName", line.getProjectTask().getProject().getFullName());
                    } else {
                        map.put("projectName", "");
                    }
                    map.put("date", date.toString());
                    map.put("duration", line.getSunday().toString());
                    dataList.add(map);
                }
            }
        }
        response.setData(dataList);
    } catch (Exception e) {
        response.setStatus(-1);
        response.setError(e.getMessage());
    }
}

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);
        }//w  ww.j av  a 2  s . co  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;
    }/*from   w  ww.  j av  a 2s.  com*/

    return false;
}