Exemplo n.º 1
0
        public ActionResult DseIncentive(int csmId, int dealerId)
        {
            var dlr = _userDealerMapServiceService.FindDealerByID(dealerId).FirstOrDefault();
            var totalManPower = _manpowerService.FindDealerUserManpowers(csmId, dealerId, string.Empty);
            var manpwer = totalManPower.Where(x => x.Type == "DSE").ToList();
            var dseIncentiveModels = new DseIncentiveModel();
            dseIncentiveModels.DseIncentives = new Dictionary<string, IEnumerable<DseIncentiveModel>>();
            var incentiveModels = new List<DseIncentiveModel>();
            foreach (var dealermanpower in manpwer)
            {
                var incentiveModel = new DseIncentiveModel();
                incentiveModel.Name = dealermanpower.Name;
                incentiveModel.Designation = dealermanpower.Type;
                incentiveModel.Onroll = "Dealer";
                var monthlyTarget = _targetService.FindDealerMonthTarget(new List<int> { dealermanpower.Id }, new List<int> { 3 }).ToList();
                incentiveModel.MonthTotalTarget1 = monthlyTarget.Sum(x => x.Target1);
                incentiveModel.MonthTotalTarget2 = monthlyTarget.Sum(x => x.Target2);
                incentiveModel.ActualTarget = monthlyTarget.Sum(x => x.Actual);
                var dsecompentencies = _competencyProfileMapService.FindCompetencyProfileMapsByID(dealermanpower.Id);
                if (dsecompentencies.Any())
                    incentiveModel.Competency =
                        (decimal)(dsecompentencies.Average(x => x.Score) * 20);
                else
                {
                    incentiveModel.Competency = 0;
                }
                decimal incentiveDse = 0;
                decimal IncentiveDSM = 0;
                foreach (var montgtDse in monthlyTarget)
                {
                    if (montgtDse.Actual > 0)
                    {
                        if (montgtDse.Actual >= montgtDse.Target1)
                        {

                            if ((montgtDse.Actual >= montgtDse.Target2))
                            {

                                incentiveDse = incentiveDse + (montgtDse.Actual * 5000);
                            }
                            else
                            {
                                incentiveDse = incentiveDse + (montgtDse.Actual * 4000);
                            }

                        }
                        else
                        {
                            incentiveDse = incentiveDse + (montgtDse.Actual * 3000);
                        }
                    }

                }
                incentiveModel.TargetIncentive = Convert.ToInt32(incentiveDse + IncentiveDSM);
                incentiveModels.Add(incentiveModel);
            }
            var res = incentiveModels.OrderBy(x => x.Region).ThenBy(x => x.Delear).ThenBy(x => x.Designation).ThenBy(x => x.Name);
            if (incentiveModels.Any())

                dseIncentiveModels.DseIncentives.Add(dlr.Name, res);
            dseIncentiveModels.dealerid = dlr.Id;
            dseIncentiveModels.HQId = csmId;
            dseIncentiveModels.HQName = dlr.Name;
            dseIncentiveModels.HQRole = "DEALER";
            dseIncentiveModels.Title = "Dealer Incentive";
            dseIncentiveModels.Header = "DSE WISE INCENTIVE PAYOUT LIST ";
            ViewBag.List = Session["BreadcrumbList"];
            return View(dseIncentiveModels);
        }
Exemplo n.º 2
0
        private DseIncentiveModel Rsm_Incentive(int id)
        {
            var rsm = _userService.GetUser(id);
            var csm = _userService.FindUsers(x => x.ParentId == rsm.Id);
            var dseIncentiveModels = new DseIncentiveModel();
            dseIncentiveModels.DseIncentives = new Dictionary<string, IEnumerable<DseIncentiveModel>>();
            var incentiveModels = new List<DseIncentiveModel>();
            foreach (var csms in csm)
            {
                var totalManPower = _manpowerService.FindAllUserManpowers(csms.Id, string.Empty).ToList();
                var existManpowerIds = totalManPower.Where(x => x.ObjectInfo.DeletedDate == null).Select(x => x.Id).ToList();
                var manPowerIds = totalManPower.Where(x => x.Type == "DSE").Select(x => x.Id).ToList();
                var incentiveModel = new DseIncentiveModel();
                incentiveModel.Name = csms.Name;
                var monthlyTarget = _targetService.FindDealerMonthTarget(manPowerIds, new List<int> { 3 }).ToList();
                incentiveModel.MonthTotalTarget1 = monthlyTarget.Sum(x => x.Target1);
                incentiveModel.MonthTotalTarget2 = monthlyTarget.Sum(x => x.Target2);
                incentiveModel.ActualTarget = monthlyTarget.Sum(x => x.Actual);
                var dsecompentencies = _competencyProfileMapService.FindCompetencyProfileMaps(existManpowerIds);
                if (dsecompentencies.Any())
                    incentiveModel.Competency =
                        (decimal)(dsecompentencies.Average(x => x.Score) * 20);
                else
                {
                    incentiveModel.Competency = 0;
                }
                decimal incentiveDse = 0;
                decimal IncentiveDSM = 0;
                foreach (var montgtDse in monthlyTarget)
                {
                    if (montgtDse.Actual > 0)
                    {
                        if (montgtDse.Actual >= montgtDse.Target1)
                        {

                            if ((montgtDse.Actual >= montgtDse.Target2))
                            {

                                incentiveDse = incentiveDse + (montgtDse.Actual * 5000);
                            }
                            else
                            {
                                incentiveDse = incentiveDse + (montgtDse.Actual * 4000);
                            }

                        }
                        else
                        {
                            incentiveDse = incentiveDse + (montgtDse.Actual * 3000);
                        }
                    }

                }
                incentiveModel.TargetIncentive = Convert.ToInt32(incentiveDse + IncentiveDSM);
                incentiveModels.Add(incentiveModel);
            }
            var res = incentiveModels.OrderBy(x => x.Region).ThenBy(x => x.Delear).ThenBy(x => x.Designation).ThenBy(x => x.Name);
            if (incentiveModels.Any())

                dseIncentiveModels.DseIncentives.Add(rsm.Name, res);
            dseIncentiveModels.HQId = rsm.Id;
            dseIncentiveModels.HQName = rsm.Name;
            dseIncentiveModels.HQRole = "RSM";
            dseIncentiveModels.Title = "RSM Incentive";
            dseIncentiveModels.Header = "RSM WISE INCENTIVE PAYOUT LIST ";
            return dseIncentiveModels;
        }
Exemplo n.º 3
0
        private DseIncentiveModel Hq_Incentive(int id)
        {
            var hq = _userService.GetUser(id);
            var dealermanpower = _dealerManpowerService.GetAllDealerManpowers().Where(x => x.Profile.SAPCode != null).OrderBy(x => x.Name).ToList();
            var now = DateTime.Now;
            var dseIncentiveModels = new DseIncentiveModel();
            dseIncentiveModels.DseIncentives = new Dictionary<string, IEnumerable<DseIncentiveModel>>();
            var filteredData = from c in dealermanpower
                               group c by c.Profile.SAPCode into g
                               select new
                               {
                                   Name = g.Max(c => c.Name),
                                   Type = g.Select(c => c.Type).First(),
                                   Id = g.Select(c => c.Id).First(),
                                   ProfileID = g.Select(c => c.Profile.Id).First(),
                                   DealerId = g.Select(c => c.DealerId).First(),
                                   SAPCode = g.Select(c => c.Profile.SAPCode).First(),
                                   UserId = g.Select(c => c.UserId).First(),
                               };
            var incentiveModels = new List<DseIncentiveModel>();
            foreach (var dlrpower in filteredData)
            {
                var incentiveModel = new DseIncentiveModel();
                incentiveModel.Name = dlrpower.Name;
                incentiveModel.Designation = dlrpower.Type;
                incentiveModel.SapCode = dlrpower.SAPCode;
                incentiveModel.Onroll = "Dealer";
                var dealers = _userDealerMapServiceService.FindDealerByID(dlrpower.DealerId).ToList();
                foreach (var dlr in dealers)
                {
                    incentiveModel.Delear = dlr.Name;
                }
                var csm = _userService.GetUser(dlrpower.UserId);
                if (csm != null)
                {
                    var getdealerMpwer = _dealerManpowerService.GetAllDealerManpowers()
                        .Where(x => (x.Profile.SAPCode == dlrpower.SAPCode && (x.Type == "DSM") && (x.DealerId == dlrpower.DealerId))).ToList();
                    if ((getdealerMpwer.Any()))
                    {
                        string whereclause = "";
                        foreach (var dl in getdealerMpwer)
                        {
                            var csms = _userService.GetUser(dl.UserId);
                            if (whereclause.Length > 0)
                            {
                                whereclause += ",";
                            }
                            whereclause += csms.Name;

                        }
                        incentiveModel.CsmName = whereclause;
                    }
                    else
                    {
                        incentiveModel.CsmName = csm.Name;
                    }

                }
                var parent = _userService.FindParents(csm.ParentId).OrderBy(x => x.Name).ToList();
                foreach (var par in parent)
                {
                    switch (par.Role)
                    {
                        case "RM":
                            var userregion = _regionStateService.FindRegionByUserId(par.Id);
                            if (userregion != null)
                            {
                                var region = _regionStateService.FindRegionByID(userregion.RegionId);
                                if (region != null)
                                {
                                    incentiveModel.Region = region.Name;
                                }
                            }

                            break;
                        case "RSM":
                            var rsm = _userService.FindParents(par.ParentId).OrderBy(x => x.Name);
                            foreach (var rsmParent in rsm)
                            {
                                var userregions = _regionStateService.FindRegionByUserId(rsmParent.Id);
                                if (userregions != null)
                                {
                                    var region = _regionStateService.FindRegionByID(userregions.RegionId);
                                    if (region != null)
                                    {
                                        incentiveModel.Region = region.Name;
                                    }
                                }
                            }

                            break;
                    }
                }
                var getAlldealerMpwer = _dealerManpowerService.GetAllDealerManpowers()
                      .Where(x => (x.Profile.SAPCode == dlrpower.SAPCode && (x.DealerId == dlrpower.DealerId))).ToList();
                if ((getAlldealerMpwer.Any()))
                {
                    var manpowerids = getAlldealerMpwer.Select(x => x.Id);
                    int monthTarget1 = 0;
                    int monthTarget2 = 0;
                    int actualTarget = 0;
                    var monthlyTarget = _targetService.FindMonthlyTarget(manpowerids, 3).ToList();
                    incentiveModel.ActualTarget = monthlyTarget.Sum(a => a.Actual);
                    incentiveModel.MonthTotalTarget1 = monthlyTarget.Sum(a => a.Target1);
                    incentiveModel.MonthTotalTarget2 = monthlyTarget.Sum(a => a.Target2);
                    monthTarget1 = monthTarget1 + incentiveModel.MonthTotalTarget1;
                    monthTarget2 = monthTarget2 + incentiveModel.MonthTotalTarget2;
                    actualTarget = actualTarget + incentiveModel.ActualTarget;
                    switch (dlrpower.Type)
                    {
                        case "DSE":
                            if ((actualTarget >= monthTarget1))
                            {
                                if ((actualTarget >= monthTarget2))
                                {

                                    incentiveModel.TargetIncentive = (actualTarget * 5000);
                                }
                                else
                                {
                                    incentiveModel.TargetIncentive = (actualTarget * 4000);
                                }

                            }
                            else
                            {
                                incentiveModel.TargetIncentive = (actualTarget * 3000);
                            }

                            break;
                        case "DSM":
                            if ((actualTarget >= monthTarget1))
                            {
                                if ((actualTarget >= monthTarget2))
                                {

                                    incentiveModel.TargetIncentive = (actualTarget * 2000);
                                }
                                else
                                {
                                    incentiveModel.TargetIncentive = (actualTarget * 1500);
                                }
                            }
                            else
                            {
                                incentiveModel.TargetIncentive = (actualTarget * 1000);
                            }
                            break;
                    }
                }
                var yearlyTarget = _targetService.FindYearlyTarget(dlrpower.Id, now.Year.ToString()).ToList();
                incentiveModel.ActualYearlyTarget = yearlyTarget.Sum(a => a.Actual);
                incentiveModel.YearTotalTarget1 = yearlyTarget.Sum(a => a.Target1);
                incentiveModel.YearTotalTarget2 = yearlyTarget.Sum(a => a.Target2);

                int yearTarget1 = incentiveModel.YearTotalTarget1;
                int yearTarget2 = incentiveModel.YearTotalTarget2;
                int yearActualTarget = incentiveModel.ActualYearlyTarget;
                if (yearActualTarget != 0)
                {
                    switch (dlrpower.Type)
                    {
                        case "DSE":
                            incentiveModel.LoyaltyIncentive = ((yearActualTarget * 3000) + (yearTarget1 * 1000) + (yearTarget2 * 2000));
                            break;
                        case "DSM":
                            incentiveModel.LoyaltyIncentive = ((yearActualTarget * 1000) + (yearTarget1 * 500) + (yearTarget2 * 1000));
                            break;
                    }
                }
                var dsecompentencies = _competencyProfileMapService.FindCompetencyProfileMapsByID(dlrpower.Id).ToList();
                if (dsecompentencies.Any())
                    incentiveModel.Competency =
                        (decimal)(dsecompentencies.Average(x => x.Score) * 20);
                else
                {
                    incentiveModel.Competency = 0;
                }
                incentiveModel.MonthlyIncentive = Convert.ToInt32(incentiveModel.CompetencyIncentive + Convert.ToInt32(incentiveModel.TargetIncentive));
                incentiveModels.Add(incentiveModel);
            }
            var res = incentiveModels.OrderBy(x => x.Region).ThenBy(x => x.Delear).ThenBy(x => x.Designation).ThenBy(x => x.Name);
            if (incentiveModels.Any())

                dseIncentiveModels.DseIncentives.Add(hq.Name, res);
            dseIncentiveModels.HQId = hq.Id;
            dseIncentiveModels.HQName = hq.Name;
            dseIncentiveModels.HQRole = "HQ";
            dseIncentiveModels.Title = "HQ Incentive";
            dseIncentiveModels.Header = "DSE/DSM WISE INCENTIVE PAYOUT LIST ";
            return dseIncentiveModels;
        }
Exemplo n.º 4
0
        private DseIncentiveModel Hqregion_Incentive(int id)
        {
            var hq = _userService.GetUser(id);
            var rm = _userService.FindUsersByRole("RM", x => x.UserRegionMaps).OrderBy(x => x.Name).ToList();
            var dseIncentiveModels = new DseIncentiveModel();
            dseIncentiveModels.DseIncentives = new Dictionary<string, IEnumerable<DseIncentiveModel>>();
            var incentiveModels = new List<DseIncentiveModel>();
            foreach (var rms in rm)
            {
                var rsms = _userService.FindUsers(x => x.ParentId == rms.Id);
                var csms = _userService.FindUsers(x => rsms.Any(y => y.Id == x.ParentId));
                var csmid = csms.Select(x => x.Id).ToList();
                var totalManPower = _dealerManpowerService.FindAllDealerManpowers(csmid).ToList();
                var incentiveModel = new DseIncentiveModel();
                incentiveModel.Name = string.Format("{0}({1})", rms.UserRegionMaps.First().Region.Name, rms.Name);
                var manpwer = totalManPower.Where(x => x.Type == "DSE").Select(x => x.Id).ToList();
                var monthlyTarget = _targetService.FindMonthlyTarget(manpwer, 3).ToList();
                incentiveModel.MonthTotalTarget1 = monthlyTarget.Sum(x => x.Target1);
                incentiveModel.MonthTotalTarget2 = monthlyTarget.Sum(x => x.Target2);
                incentiveModel.ActualTarget = monthlyTarget.Sum(x => x.Actual);
                totalManPower.RemoveAll(x => x.ObjectInfo.DeletedDate != null || x.Profile.DateOfLeaving != null);
                var compmanpwer = totalManPower.Select(x => x.Id).ToList();
                var dsecompentencies = _competencyProfileMapService.FindCompetencyProfileMaps(compmanpwer);
                if (dsecompentencies.Any())
                    incentiveModel.Competency =
                        (decimal)(dsecompentencies.Average(x => x.Score) * 20);
                else
                {
                    incentiveModel.Competency = 0;
                }
                decimal incentiveDse = 0;
                decimal IncentiveDSM = 0;
                foreach (var montgtDse in monthlyTarget)
                {
                    if (montgtDse.Actual > 0)
                    {
                        if (montgtDse.Actual >= montgtDse.Target1)
                        {

                            if ((montgtDse.Actual >= montgtDse.Target2))
                            {

                                incentiveDse = incentiveDse + (montgtDse.Actual * 5000);
                            }
                            else
                            {
                                incentiveDse = incentiveDse + (montgtDse.Actual * 4000);
                            }

                        }
                        else
                        {
                            incentiveDse = incentiveDse + (montgtDse.Actual * 3000);
                        }
                    }

                }
                incentiveModel.TargetIncentive = Convert.ToInt32(incentiveDse + IncentiveDSM);
                incentiveModels.Add(incentiveModel);
            }
            var res = incentiveModels.OrderBy(x => x.Region).ThenBy(x => x.Delear).ThenBy(x => x.Designation).ThenBy(x => x.Name);
            if (incentiveModels.Any())

                dseIncentiveModels.DseIncentives.Add(hq.Name, res);
            dseIncentiveModels.HQId = hq.Id;
            dseIncentiveModels.HQName = hq.Name;
            dseIncentiveModels.HQRole = "HQ";
            dseIncentiveModels.Title = "HQ Incentive";
            dseIncentiveModels.Header = "REGION WISE INCENTIVE PAYOUT LIST ";
            return dseIncentiveModels;
        }
Exemplo n.º 5
0
        private DseIncentiveModel CsmDealer_Incentive(int csmId, int dealerId)
        {
            var dlr = _userDealerMapServiceService.FindDealerByID(dealerId).First();
            var dealermanpowers = _dealerManpowerService.FindDealerManpowers(csmId, dealerId, string.Empty).ToList();
            string currentMonth = DateTime.Now.AddMonths(0).ToString("MMMM");
            var now = DateTime.Now;
            var totalMonths = _masterService.FindPrevMonthsIDByName(now.Year, currentMonth);
            var totalmonthIds = totalMonths.Select(x => x.Id).ToList();
            var dseIncentiveModels = new DseIncentiveModel();
            dseIncentiveModels.DseIncentives = new Dictionary<string, IEnumerable<DseIncentiveModel>>();
            var incentiveModels = new List<DseIncentiveModel>();
            var filteredData = from c in dealermanpowers
                               group c by c.Profile.SAPCode into g
                               select new
                               {
                                   Name = g.Max(c => c.Name),
                                   Type = g.Select(c => c.Type).First(),
                                   Id = g.Select(c => c.Id).First(),
                                   ProfileID = g.Select(c => c.Profile.Id).First(),
                                   DealerId = g.Select(c => c.DealerId).First(),
                                   SAPCode = g.Select(c => c.Profile.SAPCode).First(),
                                   UserId = g.Select(c => c.UserId).First(),
                               };
            filteredData = filteredData.ToList();
            foreach (var dealermanpower in dealermanpowers)
            {
                var manpwer = filteredData.Select(x => x.Id).ToList();
                var dealermanpowerDse = filteredData.Where(x => x.Type == "DSE");
                var manpwerDSE = dealermanpowerDse.Select(x => x.Id).ToList();
                var DealermanpowerDSM = filteredData.Where(x => x.Type == "DSM");
                var manpwerDSM = DealermanpowerDSM.Select(x => x.Id).ToList();
                var MonthlyTargetDSE = _targetService.FindPrvMonthlyTarget(manpwerDSE, totalmonthIds).ToList();
                var MonthlyTargetDSM = _targetService.FindPrvMonthlyTarget(manpwerDSM, totalmonthIds).ToList();
                var IncentiveModel = new DseIncentiveModel();
                IncentiveModel.Name = dealermanpower.Name;
                var MonthlyTarget = _targetService.FindPrvMonthlyTarget(manpwer, totalmonthIds);
                IncentiveModel.MonthTotalTarget1 = MonthlyTarget.Sum(x => x.Target1);
                IncentiveModel.MonthTotalTarget2 = MonthlyTarget.Sum(x => x.Target2);
                IncentiveModel.ActualTarget = MonthlyTarget.Sum(x => x.Actual);
                var dsecompentencies = _competencyProfileMapService.FindCompetencyProfileMaps(manpwer);
                if (dsecompentencies.Any())
                    IncentiveModel.Competency =
                        (decimal)(dsecompentencies.Average(x => x.Score) * 20);
                else
                {
                    IncentiveModel.Competency = 0;
                }
                decimal incentiveDse = 0;
                decimal incentiveDsm = 0;
                if ((MonthlyTargetDSE.Any()))
                {
                    foreach (var montgtDse in MonthlyTargetDSE)
                    {
                        if (montgtDse.Actual > 0)
                        {
                            if (montgtDse.Actual >= montgtDse.Target1)
                            {

                                if ((montgtDse.Actual >= montgtDse.Target2))
                                {

                                    incentiveDse += incentiveDse + (montgtDse.Actual * 5000);
                                }
                                else
                                {
                                    incentiveDse = incentiveDse + (montgtDse.Actual * 4000);
                                }

                            }
                            else
                            {
                                incentiveDse = incentiveDse + (montgtDse.Actual * 3000);
                            }
                        }

                    }
                }
                if ((MonthlyTargetDSM.Any()))
                {
                    foreach (var montgtDsm in MonthlyTargetDSM)
                    {
                        if (montgtDsm.Actual > 0)
                        {
                            if ((montgtDsm.Actual >= montgtDsm.Target1))
                            {
                                if ((montgtDsm.Actual >= montgtDsm.Target2))
                                {

                                    incentiveDsm = incentiveDsm + (montgtDsm.Actual * 2000);
                                }
                                else
                                {
                                    incentiveDsm = incentiveDsm + (montgtDsm.Actual * 1500);
                                }
                            }
                            else
                            {
                                incentiveDsm = incentiveDsm + (montgtDsm.Actual * 1000);
                            }
                        }

                    }
                }
                IncentiveModel.TargetIncentive = Convert.ToInt32(incentiveDse + incentiveDsm);
                incentiveModels.Add(IncentiveModel);
            }
            var res = incentiveModels.OrderBy(x => x.Region).ThenBy(x => x.Delear).ThenBy(x => x.Designation).ThenBy(x => x.Name);
            if (incentiveModels.Any())
                dseIncentiveModels.DseIncentives.Add(dlr.Name, res);
            dseIncentiveModels.HQId = dlr.Id;
            dseIncentiveModels.HQName = dlr.Name;
            dseIncentiveModels.HQRole = "DEALER";
            dseIncentiveModels.Title = "Dealer Incentive";
            dseIncentiveModels.Header = "DEALER WISE INCENTIVE PAYOUT LIST ";
            return dseIncentiveModels;
        }
Exemplo n.º 6
0
        public ActionResult PdfDseIncentive(int csmId, int dealerId)
        {
            var dlr = _userDealerMapServiceService.FindDealerByID(dealerId).FirstOrDefault();
            var totalManPower = _manpowerService.FindDealerUserManpowers(csmId, dealerId, string.Empty);
            var manpwer = totalManPower.Where(x => x.Type == "DSE").ToList();
            var dseIncentiveModels = new DseIncentiveModel();
            dseIncentiveModels.DseIncentives = new Dictionary<string, IEnumerable<DseIncentiveModel>>();
            var incentiveModels = new List<DseIncentiveModel>();
            foreach (var dealermanpower in manpwer)
            {
                var incentiveModel = new DseIncentiveModel();
                incentiveModel.Name = dealermanpower.Name;
                incentiveModel.Designation = dealermanpower.Type;
                incentiveModel.Onroll = "Dealer";
                var monthlyTarget = _targetService.FindDealerMonthTarget(new List<int> { dealermanpower.Id }, new List<int> { 3 }).ToList();
                incentiveModel.MonthTotalTarget1 = monthlyTarget.Sum(x => x.Target1);
                incentiveModel.MonthTotalTarget2 = monthlyTarget.Sum(x => x.Target2);
                incentiveModel.ActualTarget = monthlyTarget.Sum(x => x.Actual);
                var dsecompentencies = _competencyProfileMapService.FindCompetencyProfileMapsByID(dealermanpower.Id);
                if (dsecompentencies.Any())
                    incentiveModel.Competency =
                        (decimal)(dsecompentencies.Average(x => x.Score) * 20);
                else
                {
                    incentiveModel.Competency = 0;
                }
                decimal incentiveDse = 0;
                decimal IncentiveDSM = 0;
                foreach (var montgtDse in monthlyTarget)
                {
                    if (montgtDse.Actual > 0)
                    {
                        if (montgtDse.Actual >= montgtDse.Target1)
                        {

                            if ((montgtDse.Actual >= montgtDse.Target2))
                            {

                                incentiveDse = incentiveDse + (montgtDse.Actual * 5000);
                            }
                            else
                            {
                                incentiveDse = incentiveDse + (montgtDse.Actual * 4000);
                            }

                        }
                        else
                        {
                            incentiveDse = incentiveDse + (montgtDse.Actual * 3000);
                        }
                    }

                }
                incentiveModel.TargetIncentive = Convert.ToInt32(incentiveDse + IncentiveDSM);
                incentiveModels.Add(incentiveModel);
            }
            var res = incentiveModels.OrderBy(x => x.Region).ThenBy(x => x.Delear).ThenBy(x => x.Designation).ThenBy(x => x.Name);
            if (incentiveModels.Any())

                dseIncentiveModels.DseIncentives.Add(dlr.Name, res);
            dseIncentiveModels.dealerid = dlr.Id;
            dseIncentiveModels.HQId = csmId;
            dseIncentiveModels.HQName = dlr.Name;
            dseIncentiveModels.HQRole = "DEALER";
            dseIncentiveModels.Title = "Dealer Incentive";
            dseIncentiveModels.Header = "DSE WISE INCENTIVE PAYOUT LIST ";
            var viewString = RenderViewToString("PdfDseIncentive", dseIncentiveModels);
            var absolutePath = WkhtmlWrapper.CreatePdf(viewString, Server.MapPath("/tmp"),
                                                                   FileService.CreateTempFilePath("pdf"), "Portrait", WkhtmlWrapper.PaperSize.A4);
            var fileContents = FileService.ReadBytesFromAbsolutePath(absolutePath);
            FileService.DeleteFile(absolutePath);
            return File(fileContents, "application/pdf", "DseIncentive.pdf");
        }
Exemplo n.º 7
0
        public ActionResult ExcelDseIncentive(int csmId, int dealerId)
        {
            var dlr = _userDealerMapServiceService.FindDealerByID(dealerId).FirstOrDefault();
            var totalManPower = _manpowerService.FindDealerUserManpowers(csmId, dealerId, string.Empty);
            var manpwer = totalManPower.Where(x => x.Type == "DSE").ToList();
            var dseIncentiveModels = new DseIncentiveModel();
            dseIncentiveModels.DseIncentives = new Dictionary<string, IEnumerable<DseIncentiveModel>>();
            var incentiveModels = new List<DseIncentiveModel>();
            foreach (var dealermanpower in manpwer)
            {
                var incentiveModel = new DseIncentiveModel();
                incentiveModel.Name = dealermanpower.Name;
                incentiveModel.Designation = dealermanpower.Type;
                incentiveModel.Onroll = "Dealer";
                var monthlyTarget = _targetService.FindDealerMonthTarget(new List<int> { dealermanpower.Id }, new List<int> { 3 }).ToList();
                incentiveModel.MonthTotalTarget1 = monthlyTarget.Sum(x => x.Target1);
                incentiveModel.MonthTotalTarget2 = monthlyTarget.Sum(x => x.Target2);
                incentiveModel.ActualTarget = monthlyTarget.Sum(x => x.Actual);
                var dsecompentencies = _competencyProfileMapService.FindCompetencyProfileMapsByID(dealermanpower.Id);
                if (dsecompentencies.Any())
                    incentiveModel.Competency =
                        (decimal)(dsecompentencies.Average(x => x.Score) * 20);
                else
                {
                    incentiveModel.Competency = 0;
                }
                decimal incentiveDse = 0;
                decimal IncentiveDSM = 0;
                foreach (var montgtDse in monthlyTarget)
                {
                    if (montgtDse.Actual > 0)
                    {
                        if (montgtDse.Actual >= montgtDse.Target1)
                        {

                            if ((montgtDse.Actual >= montgtDse.Target2))
                            {

                                incentiveDse = incentiveDse + (montgtDse.Actual * 5000);
                            }
                            else
                            {
                                incentiveDse = incentiveDse + (montgtDse.Actual * 4000);
                            }

                        }
                        else
                        {
                            incentiveDse = incentiveDse + (montgtDse.Actual * 3000);
                        }
                    }

                }
                incentiveModel.TargetIncentive = Convert.ToInt32(incentiveDse + IncentiveDSM);
                incentiveModels.Add(incentiveModel);
            }
            var res = incentiveModels.OrderBy(x => x.Region).ThenBy(x => x.Delear).ThenBy(x => x.Designation).ThenBy(x => x.Name);
            if (incentiveModels.Any())
                dseIncentiveModels.DseIncentives.Add(dlr.Name, res);
            dseIncentiveModels.dealerid = dlr.Id;
            dseIncentiveModels.HQId = csmId;
            dseIncentiveModels.HQName = dlr.Name;
            dseIncentiveModels.HQRole = "DEALER";
            dseIncentiveModels.Title = "Dealer Incentive";
            dseIncentiveModels.Header = "DEALER WISE INCENTIVE PAYOUT LIST ";
            var tempPath = FileService.GetDownloadFilePath("xlsx");
            var excelFilePath = FileService.ConvertToAbsolute(tempPath);
            var converter = new HigherIncentiveConverter();
            converter.GenerateExcel(excelFilePath, dseIncentiveModels);
            var fileContent = FileService.ReadBytesFromAbsolutePath(excelFilePath);
            FileService.DeleteFile(excelFilePath);
            return File(fileContent, "application/octet-stream", "DseIncentive.xlsx");
        }