Exemple #1
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;
            }
        }
        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;
            }
        }
        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;
            }
        }