public JsonResult GetSalesOrderReceipt(long salesOrderId) { List <SalesOrderReceiptDetail> result = new List <SalesOrderReceiptDetail>(); result = CommonExtensions.ConvertDataTable <SalesOrderReceiptDetail> (_productServices.SalesReportPerSalesNo(string.Empty, salesOrderId)); var response = new { isSuccess = true, messageAlert = string.Empty, result = result, }; return(Json(response, JsonRequestBehavior.AllowGet)); }
private FileResult PurchaseAndSalesReportGeneration(DateTime startDate, DateTime endDate, long categoryId = 0) { List <PurchaseAndReportDetail> purchaseAndReportDetails = new List <PurchaseAndReportDetail>(); List <ProductDetail> productDetails = new List <ProductDetail>(); productDetails = _productServices.GetAll().Where(p => p.IsActive).ToList(); if (productDetails.Count > 0) { purchaseAndReportDetails = CommonExtensions.ConvertDataTable <PurchaseAndReportDetail> (_productServices.PurchaseandSalesReport(startDate, endDate, categoryId)); } int rowId = 0; var fileNameGenerated = string.Format("{0}_{1}{2}", LookupKey.ReportFileName.PurchaseAndSalesReport, DateTime.Now.ToString("MMddyyyy"), ".xlsx"); var contentType = "application/vnd.ms-excel"; ExcelPackage.LicenseContext = LicenseContext.NonCommercial; var package = new ExcelPackage(); var workSheet = package.Workbook.Worksheets.Add(LookupKey.ReportFileName.PurchaseAndSalesReport); rowId = 0; if (productDetails.Count > 0) { foreach (var detail in productDetails) { var purchaseAndReportResult = purchaseAndReportDetails.Where(m => m.ProductID == detail.ProductId); if (purchaseAndReportResult.ToList().Count > 0) { rowId = rowId + 1; workSheet.Cells[rowId, 1].Value = detail.ProductCode.ToUpper() + " " + detail.ProductDescription.ToString(); workSheet.Cells[rowId, 1].Style.Font.Bold = true; rowId = rowId + 1; workSheet.Cells[rowId, 1].Value = "PREVIOUS PURCHASE QTY"; workSheet.Cells[rowId, 2].Value = "PURCHASE QTY"; workSheet.Cells[rowId, 3].Value = "PREVIOUS SALES QTY"; workSheet.Cells[rowId, 4].Value = "SALES QTY"; workSheet.Cells[rowId, 5].Value = "PREVIOUS CORRECTION QTY"; workSheet.Cells[rowId, 6].Value = "CORRECTION QTY"; workSheet.Cells[rowId, 7].Value = "TRANSACTION TYPE"; workSheet.Cells[rowId, 8].Value = "TRANSACTION DATE"; workSheet.Cells[rowId, 9].Value = "CREATED BY"; workSheet.Cells[rowId, 10].Value = "REMARKS"; foreach (var item in purchaseAndReportResult) { rowId = rowId + 1; workSheet.Cells[rowId, 1].Value = Convert.ToInt64(item.PreviousPurchaseQty); workSheet.Cells[rowId, 2].Value = Convert.ToInt64(item.PurchaseQty); workSheet.Cells[rowId, 3].Value = Convert.ToInt64(item.PreviousSalesQty); workSheet.Cells[rowId, 4].Value = Convert.ToInt64(item.SalesQty); workSheet.Cells[rowId, 5].Value = Convert.ToInt64(item.PreviousCorrectionQty); workSheet.Cells[rowId, 6].Value = Convert.ToInt64(item.CorrectionQty); workSheet.Cells[rowId, 7].Value = item.TransactionType; workSheet.Cells[rowId, 8].Value = item.TransactionDate.ToString("MM/dd/yyyy hh:mm"); workSheet.Cells[rowId, 9].Value = item.CreatedBy; workSheet.Cells[rowId, 10].Value = item.Remarks; } } } } workSheet.Cells.AutoFitColumns(); var memoryStream = new MemoryStream(); //package.Save(); package.SaveAs(memoryStream); memoryStream.Position = 0; return(File(memoryStream, contentType, fileNameGenerated)); }