示例#1
0
 private List <PlanningAppState> RollbackDueByDates(int daysDiff, PlanningAppState current)
 {
     return(PlanningAppStates
            .Where(s => s.DueByDate > current.DueByDate)
            .Select(c => { c.DueByDate = c.DueByDate.AddBusinessDays(-daysDiff); return c; })
            .ToList());
 }
示例#2
0
        public void NextState(List <StateStatus> statusList)
        {
            if (!Completed())
            {
                PlanningAppStates = PlanningAppStates.OrderBy(s => s.state.OrderId).ToList();

                var currentDate = SystemDate.Instance.date;
                var prevState   = Current(); //Store reference to current state

                if (!isLastState(prevState))
                {
                    SeekNext().CurrentState = true;               //move to next state
                }
                prevState.CompleteState(currentDate, statusList); //Close out previouse state
                //If Overran then roll all future completion dates by business days overdue
                if (currentDate > prevState.DueByDate)
                {
                    var daysDiff = prevState.DueByDate.GetBusinessDays(currentDate, new List <DateTime>());
                    RollForwardDueByDates(daysDiff, prevState);
                }
            }
            if (Completed())
            {
                CurrentPlanningStatus = statusList.Where(s => s.Name == StatusList.Complete).SingleOrDefault();
            }
        }
示例#3
0
        public void generateDueByDates()
        {
            if (!Completed())
            {
                //Important - put states in order before processing!!
                PlanningAppStates = PlanningAppStates.OrderBy(s => s.state.OrderId).ToList();
                var prevState    = new PlanningAppState();
                var currState    = Current();
                var resetCurrent = Current();

                while (currState != null)
                {
                    if (!isFirstState(currState))
                    {
                        prevState = SeekPrev();
                        currState.AggregateDueByDate(prevState);
                    }
                    else
                    {
                        currState.SetDueByDate();
                    }

                    currState = Next(currState);
                }
                //Set original state
                SetCurrent(resetCurrent);
            }
        }
示例#4
0
 public void SetCurrent(PlanningAppState planningAppState)
 {
     foreach (var state  in PlanningAppStates)
     {
         state.CurrentState = false;
     }
     PlanningAppStates[PlanningAppStates.IndexOf(planningAppState)].CurrentState = true;
 }
示例#5
0
 private void RollForwardDueByDates(int daysDiff, PlanningAppState prevState)
 {
     if (!Completed())
     {
         PlanningAppStates
         .Where(s => s.DueByDate > prevState.DueByDate)
         .Select(c => { c.DueByDate = c.DueByDate.AddBusinessDays(daysDiff); return(c); })
         .ToList();
     }
 }
示例#6
0
 public PlanningAppState SeekNext()
 {
     if (!Completed() && !isLastState(Current()))
     {
         return(PlanningAppStates[PlanningAppStates.IndexOf(Current()) + 1]);
     }
     else
     {
         return(null);
     }
 }
示例#7
0
 public PlanningAppState SeekPrev(PlanningAppState planningAppState) //Get previous state based on specified State
 {
     if (!Completed() && !isFirstState(planningAppState))
     {
         return(PlanningAppStates[PlanningAppStates.IndexOf(planningAppState) - 1]);
     }
     else
     {
         return(null);
     }
 }
示例#8
0
 public PlanningAppState SeekPrev()  //Get previous state based on CurrentState
 {
     if (!Completed() && !isFirstState(Current()))
     {
         return(PlanningAppStates[PlanningAppStates.IndexOf(Current()) - 1]);
     }
     else
     {
         return(null);
     }
 }
示例#9
0
        public PlanningAppState Next(PlanningAppState planningAppState)
        {
            PlanningAppState nextState = new PlanningAppState();

            if (!isLastState(planningAppState))
            {
                nextState = PlanningAppStates[PlanningAppStates.IndexOf(planningAppState) + 1];
                planningAppState.CurrentState = false;
                nextState.CurrentState        = true;
                return(nextState);
            }
            else
            {
                return(null);
            }
        }
示例#10
0
        public PlanningApp GeneratePlanningStates(List <StateInitialiserState> stateInitialisers,
                                                  IEnumerable <StateStatus> stateStatus)
        {
            var currentDate = SystemDate.Instance.date;

            foreach (var stateInialiser in stateInitialisers)
            {
                PlanningAppState newPlanningAppState = new PlanningAppState();
                newPlanningAppState.state = stateInialiser;

                PlanningAppState prevState;
                var stateCount = PlanningAppStates.Count;
                if (stateCount > 0)
                {
                    prevState = PlanningAppStates[stateCount - 1];
                    newPlanningAppState.DueByDate = prevState.DueByDate.AddBusinessDays(stateInialiser.CompletionTime);
                }
                else
                {
                    newPlanningAppState.DueByDate = currentDate.AddBusinessDays(stateInialiser.CompletionTime);
                }

                newPlanningAppState.StateStatus = stateStatus.Where(s => s.Name == StatusList.OnTime).SingleOrDefault();
                //Add custom fields to state if exist
                foreach (var stateInitialiserStateCustomField in newPlanningAppState.state.StateInitialiserStateCustomFields)
                {
                    newPlanningAppState.customFields
                    .Add(new PlanningAppStateCustomField {
                        StateInitialiserStateCustomFieldId = stateInitialiserStateCustomField.StateInitialiserCustomFieldId
                    });
                }
                PlanningAppStates.Add(newPlanningAppState);
            }
            //set first state to current state
            if (PlanningAppStates.Count > 0)
            {
                PlanningAppStates[0].CurrentState = true;
            }

            //Set overall Status to InProgress
            CurrentPlanningStatus = stateStatus.Where(s => s.Name == StatusList.AppInProgress).SingleOrDefault();

            return(this);
        }
示例#11
0
        public void updateDueByDates()  //Called when inserting a new state to an existing planning app
        {
            if (!Completed())
            {
                //Important - put states in order before processing!!
                PlanningAppStates = PlanningAppStates.OrderBy(s => s.state.OrderId).ToList();
                var prevState    = new PlanningAppState();
                var currState    = Current();
                var resetCurrent = Current();

                while (currState != null)
                {
                    if (!isFirstState(currState))
                    {
                        prevState = SeekPrev();
                        currState.AggregateDueByDate(prevState);
                    }
                    currState = Next(currState);
                }
                //Set original state
                SetCurrent(resetCurrent);
            }
        }
示例#12
0
        public PlanningApp InsertNewPlanningState(StateInitialiserState newStateInitialiser, IEnumerable <StateStatus> stateStatus)
        {
            if (!Completed())
            {
                var currentState = Current();

                if (newStateInitialiser.OrderId > currentState.state.OrderId)
                {
                    //Remove states after current state
                    var states = this.PlanningAppStates.ToList();

                    PlanningAppState newState = new PlanningAppState();
                    newState.state          = newStateInitialiser;
                    newState.CurrentState   = false;
                    newState.StateStatus    = stateStatus.Where(s => s.Name == StatusList.OnTime).SingleOrDefault();
                    newState.CompletionDate = null;
                    newState.DueByDate      = DateTime.Now;
                    PlanningAppStates.Add(newState);

                    updateDueByDates();
                }
            }
            return(this);
        }
示例#13
0
 private PlanningAppState FirstState(PlanningAppState planningAppState)
 {
     return(PlanningAppStates.Count() > 0 ? PlanningAppStates[0] : null);
 }
示例#14
0
 private PlanningAppState SeekLastState()
 {
     return(PlanningAppStates.Count() > 0 ? PlanningAppStates[PlanningAppStates.Count() - 1] : null);
 }
示例#15
0
 public bool isFirstState(PlanningAppState planningAppState)
 {
     return(PlanningAppStates.IndexOf(planningAppState) == 0);
 }
示例#16
0
 public bool isLastState(PlanningAppState planningAppState)
 {
     return(PlanningAppStates.Count() == (PlanningAppStates.IndexOf(planningAppState) + 1));
 }
示例#17
0
 public PlanningAppState Current()
 {
     return(PlanningAppStates.Where(s => s.CurrentState == true).SingleOrDefault());
 }
示例#18
0
 public bool Completed()
 {
     return(PlanningAppStates.Where(p => p.CurrentState == true).Count() == 0);
 }