public Tuple <string, DateTime> GetNameAndDateAndMenuItems(hccCartItem cartItem, hccCartItemCalendar cartCalendar) //, out List<hccMenuItem> menuItems)
        {
            string   newName = cartItem.SimpleName;
            DateTime?delDate = null;
            Tuple <string, DateTime> retVal = null;

            try
            {
                hccProductionCalendar prodCal = hccProductionCalendar.GetById(cartCalendar.CalendarID);

                if (prodCal != null)
                {
                    hccProgramPlan             plan     = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value);
                    List <hccCartItemCalendar> cartCals = hccCartItemCalendar.GetByCartItemID(cartItem.CartItemID);
                    hccCartItemCalendar        cartCal  = cartCals.Where(a => a.CalendarID == prodCal.CalendarID).SingleOrDefault();

                    if (cartCal != null)
                    {
                        int cartCalIndex = cartCals.IndexOf(cartCal);

                        newName += " - Week: " + (cartCalIndex + 1).ToString();
                        delDate  = prodCal.DeliveryDate;
                    }
                }
            }
            catch { throw; }

            if (delDate.HasValue)
            {
                retVal = new Tuple <string, DateTime>(newName, delDate.Value);
            }

            return(retVal);
        }
        public List <int> GetDaysWithAllergens(int cartCalendarId)
        {
            try
            {
                List <int>          daysWithAllergens = new List <int>();
                hccProgramPlan      plan    = hccProgramPlan.GetById(this.Plan_PlanID.Value);
                hccUserProfile      profile = hccUserProfile.GetById(this.UserProfileID);
                hccCartItemCalendar cartCal = hccCartItemCalendar.GetById(cartCalendarId);

                if (plan != null && profile != null)
                {
                    // get list of user profile allergens
                    List <hccAllergen> userAllergens = profile.GetAllergens();

                    if (userAllergens.Count > 0)
                    {
                        List <hccProgramDefaultMenu> defaultMenus = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID);

                        defaultMenus.ForEach(delegate(hccProgramDefaultMenu defaultMenu)
                        {
                            hccCartDefaultMenuException excMenu = hccCartDefaultMenuException.GetBy(defaultMenu.DefaultMenuID, cartCal.CartCalendarID);
                            List <hccAllergen> menuAllg         = new List <hccAllergen>();

                            if (excMenu == null)
                            {
                                hccMenuItem item = hccMenuItem.GetById(defaultMenu.MenuItemID);
                                if (item != null)
                                {
                                    menuAllg = item.GetAllergens();
                                }
                            }
                            else
                            {
                                menuAllg = excMenu.GetMenuItemAllergens();
                            }

                            if (menuAllg.Count > 0)
                            {
                                if (userAllergens.Intersect(menuAllg).Count() > 0)
                                {
                                    daysWithAllergens.Add(defaultMenu.DayNumber);
                                }
                            }
                        });
                    }
                }
                return(daysWithAllergens);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public static List <ProgramPlanCountItemHolder> GetProgramPlanCounts(DateTime startDate, DateTime endDate)
        {
            try
            {
                List <ProgramPlanCountItemHolder> retVals = new List <ProgramPlanCountItemHolder>();

                List <MealItemReportItem> mealItems = ReportSprocs.GetMenuItemsByDateRange(startDate, endDate)
                                                      .Where(a => ((Enums.MealTypes)a.MealTypeId).ToString().Contains("Entree"))
                                                      .OrderBy(a => a.DeliveryDate).ThenBy(a => a.CartItemId).ThenBy(a => a.DayNum).ThenBy(a => a.MealTypeId).ToList();

                mealItems.ForEach(delegate(MealItemReportItem result)
                {
                    if (result.PlanId != 0)
                    {
                        if (retVals.Count(a => a.DeliveryDate == result.DeliveryDate && a.PlanId == result.PlanId) == 0)
                        {
                            ProgramPlanCountItemHolder newVal = new ProgramPlanCountItemHolder
                            {
                                DeliveryDate = result.DeliveryDate,
                                PlanId       = result.PlanId
                            };

                            retVals.Add(newVal);
                        }
                    }
                    else
                    {
                        if (retVals.Count(a => a.DeliveryDate == result.DeliveryDate && a.PlanId == result.PlanId && a.IsFamilyStyle == result.IsFamilyStyle) == 0)
                        {
                            ProgramPlanCountItemHolder newVal = new ProgramPlanCountItemHolder
                            {
                                DeliveryDate  = result.DeliveryDate,
                                PlanId        = result.PlanId,
                                IsFamilyStyle = result.IsFamilyStyle,
                                CartId        = result.CartId
                            };

                            retVals.Add(newVal);
                        }
                    }
                });
                int                UpdateOrderCount = 0;
                int                UpdateCount      = 0;
                bool               IsUpdate         = false;
                List <int>         CartIds;
                hccCartItem        hcccartItem  = new hccCartItem();
                List <hccCartItem> hcccartItems = new List <hccCartItem>();
                retVals.ForEach(delegate(ProgramPlanCountItemHolder holder)
                {
                    if (holder.PlanId == 0 && holder.IsFamilyStyle == false)
                    {
                        holder.PlanName    = "ALC Individual Portions";
                        holder.ProgramName = "ALC Individual Portions";
                    }
                    else if (holder.PlanId == 0 && holder.IsFamilyStyle == true)
                    {
                        holder.PlanName    = "ALC Family Style";
                        holder.ProgramName = "ALC Family Style";
                    }
                    else
                    {
                        hccProgramPlan plan = hccProgramPlan.GetById(holder.PlanId);

                        if (plan != null)
                        {
                            holder.PlanName = plan.Name;

                            hccProgram program = hccProgram.GetById(plan.ProgramID);

                            if (program != null)
                            {
                                holder.ProgramName = program.Name;
                            }
                        }
                    }

                    var oc = mealItems.Where(a => a.DeliveryDate == holder.DeliveryDate &&
                                             a.PlanId == holder.PlanId)
                             .GroupBy(a => a.OrderNumber).Distinct();
                    if (holder.PlanId == 0 && holder.IsFamilyStyle == false)
                    {
                        oc = mealItems.Where(a => a.DeliveryDate == holder.DeliveryDate &&
                                             a.PlanId == holder.PlanId && a.IsFamilyStyle == holder.IsFamilyStyle)
                             .GroupBy(a => a.OrderNumber).Distinct();
                    }
                    else if (holder.PlanId == 0 && holder.IsFamilyStyle == true)
                    {
                        oc = mealItems.Where(a => a.DeliveryDate == holder.DeliveryDate &&
                                             a.PlanId == holder.PlanId && a.IsFamilyStyle == holder.IsFamilyStyle)
                             .GroupBy(a => a.OrderNumber).Distinct();
                    }
                    holder.OrderCount = oc.Count();

                    int mealCount = 0;
                    oc.ToList().ForEach(delegate(IGrouping <string, MealItemReportItem> orderNumGroup)
                    {
                        var g = orderNumGroup.ToList();

                        g.ForEach(delegate(MealItemReportItem result)
                        {
                            mealCount += result.Quantity;
                        });
                    });

                    holder.MealCount = mealCount;
                    if (holder.PlanId == 0 && holder.IsFamilyStyle == false)
                    {
                        CartIds = mealItems.Where(x => x.PlanId == 0 && x.DeliveryDate == holder.DeliveryDate).Select(x => x.CartId).Distinct().ToList();
                        foreach (var id in CartIds)
                        {
                            hcccartItems = GetCartItemsByCartId(id, holder.DeliveryDate);

                            if (hcccartItems.Count() > 1)
                            {
                                foreach (var item in hcccartItems)
                                {
                                    if (item.Plan_IsAutoRenew == true && item.ItemTypeID == 1)
                                    {
                                        UpdateOrderCount++;
                                    }
                                    else if (item.Plan_IsAutoRenew == false && item.ItemTypeID == 1)
                                    {
                                        IsUpdate = true;
                                    }
                                }
                                if (UpdateOrderCount > 0 && IsUpdate)
                                {
                                    UpdateCount++;
                                    UpdateOrderCount = 0;
                                }
                            }
                            IsUpdate = false;
                        }
                        if (UpdateCount > 0)
                        {
                            var items        = retVals.Where(x => x.PlanName == "ALC Individual Portions" && x.DeliveryDate == holder.DeliveryDate).FirstOrDefault();
                            items.OrderCount = items.OrderCount - UpdateCount;
                            UpdateCount      = 0;
                            //foreach (var item in retVals)
                            //{
                            //    if (item.PlanName == "ALC Individual Portions" && item.DeliveryDate==holder.DeliveryDate)
                            //    {
                            //        item.OrderCount = item.OrderCount - UpdateOrderCount;
                            //    }
                            //}
                        }
                    }
                });

                return(retVals.OrderBy(a => a.DeliveryDate).ThenBy(a => a.ProgramName).ThenBy(a => a.PlanName).ToList());
            }
            catch
            {
                throw;
            }
        }
Example #4
0
        public static List <MOTCartItem> GetFromCartCalendarForWaaG(hccCartItemCalendar cartCal)
        {
            List <MOTCartItem>           retMotItems = new List <MOTCartItem>();
            hccCartItem                  cartItem    = hccCartItem.GetById(cartCal.CartItemID);
            hccProductionCalendar        prodCal     = hccProductionCalendar.GetById(cartCal.CalendarID);
            hccProgramPlan               plan        = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value);
            List <hccProgramDefaultMenu> defMenus    = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID);
            List <hccMenuItem>           planMeals   = new List <hccMenuItem>();

            defMenus.ForEach(delegate(hccProgramDefaultMenu defMenu)
            {
                hccCartDefaultMenuException cartDefMenuEx = hccCartDefaultMenuException.GetBy(defMenu.DefaultMenuID, cartCal.CartCalendarID);

                hccMenuItem selItem;
                Enums.CartItemSize selPortionSize;
                string prefsString = string.Empty;

                if (cartDefMenuEx == null)
                {
                    selItem        = hccMenuItem.GetById(defMenu.MenuItemID);
                    selPortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID;
                    prefsString    = "None";
                }
                else
                {
                    selItem        = hccMenuItem.GetById(cartDefMenuEx.MenuItemID);
                    selPortionSize = (Enums.CartItemSize)cartDefMenuEx.MenuItemSizeID;
                    prefsString    = hccCartDefaultMenuExPref.GetPrefsBy(cartDefMenuEx.DefaultMenuExceptID)
                                     .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                }

                MOTCartItem curMotItem = null;

                if (selItem != null)
                {
                    if (selPortionSize == Enums.CartItemSize.NoSize)
                    {
                        selPortionSize = Enums.CartItemSize.RegularSize;
                    }

                    curMotItem = new MOTCartItem
                    {
                        CartItem     = cartItem,
                        CartItemId   = cartItem.CartItemID,
                        CustomerName = cartItem.UserProfile.ParentProfileName,
                        OrderNumber  = cartItem.OrderNumber,
                        DeliveryDate = prodCal.DeliveryDate,
                        DayNumber    = defMenu.DayNumber,
                        ItemName     = selItem.Name,
                        MealType     = selItem.MealType,
                        PortionSize  = Enums.GetEnumDescription(selPortionSize),
                        Preferences  = prefsString,
                        ProfileName  = cartItem.UserProfile.ProfileName,
                        Servings     = cartItem.Quantity.ToString()
                    };

                    retMotItems.Add(curMotItem);
                }
            });

            return(retMotItems);
        }
Example #5
0
        public static List <MOTCartItem> GetFromCartCalendarForMOT(hccCartItemCalendar cartCal)
        {
            try
            {
                List <MOTCartItem> retMotItems  = new List <MOTCartItem>();
                List <MOTCartItem> addlMotItems = new List <MOTCartItem>();

                hccCartItem                  cartItem  = hccCartItem.GetById(cartCal.CartItemID);
                hccProductionCalendar        prodCal   = hccProductionCalendar.GetById(cartCal.CalendarID);
                hccProgramPlan               plan      = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value);
                List <hccProgramDefaultMenu> defMenus  = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID, plan.NumDaysPerWeek);
                List <hccMenuItem>           planMeals = new List <hccMenuItem>();

                defMenus.ForEach(delegate(hccProgramDefaultMenu defMenu)
                {
                    hccCartDefaultMenuException cartDefMenuEx = hccCartDefaultMenuException.GetBy(defMenu.DefaultMenuID, cartCal.CartCalendarID);

                    hccMenuItem selItem;
                    Enums.CartItemSize selPortionSize = Enums.CartItemSize.NoSize;
                    string prefsString = string.Empty;

                    if (cartDefMenuEx == null)
                    {
                        selItem        = hccMenuItem.GetById(defMenu.MenuItemID);
                        selPortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID;
                        prefsString    = "None";
                    }
                    else
                    {
                        selItem        = hccMenuItem.GetById(cartDefMenuEx.MenuItemID);
                        selPortionSize = (Enums.CartItemSize)cartDefMenuEx.MenuItemSizeID;

                        try
                        {
                            prefsString = string.Empty;
                            List <hccPreference> prefs = hccCartDefaultMenuExPref.GetPrefsBy(cartDefMenuEx.DefaultMenuExceptID);
                            prefsString = prefs.Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }

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

                    MOTCartItem curMotItem = null;

                    if (selItem != null)
                    {
                        if (selItem.MealType == Enums.MealTypes.BreakfastEntree ||
                            selItem.MealType == Enums.MealTypes.LunchEntree ||
                            selItem.MealType == Enums.MealTypes.DinnerEntree ||
                            selItem.MealType == Enums.MealTypes.ChildEntree ||
                            selItem.MealType == Enums.MealTypes.Beverage ||
                            selItem.MealType == Enums.MealTypes.Dessert ||
                            selItem.MealType == Enums.MealTypes.Goods ||
                            selItem.MealType == Enums.MealTypes.Miscellaneous ||
                            selItem.MealType == Enums.MealTypes.Salad ||
                            selItem.MealType == Enums.MealTypes.Snack ||
                            selItem.MealType == Enums.MealTypes.Soup ||
                            selItem.MealType == Enums.MealTypes.Supplement)
                        {
                            curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber &&
                                                                    a.MealType == selItem.MealType);

                            if (curMotItem == null || curMotItem.MealType == Enums.MealTypes.Snack)
                            {
                                curMotItem = new MOTCartItem
                                {
                                    CartItem     = cartItem,
                                    CartItemId   = cartItem.CartItemID,
                                    CustomerName = cartItem.UserProfile.ParentProfileName,
                                    OrderNumber  = cartItem.OrderNumber + "-PRG",
                                    DeliveryDate = prodCal.DeliveryDate,
                                    DayNumber    = defMenu.DayNumber,
                                    ItemName     = selItem.Name,
                                    MealType     = selItem.MealType,
                                    PortionSize  = Enums.GetEnumDescription(selPortionSize),
                                    Preferences  = prefsString,
                                    ProfileName  = cartItem.UserProfile != null ? cartItem.UserProfile.ProfileName : string.Empty,
                                    Servings     = cartItem.Quantity.ToString(),
                                    MenuItem     = selItem,
                                    Quantity     = cartItem.Quantity,
                                    Sides        = "None"
                                };

                                if (cartItem.SnapShipAddrId.HasValue)
                                {
                                    hccAddress addr           = hccAddress.GetById(cartItem.SnapShipAddrId.Value);
                                    curMotItem.DeliveryMethod = ((Enums.DeliveryTypes)addr.DefaultShippingTypeID).ToString();
                                }

                                retMotItems.Add(curMotItem);
                            }
                            else
                            {
                                curMotItem.Sides += selPortionSize + " - " + selItem.Name;
                            }
                        }
                        else
                        {
                            // get parent entree type
                            Enums.MealTypes parentType = Enums.MealTypes.Unknown;

                            if (selItem.MealType == Enums.MealTypes.BreakfastSide)
                            {
                                parentType = Enums.MealTypes.BreakfastEntree;
                            }
                            else if (selItem.MealType == Enums.MealTypes.LunchSide)
                            {
                                parentType = Enums.MealTypes.LunchEntree;
                            }
                            else if (selItem.MealType == Enums.MealTypes.DinnerSide)
                            {
                                parentType = Enums.MealTypes.DinnerEntree;
                            }
                            else if (selItem.MealType == Enums.MealTypes.OtherSide)
                            {
                                parentType = Enums.MealTypes.OtherEntree;
                            }
                            else if (selItem.MealType == Enums.MealTypes.ChildSide)
                            {
                                parentType = Enums.MealTypes.ChildEntree;
                            }

                            curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber &&
                                                                    a.MealType == parentType);

                            if (curMotItem == null)
                            {
                                curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber);

                                if (curMotItem == null)
                                {
                                    curMotItem = new MOTCartItem
                                    {
                                        CartItem     = cartItem,
                                        CartItemId   = cartItem.CartItemID,
                                        CustomerName = cartItem.UserProfile.ParentProfileName,
                                        OrderNumber  = cartItem.OrderNumber + "-PRG",
                                        DeliveryDate = prodCal.DeliveryDate,
                                        DayNumber    = defMenu.DayNumber,
                                        ItemName     = selItem.Name,
                                        MealType     = selItem.MealType,
                                        PortionSize  = Enums.GetEnumDescription(selPortionSize),
                                        Preferences  = prefsString,
                                        ProfileName  = cartItem.UserProfile != null ? cartItem.UserProfile.ProfileName : string.Empty,
                                        Servings     = cartItem.Quantity.ToString(),
                                        MenuItem     = selItem,
                                        Quantity     = cartItem.Quantity,
                                        Sides        = "None"
                                    };

                                    if (cartItem.SnapShipAddrId.HasValue)
                                    {
                                        hccAddress addr           = hccAddress.GetById(cartItem.SnapShipAddrId.Value);
                                        curMotItem.DeliveryMethod = ((Enums.DeliveryTypes)addr.DefaultShippingTypeID).ToString();
                                    }

                                    retMotItems.Add(curMotItem);
                                }
                            }
                            else
                            {
                                if (string.IsNullOrWhiteSpace(curMotItem.Sides))
                                {
                                    curMotItem.Sides = selItem.Name;

                                    if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString))
                                    {
                                        curMotItem.Sides += " (" + prefsString + ")";
                                    }
                                }
                                else
                                {
                                    if (curMotItem.Sides == "None")
                                    {
                                        curMotItem.Sides = selItem.Name;
                                    }
                                    else
                                    {
                                        curMotItem.Sides += ", " + selItem.Name;
                                    }

                                    if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString))
                                    {
                                        curMotItem.Sides += " (" + prefsString + ")";
                                    }
                                }
                            }
                        }
                    }
                });

                List <MOTCartItem> removeDupItems = new List <MOTCartItem>();

                retMotItems.ForEach(delegate(MOTCartItem motItem)
                {
                    if (motItem.MealType == Enums.MealTypes.BreakfastEntree ||
                        motItem.MealType == Enums.MealTypes.LunchEntree ||
                        motItem.MealType == Enums.MealTypes.DinnerEntree ||
                        motItem.MealType == Enums.MealTypes.ChildEntree ||
                        motItem.MealType == Enums.MealTypes.Beverage ||
                        motItem.MealType == Enums.MealTypes.Dessert ||
                        motItem.MealType == Enums.MealTypes.Goods ||
                        motItem.MealType == Enums.MealTypes.Miscellaneous ||
                        motItem.MealType == Enums.MealTypes.Salad ||
                        motItem.MealType == Enums.MealTypes.Snack ||
                        motItem.MealType == Enums.MealTypes.Soup ||
                        motItem.MealType == Enums.MealTypes.Supplement)
                    {
                        if (motItem.CartItem.Quantity > 1)
                        {
                            for (int i = 1; i <= motItem.CartItem.Quantity; i++)
                            {
                                MOTCartItem copyMotItem = new MOTCartItem
                                {
                                    CartItem       = motItem.CartItem,
                                    CartItemId     = motItem.CartItemId,
                                    OrderNumber    = motItem.OrderNumber,
                                    DeliveryDate   = motItem.DeliveryDate,
                                    CustomerName   = motItem.CustomerName,
                                    DayNumber      = motItem.DayNumber,
                                    ItemName       = motItem.ItemName,
                                    MealType       = motItem.MealType,
                                    PortionSize    = motItem.PortionSize,
                                    Preferences    = motItem.Preferences,
                                    ProfileName    = motItem.ProfileName,
                                    MenuItem       = motItem.MenuItem,
                                    Index          = motItem.Index,
                                    Quantity       = motItem.Quantity,
                                    Sides          = motItem.Sides,
                                    DeliveryMethod = motItem.DeliveryMethod,
                                    Servings       = "1" //motItem.Servings
                                };

                                addlMotItems.Add(copyMotItem);
                            }

                            removeDupItems.Add(motItem);
                        }
                    }
                });

                if (addlMotItems.Count > 0)
                {
                    retMotItems.AddRange(addlMotItems);
                }

                if (removeDupItems.Count > 0)
                {
                    removeDupItems.ForEach(a => retMotItems.Remove(a));
                }

                var t = retMotItems.ToList();
                return(t);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #6
0
        public static List <MOTCartItem> GetFromCartCalendar(hccCartItemCalendar cartCal)
        {
            List <MOTCartItem>           retMotItems = new List <MOTCartItem>();
            hccCartItem                  cartItem    = hccCartItem.GetById(cartCal.CartItemID);
            hccProductionCalendar        prodCal     = hccProductionCalendar.GetById(cartCal.CalendarID);
            hccProgramPlan               plan        = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value);
            List <hccProgramDefaultMenu> defMenus    = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID);
            List <hccMenuItem>           planMeals   = new List <hccMenuItem>();

            defMenus.ForEach(delegate(hccProgramDefaultMenu defMenu)
            {
                hccCartDefaultMenuException cartDefMenuEx = hccCartDefaultMenuException.GetBy(defMenu.DefaultMenuID, cartCal.CartCalendarID);

                hccMenuItem selItem;
                Enums.CartItemSize selPortionSize;
                string prefsString = string.Empty;

                // Get the current menuItem
                if (cartDefMenuEx == null)
                {
                    selItem        = hccMenuItem.GetById(defMenu.MenuItemID);
                    selPortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID;
                    prefsString    = "None";
                }
                else
                {
                    selItem        = hccMenuItem.GetById(cartDefMenuEx.MenuItemID);
                    selPortionSize = (Enums.CartItemSize)cartDefMenuEx.MenuItemSizeID;
                    prefsString    = hccCartDefaultMenuExPref.GetPrefsBy(cartDefMenuEx.DefaultMenuExceptID)
                                     .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                }

                MOTCartItem curMotItem = null;

                if (selItem != null)
                {
                    if (selPortionSize == Enums.CartItemSize.NoSize)
                    {
                        selPortionSize = Enums.CartItemSize.RegularSize;
                    }

                    // determine if current item is an Entree or side
                    if (selItem.MealType == Enums.MealTypes.BreakfastEntree ||
                        selItem.MealType == Enums.MealTypes.LunchEntree ||
                        selItem.MealType == Enums.MealTypes.DinnerEntree ||
                        selItem.MealType == Enums.MealTypes.OtherEntree ||
                        selItem.MealType == Enums.MealTypes.ChildEntree ||
                        selItem.MealType == Enums.MealTypes.Beverage ||
                        selItem.MealType == Enums.MealTypes.Dessert ||
                        selItem.MealType == Enums.MealTypes.Goods ||
                        selItem.MealType == Enums.MealTypes.Miscellaneous ||
                        selItem.MealType == Enums.MealTypes.Salad ||
                        selItem.MealType == Enums.MealTypes.Snack ||
                        selItem.MealType == Enums.MealTypes.Soup ||
                        selItem.MealType == Enums.MealTypes.Supplement)
                    {   // Entrees
                        // determine if this type of entree has been added in previous loop
                        curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber &&
                                                                a.MealType == selItem.MealType);

                        if (curMotItem == null)
                        {
                            //if not added in previous loop, add new
                            curMotItem = new MOTCartItem
                            {
                                MenuItem     = selItem,
                                CartItem     = cartItem,
                                CartItemId   = cartItem.CartItemID,
                                CustomerName = cartItem.UserProfile.ParentProfileName,
                                OrderNumber  = cartItem.OrderNumber,
                                DeliveryDate = prodCal.DeliveryDate,
                                DayNumber    = defMenu.DayNumber,
                                ItemName     = selItem.Name,
                                MealType     = selItem.MealType,
                                PortionSize  = Enums.GetEnumDescription(selPortionSize),
                                Preferences  = prefsString,
                                ProfileName  = cartItem.UserProfile.ProfileName,
                                Servings     = cartItem.Quantity.ToString(),
                            };

                            retMotItems.Add(curMotItem);
                        }
                        else
                        {
                            //if entree added in previous loop, add as a side
                            curMotItem.Sides += selPortionSize + " - " + selItem.Name;
                        }
                    }
                    else
                    {   // Sides
                        // get parent entree type
                        Enums.MealTypes parentType = Enums.MealTypes.Unknown;

                        if (selItem.MealType == Enums.MealTypes.BreakfastSide)
                        {
                            parentType = Enums.MealTypes.BreakfastEntree;
                        }
                        else if (selItem.MealType == Enums.MealTypes.LunchSide)
                        {
                            parentType = Enums.MealTypes.LunchEntree;
                        }
                        else if (selItem.MealType == Enums.MealTypes.DinnerSide)
                        {
                            parentType = Enums.MealTypes.DinnerEntree;
                        }
                        else if (selItem.MealType == Enums.MealTypes.OtherSide)
                        {
                            parentType = Enums.MealTypes.OtherEntree;
                        }
                        else if (selItem.MealType == Enums.MealTypes.ChildSide)
                        {
                            parentType = Enums.MealTypes.ChildEntree;
                        }

                        // determine if this type of entree has been added in previous loop
                        curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber &&
                                                                a.MealType == parentType);

                        if (curMotItem == null)
                        {
                            curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber);

                            if (curMotItem == null)
                            {
                                curMotItem = new MOTCartItem
                                {
                                    MenuItem     = selItem,
                                    CartItem     = cartItem,
                                    CartItemId   = cartItem.CartItemID,
                                    CustomerName = cartItem.UserProfile.ParentProfileName,
                                    OrderNumber  = cartItem.OrderNumber,
                                    DeliveryDate = prodCal.DeliveryDate,
                                    DayNumber    = defMenu.DayNumber,
                                    ItemName     = selItem.Name,
                                    MealType     = selItem.MealType,
                                    PortionSize  = Enums.GetEnumDescription(selPortionSize),
                                    Preferences  = prefsString,
                                    ProfileName  = cartItem.UserProfile.ProfileName,
                                    Servings     = cartItem.Quantity.ToString(),
                                    Sides        = "NoneB"
                                };


                                retMotItems.Add(curMotItem);
                            }
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(curMotItem.Sides))
                            {
                                curMotItem.Sides += selItem.Name;

                                if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString))
                                {
                                    curMotItem.Sides += " (" + prefsString + ")";
                                }
                            }
                            else
                            {
                                curMotItem.Sides += ", " + selItem.Name;

                                if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString))
                                {
                                    curMotItem.Sides += " (" + prefsString + ")";
                                }
                            }
                        }
                    }
                }
            });

            return(retMotItems);
        }
Example #7
0
        public static List <PackingSlip> GeneratePackingSlips(DateTime deliveryDate)
        {
            List <PackingSlip>  outSlips = new List <PackingSlip>();
            List <AggrCartItem> agItems  = hccCartItem.Search(null, null, null, deliveryDate, true, false);

            foreach (AggrCartItem agItem in agItems)
            {
                hccCart cart = hccCart.GetBy(agItem.CartItem.OrderNumber);

                if (cart != null && (cart.Status == Enums.CartStatus.Paid || cart.Status == Enums.CartStatus.Fulfilled))
                {
                    PackingSlip existItem = outSlips.SingleOrDefault(a => a.OrderNumber == agItem.CartItem.OrderNumber);

                    if (existItem == null)
                    {
                        PackingSlip ps = new PackingSlip
                        {
                            OrderNumber  = agItem.CartItem.OrderNumber,
                            DeliveryDay  = agItem.DeliveryDate.DayOfWeek.ToString(),
                            DeliveryDate = agItem.DeliveryDate.ToShortDateString()
                        };

                        //if (agItem.CartItem.UserProfile.ParentProfileID.HasValue)
                        //    ps.SpecialInstructions = hccUserProfileNote.GetBy(agItem.CartItem.UserProfile.ParentProfileID.Value, Enums.UserProfileNoteTypes.ShippingNote, null)
                        //        .Select(a => a.Note).DefaultIfEmpty(string.Empty).Aggregate((b, c) => b + ", " + c);

                        string n1 = hccUserProfileNote.GetBy(agItem.CartItem.UserProfile.UserProfileID, Enums.UserProfileNoteTypes.ShippingNote, null)
                                    .Select(a => a.Note).DefaultIfEmpty(string.Empty).Aggregate((b, c) => b + ", " + c);

                        if (!string.IsNullOrWhiteSpace(n1))
                        {
                            if (!string.IsNullOrWhiteSpace(ps.SpecialInstructions))
                            {
                                ps.SpecialInstructions += ", " + n1;
                            }
                            else
                            {
                                ps.SpecialInstructions += n1;
                            }
                        }

                        if (agItem.CartSnap != null)
                        {
                            ps.LastName     = agItem.CartSnap.LastName;
                            ps.FirstName    = agItem.CartSnap.FirstName;
                            ps.OrderProfile = agItem.CartSnap.ProfileName;
                            ps.Customer     = ps.LastName + ", " + ps.FirstName;
                        }
                        else
                        {
                            ps.LastName     = agItem.CartItem.UserProfile.ParentProfileName;
                            ps.Customer     = ps.LastName;
                            ps.OrderProfile = agItem.CartItem.UserProfile.ProfileName;
                        }
                        if (agItem.CartItem != null)
                        {
                            if (agItem.CartItem.Plan_IsAutoRenew == true && agItem.CartItem.ItemTypeID == 1)
                            {
                                ps.IsFamily = "Yes";
                            }
                            else if (agItem.CartItem.Plan_IsAutoRenew == false && agItem.CartItem.ItemTypeID == 1)
                            {
                                ps.IsFamily = "No";
                            }
                            else
                            {
                                ps.IsFamily = "N/A";
                            }
                        }
                        if (agItem.CartItem.SnapShipAddrId.HasValue)
                        {
                            hccAddress shipAddr = hccAddress.GetById(agItem.CartItem.SnapShipAddrId.Value);
                            ps.DeliveryAddress  = shipAddr.ToString();
                            ps.DeliveryAddress += shipAddr.IsBusiness ? "<b>Business Address</b>" : "<b>Residential Address</b>";
                            ps.DeliveryMethod   = Enums.GetEnumDescription(((Enums.DeliveryTypes)shipAddr.DefaultShippingTypeID));
                        }

                        if (agItem.CartItem.ItemType == Enums.CartItemType.DefinedPlan)
                        {
                            hccProductionCalendar pc = hccProductionCalendar.GetBy(agItem.DeliveryDate);
                            hccProgramPlan        pg = hccProgramPlan.GetById(agItem.CartItem.Plan_PlanID.Value);
                            int defMenuCount         = hccProgramDefaultMenu.GetBy(pc.CalendarID, pg.ProgramID)
                                                       .Where(a => a.MenuItemID > 0 && a.DayNumber <= pg.NumDaysPerWeek).Count();

                            ps.ItemsCount += agItem.TotalQuantity * defMenuCount;
                        }
                        else
                        {
                            ps.ItemsCount += agItem.TotalQuantity;
                        }

                        // NEW ASSUMPTION:  No packing sheet should be printed if no cart items exist.
                        if (ps.ItemsCount > 0)
                        {
                            outSlips.Add(ps);
                        }
                    }
                    else
                    {
                        if (agItem.CartItem.ItemType == Enums.CartItemType.DefinedPlan)
                        {
                            hccProductionCalendar pc = hccProductionCalendar.GetBy(agItem.DeliveryDate);
                            hccProgramPlan        pg = hccProgramPlan.GetById(agItem.CartItem.Plan_PlanID.Value);
                            int defMenuCount         = hccProgramDefaultMenu.GetBy(pc.CalendarID, pg.ProgramID)
                                                       .Where(a => a.MenuItemID > 0 && a.DayNumber <= pg.NumDaysPerWeek).Count();

                            existItem.ItemsCount += agItem.TotalQuantity * defMenuCount;
                        }
                        else
                        {
                            existItem.ItemsCount += agItem.TotalQuantity;
                        }
                    }
                }
            }

            return(outSlips.OrderBy(a => a.LastName).ThenBy(a => a.FirstName).ThenBy(a => a.OrderNumber).ToList());
        }