public IActionResult GetXls(DateTime?dateFrom, DateTime?dateTo, string category, string unitcode) { try { byte[] xlsInBytes; int offset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); DateTime DateFrom = dateFrom == null ? new DateTime(1970, 1, 1) : Convert.ToDateTime(dateFrom); DateTime DateTo = dateTo == null ? DateTime.Now : Convert.ToDateTime(dateTo); MemoryStream xls = _facade.GenerateExcelAStockReport(category, unitcode, DateFrom, DateTo, offset); string filename = String.IsNullOrWhiteSpace(unitcode) ? String.Format("Laporan Stock Pembukuan All Unit - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : unitcode == "C2A" ? String.Format("Laporan Stock Pembukuan KONFEKSI 2A - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : unitcode == "C2B" ? String.Format("Laporan Stock Pembukuan KONFEKSI 2B - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : unitcode == "C2C" ? String.Format("Laporan Stock Pembukuan KONFEKSI 2C - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : unitcode == "C1B" ? String.Format("Laporan Stock Pembukuan KONFEKSI 2D - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : String.Format("Laporan Stock Pembukuan All KONFEKSI 1 MNS - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")); xlsInBytes = xls.ToArray(); var file = File(xlsInBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename); return(file); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public IActionResult GetXls(DateTime?dateFrom, DateTime?dateTo, string category, string categoryname, string unitcode, string unitname) { try { identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; identityService.TimezoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); identityService.Token = Request.Headers["Authorization"].First().Replace("Bearer ", ""); byte[] xlsInBytes; int offset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); DateTime DateFrom = dateFrom == null ? new DateTime(1970, 1, 1) : Convert.ToDateTime(dateFrom); DateTime DateTo = dateTo == null ? DateTime.Now : Convert.ToDateTime(dateTo); MemoryStream xls = _facade.GenerateExcelAStockReport(category, categoryname, unitcode, unitname, DateFrom, DateTo, offset); //string filename = String.IsNullOrWhiteSpace(unitcode) ? String.Format("Laporan Stock Pembukuan All Unit - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : unitcode == "C2A" ? String.Format("Laporan Stock Pembukuan KONFEKSI 2A - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : unitcode == "C2B" ? String.Format("Laporan Stock Pembukuan KONFEKSI 2B - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : unitcode == "C2C" ? String.Format("Laporan Stock Pembukuan KONFEKSI 2C - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : unitcode == "C1B" ? String.Format("Laporan Stock Pembukuan KONFEKSI 2D - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")) : String.Format("Laporan Stock Pembukuan All KONFEKSI 1 MNS - {0}.xlsx", DateTime.UtcNow.ToString("ddMMyyyy")); string filename = string.Format("Laporan Stock Pembukuan - {0} {1} - {2}", unitname, ((DateTime)dateFrom).ToString("dd-MM-yyyy"), ((DateTime)dateTo).ToString("dd-MM-yyyy")); xlsInBytes = xls.ToArray(); var file = File(xlsInBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename); return(file); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }