Search in sources :

Example 6 with Budget

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

the class BudgetController method draft.

public void draft(ActionRequest request, ActionResponse response) {
    try {
        Budget budget = request.getContext().asType(Budget.class);
        budget = Beans.get(BudgetRepository.class).find(budget.getId());
        Beans.get(BudgetService.class).draft(budget);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Budget(com.axelor.apps.account.db.Budget) BudgetService(com.axelor.apps.account.service.BudgetService)

Example 7 with Budget

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

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

the class BudgetController method compute.

public void compute(ActionRequest request, ActionResponse response) {
    try {
        Budget budget = request.getContext().asType(Budget.class);
        response.setValue("totalAmountExpected", Beans.get(BudgetService.class).compute(budget));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Budget(com.axelor.apps.account.db.Budget)

Example 9 with Budget

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

the class PurchaseOrderServiceSupplychainImpl method requestPurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void requestPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        super.requestPurchaseOrder(purchaseOrder);
        return;
    }
    // budget control
    if (appAccountService.isApp("budget") && appAccountService.getAppBudget().getCheckAvailableBudget()) {
        List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
        Map<Budget, BigDecimal> amountPerBudget = new HashMap<>();
        if (appAccountService.getAppBudget().getManageMultiBudget()) {
            for (PurchaseOrderLine pol : purchaseOrderLines) {
                if (pol.getBudgetDistributionList() != null) {
                    for (BudgetDistribution bd : pol.getBudgetDistributionList()) {
                        Budget budget = bd.getBudget();
                        if (!amountPerBudget.containsKey(budget)) {
                            amountPerBudget.put(budget, bd.getAmount());
                        } else {
                            BigDecimal oldAmount = amountPerBudget.get(budget);
                            amountPerBudget.put(budget, oldAmount.add(bd.getAmount()));
                        }
                        isBudgetExceeded(budget, amountPerBudget.get(budget));
                    }
                }
            }
        } else {
            for (PurchaseOrderLine pol : purchaseOrderLines) {
                // getting Budget associated to POL
                Budget budget = pol.getBudget();
                if (!amountPerBudget.containsKey(budget)) {
                    amountPerBudget.put(budget, pol.getExTaxTotal());
                } else {
                    BigDecimal oldAmount = amountPerBudget.get(budget);
                    amountPerBudget.put(budget, oldAmount.add(pol.getExTaxTotal()));
                }
                isBudgetExceeded(budget, amountPerBudget.get(budget));
            }
        }
    }
    super.requestPurchaseOrder(purchaseOrder);
    int intercoPurchaseCreatingStatus = Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoPurchaseCreatingStatusSelect();
    if (purchaseOrder.getInterco() && intercoPurchaseCreatingStatus == PurchaseOrderRepository.STATUS_REQUESTED) {
        Beans.get(IntercoService.class).generateIntercoSaleFromPurchase(purchaseOrder);
    }
    if (purchaseOrder.getCreatedByInterco()) {
        fillIntercompanySaleOrderCounterpart(purchaseOrder);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) HashMap(java.util.HashMap) Budget(com.axelor.apps.account.db.Budget) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 10 with Budget

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

the class BudgetController method computeTotalAmountCommited.

public void computeTotalAmountCommited(ActionRequest request, ActionResponse response) {
    try {
        Budget budget = request.getContext().asType(Budget.class);
        budget = Beans.get(BudgetRepository.class).find(budget.getId());
        response.setValue("totalAmountCommitted", Beans.get(BudgetSupplychainService.class).computeTotalAmountCommitted(budget));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Budget(com.axelor.apps.account.db.Budget)

Aggregations

Budget (com.axelor.apps.account.db.Budget)11 BudgetService (com.axelor.apps.account.service.BudgetService)5 BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)3 BudgetLine (com.axelor.apps.account.db.BudgetLine)3 Transactional (com.google.inject.persist.Transactional)3 BigDecimal (java.math.BigDecimal)3 Invoice (com.axelor.apps.account.db.Invoice)2 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 BudgetDistributionRepository (com.axelor.apps.account.db.repo.BudgetDistributionRepository)2 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 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)2 Beans (com.axelor.inject.Beans)2 Inject (com.google.inject.Inject)2 LocalDate (java.time.LocalDate)2 List (java.util.List)2 Optional (java.util.Optional)2 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1