コード例 #1
0
        protected virtual IPagedList <BestsellersReportLine> GetBestsellersReport(BestsellerSearchModel searchModel)
        {
            //get parameters to filter bestsellers
            var orderStatus   = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null;
            var paymentStatus = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null;

            if (_workContext.CurrentVendor != null)
            {
                searchModel.VendorId = _workContext.CurrentVendor.Id;
            }
            var startDateValue = !searchModel.StartDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            //get bestsellers
            var bestsellers = _orderReportService.BestSellersReport(showHidden: true,
                                                                    createdFromUtc: startDateValue,
                                                                    createdToUtc: endDateValue,
                                                                    os: orderStatus,
                                                                    ps: paymentStatus,
                                                                    billingCountryId: searchModel.BillingCountryId,
                                                                    orderBy: OrderByEnum.OrderByTotalAmount,
                                                                    vendorId: searchModel.VendorId,
                                                                    categoryId: searchModel.CategoryId,
                                                                    manufacturerId: searchModel.ManufacturerId,
                                                                    storeId: searchModel.StoreId,
                                                                    pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            return(bestsellers);
        }
コード例 #2
0
        /// <summary>
        /// Get a formatted bestsellers total amount
        /// </summary>
        /// <param name="searchModel">Bestseller search model</param>
        /// <returns>Bestseller total amount</returns>
        public virtual string GetBestsellerTotalAmount(BestsellerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter bestsellers
            var orderStatus   = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null;
            var paymentStatus = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null;

            if (_workContext.CurrentVendor != null)
            {
                searchModel.VendorId = _workContext.CurrentVendor.Id;
            }
            var startDateValue = !searchModel.StartDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            //get a total amount
            var totalAmount = _orderReportService.BestSellersReportTotalAmount(
                showHidden: true,
                createdFromUtc: startDateValue,
                createdToUtc: endDateValue,
                os: orderStatus,
                ps: paymentStatus,
                billingCountryId: searchModel.BillingCountryId,
                vendorId: searchModel.VendorId,
                categoryId: searchModel.CategoryId,
                manufacturerId: searchModel.ManufacturerId,
                storeId: searchModel.StoreId);

            return(_priceFormatter.FormatPrice(totalAmount, true, false));
        }
コード例 #3
0
        /// <summary>
        /// Prepare paged bestseller list model
        /// </summary>
        /// <param name="searchModel">Bestseller search model</param>
        /// <returns>Bestseller list model</returns>
        public virtual BestsellerListModel PrepareBestsellerListModel(BestsellerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            var bestsellers = GetBestsellersReport(searchModel);

            //prepare list model
            var model = new BestsellerListModel().PrepareToGrid(searchModel, bestsellers, () =>
            {
                return(bestsellers.Select(bestseller =>
                {
                    //fill in model values from the entity
                    var bestsellerModel = new BestsellerModel
                    {
                        ProductId = bestseller.ProductId,
                        TotalQuantity = bestseller.TotalQuantity
                    };

                    //fill in additional values (not existing in the entity)
                    bestsellerModel.ProductName = _productService.GetProductById(bestseller.ProductId)?.Name;
                    bestsellerModel.TotalAmount = _priceFormatter.FormatPrice(bestseller.TotalAmount, true, false);

                    return bestsellerModel;
                }));
            });

            return(model);
        }
コード例 #4
0
        /// <summary>
        /// Prepare paged bestseller list model
        /// </summary>
        /// <param name="searchModel">Bestseller search model</param>
        /// <returns>Bestseller list model</returns>
        public virtual BestsellerListModel PrepareBestsellerListModel(BestsellerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter bestsellers
            var orderStatus   = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null;
            var paymentStatus = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null;

            if (_workContext.CurrentVendor != null)
            {
                searchModel.VendorId = _workContext.CurrentVendor.Id;
            }
            var startDateValue = !searchModel.StartDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            //get bestsellers
            var bestsellers = _orderReportService.BestSellersReport(showHidden: true,
                                                                    createdFromUtc: startDateValue,
                                                                    createdToUtc: endDateValue,
                                                                    os: orderStatus,
                                                                    ps: paymentStatus,
                                                                    billingCountryId: searchModel.BillingCountryId,
                                                                    orderBy: 2,
                                                                    vendorId: searchModel.VendorId,
                                                                    categoryId: searchModel.CategoryId,
                                                                    manufacturerId: searchModel.ManufacturerId,
                                                                    storeId: searchModel.StoreId,
                                                                    pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new BestsellerListModel
            {
                Data = bestsellers.Select(bestseller =>
                {
                    //fill in model values from the entity
                    var bestsellerModel = new BestsellerModel
                    {
                        ProductId     = bestseller.ProductId,
                        TotalQuantity = bestseller.TotalQuantity
                    };

                    //fill in additional values (not existing in the entity)
                    bestsellerModel.ProductName = _productService.GetProductById(bestseller.ProductId)?.Name;
                    bestsellerModel.TotalAmount = _priceFormatter.FormatPrice(bestseller.TotalAmount, true, false);

                    return(bestsellerModel);
                }),
                Total = bestsellers.TotalCount
            };

            return(model);
        }
コード例 #5
0
        public virtual IActionResult BestsellersList(BestsellerSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
            {
                return(AccessDeniedDataTablesJson());
            }

            //prepare model
            var model = _reportModelFactory.PrepareBestsellerListModel(searchModel);

            return(Json(model));
        }
コード例 #6
0
        public virtual async Task <IActionResult> BestsellersReportAggregates(BestsellerSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageOrders))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //prepare model
            var totalAmount = await _reportModelFactory.GetBestsellerTotalAmountAsync(searchModel);

            return(Json(new { aggregatortotal = totalAmount }));
        }
コード例 #7
0
        public virtual async Task <IActionResult> BestsellersList(BestsellerSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageOrders))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //prepare model
            var model = await _reportModelFactory.PrepareBestsellerListModelAsync(searchModel);

            return(Json(model));
        }
コード例 #8
0
        /// <summary>
        /// Get bestsellers total amount
        /// </summary>
        /// <param name="searchModel">Bestseller search model</param>
        /// <returns>Bestseller total amount</returns>
        public virtual string GetBestsellerTotalAmount(BestsellerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            var bestsellers = GetBestsellersReport(searchModel);

            var totalAmount = _priceFormatter.FormatPrice(bestsellers.Sum(bestseller => bestseller.TotalAmount), true, false);

            return(totalAmount);
        }
コード例 #9
0
        /// <summary>
        /// Prepare bestseller search model
        /// </summary>
        /// <param name="searchModel">Bestseller search model</param>
        /// <returns>Bestseller search model</returns>
        public virtual BestsellerSearchModel PrepareBestsellerSearchModel(BestsellerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            searchModel.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores);

            //prepare available order statuses
            _baseAdminModelFactory.PrepareOrderStatuses(searchModel.AvailableOrderStatuses);

            //prepare available payment statuses
            _baseAdminModelFactory.PreparePaymentStatuses(searchModel.AvailablePaymentStatuses);

            //prepare available categories
            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories);

            //prepare available manufacturers
            _baseAdminModelFactory.PrepareManufacturers(searchModel.AvailableManufacturers);

            //prepare available billing countries
            searchModel.AvailableCountries = _countryService.GetAllCountriesForBilling(showHidden: true)
                                             .Select(country => new SelectListItem {
                Text = country.Name, Value = country.Id.ToString()
            }).ToList();
            searchModel.AvailableCountries.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            //prepare available vendors
            _baseAdminModelFactory.PrepareVendors(searchModel.AvailableVendors);

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }