Search in sources :

Example 21 with TaxLine

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

the class SaleOrderLineController method updatePrice.

/**
 * Update the ex. tax unit price of an invoice line from its in. tax unit price.
 *
 * @param request
 * @param response
 */
public void updatePrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    try {
        BigDecimal inTaxPrice = saleOrderLine.getInTaxPrice();
        TaxLine taxLine = saleOrderLine.getTaxLine();
        response.setValue("price", Beans.get(SaleOrderLineService.class).convertUnitPrice(true, taxLine, inTaxPrice));
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 22 with TaxLine

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

use of com.axelor.apps.account.db.TaxLine 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)

Example 24 with TaxLine

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

the class ContractServiceImpl method generate.

public InvoiceLine generate(Invoice invoice, ContractLine line) throws AxelorException {
    BigDecimal inTaxPriceComputed = invoiceLineService.convertUnitPrice(false, line.getTaxLine(), line.getPrice());
    InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, line.getProduct(), line.getProductName(), line.getPrice(), inTaxPriceComputed, invoice.getInAti() ? inTaxPriceComputed : line.getPrice(), line.getDescription(), line.getQty(), line.getUnit(), line.getTaxLine(), line.getSequence(), BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, line.getExTaxTotal(), line.getInTaxTotal(), false) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    InvoiceLine invoiceLine = invoiceLineGenerator.creates().get(0);
    FiscalPositionAccountService fiscalPositionAccountService = Beans.get(FiscalPositionAccountService.class);
    FiscalPosition fiscalPosition = line.getFiscalPosition();
    Account currentAccount = invoiceLine.getAccount();
    Account replacedAccount = fiscalPositionAccountService.getAccount(fiscalPosition, currentAccount);
    boolean isPurchase = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice) == PriceListRepository.TYPE_PURCHASE;
    TaxLine taxLine = Beans.get(AccountManagementService.class).getTaxLine(appBaseService.getTodayDate(invoice.getCompany()), invoiceLine.getProduct(), invoice.getCompany(), fiscalPosition, isPurchase);
    invoiceLine.setTaxLine(taxLine);
    invoiceLine.setAccount(replacedAccount);
    if (line.getAnalyticDistributionTemplate() != null) {
        invoiceLine.setAnalyticDistributionTemplate(line.getAnalyticDistributionTemplate());
        this.copyAnalyticMoveLines(line.getAnalyticMoveLineList(), invoiceLine);
    }
    invoice.addInvoiceLineListItem(invoiceLine);
    return Beans.get(InvoiceLineRepository.class).save(invoiceLine);
}
Also used : FiscalPositionAccountService(com.axelor.apps.account.service.FiscalPositionAccountService) Account(com.axelor.apps.account.db.Account) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 25 with TaxLine

use of com.axelor.apps.account.db.TaxLine 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)

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