Esempio n. 1
0
 public ActionResult PdfDsmAttritionAnalysis(int csmId, int dealerId)
 {
     var name = _masterService.FindDealers(x => x.Id == dealerId).First().Name;
     var manpowers = _dealerManpowerService.FindAllDealerManpowers(x => x.UserId == csmId && x.DealerId == dealerId && x.Profile.DateOfLeaving != null && x.Type.Equals("DSM"));
     var dealerManpowerAttritionModels = new List<DealerManpowerAttritionModel>();
     foreach (var manpower in manpowers)
     {
         var dealerManpowerAttritionModel = new DealerManpowerAttritionModel();
         dealerManpowerAttritionModel.Name = manpower.Name;
         dealerManpowerAttritionModel.Type = manpower.Type;
         dealerManpowerAttritionModel.Age = (int)(manpower.Profile.DateOfBirth.HasValue ? DateTime.Now.Subtract(manpower.Profile.DateOfBirth.Value).TotalDays / 365 : 0);
         dealerManpowerAttritionModel.Exp = (int)(manpower.Profile.ExperienceWithVE.HasValue ? manpower.Profile.ExperienceWithVE.Value : 0);
         dealerManpowerAttritionModel.ReasonOfLeaving = manpower.AttritionProfileMap.Attrition.Name;
         dealerManpowerAttritionModel.AttritionId = manpower.AttritionProfileMap.Attrition.Id;
         dealerManpowerAttritionModels.Add(dealerManpowerAttritionModel);
     }
     var attritions = dealerManpowerAttritionModels.GroupBy(x => x.AttritionId);
     var dictionary = new Dictionary<string, int>();
     foreach (var attrition in attritions)
     {
         dictionary.Add(attrition.ElementAt(0).ReasonOfLeaving, attrition.Count());
     }
     var dealerAttritionModel = new DealerAttritionModel();
     dealerAttritionModel.Name = name;
     dealerAttritionModel.Reasons = dictionary;
     dealerAttritionModel.DealerManpowerAttritionModels = dealerManpowerAttritionModels;
     dealerAttritionModel.DealerId = dealerId;
     dealerAttritionModel.CsmId = csmId;
     var viewString = RenderViewToString("DsePdfAttritionAnalysis", dealerAttritionModel);
     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", "Attrition-Analysis.pdf");
 }
Esempio n. 2
0
 public ActionResult DsmAttritionAnalysis(int csmId, int dealerId)
 {
     Session["BreadcrumbList"] = Utils.HtmlExtensions.SetBreadcrumbs((List<BreadcrumbModel>)Session["BreadcrumbList"], string.Format("/Report/DsmAttritionAnalysis?dealerId={0}&id={1}", dealerId, csmId), "DSM Attrition Analysis");
     ViewBag.List = Session["BreadcrumbList"];
     var name = _masterService.FindDealers(x => x.Id == dealerId).First().Name;
     var manpowers = _dealerManpowerService.FindAllDealerManpowers(x => x.UserId == csmId && x.DealerId == dealerId && x.Profile.DateOfLeaving != null && x.Type.Equals("DSM"));
     var dealerManpowerAttritionModels = new List<DealerManpowerAttritionModel>();
     foreach (var manpower in manpowers)
     {
         var dealerManpowerAttritionModel = new DealerManpowerAttritionModel();
         dealerManpowerAttritionModel.Name = manpower.Name;
         dealerManpowerAttritionModel.Type = manpower.Type;
         dealerManpowerAttritionModel.Age = (int)(manpower.Profile.DateOfBirth.HasValue ? DateTime.Now.Subtract(manpower.Profile.DateOfBirth.Value).TotalDays / 365 : 0);
         dealerManpowerAttritionModel.Exp = (int)(manpower.Profile.ExperienceWithVE.HasValue ? manpower.Profile.ExperienceWithVE.Value : 0);
         dealerManpowerAttritionModel.ReasonOfLeaving = manpower.AttritionProfileMap.Attrition.Name;
         dealerManpowerAttritionModel.AttritionId = manpower.AttritionProfileMap.Attrition.Id;
         dealerManpowerAttritionModels.Add(dealerManpowerAttritionModel);
     }
     var attritions = dealerManpowerAttritionModels.GroupBy(x => x.AttritionId);
     var dictionary = new Dictionary<string, int>();
     foreach (var attrition in attritions)
     {
         dictionary.Add(attrition.ElementAt(0).ReasonOfLeaving, attrition.Count());
     }
     var dealerAttritionModel = new DealerAttritionModel();
     dealerAttritionModel.Name = name;
     dealerAttritionModel.Reasons = dictionary;
     dealerAttritionModel.DealerManpowerAttritionModels = dealerManpowerAttritionModels;
     dealerAttritionModel.DealerId = dealerId;
     dealerAttritionModel.CsmId = csmId;
     return View("DseAttritionAnalysis", dealerAttritionModel);
 }
Esempio n. 3
0
 public ActionResult ExcelDsmAttritionAnalysis(int csmId, int dealerId)
 {
     var name = _masterService.FindDealers(x => x.Id == dealerId).First().Name;
     var manpowers = _dealerManpowerService.FindAllDealerManpowers(x => x.UserId == csmId && x.DealerId == dealerId && x.Profile.DateOfLeaving != null && x.Type.Equals("DSM"));
     var dealerManpowerAttritionModels = new List<DealerManpowerAttritionModel>();
     foreach (var manpower in manpowers)
     {
         var dealerManpowerAttritionModel = new DealerManpowerAttritionModel();
         dealerManpowerAttritionModel.Name = manpower.Name;
         dealerManpowerAttritionModel.Type = manpower.Type;
         dealerManpowerAttritionModel.Age = (int)(manpower.Profile.DateOfBirth.HasValue ? DateTime.Now.Subtract(manpower.Profile.DateOfBirth.Value).TotalDays / 365 : 0);
         dealerManpowerAttritionModel.Exp = (int)(manpower.Profile.ExperienceWithVE.HasValue ? manpower.Profile.ExperienceWithVE.Value : 0);
         dealerManpowerAttritionModel.ReasonOfLeaving = manpower.AttritionProfileMap.Attrition.Name;
         dealerManpowerAttritionModel.AttritionId = manpower.AttritionProfileMap.Attrition.Id;
         dealerManpowerAttritionModels.Add(dealerManpowerAttritionModel);
     }
     var attritions = dealerManpowerAttritionModels.GroupBy(x => x.AttritionId);
     var dictionary = new Dictionary<string, int>();
     foreach (var attrition in attritions)
     {
         dictionary.Add(attrition.ElementAt(0).ReasonOfLeaving, attrition.Count());
     }
     var dealerAttritionModel = new DealerAttritionModel();
     dealerAttritionModel.Name = name;
     dealerAttritionModel.Reasons = dictionary;
     dealerAttritionModel.DealerManpowerAttritionModels = dealerManpowerAttritionModels;
     var tempPath = FileService.GetDownloadFilePath("xlsx");
     var excelFilePath = FileService.ConvertToAbsolute(tempPath);
     var converter = new AttritionAnalysisConverter();
     converter.GenerateExcel(excelFilePath, dealerAttritionModel);
     var fileContent = FileService.ReadBytesFromAbsolutePath(excelFilePath);
     FileService.DeleteFile(excelFilePath);
     return File(fileContent, "application/octet-stream", "Attrition-Analysis.xlsx");
 }