Exemple #1
0
        /// <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);
        }
 /*	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();
 }
Exemple #3
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);
        }
Exemple #4
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);
        }
 /// <summary>
 /// Get Uom Name
 /// </summary>
 /// <returns>UOM</returns>
 public String GetUomName()
 {
     if (_uom == null)
     {
         _uom = MUOM.Get(GetCtx(), GetC_UOM_ID());
     }
     return(_uom.GetName());
 }
Exemple #6
0
 /// <summary>
 ///     Parent Constructor
 /// </summary>
 /// <param name="parent"></param>
 public MUOMConversion(MUOM parent)
     : this(parent.GetCtx(), 0, parent.Get_TrxName())
 {
     SetClientOrg(parent);
     SetC_UOM_ID(parent.GetC_UOM_ID());
     SetM_Product_ID(0);
     SetC_UOM_To_ID(parent.GetC_UOM_ID());
     SetMultiplyRate(Env.ONE);
     SetDivideRate(Env.ONE);
 }
Exemple #7
0
        /*	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());
        }
Exemple #8
0
 /*	Set Qty Entered - enforce entered UOM
  *	@param QtyEntered
  */
 public void SetQtyEntered(Decimal QtyEntered)
 {
     if (QtyEntered != 0 && GetC_UOM_ID() != 0)
     {
         int precision = MUOM.GetPrecision(GetCtx(), GetC_UOM_ID());
         //QtyEntered = QtyEntered.setScale(precision, Decimal.ROUND_HALF_UP);
         QtyEntered = Decimal.Round(QtyEntered, precision, MidpointRounding.AwayFromZero);
     }
     base.SetQtyEntered(QtyEntered);
 }
 /**
    * 	Get UOM Standard Precision
    *	@return UOM Standard Precision
    */
 public int GetUOMPrecision()
 {
     if (_precision == null)
     {
         int C_UOM_ID = GetC_UOM_ID();
         if (C_UOM_ID == 0)
             return 0;	//	EA
         _precision = (int)MUOM.GetPrecision(GetCtx(), C_UOM_ID);
     }
     return (int)_precision;
 }
Exemple #10
0
        /// <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);
        }
Exemple #11
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);
        }
Exemple #12
0
        /// <summary>
        /// Get UOM from Cache
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_UOM_ID"></param>
        /// <returns>UOM</returns>
        public static MUOM Get(Ctx ctx, int C_UOM_ID)
        {
            if (s_cache.Count == 0)
            {
                LoadUOMs(ctx);
            }
            //
            int  ii  = C_UOM_ID;
            MUOM uom = (MUOM)s_cache[ii];

            if (uom != null)
            {
                return(uom);
            }
            //
            uom = new MUOM(ctx, C_UOM_ID, null);
            s_cache.Add(Utility.Util.GetValueOfInt(C_UOM_ID), uom);
            return(uom);
        }
Exemple #13
0
        /// <summary>
        /// Get Minute C_UOM_ID
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns>C_UOM_ID for Minute</returns>
        public static int GetMinute_UOM_ID(Ctx ctx)
        {
            if (Ini.IsClient())
            {
                //Iterator it = s_cache.values().iterator();
                IEnumerator it = s_cache.Values.GetEnumerator();
                while (it.MoveNext())
                {
                    MUOM uom = (MUOM)it.Current;
                    if (uom.IsMinute())
                    {
                        return(uom.GetC_UOM_ID());
                    }
                }
            }
            //	Server
            int    C_UOM_ID = 0;
            String sql      = "SELECT C_UOM_ID FROM C_UOM WHERE IsActive='Y' AND X12DE355='MJ'"; //	HardCoded
            //DataTable dt = null;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                while (idr.Read())
                {
                    C_UOM_ID = Utility.Util.GetValueOfInt(idr[0]);
                }
                idr.Close();
                idr = null;
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            return(C_UOM_ID);
        }
Exemple #14
0
        /// <summary>
        /// Convert qty to target UOM and round.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_UOM_ID"></param>
        /// <param name="qty"></param>
        /// <returns>minutes - 0 if not found</returns>
        static public int ConvertToMinutes(Ctx ctx, int C_UOM_ID, Decimal?qty)
        {
            if (qty == null)
            {
                return(0);
            }
            int C_UOM_To_ID = MUOM.GetMinute_UOM_ID(ctx);

            if (C_UOM_ID == C_UOM_To_ID)
            {
                return(Decimal.ToInt32(qty.Value));
            }

            Decimal?result = (Decimal?)Convert(ctx, C_UOM_ID, C_UOM_To_ID, qty);

            if (result == null)
            {
                return(0);
            }
            return(Decimal.ToInt32(result.Value));
        }
Exemple #15
0
        /// <summary>
        /// Load All UOMs
        /// </summary>
        /// <param name="ctx"></param>
        private static void LoadUOMs(Ctx ctx)
        {
            String sql = MRole.GetDefault(ctx, false).AddAccessSQL(
                "SELECT * FROM C_UOM "
                + "WHERE IsActive='Y'",
                "C_UOM", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);

            try
            {
                DataSet ds = ExecuteQuery.ExecuteDataset(sql, null);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr  = ds.Tables[0].Rows[i];
                    MUOM    uom = new MUOM(ctx, dr, null);
                    s_cache.Add(uom.GetC_UOM_ID(), uom);
                }
                ds = null;
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
        }
Exemple #16
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);
        }
Exemple #17
0
        /// <summary>
        /// Get Precision
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_UOM_ID"></param>
        /// <returns>Precision</returns>
        public static int GetPrecision(Ctx ctx, int C_UOM_ID)
        {
            MUOM uom = Get(ctx, C_UOM_ID);

            return(uom.GetStdPrecision());
        }
Exemple #18
0
        /****
         *  Before Save
         *	@param newRecord new
         *	@return save
         */
        protected override bool BeforeSave(bool newRecord)
        {
            log.Fine("");
            if (GetC_Charge_ID() == 0 && GetM_Product_ID() == 0)
            {
                return(false);
            }
            //	Get Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM M_InOutLine WHERE M_InOut_ID=" + GetM_InOut_ID();
                int    ii  = Utility.Util.GetValueOfInt(DataBase.DB.ExecuteScalar(sql, null, null));
                SetLine(ii);
            }
            //	UOM

            if (GetC_UOM_ID() == 0)
            {
                SetC_UOM_ID(GetCtx().GetContextAsInt("#C_UOM_ID"));
            }
            if (GetC_UOM_ID() == 0)
            {
                int C_UOM_ID = MUOM.GetDefault_UOM_ID(GetCtx());
                if (C_UOM_ID > 0)
                {
                    SetC_UOM_ID(C_UOM_ID);
                }
            }

            MInOut inO = new MInOut(Env.GetCtx(), GetM_InOut_ID(), null);

            // true in case of Shipment and False in case of MR
            if (inO.IsSOTrx() == true)
            {
                int           M_Warehouse_ID = 0; MWarehouse wh = null;
                StringBuilder qry = new StringBuilder();
                qry.Append("select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID());
                M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry.ToString()));

                wh = MWarehouse.Get(GetCtx(), M_Warehouse_ID);
                qry.Clear();
                qry.Append("SELECT QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID());
                if (GetM_AttributeSetInstance_ID() != 0)
                {
                    qry.Append(" AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID());
                }
                OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry.ToString()));
                if (wh.IsDisallowNegativeInv() == true)
                {
                    if (GetQtyEntered() < 0)
                    {
                        return(false);
                    }
                    else if ((OnHandQty - GetQtyEntered()) < 0)
                    {
                        return(false);
                    }
                }
            }
            //else
            //{
            //MProduct pro = new MProduct(GetCtx(), GetM_Product_ID(), null);
            //String qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inO.GetC_BPartner_ID();
            //int uom = Util.GetValueOfInt(DB.ExecuteScalar(qryUom));
            //if (pro.GetC_UOM_ID() != 0)
            //{
            //    if (pro.GetC_UOM_ID() != uom && uom != 0)
            //    {
            //        decimal? Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + GetM_Product_ID() + " AND IsActive='Y'"));
            //        if (Res > 0)
            //        {
            //            SetQtyEntered(GetQtyEntered() * Res);
            //            //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty);
            //        }
            //        else
            //        {
            //            decimal? res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'"));
            //            if (res > 0)
            //            {
            //                SetQtyEntered(GetQtyEntered() * res);
            //                //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty);
            //            }
            //        }
            //        SetC_UOM_ID(uom);
            //    }
            //    else
            //    {
            //        SetC_UOM_ID(pro.GetC_UOM_ID());
            //    }
            //}
            //}
            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetQtyEntered(GetQtyEntered());
            }
            if (newRecord || Is_ValueChanged("MovementQty"))
            {
                SetMovementQty(GetMovementQty());
            }
            //	Order Line
            if (GetC_OrderLine_ID() == 0)
            {
                if (GetParent().IsSOTrx())
                {
                    log.SaveError("FillMandatory", Msg.Translate(GetCtx(), "C_Order_ID"));
                    return(false);
                }
            }

            //	if (getC_Charge_ID() == 0 && getM_Product_ID() == 0)
            //		;

            /**	 Qty on instance ASI
             * if (getM_AttributeSetInstance_ID() != 0)
             * {
             *  MProduct product = getProduct();
             *  int M_AttributeSet_ID = product.getM_AttributeSet_ID();
             *  bool isInstance = M_AttributeSet_ID != 0;
             *  if (isInstance)
             *  {
             *      MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID);
             *      isInstance = mas.isInstanceAttribute();
             *  }
             *  //	Max
             *  if (isInstance)
             *  {
             *      MStorage storage = MStorage.get(getCtx(), getM_Locator_ID(),
             *          getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName());
             *      if (storage != null)
             *      {
             *          Decimal qty = storage.getQtyOnHand();
             *          if (getMovementQty().compareTo(qty) > 0)
             *          {
             *              log.warning("Qty - Stock=" + qty + ", Movement=" + getMovementQty());
             *              log.saveError("QtyInsufficient", "=" + qty);
             *              return false;
             *          }
             *      }
             *  }
             * }	/**/
            //Mandatory
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                if (GetM_AttributeSetInstance_ID() != 0)        //	Set to from
                {
                    SetM_AttributeSetInstance_ID(GetM_AttributeSetInstance_ID());
                }
                else
                {
                    MProduct product = GetProduct();
                    if (product != null &&
                        product.GetM_AttributeSet_ID() != 0)
                    {
                        //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                        //if (mas.IsInstanceAttribute()
                        //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                        //{
                        //    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                        //    return false;
                        //}
                        MInOut inout = new MInOut(Env.GetCtx(), GetM_InOut_ID(), Get_Trx());
                        if (inout.GetDescription() != "RC" && Util.GetValueOfBool(IsDTD001_IsAttributeNo()) == false)
                        {
                            if (GetDTD001_Attribute() == "" || GetDTD001_Attribute() == null)
                            {
                                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_Attribute"));

                                return(false);
                            }
                            //Check No Of Attributes Are Equal To Quantity Or Less Than
                            int Count = CountAttributes(GetDTD001_Attribute());
                            if (Count != GetQtyEntered())
                            {
                                if (Count > GetQtyEntered())
                                {
                                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MaterialAtrbteGreater"));
                                    return(false);
                                }
                                else
                                {
                                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MaterialAtrbteless"));
                                    return(false);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (product != null)
                        {
                            if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_Attribute() == "" || GetDTD001_Attribute() == null))
                            {
                                return(true);
                            }
                            else
                            {
                                //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                //ShowMessage.Info("a", true, "Product is not of Attribute Type", null);
                                log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_Attribute"));
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Exemple #19
0
        /**
         *  Set Qty
         *	@param windowNo window
         *	@param columnName column
         */
        private void SetQty(int windowNo, String columnName)
        {
            int M_Product_ID = GetM_Product_ID();

            log.Log(Level.WARNING, "qty - init - M_Product_ID=" + M_Product_ID);
            Decimal MovementQty, QtyEntered;
            int     C_UOM_To_ID = GetC_UOM_ID();

            //	No Product
            if (M_Product_ID == 0)
            {
                QtyEntered = GetQtyEntered();
                SetMovementQty(QtyEntered);
            }
            //	UOM Changed - convert from Entered -> Product
            else if (columnName.Equals("C_UOM_ID"))
            {
                QtyEntered = GetQtyEntered();
                //Decimal QtyEntered1 = QtyEntered.setScale(MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), Decimal.ROUND_HALF_UP);
                Decimal QtyEntered1 = Decimal.Round(QtyEntered, MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), MidpointRounding.AwayFromZero);
                if (QtyEntered.CompareTo(QtyEntered1) != 0)
                {
                    log.Fine("Corrected QtyEntered Scale UOM=" + C_UOM_To_ID
                             + "; QtyEntered=" + QtyEntered + "->" + QtyEntered1);
                    QtyEntered = QtyEntered1;
                    SetQtyEntered(QtyEntered);
                }
                MovementQty = (Decimal)MUOMConversion.ConvertProductFrom(GetCtx(), M_Product_ID, C_UOM_To_ID, QtyEntered);
                if (MovementQty == null)
                {
                    MovementQty = QtyEntered;
                }
                bool conversion = QtyEntered.CompareTo(MovementQty) != 0;

                log.Fine("UOM=" + C_UOM_To_ID
                         + ", QtyEntered=" + QtyEntered
                         + " -> " + conversion
                         + " MovementQty=" + MovementQty);

                //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion);
                SetMovementQty(MovementQty);
            }
            //	No UOM defined
            else if (C_UOM_To_ID == 0)
            {
                QtyEntered = GetQtyEntered();
                SetMovementQty(QtyEntered);
            }
            //	QtyEntered changed - calculate MovementQty
            else if (columnName.Equals("QtyEntered"))
            {
                QtyEntered = GetQtyEntered();
                Decimal QtyEntered1 = Decimal.Round(QtyEntered, MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), MidpointRounding.AwayFromZero);
                if (QtyEntered.CompareTo(QtyEntered1) != 0)
                {
                    log.Fine("Corrected QtyEntered Scale UOM=" + C_UOM_To_ID
                             + "; QtyEntered=" + QtyEntered + "->" + QtyEntered1);
                    QtyEntered = QtyEntered1;
                    SetQtyEntered(QtyEntered);
                }
                MovementQty = (Decimal)MUOMConversion.ConvertProductFrom(GetCtx(),
                                                                         M_Product_ID, C_UOM_To_ID, QtyEntered);
                if (MovementQty == null)
                {
                    MovementQty = QtyEntered;
                }
                bool conversion = QtyEntered.CompareTo(MovementQty) != 0;

                log.Fine("UOM=" + C_UOM_To_ID
                         + ", QtyEntered=" + QtyEntered
                         + " -> " + conversion
                         + " MovementQty=" + MovementQty);

                //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion);
                SetMovementQty(MovementQty);
            }
            //	MovementQty changed - calculate QtyEntered (should not happen)
            else if (columnName.Equals("MovementQty"))
            {
                MovementQty = GetMovementQty();
                int precision = MProduct.Get(GetCtx(), M_Product_ID).GetUOMPrecision();
                //Decimal MovementQty1 = MovementQty.setScale(precision, Decimal.ROUND_HALF_UP);
                Decimal MovementQty1 = Decimal.Round(MovementQty, precision, MidpointRounding.AwayFromZero);// Env.Scale(MovementQty);
                if (MovementQty.CompareTo(MovementQty1) != 0)
                {
                    log.Fine("Corrected MovementQty "
                             + MovementQty + "->" + MovementQty1);
                    MovementQty = MovementQty1;
                    SetMovementQty(MovementQty);
                }
                QtyEntered = (Decimal)MUOMConversion.ConvertProductTo(GetCtx(), M_Product_ID, C_UOM_To_ID, MovementQty);
                if (QtyEntered == null)
                {
                    QtyEntered = MovementQty;
                }
                bool conversion = MovementQty.CompareTo(QtyEntered) != 0;
                log.Fine("UOM=" + C_UOM_To_ID
                         + ", MovementQty=" + MovementQty
                         + " -> " + conversion
                         + " QtyEntered=" + QtyEntered);

                //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion);
                SetQtyEntered(QtyEntered);
            }

            // RMA : Check qty returned is more than qty shipped
            bool IsReturnTrx = GetParent().IsReturnTrx();

            if (M_Product_ID != 0 && IsReturnTrx)
            {
                int        oLine_ID = GetC_OrderLine_ID();
                MOrderLine oLine    = new MOrderLine(GetCtx(), oLine_ID, null);
                if (oLine.Get_ID() != 0)
                {
                    int orig_IOLine_ID = oLine.GetOrig_InOutLine_ID();
                    if (orig_IOLine_ID != 0)
                    {
                        MInOutLine orig_IOLine = new MInOutLine(GetCtx(), orig_IOLine_ID, null);
                        Decimal    shippedQty  = orig_IOLine.GetMovementQty();
                        MovementQty = GetMovementQty();
                        if (shippedQty.CompareTo(MovementQty) < 0)
                        {
                            if (GetCtx().IsSOTrx(windowNo))
                            {
                                //   p_changeVO.addError(Msg.getMsg(getCtx(), "QtyShippedLessThanQtyReturned", shippedQty));
                            }
                            else
                            {
                                // p_changeVO.addError(Msg.getMsg(getCtx(), "QtyReceivedLessThanQtyReturned", shippedQty));
                            }

                            SetMovementQty(shippedQty);
                            MovementQty = shippedQty;
                            QtyEntered  = (Decimal)MUOMConversion.ConvertProductTo(GetCtx(), M_Product_ID,
                                                                                   C_UOM_To_ID, MovementQty);
                            if (QtyEntered == null)
                            {
                                QtyEntered = MovementQty;
                            }
                            SetQtyEntered(QtyEntered);
                            log.Fine("QtyEntered : " + QtyEntered.ToString() +
                                     "MovementQty : " + MovementQty.ToString());
                        }
                    }
                }
            }
        }
Exemple #20
0
        /// <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);
        }
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true if can be saved</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            // chck pallet Functionality applicable or not
            bool isContainrApplicable = MTransaction.ProductContainerApplicable(GetCtx());

            Decimal    VA024_ProvisionPrice = 0;
            MInventory inventory            = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx());
            MProduct   product = MProduct.Get(GetCtx(), GetM_Product_ID());

            if (newRecord && _isManualEntry)
            {
                //	Product requires ASI
                if (GetM_AttributeSetInstance_ID() == 0)
                {
                    if (product.GetM_AttributeSet_ID() != 0)
                    {
                        MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                        //uncomment by Amit on behalf of Mandeep 7-3-2016
                        //if (mas.IsInstanceAttribute()
                        //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                        if (mas.IsMandatory() || mas.IsMandatoryAlways())
                        {
                            log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID"));
                            return(false);
                        }
                    }
                } //	No ASI
            }     //	new or manual

            // not to create Internal use Inventory with -ve qty -- but during reversal system will create record with -ve qty
            // duing reversal -- ReversalDoc_ID contain refernce o  orignal record id
            if (IsInternalUse() && Get_ColumnIndex("ReversalDoc_ID") > 0 && GetReversalDoc_ID() == 0 && GetQtyInternalUse() < 0)
            {
                log.SaveError("", Msg.GetMsg(GetCtx(), "VIS_CantbeNegative"));
                return(false);
            }

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_InventoryLine WHERE M_Inventory_ID=" + GetM_Inventory_ID();
                int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // SI_0644.1 : Enforce UOM Precision - Rounding Quantities
            if (newRecord || Is_ValueChanged("QtyInternalUse"))
            {
                SetQtyInternalUse(GetQtyInternalUse());
            }

            //JID_0680 set quantity according to precision
            if (Is_ValueChanged("C_UOM_ID"))
            {
                Set_Value("QtyEntered", Math.Round(Util.GetValueOfDecimal(Get_Value("QtyEntered")), MUOM.GetPrecision(GetCtx(), Util.GetValueOfInt(Get_Value("C_UOM_ID")))));
            }

            // change to set Converted Quantity in Internal Use Qty and AsonDateQty and difference qty if there is differnce in UOM of Base Product and UOM Selected on line
            if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID"))
            {
                Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered"));
                if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID")))
                {
                    qty = MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered")));
                    if (IsInternalUse())
                    {
                        SetQtyInternalUse(qty);
                    }
                    else
                    {
                        //JID_1392
                        if (GetAdjustmentType() == ADJUSTMENTTYPE_AsOnDateCount)
                        {
                            SetAsOnDateCount(qty);
                            SetDifferenceQty(Decimal.Negate(qty.Value));
                        }
                        else if (GetAdjustmentType() == ADJUSTMENTTYPE_QuantityDifference)
                        {
                            SetAsOnDateCount(Decimal.Negate(qty.Value));
                            SetDifferenceQty(qty);
                        }
                    }
                }
            }

            // SI_0644 - As on date and difference should be according to the precision of UOM attached.
            if (newRecord || Is_ValueChanged("AsOnDateCount"))
            {
                if (product != null)
                {
                    int precision = product.GetUOMPrecision();
                    SetAsOnDateCount(Decimal.Round(GetAsOnDateCount(), precision, MidpointRounding.AwayFromZero));
                }
            }

            // SI_0644 - As on date and difference should be according to the precision of UOM attached.
            if (newRecord || Is_ValueChanged("DifferenceQty"))
            {
                if (product != null)
                {
                    int precision = product.GetUOMPrecision();
                    SetDifferenceQty(Decimal.Round(GetDifferenceQty(), precision, MidpointRounding.AwayFromZero));
                }
            }

            // SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move.
            if (Env.IsModuleInstalled("DTD001_") && IsInternalUse())
            {
                qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("QtyInternalUse"));
            }

            // no need to check when record is in processing
            if (!inventory.IsProcessing() || newRecord)
            {
                int    M_Warehouse_ID = 0; MWarehouse wh = null;
                string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID();
                M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry, null, Get_TrxName()));

                wh  = MWarehouse.Get(GetCtx(), M_Warehouse_ID);
                qry = "SELECT QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID() +
                      " AND NVL(M_AttributeSetInstance_ID, 0)=" + GetM_AttributeSetInstance_ID();
                OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry, null, Get_TrxName()));

                // when record is in completed & closed stage - then no need to check qty availablity in warehouse
                if (wh.IsDisallowNegativeInv() == true &&
                    (!(inventory.GetDocStatus() == "CO" || inventory.GetDocStatus() == "CL" ||
                       inventory.GetDocStatus() == "RE" || inventory.GetDocStatus() == "VO")))
                {
                    // pick container current qty from transaction based on locator / product / ASI / Container / Movement Date
                    if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0)
                    {
                        qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC) AS CurrentQty FROM m_transaction t 
                            INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(inventory.GetMovementDate(), true) +
                              " AND t.AD_Client_ID = " + GetAD_Client_ID() + " AND t.M_Locator_ID = " + GetM_Locator_ID() +
                              " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() +
                              " AND NVL(t.M_ProductContainer_ID, 0) = " + GetM_ProductContainer_ID();
                        containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry, null, null)); // dont use Transaction here - otherwise impact goes wrong on completion
                    }

                    #region DisallowNegativeInv = True
                    if (!IsInternalUse() && GetDifferenceQty() > 0)
                    {
                        if ((OnHandQty - GetDifferenceQty()) < 0)
                        {
                            log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                            return(false);
                        }
                        if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQty - GetDifferenceQty()) < 0)
                        {
                            log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainer") + containerQty);
                            return(false);
                        }
                    }
                    else if (IsInternalUse())
                    {
                        if ((OnHandQty - GetQtyInternalUse()) < 0)
                        {
                            log.SaveError("", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                            return(false);
                        }
                        if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQty - GetQtyInternalUse()) < 0)
                        {
                            log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainer") + containerQty);
                            return(false);
                        }
                    }
                    #endregion
                }
            }

            //	Enforce Qty UOM
            if (newRecord || Is_ValueChanged("QtyCount"))
            {
                SetQtyCount(GetQtyCount());
            }

            //	InternalUse Inventory
            if (IsInternalUse() && Env.Signum(GetQtyInternalUse()) == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "QtyInternalUse"));
                return(false);
            }
            if (Env.Signum(GetQtyInternalUse()) != 0)
            {
                if (!INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType()))
                {
                    SetInventoryType(INVENTORYTYPE_ChargeAccount);
                }
                //
                if (GetC_Charge_ID() == 0)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "InternalUseNeedsCharge"));
                    return(false);
                }
            }
            else if (INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType()))
            {
                if (GetC_Charge_ID() == 0)
                {
                    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "C_Charge_ID"));
                    return(false);
                }
            }
            else if (GetC_Charge_ID() != 0)
            {
                SetC_Charge_ID(0);
            }

            //	Set AD_Org to parent if not charge
            if (GetC_Charge_ID() == 0)
            {
                SetAD_Org_ID(GetParent().GetAD_Org_ID());
            }

            // By Amit for Obsolete Inventory - 25-May-2016
            if (Env.IsModuleInstalled("VA024_"))
            {
                //MInventory inventory = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx());
                //shipment and Return to vendor
                if (inventory.IsInternalUse() || (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0))
                {
                    try
                    {
                        string qry1 = @"SELECT  SUM(o.VA024_UnitPrice)   FROM VA024_t_ObsoleteInventory o 
                                  WHERE o.IsActive = 'Y' AND  o.M_Product_ID = " + GetM_Product_ID() + @" and 
                                  ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" +
                                      " AND o.AD_Org_ID = " + GetAD_Org_ID();
                        //+" AND M_Warehouse_ID = " + inventory.GetM_Warehouse_ID();
                        VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()));
                        if (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0)
                        {
                            SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * (GetQtyBook() - GetQtyCount())));
                        }
                        else
                        {
                            SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetQtyInternalUse()));
                        }

                        if (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0)
                        {
                            qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + (GetQtyBook() - GetQtyCount());
                        }
                        else
                        {
                            qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + GetQtyInternalUse();
                        }
                        qry1 += @" FROM m_product p  INNER JOIN va024_t_obsoleteinventory oi ON p.m_product_id = oi.M_product_ID
                                 INNER JOIN m_product_category pc ON pc.m_product_category_ID = p.m_product_category_ID
                                 INNER JOIN AD_client c ON c.AD_Client_ID = p.Ad_Client_ID   INNER JOIN AD_ClientInfo ci  ON c.AD_Client_ID = ci.Ad_Client_ID
                                 INNER JOIN m_cost ct ON ( p.M_Product_ID     = ct.M_Product_ID  AND ci.C_AcctSchema1_ID = ct.C_AcctSchema_ID )
                                 INNER JOIN c_acctschema asch  ON (asch.C_AcctSchema_ID = ci.C_AcctSchema1_ID)
                                 INNER JOIN va024_obsoleteinvline oil ON oil.va024_obsoleteinvline_ID = oi.va024_obsoleteinvline_ID ";
                        qry1 += @"    WHERE ct.AD_Org_ID =  
                          CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'B')) THEN 0 
                               WHEN (pc.costinglevel IS NULL AND asch.costinglevel  = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'B')) THEN 0  END
                          AND ct.m_costelement_id =  
                          CASE WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement  
                                     WHERE m_costelement.costingmethod =pc.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  ) 
                                WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod = 'C' ) THEN  pc.m_costelement_id 
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement 
                                     WHERE m_costelement.costingmethod = asch.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  )
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  = 'C') THEN asch.m_costelement_id  END 
                         AND NVL(ct.M_Attributesetinstance_ID , 0) =  
                         CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" 
                              WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'O')) THEN 0 
                              WHEN ( pc.costinglevel IS NULL AND asch.costinglevel  = 'B') THEN " + GetM_AttributeSetInstance_ID() + @"
                              WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'O')) THEN 0  END 
                         AND p.M_Product_ID = " + GetM_Product_ID();
                        SetVA024_CostPrice(Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())));
                    }
                    catch { }
                }
            }

            return(true);
        }
Exemple #22
0
        }       //	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