/* Get UOM Symbol * @return UOM Symbol */ public String GetUOMSymbol() { int C_UOM_ID = GetC_UOM_ID(); if (C_UOM_ID == 0) return ""; return MUOM.Get(GetCtx(), C_UOM_ID).GetUOMSymbol(); }
/// <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); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">newRecord new</param> /// <returns>true if can be saved</returns> protected override bool BeforeSave(bool newRecord) { // From - To is the same if (GetC_UOM_ID() == GetC_UOM_To_ID()) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@C_UOM_ID@ = @C_UOM_ID@")); return(false); } // Nothing to convert if (GetMultiplyRate().CompareTo(Env.ZERO) <= 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@MultiplyRate@ <= 0")); return(false); } // Enforce Product UOM if (GetM_Product_ID() != 0 && (newRecord || Is_ValueChanged("M_Product_ID"))) { MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); if (product.GetC_UOM_ID() != GetC_UOM_ID()) { MUOM uom = MUOM.Get(GetCtx(), product.GetC_UOM_ID()); log.SaveError("ProductUOMConversionUOMError", uom.GetName()); return(false); } } // The Product UoM needs to be the smallest UoM - Multiplier must be > 0 if (GetM_Product_ID() != 0 && GetDivideRate().CompareTo(Env.ONE) < 0) { log.SaveError("ProductUOMConversionRateError", ""); return(false); } return(true); }
/// <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); }
/// <summary> /// Get Uom Name /// </summary> /// <returns>UOM</returns> public String GetUomName() { if (_uom == null) { _uom = MUOM.Get(GetCtx(), GetC_UOM_ID()); } return(_uom.GetName()); }
/* Get UOM Symbol * @return UOM Symbol */ public String GetUOMSymbol() { int C_UOM_ID = GetC_UOM_ID(); if (C_UOM_ID == 0) { return(""); } return(MUOM.Get(GetCtx(), C_UOM_ID).GetUOMSymbol()); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">newRecord new</param> /// <returns>true if can be saved</returns> protected override bool BeforeSave(bool newRecord) { // From - To is the same //Commented by arpit asked by sachin Sir 29 Jan,2018--to save records with same UOM also //if (GetC_UOM_ID() == GetC_UOM_To_ID()) //{ // log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@C_UOM_ID@ = @C_UOM_ID@")); // return false; //} // Nothing to convert //Getting the message from messagewindow for UOM conversion if (GetMultiplyRate().CompareTo(Env.ZERO) <= 0) { log.SaveError("", Msg.GetMsg(GetCtx(), "ProductUOMConversionRateError")); return(false); } // Enforce Product UOM if (GetM_Product_ID() != 0 && (newRecord || Is_ValueChanged("M_Product_ID"))) { MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); if (product.GetC_UOM_ID() != GetC_UOM_ID()) { MUOM uom = MUOM.Get(GetCtx(), product.GetC_UOM_ID()); log.SaveError("ProductUOMConversionUOMError", uom.GetName()); return(false); } } // The Product UoM needs to be the smallest UoM - Multiplier must be > 0 if (GetM_Product_ID() != 0 && GetDivideRate().CompareTo(Env.ONE) < 0) { // JID_0239: Currenly system show message when multiple rate is less than one like below "Product UOM Coversion rate error" log.SaveError("", Msg.GetMsg(GetCtx(), "ProductUOMConversionRateError")); return(false); } if (!String.IsNullOrEmpty(GetUPC()) && Util.GetValueOfString(Get_ValueOld("UPC")) != GetUPC()) { //string sql = "SELECT UPCUNIQUE('c','" + GetUPC() + "') as productID FROM Dual"; //int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null)); //if (manu_ID != 0 && manu_ID != GetM_Product_ID()) int manu_ID = MProduct.UpcUniqueClientWise(GetAD_Client_ID(), GetUPC()); if (manu_ID > 0) { _log.SaveError("UPCUnique", ""); return(false); } } return(true); }
/// <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); }
/// <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); }
} // getDayTimeSlots /** * Create Time Slots */ private void CreateTimeSlots() { // development error if (_typeName == null) { throw new ArgumentNullException("ResourceTypeName not set"); } List <MAssignmentSlot> list = new List <MAssignmentSlot>(); MUOM.Get(_ctx, _C_UOM_ID); int minutes = MUOMConversion.ConvertToMinutes(_ctx, _C_UOM_ID, Env.ONE); log.Config("Minutes=" + minutes); // if (minutes > 0 && minutes < 60 * 24) { // Set Start Time // GregorianCalendar cal = new GregorianCalendar(); // cal.setTime(m_startDate); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); DateTime cal = new DateTime(_startDate.Value.Year, _startDate.Value.Month, _startDate.Value.Day); // // we have slots - create first if (_slotStartTime != null) { long start = cal.Ticks; // cal.getTimeInMillis(); cal = TimeUtil.GetDayTime(_startDate, _slotStartTime); // set to start time // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); list.Add(new MAssignmentSlot(start, cal.Ticks)); } // // Set End Time // GregorianCalendar calEnd = new GregorianCalendar(); DateTime calEnd; if (_slotEndTime != null) { calEnd = TimeUtil.GetDayTime(_startDate, _slotEndTime); //calEnd.set(Calendar.SECOND, 0); // // calEnd.set(Calendar.MILLISECOND, 0); } else // No Slot - all day { // calEnd.setTime(m_startDate); // calEnd.set(Calendar.HOUR_OF_DAY, 0); // calEnd.set(Calendar.MINUTE, 0); // calEnd.set(Calendar.SECOND, 0); // calEnd.set(Calendar.MILLISECOND, 0); calEnd = new DateTime(_startDate.Value.Year, _startDate.Value.Month, _startDate.Value.Day, 0, 0, 0, 0); calEnd = calEnd.AddDays(1); } ////System.out.println("Start=" + new Timestamp(cal.getTimeInMillis())); ////System.out.println("Endt=" + new Timestamp(calEnd.getTimeInMillis())); // // Set end Slot Time // GregorianCalendar calEndSlot = new GregorianCalendar(); DateTime calEndSlot = new DateTime(cal.Ticks); // calEndSlot.setTime(cal.getTime()); calEndSlot = calEndSlot.AddMinutes(minutes); while (cal < calEnd) { list.Add(new MAssignmentSlot(cal.Ticks, calEndSlot.Ticks)); // // Next Slot cal = cal.AddMinutes(minutes); calEndSlot = calEndSlot.AddMinutes(minutes); } // // create last slot //calEndSlot.setTime(cal.getTime()); calEndSlot = new DateTime(cal.Year, cal.Month, cal.Day, 0, 0, 0, 0); // calEndSlot.set(Calendar.HOUR_OF_DAY, 0); // calEndSlot.set(Calendar.MINUTE, 0); // calEndSlot.set(Calendar.SECOND, 0); // calEndSlot.set(Calendar.MILLISECOND, 0); // calEndSlot.add(Calendar.DAY_OF_YEAR, 1); // 00:00 next day calEndSlot = calEndSlot.AddDays(1); list.Add(new MAssignmentSlot(cal.Ticks, calEndSlot.Ticks)); } else // Day, .... { list.Add(new MAssignmentSlot(TimeUtil.GetDay(_startDate), TimeUtil.GetNextDay(_startDate))); } // _timeSlots = new MAssignmentSlot[list.Count]; _timeSlots = list.ToArray(); } // createTimeSlots
/// <summary> /// Derive Standard Conversions /// </summary> /// <param name="ctx"></param> /// <param name="C_UOM_ID"></param> /// <param name="C_UOM_To_ID"></param> /// <returns>Conversion or null</returns> public static Decimal?DeriveRate(Ctx ctx, int C_UOM_ID, int C_UOM_To_ID) { if (C_UOM_ID == C_UOM_To_ID) { return(Env.ONE); } // get Info MUOM from = MUOM.Get(ctx, C_UOM_ID); MUOM to = MUOM.Get(ctx, C_UOM_To_ID); if (from == null || to == null) { return(null); } // Time - Minute if (from.IsMinute()) { if (to.IsHour()) { return(new Decimal(1.0 / 60.0)); } if (to.IsDay()) { return(new Decimal(1.0 / 1440.0)); // 24 * 60 } if (to.IsWorkDay()) { return(new Decimal(1.0 / 480.0)); // 8 * 60 } if (to.IsWeek()) { return(new Decimal(1.0 / 10080.0)); // 7 * 24 * 60 } if (to.IsMonth()) { return(new Decimal(1.0 / 43200.0)); // 30 * 24 * 60 } if (to.IsWorkMonth()) { return(new Decimal(1.0 / 9600.0)); // 4 * 5 * 8 * 60 } if (to.IsYear()) { return(new Decimal(1.0 / 525600.0)); // 365 * 24 * 60 } } // Time - Hour if (from.IsHour()) { if (to.IsMinute()) { return(new Decimal(60.0)); } if (to.IsDay()) { return(new Decimal(1.0 / 24.0)); } if (to.IsWorkDay()) { return(new Decimal(1.0 / 8.0)); } if (to.IsWeek()) { return(new Decimal(1.0 / 168.0)); // 7 * 24 } if (to.IsMonth()) { return(new Decimal(1.0 / 720.0)); // 30 * 24 } if (to.IsWorkMonth()) { return(new Decimal(1.0 / 160.0)); // 4 * 5 * 8 } if (to.IsYear()) { return(new Decimal(1.0 / 8760.0)); // 365 * 24 } } // Time - Day if (from.IsDay()) { if (to.IsMinute()) { return(new Decimal(1440.0)); // 24 * 60 } if (to.IsHour()) { return(new Decimal(24.0)); } if (to.IsWorkDay()) { return(new Decimal(3.0)); // 24 / 8 } if (to.IsWeek()) { return(new Decimal(1.0 / 7.0)); // 7 } if (to.IsMonth()) { return(new Decimal(1.0 / 30.0)); // 30 } if (to.IsWorkMonth()) { return(new Decimal(1.0 / 20.0)); // 4 * 5 } if (to.IsYear()) { return(new Decimal(1.0 / 365.0)); // 365 } } // Time - WorkDay if (from.IsWorkDay()) { if (to.IsMinute()) { return(new Decimal(480.0)); // 8 * 60 } if (to.IsHour()) { return(new Decimal(8.0)); // 8 } if (to.IsDay()) { return(new Decimal(1.0 / 3.0)); // 24 / 8 } if (to.IsWeek()) { return(new Decimal(1.0 / 5)); // 5 } if (to.IsMonth()) { return(new Decimal(1.0 / 20.0)); // 4 * 5 } if (to.IsWorkMonth()) { return(new Decimal(1.0 / 20.0)); // 4 * 5 } if (to.IsYear()) { return(new Decimal(1.0 / 240.0)); // 4 * 5 * 12 } } // Time - Week if (from.IsWeek()) { if (to.IsMinute()) { return(new Decimal(10080.0)); // 7 * 24 * 60 } if (to.IsHour()) { return(new Decimal(168.0)); // 7 * 24 } if (to.IsDay()) { return(new Decimal(7.0)); } if (to.IsWorkDay()) { return(new Decimal(5.0)); } if (to.IsMonth()) { return(new Decimal(1.0 / 4.0)); // 4 } if (to.IsWorkMonth()) { return(new Decimal(1.0 / 4.0)); // 4 } if (to.IsYear()) { return(new Decimal(1.0 / 50.0)); // 50 } } // Time - Month if (from.IsMonth()) { if (to.IsMinute()) { return(new Decimal(43200.0)); // 30 * 24 * 60 } if (to.IsHour()) { return(new Decimal(720.0)); // 30 * 24 } if (to.IsDay()) { return(new Decimal(30.0)); // 30 } if (to.IsWorkDay()) { return(new Decimal(20.0)); // 4 * 5 } if (to.IsWeek()) { return(new Decimal(4.0)); // 4 } if (to.IsWorkMonth()) { return(new Decimal(1.5)); // 30 / 20 } if (to.IsYear()) { return(new Decimal(1.0 / 12.0)); // 12 } } // Time - WorkMonth if (from.IsWorkMonth()) { if (to.IsMinute()) { return(new Decimal(9600.0)); // 4 * 5 * 8 * 60 } if (to.IsHour()) { return(new Decimal(160.0)); // 4 * 5 * 8 } if (to.IsDay()) { return(new Decimal(20.0)); // 4 * 5 } if (to.IsWorkDay()) { return(new Decimal(20.0)); // 4 * 5 } if (to.IsWeek()) { return(new Decimal(4.0)); // 4 } if (to.IsMonth()) { return(new Decimal(20.0 / 30.0)); // 20 / 30 } if (to.IsYear()) { return(new Decimal(1.0 / 12.0)); // 12 } } // Time - Year if (from.IsYear()) { if (to.IsMinute()) { return(new Decimal(518400.0)); // 12 * 30 * 24 * 60 } if (to.IsHour()) { return(new Decimal(8640.0)); // 12 * 30 * 24 } if (to.IsDay()) { return(new Decimal(365.0)); // 365 } if (to.IsWorkDay()) { return(new Decimal(240.0)); // 12 * 4 * 5 } if (to.IsWeek()) { return(new Decimal(50.0)); // 52 } if (to.IsMonth()) { return(new Decimal(12.0)); // 12 } if (to.IsWorkMonth()) { return(new Decimal(12.0)); // 12 } } // return(null); }