Search in sources :

Example 6 with BudgetLine

use of com.axelor.apps.account.db.BudgetLine in project axelor-open-suite by axelor.

the class BudgetService method computeTotalAmountRealized.

@Transactional
public BigDecimal computeTotalAmountRealized(Budget budget) {
    List<BudgetLine> budgetLineList = budget.getBudgetLineList();
    if (budgetLineList == null) {
        return BigDecimal.ZERO;
    }
    BigDecimal totalAmountRealized = budgetLineList.stream().map(BudgetLine::getAmountRealized).reduce(BigDecimal.ZERO, BigDecimal::add);
    budget.setTotalAmountRealized(totalAmountRealized);
    return totalAmountRealized;
}
Also used : BudgetLine(com.axelor.apps.account.db.BudgetLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 7 with BudgetLine

use of com.axelor.apps.account.db.BudgetLine in project axelor-open-suite by axelor.

the class BudgetService method checkSharedDates.

public void checkSharedDates(Budget budget) throws AxelorException {
    if (budget.getBudgetLineList() == null) {
        return;
    }
    List<BudgetLine> budgetLineList = budget.getBudgetLineList();
    for (int i = 0; i < budgetLineList.size() - 1; i++) {
        BudgetLine budgetLineA = budgetLineList.get(i);
        LocalDate fromDateA = budgetLineA.getFromDate();
        LocalDate toDateA = budgetLineA.getToDate();
        for (int j = i + 1; j < budgetLineList.size(); j++) {
            BudgetLine budgetLineB = budgetLineList.get(j);
            LocalDate fromDateB = budgetLineB.getFromDate();
            LocalDate toDateB = budgetLineB.getToDate();
            if (fromDateA.equals(fromDateB) || toDateA.equals(toDateB)) {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get("Two or more budget lines share dates"));
            }
            if (fromDateA.isBefore(fromDateB) && (!toDateA.isBefore(fromDateB))) {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get("Two or more budget lines share dates"));
            }
            if (fromDateA.isAfter(fromDateB) && (!fromDateA.isAfter(toDateB))) {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get("Two or more budget lines share dates"));
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) BudgetLine(com.axelor.apps.account.db.BudgetLine) LocalDate(java.time.LocalDate)

Example 8 with BudgetLine

use of com.axelor.apps.account.db.BudgetLine in project axelor-open-suite by axelor.

the class BudgetService method generatePeriods.

public List<BudgetLine> generatePeriods(Budget budget) throws AxelorException {
    if (budget.getBudgetLineList() != null && !budget.getBudgetLineList().isEmpty()) {
        List<BudgetLine> budgetLineList = budget.getBudgetLineList();
        budgetLineList.clear();
    }
    List<BudgetLine> budgetLineList = new ArrayList<BudgetLine>();
    Integer duration = budget.getPeriodDurationSelect();
    LocalDate fromDate = budget.getFromDate();
    LocalDate toDate = budget.getToDate();
    LocalDate budgetLineToDate = fromDate;
    Integer budgetLineNumber = 1;
    int c = 0;
    int loopLimit = 1000;
    while (budgetLineToDate.isBefore(toDate)) {
        if (budgetLineNumber != 1 && duration != 0)
            fromDate = fromDate.plusMonths(duration);
        if (c >= loopLimit) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BUDGET_1));
        }
        c += 1;
        budgetLineToDate = duration == 0 ? toDate : fromDate.plusMonths(duration).minusDays(1);
        if (budgetLineToDate.isAfter(toDate))
            budgetLineToDate = toDate;
        if (fromDate.isAfter(toDate))
            continue;
        BudgetLine budgetLine = new BudgetLine();
        budgetLine.setFromDate(fromDate);
        budgetLine.setToDate(budgetLineToDate);
        budgetLine.setBudget(budget);
        budgetLine.setAmountExpected(budget.getAmountForGeneration());
        budgetLineList.add(budgetLine);
        budgetLineNumber++;
        if (duration == 0)
            break;
    }
    return budgetLineList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) BudgetLine(com.axelor.apps.account.db.BudgetLine) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Aggregations

BudgetLine (com.axelor.apps.account.db.BudgetLine)8 LocalDate (java.time.LocalDate)5 Transactional (com.google.inject.persist.Transactional)4 BigDecimal (java.math.BigDecimal)3 BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)2 AxelorException (com.axelor.exception.AxelorException)2 Budget (com.axelor.apps.account.db.Budget)1 Invoice (com.axelor.apps.account.db.Invoice)1 BudgetDistributionRepository (com.axelor.apps.account.db.repo.BudgetDistributionRepository)1 BudgetService (com.axelor.apps.account.service.BudgetService)1 ArrayList (java.util.ArrayList)1