Class MUOMConversion

All Implemented Interfaces:
Serializable, Cloneable, Comparator<Object>, I_C_UOM_Conversion, I_Persistent, Evaluatee, ImmutablePOSupport

public class MUOMConversion extends X_C_UOM_Conversion implements ImmutablePOSupport
Unit of Measure Conversion Model
Version:
$Id: MUOMConversion.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
Author:
Jorg Janke
See Also:
  • Field Details

    • 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
    • s_conversionProduct

      protected static final CCache<Integer,MUOMConversion[]> s_conversionProduct
      Product Conversion Map
  • Constructor Details

    • MUOMConversion

      public MUOMConversion(Properties ctx, String C_UOM_Conversion_UU, String trxName)
      UUID based Constructor
      Parameters:
      ctx - Context
      C_UOM_Conversion_UU - UUID key
      trxName - Transaction
    • 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)
      Copy constructor
      Parameters:
      copy -
    • MUOMConversion

      public MUOMConversion(Properties ctx, MUOMConversion copy)
      Copy constructor
      Parameters:
      ctx -
      copy -
    • MUOMConversion

      public MUOMConversion(Properties ctx, MUOMConversion copy, String trxName)
      Copy constructor
      Parameters:
      ctx -
      copy -
      trxName -
  • Method Details

    • 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)
      Load conversion rate into cache
      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)
      Description copied from class: PO
      Called before Save for Pre-Save Operation.
      Default implementation is nop, to be implemented in sub-classes that needed it.
      Overrides:
      beforeSave in class PO
      Parameters:
      newRecord - true if it is a new record
      Returns:
      true if record can be saved
    • toString

      public String toString()
      String Representation
      Overrides:
      toString in class X_C_UOM_Conversion
      Returns:
      info
    • markImmutable

      public MUOMConversion markImmutable()
      Description copied from interface: ImmutablePOSupport
      mark PO as immutable
      Specified by:
      markImmutable in interface ImmutablePOSupport
      Returns:
      PO
    • getOppositeRate

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

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