public ActionResult SaleInvoice(int saleId, int style) { if (storeSettingRepository.All().Count() == 0) { TempData["Msg"] = "Configurez d'abord le paramètre du magasin, puis imprimez la facture de vente"; return(RedirectToAction("Index")); } var store = storeSettingRepository.All().FirstOrDefault(); var sale = saleRepository.All().Include(x => x.CustomerModel).SingleOrDefault(x => x.Id == saleId); sale.Items = saleItemRepository.All().Where(x => x.SalesId == saleId).ToList(); if (sale != null) { var sales = new SaleReportViewModel { company = store, Sales = sale }; if (style == 1) { SalesReport paymentReport = new SalesReport(configuration); byte[] bytes = paymentReport.CreateReport(sales); return(File(bytes, "application/pdf")); } if (style == 2) { SalesReportSmall paymentReport = new SalesReportSmall(); byte[] bytes = paymentReport.CreateReport(sales); return(File(bytes, "application/pdf")); } } return(RedirectToAction("index")); }
public ActionResult SaleInvoice(int saleId, int style) { if (storeSettingRepository.All().Count() == 0) { TempData["Msg"] = "Setup store setting first then print sale invoice"; return(RedirectToAction("Index")); } var store = storeSettingRepository.All().FirstOrDefault(); var sale = saleRepository.All().Include(x => x.CustomerModel).SingleOrDefault(x => x.Id == saleId); sale.Items = saleItemRepository.All().Where(x => x.SalesId == saleId).ToList(); if (sale != null) { var sales = new SaleReportViewModel { company = store, Sales = sale }; if (style == 1) { SalesReport paymentReport = new SalesReport(configuration); byte[] bytes = paymentReport.CreateReport(sales); return(File(bytes, "application/pdf", fileDownloadName: DateTime.Now.ToShortDateString() + "_Invoice_" + sales.Sales.SaleCode + "_" + sales.Sales.CustomerModel.Name + ".pdf")); } if (style == 2) { SalesReportSmall paymentReport = new SalesReportSmall(); byte[] bytes = paymentReport.CreateReport(sales); return(File(bytes, "application/pdf")); } } return(RedirectToAction("index")); }