/// <summary> /// Get order average report /// </summary> /// <param name="os">Order status;</param> /// <param name="startTime">Start date</param> /// <param name="endTime">End date</param> /// <returns>Result</returns> public OrderAverageReportLine GetOrderAverageReportLine(OrderStatusEnum os, DateTime? startTime, DateTime? endTime) { int orderStatusId = (int)os; var query = from o in _context.Orders where (!o.Deleted) && (o.OrderStatusId == orderStatusId) && (!startTime.HasValue || startTime.Value <= o.CreatedOn) && (!endTime.HasValue || endTime.Value >= o.CreatedOn) select o; var item = new OrderAverageReportLine(); item.SumOrders = Convert.ToDecimal(query.Sum(o => (decimal?)o.OrderTotal)); item.CountOrders = query.Count(); return item; }
private static OrderAverageReportLine DBMapping(DBOrderAverageReportLine dbItem) { if (dbItem == null) return null; OrderAverageReportLine item = new OrderAverageReportLine(); item.SumTodayOrders = dbItem.SumTodayOrders; item.CountTodayOrders = dbItem.CountTodayOrders; item.SumThisWeekOrders = dbItem.SumThisWeekOrders; item.CountThisWeekOrders = dbItem.CountThisWeekOrders; item.SumThisMonthOrders = dbItem.SumThisMonthOrders; item.CountThisMonthOrders = dbItem.CountThisMonthOrders; item.SumThisYearOrders = dbItem.SumThisYearOrders; item.CountThisYearOrders = dbItem.CountThisYearOrders; item.SumAllTimeOrders = dbItem.SumAllTimeOrders; item.CountAllTimeOrders = dbItem.CountAllTimeOrders; return item; }
/// <summary> /// Get order average report for the currently logged in vendor. /// </summary> /// <param name="os">Order start date</param> /// <param name="endTime">End date</param> /// <returns>Result</returns> public OrderAverageReportLine GetVendorOrderAverageReportLine(OrderStatusEnum os, DateTime? startTime, DateTime? endTime) { int orderStatusId = (int)os; //try this later. NFF 12.27.2011 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) && (o.OrderStatusId == orderStatusId) && (!startTime.HasValue || startTime.Value <= o.CreatedOn) && (!endTime.HasValue || endTime.Value >= o.CreatedOn) && (pv.VendorId == NopContext.Current.User.Vendor.CustomerId) //orderby o.CreatedOn descending, opv.OrderProductVariantId select o; //var query = from o in _context.Orders // where (!o.Deleted) && // (o.OrderStatusId == orderStatusId) && // (!startTime.HasValue || startTime.Value <= o.CreatedOn) && // (!endTime.HasValue || endTime.Value >= o.CreatedOn) // //from opv in o.NpOrderProductVariants // //join pv in _context.ProductVariants on opv.ProductVariantId equals pv.ProductVariantId // //where (o.NpOrderProductVariants.ProductVariant.VendorId.ProductVariant.VendorId == NopContext.Current.User.CustomerId) // // select o; var querygrp = query.Select(m => new { m.OrderId, m.OrderTotal }).Distinct(); var item = new OrderAverageReportLine(); item.SumOrders = Convert.ToDecimal(querygrp.Sum(o => (decimal?)o.OrderTotal)); item.CountOrders = query.Count(); return item; }