Search in sources :

Example 21 with AnalyticMoveLine

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

the class ContractLineServiceImpl method createAnalyticDistributionWithTemplate.

@Override
public ContractLine createAnalyticDistributionWithTemplate(ContractLine contractLine, Contract contract) {
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    List<AnalyticMoveLine> analyticMoveLineList = Beans.get(AnalyticMoveLineService.class).generateLines(contractLine.getAnalyticDistributionTemplate(), contractLine.getExTaxTotal(), AnalyticMoveLineRepository.STATUS_FORECAST_CONTRACT, appAccountService.getTodayDate(contract.getCompany()));
    contractLine.setAnalyticMoveLineList(analyticMoveLineList);
    return contractLine;
}
Also used : AnalyticMoveLineService(com.axelor.apps.account.service.AnalyticMoveLineService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 22 with AnalyticMoveLine

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

the class InvoiceLineGeneratorSupplyChain method createInvoiceLine.

/**
 * @return
 * @throws AxelorException
 */
@Override
protected InvoiceLine createInvoiceLine() throws AxelorException {
    InvoiceLine invoiceLine = super.createInvoiceLine();
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return invoiceLine;
    }
    InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
    this.assignOriginElements(invoiceLine);
    List<AnalyticMoveLine> analyticMoveLineList = null;
    if (saleOrderLine != null) {
        switch(saleOrderLine.getTypeSelect()) {
            case SaleOrderLineRepository.TYPE_END_OF_PACK:
                invoiceLine.setIsHideUnitAmounts(saleOrderLine.getIsHideUnitAmounts());
                invoiceLine.setIsShowTotal(saleOrderLine.getIsShowTotal());
                break;
            case SaleOrderLineRepository.TYPE_NORMAL:
                if (saleOrderLine.getAnalyticDistributionTemplate() != null || !ObjectUtils.isEmpty(saleOrderLine.getAnalyticMoveLineList())) {
                    invoiceLine.setAnalyticDistributionTemplate(saleOrderLine.getAnalyticDistributionTemplate());
                    this.copyAnalyticMoveLines(saleOrderLine.getAnalyticMoveLineList(), invoiceLine);
                    analyticMoveLineList = invoiceLineService.computeAnalyticDistribution(invoiceLine);
                } else {
                    analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
                    analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
                }
                break;
            default:
                return invoiceLine;
        }
    } else if (purchaseOrderLine != null) {
        if (purchaseOrderLine.getAnalyticDistributionTemplate() != null || !ObjectUtils.isEmpty(purchaseOrderLine.getAnalyticMoveLineList())) {
            invoiceLine.setAnalyticDistributionTemplate(purchaseOrderLine.getAnalyticDistributionTemplate());
            this.copyAnalyticMoveLines(purchaseOrderLine.getAnalyticMoveLineList(), invoiceLine);
            analyticMoveLineList = invoiceLineService.computeAnalyticDistribution(invoiceLine);
        } else {
            analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
            analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
        }
        this.copyBudgetDistributionList(purchaseOrderLine.getBudgetDistributionList(), invoiceLine);
        invoiceLine.setBudget(purchaseOrderLine.getBudget());
        invoiceLine.setBudgetDistributionSumAmount(purchaseOrderLine.getBudgetDistributionSumAmount());
        invoiceLine.setFixedAssets(purchaseOrderLine.getFixedAssets());
        if (product != null) {
            invoiceLine.setProductCode((String) productCompanyService.get(product, "code", invoice.getCompany()));
            Account account = accountManagementService.getProductAccount(product, invoice.getCompany(), invoice.getPartner().getFiscalPosition(), InvoiceToolService.isPurchase(invoice), invoiceLine.getFixedAssets());
            invoiceLine.setAccount(account);
        }
        if (product != null && purchaseOrderLine.getFixedAssets()) {
            FixedAssetCategory fixedAssetCategory = accountManagementService.getProductFixedAssetCategory(product, invoice.getCompany());
            invoiceLine.setFixedAssetCategory(fixedAssetCategory);
        }
    } else if (stockMoveLine != null) {
        this.price = stockMoveLine.getUnitPriceUntaxed();
        this.inTaxPrice = stockMoveLine.getUnitPriceTaxed();
        this.price = unitConversionService.convert(stockMoveLine.getUnit(), this.unit, this.price, appBaseService.getNbDecimalDigitForUnitPrice(), product);
        this.inTaxPrice = unitConversionService.convert(stockMoveLine.getUnit(), this.unit, this.inTaxPrice, appBaseService.getNbDecimalDigitForUnitPrice(), product);
        invoiceLine.setPrice(price);
        invoiceLine.setInTaxPrice(inTaxPrice);
        analyticMoveLineList = invoiceLineService.getAndComputeAnalyticDistribution(invoiceLine, invoice);
        analyticMoveLineList.stream().forEach(invoiceLine::addAnalyticMoveLineListItem);
    }
    return invoiceLine;
}
Also used : FixedAssetCategory(com.axelor.apps.account.db.FixedAssetCategory) Account(com.axelor.apps.account.db.Account) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 23 with AnalyticMoveLine

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

the class InvoiceLineGeneratorSupplyChain method copyAnalyticMoveLines.

public void copyAnalyticMoveLines(List<AnalyticMoveLine> originalAnalyticMoveLineList, InvoiceLine invoiceLine) {
    if (originalAnalyticMoveLineList == null) {
        return;
    }
    for (AnalyticMoveLine originalAnalyticMoveLine : originalAnalyticMoveLineList) {
        AnalyticMoveLine analyticMoveLine = Beans.get(AnalyticMoveLineRepository.class).copy(originalAnalyticMoveLine, false);
        analyticMoveLine.setTypeSelect(AnalyticMoveLineMngtRepository.STATUS_FORECAST_INVOICE);
        invoiceLine.addAnalyticMoveLineListItem(analyticMoveLine);
    }
}
Also used : AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 24 with AnalyticMoveLine

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

the class MoveLineManagementRepository method save.

@Override
public MoveLine save(MoveLine entity) {
    List<AnalyticMoveLine> analyticMoveLineList = entity.getAnalyticMoveLineList();
    if (analyticMoveLineList != null) {
        for (AnalyticMoveLine analyticMoveLine : analyticMoveLineList) {
            analyticMoveLine.setAccount(entity.getAccount());
            analyticMoveLine.setAccountType(entity.getAccount().getAccountType());
        }
    }
    try {
        Beans.get(MoveLineService.class).validateMoveLine(entity);
    } catch (Exception e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
        throw new PersistenceException(e.getMessage(), e);
    }
    return super.save(entity);
}
Also used : MoveLineService(com.axelor.apps.account.service.move.MoveLineService) PersistenceException(javax.persistence.PersistenceException) AxelorException(com.axelor.exception.AxelorException) PersistenceException(javax.persistence.PersistenceException) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 25 with AnalyticMoveLine

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

the class InvoiceServiceProjectImpl method updateLines.

@Transactional(rollbackOn = Exception.class)
public Invoice updateLines(Invoice invoice) {
    AnalyticMoveLineRepository analyticMoveLineRepository = Beans.get(AnalyticMoveLineRepository.class);
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        invoiceLine.setProject(invoice.getProject());
        for (AnalyticMoveLine analyticMoveLine : invoiceLine.getAnalyticMoveLineList()) {
            analyticMoveLine.setProject(invoice.getProject());
            analyticMoveLineRepository.save(analyticMoveLine);
        }
    }
    return invoice;
}
Also used : AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Transactional(com.google.inject.persist.Transactional)

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