示例#1
0
        /**
         *  Get Goals with Measure
         *	@param ctx context
         *	@param PA_Measure_ID measure
         *	@return goals
         */
        public static MGoal[] GetMeasureGoals(Ctx ctx, int PA_Measure_ID)
        {
            List <MGoal> list = new List <MGoal>();
            String       sql  = "SELECT * FROM PA_Goal WHERE IsActive='Y' AND PA_Measure_ID= " + PA_Measure_ID
                                + " ORDER BY SeqNo";
            DataTable   dt;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MGoal(ctx, dr, null));
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally { dt = null; }

            MGoal[] retValue = new MGoal[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
示例#2
0
 /**
  *  Create Test Goals
  *	@param ctx context
  *	@return array of goals
  */
 public static MGoal[] GetTestGoals(Ctx ctx)
 {
     MGoal[] retValue = new MGoal[4];
     retValue[0] = new MGoal(ctx, "Test 1", "Description 1", new Decimal(1000), null);
     retValue[0].SetMeasureActual(new Decimal(200));
     retValue[1] = new MGoal(ctx, "Test 2", "Description 2", new Decimal(1000), null);
     retValue[1].SetMeasureActual(new Decimal(900));
     retValue[2] = new MGoal(ctx, "Test 3", "Description 3", new Decimal(1000), null);
     retValue[2].SetMeasureActual(new Decimal(1200));
     retValue[3] = new MGoal(ctx, "Test 4", "Description 4", new Decimal(1000), null);
     retValue[3].SetMeasureActual(new Decimal(3200));
     return(retValue);
 }
示例#3
0
        }       //	updateManualGoals

        /**
         *  Update/save Goals with Achievement
         *  @return true if updated
         */
        private Boolean UpdateAchievementGoals()
        {
            if (!MEASURETYPE_Achievements.Equals(GetMeasureType()))
            {
                return(false);
            }
            DateTime today = DateTime.Now;

            MGoal[] goals = MGoal.GetMeasureGoals(GetCtx(), GetPA_Measure_ID());
            for (int i = 0; i < goals.Length; i++)
            {
                MGoal  goal         = goals[i];
                String MeasureScope = goal.GetMeasureScope();
                String trunc        = TimeUtil.TRUNC_DAY;
                if (MGoal.MEASUREDISPLAY_Year.Equals(MeasureScope))
                {
                    trunc = TimeUtil.TRUNC_YEAR;
                }
                else if (MGoal.MEASUREDISPLAY_Quarter.Equals(MeasureScope))
                {
                    trunc = TimeUtil.TRUNC_QUARTER;
                }
                else if (MGoal.MEASUREDISPLAY_Month.Equals(MeasureScope))
                {
                    trunc = TimeUtil.TRUNC_MONTH;
                }
                else if (MGoal.MEASUREDISPLAY_Week.Equals(MeasureScope))
                {
                    trunc = TimeUtil.TRUNC_WEEK;
                }
                DateTime compare = TimeUtil.Trunc(today, trunc);
                //
                MAchievement[] achievements = MAchievement.GetOfMeasure(GetCtx(), GetPA_Measure_ID());
                Decimal        ManualActual = Env.ZERO;
                for (int j = 0; j < achievements.Length; j++)
                {
                    MAchievement achievement = achievements[j];
                    if (achievement.IsAchieved() && achievement.GetDateDoc() != null)
                    {
                        DateTime ach = TimeUtil.Trunc(achievement.GetDateDoc(), trunc);
                        if (compare.Equals(ach))
                        {
                            ManualActual = Decimal.Add(ManualActual, achievement.GetManualActual());
                        }
                    }
                }
                goal.SetMeasureActual(ManualActual);
                goal.Save();
            }
            return(true);
        }
示例#4
0
        /**
         *  Get User Goals
         *	@param ctx context
         *	@param AD_User_ID user
         *	@return array of goals
         */
        public static MGoal[] GetUserGoals(Ctx ctx, int AD_User_ID)
        {
            if (AD_User_ID < 0)
            {
                return(GetTestGoals(ctx));
            }
            List <MGoal> list = new List <MGoal>();
            String       sql  = "SELECT * FROM PA_Goal g "
                                + "WHERE IsActive='Y'"
                                + " AND AD_Client_ID=@ADClientID" //	#1
                                + " AND ((AD_User_ID IS NULL AND AD_Role_ID IS NULL)"
                                + " OR AD_User_ID=@ADUserID"      //	#2
                                + " OR EXISTS (SELECT * FROM AD_User_Roles ur "
                                + "WHERE g.AD_User_ID=ur.AD_User_ID AND g.AD_Role_ID=ur.AD_Role_ID AND ur.IsActive='Y')) "
                                + "ORDER BY SeqNo";
            DataTable   dt;
            IDataReader idr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@ADClientID", ctx.GetAD_Client_ID());
                param[1] = new SqlParameter("@ADUserID", AD_User_ID);

                idr = DataBase.DB.ExecuteReader(sql, null, null);

                dt = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    MGoal goal = new MGoal(ctx, dr, null);
                    goal.UpdateGoal(false);
                    list.Add(goal);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally { dt = null; }

            MGoal[] retValue = new MGoal[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
示例#5
0
        }       //	updateGoals

        /**
         *  Update/save Manual Goals
         *  @return true if updated
         */
        private Boolean UpdateManualGoals()
        {
            if (!MEASURETYPE_Manual.Equals(GetMeasureType()))
            {
                return(false);
            }
            MGoal[] goals = MGoal.GetMeasureGoals(GetCtx(), GetPA_Measure_ID());
            for (int i = 0; i < goals.Length; i++)
            {
                MGoal goal = goals[i];
                goal.SetMeasureActual(GetManualActual());
                goal.Save();
            }
            return(true);
        }       //	updateManualGoals
示例#6
0
        /**
         *  Get Accessible Goals
         *	@param ctx context
         *	@return array of goals
         */
        public static MGoal[] GetGoals(Ctx ctx)
        {
            List <MGoal> list = new List <MGoal>();
            String       sql  = "SELECT * FROM PA_Goal WHERE IsActive='Y' "
                                + "ORDER BY SeqNo";

            sql = MRole.GetDefault(ctx, false).AddAccessSQL(sql, "PA_Goal",
                                                            false, true); //	RW to restrict Access
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    MGoal goal = new MGoal(ctx, dr, null);
                    goal.UpdateGoal(false);
                    list.Add(goal);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
            }
            MGoal[] retValue = new MGoal[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
示例#7
0
        /**
         *  Get Multiplier from Scope to Display
         *	@param goal goal
         *	@return null if error or multiplier
         */
        public static Decimal?GetMultiplier(MGoal goal)
        {
            String MeasureScope   = goal.GetMeasureScope();
            String MeasureDisplay = goal.GetMeasureDisplay();

            if (MeasureDisplay == null ||
                MeasureScope.Equals(MeasureDisplay))
            {
                return(Env.ONE);         //	1:1
            }
            if (MeasureScope.Equals(MEASURESCOPE_Total) ||
                MeasureDisplay.Equals(MEASUREDISPLAY_Total))
            {
                return(null);            //	Error
            }
            Decimal?Multiplier = null;

            if (MeasureScope.Equals(MEASURESCOPE_Year))
            {
                if (MeasureDisplay.Equals(MEASUREDISPLAY_Quarter))
                {
                    Multiplier = new Decimal(1.0 / 4.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Month))
                {
                    Multiplier = new Decimal(1.0 / 12.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Week))
                {
                    Multiplier = new Decimal(1.0 / 52.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Day))
                {
                    Multiplier = new Decimal(1.0 / 364.0);
                }
            }
            else if (MeasureScope.Equals(MEASURESCOPE_Quarter))
            {
                if (MeasureDisplay.Equals(MEASUREDISPLAY_Year))
                {
                    Multiplier = new Decimal(4.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Month))
                {
                    Multiplier = new Decimal(1.0 / 3.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Week))
                {
                    Multiplier = new Decimal(1.0 / 13.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Day))
                {
                    Multiplier = new Decimal(1.0 / 91.0);
                }
            }
            else if (MeasureScope.Equals(MEASURESCOPE_Month))
            {
                if (MeasureDisplay.Equals(MEASUREDISPLAY_Year))
                {
                    Multiplier = new Decimal(12.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Quarter))
                {
                    Multiplier = new Decimal(3.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Week))
                {
                    Multiplier = new Decimal(1.0 / 4.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Day))
                {
                    Multiplier = new Decimal(1.0 / 30.0);
                }
            }
            else if (MeasureScope.Equals(MEASURESCOPE_Week))
            {
                if (MeasureDisplay.Equals(MEASUREDISPLAY_Year))
                {
                    Multiplier = new Decimal(52.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Quarter))
                {
                    Multiplier = new Decimal(13.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Month))
                {
                    Multiplier = new Decimal(4.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Day))
                {
                    Multiplier = new Decimal(1.0 / 7.0);
                }
            }
            else if (MeasureScope.Equals(MEASURESCOPE_Day))
            {
                if (MeasureDisplay.Equals(MEASUREDISPLAY_Year))
                {
                    Multiplier = new Decimal(364.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Quarter))
                {
                    Multiplier = new Decimal(91.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Month))
                {
                    Multiplier = new Decimal(30.0);
                }
                else if (MeasureDisplay.Equals(MEASUREDISPLAY_Week))
                {
                    Multiplier = new Decimal(7.0);
                }
            }
            return(Multiplier);
        }
示例#8
0
 /**
  *  Update/save Goals with Projects
  *  @return true if updated
  */
 private Boolean UpdateProjects()
 {
     if (!MEASURETYPE_Project.Equals(GetMeasureType()) ||
         GetC_ProjectType_ID() == 0)
     {
         return(false);
     }
     MGoal[] goals = MGoal.GetMeasureGoals(GetCtx(), GetPA_Measure_ID());
     for (int i = 0; i < goals.Length; i++)
     {
         MGoal goal = goals[i];
         //	Find Role
         MRole role = null;
         if (goal.GetAD_Role_ID() != 0)
         {
             role = MRole.Get(GetCtx(), goal.GetAD_Role_ID());
         }
         else if (goal.GetAD_User_ID() != 0)
         {
             MUser   user  = MUser.Get(GetCtx(), goal.GetAD_User_ID());
             MRole[] roles = user.GetRoles(goal.GetAD_Org_ID());
             if (roles.Length > 0)
             {
                 role = roles[0];
             }
         }
         if (role == null)
         {
             role = MRole.GetDefault(GetCtx(), false);   //	could result in wrong data
         }
         //
         Decimal?     ManualActual = null;
         MProjectType pt           = MProjectType.Get(GetCtx(), GetC_ProjectType_ID());
         String       sql          = pt.GetSqlPI(goal.GetRestrictions(false),
                                                 goal.GetMeasureScope(), GetMeasureDataType(), null, role);
         IDataReader idr = null;
         try             //	SQL statement could be wrong
         {
             idr = DataBase.DB.ExecuteReader(sql, null, null);
             if (idr.Read())
             {
                 ManualActual = Utility.Util.GetValueOfDecimal(idr[0]);
             }
             idr.Close();
         }
         catch (Exception e)
         {
             if (idr != null)
             {
                 idr.Close();
             }
             log.Log(Level.SEVERE, sql, e);
         }
         //	SQL may return no rows or null
         if (ManualActual == null)
         {
             ManualActual = Env.ZERO;
             log.Fine("No Value = " + sql);
         }
         goal.SetMeasureActual(ManualActual);
         goal.Save();
     }
     return(true);
 }