Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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
                          join a in _addressRepository.Table on oq.BillingAddressId equals a.Id
                          group oq by a.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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get best sellers report
        /// </summary>
        /// <param name="storeId">Store identifier</param>
        /// <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="billingCountryId">Billing country identifier; 0 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(int storeId,
                                                                       DateTime?startTime, DateTime?endTime,
                                                                       OrderStatus?os, PaymentStatus?ps, ShippingStatus?ss,
                                                                       int billingCountryId = 0,
                                                                       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 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 (storeId == 0 || storeId == o.StoreId) &&
                         (!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) && (!p.IsSystemProduct) &&
                         (billingCountryId == 0 || o.BillingAddress.CountryId == billingCountryId) &&
                         (showHidden || p.Published)
                         select orderItem;

            var query2 =
                //group by products
                from orderItem in query1
                group orderItem by orderItem.ProductId into g
                select new
            {
                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");
            }

            if (recordsToReturn != 0 && recordsToReturn != int.MaxValue)
            {
                query2 = query2.Take(() => recordsToReturn);
            }

            var result = query2.ToList().Select(x =>
            {
                var reportLine = new BestsellersReportLine()
                {
                    ProductId     = x.EntityId,
                    TotalAmount   = x.TotalAmount,
                    TotalQuantity = x.TotalQuantity
                };
                return(reportLine);
            }).ToList();

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Search recurring payments
        /// </summary>
        /// <param name="storeId">The store identifier; 0 to load all records</param>
        /// <param name="customerId">The customer identifier; 0 to load all records</param>
        /// <param name="initialOrderId">The initial order identifier; 0 to load all records</param>
        /// <param name="initialOrderStatus">Initial order status identifier; null to load all records</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Recurring payment collection</returns>
        public virtual IList <RecurringPayment> SearchRecurringPayments(int storeId,
                                                                        int customerId, int initialOrderId, OrderStatus?initialOrderStatus,
                                                                        bool showHidden = false)
        {
            int?initialOrderStatusId = null;

            if (initialOrderStatus.HasValue)
            {
                initialOrderStatusId = (int)initialOrderStatus.Value;
            }

            var query1 = from rp in _recurringPaymentRepository.Table
                         join c in _customerRepository.Table on rp.InitialOrder.CustomerId equals c.Id
                         where
                         (!rp.Deleted) &&
                         (showHidden || !rp.InitialOrder.Deleted) &&
                         (showHidden || !c.Deleted) &&
                         (showHidden || rp.IsActive) &&
                         (customerId == 0 || rp.InitialOrder.CustomerId == customerId) &&
                         (storeId == 0 || rp.InitialOrder.StoreId == storeId) &&
                         (initialOrderId == 0 || rp.InitialOrder.Id == initialOrderId) &&
                         (!initialOrderStatusId.HasValue || initialOrderStatusId.Value == 0 || rp.InitialOrder.OrderStatusId == initialOrderStatusId.Value)
                         select rp.Id;

            var query2 = from rp in _recurringPaymentRepository.Table
                         where query1.Contains(rp.Id)
                         orderby rp.StartDateUtc, rp.Id
            select rp;

            var recurringPayments = query2.ToList();

            return(recurringPayments);
        }
Ejemplo n.º 5
0
        /// <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(string orderId,
                                                          string 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 (!String.IsNullOrEmpty(orderId))
            {
                filter = filter & builder.Where(o => o.Id == orderId);
            }

            if (!String.IsNullOrEmpty(customerId))
            {
                filter = filter & builder.Where(o => o.CustomerId == customerId);
            }

            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 (createdToUtc.HasValue)
            {
                filter = filter & builder.Where(o => o.CreatedOnUtc <= createdToUtc.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 == null)
                    {
                        product = _productDeletedRepository.GetById(item.OrderItems.ProductId) as Product;
                    }
                    if (product != null)
                    {
                        if (product.IsDownload)
                        {
                            items.Add(item.OrderItems);
                        }
                    }
                }
                else
                {
                    items.Add(item.OrderItems);
                }
            }
            return(items);
        }
Ejemplo n.º 6
0
        /// <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 async Task <IList <OrderByCountryReportLine> > GetCountryReport(string 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 (!String.IsNullOrEmpty(storeId))
            {
                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
            });

            return(await report.ToListAsync());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get best customers
        /// </summary>
        /// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param>
        /// <param name="createdToUtc">Order created date to (UTC); null to load all records</param>
        /// <param name="os">Order status; null to load all records</param>
        /// <param name="ps">Order payment status; null to load all records</param>
        /// <param name="ss">Order shipment status; null to load all records</param>
        /// <param name="orderBy">1 - order by order total, 2 - order by number of orders</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <returns>Report</returns>
        public 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));
        }
Ejemplo n.º 8
0
 public int ScalarFunctionWithParameters(int?id, String name, OrderStatus?status) => Orders.Where(o => o.Id == id || o.Name.Contains(name) || o.Status == status).Count();
Ejemplo n.º 9
0
        public virtual IPagedList <Invoice> SearchInvoices(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 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 = _invoiceRepository.Table;

            if (storeId > 0)
            {
                query = query.Where(inv => inv.StoreId == storeId);
            }
            if (vendorId > 0)
            {
                query = query.Where(inv => inv.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(inv => inv.PaymentMethodSystemName == paymentMethodSystemName);
            }
            //if (affiliateId > 0)
            //    query = query.Where(o => o.AffiliateId == affiliateId);
            if (createdFromUtc.HasValue)
            {
                query = query.Where(inv => createdFromUtc.Value <= inv.CreatedOnUtc);
            }
            if (createdToUtc.HasValue)
            {
                query = query.Where(inv => createdToUtc.Value >= inv.CreatedOnUtc);
            }
            //if (orderStatusId.HasValue)
            //    query = query.Where(o => orderStatusId.Value == o.OrderStatusId);
            if (paymentStatusId.HasValue)
            {
                query = query.Where(inv => paymentStatusId.Value == inv.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(orderNotes))
            //    query = query.Where(o => o.OrderNotes.Any(on => on.Note.Contains(orderNotes)));
            //query = query.Where(o => !o.Deleted);
            query = query.OrderByDescending(inv => inv.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 <Invoice>(query, pageIndex, pageSize));
        }
Ejemplo n.º 10
0
 public IEnumerable <Order> TableFunctionWithParameters(int?id, String name, OrderStatus?status) => Orders.Where(o => (o.Id == id) || o.Name.Contains(name) || (o.Status == status));
Ejemplo n.º 11
0
 public IEnumerable <Order> GetOrders(int?id, String name, OrderStatus?status) => throw new NotImplementedException();
Ejemplo n.º 12
0
        public async Task <IActionResult> BestsellersReportList(DataSourceRequest command, BestsellersReportModel model)
        {
            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && !_workContext.CurrentCustomer.IsStaff())
            {
                model.VendorId = _workContext.CurrentVendor.Id;
            }

            if (_workContext.CurrentCustomer.IsStaff())
            {
                model.StoreId = _workContext.CurrentCustomer.StaffStoreId;
            }

            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 = await _orderReportService.BestSellersReport(
                createdFromUtc : startDateValue,
                createdToUtc : endDateValue,
                os : orderStatus,
                ps : paymentStatus,
                billingCountryId : model.BillingCountryId,
                orderBy : 2,
                vendorId : model.VendorId,
                pageIndex : command.Page - 1,
                pageSize : command.PageSize,
                showHidden : true,
                storeId : model.StoreId);

            var result = new List <BestsellersReportLineModel>();

            foreach (var x in items)
            {
                var m = new BestsellersReportLineModel
                {
                    ProductId     = x.ProductId,
                    TotalAmount   = _priceFormatter.FormatPrice(x.TotalAmount, true, false),
                    TotalQuantity = x.TotalQuantity,
                };
                var product = await _productService.GetProductById(x.ProductId);

                if (product != null)
                {
                    m.ProductName = product.Name;
                }
                if (_workContext.CurrentVendor != null)
                {
                    if (product.VendorId == _workContext.CurrentVendor.Id)
                    {
                        result.Add(m);
                    }
                }
                else
                {
                    result.Add(m);
                }
            }
            var gridModel = new DataSourceResult
            {
                Data  = result,
                Total = items.TotalCount
            };

            return(Json(gridModel));
        }
        public void EditOrder(int orderId, int ffProductId, int ispProductId, OrderStatus?status, string userId, ContractTerm clientContractTerm, List <FFProdEditDto> products)
        {
            var order = GetOrder(orderId);

            order.ISPProductId       = ispProductId;
            order.ClientContractTerm = clientContractTerm;

            var action = UserAction.Edit;

            if (status != null)
            {
                order.Status = (OrderStatus)status;
                order.StatusList.Add(new Status {
                    OrderStatus = (OrderStatus)status, TimeStamp = DateTime.Now
                });
            }

            //create defuaul line speed prod
            products.Add(new FFProdEditDto
            {
                action = true,
                id     = ffProductId,
                qty    = 1
            });

            //FFProdEditDto
            //true = add/update
            //false = delete
            //null = no change/do nothing
            foreach (var prod in products)
            {
                //add or update
                if (prod.action == true)
                {
                    //if prod exists then update it
                    if (order.OrderFFProducts.Any(p => p.FFProductId == prod.id))
                    {
                        var prodToUpdate = order.OrderFFProducts.First(p => p.FFProductId == prod.id);
                        prodToUpdate.Quantity = prod.qty;
                    }
                    else //if not exists then add it
                    {
                        order.OrderFFProducts.Add(new OrderFFProduct
                        {
                            OrderId     = order.OrderId,
                            FFProductId = prod.id,
                            Quantity    = prod.qty
                        });
                    }
                }
                db.SaveChanges();

                //remove
                if (prod.action == false)
                {
                    var orderFFProdToDelete = order.OrderFFProducts.FirstOrDefault(p => p.FFProductId == prod.id);
                    if (orderFFProdToDelete != null)
                    {
                        db.OrderFFProducts.Remove(orderFFProdToDelete);
                    }
                    db.SaveChanges();
                }
            }

            order.Logs.Add(new Log {
                UserId = userId, Type = action, OrderStatus = order.Status, TimeStamp = DateTime.Now
            });
            SaveChanges(db);

            EmailSender.SendRTNewOrderNotification(orderId);
        }
Ejemplo n.º 14
0
        /// <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));
            }


            //This was the original, had to break out into 2 steps to work with MySql
            //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();

            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(), 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);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Get order average report
        /// </summary>
        /// <param name="storeId">Store identifier; pass 0 to ignore this parameter</param>
        /// <param name="customerId">Customer 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="tagid">Tag ident.</param>
        /// <returns>Result</returns>
        public virtual async Task <OrderAverageReportLine> GetOrderAverageReportLine(string storeId        = "", string customerId              = "",
                                                                                     string vendorId       = "", string billingCountryId        = "",
                                                                                     string orderId        = "", 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 tagid          = 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 builder = Builders <Order> .Filter;

            var filter = builder.Where(o => !o.Deleted);

            if (!String.IsNullOrEmpty(storeId))
            {
                filter = filter & builder.Where(o => o.StoreId == storeId);
            }

            if (!String.IsNullOrEmpty(orderId))
            {
                filter = filter & builder.Where(o => o.StoreId == storeId);
            }

            if (!string.IsNullOrEmpty(customerId))
            {
                filter = filter & builder.Where(o => o.CustomerId == customerId);
            }

            if (!String.IsNullOrEmpty(vendorId))
            {
                filter = filter & builder
                         .Where(o => o.OrderItems
                                .Any(orderItem => orderItem.VendorId == vendorId));
            }
            if (!String.IsNullOrEmpty(billingCountryId))
            {
                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 => endTimeUtc.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));
            }

            //tag filtering
            if (!string.IsNullOrEmpty(tagid))
            {
                filter = filter & builder.Where(o => o.OrderTags.Any(y => y == tagid));
            }

            var query = await _orderRepository.Collection
                        .Aggregate()
                        .Match(filter)
                        .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();


            var item2 = query.Count() > 0 ? query.FirstOrDefault() : new OrderAverageReportLine
            {
                CountOrders        = 0,
                SumShippingExclTax = decimal.Zero,
                SumTax             = decimal.Zero,
                SumOrders          = decimal.Zero,
            };

            return(item2);
        }
Ejemplo n.º 16
0
 public List <OrderDto> GetOrdersForCustomer(int customerId, [FromQuery] OrderStatus?status = null)
 {
     return(status == null?_orderRepository.GetOrdersForCustomer(customerId)
                : _orderRepository.GetOrdersForCustomer(customerId, (OrderStatus)status));
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Get best sellers report
        /// </summary>
        /// <param name="storeId">Store identifier; "" to load all records</param>
        /// <param name="vendorId">Vendor identifier; "" to load all records</param>
        /// <param name="categoryId">Category identifier; "" to load all records</param>
        /// <param name="manufacturerId">Manufacturer identifier; "" 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; "" 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 async Task <IPagedList <BestsellersReportLine> > BestSellersReport(
            string storeId          = "", string vendorId = "",
            DateTime?createdFromUtc = null, DateTime?createdToUtc = null,
            OrderStatus?os          = null, PaymentStatus?ps = null, ShippingStatus?ss = null,
            string billingCountryId = "",
            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 builderItem = Builders <UnwindedOrderItem> .Filter;

            var filter     = builder.Where(o => !o.Deleted);
            var filterItem = builderItem.Where(x => true);

            if (!String.IsNullOrEmpty(vendorId))
            {
                filterItem = filterItem & builderItem.Where(x => x.OrderItems.VendorId == vendorId);
            }

            if (!String.IsNullOrEmpty(storeId))
            {
                filter = filter & builder.Where(o => o.StoreId == storeId);
            }

            if (!String.IsNullOrEmpty(vendorId))
            {
                filter = filter & builder
                         .Where(o => o.OrderItems
                                .Any(orderItem => orderItem.VendorId == vendorId));
            }
            if (!String.IsNullOrEmpty(billingCountryId))
            {
                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);
            }

            FilterDefinition <BsonDocument> filterPublishedProduct = new BsonDocument("Product.Published", true);
            var groupBy = new BsonDocument
            {
                new BsonElement("_id", "$OrderItems.ProductId"),
                new BsonElement("TotalAmount", new BsonDocument("$sum", "$OrderItems.PriceExclTax")),
                new BsonElement("TotalQuantity", new BsonDocument("$sum", "$OrderItems.Quantity"))
            };

            var query = _orderRepository.Collection
                        .Aggregate()
                        .Match(filter)
                        .Unwind <Order, UnwindedOrderItem>(x => x.OrderItems)
                        .Match(filterItem)
                        .Lookup("Product", "OrderItems.ProductId", "_id", "Product")
                        .Match(filterPublishedProduct)
                        .Group(groupBy);

            if (orderBy == 1)
            {
                query = query.SortByDescending(x => x["TotalQuantity"]);
            }
            else
            {
                query = query.SortByDescending(x => x["TotalAmount"]);
            }

            var query2 = new List <BestsellersReportLine>();
            await query.ForEachAsync(q =>
            {
                var line           = new BestsellersReportLine();
                line.ProductId     = q["_id"].ToString();
                line.TotalAmount   = q["TotalAmount"].AsDecimal;
                line.TotalQuantity = q["TotalQuantity"].AsInt32;
                query2.Add(line);
            });

            var result = new PagedList <BestsellersReportLine>(query2, pageIndex, pageSize);

            return(result);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Get best customers
        /// </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">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?startTime,
                                                                             DateTime?endTime, 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 (!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) &&
                         (!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);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Get profit report
        /// </summary>
        /// <param name="storeId">Store identifier; pass 0 to ignore this parameter</param>
        /// <param name="CustomerId">Customer 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="tagid">Tag ident.</param>
        /// <returns>Result</returns>
        public virtual async Task <decimal> ProfitReport(string storeId          = "", string customerId        = "", string vendorId = "",
                                                         string billingCountryId = "", string orderId           = "", string paymentMethodSystemName = null,
                                                         OrderStatus?os          = null, PaymentStatus?ps       = null, ShippingStatus?ss = null,
                                                         DateTime?startTimeUtc   = null, DateTime?endTimeUtc    = null,
                                                         string billingEmail     = null, string billingLastName = "", string tagid = 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 (!String.IsNullOrEmpty(storeId))
            {
                query = query.Where(o => o.StoreId == storeId);
            }

            if (!String.IsNullOrEmpty(customerId))
            {
                query = query.Where(o => o.CustomerId == customerId);
            }

            if (!String.IsNullOrEmpty(orderId))
            {
                query = query.Where(o => o.Id == orderId);
            }

            if (!String.IsNullOrEmpty(vendorId))
            {
                query = query
                        .Where(o => o.OrderItems
                               .Any(orderItem => orderItem.VendorId == vendorId));
            }

            if (!String.IsNullOrEmpty(billingCountryId))
            {
                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));
            }

            //tag filtering
            if (!string.IsNullOrEmpty(tagid))
            {
                query = query.Where(o => o.OrderTags.Any(y => y == tagid));
            }

            var query2 = from o in query
                         from p in o.OrderItems
                         select p;


            var productCost = await query2.SumAsync(orderItem => orderItem.OriginalProductCost *orderItem.Quantity);

            var reportSummary = await GetOrderAverageReportLine(
                storeId : storeId,
                vendorId : vendorId,
                customerId : customerId,
                billingCountryId : billingCountryId,
                orderId : orderId,
                paymentMethodSystemName : paymentMethodSystemName,
                os : os,
                ps : ps,
                ss : ss,
                startTimeUtc : startTimeUtc,
                endTimeUtc : endTimeUtc,
                billingEmail : billingEmail,
                tagid : tagid
                );

            var profit = Convert.ToDecimal(reportSummary.SumOrders - reportSummary.SumShippingExclTax - reportSummary.SumTax - productCost);

            return(profit);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Search recurring payments
        /// </summary>
        /// <param name="storeId">The store identifier; 0 to load all records</param>
        /// <param name="customerId">The customer identifier; 0 to load all records</param>
        /// <param name="initialOrderId">The initial order identifier; 0 to load all records</param>
        /// <param name="initialOrderStatus">Initial order status identifier; null to load all records</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>Recurring payments</returns>
        public virtual IPagedList <RecurringPayment> SearchRecurringPayments(int storeId    = 0,
                                                                             int customerId = 0, int initialOrderId = 0, OrderStatus?initialOrderStatus = null,
                                                                             int pageIndex  = 0, int pageSize       = int.MaxValue, bool showHidden     = false)
        {
            #region Extensions by QuanNH
            var _storeMappingService = Nop.Core.Infrastructure.EngineContext.Current.Resolve <Nop.Services.Stores.IStoreMappingService>();
            storeId = _storeMappingService.CurrentStore();

            #endregion

            int?initialOrderStatusId = null;
            if (initialOrderStatus.HasValue)
            {
                initialOrderStatusId = (int)initialOrderStatus.Value;
            }

            var query1 = from rp in _recurringPaymentRepository.Table
                         join c in _customerRepository.Table on rp.InitialOrder.CustomerId equals c.Id
                         where
                         (!rp.Deleted) &&
                         (showHidden || !rp.InitialOrder.Deleted) &&
                         (showHidden || !c.Deleted) &&
                         (showHidden || rp.IsActive) &&
                         (customerId == 0 || rp.InitialOrder.CustomerId == customerId) &&
                         (storeId == 0 || rp.InitialOrder.StoreId == storeId) &&
                         (initialOrderId == 0 || rp.InitialOrder.Id == initialOrderId) &&
                         (!initialOrderStatusId.HasValue || initialOrderStatusId.Value == 0 || rp.InitialOrder.OrderStatusId == initialOrderStatusId.Value)
                         select rp.Id;

            var query2 = from rp in _recurringPaymentRepository.Table
                         where query1.Contains(rp.Id)
                         orderby rp.StartDateUtc, rp.Id
            select rp;

            var recurringPayments = new PagedList <RecurringPayment>(query2, pageIndex, pageSize);
            return(recurringPayments);
        }
Ejemplo n.º 21
0
        public async Task <OrderIndexSpecification> GetSpecificationAccordingToAuthorizationAsync(int page, int pageSize, int?storeId, OrderStatus?orderStatus)
        {
            string ownerId = null;

            if (!storeId.HasValue)
            {
                ownerId = _scopedParameters.CurrentUserId;
            }
            else
            {
                if (!(await _identityService.IsStoreAdministratorAsync(_scopedParameters.CurrentUserId, storeId.Value) ||
                      await _identityService.IsContentAdministratorAsync(_scopedParameters.CurrentUserId)))
                {
                    throw new AuthorizationException("Current user has no authorization to read orders from this store");
                }
            }
            return(new OrderIndexSpecification(page, pageSize, storeId, orderStatus, ownerId));
        }
Ejemplo n.º 22
0
 public CallResult <LiquidQuoineDefaultResponse <LiquidQuoinePlacedOrder> > GetOrders(string fundingCurrency = null, int?productId = null, OrderStatus?status = null, bool withDetails = false, int limit = 1000, int page = 1) => GetOrdersAsync(fundingCurrency, productId, status, withDetails, limit, page).Result;
Ejemplo n.º 23
0
        /// <summary>
        /// Get best customers
        /// </summary>
        /// <param name="storeId">Store ident</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="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(string storeId, 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 query = _orderRepository.Table;

            query = query.Where(o => !o.Deleted);
            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 (createdFromUtc.HasValue)
            {
                query = query.Where(o => createdFromUtc.Value <= o.CreatedOnUtc);
            }
            if (createdToUtc.HasValue)
            {
                query = query.Where(o => createdToUtc.Value >= o.CreatedOnUtc);
            }
            if (!string.IsNullOrEmpty(storeId))
            {
                query = query.Where(o => o.StoreId == storeId);
            }

            var query2 = from co in query
                         group co by co.CustomerId into g
                         select new
            {
                CustomerId = g.Key,
                OrderTotal = g.Sum(x => x.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));
        }
Ejemplo n.º 24
0
        public async Task <CallResult <LiquidQuoineDefaultResponse <LiquidQuoinePlacedOrder> > > GetOrdersAsync(string fundingCurrency = null,
                                                                                                                int?productId          = null, OrderStatus?status = null, bool withDetails = false, int limit = 1000, int page = 1, CancellationToken ct = default)
        {
            var parameters = new Dictionary <string, object>();

            parameters.AddOptionalParameter("funding_currency", fundingCurrency);
            parameters.AddOptionalParameter("product_id", productId);
            parameters.AddOptionalParameter("limit", limit);
            parameters.AddOptionalParameter("page", page);


            if (status != null)
            {
                parameters.AddOptionalParameter("status", JsonConvert.SerializeObject(status, new OrderStatusConverter()));
            }
            if (withDetails)
            {
                parameters.AddParameter("with_details", 1);
            }
            var result = await SendRequest <LiquidQuoineDefaultResponse <LiquidQuoinePlacedOrder> >(GetUrl(GetOrdersEndpoint), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

            return(new CallResult <LiquidQuoineDefaultResponse <LiquidQuoinePlacedOrder> >(result.Data, result.Error));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Search recurring payments
        /// </summary>
        /// <param name="storeId">The store identifier; 0 to load all records</param>
        /// <param name="customerId">The customer identifier; 0 to load all records</param>
        /// <param name="initialOrderId">The initial order identifier; 0 to load all records</param>
        /// <param name="initialOrderStatus">Initial order status identifier; null to load all records</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>Recurring payments</returns>
        public virtual IPagedList <RecurringPayment> SearchRecurringPayments(string storeId    = "",
                                                                             string customerId = "", string initialOrderId = "", OrderStatus?initialOrderStatus = null,
                                                                             int pageIndex     = 0, int pageSize = int.MaxValue, bool showHidden = false)
        {
            int?initialOrderStatusId = null;

            if (initialOrderStatus.HasValue)
            {
                initialOrderStatusId = (int)initialOrderStatus.Value;
            }
            //TO DO
            var query1 = from rp in _recurringPaymentRepository.Table
                         where
                         (!rp.Deleted) &&
                         (showHidden || rp.IsActive) &&
                         (customerId == "" || rp.InitialOrder.CustomerId == customerId) &&
                         (storeId == "" || rp.InitialOrder.StoreId == storeId) &&
                         (initialOrderId == "" || rp.InitialOrder.Id == initialOrderId)
                         select rp.Id;
            var cc     = query1.ToList();
            var query2 = from rp in _recurringPaymentRepository.Table
                         where cc.Contains(rp.Id)
                         orderby rp.StartDateUtc
                         select rp;

            var recurringPayments = new PagedList <RecurringPayment>(query2, pageIndex, pageSize);

            return(recurringPayments);
        }
Ejemplo n.º 26
0
        // GET: Orders
        //[HttpGet("Orders")]
        //public async Task<IActionResult> Index()
        //{
        //    var i1Delivery_KursovaContext = _context.Order
        //        .Include(o => o.Customer)
        //        .Include(o => o.OrderLine)
        //        .ThenInclude(o => o.RestaurantDishRelation)
        //        .OrderBy(o=>o.CreatedDateTime);
        //    //.ToList();

        //    i1Delivery_KursovaContext.ToList().ForEach(o => o.TotalAmt = o.OrderLine.Sum(o => o.Quantity * (o.RestaurantDishRelation?.Price ?? 0)));
        //    return View(await i1Delivery_KursovaContext.ToListAsync());
        //}

        public async Task <IActionResult> Index(string DescrSearch, string PhoneSearch, OrderStatus?orderStatus)
        {
            var i1Delivery_KursovaContext = _context.Order
                                            .Include(o => o.Customer)
                                            .Include(o => o.OrderLine)

                                            .ThenInclude(o => o.RestaurantDishRelation)
                                            .Where(o => string.IsNullOrEmpty(DescrSearch) == false? (string.IsNullOrEmpty(DescrSearch) == false ? o.Description.Contains(DescrSearch) : true): true)
                                            .Where(o => string.IsNullOrEmpty(PhoneSearch) == false? o.Customer.Phone.Contains(PhoneSearch) : true)
                                            .Where(o => orderStatus != null && o.Status != null? o.Status == orderStatus : true)
                                            .OrderByDescending(o => o.CreatedDateTime)
                                            .ToList();

            var selectList = Enum.GetValues(typeof(OrderStatus))
                             .Cast <OrderStatus>()
                             .Select(c => new
            {
                orderStatus      = c,
                orderStatusDescr = c.GetDescription()
            });

            ViewData["orderStatuses"] = new SelectList(selectList, "orderStatus", "orderStatusDescr", orderStatus);

            i1Delivery_KursovaContext.ToList().ForEach(o => o.TotalAmt = o.OrderLine.Sum(o => o.Quantity * (o.RestaurantDishRelation?.Price ?? 0)));
            return(View(i1Delivery_KursovaContext));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Search order items
        /// </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="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Result query</returns>
        private IQueryable <OrderItem> SearchOrderItems(
            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 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 bestSellers = 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 oba in _addressRepository.Table on o.BillingAddressId equals oba.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) &&
                              (billingCountryId == 0 || oba.CountryId == billingCountryId) &&
                              (showHidden || p.Published)
                              select orderItem;

            if (categoryId > 0)
            {
                bestSellers = from orderItem in bestSellers
                              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()
                              where pc.CategoryId == categoryId
                              select orderItem;
            }

            if (manufacturerId > 0)
            {
                bestSellers = from orderItem in bestSellers
                              join p in _productRepository.Table on orderItem.ProductId equals p.Id
                              join pm in _productManufacturerRepository.Table on p.Id equals pm.ProductId
                              into p_pm
                              from pm in p_pm.DefaultIfEmpty()
                              where pm.ManufacturerId == manufacturerId
                              select orderItem;
            }

            return(bestSellers);
        }
Ejemplo n.º 28
0
        /// <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);
        }
Ejemplo n.º 29
0
        /// <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="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 async Task <IPagedList <Order> > SearchOrders(string storeId          = "",
                                                                     string vendorId         = "", string customerId  = "",
                                                                     string productId        = "", string affiliateId = "", string warehouseId = "",
                                                                     string billingCountryId = "", string paymentMethodSystemName = null,
                                                                     DateTime?createdFromUtc = null, DateTime?createdToUtc        = null,
                                                                     OrderStatus?os          = null, PaymentStatus?ps       = null, ShippingStatus?ss = null,
                                                                     string billingEmail     = null, string billingLastName = "", 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 (!String.IsNullOrEmpty(storeId))
            {
                query = query.Where(o => o.StoreId == storeId);
            }
            if (!String.IsNullOrEmpty(vendorId))
            {
                query = query
                        .Where(o => o.OrderItems
                               .Any(orderItem => orderItem.VendorId == vendorId));
            }
            if (!String.IsNullOrEmpty(customerId))
            {
                query = query.Where(o => o.CustomerId == customerId);
            }
            if (!String.IsNullOrEmpty(productId))
            {
                query = query
                        .Where(o => o.OrderItems
                               .Any(orderItem => orderItem.ProductId == productId));
            }
            if (!String.IsNullOrEmpty(warehouseId))
            {
                query = query
                        .Where(o => o.OrderItems
                               .Any(orderItem =>
                                    orderItem.WarehouseId == warehouseId
                                    ));
            }
            if (!String.IsNullOrEmpty(billingCountryId))
            {
                query = query.Where(o => o.BillingAddress != null && o.BillingAddress.CountryId == billingCountryId);
            }
            if (!String.IsNullOrEmpty(paymentMethodSystemName))
            {
                query = query.Where(o => o.PaymentMethodSystemName == paymentMethodSystemName);
            }
            if (!String.IsNullOrEmpty(affiliateId))
            {
                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));
            }

            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 = await query.ToListAsync();

                orders = orders.FindAll(o => o.OrderGuid.ToString().ToLowerInvariant().Contains(orderGuid.ToLowerInvariant()));
                return(new PagedList <Order>(orders, pageIndex, pageSize));
            }

            //database layer paging
            return(await PagedList <Order> .Create(query, pageIndex, pageSize));
        }
Ejemplo n.º 30
0
 public virtual PartialViewResult GetOrderListMobile(OrderStatus?orderStatus = OrderStatus.WaitForPricing) => PartialView(MVC.OrderOffice.Views.Partials._OrderListViewMobile, _orderBusiness.GetAllOrder(officeUserId: (User as ICurrentUserPrincipal).UserId, orderStatus: orderStatus));