-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
126 lines (89 loc) · 4.35 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import logging
from fruit_manager import FruitManager
from customer import Customer
import datetime
# Configure logging
logging.basicConfig(filename='transactions.log', level=logging.INFO, format='%(asctime)s - %(message)s')
def main():
fruit_manager = FruitManager()
customer = None
while True:
print("\n===== FRUIT STORE MENU =====")
print("1. Manager")
print("2. Customer")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == '1': # Manager
while True:
print("\n===== MANAGER MENU =====")
print("1. Add Fruit Stock")
print("2. View Fruit Stock")
print("3. Update Fruit Stock")
print("4. Back to Main Menu")
manager_choice = input("Enter your choice: ")
if manager_choice == '1': # Add Fruit Stock
fruit_name = input("Enter the fruit name: ")
quantity = int(input("Enter the quantity: "))
price = float(input("Enter the price: "))
fruit_manager.add_fruit_stock(fruit_name, quantity, price)
print(f"{quantity} {fruit_name}(s) added to the stock.")
elif manager_choice == '2': # View Fruit Stock
stock = fruit_manager.view_fruit_stock()
print("\n=== Available Fruit Stock ===")
for fruit_name, details in stock.items():
print(f"{fruit_name}: Quantity - {details['quantity']}, Price - {details['price']}")
elif manager_choice == '3': # Update Fruit Stock
fruit_name = input("Enter the fruit name: ")
quantity = int(input("Enter the updated quantity: "))
if fruit_manager.update_fruit_stock(fruit_name, quantity):
print(f"{fruit_name} stock updated successfully.")
else:
print(f"{fruit_name} not found in stock.")
elif manager_choice == '4': # Back to Main Menu
break
else:
print("Invalid choice. Please try again.")
elif choice == '2': # Customer
customer_name = input("Enter your name: ")
customer = Customer(fruit_manager, customer_name)
while True:
print("\n===== CUSTOMER MENU =====")
print("1. Show Available Fruits")
print("2. Add to Cart")
print("3. View Cart")
print("4. Checkout")
print("5. Back to Main Menu")
customer_choice = input("Enter your choice: ")
if customer_choice == '1': # Show Available Fruits
available_fruits = fruit_manager.show_available_fruits()
print("\n=== Available Fruits ===")
for fruit in available_fruits:
print(fruit)
elif customer_choice == '2':
global cart
cart = {} # Add to Cart
fruit_name = input("Enter the fruit name: ")
quantity = int(input("Enter the quantity: "))
cart[fruit_name] = quantity
customer.add_to_cart(fruit_name, quantity)
elif customer_choice == '3': # View Cart
cart = customer.view_cart()
print("\n=== Your Cart ===")
for fruit_name, quantity in cart.items():
print(f"{fruit_name}: {quantity}")
elif customer_choice == '4': # Checkout
customer.calculate_total()
logging.info(f"Customer: {customer_name}, Cart: {cart}")
customer.clear_cart()
break
elif customer_choice == '5':
break
else:
print("Invalid choice. Please try again.")
elif choice == '3': # Exit
break
else:
print("Invalid choice. Please try again.")
if __name__ == '__main__':
main()
# Back to Main Menu