Esempio n. 1
0
        internal static void OrderablePrompt(Database.Database db)
        {
            OrderableItem[] currentOrders    = db.GetOrderables();
            bool            isOrderableValid = true;

            int AskValidWic()
            {
                var newWic = AskUserNumber("Wic");

                if (currentOrders.Any(x => x.Wic == newWic))
                {
                    Console.WriteLine("Wic is not unique!");
                    isOrderableValid = false;
                }
                return(newWic);
            }

            OrderableItem item = new OrderableItem(
                AskValidWic(),
                AskUser("Item Name"),
                AskUserNumber("Package Size"),
                AskUserBool("Two Week Cycle"));

            if (!isOrderableValid)
            {
                Console.WriteLine("Unable to save. Item is invalid!");
            }
            db.SaveNewOrderableItem(item);
        }
Esempio n. 2
0
        internal static void CreateNotReceiptReport(Database.Database db, DateTime reportAsOf)
        {
            if (db is null)
            {
                throw new ArgumentNullException(nameof(db));
            }

            Report rpt = new Report("PendingReceipt");

            ExpenseOrder[] allorders  = db.GetOrders();
            var            orderables = db.GetOrderables();
            // Get list of orders that have at least one item that has not been received
            //var orders = allorders.Where(currentOrder => currentOrder.orderedItems.Any(currentOrderedItem => currentOrderedItem.Value.HasBeenReceived())).ToArray();
            var orders = allorders.Where(currentOrder => currentOrder.orderedItems.Any(currentOrderedItem => currentOrderedItem.Value.HasBeenReceived()));
            int totalNumberOfMissingItems = 0;

            orders.ToList().ForEach(x => x.orderedItems.ToList().ForEach(y =>
            {
                if (!y.Value.HasBeenReceived())
                {
                    totalNumberOfMissingItems++;
                }
            }));

            rpt.AddHeader("Introduction");
            rpt.AddBlank();
            rpt.AddLine($"This file describes the pending status of pharmacy expense items.  This file is accurate as of {reportAsOf.ToShortDateString()}.  There are {orders.Count(x=>x.orderedItems.Any(x=>!x.Value.HasBeenReceived()))} orders with pending items.  There are {totalNumberOfMissingItems} items that are pending.  These items are critical to the operation of the pharmacy.");
            rpt.AddBlank();
            rpt.AddHeader("Orders with Pending Items");
            rpt.AddLine("The following orders have pending items.");
            List <string> data = new List <string>();

            orders.ToList().ForEach(x =>
            {
                data.Add(x.OrderDate.ToShortDateString());
                data.Add(x.orderedItems.Count(y => !y.Value.HasBeenReceived()).ToString());
            });
            rpt.AddBlank();
            rpt.AddTable(new string[] { "Order Date", "Number of Pending Items" }, data.ToArray());
            rpt.AddBlank();
            rpt.AddHeader("Number of Pending Items per Wic");
            rpt.AddLine("The following are the number of items for each wic that are pending");
            rpt.AddBlank();
            data = new List <string>();
            Dictionary <int, int> wicToPendingItemCountMap = new Dictionary <int, int>();

            orders.ToList().ForEach(currentOrder => currentOrder.orderedItems.ToList().ForEach(currentItem =>
            {
                if (!currentItem.Value.HasBeenReceived())
                {
                    if (wicToPendingItemCountMap.ContainsKey(currentItem.Key.Wic))
                    {
                        wicToPendingItemCountMap[currentItem.Key.Wic] += currentItem.Value.orderedAmount;
                    }
                    else
                    {
                        wicToPendingItemCountMap.Add(currentItem.Key.Wic, currentItem.Value.orderedAmount);
                    }
                }
            }));
            foreach (KeyValuePair <int, int> item in wicToPendingItemCountMap)
            {
                Console.Write($"{item.Key}, {orderables.First(x=>x.Wic == item.Key).ItemName}, {item.Value}");
            }
            rpt.AddTable(new string[] { "Wic", "Item Name", "Number of Pending Items" }, data.ToArray());
            rpt.SaveReport();
        }
Esempio n. 3
0
        internal static void OrderPrompt(Database.Database db)
        {
            OrderableItem[] orderableItems = db.GetOrderables();
            ExpenseOrder    order          = new ExpenseOrder
            {
                OrderDate = new DateTime(
                    AskUserNumber("Year"),
                    AskUserNumber("Month"),
                    AskUserNumber("Day")),
            };
            int daysUntilThursday = ((int)DayOfWeek.Thursday - (int)order.OrderDate.DayOfWeek + 7) % 7;

            order.ExpectedDateOneCycle = order.OrderDate.AddDays(daysUntilThursday);
            order.ExpectedDateTwoCycle = order.ExpectedDateOneCycle.AddDays(7);

            order.orderedItems = new Dictionary <OrderableItem, OrderedItemInfo>();
            while (true)
            {
                DisplayOrderPreorder(order);
                Console.WriteLine("Add item by (w)ic, or search by (n)ame.");
                Console.WriteLine("(s)uggested Order");
                Console.WriteLine("(f)inish order");
                var resp = AskUser("");
                if (resp == "w")
                {
                    var wic = AskUserNumber("Wic");
                    if (orderableItems.Any((x) => x.Wic == wic))
                    {
                        if (order.orderedItems.ContainsKey(orderableItems.First((x) => x.Wic == wic)))
                        {
                            Console.WriteLine("That item is already in the order.");
                            OrderedItemInfo oldItem = order.orderedItems.First((x) => x.Key.Wic == wic).Value;
                            oldItem.onHand        = AskUserNumber($"Modify on hand amount ({oldItem.onHand})");
                            oldItem.orderedAmount = AskUserNumber($"Modify ordered amount ({oldItem.orderedAmount})");
                        }
                        else
                        {
                            order.orderedItems.Add(orderableItems.First((x) => x.Wic == wic), new Database.OrderedItemInfo(AskUserNumber("On hand amount"), AskUserNumber("Ordered Amount")));
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid Wic");
                        if (AskUserBool("Add new item?"))
                        {
                            OrderablePrompt(db);
                            orderableItems = db.GetOrderables();
                        }
                    }
                }
                else if (resp == "f")
                {
                    break;
                }
                else if (resp == "s")
                {
                    foreach (KeyValuePair <int, int> k in new Dictionary <int, int>()
                    {
                        { 957754, 3 },
                        { 828188, 4 },
                        { 829838, 4 },
                        { 829839, 1 },
                        { 829841, 1 },
                        { 962843, 8 },
                        { 958293, 5 },
                        { 964586, 2 },
                        { 958292, 1 },
                        { 964588, 1 },
                        { 475071, 1 },
                        { 475070, 1 },
                        { 475069, 1 },
                        { 475068, 1 },
                        { 475067, 1 },
                        { 475066, 1 },
                        { 475065, 1 },
                        { 959737, 1 },
                        { 958843, 1 },
                        { 345150, 3 },
                        { 963233, 4 },
                        { 216735, 1 },
                        { 219561, 1 },
                        { 225610, 3 },
                        { 964880, 3 },
                        { 961510, 3 },
                        { 274002, 1 },
                        { 151913, 1 },
                        { 957507, 1 },
                    }
                             .Where(k => orderableItems.Any((x) => x.Wic == k.Key)))
                    {
                        OrderableItem item = orderableItems.First((x) => x.Wic == k.Key);
                        Console.WriteLine($"{item.Wic} : {item.ItemName}");
                        int onHand    = AskUserNumber("On Hand");
                        int orderThis = onHand < k.Value ? k.Value - onHand : 0;
                        Console.WriteLine("Suggested on hand value should be " + k.Value);
                        if (orderThis != 0)
                        {
                            if (!AskUserBool("Order this amount? (" + orderThis + ")"))
                            {
                                order.orderedItems.Add(item, new OrderedItemInfo(onHand, AskUserNumber("Quantity")));
                            }
                            else
                            {
                                order.orderedItems.Add(item, new OrderedItemInfo(onHand, orderThis));
                            }
                        }
                        else if (AskUserBool("Current amount is sufficient. Order more?"))
                        {
                            order.orderedItems.Add(item, new OrderedItemInfo(onHand, AskUserNumber("Quantity")));
                        }
                        else
                        {
                            order.orderedItems.Add(item, new OrderedItemInfo(onHand, 0));
                        }
                    }
                }
            }
            db.SaveNewOrder(order);
        }
Esempio n. 4
0
        public static void DisplayOrderables(Database.Database db)
        {
            OrderableItem[] orderables = db.GetOrderables().OrderBy((x) => x.Wic).ToArray();

            const int numberPerPage    = 5;
            int       numberOfPages    = orderables.Length / numberPerPage;
            int       currentPageIndex = 0;

            while (true)
            {
                if (currentPageIndex < 0)
                {
                    currentPageIndex = 0;
                }

                if (currentPageIndex > numberOfPages)
                {
                    currentPageIndex = numberOfPages;
                }

                Console.Clear();
                OrderableItem[] currentPage = orderables.Skip(currentPageIndex * numberPerPage).Take(numberPerPage).ToArray();
                Console.WriteLine($"Displaying {currentPage.Length} of {orderables.Length} items. Page {currentPageIndex + 1} / {numberOfPages + 1 }.");
                Console.WriteLine();
                Console.WriteLine($"|Index|Wic   |Name             |Cycle|");

                for (int i = 0; i < currentPage.Length; i++)
                {
                    OrderableItem k = currentPage[i];
                    Console.WriteLine($"|{i + 1,5:d2}|{k.Wic,6:d6}|{k.ItemName,-17}|{(k.twoWeekCycle ? 2 : 1),5:d2}|");
                }
                string resp = AskUser("(n)ext page, (p)rev page, (q)uit, or press a number to edit.");

                if (resp == "n")
                {
                    currentPageIndex++;
                }
                else if (resp == "p")
                {
                    currentPageIndex--;
                }
                else if (resp == "q")
                {
                    return;
                }
                else if (int.TryParse(resp, out int selectedItemIndex) &&
                         selectedItemIndex > 0 &&
                         selectedItemIndex <= currentPage.Length)
                {
                    OrderableItem selectedItem = currentPage.ToArray()[selectedItemIndex - 1];
                    int           oldWic       = selectedItem.Wic;
                    while (true)
                    {
                        resp = AskUser("(d)elete, (c)hange wic, change (n)ame, change c(y)cle, (f)inish)");

                        switch (resp)
                        {
                        case "d":
                            selectedItem = null;
                            goto finishEdit;

                        case "c":
                            selectedItem.Wic = int.Parse(new string(AskUserNumber("New wic?").ToString().ToArray().Take(6).ToArray()));
                            goto finishEdit;

                        case "n":
                            selectedItem.ItemName = AskUser("New name?");
                            goto finishEdit;

                        case "y":
                            selectedItem.twoWeekCycle = !selectedItem.twoWeekCycle;
                            goto finishEdit;

                        case "f":
                            goto finishEdit;

                        default:
                            Console.WriteLine("Invalid command");
                            break;
                        }
                    }
finishEdit:
                    IEnumerable <OrderableItem> newOrderables;
                    newOrderables = selectedItem == null
                        ? orderables.Where((x) => x.Wic != oldWic)
                        : orderables.Where((x) => x.Wic != oldWic).Append(selectedItem);

                    db.OverwriteOrderableItems(newOrderables.ToArray());
                    orderables    = db.GetOrderables().OrderBy((x) => x.Wic).ToArray();
                    numberOfPages = orderables.Length / numberPerPage;
                }
            }
        }