Search in sources :

Example 41 with Currency

use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.

the class InvoiceLineServiceImpl method getUnitPrice.

/**
 * A function used to get the unit price of an invoice line, either in ati or wt
 *
 * @param invoice the invoice containing the invoice line
 * @param invoiceLine
 * @param taxLine the tax line applied to the unit price
 * @param isPurchase
 * @param resultInAti whether or not you want the result unit price in ati
 * @return the unit price of the invoice line
 * @throws AxelorException
 */
private BigDecimal getUnitPrice(Invoice invoice, InvoiceLine invoiceLine, TaxLine taxLine, boolean isPurchase, boolean resultInAti) throws AxelorException {
    Product product = invoiceLine.getProduct();
    BigDecimal price = null;
    Currency productCurrency;
    if (isPurchase) {
        price = (BigDecimal) productCompanyService.get(product, "purchasePrice", invoice.getCompany());
        productCurrency = (Currency) productCompanyService.get(product, "purchaseCurrency", invoice.getCompany());
    } else {
        price = (BigDecimal) productCompanyService.get(product, "salePrice", invoice.getCompany());
        productCurrency = (Currency) productCompanyService.get(product, "saleCurrency", invoice.getCompany());
    }
    if ((Boolean) productCompanyService.get(product, "inAti", invoice.getCompany()) != resultInAti) {
        price = this.convertUnitPrice((Boolean) productCompanyService.get(product, "inAti", invoice.getCompany()), taxLine, price);
    }
    return currencyService.getAmountCurrencyConvertedAtDate(productCurrency, invoice.getCurrency(), price, invoice.getInvoiceDate()).setScale(appAccountService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
Also used : Currency(com.axelor.apps.base.db.Currency) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal)

Aggregations

Currency (com.axelor.apps.base.db.Currency)41 Company (com.axelor.apps.base.db.Company)19 BigDecimal (java.math.BigDecimal)19 AxelorException (com.axelor.exception.AxelorException)17 Partner (com.axelor.apps.base.db.Partner)14 ArrayList (java.util.ArrayList)12 List (java.util.List)10 Invoice (com.axelor.apps.account.db.Invoice)9 PaymentMode (com.axelor.apps.account.db.PaymentMode)9 PriceList (com.axelor.apps.base.db.PriceList)9 Map (java.util.Map)9 SaleOrder (com.axelor.apps.sale.db.SaleOrder)8 LocalDate (java.time.LocalDate)8 BankDetails (com.axelor.apps.base.db.BankDetails)7 Wizard (com.axelor.apps.base.db.Wizard)7 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)7 Product (com.axelor.apps.base.db.Product)6 Transactional (com.google.inject.persist.Transactional)6 PaymentCondition (com.axelor.apps.account.db.PaymentCondition)4 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)4