cs project
cs project
connector
from datetime import datetime
cursor.execute("""
CREATE TABLE IF NOT EXISTS guests (
guest_id INT AUTO_INCREMENT PRIMARY KEY,
guest_name VARCHAR(50) NOT NULL,
contact_no BIGINT NOT NULL,
email VARCHAR(100),
address TEXT
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS bookings (
booking_id INT AUTO_INCREMENT PRIMARY KEY,
guest_id INT,
room_id INT,
check_in DATE,
check_out DATE,
total_cost INT DEFAULT 0,
booking_status VARCHAR(20) DEFAULT 'Active',
FOREIGN KEY (guest_id) REFERENCES guests(guest_id),
FOREIGN KEY (room_id) REFERENCES rooms(room_id)
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS food_items (
food_id INT AUTO_INCREMENT PRIMARY KEY,
food_name VARCHAR(50) NOT NULL,
price INT NOT NULL,
food_description TEXT
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS room_service (
service_id INT AUTO_INCREMENT PRIMARY KEY,
booking_id INT,
food_id INT,
quantity INT NOT NULL,
total_price INT NOT NULL,
service_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (booking_id) REFERENCES bookings(booking_id),
FOREIGN KEY (food_id) REFERENCES food_items(food_id)
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS bills (
bill_id INT AUTO_INCREMENT PRIMARY KEY,
booking_id INT,
total_room_cost INT,
total_food_cost INT,
grand_total INT,
payment_status VARCHAR(20) DEFAULT 'Pending',
payment_method VARCHAR(20),
FOREIGN KEY (booking_id) REFERENCES bookings(booking_id)
)
""")
db.commit()
# Function Definitions
def add_guest():
name = input("Enter guest name: ")
contact = input("Enter contact number: ")
email = input("Enter email address (optional): ")
address = input("Enter address (optional): ")
cursor.execute("INSERT INTO guests (guest_name, contact_no, email, address) VALUES
(%s, %s, %s, %s)",
(name, contact, email, address))
db.commit()
print("Guest added successfully.")
def add_room():
room_type = input("Enter room type (e.g., Single, Double, Suite): ")
price = int(input("Enter price per night: "))
description = input("Enter room description (optional): ")
cursor.execute("INSERT INTO rooms (room_type, price_per_night, room_description)
VALUES (%s, %s, %s)",
(room_type, price, description))
db.commit()
print("Room added successfully.")
def book_room():
guest_id = int(input("Enter guest ID: "))
room_id = int(input("Enter room ID: "))
check_in = input("Enter check-in date (YYYY-MM-DD): ")
check_out = input("Enter check-out date (YYYY-MM-DD): ")
price = room_info[1]
total_days = (datetime.strptime(check_out, "%Y-%m-%d") - datetime.strptime(check_in,
"%Y-%m-%d")).days
total_cost = total_days * price
cursor.execute("INSERT INTO bookings (guest_id, room_id, check_in, check_out,
total_cost) VALUES (%s, %s, %s, %s, %s)",
(guest_id, room_id, check_in, check_out, total_cost))
cursor.execute("UPDATE rooms SET status = 'Booked' WHERE room_id = %s", (room_id,))
db.commit()
print("Room booked successfully with a total cost of:", total_cost)
def add_food_item():
food_name = input("Enter food item name: ")
price = int(input("Enter price: "))
description = input("Enter food description (optional): ")
cursor.execute("INSERT INTO food_items (food_name, price, food_description) VALUES
(%s, %s, %s)",
(food_name, price, description))
db.commit()
print("Food item added successfully.")
def room_service():
booking_id = int(input("Enter booking ID: "))
food_id = int(input("Enter food ID: "))
quantity = int(input("Enter quantity: "))
cursor.execute("SELECT price FROM food_items WHERE food_id = %s", (food_id,))
food_price = cursor.fetchone()[0]
total_price = food_price * quantity
cursor.execute("INSERT INTO room_service (booking_id, food_id, quantity, total_price)
VALUES (%s, %s, %s, %s)",
(booking_id, food_id, quantity, total_price))
db.commit()
print("Room service added successfully with a total cost of:", total_price)
def check_out():
booking_id = int(input("Enter booking ID for check-out: "))
cursor.execute("SELECT total_cost FROM bookings WHERE booking_id = %s",
(booking_id,))
room_cost = cursor.fetchone()[0]
cursor.execute("""
SELECT SUM(f.price * s.quantity) FROM room_service s
JOIN food_items f ON s.food_id = f.food_id
WHERE s.booking_id = %s
""", (booking_id,))
food_cost = cursor.fetchone()[0] or 0
grand_total = room_cost + food_cost
def view_rooms():
cursor.execute("SELECT * FROM rooms")
for room in cursor.fetchall():
print("Room ID:", room[0], "| Type:", room[1], "| Price per Night:", room[2], "| Status:",
room[3], "| Description:", room[4])
def view_guests():
cursor.execute("SELECT * FROM guests")
for guest in cursor.fetchall():
print("Guest ID:", guest[0], "| Name:", guest[1], "| Contact:", guest[2], "| Email:",
guest[3], "| Address:", guest[4])
def view_bookings():
cursor.execute("""
SELECT b.booking_id, g.guest_name, r.room_type, b.check_in, b.check_out, b.total_cost,
b.booking_status
FROM bookings b
JOIN guests g ON b.guest_id = g.guest_id
JOIN rooms r ON b.room_id = r.room_id
""")
for booking in cursor.fetchall():
print("Booking ID:", booking[0], "| Guest Name:", booking[1], "| Room Type:",
booking[2],
"| Check-in:", booking[3], "| Check-out:", booking[4], "| Total Cost:", booking[5], "|
Status:", booking[6])
def view_bills():
cursor.execute("""
SELECT bl.bill_id, g.guest_name, r.room_type, bl.total_room_cost, bl.total_food_cost,
bl.grand_total, bl.payment_status
FROM bills bl
JOIN bookings b ON bl.booking_id = b.booking_id
JOIN guests g ON b.guest_id = g.guest_id
JOIN rooms r ON b.room_id = r.room_id
""")
for bill in cursor.fetchall():
print("Bill ID:", bill[0], "| Guest Name:", bill[1], "| Room Type:", bill[2],
"| Room Cost:", bill[3], "| Food Cost:", bill[4], "| Grand Total:", bill[5], "| Payment
Status:", bill[6])
# Main Menu
def main_menu():
while True:
print("\n***** LODGE MANAGEMENT SYSTEM *****")
print("1. Add Guest")
print("2. Add Room")
print("3. Book Room")
print("4. Add Food Item")
print("5. Room Service")
print("6. Check-Out")
print("7. View Rooms")
print("8. View Guests")
print("9. View Bookings")
print("10. View Bills")
print("11. Exit")
try:
choice = int(input("Enter your choice: "))
except ValueError:
print("Invalid choice! Please enter a number between 1 and 11.")
continue
if choice == 1:
add_guest()
elif choice == 2:
add_room()
elif choice == 3:
book_room()
elif choice == 4:
add_food_item()
elif choice == 5:
room_service()
elif choice == 6:
check_out()
elif choice == 7:
view_rooms()
elif choice == 8:
view_guests()
elif choice == 9:
view_bookings()
elif choice == 10:
view_bills()
elif choice == 11:
print("Exiting the system.")
break
else:
print("Invalid choice! Please try again.")