Search in sources :

Example 6 with TaxLine

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

the class ImportMoveLine method importMoveLine.

@Transactional(rollbackOn = Exception.class)
public Object importMoveLine(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof MoveLine;
    MoveLine moveLine = (MoveLine) bean;
    String accountId = (String) values.get("account_importId");
    Account account = getAccount(accountId);
    if (account != null) {
        moveLine.setAccountCode(account.getCode());
        moveLine.setAccountName(account.getName());
    } else {
        moveLine.setAccountCode((String) values.get("accountCode"));
        moveLine.setAccountName((String) values.get("accountName"));
    }
    String taxLineId = (String) values.get("taxLine_importId");
    TaxLine taxLine = getTaxLine(taxLineId);
    if (taxLine != null) {
        moveLine.setTaxCode(taxLine.getTax().getCode());
        moveLine.setTaxRate(taxLine.getValue());
    } else {
        moveLine.setTaxCode((String) values.get("taxCode"));
        moveLine.setTaxRate(new BigDecimal((String) values.get("taxRate")));
    }
    String partnerId = (String) values.get("partner_importId");
    Partner partner = getPartner(partnerId);
    if (partner != null) {
        moveLine.setPartnerSeq(partner.getPartnerSeq());
        moveLine.setPartnerFullName(partner.getFullName());
    } else {
        moveLine.setPartnerSeq((String) values.get("partnerSeq"));
        moveLine.setPartnerFullName((String) values.get("partnerFullName"));
    }
    moveLineRepository.save(moveLine);
    return moveLine;
}
Also used : Account(com.axelor.apps.account.db.Account) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Transactional(com.google.inject.persist.Transactional)

Example 7 with TaxLine

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

the class PurchaseOrderStockServiceImpl method createProductStockMoveLine.

protected StockMoveLine createProductStockMoveLine(PurchaseOrderLine purchaseOrderLine, BigDecimal qty, StockMove stockMove) throws AxelorException {
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    Product product = purchaseOrderLine.getProduct();
    Unit unit = product.getUnit();
    BigDecimal priceDiscounted = purchaseOrderLine.getPriceDiscounted();
    BigDecimal companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal();
    if (purchaseOrderLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
        companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal().divide(purchaseOrderLine.getQty(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
    }
    if (unit != null && !unit.equals(purchaseOrderLine.getUnit())) {
        qty = unitConversionService.convert(purchaseOrderLine.getUnit(), unit, qty, qty.scale(), product);
        priceDiscounted = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), product);
        companyUnitPriceUntaxed = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), companyUnitPriceUntaxed, appBaseService.getNbDecimalDigitForUnitPrice(), product);
    }
    BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), qty);
    BigDecimal companyPurchasePrice = priceDiscounted;
    priceDiscounted = priceDiscounted.multiply(shippingCoef);
    companyUnitPriceUntaxed = companyUnitPriceUntaxed.multiply(shippingCoef);
    BigDecimal taxRate = BigDecimal.ZERO;
    TaxLine taxLine = purchaseOrderLine.getTaxLine();
    if (taxLine != null) {
        taxRate = taxLine.getValue();
    }
    if (purchaseOrderLine.getReceiptState() == 0) {
        purchaseOrderLine.setReceiptState(PurchaseOrderLineRepository.RECEIPT_STATE_NOT_RECEIVED);
    }
    return stockMoveLineServiceSupplychain.createStockMoveLine(product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), qty, BigDecimal.ZERO, priceDiscounted, companyUnitPriceUntaxed, companyPurchasePrice, unit, stockMove, StockMoveLineService.TYPE_PURCHASES, purchaseOrder.getInAti(), taxRate, null, purchaseOrderLine);
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 8 with TaxLine

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

the class IntercoServiceImpl method createIntercoInvoiceLine.

protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
    AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
    InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
    Invoice intercoInvoice = invoiceLine.getInvoice();
    Partner partner = intercoInvoice.getPartner();
    if (intercoInvoice.getCompany() != null) {
        Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
        invoiceLine.setAccount(account);
        TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
        invoiceLine.setTaxLine(taxLine);
        invoiceLine.setTaxRate(taxLine.getValue());
        invoiceLine.setTaxCode(taxLine.getTax().getCode());
        TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
        invoiceLine.setTaxEquiv(taxEquiv);
        invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
        invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
        if (invoiceLine.getAnalyticDistributionTemplate() != null) {
            invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
            List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
            analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
            invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
        }
    }
    return invoiceLine;
}
Also used : Account(com.axelor.apps.account.db.Account) Invoice(com.axelor.apps.account.db.Invoice) AccountManagementAccountService(com.axelor.apps.account.service.AccountManagementAccountService) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) Partner(com.axelor.apps.base.db.Partner) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TaxLine(com.axelor.apps.account.db.TaxLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 9 with TaxLine

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

the class AccountingCutOffServiceImpl method generateProductMoveLine.

protected MoveLine generateProductMoveLine(Move move, StockMoveLine stockMoveLine, String origin, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean isReverse, LocalDate originDate) throws AxelorException {
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
    Company company = move.getCompany();
    LocalDate moveDate = move.getDate();
    Partner partner = move.getPartner();
    boolean isFixedAssets = false;
    BigDecimal amountInCurrency = null;
    BigDecimal totalQty = null;
    BigDecimal notInvoicedQty = null;
    if (isPurchase && purchaseOrderLine != null) {
        totalQty = purchaseOrderLine.getQty();
        notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
        isFixedAssets = purchaseOrderLine.getFixedAssets();
        if (ati && !recoveredTax) {
            amountInCurrency = purchaseOrderLine.getInTaxTotal();
        } else {
            amountInCurrency = purchaseOrderLine.getExTaxTotal();
        }
    }
    if (!isPurchase && saleOrderLine != null) {
        totalQty = saleOrderLine.getQty();
        notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), saleOrderLine.getProduct());
        if (ati) {
            amountInCurrency = saleOrderLine.getInTaxTotal();
        } else {
            amountInCurrency = saleOrderLine.getExTaxTotal();
        }
    }
    if (totalQty == null || BigDecimal.ZERO.compareTo(totalQty) == 0) {
        return null;
    }
    BigDecimal qtyRate = notInvoicedQty.divide(totalQty, 10, RoundingMode.HALF_UP);
    amountInCurrency = amountInCurrency.multiply(qtyRate).setScale(2, RoundingMode.HALF_UP);
    if (amountInCurrency == null || amountInCurrency.compareTo(BigDecimal.ZERO) == 0) {
        return null;
    }
    Product product = stockMoveLine.getProduct();
    Account account = accountManagementAccountService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, isFixedAssets);
    boolean isDebit = false;
    if ((isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == 1) || !isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == -1) {
        isDebit = true;
    }
    if (isReverse) {
        isDebit = !isDebit;
    }
    MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, amountInCurrency, isDebit, originDate, ++counter, origin, moveDescription);
    moveLine.setDate(moveDate);
    moveLine.setDueDate(moveDate);
    getAndComputeAnalyticDistribution(product, move, moveLine);
    move.addMoveLineListItem(moveLine);
    if (recoveredTax) {
        TaxLine taxLine = accountManagementAccountService.getTaxLine(originDate, product, company, partner.getFiscalPosition(), isPurchase);
        if (taxLine != null) {
            moveLine.setTaxLine(taxLine);
            moveLine.setTaxRate(taxLine.getValue());
            moveLine.setTaxCode(taxLine.getTax().getCode());
            if (taxLine.getValue().compareTo(BigDecimal.ZERO) != 0) {
                generateTaxMoveLine(move, moveLine, origin, isPurchase, isFixedAssets, moveDescription);
            }
        }
    }
    return moveLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) MoveLine(com.axelor.apps.account.db.MoveLine) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) LocalDate(java.time.LocalDate) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 10 with TaxLine

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

the class MoveLineServiceImpl method createMoveLines.

/**
 * Créer les lignes d'écritures comptables d'une facture.
 *
 * @param invoice
 * @param move
 * @param consolidate
 * @return
 */
@Override
public List<MoveLine> createMoveLines(Invoice invoice, Move move, Company company, Partner partner, Account partnerAccount, boolean consolidate, boolean isPurchase, boolean isDebitCustomer) throws AxelorException {
    log.debug("Création des lignes d'écriture comptable de la facture/l'avoir {}", invoice.getInvoiceId());
    List<MoveLine> moveLines = new ArrayList<MoveLine>();
    Set<AnalyticAccount> analyticAccounts = new HashSet<AnalyticAccount>();
    int moveLineId = 1;
    if (partner == null) {
        throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.MOVE_LINE_1), invoice.getInvoiceId());
    }
    if (partnerAccount == null) {
        throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.MOVE_LINE_2), invoice.getInvoiceId());
    }
    String origin = invoice.getInvoiceId();
    if (InvoiceToolService.isPurchase(invoice)) {
        origin = invoice.getSupplierInvoiceNb();
    }
    // Creation of partner move line
    MoveLine moveLine1 = this.createMoveLine(move, partner, partnerAccount, invoice.getInTaxTotal(), invoice.getCompanyInTaxTotal(), null, isDebitCustomer, invoice.getInvoiceDate(), invoice.getDueDate(), invoice.getOriginDate(), moveLineId++, origin, null);
    moveLines.add(moveLine1);
    AnalyticMoveLineRepository analyticMoveLineRepository = Beans.get(AnalyticMoveLineRepository.class);
    // Creation of product move lines for each invoice line
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        BigDecimal companyExTaxTotal = invoiceLine.getCompanyExTaxTotal();
        if (companyExTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
            analyticAccounts.clear();
            Account account = invoiceLine.getAccount();
            if (account == null) {
                throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_4), invoiceLine.getName(), company.getName());
            }
            companyExTaxTotal = invoiceLine.getCompanyExTaxTotal();
            log.debug("Traitement de la ligne de facture : compte comptable = {}, montant = {}", new Object[] { account.getName(), companyExTaxTotal });
            if (invoiceLine.getAnalyticDistributionTemplate() == null && (invoiceLine.getAnalyticMoveLineList() == null || invoiceLine.getAnalyticMoveLineList().isEmpty()) && account.getAnalyticDistributionAuthorized() && account.getAnalyticDistributionRequiredOnInvoiceLines()) {
                throw new AxelorException(move, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ANALYTIC_DISTRIBUTION_MISSING), invoiceLine.getName(), company.getName());
            }
            MoveLine moveLine = this.createMoveLine(move, partner, account, invoiceLine.getExTaxTotal(), companyExTaxTotal, null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, invoiceLine.getProductName());
            moveLine.setAnalyticDistributionTemplate(invoiceLine.getAnalyticDistributionTemplate());
            if (invoiceLine.getAnalyticMoveLineList() != null && !invoiceLine.getAnalyticMoveLineList().isEmpty()) {
                for (AnalyticMoveLine invoiceAnalyticMoveLine : invoiceLine.getAnalyticMoveLineList()) {
                    AnalyticMoveLine analyticMoveLine = analyticMoveLineRepository.copy(invoiceAnalyticMoveLine, false);
                    analyticMoveLine.setTypeSelect(AnalyticMoveLineRepository.STATUS_REAL_ACCOUNTING);
                    analyticMoveLine.setInvoiceLine(null);
                    analyticMoveLine.setAccount(moveLine.getAccount());
                    analyticMoveLine.setAccountType(moveLine.getAccount().getAccountType());
                    analyticMoveLineService.updateAnalyticMoveLine(analyticMoveLine, moveLine.getDebit().add(moveLine.getCredit()), moveLine.getDate());
                    moveLine.addAnalyticMoveLineListItem(analyticMoveLine);
                }
            } else {
                generateAnalyticMoveLines(moveLine);
            }
            TaxLine taxLine = invoiceLine.getTaxLine();
            if (taxLine != null) {
                moveLine.setTaxLine(taxLine);
                moveLine.setTaxRate(taxLine.getValue());
                moveLine.setTaxCode(taxLine.getTax().getCode());
            }
            moveLines.add(moveLine);
        }
    }
    // Creation of tax move lines for each invoice line tax
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        BigDecimal companyTaxTotal = invoiceLineTax.getCompanyTaxTotal();
        if (companyTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
            Tax tax = invoiceLineTax.getTaxLine().getTax();
            boolean hasFixedAssets = !invoiceLineTax.getSubTotalOfFixedAssets().equals(BigDecimal.ZERO);
            boolean hasOtherAssets = !invoiceLineTax.getSubTotalExcludingFixedAssets().equals(BigDecimal.ZERO);
            Account account;
            MoveLine moveLine;
            if (hasFixedAssets && invoiceLineTax.getCompanySubTotalOfFixedAssets().compareTo(BigDecimal.ZERO) != 0) {
                account = taxAccountService.getAccount(tax, company, isPurchase, true);
                if (account == null) {
                    throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_6), tax.getName(), company.getName());
                }
                moveLine = this.createMoveLine(move, partner, account, invoiceLineTax.getSubTotalOfFixedAssets(), invoiceLineTax.getCompanySubTotalOfFixedAssets(), null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, null);
                moveLine.setTaxLine(invoiceLineTax.getTaxLine());
                moveLine.setTaxRate(invoiceLineTax.getTaxLine().getValue());
                moveLine.setTaxCode(tax.getCode());
                moveLines.add(moveLine);
            }
            if (hasOtherAssets && invoiceLineTax.getCompanySubTotalExcludingFixedAssets().compareTo(BigDecimal.ZERO) != 0) {
                account = taxAccountService.getAccount(tax, company, isPurchase, false);
                if (account == null) {
                    throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_6), tax.getName(), company.getName());
                }
                moveLine = this.createMoveLine(move, partner, account, invoiceLineTax.getSubTotalExcludingFixedAssets(), invoiceLineTax.getCompanySubTotalExcludingFixedAssets(), null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, null);
                moveLine.setTaxLine(invoiceLineTax.getTaxLine());
                moveLine.setTaxRate(invoiceLineTax.getTaxLine().getValue());
                moveLine.setTaxCode(tax.getCode());
                moveLines.add(moveLine);
            }
        }
    }
    if (consolidate) {
        this.consolidateMoveLines(moveLines);
    }
    return moveLines;
}
Also used : AxelorException(com.axelor.exception.AxelorException) AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) Account(com.axelor.apps.account.db.Account) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) Tax(com.axelor.apps.account.db.Tax) AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) TaxPaymentMoveLine(com.axelor.apps.account.db.TaxPaymentMoveLine) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) HashSet(java.util.HashSet) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Aggregations

TaxLine (com.axelor.apps.account.db.TaxLine)28 BigDecimal (java.math.BigDecimal)25 AxelorException (com.axelor.exception.AxelorException)9 Account (com.axelor.apps.account.db.Account)8 MoveLine (com.axelor.apps.account.db.MoveLine)7 TaxEquiv (com.axelor.apps.account.db.TaxEquiv)7 ArrayList (java.util.ArrayList)7 Context (com.axelor.rpc.Context)6 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 Partner (com.axelor.apps.base.db.Partner)5 Product (com.axelor.apps.base.db.Product)5 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)5 Tax (com.axelor.apps.account.db.Tax)4 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)4 Transactional (com.google.inject.persist.Transactional)4 HashMap (java.util.HashMap)4 FiscalPosition (com.axelor.apps.account.db.FiscalPosition)3 TaxPaymentMoveLine (com.axelor.apps.account.db.TaxPaymentMoveLine)3 Company (com.axelor.apps.base.db.Company)3