import tkinter as tk
from tkinter import messagebox
# Initialize sales records to store all sales
sales_records = []
# Function to reset the input fields for a new customer
def reset_fields():
entry_product.delete(0, tk.END)
entry_quantity.delete(0, tk.END)
label_total.config(text="Total: $0")
# Function to process and calculate the total for the current customer
def add_to_cart():
product = entry_product.get().strip()
quantity = entry_quantity.get().strip()
if product == "" or quantity == "":
messagebox.showwarning("Input Error", "Please enter both product name and
quantity.")
return
try:
quantity = int(quantity)
if quantity <= 0:
raise ValueError("Quantity must be positive")
except ValueError:
messagebox.showwarning("Input Error", "Please enter a valid quantity.")
return
# You can replace this with a real price lookup based on product
price_per_unit = 10 # Example: $10 for any product, replace with your actual
pricing logic
total = price_per_unit * quantity
current_sale.append((product, quantity, total))
# Update total amount label
total_amount = sum(item[2] for item in current_sale)
label_total.config(text=f"Total: ${total_amount}")
# Function to finalize the sale for the current customer
def finalize_sale():
if not current_sale:
messagebox.showwarning("Sale Error", "No products in the current sale.")
return
total_amount = sum(item[2] for item in current_sale)
sales_records.append({'sale': current_sale.copy(), 'total': total_amount})
# Display message
messagebox.showinfo("Sale Finalized", f"Sale finalized for ${total_amount}")
# Clear the current sale
current_sale.clear()
reset_fields()
# Function to display the end-of-day report
def show_end_of_day_report():
total_sales = sum(sale['total'] for sale in sales_records)
total_customers = len(sales_records)
report_message = f"Total customers: {total_customers}\nTotal sales: $
{total_sales}"
messagebox.showinfo("End of Day Report", report_message)
# Initialize current sale for each customer
current_sale = []
# Set up the GUI window
root = tk.Tk()
root.title("Shop Billing System")
# Labels and entries for product and quantity
label_product = tk.Label(root, text="Product Name")
label_product.grid(row=0, column=0, padx=10, pady=10)
entry_product = tk.Entry(root)
entry_product.grid(row=0, column=1, padx=10, pady=10)
label_quantity = tk.Label(root, text="Quantity")
label_quantity.grid(row=1, column=0, padx=10, pady=10)
entry_quantity = tk.Entry(root)
entry_quantity.grid(row=1, column=1, padx=10, pady=10)
# Button to add product to the cart
button_add = tk.Button(root, text="Add to Cart", command=add_to_cart)
button_add.grid(row=2, column=0, columnspan=2, padx=10, pady=10)
# Label to display total amount for the current customer
label_total = tk.Label(root, text="Total: $0")
label_total.grid(row=3, column=0, columnspan=2, padx=10, pady=10)
# Button to finalize the sale for the current customer
button_finalize = tk.Button(root, text="Finalize Sale", command=finalize_sale)
button_finalize.grid(row=4, column=0, columnspan=2, padx=10, pady=10)
# Button to show end-of-day report
button_report = tk.Button(root, text="End of Day Report",
command=show_end_of_day_report)
button_report.grid(row=5, column=0, columnspan=2, padx=10, pady=10)
# Start the GUI event loop
root.mainloop()