public IActionResult BestsellersReportList(DataSourceRequest command, BestsellersReportModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
            {
                return(Content(""));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null)
            {
                model.VendorId = _workContext.CurrentVendor.Id;
            }

            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            OrderStatus?  orderStatus   = model.OrderStatusId > 0 ? (OrderStatus?)(model.OrderStatusId) : null;
            PaymentStatus?paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)(model.PaymentStatusId) : null;

            var items = _orderReportService.BestSellersReport(
                createdFromUtc: startDateValue,
                createdToUtc: endDateValue,
                os: orderStatus,
                ps: paymentStatus,
                billingCountryId: model.BillingCountryId,
                orderBy: 2,
                vendorId: model.VendorId,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize,
                showHidden: true,
                storeId: model.StoreId);
            var gridModel = new DataSourceResult
            {
                Data = items.Select(x =>
                {
                    var m = new BestsellersReportLineModel
                    {
                        ProductId     = x.ProductId,
                        TotalAmount   = _priceFormatter.FormatPrice(x.TotalAmount, true, false),
                        TotalQuantity = x.TotalQuantity,
                    };
                    var product = _productService.GetProductById(x.ProductId);
                    if (product != null)
                    {
                        m.ProductName = product.Name;
                    }
                    return(m);
                }),
                Total = items.TotalCount
            };

            return(Json(gridModel));
        }
Exemplo n.º 2
0
        protected async Task <DataSourceResult> GetBestsellersBriefReportModel(int pageIndex,
                                                                               int pageSize, int orderBy)
        {
            //a vendor should have access only to his products
            string vendorId = "";

            if (_workContext.CurrentVendor != null && !_workContext.CurrentCustomer.IsStaff())
            {
                vendorId = _workContext.CurrentVendor.Id;
            }

            string storeId = "";

            if (_workContext.CurrentCustomer.IsStaff())
            {
                storeId = _workContext.CurrentCustomer.StaffStoreId;
            }

            var items = await _orderReportService.BestSellersReport(
                storeId : storeId,
                vendorId : vendorId,
                orderBy : orderBy,
                pageIndex : pageIndex,
                pageSize : pageSize,
                showHidden : true);

            var result = new List <BestsellersReportLineModel>();

            foreach (var x in items)
            {
                var m = new BestsellersReportLineModel
                {
                    ProductId     = x.ProductId,
                    TotalAmount   = _priceFormatter.FormatPrice(x.TotalAmount, true, false),
                    TotalQuantity = x.TotalQuantity,
                };
                var product = await _productService.GetProductById(x.ProductId);

                if (product != null)
                {
                    m.ProductName = product.Name;
                }
                result.Add(m);
            }

            var gridModel = new DataSourceResult
            {
                Data  = result,
                Total = items.TotalCount
            };

            return(gridModel);
        }
Exemplo n.º 3
0
        private async Task <IList <BestsellersReportLineModel> > GetBestsellersBriefReportModelAsync(List <BestsellersReportLine> report, bool includeFiles = false)
        {
            var productIds = report.Select(x => x.ProductId).Distinct().ToArray();
            var products   = await _db.Products
                             .AsNoTracking()
                             .Where(x => productIds.Contains(x.Id))
                             .ToDictionaryAsync(x => x.Id);

            Dictionary <int, MediaFileInfo> files = null;

            if (includeFiles)
            {
                var fileIds = products.Values
                              .Select(x => x.MainPictureId ?? 0)
                              .Where(x => x != 0)
                              .Distinct()
                              .ToArray();

                files = (await Services.MediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);
            }

            var model = report.Select(x =>
            {
                var m = new BestsellersReportLineModel
                {
                    ProductId     = x.ProductId,
                    TotalAmount   = Services.CurrencyService.PrimaryCurrency.AsMoney(x.TotalAmount),
                    TotalQuantity = x.TotalQuantity.ToString("N0")
                };

                var product = products.Get(x.ProductId);
                if (product != null)
                {
                    var file = files?.Get(product.MainPictureId ?? 0);

                    m.ProductName          = product.Name;
                    m.ProductTypeName      = product.GetProductTypeLabel(Services.Localization);
                    m.ProductTypeLabelHint = product.ProductTypeLabelHint;
                    m.Sku                 = product.Sku;
                    m.StockQuantity       = product.StockQuantity;
                    m.Price               = product.Price;
                    m.PictureThumbnailUrl = Services.MediaService.GetUrl(file, _mediaSettings.CartThumbPictureSize, null, false);
                    m.NoThumb             = file == null;
                }

                return(m);
            })
                        .ToList();

            return(model);
        }
        protected DataSourceResult GetBestsellersBriefReportModel(int pageIndex,
                                                                  int pageSize, int orderBy)
        {
            //a vendor should have access only to his products
            string vendorId = "";

            if (_workContext.CurrentVendor != null)
            {
                vendorId = _workContext.CurrentVendor.Id;
            }

            var items = _orderReportService.BestSellersReport(
                vendorId: vendorId,
                orderBy: orderBy,
                pageIndex: pageIndex,
                pageSize: pageSize,
                showHidden: true);
            var gridModel = new DataSourceResult
            {
                Data = items.Select(x =>
                {
                    var m = new BestsellersReportLineModel
                    {
                        ProductId     = x.ProductId,
                        TotalAmount   = _priceFormatter.FormatPrice(x.TotalAmount, true, false),
                        TotalQuantity = x.TotalQuantity,
                    };
                    var product = _productService.GetProductById(x.ProductId);
                    if (product != null)
                    {
                        m.ProductName = product.Name;
                    }
                    return(m);
                }),
                Total = items.TotalCount
            };

            return(gridModel);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> BestsellersReportList(DataSourceRequest command, BestsellersReportModel model)
        {
            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && !_workContext.CurrentCustomer.IsStaff())
            {
                model.VendorId = _workContext.CurrentVendor.Id;
            }

            if (_workContext.CurrentCustomer.IsStaff())
            {
                model.StoreId = _workContext.CurrentCustomer.StaffStoreId;
            }

            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            OrderStatus?  orderStatus   = model.OrderStatusId > 0 ? (OrderStatus?)(model.OrderStatusId) : null;
            PaymentStatus?paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)(model.PaymentStatusId) : null;

            var items = await _orderReportService.BestSellersReport(
                createdFromUtc : startDateValue,
                createdToUtc : endDateValue,
                os : orderStatus,
                ps : paymentStatus,
                billingCountryId : model.BillingCountryId,
                orderBy : 2,
                vendorId : model.VendorId,
                pageIndex : command.Page - 1,
                pageSize : command.PageSize,
                showHidden : true,
                storeId : model.StoreId);

            var result = new List <BestsellersReportLineModel>();

            foreach (var x in items)
            {
                var m = new BestsellersReportLineModel
                {
                    ProductId     = x.ProductId,
                    TotalAmount   = _priceFormatter.FormatPrice(x.TotalAmount, true, false),
                    TotalQuantity = x.TotalQuantity,
                };
                var product = await _productService.GetProductById(x.ProductId);

                if (product != null)
                {
                    m.ProductName = product.Name;
                }
                if (_workContext.CurrentVendor != null)
                {
                    if (product.VendorId == _workContext.CurrentVendor.Id)
                    {
                        result.Add(m);
                    }
                }
                else
                {
                    result.Add(m);
                }
            }
            var gridModel = new DataSourceResult
            {
                Data  = result,
                Total = items.TotalCount
            };

            return(Json(gridModel));
        }