Search in sources :

Example 1 with BudgetLine

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

the class BudgetService method updateLines.

@Transactional
public List<BudgetLine> updateLines(Budget budget) {
    if (budget.getBudgetLineList() != null && !budget.getBudgetLineList().isEmpty()) {
        for (BudgetLine budgetLine : budget.getBudgetLineList()) {
            budgetLine.setAmountRealized(BigDecimal.ZERO);
        }
        List<BudgetDistribution> 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) {
            Optional<LocalDate> optionaldate = getDate(budgetDistribution);
            optionaldate.ifPresent(date -> {
                for (BudgetLine budgetLine : budget.getBudgetLineList()) {
                    LocalDate fromDate = budgetLine.getFromDate();
                    LocalDate toDate = budgetLine.getToDate();
                    if (fromDate != null && toDate != null && (fromDate.isBefore(date) || fromDate.isEqual(date)) && (toDate.isAfter(date) || toDate.isEqual(date))) {
                        budgetLine.setAmountRealized(budgetLine.getAmountRealized().add(budgetDistribution.getAmount()));
                        break;
                    }
                }
            });
        }
    }
    return budget.getBudgetLineList();
}
Also used : BudgetLine(com.axelor.apps.account.db.BudgetLine) BudgetDistributionRepository(com.axelor.apps.account.db.repo.BudgetDistributionRepository) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) LocalDate(java.time.LocalDate) Transactional(com.google.inject.persist.Transactional)

Example 2 with BudgetLine

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

the class BudgetSupplychainService method computeTotalAmountCommitted.

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

Example 3 with BudgetLine

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

the class BudgetController method updateLines.

public void updateLines(ActionRequest request, ActionResponse response) {
    try {
        Budget budget = request.getContext().asType(Budget.class);
        budget = Beans.get(BudgetRepository.class).find(budget.getId());
        List<BudgetLine> budgetLineList = Beans.get(BudgetService.class).updateLines(budget);
        response.setValue("budgetLineList", budgetLineList);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : BudgetLine(com.axelor.apps.account.db.BudgetLine) Budget(com.axelor.apps.account.db.Budget) BudgetService(com.axelor.apps.account.service.BudgetService)

Example 4 with BudgetLine

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

the class BudgetSupplychainService method updateLines.

@Override
@Transactional
public List<BudgetLine> updateLines(Budget budget) {
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return super.updateLines(budget);
    }
    if (budget.getBudgetLineList() != null && !budget.getBudgetLineList().isEmpty()) {
        for (BudgetLine budgetLine : budget.getBudgetLineList()) {
            budgetLine.setAmountCommitted(BigDecimal.ZERO);
            budgetLine.setAmountRealized(BigDecimal.ZERO);
        }
        List<BudgetDistribution> budgetDistributionList = null;
        budgetDistributionList = Beans.get(BudgetDistributionRepository.class).all().filter("self.budget.id = ?1 AND self.purchaseOrderLine.purchaseOrder.statusSelect in (?2,?3)", budget.getId(), PurchaseOrderRepository.STATUS_VALIDATED, PurchaseOrderRepository.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 != null && toDate != null) && (fromDate.isBefore(orderDate) || fromDate.isEqual(orderDate)) && (toDate.isAfter(orderDate) || toDate.isEqual(orderDate))) {
                        budgetLine.setAmountCommitted(budgetLine.getAmountCommitted().add(budgetDistribution.getAmount()));
                        budgetLineRepository.save(budgetLine);
                        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) {
            Optional<LocalDate> optionaldate = getDate(budgetDistribution);
            Invoice invoice = budgetDistribution.getInvoiceLine().getInvoice();
            optionaldate.ifPresent(date -> {
                for (BudgetLine budgetLine : budget.getBudgetLineList()) {
                    LocalDate fromDate = budgetLine.getFromDate();
                    LocalDate toDate = budgetLine.getToDate();
                    if (fromDate != null && toDate != null && (fromDate.isBefore(date) || fromDate.isEqual(date)) && (toDate.isAfter(date) || toDate.isEqual(date))) {
                        budgetLine.setAmountRealized(invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND ? budgetLine.getAmountRealized().subtract(budgetDistribution.getAmount()) : budgetLine.getAmountRealized().add(budgetDistribution.getAmount()));
                        break;
                    }
                }
            });
        }
    }
    return budget.getBudgetLineList();
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) BudgetLine(com.axelor.apps.account.db.BudgetLine) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) LocalDate(java.time.LocalDate) Transactional(com.google.inject.persist.Transactional)

Example 5 with BudgetLine

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

the class BudgetSupplychainService method computeBudgetDistributionSumAmount.

public void computeBudgetDistributionSumAmount(BudgetDistribution budgetDistribution, LocalDate computeDate) {
    if (budgetDistribution.getBudget() != null && budgetDistribution.getBudget().getBudgetLineList() != null && computeDate != null) {
        List<BudgetLine> budgetLineList = budgetDistribution.getBudget().getBudgetLineList();
        BigDecimal budgetAmountAvailable = BigDecimal.ZERO;
        for (BudgetLine budgetLine : budgetLineList) {
            LocalDate fromDate = budgetLine.getFromDate();
            LocalDate toDate = budgetLine.getToDate();
            if (fromDate != null && DateTool.isBetween(fromDate, toDate, computeDate)) {
                BigDecimal amount = budgetLine.getAmountExpected().subtract(budgetLine.getAmountCommitted());
                budgetAmountAvailable = budgetAmountAvailable.add(amount);
            }
        }
        budgetDistribution.setBudgetAmountAvailable(budgetAmountAvailable);
    }
}
Also used : BudgetLine(com.axelor.apps.account.db.BudgetLine) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

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