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();
}
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;
}
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);
}
}
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();
}
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);
}
}
Aggregations