Ejemplo n.º 1
0
        /// <summary>
        /// Gets an order report
        /// </summary>
        /// <param name="os">Order status; null to load all orders</param>
        /// <param name="ps">Order payment status; null to load all orders</param>
        /// <param name="ss">Order shippment status; null to load all orders</param>
        /// <returns>IdataReader</returns>
        public OrderIncompleteReportLine GetOrderReport(OrderStatusEnum? os,
            PaymentStatusEnum? ps, ShippingStatusEnum? ss)
        {
            int? orderStatusId = null;
            if (os.HasValue)
                orderStatusId = (int)os.Value;

            int? paymentStatusId = null;
            if (ps.HasValue)
                paymentStatusId = (int)ps.Value;

            int? shippingStatusId = null;
            if (ss.HasValue)
                shippingStatusId = (int)ss.Value;

            var query = from o in _context.Orders
                        where (!o.Deleted) &&
                        (!orderStatusId.HasValue || orderStatusId.Value == 0 || o.OrderStatusId == orderStatusId.Value) &&
                        (!paymentStatusId.HasValue || paymentStatusId.Value == 0 || o.PaymentStatusId == paymentStatusId.Value) &&
                        (!shippingStatusId.HasValue || shippingStatusId.Value == 0 || o.ShippingStatusId == shippingStatusId.Value)
                        select o;

            var item = new OrderIncompleteReportLine();
            item.Total = Convert.ToDecimal(query.Sum(o => (decimal?)o.OrderTotal));
            item.Count = query.Count();
            return item;
        }
        /// <summary>
        /// Gets an order report
        /// </summary>
        /// <param name="os">Order status; null to load all orders</param>
        /// <param name="ps">Order payment status; null to load all orders</param>
        /// <param name="ss">Order shippment status; null to load all orders</param>
        /// <returns>IdataReader</returns>
        public OrderIncompleteReportLine GetVendorOrderReport(OrderStatusEnum? os,
            PaymentStatusEnum? ps, ShippingStatusEnum? ss)
        {
            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;

            //TODO: This needs to be repaired.  I do not totally understand link,
            //      hence the duplicate queries to achieve roughly the same results.

            var query = from opv in _context.OrderProductVariants
                        join o in _context.Orders on opv.OrderId equals o.OrderId
                        join pv in _context.ProductVariants on opv.ProductVariantId equals pv.ProductVariantId
                        where (!o.Deleted) &&
                        (!orderStatusId.HasValue || orderStatusId.Value == 0 || o.OrderStatusId == orderStatusId.Value) &&
                        (!paymentStatusId.HasValue || paymentStatusId.Value == 0 || o.PaymentStatusId == paymentStatusId.Value) &&
                        (!shippingStatusId.HasValue || shippingStatusId.Value == 0 || o.ShippingStatusId == shippingStatusId.Value) &&
                        (pv.VendorId == NopContext.Current.User.Vendor.CustomerId)

                        select o;

            var sideQuery = (from opv in _context.OrderProductVariants
                            join o in _context.Orders on opv.OrderId equals o.OrderId
                            join pv in _context.ProductVariants on opv.ProductVariantId equals pv.ProductVariantId
                            where (!o.Deleted) &&
                            (!orderStatusId.HasValue || orderStatusId.Value == 0 || o.OrderStatusId == orderStatusId.Value) &&
                            (!paymentStatusId.HasValue || paymentStatusId.Value == 0 || o.PaymentStatusId == paymentStatusId.Value) &&
                            (!shippingStatusId.HasValue || shippingStatusId.Value == 0 || o.ShippingStatusId == shippingStatusId.Value) &&
                            (pv.VendorId == NopContext.Current.User.Vendor.CustomerId)

                            select new { o.OrderTotal, o.OrderId }).Distinct();

            var item = new OrderIncompleteReportLine();
            item.Total = Convert.ToDecimal(sideQuery.Sum(o => (decimal?)o.OrderTotal));
            item.Count = sideQuery.Count();
            return item;
        }