public static SalaryReport Get(int userID, int employeeID, int bussinessID, EmployeeFilter filter) { var result = new SalaryReport(filter); var employees = SalaryReport.FindEmployees(bussinessID, filter); foreach (var employee in employees) { var infos = SalaryCalculator.Find(employee.ID, filter.From, filter.To); dynamic record = new ExpandoObject(); var dictionary = (IDictionary <string, object>)record; dictionary.Add("Name", employee.Name); foreach (var info in infos) { result.Employees.Add(info); var month = info.Month.Value; if (!result.Months.Contains(month)) { result.Months.Add(month); } dictionary.Add(info.Month.Value.ToString("_MMyyyy"), filter.ViewBaseSalary ? info.BaseSalary > 0 ? info.BaseSalary : employee.BaseSalary : info.CalculatedTotal.Round()); } result.Records.Add(record); } result.Months = result.Months.OrderByDescending(i => i).ToList(); return(result); }
private void SaveDownloadSalary(string fileName, SalaryReport list) { var workbook = new HSSFWorkbook(); var worksheet = workbook.CreateSheet("Report"); ExcelWorker.CellStyles = new List <ICellStyle>(); var cells = new List <ExcelCell>() { ExcelWorker.CreateCell(workbook, "Tên", HSSFColor.RoyalBlue.Index, HSSFColor.White.Index) }; var totals = new Dictionary <DateTime, decimal>(); foreach (var month in list.Months) { cells.Add(ExcelWorker.CreateCell(workbook, month.ToString("MM/yyyy"), HSSFColor.RoyalBlue.Index, HSSFColor.White.Index)); } ExcelWorker.CreateRow(worksheet, 0, cells.ToArray()); for (var i = 0; i < list.Records.Count; i++) { var record = list.Records[i]; var dictionary = (IDictionary <string, object>)record; cells = new List <ExcelCell>() { ExcelWorker.CreateCell(workbook, dictionary["Name"]) }; foreach (var month in list.Months) { var value = 0m; var key = month.ToString("_MMyyyy"); if (dictionary.ContainsKey(key)) { value = (decimal)dictionary[key]; } cells.Add(ExcelWorker.CreateCell(workbook, value.GetCurrencyString())); if (!totals.ContainsKey(month)) { totals.Add(month, value); } else { totals[month] = totals[month] + value; } } ExcelWorker.CreateRow(worksheet, i + 1, cells.ToArray()); } var index = list.Records.Count + 1; var totalCells = new List <ExcelCell>() { ExcelWorker.CreateCell(workbook, "Tổng cộng") }; totalCells.AddRange(totals.Select(i => ExcelWorker.CreateCell(workbook, i.Value.GetCurrencyString()))); ExcelWorker.CreateRow(worksheet, index, totalCells.ToArray()); using (var fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)) { workbook.Write(fs); } }
public ActionResult Salary(EmployeeFilter filter) { var model = SalaryReport.Get(UserID, Employee.ID, Employee.BussinessID, filter); if (Request.IsAjaxRequest()) { return(Json(new { html = RenderPartialViewToString(Views.SalaryPartial, model) }, JsonRequestBehavior.DenyGet)); } return(View(Views.Salary, model)); }
public ActionResult Salary() { var model = new SalaryReport(); if (Request.IsAjaxRequest()) { return(Json(new { html = RenderPartialViewToString(Views.SalaryPartial, model) }, JsonRequestBehavior.AllowGet)); } return(View(Views.Salary, model)); }
public ActionResult SalaryDownload(EmployeeFilter filter) { var result = false; try { var data = SalaryReport.Get(UserID, Employee.ID, Employee.BussinessID, filter); if (data != null) { var fileName = String.Format("Salary_{0}.xls", DateTime.Now.ToString("ddMMyyyyHHmmss")); var file = String.Format("{0}/Content/Download/{1}", SiteConfiguration.ApplicationPath, fileName); Functions.CheckDirectory(String.Format("{0}/Content/Download/", SiteConfiguration.ApplicationPath)); SaveDownloadSalary(file, data); Session[SessionKey.Download] = fileName; result = true; } } catch { } return(Json(new { result = result }, JsonRequestBehavior.DenyGet)); }