示例#1
0
 public ActionResult ExcelRsmIncentive(int id)
 {
     var dseIncentive = Rsm_Incentive(id);
     var tempPath = FileService.GetDownloadFilePath("xlsx");
     var excelFilePath = FileService.ConvertToAbsolute(tempPath);
     var converter = new HigherIncentiveConverter();
     converter.GenerateExcel(excelFilePath, dseIncentive);
     var fileContent = FileService.ReadBytesFromAbsolutePath(excelFilePath);
     FileService.DeleteFile(excelFilePath);
     return File(fileContent, "application/octet-stream", "Rsm-Incentive.xlsx");
 }
示例#2
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");
        }