Search in sources :

Example 1 with PeriodRepository

use of com.axelor.apps.base.db.repo.PeriodRepository in project axelor-open-suite by axelor.

the class ExpenseServiceImpl method updateMoveDateAndPeriod.

@Override
public Expense updateMoveDateAndPeriod(Expense expense) {
    if (CollectionUtils.isNotEmpty(expense.getGeneralExpenseLineList())) {
        LocalDate recentDate = expense.getGeneralExpenseLineList().stream().map(ExpenseLine::getExpenseDate).max(LocalDate::compareTo).get();
        expense.setMoveDate(recentDate);
        PeriodRepository periodRepository = Beans.get(PeriodRepository.class);
        if (expense.getPeriod() == null || !(recentDate.compareTo(expense.getPeriod().getFromDate()) >= 0) || !(recentDate.compareTo(expense.getPeriod().getToDate()) <= 0)) {
            expense.setPeriod(periodRepository.all().filter("self.fromDate <= :_moveDate AND self.toDate >= :_moveDate AND" + " self.statusSelect = 1 AND self.allowExpenseCreation = true AND" + " self.year.company = :_company AND self.year.typeSelect = 1").bind("_moveDate", expense.getMoveDate()).bind("_company", expense.getCompany()).fetchOne());
        }
    }
    return expense;
}
Also used : PeriodRepository(com.axelor.apps.base.db.repo.PeriodRepository) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) LocalDate(java.time.LocalDate)

Aggregations

PeriodRepository (com.axelor.apps.base.db.repo.PeriodRepository)1 ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)1 LocalDate (java.time.LocalDate)1