コード例 #1
0
ファイル: RollupManager.cs プロジェクト: agopal128-zz/dms
        /// <summary>
        /// Add/update a monthly rollup entry
        /// </summary>
        /// <param name="parentActual">Parent's actual(rolled up value)</param>
        /// <param name="parentMonthlyActualId">Id of the parent actual entry</param>
        /// <param name="rollupInfo">Rollup information</param>
        private void AddOrUpdateMonthlyRollupEntry(decimal?parentActual,
                                                   int?parentMonthlyActualId, RollupInfo rollupInfo)
        {
            ActualItem rollupEntry = new ActualItem();

            rollupEntry.ActualValue = parentActual;
            // Assign target and scorecard id
            rollupEntry.TargetId    = rollupInfo.ParentTargetId.Value;
            rollupEntry.ScorecardId = rollupInfo.ParentScorecardId;

            // Retrieves the monthly goal for the parent
            rollupEntry.GoalValue = goalCalculator.GetMonthlyGoal(
                rollupInfo.ParentTargetId.Value, rollupInfo.ActualEntry.Date.Month);
            rollupEntry.Date = rollupInfo.ActualEntry.Date;

            if (parentMonthlyActualId.HasValue)
            {
                rollupEntry.Id = parentMonthlyActualId.Value;
                actualsModifier.UpdateMonthlyActual(rollupEntry, rollupInfo.GoalTypeId,
                                                    rollupInfo.Username);
            }
            else
            {
                actualsModifier.AddMonthlyActual(rollupEntry, rollupInfo.GoalTypeId,
                                                 rollupInfo.Username);
            }
        }
コード例 #2
0
        /// <summary>
        /// Tracks the recordable date.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="actualRequestDate">The actual request date.</param>
        public void TrackRecordables(int targetId, ActualItem actualRequest, string userName)
        {
            Target target = targetRepository.Get(targetId);

            DateTime recordableDate = actualRequest.Date;
            DateTime currentDate    = TimeZoneUtility.GetCurrentTimestamp().Date;
            int      loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;

            // if tracking method is monthly and actual entry month and current month is same
            // set recordable date as current date
            if (target.TrackingMethodId == Constants.TrackingMethodMonthly &&
                actualRequest.Date.Month == currentDate.Month)
            {
                recordableDate = currentDate;
            }

            if (actualRequest.ActualValue > 0)
            {
                AddOrUpdateRecordable(target, recordableDate, loggedInUserId);
            }
            else
            {
                if (target.TrackingMethodId == Constants.TrackingMethodMonthly)
                {
                    DeleteRecordablesOfMonth(target, recordableDate, loggedInUserId);
                }
                else
                {
                    DeleteRecordablesOfDay(target, recordableDate, loggedInUserId);
                }
            }

            recordableRepository.Save();
        }
コード例 #3
0
        /// <summary>
        /// Adjusts(add or update)monthly actual when adding a new daily actual
        /// </summary>
        /// <param name="actualRequest">actual request</param>
        /// <param name="goalTypeId">goal type id</param>
        /// <param name="dataTypeId">data type id</param>
        /// <param name="loggedInUserId">logged in user id</param>
        /// <returns>Adjusted monthly Actual Entity after including daily target</returns>
        private MonthlyActual AdjustMonthlyActual(ActualItem actualRequest, int goalTypeId,
                                                  int dataTypeId, int loggedInUserId)
        {
            // Get existing monthly actual entry if exists
            var existingMonthlyActual = monthlyActualRepository.GetAll().FirstOrDefault(x =>
                                                                                        x.TargetId == actualRequest.TargetId &&
                                                                                        x.Month == actualRequest.Date.Month);

            if (existingMonthlyActual != null)
            {
                // updating existing monthly actual
                return(UpdateExistingMonthlyActualOfDailyActual(existingMonthlyActual,
                                                                actualRequest, goalTypeId, dataTypeId, loggedInUserId));
            }
            else
            {
                DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp();
                // get monthly target
                decimal?monthlyTarget = goalCalculator.GetMonthlyGoal(actualRequest.TargetId,
                                                                      actualRequest.Date.Month);
                // Assign the monthly target instead of daily target, because we
                // need to create monthly actual here
                actualRequest.GoalValue = monthlyTarget;
                return(CreateMonthlyActual(actualRequest, goalTypeId, loggedInUserId));
            }
        }
コード例 #4
0
        /// <summary>
        /// Method to add new actual entry
        /// </summary>
        /// <param name="actualRequest">Daily actual request</param>
        /// <param name="goalTypeId">Metric goal type id</param>
        /// <param name="dataTypeId">Data type id</param>
        /// <param name="userName">Logged in user name</param>
        /// <returns>Newly created Entity Id</returns>
        public virtual int AddDailyActual(ActualItem actualRequest, int goalTypeId,
                                          int dataTypeId, string userName)
        {
            // Get logged in user id
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;

            var     target = targetRepository.Get(actualRequest.TargetId);
            decimal?actualValueToBeCompared = actualRequest.ActualValue;
            decimal?goalValueToBeCompared   = actualRequest.GoalValue;
            decimal?goalValueToBeSaved      = actualRequest.GoalValue;

            //get cumulative actual & goal value that needs to be compared in case of cumulative plotting
            if (target.GraphPlottingMethodId == Constants.GraphPlottingMethodCumulative)
            {
                actualValueToBeCompared = actualCalculator.CalculateCumulativeActual(
                    actualRequest.TargetId, actualRequest.Date, actualRequest.ActualValue);
                goalValueToBeCompared = goalCalculator.CalculateCumulativeGoal(
                    target, actualRequest.Date);
                goalValueToBeSaved = goalCalculator.GetDailyGoal(actualRequest.TargetId,
                                                                 actualRequest.Date.Month, actualRequest.Date.Day);
            }

            DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp();
            // Creating daily actual entity
            var dailyActual = new DailyActual()
            {
                Date        = actualRequest.Date,
                GoalValue   = goalValueToBeSaved,
                ActualValue = actualRequest.ActualValue,
                Status      = (actualValueToBeCompared.HasValue) ? TargetActualComparer.GetActualStatus(
                    goalValueToBeCompared, actualValueToBeCompared, goalTypeId)
                    : ActualStatus.NotEntered,
                TargetId       = actualRequest.TargetId,
                CreatedOn      = curTimestamp,
                LastModifiedOn = curTimestamp,
                CreatedBy      = loggedInUserId,
                LastModifiedBy = loggedInUserId
            };

            dailyActual.DailyActualHistory = new List <DailyActualHistory>()
            {
                ActualConverters.ConvertDailyActualToDailyActualHistory(dailyActual)
            };

            // Add/Update corresponding monthly actual
            var monthlyActual = AdjustMonthlyActual(actualRequest, goalTypeId,
                                                    dataTypeId, loggedInUserId);

            // If it is a new monthly actual entry, add explicitly
            if (monthlyActual.Id == 0)
            {
                monthlyActualRepository.AddOrUpdate(monthlyActual);
            }

            dailyActualRepository.AddOrUpdate(dailyActual);
            dailyActualRepository.Save();
            return(dailyActual.Id);
        }
コード例 #5
0
        /// <summary>
        /// Add a new monthly actual entry
        /// </summary>
        /// <param name="actualRequest">Monthly actual request</param>
        /// <param name="goalTypeId">Metric goal type id</param>
        /// <param name="username">Logged in user name</param>
        /// <returns>Newly created Entity Id</returns>
        public virtual int AddMonthlyActual(ActualItem actualRequest, int goalTypeId,
                                            string username)
        {
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == username)?.Id ?? 0;
            var monthlyActual = CreateMonthlyActual(actualRequest, goalTypeId, loggedInUserId);

            monthlyActualRepository.AddOrUpdate(monthlyActual);
            monthlyActualRepository.Save();
            return(monthlyActual.Id);
        }
コード例 #6
0
        /// <summary>
        /// Method to update daily actual and monthly entry
        /// </summary>
        /// <param name="actualRequest">daily actual request</param>
        /// <param name="goalTypeId">metric goal type id</param>
        /// <param name="dataTypeId">metric data type id</param>
        /// <param name="userName">logged in user name</param>
        public virtual void UpdateDailyActual(ActualItem actualRequest, int goalTypeId,
                                              int dataTypeId, string userName)
        {
            //get logged in user id
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;
            //get existing daily actual
            var existingDailyActual = dailyActualRepository.Get(actualRequest.Id.Value);

            var     target = targetRepository.Get(actualRequest.TargetId);
            decimal?actualValueToBeCompared = actualRequest.ActualValue;
            decimal?goalValueToBeCompared   = actualRequest.GoalValue;
            decimal?goalValueToBeSaved      = actualRequest.GoalValue;

            //get cumulative actual & goal value that needs to be compared in case of cumulative plotting
            if (target.GraphPlottingMethodId == Constants.GraphPlottingMethodCumulative)
            {
                actualValueToBeCompared = actualCalculator.CalculateCumulativeActual(
                    actualRequest.TargetId, actualRequest.Date, actualRequest.ActualValue);
                goalValueToBeCompared = goalCalculator.CalculateCumulativeGoal(
                    target, actualRequest.Date);
                goalValueToBeSaved = goalCalculator.GetDailyGoal(actualRequest.TargetId,
                                                                 actualRequest.Date.Month, actualRequest.Date.Day);
            }

            //update daily actual with new changes
            existingDailyActual.ActualValue = actualRequest.ActualValue;
            existingDailyActual.GoalValue   = goalValueToBeSaved;
            existingDailyActual.Status      = (actualValueToBeCompared.HasValue) ?
                                              TargetActualComparer.GetActualStatus(goalValueToBeCompared,
                                                                                   actualValueToBeCompared, goalTypeId) : ActualStatus.NotEntered;
            existingDailyActual.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            existingDailyActual.LastModifiedBy = loggedInUserId;
            //add history of daily actual
            existingDailyActual.DailyActualHistory.Add(
                ActualConverters.ConvertDailyActualToDailyActualHistory(existingDailyActual));

            // Add/Update corresponding monthly actual
            var monthlyActual = AdjustMonthlyActual(actualRequest, goalTypeId,
                                                    dataTypeId, loggedInUserId);

            // If it is a new monthly actual entry, add explicitly
            if (monthlyActual.Id == 0)
            {
                monthlyActualRepository.AddOrUpdate(monthlyActual);
            }

            dailyActualRepository.Save();
        }
コード例 #7
0
ファイル: ActualUtility.cs プロジェクト: agopal128-zz/dms
        /// <summary>
        /// Round the actual item to two decimal places
        /// </summary>
        /// <param name="actualItem">Input actual item to round</param>
        public static void RoundActualItem(ActualItem actualItem)
        {
            // Round the actual value to two decimal places
            if (actualItem.ActualValue != null)
            {
                actualItem.ActualValue = decimal.Round(actualItem.ActualValue.Value,
                                                       2, MidpointRounding.AwayFromZero);
            }

            // Round the goal value to two decimal places
            if (actualItem.GoalValue != null)
            {
                actualItem.GoalValue = decimal.Round(actualItem.GoalValue.Value,
                                                     2, MidpointRounding.AwayFromZero);
            }
        }
コード例 #8
0
        /// <summary>
        /// Method to update monthly actual entry
        /// </summary>
        /// <param name="actualRequest">daily actual request</param>
        /// <param name="goalTypeId">metric goal type id</param>
        /// <param name="userName">logged in user name</param>
        public virtual void UpdateMonthlyActual(ActualItem actualRequest, int goalTypeId, string userName)
        {
            //get logged in user id
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName)?.Id ?? 0;
            var monthlyActual = monthlyActualRepository.Get(actualRequest.Id.Value);

            monthlyActual.ActualValue = actualRequest.ActualValue;
            monthlyActual.Status      = TargetActualComparer.GetActualStatus(actualRequest.GoalValue,
                                                                             actualRequest.ActualValue, goalTypeId);
            monthlyActual.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            monthlyActual.LastModifiedBy = loggedInUserId;
            monthlyActual.MonthlyActualHistory.Add(
                ActualConverters.ConvertMonthlyActualToMonthlyActualHistory(monthlyActual));
            monthlyActualRepository.Save();
        }
コード例 #9
0
ファイル: ListMatcher.cs プロジェクト: skolima/fitsharp
            public void ShowSurplus(CellProcessor processor, Parse theLastRow)
            {
                Parse lastRow = theLastRow;

                for (int i = 0; i < myActuals.Count;)
                {
                    ActualItem surplus = myActuals[i];
                    if (surplus.MatchRow != null)
                    {
                        i++;
                        continue;
                    }
                    Parse surplusRow = MakeSurplusRow(processor, surplus.Value);
                    lastRow.More = surplusRow;
                    lastRow      = surplusRow;
                    myActuals.RemoveAt(i);
                }
            }
コード例 #10
0
ファイル: ActualsController.cs プロジェクト: agopal128-zz/dms
        public IHttpActionResult PutActual(ActualItem actualRequest)
        {
            //if user is kpi owner not an admin, check if he is the kpi owner/team member of the given
            //scorecard else return unauthorized
            if (IsUserKPIOwnerOrTeamMemberNotAdmin())
            {
                bool isUserKPIOwnerOfScorecard = userManager.
                                                 IsUserKPIOwnerOfScorecard(Username, actualRequest.ScorecardId.Value);
                bool isUserTeamMemberOfScorecard = userManager.
                                                   IsUserTeamMemberOfScorecard(Username, actualRequest.ScorecardId.Value);
                if (!isUserKPIOwnerOfScorecard && !isUserTeamMemberOfScorecard)
                {
                    return(Unauthorized());
                }
            }

            actualsManager.UpdateActual(actualRequest, Username);
            return(Ok());
        }
コード例 #11
0
ファイル: RollupManager.cs プロジェクト: agopal128-zz/dms
        /// <summary>
        /// Performs roll up for an actual entry
        /// </summary>
        /// <param name="actualEntry">Actual entry to rollup</param>
        /// <param name="username">Logged in user name</param>
        public virtual void PerformRollup(ActualItem actualEntry, bool updateRecordable, string username)
        {
            // Find target with the given id
            var target = targetRepository.Get(actualEntry.TargetId);

            if (target.ParentTargetId != null)
            {
                // Fill the parameters needed for rollup operation
                RollupInfo rollupInfo = new RollupInfo();
                rollupInfo.ActualEntry       = actualEntry;
                rollupInfo.Username          = username;
                rollupInfo.ParentTargetId    = target.ParentTargetId;
                rollupInfo.ParentScorecardId = target.ParentTarget.ScorecardId;
                rollupInfo.RollupMethodId    = target.ParentTarget.RollUpMethodId;
                rollupInfo.DataTypeId        = target.Metric.DataTypeId;
                rollupInfo.GoalTypeId        = target.Metric.GoalTypeId;
                rollupInfo.TrackingMethodId  = target.TrackingMethodId;
                rollupInfo.UpdateRecordable  = updateRecordable;

                // Invoke the recursive rollup operation
                RollupRecursively(rollupInfo);
            }
        }
コード例 #12
0
        /// <summary>
        /// Create MonthlyActual entity from ActualEntry request
        /// </summary>
        /// <param name="actualRequest">Actual entry</param>
        /// <param name="goalTypeId">Goal type id</param>
        /// <param name="loggedInUserId">Logged in user id</param>
        /// <returns></returns>
        private MonthlyActual CreateMonthlyActual(ActualItem actualRequest, int goalTypeId,
                                                  int loggedInUserId)
        {
            DateTime curTimestamp  = TimeZoneUtility.GetCurrentTimestamp();
            var      monthlyActual = new MonthlyActual()
            {
                Month       = actualRequest.Date.Month,
                ActualValue = actualRequest.ActualValue,
                Status      = TargetActualComparer.GetActualStatus(actualRequest.GoalValue,
                                                                   actualRequest.ActualValue, goalTypeId),
                TargetId       = actualRequest.TargetId,
                CreatedOn      = curTimestamp,
                LastModifiedOn = curTimestamp,
                CreatedBy      = loggedInUserId,
                LastModifiedBy = loggedInUserId
            };

            monthlyActual.MonthlyActualHistory = new List <MonthlyActualHistory>()
            {
                ActualConverters.ConvertMonthlyActualToMonthlyActualHistory(monthlyActual)
            };
            return(monthlyActual);
        }
コード例 #13
0
        /// <summary>
        /// Update existing monthly actual while adding or updating daily actuals
        /// </summary>
        /// <param name="existingActual">existing monthly actual</param>
        /// <param name="actualUpdRequest">Actual update request</param>
        /// <param name="goalTypeId">goal type id</param>
        /// <param name="dataTypeId">data type id</param>
        /// <param name="loggedInUserId">logged in user id</param>
        /// <returns>Updated monthly actual</returns>
        public virtual MonthlyActual UpdateExistingMonthlyActualOfDailyActual(
            MonthlyActual existingActual, ActualItem actualUpdRequest,
            int goalTypeId, int dataTypeId, int loggedInUserId)
        {
            //set monthly actual value as sum of daily actuals in case
            //metric data type is amount/whole number
            if (dataTypeId == Constants.DataTypeAmount ||
                dataTypeId == Constants.DataTypeWholeNumber ||
                dataTypeId == Constants.DataTypeDecimalNumber)
            {
                if (actualUpdRequest.ActualValue != null)
                {
                    existingActual.ActualValue = FindSumOfDailyActualsExcludingCurrentEntryDate
                                                     (actualUpdRequest.TargetId, actualUpdRequest.Date) +
                                                 actualUpdRequest.ActualValue.Value;
                }
            }
            else
            {
                existingActual.ActualValue = actualUpdRequest.ActualValue;
            }

            existingActual.LastModifiedBy = loggedInUserId;
            existingActual.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            decimal?monthlyTarget = goalCalculator.GetMonthlyGoal(actualUpdRequest.TargetId,
                                                                  actualUpdRequest.Date.Month);

            existingActual.Status = TargetActualComparer.GetActualStatus(monthlyTarget,
                                                                         existingActual.ActualValue, goalTypeId);

            // Add the history as well
            existingActual.MonthlyActualHistory.Add(
                ActualConverters.ConvertMonthlyActualToMonthlyActualHistory(existingActual));

            return(existingActual);
        }
コード例 #14
0
        public async Task <bool> UpdateActualItem(string userId, ActualItem actualItem)
        {
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    return(false);
                }

                // The budget category associated with the budget item
                var budgetCategory
                    = await _context.budgetCategories
                      .FirstOrDefaultAsync(
                          bc => bc.BudgetCategoryId == actualItem.BudgetCategoryId);

                // Does the user own the budget category
                if (budgetCategory == null ||
                    budgetCategory.UserId != userId)
                {
                    // return false, the user doesn't own the budget category
                    return(false);
                }

                var budgetPeriod
                    = await _context.budgetPeriods
                      .FirstOrDefaultAsync(
                          bp => bp.BudgetPeriodId == actualItem.BudgetPeriodId);

                if (budgetPeriod == null ||
                    budgetPeriod.UserId != userId)
                {
                    // return false, the user doesn't own the budget period
                    return(false);
                }

                // Everything is good, update the item

                // Get the current item
                var currentActualItem
                    = await _context.actualItems
                      .FirstOrDefaultAsync(ai => ai.ActualItemId == actualItem.ActualItemId);

                // Update the current item
                currentActualItem.UserId           = userId;
                currentActualItem.BudgetCategoryId = actualItem.BudgetCategoryId;
                currentActualItem.BudgetPeriodId   = actualItem.BudgetPeriodId;
                currentActualItem.Date             = actualItem.Date;
                currentActualItem.Amount           = actualItem.Amount;
                currentActualItem.TransactionType  = actualItem.TransactionType;
                _context.actualItems.Update(currentActualItem);

                // Save the item changes
                if (await _context.SaveChangesAsync() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                // Something bad happened, return false
                return(false);
            }
        }