public IActionResult GetPDF(int id) { try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; UnitPaymentCorrectionNote model = _facade.ReadById(id); UnitPaymentCorrectionNoteViewModel viewModel = _mapper.Map <UnitPaymentCorrectionNoteViewModel>(model); if (indexAcceptPdf < 0) { return(Ok(new { apiVersion = ApiVersion, statusCode = General.OK_STATUS_CODE, message = General.OK_MESSAGE, data = viewModel, })); } else { int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); UnitPaymentOrder spbModel = _spbFacade.ReadById((int)model.UPOId); UnitPaymentOrderViewModel viewModelSpb = _mapper.Map <UnitPaymentOrderViewModel>(spbModel); var supplier = _facade.GetSupplier(model.SupplierId); var supplier_address = ""; if (supplier != null) { supplier_address = supplier.address; } var temp_date = new DateTimeOffset(); foreach (var item in viewModel.items) { Lib.Models.UnitReceiptNoteModel.UnitReceiptNote urnModel = _facade.ReadByURNNo(item.uRNNo); UnitReceiptNoteViewModel viewModelUrn = _mapper.Map <UnitReceiptNoteViewModel>(urnModel); if (viewModelUrn != null && temp_date < viewModelUrn.date) { temp_date = viewModelUrn.date; } } UnitPaymentQuantityCorrectionNotePDFTemplate PdfTemplate = new UnitPaymentQuantityCorrectionNotePDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel, viewModelSpb, temp_date, supplier_address, identityService.Username, clientTimeZoneOffset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = $"{model.UPCNo}.pdf" }); } } 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 GetPDF(int id) { try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; UnitPaymentCorrectionNote model = _facade.ReadById(id); UnitPaymentCorrectionNoteViewModel viewModel = _mapper.Map <UnitPaymentCorrectionNoteViewModel>(model); //if (indexAcceptPdf < 0) //{ // return Ok(new // { // apiVersion = ApiVersion, // statusCode = General.OK_STATUS_CODE, // message = General.OK_MESSAGE, // data = viewModel, // }); //} //else //{ SupplierViewModel supplier = _facade.GetSupplier(viewModel.supplier._id); viewModel.supplier.address = supplier == null ? "" : supplier.address; int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); UnitPaymentOrder spbModel = _spbFacade.ReadById((int)model.UPOId); UnitPaymentOrderViewModel viewModelSpb = _mapper.Map <UnitPaymentOrderViewModel>(spbModel); DateTimeOffset? receiptDate = null; var today = new DateTime(1970, 1, 1); foreach (var item in model.Items) { Lib.Models.UnitReceiptNoteModel.UnitReceiptNote urnModel = _facade.GetUrn(item.URNNo); if (receiptDate == null || urnModel.ReceiptDate > receiptDate) { receiptDate = urnModel == null ? today : urnModel.ReceiptDate; } } UnitPaymentPriceCorrectionNotePDFTemplate PdfTemplate = new UnitPaymentPriceCorrectionNotePDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel, viewModelSpb, identityService.Username, clientTimeZoneOffset, receiptDate); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = $"{model.UPCNo}.pdf" }); //} } 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 Get(int id) { try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); var model = facade.ReadById(id); if (indexAcceptPdf < 0) { var viewModel = mapper.Map <UnitPaymentOrderViewModel>(model); return(Ok(new { apiVersion = ApiVersion, statusCode = General.OK_STATUS_CODE, message = General.OK_MESSAGE, data = viewModel, })); } else { int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; /* tambahan */ /* get Supplier */ string supplierUri = "master/suppliers"; var httpClient = (IHttpClientService)serviceProvider.GetService(typeof(IHttpClientService)); var response = httpClient.GetAsync($"{Lib.Helpers.APIEndpoint.Core}{supplierUri}/{model.SupplierId}").Result.Content.ReadAsStringAsync(); Dictionary <string, object> result = JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Result); SupplierViewModel supplier = JsonConvert.DeserializeObject <SupplierViewModel>(result.GetValueOrDefault("data").ToString()); /* tambahan */ UnitPaymentOrderPDFTemplate PdfTemplate = new UnitPaymentOrderPDFTemplate(); var stream = PdfTemplate.Generate(model, facade, supplier, clientTimeZoneOffset, identityService.Username); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = $"{model.UPONo}.pdf" }); } } 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 Get(int id) { try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); var model = facade.ReadById(id); if (indexAcceptPdf < 0) { var viewModel = mapper.Map <UnitPaymentOrderViewModel>(model); return(Ok(new { apiVersion = ApiVersion, statusCode = General.OK_STATUS_CODE, message = General.OK_MESSAGE, data = viewModel, })); } else { int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; UnitPaymentOrderPDFTemplate PdfTemplate = new UnitPaymentOrderPDFTemplate(); var stream = PdfTemplate.Generate(model, facade, clientTimeZoneOffset, identityService.Username); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = $"{model.UPONo}.pdf" }); } } 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)); } }