public async Task ChangeShippingStatus(int id, ShippingStatus status) { await Task.Factory.StartNew(() => { client.ChangeShippingStatusAsync(id, status); }).ConfigureAwait(false); }
public Task <OrderDTO[]> ShippingStatusOrders(string SS) { ShippingStatus Status = ShippingStatus.Delivered; switch (SS) { case "Delivered": Status = ShippingStatus.Delivered; break; case "Not Yet Shipped": Status = ShippingStatus.NotYetShipped; break; case "Partially Shipped": Status = ShippingStatus.PartiallyShipped; break; case "Shipped": Status = ShippingStatus.Shipped; break; case "Shipping Not Required": Status = ShippingStatus.ShippingNotRequired; break; } var tcs = new TaskCompletionSource <OrderDTO[]>(); client.GetOrdersCompleted += (sender, result) => tcs.TrySetResult(result.Result.ToArray()); client.GetOrdersAsync(0, 0, 0, 0, 0, null, null, Status, null, 0, 20); return(tcs.Task); }
private async Task PatchOrderStatus(string orderID, ShippingStatus shippingStatus, ClaimStatus claimStatus) { var partialOrder = new PartialOrder { xp = new { ShippingStatus = shippingStatus, ClaimStatus = claimStatus } }; await _oc.Orders.PatchAsync(OrderDirection.Incoming, orderID, partialOrder); }
public async Task <OrderDTO[]> ShippingStatusOrders(string SS) { return(await Task.Factory.StartNew(() => { ShippingStatus Status = ShippingStatus.Delivered; switch (SS) { case "Delivered": Status = ShippingStatus.Delivered; break; case "Not Yet Shipped": Status = ShippingStatus.NotYetShipped; break; case "Partially Shipped": Status = ShippingStatus.PartiallyShipped; break; case "Shipped": Status = ShippingStatus.Shipped; break; case "Shipping Not Required": Status = ShippingStatus.ShippingNotRequired; break; } return client.GetOrders(0, 0, 0, 0, 0, null, null, Status, null, 0, 20); }).ConfigureAwait(false)); }
/// <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 virtual IPagedList<BestCustomerReportLine> GetBestCustomersReport(DateTime? createdFromUtc, DateTime? createdToUtc, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, int orderBy, int pageIndex = 0, int pageSize = 214748364) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query1 = from c in _customerRepository.Table join o in _orderRepository.Table on c.Id equals o.CustomerId where (!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) && (!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && (!o.Deleted) && (!c.Deleted) select new { c, o }; var query2 = from co in query1 group co by co.c.Id into g select new { CustomerId = g.Key, OrderTotal = g.Sum(x => x.o.OrderTotal), OrderCount = g.Count() }; switch (orderBy) { case 1: { query2 = query2.OrderByDescending(x => x.OrderTotal); } break; case 2: { query2 = query2.OrderByDescending(x => x.OrderCount); } break; default: throw new ArgumentException("Wrong orderBy parameter", "orderBy"); } var tmp = new PagedList<dynamic>(query2, pageIndex, pageSize); return new PagedList<BestCustomerReportLine>(tmp.Select(x => new BestCustomerReportLine { CustomerId = x.CustomerId, OrderTotal = x.OrderTotal, OrderCount = x.OrderCount }), tmp.PageIndex, tmp.PageSize, tmp.TotalCount); }
/** * Shipment has been sent to the customer. */ public void Ship() { if (ShipmentStatus != ShippingStatus.Waiting) { throw new IllegalStateException("Cannot ship in status " + ShipmentStatus); } ShipmentStatus = ShippingStatus.Sent; EventPublisher.Publish(new OrderShippedEvent(OrderId, Id)); }
/** * Shipment has been confirmed received by the customer. */ public void Deliver() { if (ShipmentStatus != ShippingStatus.Sent) { throw new IllegalStateException("cannot deliver in status " + ShipmentStatus); } ShipmentStatus = ShippingStatus.Delivered; EventPublisher.Publish(new ShipmentDeliveredEvent(Id)); }
/** * Shipment has been sent to the customer. */ public void Ship() { if (ShipmentStatus != ShippingStatus.WAITING) { throw new IllegalStateException("Cannot ship in status " + ShipmentStatus); } ShipmentStatus = ShippingStatus.SENT; EventPublisher.Publish(new OrderShippedEvent(OrderId, AggregateId)); }
private async void PatchOrderStatus(Order ocOrder, ShippingStatus shippingStatus, OrderStatus orderStatus) { var partialOrder = new PartialOrder { xp = new { ShippingStatus = shippingStatus, SubmittedOrderStatus = orderStatus } }; await _oc.Orders.PatchAsync(OrderDirection.Outgoing, ocOrder.ID, partialOrder); }
private Query GetShippingStatusQuery() { return(new BooleanQuery { { new TermQuery(new Term(FieldDefinition.GetFieldName <OrderSearchShippingStatusDefinition>(), ShippingStatus.ToString())), Occur.MUST } }); }
/// <summary> /// Get "order by country" report /// </summary> /// <param name="storeId">Store identifier</param> /// <param name="os">Order status</param> /// <param name="ps">Payment status</param> /// <param name="ss">Shipping status</param> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</param> /// <returns>Result</returns> public virtual IList<OrderByCountryReportLine> GetCountryReport(int storeId, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, DateTime? startTimeUtc, DateTime? endTimeUtc) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; query = query.Where(o => !o.Deleted); if (storeId > 0) query = query.Where(o => o.StoreId == storeId); if (orderStatusId.HasValue) query = query.Where(o => o.OrderStatusId == orderStatusId.Value); if (paymentStatusId.HasValue) query = query.Where(o => o.PaymentStatusId == paymentStatusId.Value); if (shippingStatusId.HasValue) query = query.Where(o => o.ShippingStatusId == shippingStatusId.Value); if (startTimeUtc.HasValue) query = query.Where(o => startTimeUtc.Value <= o.CreatedOnUtc); if (endTimeUtc.HasValue) query = query.Where(o => endTimeUtc.Value >= o.CreatedOnUtc); var report = (from oq in query group oq by oq.BillingAddress.CountryId into result select new { CountryId = result.Key, TotalOrders = result.Count(), SumOrders = result.Sum(o => o.OrderTotal) } ) .OrderByDescending(x => x.SumOrders) .Select(r => new OrderByCountryReportLine { CountryId = r.CountryId, TotalOrders = r.TotalOrders, SumOrders = r.SumOrders }) .ToList(); return report; }
public void AfterChangeShippingStatus(Order order, ShippingStatus oldStatus) { var systemConfig = _configService.Get <SystemConfig>(); if (oldStatus == ShippingStatus.Unshipped && order.ShippingStatus == ShippingStatus.Shipped) { //订单付款减库存 if (systemConfig.ReduceStock == Config.Models.ReduceStock.AfterDeliver) { ReduceStock(order); } } }
private string GetShippingStatusName(ShippingStatus status) { switch (status) { case ShippingStatus.Delivered: return("رسیده به دست مشتری"); case ShippingStatus.NotYetShipped: return("هنوز ارسال نشده"); case ShippingStatus.Shipped: return("ارسال شده"); case ShippingStatus.ShippingNotRequired: return("ارسال نیاز نمیباشد"); } return(null); }
public void GetShippingStatus_ResultExistsInCache_ReturnsTheResult() { // arrange Mock <ObjectCache> mockCache = new Mock <ObjectCache>(); mockCache.Setup(c => c["statusForOrder#12"]).Returns(ShippingStatus.OutForDelivery); ShippingService sut = new ShippingService(null, null, null, mockCache.Object); // act ShippingStatus actual = sut.GetShippingStatus(12); // assert Assert.AreEqual(ShippingStatus.OutForDelivery, actual); mockCache.Verify(c => c["statusForOrder#12"], Times.Once()); }
public IQueryable <ServiceRequest> GetServiceRequests() { string key; ShippingStatus current = ShippingStatus.New; if (TryGetRouteParameter("Key", out key) && !string.IsNullOrEmpty(key)) { Enum.TryParse(key, true, out current); } if (CurrentUser == null) { return(null); } return(adminServices.GethippingTransactionsData(current).AsQueryable()); }
public void GetShippingStatus_ResultNotExistsInCache_FetchesTheResultFromDatabase() { // arrange Mock <ObjectCache> mockCache = new Mock <ObjectCache>(); Mock <IShippingInfoRepository> mockShippingRepo = new Mock <IShippingInfoRepository>(); mockShippingRepo.Setup(r => r.GetShippingStatus(It.Is <int>(i => i == 210))).Returns(ShippingStatus.InTransit); ShippingService sut = new ShippingService(null, mockShippingRepo.Object, null, mockCache.Object); // act ShippingStatus actual = sut.GetShippingStatus(210); // assert Assert.AreEqual(ShippingStatus.InTransit, actual); mockCache.Verify(c => c["statusForOrder#210"], Times.Once()); }
public void ShippingStatus_Serialize_PropertyNamesAsExpected() { // Arrange var shippingStatus = new ShippingStatus(); // Act var serializedObject = JsonConvert.SerializeObject(shippingStatus); // Assert Assert.AreEqual(@"{ ""tracktrace_code"": null, ""carrier"": null, ""ship_date"": null, ""memo"": null }".RemoveWhiteSpace(), serializedObject.RemoveWhiteSpace()); }
private string GetStatusTitle(ShippingStatus status) { switch (status) { case ShippingStatus.OutForDelivery: return("Out for Delivery"); case ShippingStatus.PickedUp: return("Picked up"); case ShippingStatus.ReceivedOrder: return("Received order"); default: return(status.ToString()); } }
public async Task Update( int id, OrderStatus orderStatus, PaymentStatus paymentStatus, ShippingStatus shippingStatus ) { using (var conn = new MySqlConnection(_connStr)) { await conn.ExecuteAsync(updOrder, new { id, @status = (int)orderStatus, @pmt_status = (int)paymentStatus, @shipping_status = (int)shippingStatus, }); } }
public IPagedList<BestCustomerReportLine> GetBestCustomersReport(DateTime? createdFromUtc, DateTime? createdToUtc, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, int orderBy, int pageIndex = 0, int pageSize = int.MaxValue) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query1 = from c in _customerRepository.Table join o in _orderRepository.Table on c.Id equals o.CustomerId where !c.Deleted && !o.Deleted && (!createdFromUtc.HasValue || o.CreatedOnUtc >= createdFromUtc.Value) && (!createdToUtc.HasValue || o.CreatedOnUtc <= createdToUtc.Value) && (!orderStatusId.HasValue || o.OrderStatusId == orderStatusId.Value) && (!paymentStatusId.HasValue || o.PaymentStatusId == paymentStatusId.Value) && (!shippingStatusId.HasValue || o.ShippingStatusId == shippingStatusId.Value) select new { c, o }; var query = from co in query1 group co by co.c.Id into g select new BestCustomerReportLine // khác chỗ này { CustomerId = g.Key, OrderTotal = g.Sum(x => x.o.OrderTotal), OrderCount = g.Count() }; switch(orderBy) { case 1: query = query.OrderByDescending(p => p.OrderTotal); break; case 2: query = query.OrderByDescending(p => p.OrderCount); break; default: throw new ArgumentException("Wrong orderBy parameter", "orderBy"); } var result = new PagedList<BestCustomerReportLine>(query, pageIndex, pageSize); return result; }
/// <summary> /// Get order average report /// </summary> /// <param name="os">Order status</param> /// <param name="ps">Payment status</param> /// <param name="ss">Shipping status</param> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="ignoreCancelledOrders">A value indicating whether to ignore cancelled orders</param> /// <returns>Result</returns> public virtual OrderAverageReportLine GetOrderAverageReportLine(OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, DateTime? startTimeUtc, DateTime? endTimeUtc, string billingEmail, bool ignoreCancelledOrders = false) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; query = query.Where(o => !o.Deleted); if (ignoreCancelledOrders) { int cancelledOrderStatusId = (int)OrderStatus.Cancelled; query = query.Where(o => o.OrderStatusId != cancelledOrderStatusId); } if (orderStatusId.HasValue) query = query.Where(o => o.OrderStatusId == orderStatusId.Value); if (paymentStatusId.HasValue) query = query.Where(o => o.PaymentStatusId == paymentStatusId.Value); if (shippingStatusId.HasValue) query = query.Where(o => o.ShippingStatusId == shippingStatusId.Value); if (startTimeUtc.HasValue) query = query.Where(o => startTimeUtc.Value <= o.CreatedOnUtc); if (endTimeUtc.HasValue) query = query.Where(o => endTimeUtc.Value >= o.CreatedOnUtc); if (!String.IsNullOrEmpty(billingEmail)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail)); var item = (from oq in query group oq by 1 into result select new { OrderCount = result.Count(), OrderTaxSum = result.Sum(o => o.OrderTax), OrderTotalSum = result.Sum(o => o.OrderTotal) } ).Select(r => new OrderAverageReportLine(){ SumTax = r.OrderTaxSum, CountOrders=r.OrderCount, SumOrders = r.OrderTotalSum}).FirstOrDefault(); item = item ?? new OrderAverageReportLine() { CountOrders = 0, SumOrders = decimal.Zero, SumTax = decimal.Zero }; return item; }
public void GetShippingStatus_GivenAValidOrderID_ReturnsTheShippingStatus() { // arrange ShippingInfo shipping = new ShippingInfo() { Status = ShippingStatus.InTransit }; Mock <DbSet <ShippingInfo> > mockSet = new Mock <DbSet <ShippingInfo> >(); mockSet.Setup(s => s.Find(It.Is <int>(a => a == 300))).Returns(shipping); Mock <ShippingDb> mockContext = new Mock <ShippingDb>(); mockContext.Setup(c => c.Shippings).Returns(mockSet.Object); ShippingInfoRepository sut = new ShippingInfoRepository(mockContext.Object); // act ShippingStatus actual = sut.GetShippingStatus(300); // assert mockSet.Verify(s => s.Find(It.Is <int>(a => a == 300)), Times.Once()); Assert.AreEqual(ShippingStatus.InTransit, actual); }
protected string GetShipButtonText(ShippingStatus shippingStatus) { string text = ""; switch (shippingStatus) { case ShippingStatus.New: text = "تحويل الطلب للبريد"; break; case ShippingStatus.SentToPostOffice: text = "تأكيد الإستلام"; break; case ShippingStatus.ReceivedFromCustomer: text = "تأكيد التسليم"; break; case ShippingStatus.SentToPartner: text = "تم الإستلام"; break; case ShippingStatus.ReceivedFromPartner: text = "تم التحويل"; break; case ShippingStatus.SentToCustomer: text = "محول"; break; default: text = ""; break; } return(text); }
public Shipment(AggregateId orderId) { OrderId = orderId; ShipmentStatus = ShippingStatus.WAITING; }
/// <summary> /// Get best sellers report /// </summary> /// <param name="storeId">Store identifier (orders placed in a specific store); 0 to load all records</param> /// <param name="vendorId">Vendor identifier; 0 to load all records</param> /// <param name="categoryId">Category identifier; 0 to load all records</param> /// <param name="manufacturerId">Manufacturer identifier; 0 to load all records</param> /// <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">Shipping status; null to load all records</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all records</param> /// <param name="orderBy">1 - order by quantity, 2 - order by total amount</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Result</returns> public virtual IPagedList<BestsellersReportLine> BestSellersReport( int categoryId = 0, int manufacturerId = 0, int storeId = 0, int vendorId = 0, DateTime? createdFromUtc = null, DateTime? createdToUtc = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, int billingCountryId = 0, int orderBy = 1, int pageIndex = 0, int pageSize = int.MaxValue, bool showHidden = false) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query1 = from orderItem in _orderItemRepository.Table join o in _orderRepository.Table on orderItem.OrderId equals o.Id join p in _productRepository.Table on orderItem.ProductId equals p.Id //join pc in _productCategoryRepository.Table on p.Id equals pc.ProductId into p_pc from pc in p_pc.DefaultIfEmpty() //join pm in _productManufacturerRepository.Table on p.Id equals pm.ProductId into p_pm from pm in p_pm.DefaultIfEmpty() where (storeId == 0 || storeId == o.StoreId) && (!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) && (!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && (!o.Deleted) && (!p.Deleted) && (vendorId == 0 || p.VendorId == vendorId) && //(categoryId == 0 || pc.CategoryId == categoryId) && //(manufacturerId == 0 || pm.ManufacturerId == manufacturerId) && (categoryId == 0 || p.ProductCategories.Count(pc => pc.CategoryId == categoryId) > 0) && (manufacturerId == 0 || p.ProductManufacturers.Count(pm => pm.ManufacturerId == manufacturerId) > 0) && (billingCountryId == 0 || o.BillingAddress.CountryId == billingCountryId) && (showHidden || p.Published) select orderItem; IQueryable<BestsellersReportLine> query2 = //group by products from orderItem in query1 group orderItem by orderItem.ProductId into g select new BestsellersReportLine { ProductId = g.Key, TotalAmount = g.Sum(x => x.PriceExclTax), TotalQuantity = g.Sum(x => x.Quantity), } ; switch (orderBy) { case 1: { query2 = query2.OrderByDescending(x => x.TotalQuantity); } break; case 2: { query2 = query2.OrderByDescending(x => x.TotalAmount); } break; default: throw new ArgumentException("Wrong orderBy parameter", "orderBy"); } var result = new PagedList<BestsellersReportLine>(query2, pageIndex, pageSize); return result; }
/// <summary> /// Search orders /// </summary> /// <param name="startTime">Order start time; null to load all orders</param> /// <param name="endTime">Order end time; null to load all orders</param> /// <param name="os">Order status; null to load all orders</param> /// <param name="ps">Order payment status; null to load all orders</param> /// <param name="ss">Order shippment status; null to load all orders</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="orderGuid">Search by order GUID (Global unique identifier) or part of GUID. Leave empty to load all orders.</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>Order collection</returns> public virtual IPagedList<Order> SearchOrders(DateTime? startTime, DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, string billingEmail, string orderGuid, int pageIndex, int pageSize) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; if (startTime.HasValue) query = query.Where(o => startTime.Value <= o.CreatedOnUtc); if (endTime.HasValue) query = query.Where(o => endTime.Value >= o.CreatedOnUtc); if (orderStatusId.HasValue) query = query.Where(o => orderStatusId.Value == o.OrderStatusId); if (paymentStatusId.HasValue) query = query.Where(o => paymentStatusId.Value == o.PaymentStatusId); if (shippingStatusId.HasValue) query = query.Where(o => shippingStatusId.Value == o.ShippingStatusId); if (!String.IsNullOrEmpty(billingEmail)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail)); query = query.Where(o => !o.Deleted); query = query.OrderByDescending(o => o.CreatedOnUtc); var orders = query.ToList(); //filter by GUID. Filter in BLL because EF doesn't support casting of GUID to string if (!String.IsNullOrEmpty(orderGuid)) orders = orders.FindAll(o => o.OrderGuid.ToString().ToLowerInvariant().Contains(orderGuid.ToLowerInvariant())); return new PagedList<Order>(orders, pageIndex, pageSize); }
/// <summary> /// Gets all order product variants /// </summary> /// <param name="orderId">Order identifier; null to load all records</param> /// <param name="customerId">Customer identifier; null to load all records</param> /// <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 shippment status; null to load all records</param> /// <param name="loadDownloableProductsOnly">Value indicating whether to load downloadable products only</param> /// <returns>Order collection</returns> public virtual IList<OrderProductVariant> GetAllOrderProductVariants(int? orderId, int? customerId, DateTime? createdFromUtc, DateTime? createdToUtc, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, bool loadDownloableProductsOnly) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = from opv in _opvRepository.Table join o in _orderRepository.Table on opv.OrderId equals o.Id join pv in _pvRepository.Table on opv.ProductVariantId equals pv.Id where (!orderId.HasValue || orderId.Value == 0 || orderId == o.Id) && (!customerId.HasValue || customerId.Value == 0 || customerId == o.CustomerId) && (!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) && (!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId.Value == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId.Value == o.ShippingStatusId) && (!loadDownloableProductsOnly || pv.IsDownload) && !o.Deleted orderby o.CreatedOnUtc descending, opv.Id select opv; var orderProductVariants = query.ToList(); return orderProductVariants; }
/// <summary> /// Get best sellers report /// </summary> /// <param name="storeId">Store identifier; 0 to load all records</param> /// <param name="vendorId">Vendor identifier; 0 to load all records</param> /// <param name="categoryId">Category identifier; 0 to load all records</param> /// <param name="manufacturerId">Manufacturer identifier; 0 to load all records</param> /// <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">Shipping status; null to load all records</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all records</param> /// <param name="orderBy">1 - order by quantity, 2 - order by total amount</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Result</returns> public virtual IPagedList<BestsellersReportLine> BestSellersReport( int categoryId = 0, int manufacturerId = 0, int storeId = 0, int vendorId = 0, DateTime? createdFromUtc = null, DateTime? createdToUtc = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, int billingCountryId = 0, int orderBy = 1, int pageIndex = 0, int pageSize = int.MaxValue, bool showHidden = false) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var builder = Builders<Order>.Filter; var filter = builder.Where(o => !o.Deleted); if (storeId > 0) filter = filter & builder.Where(o => o.StoreId == storeId); if (vendorId > 0) { filter = filter & builder .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.VendorId == vendorId)); } if (billingCountryId > 0) filter = filter & builder.Where(o => o.BillingAddress != null && o.BillingAddress.CountryId == billingCountryId); if (orderStatusId.HasValue) filter = filter & builder.Where(o => o.OrderStatusId == orderStatusId.Value); if (paymentStatusId.HasValue) filter = filter & builder.Where(o => o.PaymentStatusId == paymentStatusId.Value); if (shippingStatusId.HasValue) filter = filter & builder.Where(o => o.ShippingStatusId == shippingStatusId.Value); if (createdFromUtc.HasValue) filter = filter & builder.Where(o => createdFromUtc.Value <= o.CreatedOnUtc); if (createdToUtc.HasValue) filter = filter & builder.Where(o => createdToUtc.Value >= o.CreatedOnUtc); if(manufacturerId > 0) filter = filter & builder.Where( o=> o.OrderItems.Any(x => x.Product.ProductManufacturers.Any(pm => pm.ManufacturerId == manufacturerId))); if (categoryId > 0) filter = filter & builder.Where(o => o.OrderItems.Any(x => x.Product.ProductCategories.Any(pc => pc.CategoryId == categoryId))); var query = _orderRepository.Collection .Aggregate() .Match(filter) .Unwind<Order, UnwindedOrderItem>(x => x.OrderItems) .Group(x => x.OrderItems.ProductId, g => new BestsellersReportLine { ProductId = g.Key, TotalAmount = g.Sum(x => x.OrderItems.PriceExclTax), TotalQuantity = g.Sum(x => x.OrderItems.Quantity), }); if (orderBy == 1) { query = query.SortByDescending(x => x.TotalQuantity); } else { query = query.SortByDescending(x => x.TotalAmount); } var query2 = query.ToListAsync().Result; var result = new PagedList<BestsellersReportLine>(query2, pageIndex, pageSize); return result; }
/// <summary> /// Get order average report /// </summary> /// <param name="storeId">Store identifier; pass 0 to ignore this parameter</param> /// <param name="vendorId">Vendor identifier; pass 0 to ignore this parameter</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all orders</param> /// <param name="orderId">Order identifier; pass 0 to ignore this parameter</param> /// <param name="paymentMethodSystemName">Payment method system name; null to load all records</param> /// <param name="os">Order status</param> /// <param name="ps">Payment status</param> /// <param name="ss">Shipping status</param> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="ignoreCancelledOrders">A value indicating whether to ignore cancelled orders</param> /// <param name="orderNotes">Search in order notes. Leave empty to load all records.</param> /// <returns>Result</returns> public virtual OrderAverageReportLine GetOrderAverageReportLine(int storeId = 0, int vendorId = 0, int billingCountryId = 0, int orderId = 0, string paymentMethodSystemName = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, DateTime? startTimeUtc = null, DateTime? endTimeUtc = null, string billingEmail = null, string billingLastName = "", bool ignoreCancelledOrders = false) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var builder = Builders<Order>.Filter; var filter = builder.Where(o => !o.Deleted); if (storeId > 0) filter = filter & builder.Where(o => o.StoreId == storeId); if (orderId > 0) filter = filter & builder.Where(o => o.StoreId == storeId); if (vendorId > 0) { filter = filter & builder .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.VendorId == vendorId)); } if (billingCountryId > 0) filter = filter & builder.Where(o => o.BillingAddress != null && o.BillingAddress.CountryId == billingCountryId); if (ignoreCancelledOrders) { var cancelledOrderStatusId = (int)OrderStatus.Cancelled; filter = filter & builder.Where(o => o.OrderStatusId == cancelledOrderStatusId); } if (!String.IsNullOrEmpty(paymentMethodSystemName)) filter = filter & builder.Where(o => o.PaymentMethodSystemName == paymentMethodSystemName); if (orderStatusId.HasValue) filter = filter & builder.Where(o => o.OrderStatusId == orderStatusId.Value); if (paymentStatusId.HasValue) filter = filter & builder.Where(o => o.PaymentStatusId == paymentStatusId.Value); if (shippingStatusId.HasValue) filter = filter & builder.Where(o => o.ShippingStatusId == shippingStatusId.Value); if (startTimeUtc.HasValue) filter = filter & builder.Where(o => startTimeUtc.Value <= o.CreatedOnUtc); if (endTimeUtc.HasValue) filter = filter & builder.Where(o => startTimeUtc.Value >= o.CreatedOnUtc); if (!String.IsNullOrEmpty(billingEmail)) filter = filter & builder.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail)); if (!String.IsNullOrEmpty(billingLastName)) filter = filter & builder.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.LastName) && o.BillingAddress.LastName.Contains(billingLastName)); var query = _orderRepository.Collection .Aggregate() .Match(filter) .Unwind<Order, Order>(x => x.OrderItems) .Group(x => 1, g => new OrderAverageReportLine { CountOrders = g.Count(), SumShippingExclTax = g.Sum(o => o.OrderShippingExclTax), SumTax = g.Sum(o => o.OrderTax), SumOrders = g.Sum(o => o.OrderTotal) }).ToListAsync().Result; var item2 = query.Count() > 0 ? query.FirstOrDefault() : new OrderAverageReportLine { CountOrders = 0, SumShippingExclTax = decimal.Zero, SumTax = decimal.Zero, SumOrders = decimal.Zero, }; return item2; }
/// <summary> /// Gets all order items /// </summary> /// <param name="orderId">Order identifier; null to load all records</param> /// <param name="customerId">Customer identifier; null to load all records</param> /// <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="loadDownloableProductsOnly">Value indicating whether to load downloadable products only</param> /// <returns>Orders</returns> public virtual IList<OrderItem> GetAllOrderItems(int? orderId, int? customerId, DateTime? createdFromUtc, DateTime? createdToUtc, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, bool loadDownloableProductsOnly) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var builder = Builders<Order>.Filter; var filter = builder.Where(x => true); if (orderId.HasValue) filter = filter & builder.Where(o => o.Id == orderId.Value); if (customerId.HasValue) filter = filter & builder.Where(o => o.CustomerId == customerId.Value); if (orderStatusId.HasValue) filter = filter & builder.Where(o => o.OrderStatusId == orderStatusId.Value); if (paymentStatusId.HasValue) filter = filter & builder.Where(o => o.PaymentStatusId== paymentStatusId.Value); if (shippingStatusId.HasValue) filter = filter & builder.Where(o => o.ShippingStatusId == shippingStatusId.Value); if (createdFromUtc.HasValue) filter = filter & builder.Where(o => o.CreatedOnUtc >= createdFromUtc.Value); if (createdFromUtc.HasValue) filter = filter & builder.Where(o => o.CreatedOnUtc >= createdFromUtc.Value); var query = _orderRepository.Collection.Aggregate().Match(filter).Unwind<Order, UnwindOrderItem>(x => x.OrderItems).ToListAsync().Result; var items = new List<OrderItem>(); foreach(var item in query) { if(loadDownloableProductsOnly) { var product = _productRepository.GetById(item.OrderItems.ProductId); if (product.IsDownload) { item.OrderItems.Product = product; items.Add(item.OrderItems); } } else items.Add(item.OrderItems); } //var query = from o in _orderRepository.Collection.AsQueryable() // where (!orderId.HasValue || orderId.Value == 0 || orderId == o.Id) && // (customerId == o.CustomerId) && !o.Deleted // //(!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) && // //(!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) && // //(!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && // //(!paymentStatusId.HasValue || paymentStatusId.Value == o.PaymentStatusId) && // //(!shippingStatusId.HasValue || shippingStatusId.Value == o.ShippingStatusId) && // //(!loadDownloableProductsOnly || p.IsDownload) && // from orderItem in o.OrderItems // //join p in _productRepository.Table on orderItem.ProductId equals p.Id // orderby o.CreatedOnUtc descending, orderItem.Id // select orderItem; //var orderItems = query.ToList(); return items; }
/// <summary> /// Get profit report /// </summary> /// <param name="storeId">Store identifier; pass 0 to ignore this parameter</param> /// <param name="vendorId">Vendor identifier; pass 0 to ignore this parameter</param> /// <param name="orderId">Order identifier; pass 0 to ignore this parameter</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all orders</param> /// <param name="paymentMethodSystemName">Payment method system name; null to load all records</param> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</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">Shipping status; null to load all records</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="orderNotes">Search in order notes. Leave empty to load all records.</param> /// <returns>Result</returns> public virtual decimal ProfitReport(int storeId = 0, int vendorId = 0, int billingCountryId = 0, int orderId = 0, string paymentMethodSystemName = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, DateTime? startTimeUtc = null, DateTime? endTimeUtc = null, string billingEmail = null, string billingLastName = "") { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; query = query.Where(o => !o.Deleted); if (storeId > 0) query = query.Where(o => o.StoreId == storeId); if (orderId > 0) query = query.Where(o => o.Id == orderId); if (vendorId > 0) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.VendorId == vendorId)); } if (billingCountryId > 0) query = query.Where(o => o.BillingAddress != null && o.BillingAddress.CountryId == billingCountryId); if (!String.IsNullOrEmpty(paymentMethodSystemName)) query = query.Where(o => o.PaymentMethodSystemName == paymentMethodSystemName); if (orderStatusId.HasValue) query = query.Where(o => o.OrderStatusId == orderStatusId.Value); if (paymentStatusId.HasValue) query = query.Where(o => o.PaymentStatusId == paymentStatusId.Value); if (shippingStatusId.HasValue) query = query.Where(o => o.ShippingStatusId == shippingStatusId.Value); if (startTimeUtc.HasValue) query = query.Where(o => startTimeUtc.Value <= o.CreatedOnUtc); if (endTimeUtc.HasValue) query = query.Where(o => endTimeUtc.Value >= o.CreatedOnUtc); if (!String.IsNullOrEmpty(billingEmail)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail)); if (!String.IsNullOrEmpty(billingLastName)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.LastName) && o.BillingAddress.LastName.Contains(billingLastName)); var query2 = from o in query from p in o.OrderItems select p; var productCost = query2.Sum(orderItem => orderItem.OriginalProductCost * orderItem.Quantity); var reportSummary = GetOrderAverageReportLine( storeId: storeId, vendorId: vendorId, billingCountryId: billingCountryId, orderId: orderId, paymentMethodSystemName: paymentMethodSystemName, os: os, ps: ps, ss: ss, startTimeUtc: startTimeUtc, endTimeUtc: endTimeUtc, billingEmail: billingEmail ); var profit = Convert.ToDecimal( reportSummary.SumOrders - reportSummary.SumShippingExclTax - reportSummary.SumTax - productCost); return profit; }
/// <summary> /// Search orders /// </summary> /// <param name="startTime">Order start time; null to load all orders</param> /// <param name="endTime">Order end time; null to load all orders</param> /// <param name="os">Order status; null to load all orders</param> /// <param name="ps">Order payment status; null to load all orders</param> /// <param name="ss">Order shippment status; null to load all orders</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="orderGuid">Search by order GUID (Global unique identifier) or part of GUID. Leave empty to load all orders.</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <param name="storId">vendor id</param> /// <returns>Order collection</returns> public virtual IPagedList<Order> SearchOrders(DateTime? startTime, DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, string billingEmail, string orderGuid, int pageIndex, int pageSize, int vendorId) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; //add by hz if (vendorId > 0) { query = (from o in _orderRepository.Table join opv in _opvRepository.Table on o.Id equals opv.OrderId join pv in _pvRepository.Table on opv.ProductVariantId equals pv.Id join p in _productRepository.Table on pv.ProductId equals p.Id join pvendor in _productVendorRepository.Table on p.Id equals pvendor.ProductId where pvendor.VendorId == vendorId select o).Distinct() ; } //end by hz if (startTime.HasValue) query = query.Where(o => startTime.Value <= o.CreatedOnUtc); if (endTime.HasValue) query = query.Where(o => endTime.Value >= o.CreatedOnUtc); if (orderStatusId.HasValue) query = query.Where(o => orderStatusId.Value == o.OrderStatusId); if (paymentStatusId.HasValue) query = query.Where(o => paymentStatusId.Value == o.PaymentStatusId); if (shippingStatusId.HasValue) query = query.Where(o => shippingStatusId.Value == o.ShippingStatusId); if (!String.IsNullOrEmpty(billingEmail)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail)); query = query.Where(o => !o.Deleted); query = query.OrderByDescending(o => o.CreatedOnUtc); var orders = query.ToList(); //filter by GUID. Filter in BLL because EF doesn't support casting of GUID to string if (!String.IsNullOrEmpty(orderGuid)) orders = orders.FindAll(o => o.OrderGuid.ToString().ToLowerInvariant().Contains(orderGuid.ToLowerInvariant())); return new PagedList<Order>(orders, pageIndex, pageSize); }
public void WhenCalledWithSomeShippingStatus_GivenOrdersCollectionContainingOrdersHavingThisStatus_ShouldReturnTheOrdersHavingThisStatusOrderedById(ShippingStatus shippingStatus) { // Arange var expectedCollection = _existigOrders.Where(x => x.ShippingStatus == shippingStatus).OrderBy(x => x.Id); // Act var orders = _orderApiService.GetOrders(shippingStatus: shippingStatus); // Assert CollectionAssert.IsNotEmpty(orders); Assert.AreEqual(expectedCollection.Count(), orders.Count); Assert.IsTrue(orders.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id))); }
/// <summary> /// Get best sellers report /// </summary> /// <param name="storeId">Store identifier; 0 to load all records</param> /// <param name="vendorId">Vendor identifier; 0 to load all records</param> /// <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">Shipping status; null to load all records</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all records</param> /// <param name="orderBy">1 - order by quantity, 2 - order by total amount</param> /// <param name="groupBy">1 - group by product variants, 2 - group by products</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Result</returns> public virtual IPagedList<BestsellersReportLine> BestSellersReport(int storeId = 0, int vendorId = 0, DateTime? createdFromUtc = null, DateTime? createdToUtc = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, int billingCountryId = 0, int orderBy = 1, int groupBy = 1, int pageIndex = 0, int pageSize = 2147483647, bool showHidden = false) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query1 = from opv in _opvRepository.Table join o in _orderRepository.Table on opv.OrderId equals o.Id join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id join p in _productRepository.Table on pv.ProductId equals p.Id where (storeId == 0 || storeId == o.StoreId) && (!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) && (!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && (!o.Deleted) && (!p.Deleted) && (vendorId == 0 || p.VendorId == vendorId) && (!pv.Deleted) && (billingCountryId == 0 || o.BillingAddress.CountryId == billingCountryId) && (showHidden || p.Published) && (showHidden || pv.Published) select opv; IQueryable<BestsellersReportLine> query2 = groupBy == 1 ? //group by product variants from opv in query1 group opv by opv.ProductVariantId into g select new BestsellersReportLine() { EntityId = g.Key, TotalAmount = g.Sum(x => x.PriceExclTax), TotalQuantity = g.Sum(x => x.Quantity), } : //group by products from opv in query1 group opv by opv.ProductVariant.ProductId into g select new BestsellersReportLine() { EntityId = g.Key, TotalAmount = g.Sum(x => x.PriceExclTax), TotalQuantity = g.Sum(x => x.Quantity), } ; switch (orderBy) { case 1: { query2 = query2.OrderByDescending(x => x.TotalQuantity); } break; case 2: { query2 = query2.OrderByDescending(x => x.TotalAmount); } break; default: throw new ArgumentException("Wrong orderBy parameter", "orderBy"); } var result = new PagedList<BestsellersReportLine>(query2, pageIndex, pageSize); return result; }
/// <summary> /// Get best sellers report /// </summary> /// <param name="startTime">Order start time; null to load all</param> /// <param name="endTime">Order end time; null to load all</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">Shipping status; null to load all records</param> /// <param name="recordsToReturn">Records to return</param> /// <param name="orderBy">1 - order by quantity, 2 - order by total amount</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Result</returns> public virtual IList<BestsellersReportLine> BestSellersReport(DateTime? startTime, DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, int recordsToReturn = 5, int orderBy = 1, bool showHidden = false) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query1 = from opv in _opvRepository.Table join o in _orderRepository.Table on opv.OrderId equals o.Id join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id join p in _productRepository.Table on pv.ProductId equals p.Id where (!startTime.HasValue || startTime.Value <= o.CreatedOnUtc) && (!endTime.HasValue || endTime.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && (!o.Deleted) && (!p.Deleted) && (!pv.Deleted) && (showHidden || p.Published) && (showHidden || pv.Published) select opv; var query2 = from opv in query1 group opv by opv.ProductVariantId into g select new { ProductVariantId = g.Key, TotalAmount = g.Sum(x => x.PriceExclTax), TotalQuantity = g.Sum(x => x.Quantity), }; switch (orderBy) { case 1: { query2 = query2.OrderByDescending(x => x.TotalQuantity); } break; case 2: { query2 = query2.OrderByDescending(x => x.TotalAmount); } break; default: throw new ArgumentException("Wrong orderBy parameter", "orderBy"); } if (recordsToReturn != 0 && recordsToReturn != int.MaxValue) query2 = query2.Take(recordsToReturn); var result = query2.ToList().Select(x => { return new BestsellersReportLine() { ProductVariantId = x.ProductVariantId, TotalAmount = x.TotalAmount, TotalQuantity = x.TotalQuantity }; }).ToList(); return result; }
/// <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 shippment status; null to load all records</param> /// <param name="orderBy">1 - order by order total, 2 - order by number of orders</param> /// <returns>Report</returns> public virtual IList<BestCustomerReportLine> GetBestCustomersReport(DateTime? createdFromUtc, DateTime? createdToUtc, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, int orderBy) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query1 = from c in _customerRepository.Table join o in _orderRepository.Table on c.Id equals o.CustomerId where (!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) && (!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && (!o.Deleted) && (!c.Deleted) select new { c, o }; var query2 = from co in query1 group co by co.c.Id into g select new { CustomerId = g.Key, OrderTotal = g.Sum(x => x.o.OrderTotal), OrderCount = g.Count() }; switch (orderBy) { case 1: { query2 = query2.OrderByDescending(x => x.OrderTotal); } break; case 2: { query2 = query2.OrderByDescending(x => x.OrderCount); } break; default: throw new ArgumentException("Wrong orderBy parameter", "orderBy"); } //load 20 customers query2 = query2.Take(20); var result = query2.ToList().Select(x => { return new BestCustomerReportLine() { CustomerId = x.CustomerId, OrderTotal = x.OrderTotal, OrderCount = x.OrderCount }; }).ToList(); return result; }
/// <summary> /// Get order average report /// </summary> /// <param name="storeId">Store identifier; pass 0 to ignore this parameter</param> /// <param name="vendorId">Vendor identifier; pass 0 to ignore this parameter</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all orders</param> /// <param name="orderId">Order identifier; pass 0 to ignore this parameter</param> /// <param name="paymentMethodSystemName">Payment method system name; null to load all records</param> /// <param name="os">Order status</param> /// <param name="ps">Payment status</param> /// <param name="ss">Shipping status</param> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="billingLastName">Billing last name. Leave empty to load all records.</param> /// <param name="ignoreCancelledOrders">A value indicating whether to ignore cancelled orders</param> /// <param name="orderNotes">Search in order notes. Leave empty to load all records.</param> /// <returns>Result</returns> public virtual OrderAverageReportLine GetOrderAverageReportLine(int storeId = 0, int vendorId = 0, int billingCountryId = 0, int orderId = 0, string paymentMethodSystemName = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, DateTime? startTimeUtc = null, DateTime? endTimeUtc = null, string billingEmail = null, string billingLastName = "", bool ignoreCancelledOrders = false, string orderNotes = null) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; query = query.Where(o => !o.Deleted); if (storeId > 0) query = query.Where(o => o.StoreId == storeId); if (orderId > 0) query = query.Where(o => o.Id == orderId); if (vendorId > 0) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.VendorId == vendorId)); } if (billingCountryId > 0) query = query.Where(o => o.BillingAddress != null && o.BillingAddress.CountryId == billingCountryId); if (ignoreCancelledOrders) { var cancelledOrderStatusId = (int)OrderStatus.Cancelled; query = query.Where(o => o.OrderStatusId != cancelledOrderStatusId); } if (!String.IsNullOrEmpty(paymentMethodSystemName)) query = query.Where(o => o.PaymentMethodSystemName == paymentMethodSystemName); if (orderStatusId.HasValue) query = query.Where(o => o.OrderStatusId == orderStatusId.Value); if (paymentStatusId.HasValue) query = query.Where(o => o.PaymentStatusId == paymentStatusId.Value); if (shippingStatusId.HasValue) query = query.Where(o => o.ShippingStatusId == shippingStatusId.Value); if (startTimeUtc.HasValue) query = query.Where(o => startTimeUtc.Value <= o.CreatedOnUtc); if (endTimeUtc.HasValue) query = query.Where(o => endTimeUtc.Value >= o.CreatedOnUtc); if (!String.IsNullOrEmpty(billingEmail)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail)); if (!String.IsNullOrEmpty(billingLastName)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.LastName) && o.BillingAddress.LastName.Contains(billingLastName)); if (!String.IsNullOrEmpty(orderNotes)) query = query.Where(o => o.OrderNotes.Any(on => on.Note.Contains(orderNotes))); var grouping = (from oq in query group oq by 1 into result select result).AsEnumerable(); var item = (from result in grouping select new { OrderCount = result.Count(), OrderShippingExclTaxSum = result.Sum(o => o.OrderShippingExclTax), OrderTaxSum = result.Sum(o => o.OrderTax), OrderTotalSum = result.Sum(o => o.OrderTotal) } ).Select(r => new OrderAverageReportLine { SumTax = r.OrderTaxSum, CountOrders = r.OrderCount, SumShippingExclTax = r.OrderShippingExclTaxSum, SumOrders = r.OrderTotalSum }) .FirstOrDefault(); // var item = (from oq in query //group oq by 1 into result //select new // { // OrderCount = result.Count(), // OrderShippingExclTaxSum = result.Sum(o => o.OrderShippingExclTax), // OrderTaxSum = result.Sum(o => o.OrderTax), // OrderTotalSum = result.Sum(o => o.OrderTotal) // } // ).Select(r => new OrderAverageReportLine // { // CountOrders = r.OrderCount, // SumShippingExclTax = r.OrderShippingExclTaxSum, // SumTax = r.OrderTaxSum, // SumOrders = r.OrderTotalSum // }) // .FirstOrDefault(); item = item ?? new OrderAverageReportLine { CountOrders = 0, SumShippingExclTax = decimal.Zero, SumTax = decimal.Zero, SumOrders = decimal.Zero, }; return item; }
/// <summary> /// Get order average report /// </summary> /// <param name="os">Order status</param> /// <param name="ps">Payment status</param> /// <param name="ss">Shipping status</param> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</param> /// <param name="ignoreCancelledOrders">A value indicating whether to ignore cancelled orders</param> /// <returns>Result</returns> public virtual OrderAverageReportLine GetOrderAverageReportLine(OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, DateTime? startTimeUtc, DateTime? endTimeUtc, bool ignoreCancelledOrders = false) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; query = query.Where(o => !o.Deleted); if (ignoreCancelledOrders) { int cancelledOrderStatusId = (int)OrderStatus.Cancelled; query = query.Where(o => o.OrderStatusId != cancelledOrderStatusId); } if (orderStatusId.HasValue) query = query.Where(o => o.OrderStatusId == orderStatusId.Value); if (paymentStatusId.HasValue) query = query.Where(o => o.PaymentStatusId == paymentStatusId.Value); if (shippingStatusId.HasValue) query = query.Where(o => o.ShippingStatusId == shippingStatusId.Value); if (startTimeUtc.HasValue) query = query.Where(o => startTimeUtc.Value <= o.CreatedOnUtc); if (endTimeUtc.HasValue) query = query.Where(o => endTimeUtc.Value >= o.CreatedOnUtc); var item = new OrderAverageReportLine(); item.SumOrders = Convert.ToDecimal(query.Sum(o => (decimal?)o.OrderTotal)); item.CountOrders = query.Count(); return item; }
/// <summary> /// Get profit report /// </summary> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</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">Shipping status; null to load all records</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <returns>Result</returns> public virtual decimal ProfitReport(OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, DateTime? startTimeUtc, DateTime? endTimeUtc, string billingEmail) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; //We cannot use String.IsNullOrEmpty(billingEmail) in SQL Compact bool dontSearchEmail = String.IsNullOrEmpty(billingEmail); var query = from opv in _opvRepository.Table join o in _orderRepository.Table on opv.OrderId equals o.Id join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id join p in _productRepository.Table on pv.ProductId equals p.Id where (!startTimeUtc.HasValue || startTimeUtc.Value <= o.CreatedOnUtc) && (!endTimeUtc.HasValue || endTimeUtc.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && (!o.Deleted) && (!p.Deleted) && (!pv.Deleted) && (dontSearchEmail || (o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail))) select new { opv, pv }; var opvPrices = Convert.ToDecimal(query.Sum(o => (decimal?)o.opv.PriceExclTax)); var productCost = Convert.ToDecimal(query.Sum(o => (decimal?) o.pv.ProductCost * o.opv.Quantity)); var profit = opvPrices - productCost; return profit; }
/// <summary> /// Get profit report /// </summary> /// <param name="storeId">Store identifier; pass 0 to ignore this parameter</param> /// <param name="vendorId">Vendor identifier; pass 0 to ignore this parameter</param> /// <param name="orderId">Order identifier; pass 0 to ignore this parameter</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all orders</param> /// <param name="paymentMethodSystemName">Payment method system name; null to load all records</param> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</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">Shipping status; null to load all records</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="billingLastName">Billing last name. Leave empty to load all records.</param> /// <param name="orderNotes">Search in order notes. Leave empty to load all records.</param> /// <returns>Result</returns> public virtual decimal ProfitReport(int storeId = 0, int vendorId = 0, int billingCountryId = 0, int orderId = 0, string paymentMethodSystemName = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, DateTime? startTimeUtc = null, DateTime? endTimeUtc = null, string billingEmail = null, string billingLastName = "", string orderNotes = null) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; //We cannot use String.IsNullOrEmpty() in SQL Compact bool dontSearchEmail = String.IsNullOrEmpty(billingEmail); //We cannot use String.IsNullOrEmpty() in SQL Compact bool dontSearchLastName = String.IsNullOrEmpty(billingLastName); //We cannot use String.IsNullOrEmpty() in SQL Compact bool dontSearchOrderNotes = String.IsNullOrEmpty(orderNotes); //We cannot use String.IsNullOrEmpty() in SQL Compact bool dontSearchPaymentMethods = String.IsNullOrEmpty(paymentMethodSystemName); var query = from orderItem in _orderItemRepository.Table join o in _orderRepository.Table on orderItem.OrderId equals o.Id where (storeId == 0 || storeId == o.StoreId) && (orderId == 0 || orderId == o.Id) && (billingCountryId ==0 || (o.BillingAddress != null && o.BillingAddress.CountryId == billingCountryId)) && (dontSearchPaymentMethods || paymentMethodSystemName == o.PaymentMethodSystemName) && (!startTimeUtc.HasValue || startTimeUtc.Value <= o.CreatedOnUtc) && (!endTimeUtc.HasValue || endTimeUtc.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && (!o.Deleted) && (vendorId == 0 || orderItem.Product.VendorId == vendorId) && //we do not ignore deleted products when calculating order reports //(!p.Deleted) (dontSearchEmail || (o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail))) && (dontSearchLastName || (o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.LastName) && o.BillingAddress.LastName.Contains(billingLastName))) && (dontSearchOrderNotes || o.OrderNotes.Any(oNote => oNote.Note.Contains(orderNotes))) select orderItem; var productCost = Convert.ToDecimal(query.Sum(orderItem => (decimal?)orderItem.OriginalProductCost * orderItem.Quantity)); var reportSummary = GetOrderAverageReportLine( storeId: storeId, vendorId: vendorId, billingCountryId: billingCountryId, orderId: orderId, paymentMethodSystemName: paymentMethodSystemName, os: os, ps: ps, ss: ss, startTimeUtc: startTimeUtc, endTimeUtc: endTimeUtc, billingEmail: billingEmail, billingLastName: billingLastName, orderNotes: orderNotes); var profit = reportSummary.SumOrders - reportSummary.SumShippingExclTax - reportSummary.SumTax - productCost; return profit; }
public void WhenCalledWithSomeShippingStatus_GivenOrdersCollectionContainingOrdersHavingThisStatus_ShouldReturnTheCountOfTheOrdersHavingThisStatus(ShippingStatus shippingStatus) { // Arange var expectedCollectionCount = _existigOrders.Count(x => x.ShippingStatus == shippingStatus); // Act var resultCount = _orderApiService.GetOrdersCount(shippingStatus: shippingStatus); // Assert Assert.AreEqual(expectedCollectionCount, resultCount); }
public Shipment(int orderId) { OrderId = orderId; ShipmentStatus = ShippingStatus.Waiting; }
/// <summary> /// Get profit report /// </summary> /// <param name="storeId">Store identifier</param> /// <param name="vendorId">Vendor identifier</param> /// <param name="startTimeUtc">Start date</param> /// <param name="endTimeUtc">End date</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">Shipping status; null to load all records</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <returns>Result</returns> public virtual decimal ProfitReport(int storeId, int vendorId, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, DateTime? startTimeUtc, DateTime? endTimeUtc, string billingEmail) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; //We cannot use String.IsNullOrEmpty(billingEmail) in SQL Compact bool dontSearchEmail = String.IsNullOrEmpty(billingEmail); var query = from opv in _opvRepository.Table join o in _orderRepository.Table on opv.OrderId equals o.Id join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id join p in _productRepository.Table on pv.ProductId equals p.Id where (storeId == 0 || storeId == o.StoreId) && (!startTimeUtc.HasValue || startTimeUtc.Value <= o.CreatedOnUtc) && (!endTimeUtc.HasValue || endTimeUtc.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) && (!o.Deleted) && (vendorId == 0 || opv.ProductVariant.Product.VendorId == vendorId) && //we do not ignore deleted products when calculating order reports //(!p.Deleted) && //(!pv.Deleted) && (dontSearchEmail || (o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail))) select new { opv, pv }; var productCost = Convert.ToDecimal(query.Sum(o => (decimal?) o.pv.ProductCost * o.opv.Quantity)); var reportSummary = GetOrderAverageReportLine(storeId, vendorId, os, ps, ss, startTimeUtc, endTimeUtc, billingEmail); var profit = reportSummary.SumOrders - reportSummary.SumTax - productCost; return profit; }
public ShipmentDto(int shipmentId, int orderId, ShippingStatus status) { ShipmentId = shipmentId; OrderId = orderId; Status = status; }
/// <summary> /// Search orders /// </summary> /// <param name="storeId">Store identifier; 0 to load all orders</param> /// <param name="vendorId">Vendor identifier; null to load all orders</param> /// <param name="customerId">Customer identifier; 0 to load all orders</param> /// <param name="productId">Product identifier which was purchased in an order; 0 to load all orders</param> /// <param name="affiliateId">Affiliate identifier; 0 to load all orders</param> /// <param name="warehouseId">Warehouse identifier, only orders with products from a specified warehouse will be loaded; 0 to load all orders</param> /// <param name="createdFromUtc">Created date from (UTC); null to load all records</param> /// <param name="createdToUtc">Created date to (UTC); null to load all records</param> /// <param name="os">Order status; null to load all orders</param> /// <param name="ps">Order payment status; null to load all orders</param> /// <param name="ss">Order shipment status; null to load all orders</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="orderGuid">Search by order GUID (Global unique identifier) or part of GUID. Leave empty to load all orders.</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>Order collection</returns> public virtual IPagedList<Order> SearchOrders(int storeId = 0, int vendorId = 0, int customerId = 0, int productId = 0, int affiliateId = 0, int warehouseId = 0, DateTime? createdFromUtc = null, DateTime? createdToUtc = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, string billingEmail = null, string orderGuid = null, int pageIndex = 0, int pageSize = int.MaxValue) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; if (storeId > 0) query = query.Where(o => o.StoreId == storeId); if (vendorId > 0) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.VendorId == vendorId)); } if (customerId > 0) query = query.Where(o => o.CustomerId == customerId); if (productId > 0) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.Id == productId)); } if (warehouseId > 0) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.WarehouseId == warehouseId)); } if (affiliateId > 0) query = query.Where(o => o.AffiliateId == affiliateId); if (createdFromUtc.HasValue) query = query.Where(o => createdFromUtc.Value <= o.CreatedOnUtc); if (createdToUtc.HasValue) query = query.Where(o => createdToUtc.Value >= o.CreatedOnUtc); if (orderStatusId.HasValue) query = query.Where(o => orderStatusId.Value == o.OrderStatusId); if (paymentStatusId.HasValue) query = query.Where(o => paymentStatusId.Value == o.PaymentStatusId); if (shippingStatusId.HasValue) query = query.Where(o => shippingStatusId.Value == o.ShippingStatusId); if (!String.IsNullOrEmpty(billingEmail)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail)); query = query.Where(o => !o.Deleted); query = query.OrderByDescending(o => o.CreatedOnUtc); if (!String.IsNullOrEmpty(orderGuid)) { //filter by GUID. Filter in BLL because EF doesn't support casting of GUID to string var orders = query.ToList(); orders = orders.FindAll(o => o.OrderGuid.ToString().ToLowerInvariant().Contains(orderGuid.ToLowerInvariant())); return new PagedList<Order>(orders, pageIndex, pageSize); } else { //database layer paging return new PagedList<Order>(query, pageIndex, pageSize); } }
private void ChangeStatus_Click(object sender, RoutedEventArgs e) { StackPanel sp = new StackPanel(); ListPicker ShippingDrop = new ListPicker(); ListPicker PaymentDrop = new ListPicker(); PaymentDrop.SetValue(Microsoft.Phone.Controls.ListPicker.ItemCountThresholdProperty, 6); ListPicker OrderDrop = new ListPicker(); var OrderIndex = Array.IndexOf(OrderStatusValues, Order.OrderStatus.ToString()); var ShippingIndex = 0; switch (Order.ShippingStatus) { case ShippingStatus.NotYetShipped: ShippingIndex = 1; break; case ShippingStatus.PartiallyShipped: ShippingIndex = 2; break; case ShippingStatus.ShippingNotRequired: ShippingIndex = 4; break; default: ShippingIndex = Array.IndexOf(ShippingStatusValues, Order.ShippingStatus.ToString()); break; } var PaymentIndex = 0; switch (Order.PayStatus) { case PaymentStatus.PartiallyRefunded: PaymentIndex = 2; break; default: PaymentIndex = Array.IndexOf(PayStatusValues, Order.PayStatus.ToString()); break; } ShippingDrop.ItemsSource = ShippingStatusValues; PaymentDrop.ItemsSource = PayStatusValues; OrderDrop.ItemsSource = this.OrderStatusValues; ShippingDrop.SelectedIndex = ShippingIndex; OrderDrop.SelectedIndex = OrderIndex; PaymentDrop.SelectedIndex = PaymentIndex; ShippingDrop.SelectionChanged += (se, ev) => { ShippingIndex = ShippingDrop.SelectedIndex; }; OrderDrop.SelectionChanged += (se, ev) => { OrderIndex = OrderDrop.SelectedIndex; }; PaymentDrop.SelectionChanged += (se, ev) => { PaymentIndex = PaymentDrop.SelectedIndex; }; sp.Children.Add(ShippingDrop); sp.Children.Add(PaymentDrop); sp.Children.Add(OrderDrop); CustomMessageBox messageBox = new CustomMessageBox() { Caption = "Change Order Status", Message = "Change the status accordingly", Content = sp, LeftButtonContent = "Submit", RightButtonContent = "Cancel" }; messageBox.Dismissed += async(s1, e1) => { switch (e1.Result) { case CustomMessageBoxResult.LeftButton: await api.ChangeOrderStatus(Order.OrderID, OrderStatusValues[OrderIndex]); var PayS = new PaymentStatus[] { PaymentStatus.Paid, PaymentStatus.Authorized, PaymentStatus.PartiallyRefunded, PaymentStatus.Pending, PaymentStatus.Refunded, PaymentStatus.Voided }; await api.ChangePaymentStatus(Order.OrderID, PayS[PaymentIndex]); var ShipS = new ShippingStatus[] { ShippingStatus.Delivered, ShippingStatus.NotYetShipped, ShippingStatus.PartiallyShipped, ShippingStatus.Shipped, ShippingStatus.ShippingNotRequired }; await api.ChangeShippingStatus(Order.OrderID, ShipS[ShippingIndex]); MessageBox.Show("Status changed sucessfuly"); InitializeOrder(); break; } }; messageBox.Show(); }
/// <summary> /// Gets all Order items /// </summary> /// <param name="orderId">Order identifier; null to load all records</param> /// <param name="customerId">Customer identifier; null to load all records</param> /// <param name="startTime">Order start time; null to load all records</param> /// <param name="endTime">Order end time; 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 shippment status; null to load all records</param> /// <param name="loadDownloableProductsOnly">Value indicating whether to load downloadable products only</param> /// <returns>Order collection</returns> public virtual IList<OrderItem> GetAllOrderItems(int? orderId, int? customerId, DateTime? startTime, DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, bool loadDownloableProductsOnly) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = from orderItem in _orderItemRepository.Table join o in _orderRepository.Table on orderItem.OrderId equals o.Id join p in _productRepository.Table on orderItem.ProductId equals p.Id where (!orderId.HasValue || orderId.Value == 0 || orderId == o.Id) && (!customerId.HasValue || customerId.Value == 0 || customerId == o.CustomerId) && (!startTime.HasValue || startTime.Value <= o.CreatedOnUtc) && (!endTime.HasValue || endTime.Value >= o.CreatedOnUtc) && (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) && (!paymentStatusId.HasValue || paymentStatusId.Value == o.PaymentStatusId) && (!shippingStatusId.HasValue || shippingStatusId.Value == o.ShippingStatusId) && (!loadDownloableProductsOnly || p.IsDownload) && !o.Deleted orderby o.CreatedOnUtc descending, orderItem.Id select orderItem; var orderItems = query.ToList(); return orderItems; }
/// <summary> /// Search orders /// </summary> /// <param name="storeId">Store identifier; 0 to load all orders</param> /// <param name="vendorId">Vendor identifier; null to load all orders</param> /// <param name="customerId">Customer identifier; 0 to load all orders</param> /// <param name="productId">Product identifier which was purchased in an order; 0 to load all orders</param> /// <param name="affiliateId">Affiliate identifier; 0 to load all orders</param> /// <param name="billingCountryId">Billing country identifier; 0 to load all orders</param> /// <param name="warehouseId">Warehouse identifier, only orders with products from a specified warehouse will be loaded; 0 to load all orders</param> /// <param name="paymentMethodSystemName">Payment method system name; null to load all records</param> /// <param name="createdFromUtc">Created date from (UTC); null to load all records</param> /// <param name="createdToUtc">Created date to (UTC); null to load all records</param> /// <param name="os">Order status; null to load all orders</param> /// <param name="ps">Order payment status; null to load all orders</param> /// <param name="ss">Order shipment status; null to load all orders</param> /// <param name="billingEmail">Billing email. Leave empty to load all records.</param> /// <param name="billingLastName">Billing last name. Leave empty to load all records.</param> /// <param name="orderNotes">Search in order notes. Leave empty to load all records.</param> /// <param name="orderGuid">Search by order GUID (Global unique identifier) or part of GUID. Leave empty to load all orders.</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>Orders</returns> public virtual IPagedList<Order> SearchOrders(int storeId = 0, int vendorId = 0, int customerId = 0, int productId = 0, int affiliateId = 0, int warehouseId = 0, int billingCountryId = 0, string paymentMethodSystemName = null, DateTime? createdFromUtc = null, DateTime? createdToUtc = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, string billingEmail = null, string billingLastName = "", string orderNotes = null, string orderGuid = null, int pageIndex = 0, int pageSize = int.MaxValue) { int? orderStatusId = null; if (os.HasValue) orderStatusId = (int)os.Value; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; int? shippingStatusId = null; if (ss.HasValue) shippingStatusId = (int)ss.Value; var query = _orderRepository.Table; if (storeId > 0) query = query.Where(o => o.StoreId == storeId); if (vendorId > 0) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.VendorId == vendorId)); } if (customerId > 0) query = query.Where(o => o.CustomerId == customerId); if (productId > 0) { query = query .Where(o => o.OrderItems .Any(orderItem => orderItem.Product.Id == productId)); } if (warehouseId > 0) { var manageStockInventoryMethodId = (int)ManageInventoryMethod.ManageStock; query = query .Where(o => o.OrderItems .Any(orderItem => //"Use multiple warehouses" enabled //we search in each warehouse (orderItem.Product.ManageInventoryMethodId == manageStockInventoryMethodId && orderItem.Product.UseMultipleWarehouses && orderItem.Product.ProductWarehouseInventory.Any(pwi => pwi.WarehouseId == warehouseId)) || //"Use multiple warehouses" disabled //we use standard "warehouse" property ((orderItem.Product.ManageInventoryMethodId != manageStockInventoryMethodId || !orderItem.Product.UseMultipleWarehouses) && orderItem.Product.WarehouseId == warehouseId)) ); } if (billingCountryId > 0) query = query.Where(o => o.BillingAddress != null && o.BillingAddress.CountryId == billingCountryId); if (!String.IsNullOrEmpty(paymentMethodSystemName)) query = query.Where(o => o.PaymentMethodSystemName == paymentMethodSystemName); if (affiliateId > 0) query = query.Where(o => o.AffiliateId == affiliateId); if (createdFromUtc.HasValue) query = query.Where(o => createdFromUtc.Value <= o.CreatedOnUtc); if (createdToUtc.HasValue) query = query.Where(o => createdToUtc.Value >= o.CreatedOnUtc); if (orderStatusId.HasValue) query = query.Where(o => orderStatusId.Value == o.OrderStatusId); if (paymentStatusId.HasValue) query = query.Where(o => paymentStatusId.Value == o.PaymentStatusId); if (shippingStatusId.HasValue) query = query.Where(o => shippingStatusId.Value == o.ShippingStatusId); if (!String.IsNullOrEmpty(billingEmail)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.Email) && o.BillingAddress.Email.Contains(billingEmail)); if (!String.IsNullOrEmpty(billingLastName)) query = query.Where(o => o.BillingAddress != null && !String.IsNullOrEmpty(o.BillingAddress.LastName) && o.BillingAddress.LastName.Contains(billingLastName)); if (!String.IsNullOrEmpty(orderNotes)) query = query.Where(o => o.OrderNotes.Any(on => on.Note.Contains(orderNotes))); query = query.Where(o => !o.Deleted); query = query.OrderByDescending(o => o.CreatedOnUtc); if (!String.IsNullOrEmpty(orderGuid)) { //filter by GUID. Filter in BLL because EF doesn't support casting of GUID to string var orders = query.ToList(); orders = orders.FindAll(o => o.OrderGuid.ToString().ToLowerInvariant().Contains(orderGuid.ToLowerInvariant())); return new PagedList<Order>(orders, pageIndex, pageSize); } //database layer paging return new PagedList<Order>(query, pageIndex, pageSize); }