Search in sources :

Example 16 with TaxLine

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

the class PurchaseOrderLineController 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();
    PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
    try {
        BigDecimal inTaxPrice = purchaseOrderLine.getInTaxPrice();
        TaxLine taxLine = purchaseOrderLine.getTaxLine();
        response.setValue("price", Beans.get(PurchaseOrderLineService.class).convertUnitPrice(true, taxLine, inTaxPrice));
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 17 with TaxLine

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

the class PurchaseOrderLineServiceImpl method getPurchaseMaxPrice.

@Override
public BigDecimal getPurchaseMaxPrice(PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
    try {
        Product product = purchaseOrderLine.getProduct();
        if (product == null || !((Boolean) productCompanyService.get(product, "sellable", purchaseOrder.getCompany()))) {
            return BigDecimal.ZERO;
        }
        TaxLine saleTaxLine = accountManagementService.getTaxLine(purchaseOrder.getOrderDate(), purchaseOrderLine.getProduct(), purchaseOrder.getCompany(), purchaseOrder.getSupplierPartner().getFiscalPosition(), false);
        BigDecimal price;
        if (purchaseOrder.getInAti() != (Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany())) {
            price = this.convertUnitPrice((Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany()), saleTaxLine, ((BigDecimal) productCompanyService.get(product, "salePrice", purchaseOrder.getCompany())).divide(product.getManagPriceCoef().signum() == 0 ? BigDecimal.ONE : product.getManagPriceCoef(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP));
        } else {
            price = ((BigDecimal) productCompanyService.get(product, "salePrice", purchaseOrder.getCompany())).divide(product.getManagPriceCoef().signum() == 0 ? BigDecimal.ONE : product.getManagPriceCoef(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
        }
        return currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "saleCurrency", purchaseOrder.getCompany()), purchaseOrder.getCurrency(), price, purchaseOrder.getOrderDate()).setScale(appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
    } catch (Exception e) {
        return BigDecimal.ZERO;
    }
}
Also used : Currency(com.axelor.apps.base.db.Currency) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 18 with TaxLine

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

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

the class AccountingCutOffServiceImpl method generateTaxMoveLine.

protected void generateTaxMoveLine(Move move, MoveLine productMoveLine, String origin, boolean isPurchase, boolean isFixedAssets, String moveDescription) throws AxelorException {
    TaxLine taxLine = productMoveLine.getTaxLine();
    Tax tax = taxLine.getTax();
    Account taxAccount = taxAccountService.getAccount(tax, move.getCompany(), isPurchase, isFixedAssets);
    BigDecimal currencyTaxAmount = InvoiceLineManagement.computeAmount(productMoveLine.getCurrencyAmount(), taxLine.getValue());
    MoveLine taxMoveLine = moveLineService.createMoveLine(move, move.getPartner(), taxAccount, currencyTaxAmount, productMoveLine.getDebit().compareTo(BigDecimal.ZERO) == 1, productMoveLine.getOriginDate(), ++counter, origin, moveDescription);
    taxMoveLine.setDate(move.getDate());
    taxMoveLine.setDueDate(move.getDate());
    move.addMoveLineListItem(taxMoveLine);
}
Also used : Account(com.axelor.apps.account.db.Account) MoveLine(com.axelor.apps.account.db.MoveLine) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Tax(com.axelor.apps.account.db.Tax) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 20 with TaxLine

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

the class SaleOrderInvoiceServiceImpl method createInvoiceLinesFromTax.

@Override
public List<InvoiceLine> createInvoiceLinesFromTax(Invoice invoice, List<SaleOrderLineTax> taxLineList, Product invoicingProduct, BigDecimal percentToInvoice) throws AxelorException {
    List<InvoiceLine> createdInvoiceLineList = new ArrayList<>();
    if (taxLineList != null) {
        for (SaleOrderLineTax saleOrderLineTax : taxLineList) {
            BigDecimal lineAmountToInvoice = percentToInvoice.multiply(saleOrderLineTax.getExTaxBase()).divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
            TaxLine taxLine = saleOrderLineTax.getTaxLine();
            BigDecimal lineAmountToInvoiceInclTax = (taxLine != null) ? lineAmountToInvoice.add(lineAmountToInvoice.multiply(taxLine.getValue())) : lineAmountToInvoice;
            InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, invoicingProduct, invoicingProduct.getName(), lineAmountToInvoice, lineAmountToInvoiceInclTax, invoice.getInAti() ? lineAmountToInvoiceInclTax : lineAmountToInvoice, invoicingProduct.getDescription(), BigDecimal.ONE, invoicingProduct.getUnit(), taxLine, InvoiceLineGenerator.DEFAULT_SEQUENCE, BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, lineAmountToInvoice, null, false) {

                @Override
                public List<InvoiceLine> creates() throws AxelorException {
                    InvoiceLine invoiceLine = this.createInvoiceLine();
                    List<InvoiceLine> invoiceLines = new ArrayList<>();
                    invoiceLines.add(invoiceLine);
                    return invoiceLines;
                }
            };
            List<InvoiceLine> invoiceOneLineList = invoiceLineGenerator.creates();
            // link to the created invoice line the first line of the sale order.
            for (InvoiceLine invoiceLine : invoiceOneLineList) {
                SaleOrderLine saleOrderLine = saleOrderLineTax.getSaleOrder().getSaleOrderLineList().get(0);
                invoiceLine.setSaleOrderLine(saleOrderLine);
            }
            createdInvoiceLineList.addAll(invoiceOneLineList);
        }
    }
    return createdInvoiceLineList;
}
Also used : SaleOrderLineTax(com.axelor.apps.sale.db.SaleOrderLineTax) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) 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