def search(code): if code is False: extraction = prompt.ff("Manufacturers -> Search", "Name", manufacturerDB.extract_from_db_by_name)[0] else: extraction = prompt.ff("Manufacturers -> Search", "Code", manufacturerDB.extract_from_db_by_code)[0] sep() extraction.print_data() sep()
def new(): sep() while True: print("Input manufacturer name") name = input("Name: ") copy = manufacturerDB.get_code_from_name(name) if copy is None: break else: sep() print(name + " is being used by another manufacturer (code: " + copy + ")") sep() while True: print("Input 5-digit code") code = input("Code: ") if code.isdigit() and len(code) == 5: copy = manufacturerDB.get_name_from_code(code) if copy is None: break else: sep() print(copy + " is already using the code " + code) else: sep() print(code + " is an invalid 5-digit code") rules = [] sep() while True: n = prompt.mc( "Would you like to add product code rules to this manufacturer?", options, "Yes", "No", "Cancel manufacturer")[1] if n == 1: my_rule = input("Rule " + str(len(rules) + 1) + ": ") rules.append(my_rule) sep() print("Current rules: ") for rule in rules: print("- " + rule) sep() elif n == 2: break elif n == 3: sep() return else: sep() print("Invalid input") sep() manufacturerDB.add_to_db(Manufacturer(name, code, rules)) print(name + " successfully added to the manufacturer database.") sep()
def new(): sep() try: extraction = prompt.ff( "Input the transaction ID for which to process a refund", "Transaction ID", transactionDB.extract_from_db) except ValueError: sep() print("Invalid ID. Returning to menu.") sep() return t_id = extraction[1] transaction = extraction[0] refund = Refund(t_id) print("The following items are associated with the transaction ID " + t_id + ":") transaction.print_cart() while True: if len(refund.items) > 0: print("Items to be refunded: ") refund.print_items() if prompt.ff( "Scan item to be returned, or press enter for more options", "Barcode", refund.add_to_items, transaction.cart) is None: sep() n = prompt.mc("Options", options, "Continue", "Return all items", "Add items", "Remove items", "Cancel transaction")[1] if n == 1: if len(refund.items) > 0: break else: print("Error: No items in refund list") elif n == 2: refund.add_all_to_items(transaction.cart) break elif n == 3: continue elif n == 4: if len(refund.items) > 0: refund.print_items() prompt.mc("Select item to remove", refund.remove_from_items) else: print("Error: No items in refund list.") elif n == 5: sep() return sep() refund.reason = prompt.ff("What is the reason for returning these items?", "Reason", options)[1] sep() refundDB.add_to_db(refund) print("Refund successfully processed.") sep()
def main(): sep() user_input = prompt.navigate_menu("Main Menu", "Transactions", "Refunds", "Items", "Manufacturers") sep() if user_input == 1: user_input = prompt.navigate_menu("Transactions", "New", "Search") sep() if user_input == 0: return elif user_input == 1: transaction_new() return elif user_input == 2: transaction_search() return elif user_input == 2: user_input = prompt.navigate_menu("Refunds", "New", "Search") sep() if user_input == 0: return elif user_input == 1: refund_new() return elif user_input == 2: refund_search() return elif user_input == 3: user_input = prompt.navigate_menu("Items", "New", "Search") sep() if user_input == 0: return elif user_input == 1: item_new() return elif user_input == 2: item_search() return elif user_input == 4: user_input = prompt.navigate_menu("Manufacturers", "New", "Search") sep() if user_input == 0: return elif user_input == 1: manufacturer_new() return elif user_input == 2: user_input = prompt.navigate_menu("Search Manufacturers", "By Name", "By Code") if user_input == 0: return elif user_input == 1: manufacturer_search(False) elif user_input == 2: manufacturer_search(True) return
def search(): extraction = prompt.ff("Refunds -> Search", "ID", refundDB.extract_from_db) sep() extraction.print_data() sep()
def new(): sep() name = input("Input the name of this item: ") while True: sep() n = prompt.mc("Assign a manufacturer to the item", options, "Input by name", "Input by code", "Cancel item")[1] sep() if n == 1: m_info = prompt.ff("Manufacturer by name", "Name", manufacturerDB.get_code_from_name) if m_info[0] is None: sep() print("Manufacturer does not exists.") continue else: m_code = m_info[0] m_name = m_info[1] break elif n == 2: m_info = prompt.ff("Manufacturer by code", "Code", manufacturerDB.get_name_from_code) if m_info[0] is None: sep() print("Manufacturer does not exists.") continue else: m_name = m_info[0] m_code = m_info[1] break elif n == 3: return while True: sep() n = prompt.mc("Input the price of the item", options, "Input price", "Skip", "Cancel item")[1] sep() if n == 1: try: price = input("Price: ") if price == "": continue else: price = float(price) break except ValueError: print("Invalid input.") continue elif n == 2: price = float(0.00) break elif n == 3: return while True: sep() n = prompt.mc("Determine the rewards benefits of the item", options, "No discount", "Input percent discount", "Input modified price", "Cancel item")[1] sep() if n == 1: multiplier = float(1.00) break elif n == 2: try: percent = input("Percent off: ") multiplier = (100 - float(percent)) * 0.01 break except ValueError: print("Invalid input.") continue elif n == 3: try: modified_price = float(input("Modified price: ")) multiplier = modified_price / price break except ValueError: print("Invalid input.") continue elif n == 4: return while True: sep() n = prompt.mc("Input the quantity of the item", options, "Input quantity", "Skip", "Cancel item")[1] if n == 1: try: quantity = int(input("Quantity: ")) break except ValueError: print("Invalid input.") continue elif n == 2: quantity = 0 break elif n == 3: return item = Item(m_name, name, price, multiplier, quantity) while True: i = 0 sep() n = prompt.mc("Input the 5-digit code for this product", options, "Input code", "Auto-select", "Cancel item")[1] sep() if n == 1: p_code = input("Code: ") if p_code.isdigit() and len(p_code) == 5: try: item.build_barcode('0', m_code, p_code) break except ValueError: print( "An identical barcode already exists in the database.") else: print("Invalid input.") continue elif n == 2: while True: i += 1 p_code = str(i) while len(p_code) < 5: p_code = '0' + p_code try: item.build_barcode('0', m_code, p_code) break except ValueError: continue break elif n == 3: return itemDB.add_to_db(item) sep() print(name + " successfully added to the item database.") print("Barcode given: " + item.barcode) sep()
def search(): sep() extraction = prompt.ff("Items -> Search", "Barcode", itemDB.extract_from_db) if extraction is not None: item = Item(extraction[0][0], extraction[0][1], extraction[0][2], extraction[0][3], extraction[0][4], extraction[0][5]) barcode = extraction[1] while True: sep() item.print_data() sep() try: n = prompt.mc("Edit item values?", options, "Return to main menu", "Quantity", "Price", "Discount")[1] sep() if n == 1: sep() return elif n == 2: try: n = prompt.mc("Edit item quantity options", options, "Return to main menu", "Set total", "Add to total", "Subtract from total")[1] except TypeError: sep() print("Not a valid price. Returning to main menu.") sep() return except ValueError: sep() print("Not a valid price. Returning to main menu.") sep() return sep() if n == 1: return elif n == 2: try: ans = prompt.ff( "Set total number of " + item.product + " in stock", "Total", options)[1] except TypeError: sep() print("Not a valid price. Returning to main menu.") sep() return except ValueError: sep() print("Not a valid price. Returning to main menu.") sep() return sep() if ans is None: sep() print("Operation cancelled.") else: try: item.quantity = int(ans) itemDB.set_quantity(barcode, item.quantity) print("Quantity successfully adjusted.") except ValueError: sep() print("Invalid input.") continue elif n == 3: try: ans = prompt.ff( "Adding to current value of " + str(item.quantity), "Value", options)[1] except TypeError: sep() print("Not a valid price. Returning to main menu.") sep() return except ValueError: sep() print("Not a valid price. Returning to main menu.") sep() return sep() if ans is None: sep() print("Operation cancelled.") else: try: item.quantity = item.quantity + int(ans) itemDB.add_quantity(barcode, item.quantity) print("Quantity successfully adjusted.") except ValueError: sep() print("Invalid input.") continue elif n == 4: try: ans = prompt.ff( "Subtracting from current value of " + str(item.quantity), "Value", options)[1] except TypeError: sep() print("Not a valid price. Returning to main menu.") sep() return except ValueError: sep() print("Not a valid price. Returning to main menu.") sep() return sep() if ans is None: sep() print("Operation cancelled.") else: try: item.quantity = item.quantity - int(ans) itemDB.subtract_quantity(barcode, int(ans)) print("Quantity successfully adjusted.") except ValueError: sep() print("Invalid input.") elif n == 3: try: n = prompt.ff( "Edit item price (current: " + str(item.price) + ")", "Price", options)[1] n = float(n) item.price = n itemDB.set_price(barcode, item.price) sep() print("Price successfully adjusted.") except TypeError: sep() print("Not a valid price. Returning to main menu.") sep() return except ValueError: sep() print("Not a valid price. Returning to main menu.") sep() return elif n == 4: try: n = prompt.mc("Edit item discount options", options, "Return to main menu", "Set percent off", "set multiplier")[1] sep() if n == 1: return elif n == 2: try: ans = prompt.ff("Set percent off", "Percent", options)[1] except ValueError or TypeError: sep() print("Returning to main menu.") sep() return sep() if ans is None: sep() print("Operation cancelled.") else: try: item.multiplier = 100.00 - float(ans) itemDB.set_quantity( barcode, item.multiplier) print("Percent off successfully adjusted.") except ValueError: sep() print("Invalid input.") elif n == 3: try: ans = prompt.ff("Set multiplier", "Multiplier", options)[1] except ValueError or TypeError: sep() print("Returning to main menu.") sep() return sep() if ans is None: sep() print("Operation cancelled.") else: try: item.multiplier = float(ans) itemDB.set_quantity( barcode, item.multiplier) print("Multiplier successfully adjusted.") except ValueError: sep() print("Invalid input.") except ValueError: sep() print("Returning to main menu.") sep() return continue except ValueError: sep() print("Invalid input. Returning to main menu.") sep() return else: sep() print("Item not found in database.") sep()
def search(): extraction = prompt.ff("Transaction -> Search", "ID", transactionDB.extract_from_db) sep() extraction[0].print_data(extraction[1]) sep()
def new(): _transaction = Transaction() while True: while True: if prompt.ff("Scan items, or press enter to continue", "Barcode", _transaction.add_to_cart) is None: sep() n = prompt.mc("Options", options, "Continue", "Add items", "Remove items", "Cancel transaction")[1] sep() if n == 1: if len(_transaction.cart) > 0: break else: print("Error: No items in cart") elif n == 2: continue elif n == 3: if len(_transaction.cart) > 0: _transaction.print_cart() prompt.mc("Select item to remove", _transaction.remove_from_cart) else: print("Error: No items in cart") elif n == 4: return else: print("Invalid input.") sep() print("Items scanned so far:") for _item in _transaction.cart: print(_item) while True: if prompt.mc("Select payment type", _transaction.set_payment_method, "cash", "credit", "debit") \ is None: n = prompt.mc("Options", options, "Select payment type", "Edit cart", "Cancel transaction")[1] if n == 1: continue elif n == 2: break elif n == 3: return break if n == 2: continue while True: if _transaction.payment_method != "cash": sep() if prompt.ff( _transaction.payment_method[0].upper() + _transaction.payment_method[1:] + " selected", "Card Number", _transaction.set_card_number) is None: n = prompt.mc("Options", options, "Input card number", "Edit cart", "Cancel transaction")[1] if n == 1: continue elif n == 2: break elif n == 3: return break break if n == 2: continue sep() transactionDB.add_to_db(_transaction) print("Transaction added") # THIS IS WHERE THE RECEIPT IS PRINTED AND TRANSACTION ADDED TO DB, if you can get here. break sep()