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Define the menu items with prices
|
| 8 |
+
menu = {
|
| 9 |
+
"01": {"name": "Chicken Fried Rice", "price": 80},
|
| 10 |
+
"02": {"name": "Veg Fried Rice", "price": 70},
|
| 11 |
+
"03": {"name": "Chicken Noodles", "price": 90},
|
| 12 |
+
"04": {"name": "Veg Noodles", "price": 75}
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
# Excel file for storing billing data
|
| 16 |
+
excel_file = "billing_data.xlsx"
|
| 17 |
+
|
| 18 |
+
# Initialize or load the Excel file
|
| 19 |
+
def initialize_excel():
|
| 20 |
+
try:
|
| 21 |
+
wb = load_workbook(excel_file)
|
| 22 |
+
ws = wb.active
|
| 23 |
+
if ws.max_row == 1: # If only headers exist, reinitialize
|
| 24 |
+
ws.append(["Date", "Bill Number", "Phone Number", "Item Name", "Quantity", "Price", "Total Amount", "Status"])
|
| 25 |
+
wb.save(excel_file)
|
| 26 |
+
except FileNotFoundError:
|
| 27 |
+
wb = Workbook()
|
| 28 |
+
ws = wb.active
|
| 29 |
+
ws.title = "Billing Data"
|
| 30 |
+
ws.append(["Date", "Bill Number", "Phone Number", "Item Name", "Quantity", "Price", "Total Amount", "Status"])
|
| 31 |
+
wb.save(excel_file)
|
| 32 |
+
|
| 33 |
+
initialize_excel()
|
| 34 |
+
|
| 35 |
+
# Streamlit UI Setup
|
| 36 |
+
st.set_page_config(page_title="The Taste Quest", page_icon="π", layout="wide")
|
| 37 |
+
|
| 38 |
+
# Title in the center
|
| 39 |
+
st.markdown("<h1 style='text-align: center;'>π The Taste Quest</h1>", unsafe_allow_html=True)
|
| 40 |
+
|
| 41 |
+
# Layout - Two Columns
|
| 42 |
+
col1, col2 = st.columns([1, 1]) # Left for customer details & history, right for billing
|
| 43 |
+
|
| 44 |
+
# Left Side (Customer Phone + Billing History)
|
| 45 |
+
with col1:
|
| 46 |
+
st.subheader("π Customer Details")
|
| 47 |
+
phone_number = st.text_input("Enter Customer Phone Number:")
|
| 48 |
+
|
| 49 |
+
# Generate unique bill number (same bill number for multiple items in one session)
|
| 50 |
+
if "bill_number" not in st.session_state:
|
| 51 |
+
st.session_state["bill_number"] = str(uuid.uuid4())[:8]
|
| 52 |
+
bill_number = st.session_state["bill_number"]
|
| 53 |
+
|
| 54 |
+
# Show past billing history for entered phone number
|
| 55 |
+
if phone_number:
|
| 56 |
+
try:
|
| 57 |
+
df = pd.read_excel(excel_file) # Read all columns
|
| 58 |
+
df.columns = ["Date", "Bill Number", "Phone Number", "Item Name", "Quantity", "Price", "Total Amount", "Status"]
|
| 59 |
+
customer_history = df[df["Phone Number"] == phone_number]
|
| 60 |
+
|
| 61 |
+
if not customer_history.empty:
|
| 62 |
+
customer_history["Date"] = pd.to_datetime(customer_history["Date"]) # Convert to datetime
|
| 63 |
+
customer_history = customer_history.sort_values(by="Date", ascending=False) # Sort by date
|
| 64 |
+
|
| 65 |
+
st.subheader("π Past Orders")
|
| 66 |
+
st.dataframe(customer_history)
|
| 67 |
+
else:
|
| 68 |
+
st.write("No previous records found for this number.")
|
| 69 |
+
except Exception as e:
|
| 70 |
+
st.error(f"Error loading billing history: {e}")
|
| 71 |
+
|
| 72 |
+
# Right Side (Item Selection + Quantity + Add to Bill)
|
| 73 |
+
with col2:
|
| 74 |
+
st.subheader("π Order Details")
|
| 75 |
+
|
| 76 |
+
# Auto-complete for item selection
|
| 77 |
+
item_names = {v["name"]: k for k, v in menu.items()} # Reverse lookup for codes
|
| 78 |
+
selected_item = st.selectbox("π Select an item:", options=list(item_names.keys()))
|
| 79 |
+
|
| 80 |
+
# Display price in a small card
|
| 81 |
+
if selected_item:
|
| 82 |
+
item_code = item_names[selected_item]
|
| 83 |
+
item = menu[item_code]
|
| 84 |
+
st.markdown(f"**Price:** Rs. {item['price']}")
|
| 85 |
+
|
| 86 |
+
quantity = st.number_input("π¦ Enter quantity:", min_value=1, step=1)
|
| 87 |
+
|
| 88 |
+
if st.button("β
Add to Bill"):
|
| 89 |
+
if selected_item and phone_number:
|
| 90 |
+
item_code = item_names[selected_item]
|
| 91 |
+
item = menu[item_code]
|
| 92 |
+
total_amount = item["price"] * quantity
|
| 93 |
+
|
| 94 |
+
# Get the current date & time
|
| 95 |
+
current_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 96 |
+
|
| 97 |
+
# Save to Excel properly
|
| 98 |
+
wb = load_workbook(excel_file)
|
| 99 |
+
ws = wb.active
|
| 100 |
+
ws.append([
|
| 101 |
+
current_date, # Date
|
| 102 |
+
str(bill_number), # Bill Number
|
| 103 |
+
str(phone_number), # Phone Number
|
| 104 |
+
item["name"], # Item Name
|
| 105 |
+
int(quantity), # Quantity
|
| 106 |
+
int(item["price"]), # Price
|
| 107 |
+
int(total_amount), # Total Amount
|
| 108 |
+
"Pending" # Status
|
| 109 |
+
])
|
| 110 |
+
wb.save(excel_file)
|
| 111 |
+
|
| 112 |
+
st.success(f"β
{item['name']} added! Total Amount: Rs. {total_amount}")
|
| 113 |
+
|
| 114 |
+
else:
|
| 115 |
+
st.error("β Please enter a phone number and select an item.")
|
| 116 |
+
|
| 117 |
+
# Pending Orders Section at the bottom right
|
| 118 |
+
st.subheader("π Pending Orders")
|
| 119 |
+
|
| 120 |
+
try:
|
| 121 |
+
df = pd.read_excel(excel_file) # Read all columns
|
| 122 |
+
df.columns = ["Date", "Bill Number", "Phone Number", "Item Name", "Quantity", "Price", "Total Amount", "Status"]
|
| 123 |
+
pending_orders = df[df["Status"] == "Pending"]
|
| 124 |
+
|
| 125 |
+
if not pending_orders.empty:
|
| 126 |
+
for index, row in pending_orders.iterrows():
|
| 127 |
+
col1, col2 = st.columns([3, 1])
|
| 128 |
+
with col1:
|
| 129 |
+
st.write(f"**Bill Number:** {row['Bill Number']} | **Item:** {row['Item Name']} | **Quantity:** {row['Quantity']} | **Total Amount:** Rs. {row['Total Amount']}")
|
| 130 |
+
with col2:
|
| 131 |
+
if st.checkbox("Mark as Completed", key=index):
|
| 132 |
+
# Update status to "Completed"
|
| 133 |
+
wb = load_workbook(excel_file)
|
| 134 |
+
ws = wb.active
|
| 135 |
+
ws.cell(row=index + 2, column=8, value="Completed") # Update status in Excel
|
| 136 |
+
wb.save(excel_file)
|
| 137 |
+
st.rerun() # Refresh the page to reflect changes
|
| 138 |
+
else:
|
| 139 |
+
st.write("No pending orders.")
|
| 140 |
+
except Exception as e:
|
| 141 |
+
st.error(f"Error loading pending orders: {e}")
|