Package org.openbravo.financial
Class FinancialUtils
- java.lang.Object
-
- org.openbravo.financial.FinancialUtils
-
public class FinancialUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
PRECISION_COSTING
static String
PRECISION_PRICE
static String
PRECISION_STANDARD
-
Constructor Summary
Constructors Constructor Description FinancialUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static BigDecimal
calculateNetAmtFromGross(String strTaxId, BigDecimal grossAmount, int stdPrecision, BigDecimal alternateAmount)
Calculates the net unit price using the C_GET_NET_AMOUNT_FROM_GROSS stored procedure.static BigDecimal
calculateNetFromGross(String strTaxId, BigDecimal grossAmount, int pricePrecision, BigDecimal alternateAmount, BigDecimal quantity)
Deprecated.static ConversionRate
getConversionRate(Date date, Currency fromCurrency, Currency toCurrency, Organization org, Client client)
Method to get the conversion rate defined at system level.static BigDecimal
getConvertedAmount(BigDecimal amount, Currency curFrom, Currency curTo, Date date, Organization org, String strPrecision)
It callsgetConvertedAmount(BigDecimal, Currency, Currency, Date, Organization, String, List)
with an empty list of conversion rates at document levelstatic BigDecimal
getConvertedAmount(BigDecimal amount, Currency curFrom, Currency curTo, Date date, Organization org, String strPrecision, List<ConversionRateDoc> rateDocs)
Converts an amount.static Currency
getLegalEntityCurrency(Organization organization)
Returns the Currency of a Legal Entity.static org.hibernate.ScrollableResults
getPaymentsWithCredit(String businessPartnerId, String currencyId)
Get all the payment details with available creditstatic ProductPrice
getProductPrice(Product product, Date date, boolean useSalesPriceList)
static ProductPrice
getProductPrice(Product product, Date date, boolean useSalesPriceList, PriceList priceList)
static ProductPrice
getProductPrice(Product product, Date date, boolean useSalesPriceList, PriceList priceList, boolean throwException)
static ProductPrice
getProductPrice(Product product, Date date, boolean useSalesPriceList, PriceList priceList, boolean throwException, boolean usePriceIncludeTax)
Method to get a valid ProductPrice for the given Product.static BigDecimal
getProductStdPrice(Product product, Date date, boolean useSalesPriceList, Currency currency, Organization organization)
static BigDecimal
getProductStdPrice(Product product, Date date, boolean useSalesPriceList, PriceList pricelist, Currency currency, Organization organization)
Calculates the Standard Price of the given Product.
-
-
-
Field Detail
-
PRECISION_STANDARD
public static final String PRECISION_STANDARD
- See Also:
- Constant Field Values
-
PRECISION_COSTING
public static final String PRECISION_COSTING
- See Also:
- Constant Field Values
-
PRECISION_PRICE
public static final String PRECISION_PRICE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getProductStdPrice
public static BigDecimal getProductStdPrice(Product product, Date date, boolean useSalesPriceList, Currency currency, Organization organization) throws OBException
-
getProductStdPrice
public static BigDecimal getProductStdPrice(Product product, Date date, boolean useSalesPriceList, PriceList pricelist, Currency currency, Organization organization) throws OBException
Calculates the Standard Price of the given Product. It uses thegetProductPrice()
method to get the ProductPrice to be used. In case a conversion is needed it uses thegetConvertedAmount()
method.- Parameters:
product
- Product to get its ProductPrice.date
- Date when Product Price is needed.useSalesPriceList
- boolean to set if the price list should be a sales or purchase price list.pricelist
- PriceList to get its ProductPricecurrency
- Currency to convert to the returned price.organization
- Organization where price needs to be used to retrieve the proper conversion rate.- Returns:
- a BigDecimal with the Standard Price of the Product for the given parameters.
- Throws:
OBException
- when no valid ProductPrice is found.
-
getProductPrice
public static ProductPrice getProductPrice(Product product, Date date, boolean useSalesPriceList) throws OBException
- Throws:
OBException
- See Also:
getProductPrice(Product, Date, boolean, PriceList, boolean)
-
getProductPrice
public static ProductPrice getProductPrice(Product product, Date date, boolean useSalesPriceList, PriceList priceList) throws OBException
- Throws:
OBException
- See Also:
getProductPrice(Product, Date, boolean, PriceList, boolean)
-
getProductPrice
public static ProductPrice getProductPrice(Product product, Date date, boolean useSalesPriceList, PriceList priceList, boolean throwException) throws OBException
-
getProductPrice
public static ProductPrice getProductPrice(Product product, Date date, boolean useSalesPriceList, PriceList priceList, boolean throwException, boolean usePriceIncludeTax) throws OBException
Method to get a valid ProductPrice for the given Product. It only considers PriceList versions valid on the given date. If a PriceList is given it searches on that one. If PriceList null is passed it search on any Sales or Purchase PriceList based on the useSalesPriceList.- Parameters:
product
- Product to get its ProductPrice.date
- Date when Product Price is needed.useSalesPriceList
- boolean to set if the price list should be a sales or purchase price list.priceList
- PriceList to get its ProductPricethrowException
- boolean to determine if an exception has to be thrown when no pricelist is found.usePriceIncludeTax
- boolean to set if price lists including taxes should be considered or not.- Returns:
- a valid ProductPrice for the given parameters. Null is no exception is to be thrown.
- Throws:
OBException
- when no valid ProductPrice is found and throwException is true.
-
getConversionRate
public static ConversionRate getConversionRate(Date date, Currency fromCurrency, Currency toCurrency, Organization org, Client client)
Method to get the conversion rate defined at system level. If there is not a conversion rate defined on the given Organization it is searched recursively on its parent organization until one is found. If no conversion rate is found null is returned.- Parameters:
date
- Date conversion is being performed.fromCurrency
- Currency to convert from.toCurrency
- Currency to convert to.org
- Organization of the document that needs to be converted.- Returns:
- a valid ConversionRate for the given parameters, null if none is found.
-
getConvertedAmount
public static BigDecimal getConvertedAmount(BigDecimal amount, Currency curFrom, Currency curTo, Date date, Organization org, String strPrecision) throws OBException
It callsgetConvertedAmount(BigDecimal, Currency, Currency, Date, Organization, String, List)
with an empty list of conversion rates at document level- Throws:
OBException
-
getConvertedAmount
public static BigDecimal getConvertedAmount(BigDecimal amount, Currency curFrom, Currency curTo, Date date, Organization org, String strPrecision, List<ConversionRateDoc> rateDocs) throws OBException
Converts an amount.- Parameters:
amount
- BigDecimal amount to convert.curFrom
- Currency to convert from.curTo
- Currency to convert to.date
- Date conversion is being performed.org
- Organization of the document that needs to be converted.strPrecision
- type of precision to be used to round the converted amount.rateDocs
- list of conversion rates defined on the document of the amount that needs to be converted.- Returns:
- a BigDecimal representing the converted amount.
- Throws:
OBException
- when no Conversion Rate is found for the given parameters.
-
getLegalEntityCurrency
public static Currency getLegalEntityCurrency(Organization organization)
Returns the Currency of a Legal Entity. If there is no one defined, returns the currency of the Client.
-
calculateNetFromGross
@Deprecated public static BigDecimal calculateNetFromGross(String strTaxId, BigDecimal grossAmount, int pricePrecision, BigDecimal alternateAmount, BigDecimal quantity)
Deprecated.Calculates the net unit price using the C_GET_NET_PRICE_FROM_GROSS stored procedure.- Parameters:
strTaxId
- Tax that applies to the price.grossAmount
- Gross Amount to calculate the net unit price from.pricePrecision
- Precision to round the result to.alternateAmount
- alternate amount in case the tax uses it.quantity
- number of units to divide the amount to get the price.- Returns:
- the net unit price
-
calculateNetAmtFromGross
public static BigDecimal calculateNetAmtFromGross(String strTaxId, BigDecimal grossAmount, int stdPrecision, BigDecimal alternateAmount)
Calculates the net unit price using the C_GET_NET_AMOUNT_FROM_GROSS stored procedure.- Parameters:
strTaxId
- Tax that applies to the price.grossAmount
- Gross Amount to calculate the net unit price from.stdPrecision
- Standard to round the result to.alternateAmount
- alternate amount in case the tax uses it.- Returns:
- the net unit price
-
-