Ejemplo n.º 1
0
        private static void AddMissedDays(int daysPerWeek, List <CustCalDay> custCals, CustCalDay firstCCD)
        {
            const int DaysInWeek = 7;

            if (firstCCD == null)
            {
                return;
            }

            for (int i = 0; i < DaysInWeek - daysPerWeek; i++)
            {
                CustCalDay ccd = new CustCalDay
                {
                    DeliveryDate = firstCCD.DeliveryDate,
                    OrderNumber  = firstCCD.OrderNumber,
                    PlanName     = firstCCD.PlanName,
                    DayNumber    = daysPerWeek + i + 1,
                    ProfileName  = firstCCD.ProfileName,
                    UserName     = firstCCD.UserName,
                    LastName     = firstCCD.LastName,
                    FirstName    = firstCCD.FirstName
                };

                custCals.Add(ccd);
            }
        }
Ejemplo n.º 2
0
 private static CustCalDay LeftTrim(CustCalDay ccd)
 {
     ccd.Beverage  = LeftTrim(ccd.Beverage);
     ccd.Breakfast = LeftTrim(ccd.Breakfast);
     ccd.Dessert   = LeftTrim(ccd.Dessert);
     ccd.Dinner    = LeftTrim(ccd.Dinner);
     ccd.Lunch     = LeftTrim(ccd.Lunch);
     ccd.Snack     = LeftTrim(ccd.Snack);
     ccd.Other     = LeftTrim(ccd.Other);
     return(ccd);
 }
Ejemplo n.º 3
0
        private static CustCalDay AgregateByDay(CustCalDay ccd, MealItemReportItem reportItem, bool init)
        {
            switch ((Enums.MealTypes)reportItem.MealTypeId)
            {
            case Enums.MealTypes.BreakfastEntree:
                ccd.Breakfast += AddAsEntree(reportItem);
                break;

            case Enums.MealTypes.BreakfastSide:
                ccd.Breakfast += AddAsSide(reportItem);
                break;

            case Enums.MealTypes.Snack:
                ccd.Snack += AddAsEntree(reportItem);
                break;

            case Enums.MealTypes.Dessert:
                ccd.Dessert += AddAsEntree(reportItem);
                break;

            case Enums.MealTypes.DinnerEntree:
                ccd.Dinner += AddAsEntree(reportItem);
                break;

            case Enums.MealTypes.DinnerSide:
                ccd.Dinner += AddAsSide(reportItem);
                break;

            case Enums.MealTypes.LunchEntree:
                ccd.Lunch += AddAsEntree(reportItem);
                break;

            case Enums.MealTypes.LunchSide:
                ccd.Lunch += AddAsSide(reportItem);
                break;

            case Enums.MealTypes.OtherEntree:
            case Enums.MealTypes.ChildEntree:
            case Enums.MealTypes.Beverage:
            case Enums.MealTypes.Salad:
            case Enums.MealTypes.Soup:
            case Enums.MealTypes.Supplement:
            case Enums.MealTypes.Goods:
            case Enums.MealTypes.Miscellaneous:
                ccd.Other += AddAsEntree(reportItem);
                break;

            case Enums.MealTypes.OtherSide:
            case Enums.MealTypes.ChildSide:
                ccd.Other += AddAsSide(reportItem);
                break;
            }
            return(ccd);
        }
Ejemplo n.º 4
0
        public static List <CustCalDay> GetCustomerCalendars(DateTime startDate, DateTime endDate)
        {
            try
            {
                List <CustCalDay>         CustCals  = new List <CustCalDay>();
                List <MealItemReportItem> menuItems = ReportSprocs.GetMenuItemsByDateRange(startDate, endDate, false).Where(a => a.ParentTypeId != 1)
                                                      .OrderBy(a => a.DeliveryDate).ThenBy(a => a.CartItemId).ThenBy(a => a.DayNum).ThenBy(a => a.MealTypeId).ToList();

                menuItems.ForEach(delegate(MealItemReportItem result)
                {
                    CustCalDay ccd = CustCals.SingleOrDefault(a => a.UserProfileId == result.UserProfileId && a.DeliveryDate == result.DeliveryDate &&
                                                              a.OrderNumber == result.OrderNumber && a.PlanName == result.PlanName && a.DayNumber == result.DayNum);

                    if (ccd == null)
                    {
                        hccUserProfile prof = hccUserProfile.GetById(result.UserProfileId);

                        if (prof != null)
                        {
                            ccd = new CustCalDay
                            {
                                DeliveryDate  = result.DeliveryDate,
                                CartItemId    = result.CartItemId,
                                OrderNumber   = result.OrderNumber,
                                PlanName      = result.PlanName,
                                DayNumber     = result.DayNum,
                                ProfileName   = prof.ProfileName,
                                UserName      = prof.FullName,
                                LastName      = prof.LastName,
                                FirstName     = prof.FirstName,
                                UserProfileId = result.UserProfileId
                            };

                            ccd = AgregateByDay(ccd, result, true);

                            CustCals.Add(ccd);
                        }
                    }
                    else
                    {
                        ccd = AgregateByDay(ccd, result, false);
                    }
                });

                // trim the crap from the begins
                foreach (CustCalDay day in CustCals)
                {
                    LeftTrim(day);
                }

                // add missed days to show in the report (for example: for 3 day plan add 4-7 days with empty lists)
                var groupsByUser = CustCals.GroupBy(i => new { i.UserName, i.DeliveryDate, i.OrderNumber, i.PlanName }).Select(r => new
                {
                    UserName         = r.Key,
                    DaysPerWeek      = r.GroupBy(g => g.DayNumber).Count(),
                    FirstItemInGroup = r.FirstOrDefault()
                }).ToList();

                foreach (var group in groupsByUser)
                {
                    if (group.DaysPerWeek == 7 || group.FirstItemInGroup == null)
                    {
                        continue;
                    }

                    AddMissedDays(group.DaysPerWeek, CustCals, group.FirstItemInGroup);
                }

                return(CustCals);
            }
            catch (Exception)
            {
                throw;
            }
        }