public async Task <IActionResult> Export(string format, string searchTerm = null, int timezoneOffset = 0)
        {
            var model = new InvoiceExport(_CurrencyNameTable);

            InvoiceQuery invoiceQuery = GetInvoiceQuery(searchTerm, timezoneOffset);

            invoiceQuery.Skip  = 0;
            invoiceQuery.Count = int.MaxValue;
            var invoices = await _InvoiceRepository.GetInvoices(invoiceQuery);

            var res = model.Process(invoices, format);

            var cd = new ContentDisposition
            {
                FileName = $"btcpay-export-{DateTime.UtcNow.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture)}.{format}",
                Inline   = true
            };

            Response.Headers.Add("Content-Disposition", cd.ToString());
            Response.Headers.Add("X-Content-Type-Options", "nosniff");
            return(Content(res, "application/" + format));
        }
Exemple #2
0
        public ActionResult MonthlyInvoiceExport()
        {
            var orderDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            if (Request["OrderMonth"] != null && Request["OrderYear"] != null)
            {
                orderDate = new DateTime(Int32.Parse(Request["OrderYear"]), Int32.Parse(Request["OrderMonth"]), 1);
            }

            var recordSchoolCount = "";

            if (Request["schoolListCounts"] != null)
            {
                recordSchoolCount = Request["schoolListCounts"];
            }


            var recordCount = 1000;

            if (!string.IsNullOrWhiteSpace(Request["RecordCount"]))
            {
                recordCount = Int32.Parse(Request["RecordCount"]);
            }

            var request = new InvoiceGetAllRequest
            {
                Filter = new InvoiceFilterView {
                    OrderDate = orderDate, SchoolNameStartsWith = Request["SchoolNameStartsWith"] ?? string.Empty
                },
                OrderByAsc   = true,
                OrderByField = "SchoolName",
                PageIndex    = 1,
                PageSize     = recordCount
            };

            TryUpdateModel(request.Filter);
            var result = OrderService.SchoolInvoicesGetAllByFilter(request);

            if (result.SchoolInvoices.Count != 0)
            {
                byte[]     fileContent       = new byte[4096];
                var        fileName          = "";
                var        directoryPath     = "";
                var        templateDirectory = "";
                string[]   files             = new string[4096];
                int        j       = 0;
                List <int> numbers = new List <int>();
                string[]   words   = recordSchoolCount.Split('-');
                foreach (string word in words)
                {
                    int Count = Convert.ToInt32(word);
                    numbers.Add(Count);
                }
                for (j = numbers[0]; j <= numbers[1]; j++)
                {
                    var        invoiceId = result.SchoolInvoices[j].InvoiceList;
                    List <int> countIds  = new List <int>();
                    for (int i = 0; i <= invoiceId.Count - 1; i++)
                    {
                        int list56 = Convert.ToInt32(invoiceId[i].Id);
                        countIds.Add(list56);
                    }

                    int[] invoiceIds = countIds.ToArray();

                    var orderReports = new List <MealMenuOrderReportResponse>();
                    var model        = new InvoiceExportViewModel();

                    foreach (var i in invoiceIds)
                    {
                        var orderList = OrderService.InvoicesGetAllByFilter(new InvoiceGetAllRequest {
                            Filter = new InvoiceFilterView()
                            {
                                OrderId = i
                            }
                        });
                        if (orderList != null && orderList.Invoices != null && orderList.Invoices.Count > 0)
                        {
                            var note     = orderList.Invoices[0].Note;
                            var mealType = (MealTypes)orderList.Invoices[0].MealType.Id;
                            model.Notes.Add(mealType, note);
                        }
                    }

                    foreach (int i in invoiceIds)
                    {
                        var orderReport =
                            OrderService.GetOrderReport(new MealMenuOrderReportRequest
                        {
                            Filter = new OrderReportFilterView {
                                OrderId = i
                            },
                            OrderByAsc   = true,
                            OrderByField = "Id",
                            PageIndex    = 0,
                            // PageSize = 20
                        });
                        if (orderReport.Result == Result.Success && orderReport.Orders.Any())
                        {
                            orderReports.Add(orderReport);
                        }
                    }
                    if (orderReports.Count == 0)
                    {
                        ErrorMessage = "Invoice Couldn't be found.";
                        return(null);
                    }

                    var school = SchoolService.Get(new SchoolGetRequest {
                        Id = orderReports[0].Orders[0].SchoolId
                    });

                    model.School       = school.School;
                    model.orderReports = orderReports;


                    templateDirectory = Settings.GetSetting <string>("TemplateDirectory");
                    var templateFile = Server.MapPath(string.Format(@"\{0}\invoice5.xlsx", templateDirectory));

                    directoryPath =
                        Server.MapPath(string.Format(@"~\{0}\Invoices\{1}", templateDirectory, "InvoiceReport"));

                    if (Directory.Exists(directoryPath))
                    {
                        Directory.CreateDirectory(directoryPath);
                    }

                    var dateString = DateTime.Now.ToString("yyyyMMdd");
                    files = Directory.GetFiles(directoryPath, string.Format("{0}*", dateString),
                                               SearchOption.TopDirectoryOnly);
                    fileName = string.Format("{0}_" + result.SchoolInvoices[j].SchoolName + ".xlsx", dateString, files.Count() + 1);
                    var filePath = string.Format(@"{0}\{1}", directoryPath, fileName);

                    InvoiceExport invoice = new InvoiceExport(model, filePath, templateFile, OrderService, SchoolService);
                    invoice.GenerateInvoiceSheet();
                    invoice.CloseWorkSheet();

                    //var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);

                    //fileContent = new byte[fs.Length];
                    //fs.Read(fileContent, 0, fileContent.Length);
                }

                //DirectoryInfo di = fi.Directory;
                //if (di.Exists)
                //    di.Delete(true);
                //return File(fileContent, "application/vnd.ms-excel", fileName);
                //return new FileStreamResult(new FileStream(fileName, FileMode.Open), "application/zip")
                //{
                //    FileDownloadName = directoryPath
                //};
                var zipFile = Server.MapPath(string.Format(@"~\{0}\Invoices\{1}", templateDirectory, "InvoiceAllReport.zip"));
                using (var stream = new FileStream(zipFile, FileMode.Create))
                {
                    var zipFolder = Server.MapPath(string.Format(@"~\{0}\Invoices\{1}", templateDirectory, "InvoiceAllReport"));
                    ZipComponentFactory.CreateZipComponent().Zip(stream, directoryPath, true);
                    string[]      filePaths = Directory.GetFiles(directoryPath);
                    FileInfo      fi        = new FileInfo(directoryPath);
                    DirectoryInfo dir       = new DirectoryInfo(directoryPath);
                    dir.GetFiles("*", SearchOption.AllDirectories).ToList().ForEach(file => file.Delete());
                }
                using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(zipFile))
                {
                    zip.RemoveSelectedEntries("InvoiceAllReport/*"); // Remove folder and all its contents
                    zip.Save();
                }
                return(new FileStreamResult(new FileStream(zipFile, FileMode.Open), "application/zip")
                {
                    FileDownloadName = "InvoiceAllReport.zip"
                });
            }
            return(null);
        }
Exemple #3
0
 public void init()
 {
     invoiceExport = new InvoiceExport();
     AddActionClassesToList(invoiceExport);
 }
Exemple #4
0
        public ActionResult Generate(int[] invoiceIds)//block içerisindeki invoiceId'ler invoiceIds[0] yapıldı, düzenlenmeli!
        {
            var orderReports = new List <MealMenuOrderReportResponse>();
            var model        = new InvoiceExportViewModel();

            foreach (var i in invoiceIds)
            {
                var orderList = OrderService.InvoicesGetAllByFilter(new InvoiceGetAllRequest {
                    Filter = new InvoiceFilterView()
                    {
                        OrderId = i
                    }
                });
                if (orderList != null && orderList.Invoices != null && orderList.Invoices.Count > 0)
                {
                    var note     = orderList.Invoices[0].Note;
                    var mealType = (MealTypes)orderList.Invoices[0].MealType.Id;
                    model.Notes.Add(mealType, note);
                }
            }

            foreach (int i in invoiceIds)
            {
                var orderReport =
                    OrderService.GetOrderReport(new MealMenuOrderReportRequest
                {
                    Filter = new OrderReportFilterView {
                        OrderId = i
                    },
                    OrderByAsc   = true,
                    OrderByField = "Id",
                    PageIndex    = 0,
                    // PageSize = 20
                });
                if (orderReport.Result == Result.Success && orderReport.Orders.Any())
                {
                    orderReports.Add(orderReport);
                }
            }
            if (orderReports.Count == 0)
            {
                ErrorMessage = "Invoice Couldn't be found.";
                return(null);
            }

            var school = SchoolService.Get(new SchoolGetRequest {
                Id = orderReports[0].Orders[0].SchoolId
            });

            model.School       = school.School;
            model.orderReports = orderReports;


            var templateDirectory = Settings.GetSetting <string>("TemplateDirectory");
            var templateFile      = Server.MapPath(string.Format(@"\{0}\invoice5.xlsx", templateDirectory));

            var directoryPath =
                Server.MapPath(string.Format(@"~\{0}\Invoices\{1}", templateDirectory, invoiceIds[0]));

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            var dateString = DateTime.Now.ToString("yyyyMMdd");
            var files      = Directory.GetFiles(directoryPath, string.Format("{0}*", dateString),
                                                SearchOption.TopDirectoryOnly);
            var fileName = string.Format("{0}_{1}.xlsx", dateString, files.Count() + 1);
            var filePath = string.Format(@"{0}\{1}", directoryPath, fileName);


            InvoiceExport invoice = new InvoiceExport(model, filePath, templateFile, OrderService, SchoolService);

            invoice.GenerateInvoiceSheet();
            invoice.CloseWorkSheet();

            var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            var fileContent = new byte[fs.Length];

            fs.Read(fileContent, 0, fileContent.Length);

            return(File(fileContent, "application/vnd.ms-excel", fileName));
        }