private DseProductReportModel Dse_Productivity(int csmId, int dealerId) { var dealer = _masterService.GetDealer(dealerId); var manpowers = _dealerManpowerService.FindDealerManpowers(new List<int> { dealer.Id }, csmId, string.Empty, x => x.Targets).OrderBy(x => x.Name); var dseProductivityModels = new List<DseProductivityModel>(); var products = _masterService.GetAllProducts().ToList(); var now = DateTime.Now; var currentMonth = _masterService.FindAndCreateMonth(now.ToString("MMMM"), now.Year); foreach (var dealerManpower in manpowers) { var dseProductivityModel = new DseProductivityModel(); dseProductivityModel.DseId = dealerManpower.Id; dseProductivityModel.Type = dealerManpower.Type; dseProductivityModel.DseName = dealerManpower.Name; dseProductivityModel.Segment = products.Single(x => x.Id == dealerManpower.ProductId).Name; dseProductivityModel.Productivity = dealerManpower.Targets.Any() ? decimal.Round((decimal)dealerManpower.Targets.Where(x => x.MonthId == currentMonth.Id).Average(x => x.Actual), 1) : 0; dseProductivityModels.Add(dseProductivityModel); } var model = new DseProductReportModel(); model.CsmId = csmId; model.DealerId = dealerId; model.DseProductivityModels = dseProductivityModels; model.Name = dealer.Name; return model; }
private CsmProductivityReport Csm_productivity(int csmId) { var csm = _userService.GetUser(csmId); var dealers = _userDealerMapServiceService.FindDealers(new List<int> { csm.Id }); var dealerProductivityReport = new List<DealerProductivityReport>(); var products = _masterService.GetAllProducts().ToList(); var now = DateTime.Now; var janMonth = _masterService.FindAndCreateMonth("January", now.Year); foreach (var dealer in dealers) { var manpowers = _dealerManpowerService.FindDealerManpowers(new List<int> { dealer.Id }, csm.Id, string.Empty, x => x.Targets); var dseProductivityModels = new List<DseProductivityModel>(); foreach (var dealerManpower in manpowers) { var dseProductivityModel = new DseProductivityModel(); dseProductivityModel.DseName = dealerManpower.Name; dseProductivityModel.Segment = products.Single(x => x.Id == dealerManpower.ProductId).Name; dseProductivityModel.Type = dealerManpower.Type; dseProductivityModel.Productivity = dealerManpower.Targets.Any(x => x.MonthId == janMonth.Id) ? decimal.Round((decimal)dealerManpower.Targets.Where(x => x.MonthId == janMonth.Id).Average(x => x.Actual), 1) : 0; dseProductivityModels.Add(dseProductivityModel); } var productivityReport = new DealerProductivityReport(); productivityReport.Name = dealer.Name; productivityReport.DseProductivityModels = dseProductivityModels; dealerProductivityReport.Add(productivityReport); } var model = new CsmProductivityReport(); model.DealerProductivityReports = dealerProductivityReport; model.CsmId = csm.Id; model.CsmName = csm.Name; return model; }