use of com.axelor.apps.account.db.BudgetDistribution 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();
}
use of com.axelor.apps.account.db.BudgetDistribution in project axelor-open-suite by axelor.
the class InvoiceLineSupplychainService method computeBudgetDistributionSumAmount.
public void computeBudgetDistributionSumAmount(InvoiceLine invoiceLine, Invoice invoice) {
List<BudgetDistribution> budgetDistributionList = invoiceLine.getBudgetDistributionList();
PurchaseOrderLine purchaseOrderLine = invoiceLine.getPurchaseOrderLine();
BigDecimal budgetDistributionSumAmount = BigDecimal.ZERO;
LocalDate computeDate = invoice.getInvoiceDate();
if (purchaseOrderLine != null && purchaseOrderLine.getPurchaseOrder().getOrderDate() != null) {
computeDate = purchaseOrderLine.getPurchaseOrder().getOrderDate();
}
if (budgetDistributionList != null && !budgetDistributionList.isEmpty()) {
for (BudgetDistribution budgetDistribution : budgetDistributionList) {
budgetDistributionSumAmount = budgetDistributionSumAmount.add(budgetDistribution.getAmount());
Beans.get(BudgetSupplychainService.class).computeBudgetDistributionSumAmount(budgetDistribution, computeDate);
}
}
invoiceLine.setBudgetDistributionSumAmount(budgetDistributionSumAmount);
}
use of com.axelor.apps.account.db.BudgetDistribution in project axelor-open-suite by axelor.
the class PurchaseOrderLineServiceSupplychainImpl method computeBudgetDistributionSumAmount.
public void computeBudgetDistributionSumAmount(PurchaseOrderLine purchaseOrderLine, PurchaseOrder purchaseOrder) {
List<BudgetDistribution> budgetDistributionList = purchaseOrderLine.getBudgetDistributionList();
BigDecimal budgetDistributionSumAmount = BigDecimal.ZERO;
LocalDate computeDate = purchaseOrder.getOrderDate();
if (budgetDistributionList != null && !budgetDistributionList.isEmpty()) {
for (BudgetDistribution budgetDistribution : budgetDistributionList) {
budgetDistributionSumAmount = budgetDistributionSumAmount.add(budgetDistribution.getAmount());
Beans.get(BudgetSupplychainService.class).computeBudgetDistributionSumAmount(budgetDistribution, computeDate);
}
}
purchaseOrderLine.setBudgetDistributionSumAmount(budgetDistributionSumAmount);
}
use of com.axelor.apps.account.db.BudgetDistribution in project axelor-open-suite by axelor.
the class PurchaseOrderServiceSupplychainImpl method generateBudgetDistribution.
@Transactional
@Override
public void generateBudgetDistribution(PurchaseOrder purchaseOrder) {
if (purchaseOrder.getPurchaseOrderLineList() != null) {
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
if (purchaseOrderLine.getBudget() != null && (purchaseOrderLine.getBudgetDistributionList() == null || purchaseOrderLine.getBudgetDistributionList().isEmpty())) {
BudgetDistribution budgetDistribution = new BudgetDistribution();
budgetDistribution.setBudget(purchaseOrderLine.getBudget());
budgetDistribution.setAmount(purchaseOrderLine.getCompanyExTaxTotal());
purchaseOrderLine.addBudgetDistributionListItem(budgetDistribution);
}
}
// purchaseOrderRepo.save(purchaseOrder);
}
}
use of com.axelor.apps.account.db.BudgetDistribution 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);
}
}
Aggregations