예제 #1
0
        /**
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            GetQty();           //	set to 1
            MAssetGroup astGrp = new MAssetGroup(GetCtx(), GetA_Asset_Group_ID(), Get_TrxName());

            if (newRecord && astGrp.Get_ColumnIndex("M_SerNoCtl_ID") > 0)
            {
                string    name = "";
                MSerNoCtl ctl  = new MSerNoCtl(GetCtx(), astGrp.GetM_SerNoCtl_ID(), Get_TrxName());
                name = ctl.CreateSerNo();
                SetValue(name);
            }
            #region Fixed Asset Management
            /*to Set Written Down Value on Asset i.e. Gross value of Asset-Depreciated/ Amortized Value Arpit*/
            if (Util.GetValueOfInt(DB.ExecuteScalar("select ad_moduleinfo_id from ad_moduleinfo where prefix='VAFAM_' and isactive='Y'")) > 0)
            {
                if (Get_ColumnIndex("VAFAM_WrittenDownValue") > 0 &&
                    Get_ColumnIndex("VAFAM_AssetGrossValue") > 0 && Get_ColumnIndex("VAFAM_SLMDepreciation") > 0)
                {
                    Set_Value("VAFAM_WrittenDownValue",
                              Decimal.Subtract(Util.GetValueOfDecimal(Get_Value("VAFAM_AssetGrossValue")),
                                               Util.GetValueOfDecimal(Get_Value("VAFAM_SLMDepreciation"))));
                }
            }
            #endregion

            return(true);
        }
 /**
  *	Get Serial No
  *  @param getNew if true create/set new Ser No
  *	@return Serial Number
  */
 public String GetSerNo(bool getNew)
 {
     if (getNew)
     {
         int M_SerNoCtl_ID = GetMAttributeSet().GetM_SerNoCtl_ID();
         if (M_SerNoCtl_ID != 0)
         {
             MSerNoCtl ctl = new MSerNoCtl(GetCtx(), M_SerNoCtl_ID, Get_TrxName());
             SetSerNo(ctl.CreateSerNo());
         }
     }
     return(GetSerNo());
 }
        /**
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            GetQty();           //	set to 1
            MAssetGroup astGrp = new MAssetGroup(GetCtx(), GetA_Asset_Group_ID(), Get_TrxName());

            if (newRecord && astGrp.Get_ColumnIndex("M_SerNoCtl_ID") >= 0 && astGrp.GetM_SerNoCtl_ID() > 0 && String.IsNullOrEmpty(GetValue()))
            {
                string    name = "";
                MSerNoCtl ctl  = new MSerNoCtl(GetCtx(), astGrp.GetM_SerNoCtl_ID(), Get_TrxName());

                // if Organization level check box is true on Serila No Control, then Get Current next from Serila No tab.
                if (ctl.Get_ColumnIndex("IsOrgLevelSequence") >= 0)
                {
                    name = ctl.CreateDefiniteSerNo(this);
                }
                else
                {
                    name = ctl.CreateSerNo();
                }
                SetValue(name);
            }
            #region Fixed Asset Management
            /*to Set Written Down Value on Asset i.e. Gross value of Asset-Depreciated/ Amortized Value Arpit*/
            if (Util.GetValueOfInt(DB.ExecuteScalar("select ad_moduleinfo_id from ad_moduleinfo where prefix='VAFAM_' and isactive='Y'")) > 0)
            {
                if (Get_ColumnIndex("VAFAM_WrittenDownValue") > 0 &&
                    Get_ColumnIndex("VAFAM_AssetGrossValue") > 0 && Get_ColumnIndex("VAFAM_SLMDepreciation") > 0)
                {
                    Set_Value("VAFAM_WrittenDownValue",
                              Decimal.Subtract(Util.GetValueOfDecimal(Get_Value("VAFAM_AssetGrossValue")),
                                               Util.GetValueOfDecimal(Get_Value("VAFAM_SLMDepreciation"))));
                }
            }
            #endregion

            return(true);
        }
        /**
         * 	Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            // Set Search Key from Serial No defined on Product Category.
            MProductCategory pc = new MProductCategory(GetCtx(), GetM_Product_Category_ID(), Get_TrxName());
            if (newRecord && pc.Get_ColumnIndex("M_SerNoCtl_ID") >= 0 && pc.GetM_SerNoCtl_ID() > 0)
            {
                string name = "";
                MSerNoCtl ctl = new MSerNoCtl(GetCtx(), pc.GetM_SerNoCtl_ID(), Get_TrxName());

                // if Organization level check box is true on Serila No Control, then Get Current next from Serila No tab.
                if (ctl.Get_ColumnIndex("IsOrgLevelSequence") >= 0)
                {
                    name = ctl.CreateDefiniteSerNo(this);
                }
                else
                {
                    name = ctl.CreateSerNo();
                }
                SetValue(name);
            }

            //	Check Storage
            if (!newRecord && 	//
                ((Is_ValueChanged("IsActive") && !IsActive())		//	now not active
                || (Is_ValueChanged("IsStocked") && !IsStocked())	//	now not stocked
                || (Is_ValueChanged("ProductType") 					//	from Item
                    && PRODUCTTYPE_Item.Equals(Get_ValueOld("ProductType")))))
            {
                MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName());
                Decimal OnHand = Env.ZERO;
                Decimal Ordered = Env.ZERO;
                Decimal Reserved = Env.ZERO;
                for (int i = 0; i < storages.Length; i++)
                {
                    OnHand = Decimal.Add(OnHand, (storages[i].GetQtyOnHand()));
                    Ordered = Decimal.Add(OnHand, (storages[i].GetQtyOrdered()));
                    Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved()));
                }
                String errMsg = "";
                if (Env.Signum(OnHand) != 0)
                    errMsg = "@QtyOnHand@ = " + OnHand;
                if (Env.Signum(Ordered) != 0)
                    errMsg += " - @QtyOrdered@ = " + Ordered;
                if (Env.Signum(Reserved) != 0)
                    errMsg += " - @QtyReserved@" + Reserved;
                if (errMsg.Length > 0)
                {
                    log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg));
                    return false;
                }
            }	//	storage

            //	Reset Stocked if not Item
            if (IsStocked() && !PRODUCTTYPE_Item.Equals(GetProductType()))
                SetIsStocked(false);

            //	UOM reset
            if (_precision != null && Is_ValueChanged("C_UOM_ID"))
                _precision = null;
            if (Util.GetValueOfInt(Env.GetCtx().GetContext("#AD_User_ID")) != 100)
            {
                if (Is_ValueChanged("C_UOM_ID") || Is_ValueChanged("M_AttributeSet_ID"))
                {
                    string uqry = "SELECT SUM(cc) as count FROM  (SELECT COUNT(*) AS cc FROM M_MovementLine WHERE M_Product_ID = " + GetM_Product_ID() + @"  UNION
                SELECT COUNT(*) AS cc FROM M_InventoryLine WHERE M_Product_ID = " + GetM_Product_ID() + " UNION SELECT COUNT(*) AS cc FROM C_OrderLine WHERE M_Product_ID = " + GetM_Product_ID() +
                    " UNION  SELECT COUNT(*) AS cc FROM M_InOutLine WHERE M_Product_ID = " + GetM_Product_ID() + ") t";
                    int no = Util.GetValueOfInt(DB.ExecuteScalar(uqry));
                    if (no == 0 || IsBOM())
                    {
                        uqry = "SELECT count(*) FROM M_ProductionPlan WHERE M_Product_ID = " + GetM_Product_ID();
                        no = Util.GetValueOfInt(DB.ExecuteScalar(uqry));
                    }
                    if (no > 0)
                    {
                        log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "Could not Save Record. Transactions available in System."));
                        return false;
                    }
                }
            }
            if (newRecord)
            {
                //string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual";
                //int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));

                int manu_ID = UpcUniqueClientWise(GetAD_Client_ID(), GetUPC());
                if (manu_ID > 0)
                {
                    _log.SaveError("UPCUnique", "");
                    return false;
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(GetUPC()) &&
                   Util.GetValueOfString(Get_ValueOld("UPC")) != GetUPC())
                {
                    //string sql = "SELECT UPCUNIQUE('p','" + 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 = UpcUniqueClientWise(GetAD_Client_ID(), GetUPC());
                    if (manu_ID > 0)
                    {
                        _log.SaveError("UPCUnique", "");
                        return false;
                    }
                }
            }
            return true;
        }