0% found this document useful (0 votes)
4 views7 pages

Restaurant Management

The document contains a Python implementation of a Restaurant Management System that manages menu items, customer information, and orders. It includes classes for MenuItem, Order, and RestaurantManagement, with methods for loading, saving, updating, and displaying data. The system allows users to interact through a command-line interface for various operations like viewing the menu, placing orders, and managing customer information.

Uploaded by

mirza480455
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Restaurant Management

The document contains a Python implementation of a Restaurant Management System that manages menu items, customer information, and orders. It includes classes for MenuItem, Order, and RestaurantManagement, with methods for loading, saving, updating, and displaying data. The system allows users to interact through a command-line interface for various operations like viewing the menu, placing orders, and managing customer information.

Uploaded by

mirza480455
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Source code

import csv
import os
import datetime
from typing import List, Dict
import uuid

class MenuItem:
def __init__(self, item_id: str, name: str, category: str, price: float, available: bool = True):
self.item_id = item_id
self.name = name
self.category = category
self.price = price
self.available = available

def to_dict(self) -> Dict:


return {
'item_id': self.item_id,
'name': self.name,
'category': self.category,
'price': str(self.price),
'available': str(self.available)
}

class Order:
def __init__(self, order_id: str, customer_name: str, items: List[Dict], status: str =
'Pending'):
self.order_id = order_id
self.customer_name = customer_name
self.items = items
self.status = status
self.order_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

def calculate_total(self) -> float:


return sum(float(item['price']) * item['quantity'] for item in self.items)

def to_dict(self) -> Dict:


return {
'order_id': self.order_id,
'customer_name': self.customer_name,
'items': self.items,
'status': self.status,
'order_date': self.order_date,
'total': str(self.calculate_total())
}

class RestaurantManagement:
def __init__(self):
self.menu_file = 'menu.csv'
self.orders_file = 'orders.csv'
self.customers_file = 'customers.csv'
self.menu = self.load_menu()
self.orders = self.load_orders()
self.customers = self.load_customers()

def load_menu(self) -> List[MenuItem]:


menu = []
if os.path.exists(self.menu_file):
with open(self.menu_file, 'r', newline='') as file:
reader = csv.DictReader(file)
for row in reader:
menu.append(MenuItem(
row['item_id'],
row['name'],
row['category'],
float(row['price']),
row['available'].lower() == 'true'
))
return menu

def save_menu(self):
with open(self.menu_file, 'w', newline='') as file:
fieldnames = ['item_id', 'name', 'category', 'price', 'available']
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
for item in self.menu:
writer.writerow(item.to_dict())

def load_orders(self) -> List[Order]:


orders = []
if os.path.exists(self.orders_file):
with open(self.orders_file, 'r', newline='') as file:
reader = csv.DictReader(file)
for row in reader:
items = eval(row['items']) # Convert string representation back to list
orders.append(Order(
row['order_id'],
row['customer_name'],
items,
row['status']
))
return orders

def save_orders(self):
with open(self.orders_file, 'w', newline='') as file:
fieldnames = ['order_id', 'customer_name', 'items', 'status', 'order_date', 'total']
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
for order in self.orders:
writer.writerow(order.to_dict())

def load_customers(self) -> Dict:


customers = {}
if os.path.exists(self.customers_file):
with open(self.customers_file, 'r', newline='') as file:
reader = csv.DictReader(file)
for row in reader:
customers[row['customer_name']] = {
'phone': row['phone'],
'email': row['email'],
'orders': int(row['orders'])
}
return customers

def save_customers(self):
with open(self.customers_file, 'w', newline='') as file:
fieldnames = ['customer_name', 'phone', 'email', 'orders']
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
for name, info in self.customers.items():
writer.writerow({
'customer_name': name,
'phone': info['phone'],
'email': info['email'],
'orders': info['orders']
})

def add_menu_item(self, name: str, category: str, price: float):


item_id = str(uuid.uuid4())
new_item = MenuItem(item_id, name, category, price)
self.menu.append(new_item)
self.save_menu()
print(f"Added {name} to the menu.")

def update_menu_item(self, item_id: str, name: str = None, category: str = None,
price: float = None, available: bool = None):
for item in self.menu:
if item.item_id == item_id:
if name:
item.name = name
if category:
item.category = category
if price is not None:
item.price = price
if available is not None:
item.available = available
self.save_menu()
print(f"Updated menu item {item.name}")
return
print("Item not found.")

def remove_menu_item(self, item_id: str):


self.menu = [item for item in self.menu if item.item_id != item_id]
self.save_menu()
print("Item removed from menu.")

def place_order(self, customer_name: str, items: List[Dict]):


order_id = str(uuid.uuid4())
new_order = Order(order_id, customer_name, items)
self.orders.append(new_order)

# Update customer records


if customer_name in self.customers:
self.customers[customer_name]['orders'] += 1
else:
self.customers[customer_name] = {
'phone': '',
'email': '',
'orders': 1
}
self.save_orders()
self.save_customers()
print(f"Order placed successfully. ID: {order_id}")

def update_order_status(self, order_id: str, status: str):


for order in self.orders:
if order.order_id == order_id:
order.status = status
self.save_orders()
print(f"Order {order_id} status updated to {status}")
return
print("Order not found.")

def add_customer_info(self, customer_name: str, phone: str, email: str):


self.customers[customer_name] = {
'phone': phone,
'email': email,
'orders': self.customers.get(customer_name, {}).get('orders', 0)
}
self.save_customers()
print(f"Customer {customer_name} information updated.")
def display_menu(self):
print("\n=== Menu ===")
for item in self.menu:
status = "Available" if item.available else "Unavailable"
print(f"ID: {item.item_id} | {item.name} ({item.category}) - ${item.price:.2f} [{status}]")

def display_orders(self):
print("\n=== Orders ===")
for order in self.orders:
print(f"Order ID: {order.order_id}")
print(f"Customer: {order.customer_name}")
print(f"Date: {order.order_date}")
print(f"Status: {order.status}")
print("Items:")
for item in order.items:
print(f" - {item['name']} x{item['quantity']} @ ${item['price']:.2f}")
print(f"Total: ${order.calculate_total():.2f}\n")

def display_customers(self):
print("\n=== Customers ===")
for name, info in self.customers.items():
print(f"Name: {name}")
print(f"Phone: {info['phone']}")
print(f"Email: {info['email']}")
print(f"Total Orders: {info['orders']}\n")

def main():
rm = RestaurantManagement()

while True:
print("\n=== Restaurant Management System ===")
print("1. View Menu")
print("2. Add Menu Item")
print("3. Update Menu Item")
print("4. Remove Menu Item")
print("5. Place Order")
print("6. Update Order Status")
print("7. Add/Update Customer Info")
print("8. View Orders")
print("9. View Customers")
print("10. Exit")

choice = input("Enter your choice (1-10): ")

if choice == '1':
rm.display_menu()
elif choice == '2':
name = input("Enter item name: ")
category = input("Enter category (Appetizer/Main/Dessert/Beverage): ")
price = float(input("Enter price: "))
rm.add_menu_item(name, category, price)

elif choice == '3':


rm.display_menu()
item_id = input("Enter item ID to update: ")
name = input("Enter new name (press Enter to skip): ")
category = input("Enter new category (press Enter to skip): ")
price_input = input("Enter new price (press Enter to skip): ")
available_input = input("Is available? (true/false, press Enter to skip): ")

price = float(price_input) if price_input else None


available = available_input.lower() == 'true' if available_input else None
rm.update_menu_item(item_id, name or None, category or None, price, available)

elif choice == '4':


rm.display_menu()
item_id = input("Enter item ID to remove: ")
rm.remove_menu_item(item_id)

elif choice == '5':


rm.display_menu()
customer_name = input("Enter customer name: ")
items = []
while True:
item_id = input("Enter item ID (or 'done' to finish): ")
if item_id.lower() == 'done':
break
quantity = int(input("Enter quantity: "))
for menu_item in rm.menu:
if menu_item.item_id == item_id and menu_item.available:
items.append({
'name': menu_item.name,
'price': menu_item.price,
'quantity': quantity
})
break
else:
print("Item not found or unavailable.")
if items:
rm.place_order(customer_name, items)

elif choice == '6':


rm.display_orders()
order_id = input("Enter order ID to update: ")
status = input("Enter new status (Pending/Preparing/Completed/Cancelled): ")
rm.update_order_status(order_id, status)

elif choice == '7':


customer_name = input("Enter customer name: ")
phone = input("Enter phone number: ")
email = input("Enter email: ")
rm.add_customer_info(customer_name, phone, email)

elif choice == '8':


rm.display_orders()

elif choice == '9':


rm.display_customers()

elif choice == '10':


print("Thank you for using the Restaurant Management System!")
break

else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
main()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy