示例#1
0
        /**
         *  Is Std Costing Method
         *	@return true if StandardCosting
         */
        public bool IsStandardCosting()
        {
            String cm = GetCostingMethod();

            return(cm != null &&
                   cm.Equals(COSTINGMETHOD_StandardCosting) &&
                   COSTELEMENTTYPE_Material.Equals(GetCostElementType()));
        }
示例#2
0
        /**
         *  Is User Costing Method
         *	@return true if User Defined
         */
        public bool IsUserDefined()
        {
            String cm = GetCostingMethod();

            return(cm != null &&
                   cm.Equals(COSTINGMETHOD_UserDefined) &&
                   COSTELEMENTTYPE_Material.Equals(GetCostElementType()));
        }
示例#3
0
        /**
         *  Is Last PO Costing Method
         *	@return true if LastPOPrice
         */
        public bool IsLastPOPrice()
        {
            String cm = GetCostingMethod();

            return(cm != null &&
                   cm.Equals(COSTINGMETHOD_LastPOPrice) &&
                   COSTELEMENTTYPE_Material.Equals(GetCostElementType()));
        }
示例#4
0
        /**
         *  Is Avg PO Costing Method
         *	@return true if AveragePO
         */
        public bool IsAveragePO()
        {
            String cm = GetCostingMethod();

            return(cm != null &&
                   cm.Equals(COSTINGMETHOD_AveragePO) &&
                   COSTELEMENTTYPE_Material.Equals(GetCostElementType()));
        }
示例#5
0
        /**
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            //	Check Unique Costing Method
            if (COSTELEMENTTYPE_Material.Equals(GetCostElementType()) &&
                (newRecord || Is_ValueChanged("CostingMethod")))
            {
                String sql = "SELECT COALESCE(MAX(M_CostElement_ID),0) FROM M_CostElement "
                             + "WHERE AD_Client_ID=" + GetAD_Client_ID() + " AND CostingMethod='" + GetCostingMethod() + "'";
                int id = Utility.Util.GetValueOfInt(DataBase.DB.ExecuteScalar(sql, null, null));
                if (id > 0 && id != Get_ID())
                {
                    log.SaveError("AlreadyExists", Msg.GetElement(GetCtx(), "CostingMethod"));
                    return(false);
                }
            }

            // when Element Type is "Cost Combination" then costing method will be "Cost Combination"
            if (COSTELEMENTTYPE_CostCombination.Equals(GetCostElementType()) &&
                !COSTINGMETHOD_CostCombination.Equals(GetCostingMethod()))
            {
                log.SaveError("WrongCostMethod", "");
                return(false);
            }

            //	Maintain Calclated
            if (COSTELEMENTTYPE_Material.Equals(GetCostElementType()))
            {
                String cm = GetCostingMethod();
                if (cm == null || cm.Length == 0 ||
                    COSTINGMETHOD_StandardCosting.Equals(cm))
                {
                    SetIsCalculated(false);
                }
                else
                {
                    SetIsCalculated(true);
                }
            }
            else if (!(COSTELEMENTTYPE_CostCombination.Equals(GetCostElementType())))
            {
                if (IsCalculated())
                {
                    SetIsCalculated(false);
                }
                if (GetCostingMethod() != null)
                {
                    SetCostingMethod(null);
                }
            }

            if (GetAD_Org_ID() != 0)
            {
                SetAD_Org_ID(0);
            }
            return(true);
        }
示例#6
0
 /**
  *  Is this a Costing Method
  *	@return true if not Material cost or no costing method.
  */
 public bool IsCostingMethod()
 {
     return(COSTELEMENTTYPE_Material.Equals(GetCostElementType()) &&
            GetCostingMethod() != null);
 }
示例#7
0
        /**
         *  Before Delete
         *	@return true if can be deleted
         */
        protected override bool BeforeDelete()
        {
            String cm = GetCostingMethod();

            if (cm == null ||
                !COSTELEMENTTYPE_Material.Equals(GetCostElementType()))
            {
                return(true);
            }

            //	Costing Methods on AS level
            MAcctSchema[] ass = MAcctSchema.GetClientAcctSchema(GetCtx(), GetAD_Client_ID());
            for (int i = 0; i < ass.Length; i++)
            {
                if (ass[i].GetCostingMethod().Equals(GetCostingMethod()))
                {
                    log.SaveError("CannotDeleteUsed", Msg.GetElement(GetCtx(), "C_AcctSchema_ID")
                                  + " - " + ass[i].GetName());
                    return(false);
                }
            }

            //	Costing Methods on PC level
            String      sql = "SELECT M_Product_Category_ID FROM M_Product_Category_Acct WHERE AD_Client_ID=" + GetAD_Client_ID() + " AND CostingMethod=@costingMethod";
            int         M_Product_Category_ID = 0;
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@costingMethod", GetCostingMethod());

                idr = DataBase.DB.ExecuteReader(sql, param, null);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    M_Product_Category_ID = Convert.ToInt32(dr[0]);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
            }

            if (M_Product_Category_ID != 0)
            {
                log.SaveError("CannotDeleteUsed", Msg.GetElement(GetCtx(), "M_Product_Category_ID")
                              + " (ID=" + M_Product_Category_ID + ")");
                return(false);
            }
            return(true);
        }