public static List <ChefProdItem> GetWaaGItems(DateTime startDate, DateTime endDate)
        {
            try
            {
                List <ChefProdItem> chefItems = new List <ChefProdItem>();
                List <ChefProdItem> retItems  = new List <ChefProdItem>();

                List <MealItemReportItem> results = ReportSprocs.GetMenuItemsByDateRange(startDate, endDate).ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (MealItemReportItem result in results)
                    {
                        chefItems.Add(new ChefProdItem
                        {
                            ParentTypeId = result.ParentTypeId,
                            ParentId     = result.ParentId,
                            MenuItemId   = result.MenuItemId,
                            MealTypeId   = result.MealTypeId,
                            MealSizeId   = result.MealSizeId,
                            ItemName     = result.ItemName,
                            MealType     = Enums.GetEnumDescription(((Enums.MealTypes)result.MealTypeId)),
                            MealSize     = Enums.GetEnumDescription(((Enums.CartItemSize)result.MealSizeId)),
                            Quantity     = result.Quantity,
                            DeliveryDate = result.DeliveryDate,
                            OrderNumber  = result.OrderNumber
                        });
                    }

                    var s = chefItems.OrderBy(a => a.MealType).ThenBy(a => a.ItemName).ThenBy(a => a.MealSize).ThenBy(a => a.Prefs).ToList();

                    foreach (ChefProdItem chefItem in s)
                    {
                        ChefProdItem existItem = retItems.SingleOrDefault(a => a.MealType == chefItem.MealType &&
                                                                          a.ItemName == chefItem.ItemName && a.MealSize == chefItem.MealSize);

                        if (existItem == null)
                        {
                            retItems.Add(new ChefProdItem
                            {
                                ParentTypeId = 0,
                                ParentId     = 0,
                                MenuItemId   = chefItem.MenuItemId,
                                ItemName     = chefItem.ItemName,
                                MealType     = chefItem.MealType,
                                MealSize     = chefItem.MealSize,
                                Quantity     = chefItem.Quantity,
                                DeliveryDate = chefItem.DeliveryDate,
                                MealSizeId   = chefItem.MealSizeId,
                                MealTypeId   = chefItem.MealTypeId,
                                OrderNumber  = chefItem.OrderNumber
                            });
                        }
                        else
                        {
                            existItem.Quantity += chefItem.Quantity;
                        }
                    }
                }

                var r = retItems.OrderBy(a => a.MealType).ThenBy(a => a.ItemName).ThenBy(a => a.MealSize).ToList();
                return(r);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static List <ChefProdItem> GetPackSlipItems(string orderNumber, DateTime deliveryDate)
        {
            try
            {
                List <MealItemReportItem> results  = null;
                List <ChefProdItem>       retItems = new List <ChefProdItem>();

                results = ReportSprocs.GetMenuItemsByOrderNumber(orderNumber, deliveryDate).ToList();
                results = results.Where(ri => !hccMenuItem.SideMealTypes.Contains((Enums.MealTypes)ri.MealTypeId)).ToList();

                var cartItems = hccCartItem.GetByIds(results.Select(i => i.CartItemId).ToList());

                if (results != null && results.Count > 0)
                {
                    foreach (MealItemReportItem result in results)
                    {
                        if (result.MealSizeId == 0)
                        {
                            result.MealSizeId = 3; // update noSize to regular size
                        }
                        var cartItem = cartItems.FirstOrDefault(i => i.CartItemID == result.CartItemId);

                        if (cartItem == null)
                        {
                            continue; // should not happen
                        }
                        var newItem = new ChefProdItem
                        {
                            ParentTypeId = result.ParentTypeId,
                            ParentId     = result.ParentId,
                            MenuItemId   = result.MenuItemId,
                            MealTypeId   = result.MealTypeId,
                            MealSizeId   = result.MealSizeId,
                            ItemName     = result.ItemName, // + "-" + result.OrderNumber + " - " + result.ParentTypeId + "-" + result.ParentId,
                            MealType     = Enums.GetEnumDescription(((Enums.MealTypes)result.MealTypeId)),
                            MealSize     = Enums.GetEnumDescription(((Enums.CartItemSize)result.MealSizeId)),
                            Quantity     = result.Quantity,
                            DeliveryDate = result.DeliveryDate,
                            OrderNumber  = result.OrderNumber,
                            DayNumber    = result.DayNum,
                            Prefs        = string.IsNullOrWhiteSpace(result.Prefs) ? "" : result.Prefs,
                            CartItemId   = result.CartItemId,
                            CartItemType = Enums.GetEnumDescription(((Enums.CartItemTypeAbbr)cartItem.ItemTypeID))
                        };

                        if (cartItem.ItemTypeID == Convert.ToInt32((Enums.CartItemType.AlaCarte)) && cartItem.Plan_IsAutoRenew == true)
                        {
                            newItem.IsFamilyStyle = "Yes";
                        }
                        else if (cartItem.ItemTypeID == Convert.ToInt32((Enums.CartItemType.AlaCarte)) && cartItem.Plan_IsAutoRenew == false)
                        {
                            newItem.IsFamilyStyle = "No";
                        }
                        else
                        {
                            newItem.IsFamilyStyle = "N/A";
                        }
                        hccUserProfile prof = hccUserProfile
                                              .GetById(result.UserProfileId);

                        if (prof != null)
                        {
                            newItem.UserName    = prof.ParentProfileName;
                            newItem.ProfileName = prof.ProfileName;
                        }

                        hccCartItemCalendar cartCal = hccCartItemCalendar.GetBy(newItem.CartItemId, newItem.DeliveryDate);

                        if (newItem.ParentTypeId == 1) //a la carte
                        {
                            newItem.Sides = cartItem.GetMealSideMenuItemsAsSectionString(", ");
                            newItem.Side1 = cartItem.GetMealSide1MenuItemName();
                            newItem.Side2 = cartItem.GetMealSide2MenuItemName();
                            retItems.Add(newItem);
                        }
                        else //is program plan
                        {
                            Enums.MealTypes mealType = (Enums.MealTypes)result.MealTypeId;

                            if (mealType == Enums.MealTypes.BreakfastEntree ||
                                mealType == Enums.MealTypes.LunchEntree ||
                                mealType == Enums.MealTypes.DinnerEntree ||
                                mealType == Enums.MealTypes.OtherEntree ||
                                mealType == Enums.MealTypes.ChildEntree ||
                                mealType == Enums.MealTypes.Beverage ||
                                mealType == Enums.MealTypes.Dessert ||
                                mealType == Enums.MealTypes.Goods ||
                                mealType == Enums.MealTypes.Miscellaneous ||
                                mealType == Enums.MealTypes.Salad ||
                                mealType == Enums.MealTypes.Snack ||
                                mealType == Enums.MealTypes.Soup ||
                                mealType == Enums.MealTypes.Supplement)    // Non-Side Types
                            {
                                hccProgramDefaultMenu        defMenu = null;
                                List <hccProgramDefaultMenu> defMenus;

                                if (newItem.ParentTypeId == 2) //plan with exception
                                {
                                    hccCartDefaultMenuException defEx = hccCartDefaultMenuException.GetById(newItem.ParentId);

                                    if (defEx != null)
                                    {
                                        defMenu = hccProgramDefaultMenu.GetById(defEx.DefaultMenuID);

                                        //newItem.Prefs = hccCartDefaultMenuExPref.GetPrefsBy(defEx.DefaultMenuExceptID)
                                        //    .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                                    }
                                }
                                else if (newItem.ParentTypeId == 3) //plan default
                                {
                                    defMenu       = hccProgramDefaultMenu.GetById(newItem.ParentId);
                                    newItem.Prefs = "";
                                }

                                //newItem.DayNumber = defMenu.DayNumber;
                                if (defMenu == null)
                                {
                                    retItems.Add(newItem);
                                    continue;
                                }

                                defMenus = hccProgramDefaultMenu.GetBy(defMenu.CalendarID, defMenu.ProgramID);

                                //cheat to find related sides
                                List <hccProgramDefaultMenu> sides = new List <hccProgramDefaultMenu>();
                                string sideStr = string.Empty;

                                if (newItem.MealTypeId < 100)
                                {
                                    sides = defMenus.Where(a => a.DayNumber == newItem.DayNumber && (a.MealTypeID == (newItem.MealTypeId + 10))).ToList();
                                }

                                sides.ForEach(delegate(hccProgramDefaultMenu sideDefMenu)
                                {
                                    hccCartDefaultMenuException sideEx = hccCartDefaultMenuException.GetBy(sideDefMenu.DefaultMenuID, cartCal.CartCalendarID);
                                    hccMenuItem sideItem;
                                    Enums.CartItemSize sidePortionSize;
                                    string prefsString = string.Empty;

                                    if (sideEx == null)
                                    {
                                        sideItem        = hccMenuItem.GetById(sideDefMenu.MenuItemID);
                                        sidePortionSize = (Enums.CartItemSize)sideDefMenu.MenuItemSizeID;
                                        prefsString     = string.Empty;
                                    }
                                    else
                                    {
                                        sideItem        = hccMenuItem.GetById(sideEx.MenuItemID);
                                        sidePortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID;
                                        prefsString     = hccCartDefaultMenuExPref.GetPrefsBy(sideEx.DefaultMenuExceptID)
                                                          .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                                    }

                                    if (sideItem != null)
                                    {
                                        switch (sideDefMenu.Ordinal)
                                        {
                                        case 1:
                                            {
                                                newItem.Side1 = sideItem.Name;
                                                if (!string.IsNullOrWhiteSpace(prefsString))
                                                {
                                                    newItem.Side1 += " - " + prefsString;
                                                }
                                                break;
                                            }

                                        case 2:
                                            {
                                                newItem.Side2 = sideItem.Name;
                                                if (!string.IsNullOrWhiteSpace(prefsString))
                                                {
                                                    newItem.Side2 += " - " + prefsString;
                                                }
                                                break;
                                            }

                                        default:
                                            {
                                                // not supported side
                                                break;
                                            }
                                        }
                                    }

                                    if (sidePortionSize == Enums.CartItemSize.NoSize)
                                    {
                                        sidePortionSize = Enums.CartItemSize.RegularSize;
                                    }

                                    if (string.IsNullOrWhiteSpace(sideStr))
                                    {
                                        if (sideItem != null)
                                        {
                                            sideStr = sideItem.Name;
                                        }

                                        //sideStr += " - " + sidePortionSize.ToString();

                                        if (!string.IsNullOrWhiteSpace(prefsString))
                                        {
                                            sideStr += " - " + prefsString;
                                        }
                                    }
                                    else
                                    {
                                        if (sideItem != null)
                                        {
                                            sideStr += ", " + sideItem.Name;
                                        }

                                        //sideStr += " - " + sidePortionSize.ToString();

                                        if (!string.IsNullOrWhiteSpace(prefsString))
                                        {
                                            sideStr += " - " + prefsString;
                                        }
                                    }
                                });

                                if (string.IsNullOrWhiteSpace(sideStr) || string.Equals(sideStr, "None", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    sideStr = string.Empty;
                                }

                                newItem.Sides = sideStr;
                                retItems.Add(newItem);
                            }
                            else // it is a side item
                            { // skip it
                            }
                        }
                    }
                }

                return(retItems);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static List <ChefProdItem> GetChefProdItems(DateTime startDate, DateTime endDate)
        {
            try
            {
                List <MealItemReportItem> results = ReportSprocs.GetMenuItemsByDateRange(startDate, endDate).ToList();
                //List<ChefProdItem> chefItems = new List<ChefProdItem>();
                List <ChefProdItem> retItems = new List <ChefProdItem>();

                foreach (MealItemReportItem result in results)
                {
                    ChefProdItem existItem = retItems
                                             .SingleOrDefault(a => a.DeliveryDate == result.DeliveryDate &&
                                                              a.MenuItemId == result.MenuItemId &&
                                                              a.MealTypeId == result.MealTypeId &&
                                                              a.MealSizeId == result.MealSizeId &&
                                                              a.Prefs == result.Prefs);

                    if (existItem == null)
                    {
                        retItems.Add(new ChefProdItem
                        {
                            MenuItemId   = result.MenuItemId,
                            MealTypeId   = result.MealTypeId,
                            MealSizeId   = result.MealSizeId,
                            ItemName     = result.ItemName,
                            MealType     = result.MealTypeName,
                            MealSize     = result.MealSizeName,
                            Quantity     = result.Quantity,
                            Prefs        = string.IsNullOrWhiteSpace(result.Prefs) ? string.Empty : result.Prefs,
                            DeliveryDate = result.DeliveryDate,
                            OrderNumber  = result.OrderNumber
                        });
                    }
                    else
                    {
                        existItem.Quantity += result.Quantity;
                    }
                }

                //var s = chefItems.OrderBy(a => a.MealType).ThenBy(a => a.ItemName).ThenBy(a => a.MealSize).ThenBy(a => a.Prefs).ToList();

                //foreach (ChefProdItem chefItem in s)
                //{
                //    ChefProdItem existItem = retItems.SingleOrDefault(a => a.MealType == chefItem.MealType
                //        && a.ItemName == chefItem.ItemName && a.MealSize == chefItem.MealSize && a.Prefs == chefItem.Prefs);

                //    if (existItem == null)
                //    {
                //        retItems.Add(new ChefProdItem
                //        {
                //            ParentTypeId = 0,
                //            ParentId = 0,
                //            MenuItemId = chefItem.MenuItemId,
                //            ItemName = chefItem.ItemName,
                //            MealType = chefItem.MealType,
                //            MealSize = chefItem.MealSize,
                //            Quantity = chefItem.Quantity,
                //            Prefs = chefItem.Prefs,
                //            DeliveryDate = chefItem.DeliveryDate,
                //            OrderNumber = chefItem.OrderNumber,
                //            MealSizeId = chefItem.MealSizeId,
                //            MealTypeId = chefItem.MealTypeId
                //        });
                //    }
                //    else
                //    {
                //        existItem.Quantity += chefItem.Quantity;
                //    }
                //}

                var r = retItems.OrderBy(a => a.MealType).ThenBy(a => a.ItemName).ThenByDescending(a => a.MealSize).ThenByDescending(a => a.Prefs).ToList();
                return(r);
            }
            catch (Exception)
            {
                throw;
            }
        }