public async Task Should_Success_Generate_Pdf_LocalValasCorrection() { var dbContext = _dbContext(GetCurrentMethod()); var serviceProvider = _getServiceProvider(GetCurrentMethod()).Object; var unitPaymentOrderFacade = new UnitPaymentOrderFacade(serviceProvider, dbContext); var dataUtil = await _dataUtil(unitPaymentOrderFacade, dbContext, GetCurrentMethod()).GetTestLocalData(); var urnId = dataUtil.Items.FirstOrDefault().URNId; var urn = dbContext.UnitReceiptNotes.FirstOrDefault(f => f.Id.Equals(urnId)); var prId = urn.Items.FirstOrDefault(f => f.URNId.Equals(urn.Id)).PRId; var pr = dbContext.PurchaseRequests.FirstOrDefault(f => f.Id.Equals(prId)); var facade = new LocalPurchasingBookReportFacade(serviceProvider, dbContext); var result = await facade.GetReportDataV2(urn.URNNo, Convert.ToInt32(urn.UnitId), Convert.ToInt32(pr.CategoryId), DateTime.Now.AddDays(-7), DateTime.Now.AddDays(7), false, It.IsAny <int>()); result.Reports[0].DataSourceSort = 2; var localPdf = LocalPurchasingBookReportPdfTemplate.Generate(result, 1, null, null); Assert.NotNull(localPdf); var localCurrencyPdf = LocalPurchasingForeignCurrencyBookReportPdfTemplate.Generate(result, 1, DateTime.Now.AddDays(-7), DateTime.Now.AddDays(7)); Assert.NotNull(localCurrencyPdf); var importPdf = ImportPurchasingBookReportPdfTemplate.Generate(result, 1, DateTime.Now.AddDays(-7), DateTime.Now.AddDays(7)); Assert.NotNull(importPdf); }
public async Task <IActionResult> GetPdf(string no, int accountingUnitId, int accountingCategoryId, DateTime?dateFrom, DateTime?dateTo, bool isValas, int divisionId) { try { var clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); //var data = await localPurchasingBookReportFacade.GetReport(no, unit, category, dateFrom, dateTo, isValas); var data = await localPurchasingBookReportFacade.GetReportV2(no, accountingUnitId, accountingCategoryId, dateFrom, dateTo, isValas, divisionId); var stream = isValas ? LocalPurchasingForeignCurrencyBookReportPdfTemplate.Generate(data, clientTimeZoneOffset, dateFrom, dateTo) : LocalPurchasingBookReportPdfTemplate.Generate(data, clientTimeZoneOffset, dateFrom, dateTo); var filename = isValas ? "Laporan Buku Pembelian Lokal Valas" : "Laporan Buku Pembelian Lokal"; //if (dateFrom != null) filename += " " + ((DateTime)dateFrom).ToString("dd-MM-yyyy"); //if (dateTo != null) filename += "_" + ((DateTime)dateTo).ToString("dd-MM-yyyy"); filename += ".pdf"; return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = filename }); } catch (Exception e) { var result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message).Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result)); } }