Esempio n. 1
0
        /// <summary>
        /// Convert Qty/Amt FROM product UOM to entered UOM and round.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="C_UOM_To_ID">quantity or price</param>
        /// <param name="qtyPrice">quantity or price</param>
        /// <returns>Entered: Qty in entered UoM (precision rounded)</returns>
        //public static Decimal? ConvertProductFrom(Ctx ctx, int M_Product_ID, int C_UOM_To_ID, Decimal? qtyPrice,bool _ProductToConversion=false)
        public static Decimal?ConvertProductFrom(Ctx ctx, int M_Product_ID, int C_UOM_To_ID, Decimal?qtyPrice)
        {
            //	No conversion
            // Arpit to Pass a Parametrized Constructor so that we can have the reverse conversion rate for the defined product
            // bool ProductToConversion = _ProductToConversion;
            //  Arpit
            if (qtyPrice == null || qtyPrice.Equals(Env.ZERO) || C_UOM_To_ID == 0 || M_Product_ID == 0)
            {
                _log.Fine("No Conversion - QtyPrice=" + qtyPrice);
                return(qtyPrice);
            }
            //Decimal? retValue = (Decimal?)GetProductRateFrom(ctx, M_Product_ID, C_UOM_To_ID, ProductToConversion);
            Decimal?retValue = (Decimal?)GetProductRateFrom(ctx, M_Product_ID, C_UOM_To_ID);

            if (retValue != null)
            {
                if (Env.ONE.CompareTo(retValue.Value) == 0)
                {
                    return(qtyPrice);
                }
                MUOM uom = MUOM.Get(ctx, C_UOM_To_ID);
                if (uom != null)
                {
                    return(uom.Round(Decimal.Multiply(retValue.Value, qtyPrice.Value), true));
                }
                //return retValue.multiply(qtyPrice);
                return(Decimal.Multiply(retValue.Value, (Decimal)qtyPrice));
            }
            _log.Fine("No Rate M_Product_ID=" + M_Product_ID);
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Convert Qty/Amt FROM product UOM to entered UOM and round.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="C_UOM_To_ID">quantity or price</param>
        /// <param name="qtyPrice">quantity or price</param>
        /// <returns>Entered: Qty in entered UoM (precision rounded)</returns>
        public static Decimal?ConvertProductFrom(Ctx ctx, int M_Product_ID, int C_UOM_To_ID, Decimal?qtyPrice)
        {
            //	No conversion
            if (qtyPrice == null || qtyPrice.Equals(Env.ZERO) || C_UOM_To_ID == 0 || M_Product_ID == 0)
            {
                _log.Fine("No Conversion - QtyPrice=" + qtyPrice);
                return(qtyPrice);
            }

            Decimal?retValue = (Decimal?)GetProductRateFrom(ctx, M_Product_ID, C_UOM_To_ID);

            if (retValue != null)
            {
                if (Env.ONE.CompareTo(retValue.Value) == 0)
                {
                    return(qtyPrice);
                }
                MUOM uom = MUOM.Get(ctx, C_UOM_To_ID);
                if (uom != null)
                {
                    return(uom.Round(Decimal.Multiply(retValue.Value, qtyPrice.Value), true));
                }
                //return retValue.multiply(qtyPrice);
                return(Decimal.Multiply(retValue.Value, (Decimal)qtyPrice));
            }
            _log.Fine("No Rate M_Product_ID=" + M_Product_ID);
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Convert qty to target UOM and round.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_UOM_ID">from UOM</param>
        /// <param name="C_UOM_To_ID">to UOM</param>
        /// <param name="qty"></param>
        /// <returns>converted qty (std precision)</returns>
        static public Decimal?Convert(Ctx ctx, int C_UOM_ID, int C_UOM_To_ID, Decimal?qty)
        {
            if (qty == null || qty.Equals(Env.ZERO) || C_UOM_ID == C_UOM_To_ID)
            {
                return(qty);
            }
            Decimal?retValue = GetRate(ctx, C_UOM_ID, C_UOM_To_ID);

            if (retValue != null)
            {
                MUOM uom = MUOM.Get(ctx, C_UOM_To_ID);
                if (uom != null)
                {
                    return(uom.Round(Decimal.Multiply(retValue.Value, qty.Value), true));
                }
                return(Decimal.Multiply(retValue.Value, qty.Value));
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Convert Qty/Amt from entered UOM TO product UoM and round.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="C_UOM_To_ID">entered UOM</param>
        /// <param name="qtyPrice">entered quantity or price</param>
        /// <returns>Product: Qty/Amt in product UoM (precision rounded)</returns>
        public static Decimal?ConvertProductTo(Ctx ctx, int M_Product_ID, int C_UOM_To_ID, Decimal?qtyPrice)
        {
            if (qtyPrice == null || qtyPrice == 0 || M_Product_ID == 0 || C_UOM_To_ID == 0)
            {
                return(qtyPrice);
            }

            Decimal?retValue = (Decimal?)(GetProductRateTo(ctx, M_Product_ID, C_UOM_To_ID));

            if (retValue != null)
            {
                if (Env.ONE.CompareTo(retValue) == 0)
                {
                    return(qtyPrice);
                }
                MUOM uom = MUOM.Get(ctx, C_UOM_To_ID);
                if (uom != null)
                {
                    return(uom.Round(Decimal.Multiply(Utility.Util.GetValueOfDecimal(retValue), Utility.Util.GetValueOfDecimal(qtyPrice)), true));
                }
                return(Decimal.Multiply(Utility.Util.GetValueOfDecimal(retValue), Utility.Util.GetValueOfDecimal(qtyPrice)));
            }
            return(null);
        }