/// <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 async Task <BestCustomersReportListModel> PrepareBestCustomersReportListModelAsync(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, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = !searchModel.EndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).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 = await _customerReportService.GetBestCustomersReportAsync(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 = await new BestCustomersReportListModel().PrepareToGridAsync(searchModel, reportItems, () => { return(reportItems.SelectAwait(async item => { //fill in model values from the entity var bestCustomersReportModel = new BestCustomersReportModel { CustomerId = item.CustomerId, OrderTotal = await _priceFormatter.FormatPriceAsync(item.OrderTotal, true, false), OrderCount = item.OrderCount }; //fill in additional values (not existing in the entity) var customer = await _customerService.GetCustomerByIdAsync(item.CustomerId); if (customer != null) { bestCustomersReportModel.CustomerName = (await _customerService.IsRegisteredAsync(customer)) ? customer.Email : await _localizationService.GetResourceAsync("Admin.Customers.Guest"); } return bestCustomersReportModel; })); }); return(model); }
public async Task <IActionResult> ReportBestCustomersByNumberOfOrdersList(DataSourceRequest command, BestCustomersReportModel model) { if (_workContext.CurrentCustomer.IsStaff()) { model.StoreId = _workContext.CurrentCustomer.StaffStoreId; } var(bestCustomerReportLineModels, totalCount) = await _customerViewModelService.PrepareBestCustomerReportLineModel(model, 2, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = bestCustomerReportLineModels.ToList(), Total = totalCount }; return(Json(gridModel)); }
public IActionResult ReportBestCustomersByNumberOfOrdersList(DataSourceRequest command, BestCustomersReportModel model) { var items = _customerViewModelService.PrepareBestCustomerReportLineModel(model, 2, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = items.bestCustomerReportLineModels.ToList(), Total = items.totalCount }; return(Json(gridModel)); }
public async Task <IActionResult> ReportBestCustomersByOrderTotalList(DataSourceRequest command, BestCustomersReportModel model) { var(bestCustomerReportLineModels, totalCount) = await _customerViewModelService.PrepareBestCustomerReportLineModel(model, 1, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = bestCustomerReportLineModels.ToList(), Total = totalCount }; return(Json(gridModel)); }
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); }