Search in sources :

Example 6 with TaxEquiv

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

the class PurchaseOrderLineTaxService method createsPurchaseOrderLineTax.

/**
 * Créer les lignes de TVA de la commande. La création des lignes de TVA se basent sur les lignes
 * de commande.
 *
 * @param purchaseOrder La commande.
 * @param purchaseOrderLineList Les lignes de commandes.
 * @return La liste des lignes de TVA de la commande.
 */
public List<PurchaseOrderLineTax> createsPurchaseOrderLineTax(PurchaseOrder purchaseOrder, List<PurchaseOrderLine> purchaseOrderLineList) {
    List<PurchaseOrderLineTax> purchaseOrderLineTaxList = new ArrayList<PurchaseOrderLineTax>();
    Map<TaxLine, PurchaseOrderLineTax> map = new HashMap<TaxLine, PurchaseOrderLineTax>();
    if (purchaseOrderLineList != null && !purchaseOrderLineList.isEmpty()) {
        LOG.debug("Création des lignes de tva pour les lignes de commande.");
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            TaxLine taxLine = purchaseOrderLine.getTaxLine();
            TaxEquiv taxEquiv = purchaseOrderLine.getTaxEquiv();
            TaxLine taxLineRC = (taxEquiv != null && taxEquiv.getReverseCharge() && taxEquiv.getReverseChargeTax() != null) ? taxEquiv.getReverseChargeTax().getActiveTaxLine() : null;
            if (taxLine != null) {
                LOG.debug("TVA {}", taxLine);
                if (map.containsKey(taxLine)) {
                    PurchaseOrderLineTax purchaseOrderLineVat = map.get(taxLine);
                    purchaseOrderLineVat.setExTaxBase(purchaseOrderLineVat.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
                    purchaseOrderLineVat.setReverseCharged(false);
                } else {
                    PurchaseOrderLineTax purchaseOrderLineTax = new PurchaseOrderLineTax();
                    purchaseOrderLineTax.setPurchaseOrder(purchaseOrder);
                    purchaseOrderLineTax.setExTaxBase(purchaseOrderLine.getExTaxTotal());
                    purchaseOrderLineTax.setReverseCharged(false);
                    purchaseOrderLineTax.setTaxLine(taxLine);
                    map.put(taxLine, purchaseOrderLineTax);
                }
            }
            if (taxLineRC != null) {
                LOG.debug("TVA {}", taxLineRC);
                if (map.containsKey(taxLineRC)) {
                    PurchaseOrderLineTax purchaseOrderLineRC = map.get(taxEquiv.getReverseChargeTax().getActiveTaxLine());
                    purchaseOrderLineRC.setExTaxBase(purchaseOrderLineRC.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
                    purchaseOrderLineRC.setReverseCharged(true);
                } else {
                    PurchaseOrderLineTax purchaseOrderLineTaxRC = new PurchaseOrderLineTax();
                    purchaseOrderLineTaxRC.setPurchaseOrder(purchaseOrder);
                    purchaseOrderLineTaxRC.setExTaxBase(purchaseOrderLine.getExTaxTotal());
                    purchaseOrderLineTaxRC.setReverseCharged(true);
                    purchaseOrderLineTaxRC.setTaxLine(taxLineRC);
                    map.put(taxLineRC, purchaseOrderLineTaxRC);
                }
            }
        }
    }
    for (PurchaseOrderLineTax purchaseOrderLineTax : map.values()) {
        // Dans la devise de la commande
        BigDecimal exTaxBase = (purchaseOrderLineTax.getReverseCharged()) ? purchaseOrderLineTax.getExTaxBase().negate() : purchaseOrderLineTax.getExTaxBase();
        BigDecimal taxTotal = BigDecimal.ZERO;
        if (purchaseOrderLineTax.getTaxLine() != null)
            taxTotal = purchaseOrderToolService.computeAmount(exTaxBase, purchaseOrderLineTax.getTaxLine().getValue());
        purchaseOrderLineTax.setTaxTotal(taxTotal);
        purchaseOrderLineTax.setInTaxTotal(purchaseOrderLineTax.getExTaxBase().add(taxTotal));
        purchaseOrderLineTaxList.add(purchaseOrderLineTax);
        LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", new Object[] { purchaseOrderLineTax.getTaxTotal(), purchaseOrderLineTax.getInTaxTotal() });
    }
    return purchaseOrderLineTaxList;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) PurchaseOrderLineTax(com.axelor.apps.purchase.db.PurchaseOrderLineTax) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 7 with TaxEquiv

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

the class InvoiceLineServiceImpl method fillPriceAndAccount.

@Override
public Map<String, Object> fillPriceAndAccount(Invoice invoice, InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
    Map<String, Object> productInformation = resetProductInformation(invoice);
    Product product = invoiceLine.getProduct();
    TaxLine taxLine = null;
    Company company = invoice.getCompany();
    FiscalPosition fiscalPosition = invoice.getPartner().getFiscalPosition();
    try {
        taxLine = this.getTaxLine(invoice, invoiceLine, isPurchase);
        invoiceLine.setTaxLine(taxLine);
        productInformation.put("taxLine", taxLine);
        productInformation.put("taxRate", taxLine.getValue());
        productInformation.put("taxCode", taxLine.getTax().getCode());
        TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(product, company, fiscalPosition, isPurchase);
        productInformation.put("taxEquiv", taxEquiv);
        Account account = accountManagementAccountService.getProductAccount(product, company, fiscalPosition, isPurchase, invoiceLine.getFixedAssets());
        productInformation.put("account", account);
    } catch (AxelorException e) {
        productInformation.put("error", e.getMessage());
    }
    BigDecimal price = this.getExTaxUnitPrice(invoice, invoiceLine, taxLine, isPurchase);
    BigDecimal inTaxPrice = this.getInTaxUnitPrice(invoice, invoiceLine, taxLine, isPurchase);
    productInformation.put("price", price);
    productInformation.put("inTaxPrice", inTaxPrice);
    productInformation.putAll(this.getDiscount(invoice, invoiceLine, product.getInAti() ? inTaxPrice : price));
    productInformation.put("productName", invoiceLine.getProduct().getName());
    return productInformation;
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) Product(com.axelor.apps.base.db.Product) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 8 with TaxEquiv

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

the class InvoiceLineGenerator method createInvoiceLine.

/**
 * @return
 * @throws AxelorException
 */
protected InvoiceLine createInvoiceLine() throws AxelorException {
    InvoiceLine invoiceLine = new InvoiceLine();
    boolean isPurchase = InvoiceToolService.isPurchase(invoice);
    Partner partner = invoice.getPartner();
    Company company = invoice.getCompany();
    invoiceLine.setInvoice(invoice);
    invoiceLine.setProduct(product);
    invoiceLine.setProductName(productName);
    if (product != null) {
        invoiceLine.setProductCode((String) productCompanyService.get(product, "code", company));
        Account account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, invoiceLine.getFixedAssets());
        invoiceLine.setAccount(account);
    }
    invoiceLine.setDescription(description);
    invoiceLine.setPrice(price);
    invoiceLine.setInTaxPrice(inTaxPrice);
    invoiceLine.setPriceDiscounted(priceDiscounted);
    invoiceLine.setQty(qty);
    invoiceLine.setUnit(unit);
    invoiceLine.setTypeSelect(typeSelect);
    if (taxLine == null) {
        this.determineTaxLine();
    }
    if (product != null) {
        TaxEquiv taxEquiv = Beans.get(AccountManagementService.class).getProductTaxEquiv(product, company, partner.getFiscalPosition(), isPurchase);
        invoiceLine.setTaxEquiv(taxEquiv);
    }
    invoiceLine.setTaxLine(taxLine);
    if (taxLine != null) {
        invoiceLine.setTaxRate(taxLine.getValue());
        invoiceLine.setTaxCode(taxLine.getTax().getCode());
    }
    if ((exTaxTotal == null || inTaxTotal == null)) {
        this.computeTotal();
    }
    invoiceLine.setExTaxTotal(exTaxTotal);
    invoiceLine.setInTaxTotal(inTaxTotal);
    this.computeCompanyTotal(invoiceLine);
    invoiceLine.setSequence(sequence);
    invoiceLine.setDiscountTypeSelect(discountTypeSelect);
    invoiceLine.setDiscountAmount(discountAmount);
    return invoiceLine;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Partner(com.axelor.apps.base.db.Partner) TaxEquiv(com.axelor.apps.account.db.TaxEquiv)

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