Exemplo n.º 1
0
        public ResultModels InsertCashInOutReport(List <CashInOutReportModels> lstInfo)
        {
            //_logger.Info("==========================================================");
            //_logger.Info("Start insert CashInOut data.......................");
            NSLog.Logger.Info("Start insert Cash In Out data.......................", lstInfo);

            var result = new ResultModels();

            if (lstInfo != null && lstInfo.Any())
            {
                CashInOutReportFactory cashInOutReportFactory = new CashInOutReportFactory();
                result.IsOk = cashInOutReportFactory.Insert(lstInfo);
            }
            return(result);
        }
Exemplo n.º 2
0
        public ActionResult Report(BaseReportModel model)
        {
            try
            {
                if (model.FromDate > model.ToDate)
                {
                    ModelState.AddModelError("FromDate", CurrentUser.GetLanguageTextFromKey("From Date must be less than To Date."));
                }
                else if (model.Type == Commons.TypeCompanySelected) //Company
                {
                    if (model.ListCompanys == null)
                    {
                        ModelState.AddModelError("ListCompanys", CurrentUser.GetLanguageTextFromKey("Please choose company."));
                    }
                }
                else //Store
                {
                    if (model.ListStores == null)
                    {
                        ModelState.AddModelError("ListStores", CurrentUser.GetLanguageTextFromKey("Please choose store."));
                    }
                }

                if (!ModelState.IsValid)
                {
                    return(View("Index", model));
                }
                //Get Selected Store
                List <StoreModels> lstStore = new List <StoreModels>();
                ////if (model.Type == Commons.TypeCompanySelected) //Company
                ////{
                ////    lstStore = model.GetSelectedStoreCompany();
                ////}
                ////else //Store
                ////{
                ////    List<SelectListItem> vbStore = ViewBag.Stores;
                ////    lstStore = model.GetSelectedStore(vbStore);
                ////}
                ///////======= Updated 072018
                if (model.Type == Commons.TypeCompanySelected) //Company
                {
                    lstStore         = listStoresInfoSession.Where(ww => model.ListCompanys.Contains(ww.CompanyId)).ToList();
                    model.ListStores = lstStore.Select(ss => ss.Id).ToList();
                }
                else //Store
                {
                    lstStore = listStoresInfoSession.Where(ww => model.ListStores.Contains(ww.Id)).ToList();
                }
                //End Get Selected Store

                //Export excel
                var cashInOutReportFactory = new CashInOutReportFactory();
                DateTimeHelper.GetDateTime(ref model);
                ClosedXML.Excel.XLWorkbook wb = cashInOutReportFactory.ExportExcelCashOut(model, lstStore, Commons.CashOut);
                ViewBag.wb = wb;

                string sheetName = string.Format("Report_Cash_Out_{0}", DateTime.Now.ToString("MMddyyyy"));
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Charset         = System.Text.UTF8Encoding.UTF8.WebName;
                Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
                if (model.FormatExport.Equals(Commons.Html))
                {
                    Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.html", sheetName.Replace(" ", "_")));
                }
                else
                {
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", sheetName.Replace(" ", "_")));
                }
                using (var memoryStream = new MemoryStream())
                {
                    wb.SaveAs(memoryStream);
                    if (model.FormatExport.Equals(Commons.Html))
                    {
                        Workbook workbook = new Workbook();
                        workbook.LoadFromStream(memoryStream);
                        //convert Excel to HTML
                        Worksheet sheet = workbook.Worksheets[0];
                        using (var ms = new MemoryStream())
                        {
                            sheet.SaveToHtml(ms);
                            ms.WriteTo(HttpContext.Response.OutputStream);
                            ms.Close();
                        }
                    }
                    else
                    {
                        memoryStream.WriteTo(HttpContext.Response.OutputStream);
                    }
                    memoryStream.Close();
                }
                HttpContext.Response.End();

                return(View("Index", model));
            }
            catch (Exception ex)
            {
                _logger.Error("Cash In Summary Report Error: " + ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }