public virtual ActionResult OrderList(DataSourceRequest command, Admin.Models.Orders.OrderListModel model) { var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); var amazonSettings = _settingService.LoadSetting<OrderAmazonSettings>(storeScope); if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedKendoGridJson(); //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); var orderStatusIds = !model.OrderStatusIds.Contains(0) ? model.OrderStatusIds : null; var paymentStatusIds = !model.PaymentStatusIds.Contains(0) ? model.PaymentStatusIds : null; var shippingStatusIds = !model.ShippingStatusIds.Contains(0) ? model.ShippingStatusIds : null; var filterByProductId = 0; var product = _productService.GetProductById(model.ProductId); if (product != null && HasAccessToProduct(product)) filterByProductId = model.ProductId; //load orders var orders = _orderAmazonService.SearchOrders(storeId: model.StoreId, vendorId: model.VendorId, productId: filterByProductId, warehouseId: model.WarehouseId, paymentMethodSystemName: model.PaymentMethodSystemName, createdFromUtc: startDateValue, createdToUtc: endDateValue, osIds: orderStatusIds, psIds: paymentStatusIds, ssIds: shippingStatusIds, billingEmail: model.BillingEmail, billingLastName: model.BillingLastName, billingCountryId: model.BillingCountryId, orderNotes: model.OrderNotes, pageIndex: command.Page - 1, pageSize: command.PageSize); var gridModel = new DataSourceResult { Data = orders.Select(x => { var store = _storeService.GetStoreById(x.StoreId); return new OrderModel { Id = x.Id, StoreName = store != null ? store.Name : "Unknown", OrderTotal = _priceFormatter.FormatPrice(x.OrderTotal, true, false), OrderStatus = x.OrderStatus.GetLocalizedEnum(_localizationService, _workContext), OrderStatusId = x.OrderStatusId, PaymentStatus = x.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext), PaymentStatusId = x.PaymentStatusId, ShippingStatus = x.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext), ShippingStatusId = x.ShippingStatusId, CustomerEmail = x.BillingAddress.Email, CustomerFullName = string.Format("{0} {1}", x.BillingAddress.FirstName, x.BillingAddress.LastName), CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc), CustomOrderNumber = x.CustomOrderNumber, OrderAmazon = _orderAmazonService.GetOrderAmazonByOrderId(x.Id) }; }), Total = orders.TotalCount }; //summary report //currently we do not support productId and warehouseId parameters for this report var reportSummary = _orderReportService.GetOrderAverageReportLine( storeId: model.StoreId, vendorId: model.VendorId, orderId: 0, paymentMethodSystemName: model.PaymentMethodSystemName, osIds: orderStatusIds, psIds: paymentStatusIds, ssIds: shippingStatusIds, startTimeUtc: startDateValue, endTimeUtc: endDateValue, billingEmail: model.BillingEmail, billingLastName: model.BillingLastName, billingCountryId: model.BillingCountryId, orderNotes: model.OrderNotes); var profit = _orderReportService.ProfitReport( storeId: model.StoreId, vendorId: model.VendorId, paymentMethodSystemName: model.PaymentMethodSystemName, osIds: orderStatusIds, psIds: paymentStatusIds, ssIds: shippingStatusIds, startTimeUtc: startDateValue, endTimeUtc: endDateValue, billingEmail: model.BillingEmail, billingLastName: model.BillingLastName, billingCountryId: model.BillingCountryId, orderNotes: model.OrderNotes); var primaryStoreCurrency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId); if (primaryStoreCurrency == null) throw new Exception("Cannot load primary store currency"); gridModel.ExtraData = new Admin.Models.Orders.OrderAggreratorModel { aggregatorprofit = _priceFormatter.FormatPrice(profit, true, false), aggregatorshipping = _priceFormatter.FormatShippingPrice(reportSummary.SumShippingExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false), aggregatortax = _priceFormatter.FormatPrice(reportSummary.SumTax, true, false), aggregatortotal = _priceFormatter.FormatPrice(reportSummary.SumOrders, true, false) }; return Json(gridModel); }
public virtual ActionResult List( [ModelBinder(typeof(CommaSeparatedModelBinder))] List<string> orderStatusIds = null, [ModelBinder(typeof(CommaSeparatedModelBinder))] List<string> paymentStatusIds = null, [ModelBinder(typeof(CommaSeparatedModelBinder))] List<string> shippingStatusIds = null) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); //order statuses var model = new Admin.Models.Orders.OrderListModel(); model.AvailableOrderStatuses = OrderStatus.Pending.ToSelectList(false).ToList(); model.AvailableOrderStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0", Selected = true }); if (orderStatusIds != null && orderStatusIds.Any()) { foreach (var item in model.AvailableOrderStatuses.Where(os => orderStatusIds.Contains(os.Value))) item.Selected = true; model.AvailableOrderStatuses.First().Selected = false; } //payment statuses model.AvailablePaymentStatuses = PaymentStatus.Pending.ToSelectList(false).ToList(); model.AvailablePaymentStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0", Selected = true }); if (paymentStatusIds != null && paymentStatusIds.Any()) { foreach (var item in model.AvailablePaymentStatuses.Where(ps => paymentStatusIds.Contains(ps.Value))) item.Selected = true; model.AvailablePaymentStatuses.First().Selected = false; } //shipping statuses model.AvailableShippingStatuses = ShippingStatus.NotYetShipped.ToSelectList(false).ToList(); model.AvailableShippingStatuses.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0", Selected = true }); if (shippingStatusIds != null && shippingStatusIds.Any()) { foreach (var item in model.AvailableShippingStatuses.Where(ss => shippingStatusIds.Contains(ss.Value))) item.Selected = true; model.AvailableShippingStatuses.First().Selected = false; } //stores model.AvailableStores.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var s in _storeService.GetAllStores()) model.AvailableStores.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString() }); //vendors model.AvailableVendors.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); var vendors = SelectListHelper.GetVendorList(_vendorService, _cacheManager, true); foreach (var v in vendors) model.AvailableVendors.Add(v); //warehouses model.AvailableWarehouses.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); foreach (var w in _shippingService.GetAllWarehouses()) model.AvailableWarehouses.Add(new SelectListItem { Text = w.Name, Value = w.Id.ToString() }); //payment methods model.AvailablePaymentMethods.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "" }); foreach (var pm in _paymentService.LoadAllPaymentMethods()) model.AvailablePaymentMethods.Add(new SelectListItem { Text = pm.PluginDescriptor.FriendlyName, Value = pm.PluginDescriptor.SystemName }); //billing countries foreach (var c in _countryService.GetAllCountriesForBilling(showHidden: true)) { model.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id.ToString() }); } model.AvailableCountries.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); //a vendor should have access only to orders with his products model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; return View("~/Plugins/Order.Amazon/Views/List.cshtml", model); }