Search in sources :

Example 26 with AnalyticMoveLine

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

the class ContractLineServiceProjectImpl method createAnalyticDistributionWithTemplate.

@Override
public ContractLine createAnalyticDistributionWithTemplate(ContractLine contractLine, Contract contract) {
    contractLine = super.createAnalyticDistributionWithTemplate(contractLine, contract);
    Project project = contract.getProject();
    if (project != null) {
        List<AnalyticMoveLine> analyticMoveLineList = contractLine.getAnalyticMoveLineList();
        analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setProject(project));
        contractLine.setAnalyticMoveLineList(analyticMoveLineList);
    }
    return contractLine;
}
Also used : Project(com.axelor.apps.project.db.Project) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 27 with AnalyticMoveLine

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

the class SaleOrderLineProjectServiceImpl method createAnalyticDistributionWithTemplate.

@Override
public SaleOrderLine createAnalyticDistributionWithTemplate(SaleOrderLine saleOrderLine) {
    SaleOrderLine soLine = super.createAnalyticDistributionWithTemplate(saleOrderLine);
    List<AnalyticMoveLine> analyticMoveLineList = soLine.getAnalyticMoveLineList();
    if (soLine.getProject() != null && analyticMoveLineList != null) {
        analyticMoveLineList.forEach(analyticLine -> analyticLine.setProject(soLine.getProject()));
    }
    return soLine;
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 28 with AnalyticMoveLine

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

the class ProjectAnalyticMoveLineServiceImpl method updateLines.

@Override
@Transactional(rollbackOn = Exception.class)
public PurchaseOrder updateLines(PurchaseOrder purchaseOrder) {
    for (PurchaseOrderLine orderLine : purchaseOrder.getPurchaseOrderLineList()) {
        orderLine.setProject(purchaseOrder.getProject());
        for (AnalyticMoveLine analyticMoveLine : orderLine.getAnalyticMoveLineList()) {
            analyticMoveLine.setProject(purchaseOrder.getProject());
            analyticMoveLineRepository.save(analyticMoveLine);
        }
    }
    return purchaseOrder;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 29 with AnalyticMoveLine

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

the class MoveLineServiceImpl method updateAccountTypeOnAnalytic.

@Override
public void updateAccountTypeOnAnalytic(MoveLine moveLine, List<AnalyticMoveLine> analyticMoveLineList) {
    if ((analyticMoveLineList == null || analyticMoveLineList.isEmpty())) {
        return;
    }
    for (AnalyticMoveLine analyticMoveLine : analyticMoveLineList) {
        if (moveLine.getAccount() != null) {
            analyticMoveLine.setAccount(moveLine.getAccount());
            analyticMoveLine.setAccountType(moveLine.getAccount().getAccountType());
        }
    }
}
Also used : AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 30 with AnalyticMoveLine

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

the class MoveLineServiceImpl method consolidateMoveLines.

/**
 * Consolider des lignes d'écritures par compte comptable.
 *
 * @param moveLines
 */
@Override
public List<MoveLine> consolidateMoveLines(List<MoveLine> moveLines) {
    Map<List<Object>, MoveLine> map = new HashMap<List<Object>, MoveLine>();
    MoveLine consolidateMoveLine = null;
    for (MoveLine moveLine : moveLines) {
        List<Object> keys = new ArrayList<Object>();
        keys.add(moveLine.getAccount());
        keys.add(moveLine.getTaxLine());
        keys.add(moveLine.getAnalyticDistributionTemplate());
        consolidateMoveLine = this.findConsolidateMoveLine(map, moveLine, keys);
        if (consolidateMoveLine != null) {
            BigDecimal consolidateCurrencyAmount = BigDecimal.ZERO;
            log.debug("MoveLine :: Debit : {}, Credit : {}, Currency amount : {}", moveLine.getDebit(), moveLine.getCredit(), moveLine.getCurrencyAmount());
            log.debug("Consolidate moveLine :: Debit : {}, Credit : {}, Currency amount : {}", consolidateMoveLine.getDebit(), consolidateMoveLine.getCredit(), consolidateMoveLine.getCurrencyAmount());
            if (moveLine.getDebit().subtract(moveLine.getCredit()).compareTo(BigDecimal.ZERO) != consolidateMoveLine.getDebit().subtract(consolidateMoveLine.getCredit()).compareTo(BigDecimal.ZERO)) {
                consolidateCurrencyAmount = consolidateMoveLine.getCurrencyAmount().subtract(moveLine.getCurrencyAmount());
            } else {
                consolidateCurrencyAmount = consolidateMoveLine.getCurrencyAmount().add(moveLine.getCurrencyAmount());
            }
            consolidateMoveLine.setCurrencyAmount(consolidateCurrencyAmount.abs());
            consolidateMoveLine.setCredit(consolidateMoveLine.getCredit().add(moveLine.getCredit()));
            consolidateMoveLine.setDebit(consolidateMoveLine.getDebit().add(moveLine.getDebit()));
            if (consolidateMoveLine.getAnalyticMoveLineList() != null && !consolidateMoveLine.getAnalyticMoveLineList().isEmpty()) {
                for (AnalyticMoveLine analyticDistributionLine : consolidateMoveLine.getAnalyticMoveLineList()) {
                    for (AnalyticMoveLine analyticDistributionLineIt : moveLine.getAnalyticMoveLineList()) {
                        if (analyticDistributionLine.getAnalyticAxis().equals(analyticDistributionLineIt.getAnalyticAxis()) && analyticDistributionLine.getAnalyticAccount().equals(analyticDistributionLineIt.getAnalyticAccount()) && analyticDistributionLine.getAccount().equals(analyticDistributionLineIt.getAccount()) && analyticDistributionLine.getPercentage().equals(analyticDistributionLineIt.getPercentage()) && ((analyticDistributionLine.getAnalyticJournal() == null && analyticDistributionLineIt.getAnalyticJournal() == null) || analyticDistributionLine.getAnalyticJournal().equals(analyticDistributionLineIt.getAnalyticJournal()))) {
                            analyticDistributionLine.setAmount(analyticDistributionLine.getAmount().add(analyticDistributionLineIt.getAmount()));
                            break;
                        }
                    }
                }
            }
        } else {
            map.put(keys, moveLine);
        }
    }
    BigDecimal credit = null;
    BigDecimal debit = null;
    int moveLineId = 1;
    moveLines.clear();
    for (MoveLine moveLine : map.values()) {
        credit = moveLine.getCredit();
        debit = moveLine.getDebit();
        moveLine.setCurrencyAmount(moveLine.getCurrencyAmount().abs());
        if (debit.compareTo(BigDecimal.ZERO) == 1 && credit.compareTo(BigDecimal.ZERO) == 1) {
            if (debit.compareTo(credit) == 1) {
                moveLine.setDebit(debit.subtract(credit));
                moveLine.setCredit(BigDecimal.ZERO);
                moveLine.setCounter(moveLineId++);
                moveLines.add(moveLine);
            } else if (credit.compareTo(debit) == 1) {
                moveLine.setCredit(credit.subtract(debit));
                moveLine.setDebit(BigDecimal.ZERO);
                moveLine.setCounter(moveLineId++);
                moveLines.add(moveLine);
            }
        } else if (debit.compareTo(BigDecimal.ZERO) == 1 || credit.compareTo(BigDecimal.ZERO) == 1) {
            moveLine.setCounter(moveLineId++);
            moveLines.add(moveLine);
        }
    }
    return moveLines;
}
Also used : HashMap(java.util.HashMap) TaxPaymentMoveLine(com.axelor.apps.account.db.TaxPaymentMoveLine) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Aggregations

AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)30 MoveLine (com.axelor.apps.account.db.MoveLine)7 Transactional (com.google.inject.persist.Transactional)6 BigDecimal (java.math.BigDecimal)6 AnalyticMoveLineRepository (com.axelor.apps.account.db.repo.AnalyticMoveLineRepository)5 ArrayList (java.util.ArrayList)5 Account (com.axelor.apps.account.db.Account)4 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)4 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)4 AxelorException (com.axelor.exception.AxelorException)4 TaxPaymentMoveLine (com.axelor.apps.account.db.TaxPaymentMoveLine)3 Company (com.axelor.apps.base.db.Company)3 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)3 LocalDate (java.time.LocalDate)3 AnalyticAccount (com.axelor.apps.account.db.AnalyticAccount)2 Move (com.axelor.apps.account.db.Move)2 TaxLine (com.axelor.apps.account.db.TaxLine)2 AnalyticMoveLineService (com.axelor.apps.account.service.AnalyticMoveLineService)2 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)2 Partner (com.axelor.apps.base.db.Partner)2