public virtual async Task <(IEnumerable <BestCustomerReportLineModel> bestCustomerReportLineModels, int totalCount)> PrepareBestCustomerReportLineModel(BestCustomersReportModel model, int orderBy, int pageIndex, int pageSize)
        {
            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);

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

            int?           orderStatus    = model.OrderStatusId > 0 ? model.OrderStatusId : null;
            PaymentStatus? paymentStatus  = model.PaymentStatusId > 0 ? (PaymentStatus?)(model.PaymentStatusId) : null;
            ShippingStatus?shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)(model.ShippingStatusId) : null;

            var items = _customerReportService.GetBestCustomersReport(model.StoreId, startDateValue, endDateValue,
                                                                      orderStatus, paymentStatus, shippingStatus, 2, pageIndex - 1, pageSize);

            var report = new List <BestCustomerReportLineModel>();

            foreach (var x in items)
            {
                var m = new BestCustomerReportLineModel {
                    CustomerId = x.CustomerId,
                    OrderTotal = _priceFormatter.FormatPrice(x.OrderTotal, false),
                    OrderCount = x.OrderCount,
                };
                var customer = await _customerService.GetCustomerById(x.CustomerId);

                if (customer != null)
                {
                    m.CustomerName = !string.IsNullOrEmpty(customer.Email) ? customer.Email : _translationService.GetResource("Admin.Customers.Guest");
                }
                report.Add(m);
            }
            return(report, items.TotalCount);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prepare paged best customers report list model
        /// </summary>
        /// <param name="searchModel">Best customers report search model</param>
        /// <returns>Best customers report list model</returns>
        public virtual BestCustomersReportListModel PrepareBestCustomersReportListModel(BestCustomersReportSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter
            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);
            var orderStatus    = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null;
            var paymentStatus  = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null;
            var shippingStatus = searchModel.ShippingStatusId > 0 ? (ShippingStatus?)searchModel.ShippingStatusId : null;

            //get report items
            var reportItems = _customerReportService.GetBestCustomersReport(createdFromUtc: startDateValue,
                                                                            createdToUtc: endDateValue,
                                                                            os: orderStatus,
                                                                            ps: paymentStatus,
                                                                            ss: shippingStatus,
                                                                            orderBy: searchModel.OrderBy,
                                                                            pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new BestCustomersReportListModel
            {
                Data = reportItems.Select(item =>
                {
                    //fill in model values from the entity
                    var bestCustomersReportModel = new BestCustomersReportModel
                    {
                        CustomerId = item.CustomerId,
                        OrderTotal = _priceFormatter.FormatPrice(item.OrderTotal, true, false),
                        OrderCount = item.OrderCount
                    };

                    //fill in additional values (not existing in the entity)
                    var customer = _customerService.GetCustomerById(item.CustomerId);
                    if (customer != null)
                    {
                        bestCustomersReportModel.CustomerName = customer.IsRegistered() ? customer.Email :
                                                                _localizationService.GetResource("Admin.Customers.Guest");
                    }

                    return(bestCustomersReportModel);
                }),
                Total = reportItems.TotalCount
            };

            return(model);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Get best customers
 /// </summary>
 /// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param>
 /// <param name="createdToUtc">Order created date to (UTC); null to load all records</param>
 /// <param name="os">Order status; null to load all records</param>
 /// <param name="ps">Order payment status; null to load all records</param>
 /// <param name="ss">Order shipment status; null to load all records</param>
 /// <param name="orderBy">1 - order by order total, 2 - order by number of orders</param>
 /// <param name="pageIndex">Page index</param>
 /// <param name="pageSize">Page size</param>
 /// <returns>Report</returns>
 public IAPIPagedList <BestCustomerReportLine> GetBestCustomersReport(DateTime?createdFromUtc,
                                                                      DateTime?createdToUtc, OrderStatus?os, PaymentStatus?ps, ShippingStatus?ss, int orderBy,
                                                                      int pageIndex = 0, int pageSize = 214748364)
 {
     return(_customerReportService.GetBestCustomersReport(createdFromUtc, createdToUtc, os, ps, ss, orderBy, pageIndex, pageSize).ConvertPagedListToAPIPagedList());
 }