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(); }
public static ExpenseOrder ChooseOrder(Database.Database db) { if (db is null) { throw new ArgumentNullException(nameof(db)); } ExpenseOrder[] orders = db.GetOrders().OrderBy(x => x.OrderDate.ToFileTimeUtc()).ToArray(); Console.Clear(); const int numberPerPage = 5; int numberOfPages = orders.Length / numberPerPage; int currentPageIndex = 0; ExpenseOrder retVal = null; while (retVal == null) { if (currentPageIndex < 0) { currentPageIndex = 0; } if (currentPageIndex > numberOfPages) { currentPageIndex = numberOfPages; } Console.Clear(); ExpenseOrder[] currentPage = orders.Skip(currentPageIndex * numberPerPage).Take(numberPerPage).ToArray(); Console.WriteLine($"Displaying {currentPage.Length} of {orders.Length} orders."); for (int i = 0; i < currentPage.Length; i++) { ExpenseOrder order = currentPage[i]; Console.WriteLine($"{i + 1} : Order from {order.OrderDate.ToShortDateString()}"); } string resp = ConsoleUtilities.AskUser("(n)ext page, (p)rev page, (q)uit, or press a number to select an order."); if (resp == "n") { currentPageIndex++; } else if (resp == "p") { currentPageIndex--; } else if (resp == "q") { return(null); } else if (int.TryParse(resp, out int selectedItemIndex) && selectedItemIndex > 0 && selectedItemIndex <= currentPage.Length) { return(currentPage.ToArray()[selectedItemIndex - 1]); } } return(null); }