public async Task <IActionResult> CountryReport() { if (!await _permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedView()); } var model = new CountryReportModel { //order statuses AvailableOrderStatuses = OrderStatus.Pending.ToSelectList(HttpContext, false).ToList() }; model.AvailableOrderStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "" }); //payment statuses model.AvailablePaymentStatuses = PaymentStatus.Pending.ToSelectList(HttpContext, false).ToList(); model.AvailablePaymentStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "" }); return(View(model)); }
/// <summary> /// Prepare paged country report list model /// </summary> /// <param name="searchModel">Country report search model</param> /// <returns>Country report list model</returns> public virtual CountryReportListModel PrepareCountrySalesListModel(CountryReportSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter countryReports var orderStatus = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null; var paymentStatus = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null; 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 items var items = _orderReportService.GetCountryReport(os: orderStatus, ps: paymentStatus, startTimeUtc: startDateValue, endTimeUtc: endDateValue); //prepare list model var model = new CountryReportListModel { Data = items.PaginationByRequestModel(searchModel).Select(item => { //fill in model values from the entity var countryReportModel = new CountryReportModel { TotalOrders = item.TotalOrders }; //fill in additional values (not existing in the entity) countryReportModel.SumOrders = _priceFormatter.FormatPrice(item.SumOrders, true, false); countryReportModel.CountryName = _countryService.GetCountryById(item.CountryId ?? 0)?.Name; return(countryReportModel); }), Total = items.Count }; return(model); }
/// <summary> /// Prepare paged country report list model /// </summary> /// <param name="searchModel">Country report search model</param> /// <returns>Country report list model</returns> public virtual async Task <CountryReportListModel> PrepareCountrySalesListModelAsync(CountryReportSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter countryReports var orderStatus = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null; var paymentStatus = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null; 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); //get items var items = (await _orderReportService.GetCountryReportAsync(os: orderStatus, ps: paymentStatus, startTimeUtc: startDateValue, endTimeUtc: endDateValue)).ToPagedList(searchModel); //prepare list model var model = await new CountryReportListModel().PrepareToGridAsync(searchModel, items, () => { return(items.SelectAwait(async item => { //fill in model values from the entity var countryReportModel = new CountryReportModel { TotalOrders = item.TotalOrders }; //fill in additional values (not existing in the entity) countryReportModel.SumOrders = await _priceFormatter.FormatPriceAsync(item.SumOrders, true, false); countryReportModel.CountryName = (await _countryService.GetCountryByIdAsync(item.CountryId ?? 0))?.Name; return countryReportModel; })); }); return(model); }
public IActionResult CountryReportList(DataSourceRequest command, CountryReportModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.OrderCountryReport)) { return(Content("")); } 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.GetCountryReport( os: orderStatus, ps: paymentStatus, startTimeUtc: startDateValue, endTimeUtc: endDateValue); var gridModel = new DataSourceResult { Data = items.Select(x => { var country = _countryService.GetCountryById(!String.IsNullOrEmpty(x.CountryId) ? x.CountryId : ""); var m = new CountryReportLineModel { CountryName = country != null ? country.Name : "Unknown", SumOrders = _priceFormatter.FormatPrice(x.SumOrders, true, false), TotalOrders = x.TotalOrders, }; return(m); }), Total = items.Count }; return(Json(gridModel)); }
public IActionResult CountryReport() { if (!_permissionService.Authorize(StandardPermissionProvider.OrderCountryReport)) { return(AccessDeniedView()); } var model = new CountryReportModel(); //order statuses model.AvailableOrderStatuses = OrderStatus.Pending.ToSelectList(false).ToList(); model.AvailableOrderStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "" }); //payment statuses model.AvailablePaymentStatuses = PaymentStatus.Pending.ToSelectList(false).ToList(); model.AvailablePaymentStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "" }); return(View(model)); }
public async Task <IActionResult> CountryReportList(DataSourceRequest command, CountryReportModel model) { 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; string storeId = ""; if (_workContext.CurrentCustomer.IsStaff()) { storeId = _workContext.CurrentCustomer.StaffStoreId; } var items = await _orderReportService.GetCountryReport( storeId : storeId, os : orderStatus, ps : paymentStatus, startTimeUtc : startDateValue, endTimeUtc : endDateValue); var result = new List <CountryReportLineModel>(); foreach (var x in items) { var country = await _countryService.GetCountryById(!String.IsNullOrEmpty(x.CountryId)?x.CountryId : ""); var m = new CountryReportLineModel { CountryName = country != null ? country.Name : "Unknown", SumOrders = _priceFormatter.FormatPrice(x.SumOrders, true, false), TotalOrders = x.TotalOrders, }; result.Add(m); } var gridModel = new DataSourceResult { Data = result, Total = items.Count }; return(Json(gridModel)); }