Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
7.5 kB
0
Indexable
Never
# Customer Menu - Additional Options
def customer_menu_additional_options(customer_name):
    while True:
        print("\nAdditional Options:")
        y = int(input('''
1. Modify Order
2. Back to Customer Menu
'''))
        if y == 1:
            customer_modify_order(customer_name)
        elif y == 2:
            break
        else:
            print('Please enter a valid input. ')

# Admin - Display Customer Orders Admin
def admin_display_customer_orders_admin():
    try:
        cur.execute("SELECT Customer_Orders_Admin.OrderID, Menu.ItemName, "
                    "Customer_Orders_Admin.OrderDate, Customer_Orders_Admin.Quantity, "
                    "Customer_Orders_Admin.Packaging, Customer_Orders_Admin.Status "
                    "FROM Customer_Orders_Admin JOIN Menu ON Customer_Orders_Admin.ItemID = Menu.ItemID")
        orders = cur.fetchall()
        table = PrettyTable(["Order ID", "Item Name", "Order Date", "Quantity", "Packaging", "Status"])
        for order in orders:
            table.add_row(order)
        print(table)

    except mysql.connector.Error as err:
        print(f"Error: {err}")
        con.rollback()

# Admin - Modify Customer Orders Admin
def admin_modify_customer_orders_admin():
    try:
        admin_display_customer_orders_admin()
        order_id = int(input("Enter Order ID to modify: "))
        cur.execute("SELECT OrderID FROM Customer_Orders_Admin")
        data = cur.fetchall()

        if (order_id,) in data:
            new_quantity = int(input("Enter the new quantity: "))
            new_packaging = input("Enter 'Dine-in' or 'Take away': ").capitalize()
            cur.execute("UPDATE Customer_Orders_Admin SET Quantity = %s, Packaging = %s WHERE OrderID = %s",
                        (new_quantity, new_packaging, order_id))
            con.commit()
            print(f"Order ID {order_id} modified successfully!")
        else:
            print('Sorry, this order does not exist.')

    except (mysql.connector.Error, ValueError) as err:
        print(f"Error: {err}")
        con.rollback()

# Admin - Change Status of Customer Orders Admin
def admin_change_status_customer_orders_admin():
    try:
        admin_display_customer_orders_admin()
        order_id = int(input("Enter Order ID to change status: "))
        cur.execute("SELECT OrderID FROM Customer_Orders_Admin")
        data = cur.fetchall()

        if (order_id,) in data:
            new_status = input("Enter 'Pending' or 'Delivered': ").capitalize()
            cur.execute("UPDATE Customer_Orders_Admin SET Status = %s WHERE OrderID = %s",
                        (new_status, order_id))
            con.commit()
            print(f"Status of Order ID {order_id} changed to {new_status} successfully!")
        else:
            print('Sorry, this order does not exist.')

    except (mysql.connector.Error, ValueError) as err:
        print(f"Error: {err}")
        con.rollback()

# Admin - Change Order Status
def admin_change_order_status():
    try:
        admin_view_orders_with_status()  
        order_id = int(input("Enter Order ID to change status: "))
        cur.execute("SELECT OrderID FROM Orders")
        data = cur.fetchall()

        if (order_id,) in data:
            new_status = input("Enter 'Pending' or 'Delivered': ").capitalize()
            cur.execute("UPDATE Orders SET Status = %s WHERE OrderID = %s", (new_status, order_id))
            con.commit()
            print(f"Order ID {order_id} status changed successfully!")
        else:
            print('Sorry, this order does not exist.')

    except (mysql.connector.Error, ValueError) as err:
        print(f"Error: {err}")
        con.rollback()

# Customer - Place Order with Packaging Option
def customer_place_order_with_packaging(customer_name):
    try:
        display_menu()
        item_id = int(input("\nEnter the Item ID to order: "))
        quantity = int(input("Enter the quantity: "))
        packaging = input("Enter 'Dine-in' or 'Take away': ").capitalize()
        order_date = time.strftime('%Y-%m-%d')

        cur.execute('SELECT ItemID FROM Menu')
        data = cur.fetchall()

        if (item_id,) in data:
            cur.execute("INSERT INTO Orders (ItemID, CustomerName, OrderDate, Quantity, Packaging) "
                        "VALUES (%s, %s, %s, %s, %s)",
                        (item_id, customer_name, order_date, quantity, packaging))
            print(f"\nOrder placed successfully for {customer_name}!")
            con.commit()
        else:
            print('Item not found.')

    except (mysql.connector.Error, ValueError) as err:
        print(f"Error: {err}")
        con.rollback()

# Admin Menu
def admin_menu():
    while True:
        print("\n\t\t\t\tAdmin Menu")
        choice = int(input('''
1. View Orders with Status
2. Change Order Status
3. Total Revenue with Status
4. Statistics with Quantity
5. Create Customer_Orders_Admin Table
6. Exit
'''))

        if choice == 1:
            admin_view_orders_with_status()
        elif choice == 2:
            admin_change_order_status()
        elif choice == 3:
            admin_total_revenue_with_status()
        elif choice == 4:
            admin_statistics_with_quantity()
        elif choice == 5:
            admin_customer_order_admin_table()
        elif choice == 6:
            break
        else:
            print('Please enter a valid input.')

# Customer Menu - Modify Food Order
def customer_menu_modify_food_order(customer_name):
    while True:
        print("\n\t\t\t\tCustomer Menu")
        print("1. View Menu")
        print("2. Place Order")
        print("3. View Orders")
        print("4. Modify Food Order")
        print("5. Logout")

        choice = int(input("Enter your choice (1-5): "))
        if choice == 1:
            display_menu()
        elif choice == 2:
            customer_place_order_with_packaging(customer_name)
        elif choice == 3:
            display_customer_orders(customer_name)
        elif choice == 4:
            customer_modify_food_order(customer_name)
        elif choice == 5:
            break
        else:
            print("Invalid input! Please choose a valid option.")

# Main Function
def main():
    while True:
        print("𝒲𝐸𝐿𝒞𝒪𝑀𝐸 𝒯𝒪 𝒳𝒴𝒵 𝑅𝐸𝒮𝒯𝒜𝒰𝑅𝒜𝒩𝒯")
        print("1. Login as Admin")
        print("2. Login as Customer")
        print("3. Exit\n")

        user_type = input("Enter your choice (1-3): ")

        if user_type == '1':
            admin_menu()
        elif user_type == '2':
            print("1. Login")
            print("2. Sign Up")
            login_choice = input("Enter your choice (1-2): ")

            if login_choice == '1':
                customer_name = input("Enter your name: ")
                customer_log_in()
                customer_menu_modify_food_order(customer_name)
            elif login_choice == '2':
                customer_sign_up()
            else:
                print("Invalid input! Please choose a valid option.")
        elif user_type == '3':
            print("Thank you for using the Restaurant Management System!")
            break
        else:
            print("Invalid input! Please choose a valid option.")

main()
# designed by teja sai 12A
Leave a Comment