public IActionResult ByDay(DateTime?from, DateTime?to) { var dayReportFilterInput = new DayReportFilterInput(); dayReportFilterInput.From = from.HasValue ? from.Value : DateTime.Now.Date; dayReportFilterInput.To = to.HasValue ? to.Value : dayReportFilterInput.From.Value.AddDays(1).AddMinutes(-1); return(View(dayReportFilterInput)); }
public DayReportFilterResult ByDay([FromQuery] DayReportFilterInput input) { if (!input.From.HasValue) { input.From = DateTime.Now.Date.AddDays(-7); } if (!input.To.HasValue) { input.To = DateTime.Now.Date; } if (input.Count <= 0) { input.Count = 10; } if (input.Page <= 0) { input.Page = 1; } var result = new DayReportFilterResult(); var ordersQuery = _orderRepository.GetAll.Include(o => o.OrderDetails) .Include("OrderDetails.OrderDetailToppings").Include(o => o.OrderDelivery).ThenInclude(od => od.DeliveryPartner) .Where(o => !o.IsDeleted && o.OrderPlaced >= input.From && o.OrderPlaced.Date <= input.To).AsNoTracking().ToList(); result.Days = ordersQuery .GroupBy(o => o.OrderPlaced.Date) .OrderByDescending(g => g.Key) .Skip((input.Page - 1) * input.Count).Take(input.Count) .Select(g => new DayReportItem { Date = Utilities.FormatDatetime(g.Key), Orders = g.OrderBy(o => o.OrderPlaced).Select(o => new OrderDayReportItem { OrderId = o.OrderId, OrderCode = o.Code, OrderPlaced = o.OrderPlaced, OrderDeliveried = o.OrderDeliveried, PromotionCode = o.PromotionCode, MoneySurcharge = o.SurchargeAmount, ShipFee = o.ShipFee, NinjaOrderTotal = o.OrderTotal, DiscountAmount = o.DiscountAmount, BonusDiscountAmount = 0, Partner = o.OrderDelivery != null ? o.OrderDelivery.DeliveryPartner?.Name : "", PartnerShipFee = o.OrderDelivery != null ? o.OrderDelivery.PartnerShipFee : 0, Drinks = o.OrderDetails.Select(od => new DrinkDayReportItem { Amount = od.Amount, DrinkName = od.DrinkName, DrinkSize = od.DrinkSize, FullPrice = od.FullPrice, IceOption = od.IceOption, Quantity = od.Quantity, SugarOption = od.SugarOption, Toppings = od.OrderDetailToppings.Select(t => t.ToppingName).ToArray() }).ToList(), CustomerName = string.Join(" ", new string[] { o.LastName, o.MiddleName, o.FirstName }.Where(s => !string.IsNullOrEmpty(s))), CustomerAddress = o.AddressLine, CustomerDistance = o.Distance.ToString(), CustomerPhone = o.PhoneNumber, Note = o.EmployeeNote }) }).ToList(); result.From = input.From; result.To = input.To; result.Page = input.Page; result.TotalPage = (ordersQuery.Count + input.Count - 1) / input.Count; return(result); }