Class MUOMConversion

    • Field Detail

      • GETRATE

        protected static final BigDecimal GETRATE
        Indicator for Rate
      • s_conversions

        protected static CCache<Point,​BigDecimal> s_conversions
        Conversion Map: Key=Point(from,to) Value=BigDecimal
    • Constructor Detail

      • MUOMConversion

        public MUOMConversion​(Properties ctx,
                              int C_UOM_Conversion_ID,
                              String trxName)
        Default Constructor
        Parameters:
        ctx - context
        C_UOM_Conversion_ID - id
        trxName - transaction
      • MUOMConversion

        public MUOMConversion​(Properties ctx,
                              ResultSet rs,
                              String trxName)
        Load Constructor
        Parameters:
        ctx - context
        rs - result set
        trxName - transaction
      • MUOMConversion

        public MUOMConversion​(MUOM parent)
        Parent Constructor
        Parameters:
        parent - uom parent
      • MUOMConversion

        public MUOMConversion​(MProduct parent)
        Parent Constructor
        Parameters:
        parent - product parent
      • MUOMConversion

        public MUOMConversion​(MUOMConversion copy)
        Parameters:
        copy -
    • Method Detail

      • convert

        public static BigDecimal convert​(Properties ctx,
                                         int C_UOM_ID,
                                         int C_UOM_To_ID,
                                         BigDecimal qty)
        Convert qty to target UOM and round.
        Parameters:
        ctx - context
        C_UOM_ID - from UOM
        C_UOM_To_ID - to UOM
        qty - qty
        Returns:
        converted qty (std precision)
      • getRate

        public static BigDecimal getRate​(Properties ctx,
                                         int C_UOM_ID,
                                         int C_UOM_To_ID)
        Get Multiplier Rate to target UOM
        Parameters:
        ctx - context
        C_UOM_ID - from UOM
        C_UOM_To_ID - to UOM
        Returns:
        multiplier
      • convertToMinutes

        public static int convertToMinutes​(Properties ctx,
                                           int C_UOM_ID,
                                           BigDecimal qty)
        Convert qty to target UOM and round.
        Parameters:
        ctx - context
        C_UOM_ID - from UOM
        qty - qty
        Returns:
        minutes - 0 if not found
      • getEndDate

        public static Timestamp getEndDate​(Properties ctx,
                                           Timestamp startDate,
                                           int C_UOM_ID,
                                           BigDecimal qty)
        Calculate End Date based on start date and qty
        Parameters:
        ctx - context
        startDate - date
        C_UOM_ID - UOM
        qty - qty
        Returns:
        end date
      • getRate

        protected static BigDecimal getRate​(Properties ctx,
                                            Point p)
        Get Conversion Multiplier Rate, try to derive it if not found directly
        Parameters:
        ctx - context
        p - Point with from(x) - to(y) C_UOM_ID
        Returns:
        conversion multiplier or null
      • createRates

        protected static void createRates​(Properties ctx)
        Create Conversion Matrix (Client)
        Parameters:
        ctx - context
      • deriveRate

        public static BigDecimal deriveRate​(Properties ctx,
                                            int C_UOM_ID,
                                            int C_UOM_To_ID)
        Derive Standard Conversions
        Parameters:
        ctx - context
        C_UOM_ID - from UOM
        C_UOM_To_ID - to UOM
        Returns:
        Conversion or null
      • getRate

        public static BigDecimal getRate​(int C_UOM_ID,
                                         int C_UOM_To_ID)
        Get Conversion Multiplier Rate from Server
        Parameters:
        C_UOM_ID - from UOM
        C_UOM_To_ID - to UOM
        Returns:
        conversion multiplier or null
      • convert

        public static BigDecimal convert​(int C_UOM_From_ID,
                                         int C_UOM_To_ID,
                                         BigDecimal qty,
                                         boolean StdPrecision)
        Get Converted Qty from Server (no cache)
        Parameters:
        qty - The quantity to be converted
        C_UOM_From_ID - The C_UOM_ID of the qty
        C_UOM_To_ID - The targeted UOM
        StdPrecision - if true, standard precision, if false costing precision
        Returns:
        amount
      • convertProductTo

        public static BigDecimal convertProductTo​(Properties ctx,
                                                  int M_Product_ID,
                                                  int C_UOM_To_ID,
                                                  BigDecimal qtyPrice)
        Convert PRICE expressed in entered UoM to equivalent price in product UoM and round.
        OR Convert QTY in product UOM to qty in entered UoM and round.
        eg: $6/6pk => $1/ea
        OR 6 X ea => 1 X 6pk
        Parameters:
        ctx - context
        M_Product_ID - product
        C_UOM_To_ID - entered UOM
        qtyPrice - quantity or price
        Returns:
        Product: Qty/Price (precision rounded)
      • convertProductTo

        public static BigDecimal convertProductTo​(Properties ctx,
                                                  int M_Product_ID,
                                                  int C_UOM_To_ID,
                                                  BigDecimal qtyPrice,
                                                  int precision)
        Convert PRICE expressed in entered UoM to equivalent price in product UoM and round.
        OR Convert QTY in product UOM to qty in entered UoM and round.
        eg: $6/6pk => $1/ea
        OR 6 X ea => 1 X 6pk
        Parameters:
        ctx - context
        M_Product_ID - product
        C_UOM_To_ID - entered UOM
        qtyPrice - quantity or price
        precision - Rounding precision, -1 to use precision from UOM
        Returns:
        Product: Qty/Price (precision rounded)
      • getProductRateTo

        public static BigDecimal getProductRateTo​(Properties ctx,
                                                  int M_Product_ID,
                                                  int C_UOM_To_ID)
        Get multiply rate to convert PRICE from price in entered UOM to price in product UOM
        OR multiply rate to convert QTY from product UOM to entered UOM
        Parameters:
        ctx - context
        M_Product_ID - product
        C_UOM_To_ID - entered UOM
        Returns:
        multiplier or null
      • convertProductFrom

        public static BigDecimal convertProductFrom​(Properties ctx,
                                                    int M_Product_ID,
                                                    int C_UOM_To_ID,
                                                    BigDecimal qtyPrice)
        Convert PRICE expressed in product UoM to equivalent price in entered UoM and round.
        OR Convert QTY in entered UOM to qty in product UoM and round.
        eg: $1/ea => $6/6pk
        OR 1 X 6pk => 6 X ea
        Parameters:
        ctx - context
        M_Product_ID - product
        C_UOM_To_ID - entered UOM
        qtyPrice - quantity or price
        Returns:
        Product: Qty/Price (precision rounded)
      • convertProductFrom

        public static BigDecimal convertProductFrom​(Properties ctx,
                                                    int M_Product_ID,
                                                    int C_UOM_To_ID,
                                                    BigDecimal qtyPrice,
                                                    int precision)
        Convert PRICE expressed in product UoM to equivalent price in entered UoM and round.
        OR Convert QTY in entered UOM to qty in product UoM and round.
        eg: $1/ea => $6/6pk
        OR 1 X 6pk => 6 X ea
        Parameters:
        ctx - context
        M_Product_ID - product
        C_UOM_To_ID - entered UOM
        qtyPrice - quantity or price
        precision - Rounding precision, -1 to use precision from UOM
        Returns:
        Product: Qty/Price (precision rounded)
      • getProductRateFrom

        public static BigDecimal getProductRateFrom​(Properties ctx,
                                                    int M_Product_ID,
                                                    int C_UOM_To_ID)
        Get multiply rate to convert PRICE from price in entered UOM to price in product UOM
        OR multiply rate to convert QTY from product UOM to entered UOM
        Parameters:
        ctx - context
        M_Product_ID - product
        C_UOM_To_ID - entered UOM
        Returns:
        multiplier or null
      • getProductConversions

        public static MUOMConversion[] getProductConversions​(Properties ctx,
                                                             int M_Product_ID)
        Get Product Conversions (cached)
        Parameters:
        ctx - context
        M_Product_ID - product
        Returns:
        array of conversions
      • beforeSave

        protected boolean beforeSave​(boolean newRecord)
        Before Save
        Overrides:
        beforeSave in class PO
        Parameters:
        newRecord - new
        Returns:
        true if can be saved
      • getOppositeRate

        public static BigDecimal getOppositeRate​(BigDecimal rate)
        Calculate opposite conversion rate, i.e calculate divide rate for multiply rate and vice versa.
        Parameters:
        rate -
        Returns:
        BigDecimal