コード例 #1
0
        public async Task <IActionResult> ProductCsvReport(ProductReportModel model)
        {
            var result = await _reportBiz.GenerateProductCsvReport(model);

            if (!result.Success)
            {
                return(NotFound());
            }
            return(File(Encoding.UTF8.GetBytes(result.Data), "text/csv", "Sample.csv"));
        }
コード例 #2
0
        public async Task <IActionResult> ProductPDFReport(ProductReportModel model)
        {
            var result = await _reportBiz.GenerateProductPdfReport(model);

            if (!result.Success || result.Data == null)
            {
                return(NotFound());
            }
            return(File(result.Data, System.Net.Mime.MediaTypeNames.Application.Pdf, "Sample.pdf"));
        }
コード例 #3
0
        public async Task <IActionResult> ProductExcelReport(ProductReportModel model)
        {
            var result = await _reportBiz.GenerateProductExcelReport(model);

            if (!result.Success)
            {
                return(NotFound());
            }
            return(File(result.Data,
                        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                        "Sample.xlsx"));
        }
コード例 #4
0
ファイル: ReportController.cs プロジェクト: rudywilkjr/SMBIM
        public ActionResult Product(ProductReportModel model)
        {
            model.Items     = productService.GetLocationsWithProduct(model.SelectedProductId, model.SelectedLocationId);
            model.Products  = productService.GetProductItems(string.Empty);
            model.Locations = locationService.GetLocations(3); //3: Warehouse

            model.Products.Insert(0, new ProductDto {
                Id = 0, Name = "Select a Product"
            });
            model.Locations.Insert(0, new LocationDto {
                Id = 0, Description = "Select a Location"
            });

            return(View("Product", model));
        }
コード例 #5
0
        public Task <Result <byte[]> > GenerateProductPdfReport(ProductReportModel model) =>
        Result <byte[]> .TryAsync(async() =>
        {
            Result <IList <ProductModel> > result = await GetProductListFromDB(model);
            if (!result.Success)
            {
                return(Result <byte[]> .Failed(Error.WithCode(ErrorCodes.ErrorInProductReport)));
            }
            var productModels = result.Data;

            //Initialize HTML to PDF converter
            HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter()
            {
                //Assign WebKit settings to HTML converter
                ConverterSettings = new WebKitConverterSettings
                {
                    //Set WebKit path
                    WebKitPath = $"{Directory.GetCurrentDirectory()}" +
                                 $"{Path.DirectorySeparatorChar}bin" +
                                 $"{Path.DirectorySeparatorChar}Debug" +
                                 $"{Path.DirectorySeparatorChar}netcoreapp3.1" +
                                 $"{Path.DirectorySeparatorChar}QtBinariesWindows"
                }
            };

            string templatesPath = $"{Directory.GetCurrentDirectory()}" +
                                   $"{Path.DirectorySeparatorChar}wwwroot" +
                                   $"{Path.DirectorySeparatorChar}Resources" +
                                   $"{Path.DirectorySeparatorChar}ReportTemplates";

            RazorLightEngine engine = new RazorLightEngineBuilder().UseFileSystemProject(templatesPath)
                                      .UseMemoryCachingProvider().Build();
            string resultt = await engine.CompileRenderAsync("ProductPdfReport.cshtml", productModels);

            var pdfDocument     = htmlToPdfConverter.Convert(resultt, $"www.google.com");
            MemoryStream stream = new MemoryStream();
            pdfDocument.Save(stream);

            _logger.Info("Product pdf report generated");
            return(Result <byte[]> .Successful(stream.ToArray()));
        });
コード例 #6
0
        // GET: ProductReport
        //[Route("productreport")]
        public ActionResult ProductReport()
        {
            var productreport = new ProductReportModel();
            var startDate     = DateTime.Today.AddDays(-40);
            var endDate       = DateTime.Today.AddDays(0);
            var trans         = _context.Transaction.ToList();

            productreport.PrepaidVolume  = _context.Transaction.Where(s => s.ServiceId == 1 && (s.Datetime >= startDate) && (s.Datetime < endDate)).Count();
            productreport.PostpaidVolume = _context.Transaction.Where(s => s.ServiceId == 2 && s.Datetime <endDate && s.Datetime> startDate).Count();
            productreport.CreditVolume   = _context.Transaction.Where(s => s.ServiceId == 3 && s.Datetime <endDate && s.Datetime> startDate).Count();
            productreport.DebitVolume    = _context.Transaction.Where(s => s.ServiceId == 4 && s.Datetime <endDate && s.Datetime> startDate).Count();
            productreport.RefundVolume   = _context.Transaction.Where(s => s.ServiceId == 5 && s.Datetime <endDate && s.Datetime> startDate).Count();
            productreport.TotalVolume    = _context.Transaction.Where(s => s.ServiceId != 6 && s.Datetime <endDate && s.Datetime> startDate).Count();

            productreport.PrepaidSales  = _context.Transaction.Where(s => s.ServiceId == 1 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.Amount).ToList().Sum();
            productreport.PostpaidSales = _context.Transaction.Where(s => s.ServiceId == 2 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.Amount).ToList().Sum();
            productreport.CreditSales   = _context.Transaction.Where(s => s.ServiceId == 3 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.Amount).ToList().Sum();
            productreport.DebitSales    = _context.Transaction.Where(s => s.ServiceId == 4 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.Amount).ToList().Sum();
            productreport.RefundSales   = _context.Transaction.Where(s => s.ServiceId == 5 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.Amount).ToList().Sum();
            productreport.TotalSales    = _context.Transaction.Where(s => s.ServiceId != 6 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.Amount).ToList().Sum();

            productreport.BrinqPrepaidProfit  = _context.Transaction.Where(s => s.ServiceId == 1 && (s.Datetime >= startDate) && (s.Datetime < endDate)).Select(s => s.AgentProfit).ToList().Sum();
            productreport.BrinqPostpaidProfit = _context.Transaction.Where(s => s.ServiceId == 2 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.AgentProfit).ToList().Sum();
            productreport.BrinqTotalProfit    = productreport.BrinqPostpaidProfit + productreport.BrinqPrepaidProfit;

            productreport.AgentPrepaidProfit  = _context.Transaction.Where(s => s.ServiceId == 1 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.AgentProfit).ToList().Sum();
            productreport.AgentPostpaidProfit = _context.Transaction.Where(s => s.ServiceId == 2 && s.Datetime <endDate && s.Datetime> startDate).Select(s => s.AgentProfit).ToList().Sum();
            productreport.AgentTotalProfit    = productreport.AgentPostpaidProfit + productreport.AgentPrepaidProfit;

            List <AgentReportModel> agentreport = new List <AgentReportModel>();

            foreach (var user in _context.Kaedcuser.Where(u => u.IsActive == 1))
            {
                var c = _context.Kaedcuser.Where(u => u.Id == user.Id).Select(u => u.Transaction.Where(t => t.ServiceId == 1)).Count();
            }


            return(View(productreport));
        }
コード例 #7
0
        public HttpResponseMessage Report()
        {
            try
            {
                string tempPath = ConfigurationManager.AppSettings["TempPath"];
                long   ticks    = DateTime.Now.Ticks;
                string fileName = $"ProductsReport-{ticks}.xls";
                string fullName = $"{tempPath}\\" + fileName;
                List <ProductViewModel> allAsync = service.GetAll();
                string headerValue = "Product Report \n Printed " + DateTime.Now.ToString("dd-MM-yyyy");
                List <ProductReportModel> reportdata = allAsync.Select(x => new ProductReportModel {
                    BarCode = x.BarCode, Name = x.Name, GroupName = x.GroupName, Brand = x.Brand, OnHand = x.OnHand, CostPrice = x.CostPrice, SalePrice = x.SalePrice, CostTotal = x.OnHand * x.CostPrice, Modified = x.Modified
                }).ToList();
                ProductReportModel item = new ProductReportModel
                {
                    BarCode   = "Total",
                    CostTotal = reportdata.Sum(x => x.CostTotal), Modified = DateTime.Now
                };

                reportdata.Add(item);
                GenericReportGenerator <ProductReportModel> .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));
            }
        }
コード例 #8
0
        //#region GenerateProductPdfReport

        //public Task<Result<byte[]>> GenerateProductPdfReport(ProductReportModel model) =>
        //    Result<byte[]>.TryAsync(async () =>
        //    {
        //        Result<IList<ProductModel>> result = await GetProductListFromDB(model);
        //        if (!result.Success)
        //        {
        //            return Result<byte[]>.Failed(Error.WithCode(ErrorCodes.ErrorInProductReport));
        //        }
        //        var productModels = result.Data;

        //        string reportTemplatesPath = $"{Directory.GetCurrentDirectory()}" +
        //                   $"{Path.DirectorySeparatorChar}Businesses" +
        //                   $"{Path.DirectorySeparatorChar}Resources" +
        //                   $"{Path.DirectorySeparatorChar}ReportTemplates";
        //        RazorLightEngine engine = new RazorLightEngineBuilder().UseFileSystemProject(reportTemplatesPath)
        //            .UseMemoryCachingProvider().Build();
        //        string resultt = await engine.CompileRenderAsync("ProductPdfReport.cshtml", productModels);


        //        var globalSettings = new GlobalSettings
        //        {

        //            ColorMode = ColorMode.Color,
        //            Orientation = Orientation.Portrait,
        //            PaperSize = PaperKind.A4,
        //            Margins = new MarginSettings { Top = 10 },
        //            DocumentTitle = "PDF Report",
        //            //  Out = @"D:\PDFCreator\Employee_Report.pdf"
        //        };
        //        var objectSettings = new ObjectSettings
        //        {
        //            PagesCount = true,
        //            HtmlContent = resultt,
        //            WebSettings = { DefaultEncoding = "utf-8",
        //                UserStyleSheet = reportTemplatesPath + $"{Path.DirectorySeparatorChar}styles.css"},
        //            HeaderSettings = { FontName = "Arial", FontSize = 9,
        //                Right = "Page [page] of [toPage]", Line = true },
        //            FooterSettings = { FontName = "Arial", FontSize = 9,
        //                Line = true, Center = "Report Footer" }
        //        };
        //        var pdf = new HtmlToPdfDocument()
        //        {
        //            GlobalSettings = globalSettings,
        //            Objects = { objectSettings }
        //        };

        //        var byteArray = _converter.Convert(pdf);

        //        _logger.Info("Product pdf report generated");
        //        return Result<byte[]>.Successful(byteArray);
        //    });

        //#endregion

        #region GenerateProductExcelReport

        public Task <Result <byte[]> > GenerateProductExcelReport(ProductReportModel model) =>
        Result <byte[]> .TryAsync(async() =>