/// <summary> /// Sets the purchase product supplier in the Sales invoice, according to the purchaseReportContent list /// </summary> /// <param name="salesInvoice">Sales invoice</param> /// <param name="purchaseReportContent">The Purchase Report</param> public void SetInvoiceModel_ProductSupplier(List <InvoiceProductModel> salesInvoice, List <PurchaseReportModel> purchaseReportContent) { if (salesInvoice != null && purchaseReportContent != null) { foreach (InvoiceProductModel item in salesInvoice) { PurchaseReportModel reportRow = purchaseReportContent.Where(p => p.ProductCode == item.Code).FirstOrDefault(); item.SupplierName = reportRow == null ? "Supplier Name Not Found" : reportRow.SupplierName; } } }
public HttpResponseMessage Report() { try { string tempPath = ConfigurationManager.AppSettings["TempPath"]; long ticks = DateTime.Now.Ticks; string fileName = $"PurchasesReport-{ticks}.xls"; string fullName = $"{tempPath}\\" + fileName; List <PurchaseViewModel> allAsync = service.GetAll(); string headerValue = "Purchase Report \n Printed " + DateTime.Now.ToString("dd-MM-yyyy"); List <PurchaseReportModel> reportdata = allAsync.Select(x => new PurchaseReportModel { Created = x.Created, Supplier = x.Supplier.Name, Memo = x.Memo, Total = x.Total, Modified = x.Modified }).ToList(); PurchaseReportModel item = new PurchaseReportModel { Supplier = "Total", Total = reportdata.Sum(x => x.Total), Modified = DateTime.Now, Created = DateTime.Now }; reportdata.Add(item); GenericReportGenerator <PurchaseReportModel> .WriteExcel(reportdata, headerValue, fullName); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); var stream = new FileStream(fullName, FileMode.Open); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; return(result); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }