Search in sources :

Example 1 with TaxEquiv

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

the class TaxInvoiceLine method createInvoiceLineTaxes.

protected void createInvoiceLineTaxes(InvoiceLine invoiceLine, Map<TaxLine, InvoiceLineTax> map) {
    TaxLine taxLine = invoiceLine.getTaxLine();
    TaxEquiv taxEquiv = invoiceLine.getTaxEquiv();
    TaxLine taxLineRC = (taxEquiv != null && taxEquiv.getReverseCharge() && taxEquiv.getReverseChargeTax() != null) ? taxEquiv.getReverseChargeTax().getActiveTaxLine() : null;
    if (taxLine != null) {
        createOrUpdateInvoiceLineTax(invoiceLine, taxLine, map);
    }
    if (taxLineRC != null) {
        createOrUpdateInvoiceLineTaxRc(invoiceLine, taxLineRC, taxEquiv, map);
    }
}
Also used : TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 2 with TaxEquiv

use of com.axelor.apps.account.db.TaxEquiv 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 3 with TaxEquiv

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

the class PurchaseOrderLineServiceImpl method fill.

public PurchaseOrderLine fill(PurchaseOrderLine line, PurchaseOrder purchaseOrder) throws AxelorException {
    Preconditions.checkNotNull(line, I18n.get("The line cannot be null."));
    Preconditions.checkNotNull(purchaseOrder, I18n.get("You need a purchase order associated to line."));
    Partner supplierPartner = purchaseOrder.getSupplierPartner();
    Product product = line.getProduct();
    String[] productSupplierInfos = getProductSupplierInfos(purchaseOrder, line);
    if (!line.getEnableFreezeFields()) {
        line.setProductName(productSupplierInfos[0]);
        line.setQty(getQty(purchaseOrder, line));
    }
    line.setProductCode(productSupplierInfos[1]);
    line.setUnit(getPurchaseUnit(line));
    if (appPurchaseService.getAppPurchase().getIsEnabledProductDescriptionCopy()) {
        line.setDescription(product.getDescription());
    }
    TaxLine taxLine = getTaxLine(purchaseOrder, line);
    line.setTaxLine(taxLine);
    BigDecimal price = getExTaxUnitPrice(purchaseOrder, line, taxLine);
    BigDecimal inTaxPrice = getInTaxUnitPrice(purchaseOrder, line, taxLine);
    if (price == null || inTaxPrice == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PURCHASE_ORDER_LINE_NO_SUPPLIER_CATALOG));
    }
    TaxEquiv taxEquiv = accountManagementService.getProductTaxEquiv(product, purchaseOrder.getCompany(), supplierPartner.getFiscalPosition(), true);
    line.setTaxEquiv(taxEquiv);
    Map<String, Object> discounts = getDiscountsFromPriceLists(purchaseOrder, line, purchaseOrder.getInAti() ? inTaxPrice : price);
    if (discounts != null) {
        if (discounts.get("price") != null) {
            BigDecimal discountPrice = (BigDecimal) discounts.get("price");
            if (product.getInAti()) {
                inTaxPrice = discountPrice;
                price = this.convertUnitPrice(true, line.getTaxLine(), discountPrice);
            } else {
                price = discountPrice;
                inTaxPrice = this.convertUnitPrice(false, line.getTaxLine(), discountPrice);
            }
        }
        if (product.getInAti() != purchaseOrder.getInAti() && (Integer) discounts.get("discountTypeSelect") != PriceListLineRepository.AMOUNT_TYPE_PERCENT) {
            line.setDiscountAmount(this.convertUnitPrice(product.getInAti(), line.getTaxLine(), (BigDecimal) discounts.get("discountAmount")));
        } else {
            line.setDiscountAmount((BigDecimal) discounts.get("discountAmount"));
        }
        line.setDiscountTypeSelect((Integer) discounts.get("discountTypeSelect"));
    }
    if (!line.getEnableFreezeFields()) {
        line.setPrice(price);
    }
    line.setInTaxPrice(inTaxPrice);
    line.setMaxPurchasePrice(getPurchaseMaxPrice(purchaseOrder, line));
    return line;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) Partner(com.axelor.apps.base.db.Partner) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 4 with TaxEquiv

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

the class SaleOrderLineServiceImpl method fillTaxInformation.

protected void fillTaxInformation(SaleOrderLine saleOrderLine, SaleOrder saleOrder) throws AxelorException {
    if (saleOrder.getClientPartner() != null) {
        TaxLine taxLine = this.getTaxLine(saleOrder, saleOrderLine);
        saleOrderLine.setTaxLine(taxLine);
        FiscalPosition fiscalPosition = saleOrder.getClientPartner().getFiscalPosition();
        TaxEquiv taxEquiv = accountManagementService.getProductTaxEquiv(saleOrderLine.getProduct(), saleOrder.getCompany(), fiscalPosition, false);
        saleOrderLine.setTaxEquiv(taxEquiv);
    } else {
        saleOrderLine.setTaxLine(null);
        saleOrderLine.setTaxEquiv(null);
    }
}
Also used : FiscalPosition(com.axelor.apps.account.db.FiscalPosition) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 5 with TaxEquiv

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

the class SaleOrderLineTaxService method createsSaleOrderLineTax.

/**
 * Créer les lignes de TVA du devis. La création des lignes de TVA se basent sur les lignes de
 * devis ainsi que les sous-lignes de devis de celles-ci. Si une ligne de devis comporte des
 * sous-lignes de devis, alors on se base uniquement sur celles-ci.
 *
 * @param invoice La facture.
 * @param invoiceLines Les lignes de facture.
 * @param invoiceLineTaxes Les lignes des taxes de la facture.
 * @return La liste des lignes de taxe de la facture.
 */
public List<SaleOrderLineTax> createsSaleOrderLineTax(SaleOrder saleOrder, List<SaleOrderLine> saleOrderLineList) {
    List<SaleOrderLineTax> saleOrderLineTaxList = new ArrayList<SaleOrderLineTax>();
    Map<TaxLine, SaleOrderLineTax> map = new HashMap<TaxLine, SaleOrderLineTax>();
    Set<String> specificNotes = new HashSet<String>();
    boolean customerSpecificNote = false;
    if (saleOrder.getClientPartner().getFiscalPosition() != null) {
        customerSpecificNote = saleOrder.getClientPartner().getFiscalPosition().getCustomerSpecificNote();
    }
    if (saleOrderLineList != null && !saleOrderLineList.isEmpty()) {
        LOG.debug("Création des lignes de tva pour les lignes de factures.");
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            TaxLine taxLine = saleOrderLine.getTaxLine();
            if (taxLine != null) {
                LOG.debug("Tax {}", taxLine);
                if (map.containsKey(taxLine)) {
                    SaleOrderLineTax saleOrderLineTax = map.get(taxLine);
                    saleOrderLineTax.setExTaxBase(saleOrderLineTax.getExTaxBase().add(saleOrderLine.getExTaxTotal()));
                } else {
                    SaleOrderLineTax saleOrderLineTax = new SaleOrderLineTax();
                    saleOrderLineTax.setSaleOrder(saleOrder);
                    saleOrderLineTax.setExTaxBase(saleOrderLine.getExTaxTotal());
                    saleOrderLineTax.setTaxLine(taxLine);
                    map.put(taxLine, saleOrderLineTax);
                }
            }
            if (!customerSpecificNote) {
                TaxEquiv taxEquiv = saleOrderLine.getTaxEquiv();
                if (taxEquiv != null && taxEquiv.getSpecificNote() != null) {
                    specificNotes.add(taxEquiv.getSpecificNote());
                }
            }
        }
    }
    for (SaleOrderLineTax saleOrderLineTax : map.values()) {
        // Dans la devise de la facture
        BigDecimal exTaxBase = saleOrderLineTax.getExTaxBase();
        BigDecimal taxTotal = BigDecimal.ZERO;
        if (saleOrderLineTax.getTaxLine() != null) {
            taxTotal = saleOrderToolService.computeAmount(exTaxBase, saleOrderLineTax.getTaxLine().getValue());
            saleOrderLineTax.setTaxTotal(taxTotal);
        }
        saleOrderLineTax.setInTaxTotal(exTaxBase.add(taxTotal));
        saleOrderLineTaxList.add(saleOrderLineTax);
        LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", new Object[] { saleOrderLineTax.getTaxTotal(), saleOrderLineTax.getInTaxTotal() });
    }
    if (!customerSpecificNote) {
        saleOrder.setSpecificNotes(Joiner.on('\n').join(specificNotes));
    } else {
        saleOrder.setSpecificNotes(saleOrder.getClientPartner().getSpecificTaxNote());
    }
    return saleOrderLineTaxList;
}
Also used : SaleOrderLineTax(com.axelor.apps.sale.db.SaleOrderLineTax) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) HashSet(java.util.HashSet)

Aggregations

TaxEquiv (com.axelor.apps.account.db.TaxEquiv)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 BigDecimal (java.math.BigDecimal)4 Account (com.axelor.apps.account.db.Account)3 Partner (com.axelor.apps.base.db.Partner)3 FiscalPosition (com.axelor.apps.account.db.FiscalPosition)2 Company (com.axelor.apps.base.db.Company)2 Product (com.axelor.apps.base.db.Product)2 AxelorException (com.axelor.exception.AxelorException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 AccountManagementAccountService (com.axelor.apps.account.service.AccountManagementAccountService)1 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)1 AccountManagementService (com.axelor.apps.base.service.tax.AccountManagementService)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 PurchaseOrderLineTax (com.axelor.apps.purchase.db.PurchaseOrderLineTax)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1