/// <summary> /// Processes a return request given a receipt. /// </summary> /// <param name="receiptID"></param> /// <param name="itemID"></param> /// <param name="itemAmount"></param> public void ProcessReturn(int receiptID, int itemID, int itemAmount) { status = State.Return; if (receiptID > TransactionDB.GetTransactionInt() || receiptID < 0) { throw new Exception(); } Transaction receipt = TransactionDB.GetTransaction(receiptID); for (int i = 0; i < receipt.GetItems.Count; i++) { List <Tuple <Product, int> > temp = receipt.GetItems; if (temp[i].Item1.ID == itemID) { if (itemAmount > temp[i].Item2) { returnval = "Error. Cannot return more items than purchased."; update(returnval, status); return; } else { temp[i] = new Tuple <Product, int>(temp[i].Item1, temp[i].Item2 - itemAmount); returnval = "Success! Items returned."; update(returnval, status); return; } } } returnval = "Error. Item Not Found."; update(returnval, status); }
/// <summary> /// Adds a Transaction to the Rebate DataBase. /// </summary> /// <param name="Date"></param> /// <param name="ID"></param> public void AddToRebateList(DateTime Date, int ID) { status = State.Rebate; if ((ID) <= 0 || (ID--) >= TransactionDB.GetTransactionInt()) { update("Transaction ID does not exist.", status); } else { Transaction temp = TransactionDB.GetTransaction(ID); returnval = RebateDB.AddRebateToList(temp, Date); update(returnval, status); } }
/// <summary> /// Prompts the user for return data. /// Passes a return request to the Return Controller. /// </summary> /// <param name="ID">item ID of the item to be returned</param> /// <param name="returnval">the receipt itself</param> public void ProcessReturn() { try { status = State.Return; int itemNum = 0, itemAmount = 0, receipt_num = 0; bool cont = true; Console.Write("Please enter in your receipt number: "); receipt_num = Convert.ToInt32(Console.ReadLine()); Transaction items = TransactionDB.GetTransaction(receipt_num); Console.WriteLine(items.FormatReceipt() + "\n"); while (cont) { Console.Write("What item number would you like to return?: "); itemNum = Convert.ToInt32(Console.ReadLine()); Console.Write("How many would you like to return?: "); itemAmount = Convert.ToInt32(Console.ReadLine()); Console.Write("Would you like to continue returning more items? (Y/N): "); string answer = Console.ReadLine().ToUpper(); if (answer == "Y") { cont = true; } else if (answer == "N") { cont = false; } else { Console.WriteLine("Invalid input. Start over.\n"); status = State.Default; cont = false; } } return_handler(receipt_num, itemNum, itemAmount); } catch { Console.WriteLine("\nInvalid Entry. Please try again.\n"); } Menu(); }
/// <summary> /// Creates a new transaction. /// </summary> /// <param name="transaction"></param> public void CreateTransaction(List <Tuple <int, int> > transaction) { try { status = State.Transaction; List <Tuple <Product, int> > TrueTransaction = new List <Tuple <Product, int> >(); // error checking foreach (Tuple <int, int> T in transaction) { if (T.Item1 >= ProductDB.GetProductList().Count || T.Item1 <= 0) { throw new Exception("Invalid item ID "); } else if (T.Item2 <= 0) { throw new Exception("Invalid item quantity "); } else { TrueTransaction.Add(new Tuple <Product, int>(ProductDB.GetProduct(T.Item1), T.Item2)); } } if (TrueTransaction.Count == 0) { throw new Exception(); } salesID++; Transaction newTransaction = new Transaction(salesID, TrueTransaction); TransactionDB.AddTransaction(newTransaction); Console.WriteLine("\n" + newTransaction.FormatReceipt()); returnval = "Transaction generated successfully!"; update(returnval, status); } catch (Exception) { returnval = "\nAn error has occurred. Please try again."; } }