Ejemplo n.º 1
0
 /// <summary>
 /// Creates an instance of "Same As Child" rollup and returns
 /// </summary>
 /// <returns></returns>
 protected virtual IRollupStrategy CreateSameAsChildRollupStrategy()
 {
     if (sameAsChildRollup == null)
     {
         sameAsChildRollup = new SameAsChildRollup(dailyActualRepository,
                                                   monthlyActualRepository, targetRepository);
     }
     return(sameAsChildRollup);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates an instance of "Sum Of Children" rollup and returns
 /// </summary>
 /// <returns></returns>
 protected virtual IRollupStrategy CreateSumOfChildrenRollupStrategy()
 {
     if (sumOfChildrenRollup == null)
     {
         sumOfChildrenRollup = new SumOfChildrenRollup(
             dailyActualRepository, monthlyActualRepository, targetRepository);
     }
     return(sumOfChildrenRollup);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates an instance of "Average Of Children" rollup and returns
 /// </summary>
 /// <returns></returns>
 protected virtual IRollupStrategy CreateAverageOfChildrenRollupStrategy()
 {
     if (avgOfChildrenRollup == null)
     {
         avgOfChildrenRollup = new AverageOfChildrenRollup(dailyActualRepository,
                                                           monthlyActualRepository, targetRepository);
     }
     return(avgOfChildrenRollup);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Calculates the roll up value based on the rollup method set
        /// </summary>
        /// <param name="rollupInfo">Rollup information</param>
        /// <returns>Calculated rollup value</returns>
        private decimal?CalculateRollupTargetValue(RollupInfo rollupInfo)
        {
            decimal?rolledupValue = null;
            // Retrieve all child targets
            var childTargetIds = targetRepository.GetAll().Where(x =>
                                                                 x.ParentTargetId == rollupInfo.ParentTargetId &&
                                                                 x.IsActive).Select(y => y.Id).ToList();

            switch (rollupInfo.RollupMethodId)
            {
            // "Sum of Children"
            case Constants.RollupMethodSumOfChildren:
            {
                IRollupStrategy sumOfChildrenRollup = CreateSumOfChildrenRollupStrategy();
                rolledupValue = sumOfChildrenRollup.CalculateRollupTarget(rollupInfo,
                                                                          childTargetIds);
                break;
            }

            // "Average of Children"
            case Constants.RollupMethodAverageOfChildren:
            {
                IRollupStrategy avgOfChildrentRollup =
                    CreateAverageOfChildrenRollupStrategy();
                rolledupValue = avgOfChildrentRollup.CalculateRollupTarget(rollupInfo,
                                                                           childTargetIds);
                break;
            }

            // "Same as Child"
            case Constants.RollupMethodSameAsChild:
            {
                IRollupStrategy sameAsChildRollup = CreateSameAsChildRollupStrategy();
                rolledupValue = sameAsChildRollup.CalculateRollupTarget(rollupInfo,
                                                                        childTargetIds);
                break;
            }
            }

            // Round the rolled up value to two decimal places
            if (rolledupValue.HasValue)
            {
                var rollupValue = decimal.Round(rolledupValue.Value, 2, MidpointRounding.AwayFromZero);
                if (rollupInfo.DataTypeId == Constants.DataTypeWholeNumber)
                {
                    rollupValue = decimal.Round(rolledupValue.Value, 0, MidpointRounding.AwayFromZero);
                }

                return(rollupValue);
            }

            return(rolledupValue);
        }