/// <summary> /// Get order average report /// </summary> /// <param name="os">Order status</param> /// <returns>Result</returns> public virtual OrderAverageReportLineSummary OrderAverageReport(OrderStatus os) { var item = new OrderAverageReportLineSummary(); item.OrderStatus = os; DateTime nowDt = _dateTimeHelper.ConvertToUserTime(DateTime.Now); TimeZoneInfo timeZone = _dateTimeHelper.CurrentTimeZone; //today DateTime t1 = new DateTime(nowDt.Year, nowDt.Month, nowDt.Day); if (!timeZone.IsInvalidTime(t1)) { DateTime? startTime1 = _dateTimeHelper.ConvertToUtcTime(t1, timeZone); DateTime? endTime1 = null; var todayResult = GetOrderAverageReportLine(os, null,null, startTime1, endTime1, null); item.SumTodayOrders = todayResult.SumOrders; item.CountTodayOrders = todayResult.CountOrders; } //week DayOfWeek fdow = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; DateTime today = new DateTime(nowDt.Year, nowDt.Month, nowDt.Day); DateTime t2 = today.AddDays(-(today.DayOfWeek - fdow)); if (!timeZone.IsInvalidTime(t2)) { DateTime? startTime2 = _dateTimeHelper.ConvertToUtcTime(t2, timeZone); DateTime? endTime2 = null; var weekResult = GetOrderAverageReportLine(os, null, null, startTime2, endTime2, null); item.SumThisWeekOrders = weekResult.SumOrders; item.CountThisWeekOrders = weekResult.CountOrders; } //month DateTime t3 = new DateTime(nowDt.Year, nowDt.Month, 1); if (!timeZone.IsInvalidTime(t3)) { DateTime? startTime3 = _dateTimeHelper.ConvertToUtcTime(t3, timeZone); DateTime? endTime3 = null; var monthResult = GetOrderAverageReportLine(os, null, null, startTime3, endTime3, null); item.SumThisMonthOrders = monthResult.SumOrders; item.CountThisMonthOrders = monthResult.CountOrders; } //year DateTime t4 = new DateTime(nowDt.Year, 1, 1); if (!timeZone.IsInvalidTime(t4)) { DateTime? startTime4 = _dateTimeHelper.ConvertToUtcTime(t4, timeZone); DateTime? endTime4 = null; var yearResult = GetOrderAverageReportLine(os, null, null, startTime4, endTime4, null); item.SumThisYearOrders = yearResult.SumOrders; item.CountThisYearOrders = yearResult.CountOrders; } //all time DateTime? startTime5 = null; DateTime? endTime5 = null; var allTimeResult = GetOrderAverageReportLine(os, null, null, startTime5, endTime5, null); item.SumAllTimeOrders = allTimeResult.SumOrders; item.CountAllTimeOrders = allTimeResult.CountOrders; return item; }
/// <summary> /// Get order average report /// </summary> /// <param name="storeId">Store identifier</param> /// <param name="os">Order status</param> /// <returns>Result</returns> public virtual OrderAverageReportLineSummary OrderAverageReport(int storeId, OrderStatus os) { var item = new OrderAverageReportLineSummary(); item.OrderStatus = os; var orderStatuses = new List<int>() { (int)os }; DateTime nowDt = _dateTimeHelper.ConvertToUserTime(DateTime.Now); TimeZoneInfo timeZone = _dateTimeHelper.CurrentTimeZone; //today var t1 = new DateTime(nowDt.Year, nowDt.Month, nowDt.Day); if (!timeZone.IsInvalidTime(t1)) { DateTime? startTime1 = _dateTimeHelper.ConvertToUtcTime(t1, timeZone); var todayResult = GetOrderAverageReportLine(storeId: storeId, osIds: orderStatuses, startTimeUtc: startTime1); item.SumTodayOrders = todayResult.SumOrders; item.CountTodayOrders = todayResult.CountOrders; } //week DayOfWeek fdow = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; var today = new DateTime(nowDt.Year, nowDt.Month, nowDt.Day); DateTime t2 = today.AddDays(-(today.DayOfWeek - fdow)); if (!timeZone.IsInvalidTime(t2)) { DateTime? startTime2 = _dateTimeHelper.ConvertToUtcTime(t2, timeZone); var weekResult = GetOrderAverageReportLine(storeId: storeId, osIds: orderStatuses, startTimeUtc: startTime2); item.SumThisWeekOrders = weekResult.SumOrders; item.CountThisWeekOrders = weekResult.CountOrders; } //month var t3 = new DateTime(nowDt.Year, nowDt.Month, 1); if (!timeZone.IsInvalidTime(t3)) { DateTime? startTime3 = _dateTimeHelper.ConvertToUtcTime(t3, timeZone); var monthResult = GetOrderAverageReportLine(storeId: storeId, osIds: orderStatuses, startTimeUtc: startTime3); item.SumThisMonthOrders = monthResult.SumOrders; item.CountThisMonthOrders = monthResult.CountOrders; } //year var t4 = new DateTime(nowDt.Year, 1, 1); if (!timeZone.IsInvalidTime(t4)) { DateTime? startTime4 = _dateTimeHelper.ConvertToUtcTime(t4, timeZone); var yearResult = GetOrderAverageReportLine(storeId: storeId, osIds: orderStatuses, startTimeUtc: startTime4); item.SumThisYearOrders = yearResult.SumOrders; item.CountThisYearOrders = yearResult.CountOrders; } //all time var allTimeResult = GetOrderAverageReportLine(storeId: storeId, osIds: orderStatuses); item.SumAllTimeOrders = allTimeResult.SumOrders; item.CountAllTimeOrders = allTimeResult.CountOrders; return item; }