Exemple #1
0
        /// <summary>
        /// Gets the plan.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="salaries">The salaries.</param>
        /// <param name="userTarget">The user target.</param>
        /// <param name="simulationId">The simulation identifier.</param>
        /// <returns>
        /// returns plan view model
        /// </returns>
        private PlanViewModel GetPlan(UserModel user, Dictionary <FrequencyDetails, decimal> salaries, UserTargetModel userTarget, int simulationId)
        {
            var           applicationSetting = this.applicationSettings.GetApplicationSettingByKeyName(Constants.ApplicationSettingCodes.CryptoKey);
            PlanViewModel planViewModel      = new PlanViewModel();

            planViewModel = new PlanViewModel()
            {
                PlanId          = user.CurentPlan.Id,
                UserId          = user.Id,
                CountryId       = user.CountryId,
                BussinessUnitId = user.BusinessUnitId,
                RoleId          = user.CurentPlan.RoleId,
                Year            = user.CurentPlan.Year,
                Role            = user.CurentPlan.Name,
                PlanName        = user.CurentPlan.Name
            };

            UserSimulationModel userSimulation = null;

            if (userTarget != null && userTarget.UserSimulations.Count > 0)
            {
                planViewModel.SimulationId   = simulationId;
                planViewModel.SimulationName = userTarget.UserSimulations.Where(x => x.Id == simulationId).Select(x => x.Name).FirstOrDefault();
                planViewModel.TotalPayout    = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, userTarget.UserSimulations.Where(x => x.Id == simulationId).Select(x => x.TotalPayout).FirstOrDefault()));
                userSimulation = userTarget.UserSimulations.Where(x => x.Id == simulationId).FirstOrDefault();
            }

            foreach (var measure in user.CurentPlan.PlanMeasures)
            {
                MeassureViewModel meassureViewModel = new MeassureViewModel();
                meassureViewModel.Id                      = measure.Id;
                meassureViewModel.Name                    = measure.MeasureName;
                meassureViewModel.SequenceId              = measure.Sequence;
                meassureViewModel.PayoutCurveId           = measure.PayoutCurveId;
                meassureViewModel.PayoutTypeId            = measure.PayoutTypeId;
                meassureViewModel.PayoutCurve             = measure.PayoutCurve;
                meassureViewModel.Frequency               = measure.Frequency.Name;
                meassureViewModel.MeasureTargetPercentage = Convert.ToString(measure.MeasureWeightage);
                meassureViewModel.HasGoal                 = measure.HasGoal;
                meassureViewModel.DataType                = measure.DataType;
                meassureViewModel.ValueType               = measure.ValueType;
                meassureViewModel.IsKPI                   = measure.IsKPI;
                UserSimulationMeasureDetailModel userSimulationMeasureDetail = null;
                if (userSimulation != null && userSimulation.UserSimulationMeasureDetails != null)
                {
                    userSimulationMeasureDetail = userSimulation.UserSimulationMeasureDetails.FirstOrDefault(x => x.PlanMeasureId == measure.Id);
                }

                if (userSimulationMeasureDetail != null)
                {
                    meassureViewModel.ActualAchievment           = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, userSimulationMeasureDetail.Achievement));
                    meassureViewModel.ActualAchievmentPercentage = userSimulationMeasureDetail.AchievementPercentage;
                    meassureViewModel.YTDCumilativePayout        = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, userSimulationMeasureDetail.PayoutAmount));
                }

                var diffInIncentive = 0.0M;
                foreach (var payoutPercentageDetail in measure.PayoutPercentage.PayoutPercentageDetails)
                {
                    MeasureFrequencyDetailViewModel field = new MeasureFrequencyDetailViewModel();
                    field.Id               = payoutPercentageDetail.FrequencyDetailId;
                    field.TargetPer        = payoutPercentageDetail.PayoutPercentageWeightage;
                    field.Label            = payoutPercentageDetail.FrequencyDetail.Name;
                    field.Incentive        = salaries[(FrequencyDetails)payoutPercentageDetail.FrequencyDetailId] * (user.CurentPlan.TargetIncentivePercentage / 100) * (measure.MeasureWeightage / 100) * (payoutPercentageDetail.PayoutPercentageWeightage / 100);
                    field.CurrentIncentive = salaries[FrequencyDetails.Annual] * (user.CurentPlan.TargetIncentivePercentage / 100) * (measure.MeasureWeightage / 100) * (payoutPercentageDetail.PayoutPercentageWeightage / 100);
                    if (measure.PayoutCurve.PayoutCurveTypeId == Convert.ToInt32(PayoutCurveType.Linear))
                    {
                        field.AdditionalFields.Add("Expense", 0);
                        field.AdditionalFields.Add("Revenue", 0);
                    }

                    diffInIncentive += field.CurrentIncentive - field.Incentive;

                    if (userTarget != null && userTarget.UserTargetDetails != null)
                    {
                        var userTargetDetail = userTarget.UserTargetDetails.FirstOrDefault(x => x.PlanMeasureId == measure.Id && x.FrequencyDetailId == payoutPercentageDetail.FrequencyDetailId);
                        if (userTargetDetail != null)
                        {
                            field.Goal = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, userTargetDetail.Goal));
                        }
                    }

                    UserSimulationMeasureFrequencyDetailModel userSimulationMeasureFrequencyDetail = null;
                    if (userSimulationMeasureDetail != null && userSimulationMeasureDetail.UserSimulationMeasureFrequencyDetails != null)
                    {
                        userSimulationMeasureFrequencyDetail = userSimulationMeasureDetail.UserSimulationMeasureFrequencyDetails.FirstOrDefault(x => x.FrequencyDetailId == payoutPercentageDetail.FrequencyDetailId);
                    }

                    if (userSimulationMeasureFrequencyDetail != null)
                    {
                        field.ActualAchievment           = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, userSimulationMeasureFrequencyDetail.Achievement));
                        field.ActualAchievmentPercentage = userSimulationMeasureFrequencyDetail.AchievementPercentage;
                        field.YTDCumilativePayout        = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, userSimulationMeasureFrequencyDetail.PayoutAmount));
                        field.CumulativePercentage       = Convert.ToDecimal(userSimulationMeasureFrequencyDetail.CumulativePercentage);
                        field.IsValue = userSimulationMeasureFrequencyDetail.IsValue == null ? false : userSimulationMeasureFrequencyDetail.IsValue;
                        if (!string.IsNullOrWhiteSpace(userSimulationMeasureFrequencyDetail.AdditionalFields))
                        {
                            XmlDocument xdoc = new XmlDocument();
                            xdoc.LoadXml(userSimulationMeasureFrequencyDetail.AdditionalFields);

                            foreach (XmlElement x in xdoc.DocumentElement.ChildNodes)
                            {
                                field.AdditionalFields[x.Name] = Convert.ToInt32(x.InnerText);
                            }
                        }
                    }

                    meassureViewModel.Fields.Add(field);
                }

                if (meassureViewModel.PayoutTypeId == Convert.ToInt32(PayoutType.Cumulative) && meassureViewModel.Fields.Count >= 1)
                {
                    var lastField = meassureViewModel.Fields[meassureViewModel.Fields.Count - 1];
                    lastField.Incentive = lastField.CurrentIncentive + diffInIncentive;
                }

                planViewModel.RoleMeassures.Add(meassureViewModel);
            }

            foreach (var modifier in user.CurentPlan.PlanModifiers)
            {
                ModifierViewModel modifierViewModel = new ModifierViewModel();
                modifierViewModel.Id          = modifier.Id;
                modifierViewModel.Name        = modifier.ModifierName;
                modifierViewModel.PayoutCurve = modifier.PayoutCurve;
                modifierViewModel.DataType    = modifier.DataType;
                modifierViewModel.ValueType   = modifier.ValueType;
                if (userSimulation != null)
                {
                    var targetsimulationmodifierdetail = userSimulation.UserSimulationModifierDetails.FirstOrDefault(x => x.PlanModifierId == modifier.Id);
                    if (targetsimulationmodifierdetail != null)
                    {
                        modifierViewModel.ModifierFieldValue = targetsimulationmodifierdetail.ModifierFieldValue;
                        modifierViewModel.ModifierPayout     = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, targetsimulationmodifierdetail.ModifierPayout));
                    }
                }

                planViewModel.Modifiers.Add(modifierViewModel);
            }

            planViewModel.UpdateSequence();
            return(planViewModel);
        }
Exemple #2
0
        /// <summary>
        /// Gets the payout history.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>returns view model</returns>
        public List <PlanViewModel> GetPayoutHistory(UserModel user)
        {
            var result = new List <PlanViewModel>();
            List <UserPayoutHistoryModel> payoutHistory = new List <UserPayoutHistoryModel>();

            if (user.Id == 0)
            {
                return(result);
            }

            payoutHistory = this.syngentaSIPUnitOfWork.PlanRepository.GetUserPayoutHistory(user.Id);
            if (payoutHistory != null && payoutHistory.Count > 0)
            {
                var yearPayouts = payoutHistory.Where(x => x.VisibilityDate.Date != null && x.VisibilityDate.Date <= DateTime.UtcNow.Date).GroupBy(x => x.Year).Select(g => new { g.Key, Payouts = g.ToList() }).ToList();
                payoutHistory = payoutHistory.Select(x => x).Where(x => x.VisibilityDate.Date != null && x.VisibilityDate.Date <= DateTime.UtcNow.Date).ToList();
                var applicationSetting = this.applicationSettings.GetApplicationSettingByKeyName(Constants.ApplicationSettingCodes.CryptoKey);
                foreach (var yearPayout in yearPayouts)
                {
                    PlanViewModel userPayout = new PlanViewModel();
                    foreach (var test in yearPayout.Payouts)
                    {
                        MeassureViewModel meassureViewModel = new MeassureViewModel();

                        meassureViewModel.Name      = test.MeasureName;
                        meassureViewModel.Frequency = test.Frequency.Name;
                        if (test.Frequency.Id == (int)Frequency.Annual)
                        {
                            MeasureFrequencyDetailViewModel field = new MeasureFrequencyDetailViewModel();
                            field.Label     = (string)FrequencyDetails.Annual.ToString();
                            field.Incentive = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, test.Quarter4));
                            meassureViewModel.Fields.Add(field);
                        }

                        if (test.Frequency.Id == (int)Frequency.HalfYearly)
                        {
                            MeasureFrequencyDetailViewModel field1 = new MeasureFrequencyDetailViewModel();
                            field1.Label     = (string)FrequencyDetails.H1.ToString();
                            field1.Incentive = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, test.Quarter2));
                            meassureViewModel.Fields.Add(field1);

                            MeasureFrequencyDetailViewModel field2 = new MeasureFrequencyDetailViewModel();
                            field2.Label     = (string)FrequencyDetails.H2.ToString();
                            field2.Incentive = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, test.Quarter4));
                            meassureViewModel.Fields.Add(field2);
                        }

                        if (test.Frequency.Id == (int)Frequency.Quarterly)
                        {
                            MeasureFrequencyDetailViewModel field1 = new MeasureFrequencyDetailViewModel();
                            field1.Label     = (string)FrequencyDetails.Q1.ToString();
                            field1.Incentive = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, test.Quarter1));
                            meassureViewModel.Fields.Add(field1);

                            MeasureFrequencyDetailViewModel field2 = new MeasureFrequencyDetailViewModel();
                            field2.Label     = (string)FrequencyDetails.Q2.ToString();
                            field2.Incentive = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, test.Quarter2));
                            meassureViewModel.Fields.Add(field2);

                            MeasureFrequencyDetailViewModel field3 = new MeasureFrequencyDetailViewModel();
                            field3.Label     = (string)FrequencyDetails.Q3.ToString();
                            field3.Incentive = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, test.Quarter3));
                            meassureViewModel.Fields.Add(field3);

                            MeasureFrequencyDetailViewModel field4 = new MeasureFrequencyDetailViewModel();
                            field4.Label     = (string)FrequencyDetails.Q4.ToString();
                            field4.Incentive = Convert.ToDecimal(this.cryptoService.Decrypt(applicationSetting.Value, test.Quarter4));
                            meassureViewModel.Fields.Add(field4);
                        }

                        userPayout.RoleMeassures.Add(meassureViewModel);
                    }

                    userPayout.Year     = yearPayout.Key;
                    userPayout.PlanName = yearPayout.Payouts.First().PlanName;
                    result.Add(userPayout);
                }
            }

            return(result);
        }