Search in sources :

Example 1 with BudgetDistribution

use of com.axelor.apps.account.db.BudgetDistribution 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 BudgetDistribution

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

the class PurchaseOrderServiceSupplychainImpl method applyToallBudgetDistribution.

@Transactional
@Override
public void applyToallBudgetDistribution(PurchaseOrder purchaseOrder) {
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
        BudgetDistribution newBudgetDistribution = new BudgetDistribution();
        newBudgetDistribution.setAmount(purchaseOrderLine.getCompanyExTaxTotal());
        newBudgetDistribution.setBudget(purchaseOrder.getBudget());
        newBudgetDistribution.setPurchaseOrderLine(purchaseOrderLine);
        Beans.get(BudgetDistributionRepository.class).save(newBudgetDistribution);
        Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).computeBudgetDistributionSumAmount(purchaseOrderLine, purchaseOrder);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BudgetDistributionRepository(com.axelor.apps.account.db.repo.BudgetDistributionRepository) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) Transactional(com.google.inject.persist.Transactional)

Example 3 with BudgetDistribution

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

the class BudgetSupplychainService method updateBudgetLinesFromPurchaseOrder.

public void updateBudgetLinesFromPurchaseOrder(PurchaseOrder purchaseOrder) {
    List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
    if (purchaseOrderLineList == null) {
        return;
    }
    purchaseOrderLineList.stream().flatMap(x -> x.getBudgetDistributionList().stream()).forEach(budgetDistribution -> {
        Budget budget = budgetDistribution.getBudget();
        updateLines(budget);
        computeTotalAmountCommitted(budget);
    });
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BudgetLineRepository(com.axelor.apps.account.db.repo.BudgetLineRepository) Budget(com.axelor.apps.account.db.Budget) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) BudgetDistributionRepository(com.axelor.apps.account.db.repo.BudgetDistributionRepository) Inject(com.google.inject.Inject) Invoice(com.axelor.apps.account.db.Invoice) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) BudgetService(com.axelor.apps.account.service.BudgetService) List(java.util.List) BudgetLine(com.axelor.apps.account.db.BudgetLine) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BudgetRepository(com.axelor.apps.account.db.repo.BudgetRepository) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) LocalDate(java.time.LocalDate) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) DateTool(com.axelor.apps.tool.date.DateTool) Budget(com.axelor.apps.account.db.Budget)

Example 4 with BudgetDistribution

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

the class ValidateState method generateBudgetDistribution.

private void generateBudgetDistribution(Invoice invoice) {
    if (invoice.getInvoiceLineList() != null) {
        for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
            if (invoiceLine.getBudget() != null && (invoiceLine.getBudgetDistributionList() == null || invoiceLine.getBudgetDistributionList().isEmpty())) {
                BudgetDistribution budgetDistribution = new BudgetDistribution();
                budgetDistribution.setBudget(invoiceLine.getBudget());
                budgetDistribution.setAmount(invoiceLine.getCompanyExTaxTotal());
                invoiceLine.addBudgetDistributionListItem(budgetDistribution);
            }
        }
    }
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution)

Example 5 with BudgetDistribution

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

the class InvoiceLineGeneratorSupplyChain method copyBudgetDistributionList.

public void copyBudgetDistributionList(List<BudgetDistribution> originalBudgetDistributionList, InvoiceLine invoiceLine) {
    if (originalBudgetDistributionList == null) {
        return;
    }
    for (BudgetDistribution budgetDistributionIt : originalBudgetDistributionList) {
        BudgetDistribution budgetDistribution = new BudgetDistribution();
        budgetDistribution.setBudget(budgetDistributionIt.getBudget());
        budgetDistribution.setAmount(budgetDistributionIt.getAmount());
        budgetDistribution.setBudgetAmountAvailable(budgetDistributionIt.getBudgetAmountAvailable());
        invoiceLine.addBudgetDistributionListItem(budgetDistribution);
    }
}
Also used : BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution)

Aggregations

BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)11 Transactional (com.google.inject.persist.Transactional)7 LocalDate (java.time.LocalDate)6 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)5 BigDecimal (java.math.BigDecimal)5 BudgetLine (com.axelor.apps.account.db.BudgetLine)4 BudgetDistributionRepository (com.axelor.apps.account.db.repo.BudgetDistributionRepository)4 Budget (com.axelor.apps.account.db.Budget)3 Invoice (com.axelor.apps.account.db.Invoice)3 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)3 BudgetLineRepository (com.axelor.apps.account.db.repo.BudgetLineRepository)2 BudgetRepository (com.axelor.apps.account.db.repo.BudgetRepository)2 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)2 Beans (com.axelor.inject.Beans)2 Inject (com.google.inject.Inject)2 List (java.util.List)2 Optional (java.util.Optional)2 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)1 BudgetService (com.axelor.apps.account.service.BudgetService)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1