Class FinancialUtils


  • public class FinancialUtils
    extends Object
    • Constructor Detail

      • FinancialUtils

        public FinancialUtils()
    • Method Detail

      • 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 the getProductPrice() method to get the ProductPrice to be used. In case a conversion is needed it uses the getConvertedAmount() 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 ProductPrice
        currency - 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,
                                                   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 ProductPrice
        throwException - 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,
                                                    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.
      • 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
      • getPaymentsWithCredit

        public static org.hibernate.ScrollableResults getPaymentsWithCredit​(String businessPartnerId,
                                                                            String currencyId)
        Get all the payment details with available credit