GobhiMart: Retail Management System
GobhiMart: Retail Management System
Hardware Requirements :-
1. Processor: Minimum Dual-core processor (Intel/AMD).
Recommended: Core i3 or higher.
2. RAM: At least 4 GB. Recommended: 8 GB for smooth execution of
Python + MySQL.
3. Storage: Minimum 1 GB free space. MySQL requires additional
space for databases.
4. Monitor: Any standard display to view the interface and output.
5. Keyboard & Mouse: For input operations during registration and
login.
The hardware requirements ensure that the system can handle both
Python execution and MySQL database operations without lag.
Software Requirements :-
1.`slow_print(text, delay=0.05)`
- Prints text character by character with a delay
2. show_product_list(cursor, category_to_table)`
- Displays all products across all categories in a formatted
table
4. `manager_view_stock(cursor, category_to_table)`
- Displays stock inventory in tabular format for manager
5. `manager_change_password()`
- Allows manager to change the customer entry password
7. `authenticate_manager()`
- Authenticates manager and returns True if successful
8. authenticate_customer()`
- Authenticates customer and returns True if successful
12. `main()`
- Main entry point: initializes database, creates tables,
seeds data, and runs the main program loop
1. sys
- Used for `[Link]()` and `[Link]()` in
`slow_print()`, and `[Link]()` for program termination
2. getpass
- Used for secure password input with `[Link]()` in
authentication functions
3. datetime)
- Used for `[Link]()` to get current date/time for
receipts and sales records
4. time
- Used for `[Link]()` to add delays in the `slow_print()`
function
5. [Link]
- Used for MySQL database connectivity
- Provides `[Link]()` for database
connections
- Handles database operations and error handling
Source Code
import sys
import getpass
from datetime import datetime
import [Link]
import time
if not products:
print(" No products in this category.")
continue
total_revenue_all = 0.0
total_cost_all = 0.0
total_profit_all = 0.0
if not products:
print(" No products in this category.")
continue
total_revenue_all += revenue
total_cost_all += (float(cost) * qty_sold)
total_profit_all += profit
if not products:
print(" No products in this category.")
continue
def manager_change_password():
"""Allow manager to change the customer entry password"""
global CUSTOMER_PASSWORD
print("\n" + "=" * 60)
print("CHANGE CUSTOMER ENTRY PASSWORD")
print("=" * 60)
print(f"Current customer password: {'*' * len(CUSTOMER_PASSWORD)}")
while True:
new_password = [Link](prompt="Enter new customer password: ")
if not new_password:
print("* Password cannot be empty.")
continue
confirm_password = [Link](prompt="Confirm new customer password: ")
if new_password != confirm_password:
print("* Passwords do not match. Please try again.")
continue
CUSTOMER_PASSWORD = new_password
print("Customer password updated successfully!")
break
# Show categories
categories = list(category_to_table.keys())
print("\nCategories:")
for i in range(len(categories)):
print(f" {i + 1}. {categories[i]}")
while True:
cat_choice = input("\nSelect category by number (0 to cancel): ").strip()
if not cat_choice.isdigit():
print("* Invalid input.")
continue
cat_num = int(cat_choice)
if cat_num == 0:
return
if cat_num < 1 or cat_num > len(categories):
print("* Invalid category number.")
continue
break
selected_category = categories[cat_num - 1]
table = category_to_table[selected_category]
if not products:
print("No products in this category.")
return
print(f"\nProducts in {selected_category}:")
print(f"{'ID':<5} {'Product Name':<30} {'Current Price':<15} {'Stock':<10}")
print("-" * 60)
for pid, name, price, stock in products:
print(f"{pid:<5} {name:<30} ${price:<14.2f} {stock:<10}")
while True:
prod_id = input("\nEnter product ID to change price (0 to cancel): ").strip()
if not prod_id.isdigit():
print("* Invalid input.")
continue
prod_id = int(prod_id)
if prod_id == 0:
return
def authenticate_manager():
"""Authenticate manager and return True if successful"""
manager_password = "gobhi"
attempts_left = 3
while attempts_left > 0:
entered = [Link](prompt="Enter manager password: ")
if entered == manager_password:
return True
attempts_left -= 1
print("* Incorrect password. Attempts left:", attempts_left)
print("Access denied.")
return False
def authenticate_customer():
"""Authenticate customer and return True if successful"""
global CUSTOMER_PASSWORD
attempts_left = 3
while attempts_left > 0:
entered = [Link](prompt="Enter customer password: ")
if entered == CUSTOMER_PASSWORD:
return True
attempts_left -= 1
print("* Incorrect password. Attempts left:", attempts_left)
print("Access denied.")
return False
if choice == '1':
manager_view_stock(cursor, category_to_table)
elif choice == '2':
manager_change_password()
elif choice == '3':
manager_change_price(cursor, conn, category_to_table)
elif choice == '4':
return 'switch'
elif choice == '5':
return 'exit'
else:
print("* Invalid choice. Please enter 1-5.")
print("-" * 80)
print(f"{'SUBTOTAL:':<63} ${subtotal:.2f}")
print(f"{'PAYMENT METHOD:':<63} {payment_method}")
print("=" * 80)
print(" " * 25 + "THANK YOU FOR SHOPPING!")
print(" " * 20 + "Visit us again at GobhiMart")
print("=" * 80 + "\n")
while True:
print("\nCategories:")
for i in range(len(categories)):
cat = categories[i]
print(f" {i + 1}. {cat}")
print(" 0. Proceed to payment")
selected_category = categories[choice_num - 1]
table = category_to_table[selected_category]
[Link](
f"SELECT id, name, price, stock FROM {table} ORDER BY name"
)
products = [Link]()
if not products:
print("No products in this category.")
continue
print(f"\nProducts in {selected_category}:")
for i in range(len(products)):
pid, name, price, stock = products[i]
print(f" {i + 1}. {name} - ${price} (Stock: {stock})")
print(" 0. Back to categories")
if not cart:
print("Cart is empty. Returning to menu.")
return
print("\nCart:")
subtotal = 0.0
for i in range(len(cart)):
if len(cart[i]) == 6: # Has size (Clothing)
table, pid, pname, unit_price, qty, size = cart[i]
line_total = unit_price * qty
subtotal += line_total
print(f" {i + 1}. {pname} (Size: {size}) x {qty} @ ${unit_price:.2f} = $
{line_total:.2f}")
else: # No size (Other categories)
table, pid, pname, unit_price, qty = cart[i]
line_total = unit_price * qty
subtotal += line_total
print(f" {i + 1}. {pname} x {qty} @ ${unit_price:.2f} = ${line_total:.2f}")
print(f"Subtotal: ${subtotal:.2f}")
# Payment methods
methods = ["Cash", "Card", "UPI"]
while True:
print("Payment methods:")
for i in range(len(methods)):
m = methods[i]
print(f" {i + 1}. {m}")
pm_in = input("Choose payment method: ").strip()
if pm_in.isdigit() and 1 <= int(pm_in) <= len(methods):
payment_method = methods[int(pm_in) - 1]
break
print("* Invalid choice.")
while True:
customer_name = input("Enter your name: ").strip()
if customer_name:
break
print("* Name cannot be empty. Please enter your name.")
while True:
phone_number = input("Enter your phone number: ").strip()
if phone_number:
# Basic validation - check if it contains digits
if any([Link]() for char in phone_number):
break
else:
print("* Please enter a valid phone number with digits.")
else:
print("* Phone number cannot be empty. Please enter your phone number.")
while True:
address = input("Enter delivery address: ").strip()
if address:
print(f"\nDelivery address: {address}")
break
print("* Address cannot be empty. Please enter a valid address.")
# Confirm
confirm = input("\nConfirm purchase? (y/n): ").strip().lower()
if confirm != "y":
print("Purchase cancelled.")
return
[Link](
f"SELECT stock FROM {table} WHERE id=%s FOR UPDATE",
(pid,),
)
row = [Link]()
if not row:
raise ValueError("Product disappeared: " + str(pid))
current_stock = int(row[0])
if qty > current_stock:
raise ValueError(f"Insufficient stock for product {pname}")
# Generate transaction ID
transaction_id = f"TXN{[Link]().strftime('%Y%m%d%H%M%S')}"
# Print receipt
print_receipt(customer_name, phone_number, address, cart, subtotal, payment_method,
transaction_id)
def main():
# Welcome message
welcome_message = "Welcome to GobhiMart - Your One-Stop Shopping Destination!"
slow_print(welcome_message)
slow_print("=" * len(welcome_message))
print()
# Connect to MySQL
try:
conn = [Link](
host="localhost",
user="root",
password="omijebhabha",
database="gobhimart",
)
except [Link] as e:
print("Database connection failed:", e)
[Link](2)
cursor = [Link]()
if mode_choice == '1':
# Manager mode authentication
if not authenticate_manager():
continue
print("Manager access granted!")
cleanup(cursor, conn)
if __name__ == "__main__":
main()
OUTPUT
Customer :-
============================================================
MODE SELECTION
============================================================
Select mode:
1. Manager
2. Customer
3. Exit Program
Select an option:
s - Shopping
w - View Stock and Sales
m - Switch to Manager Mode
x - Exit Program
=========================================================================
=======
PRODUCT LIST
=========================================================================
=======
Electronics:
--------------------------------------------------------------------------------
Product Name Price Stock
--------------------------------------------------------------------------------
Headphones $199.99 74
Laptop $899.99 27
Smart Watch $149.99 40
Smartphone $299.99 50
Tablet $249.99 60
Clothing:
--------------------------------------------------------------------------------
Product Name Price Stock
--------------------------------------------------------------------------------
Dress $39.99 53
Jacket $79.99 45
Jeans $49.99 58
Shoes $89.99 35
T-Shirt $19.99 98
Books:
--------------------------------------------------------------------------------
Product Name Price Stock
--------------------------------------------------------------------------------
Data Science $24.21 145
Database $24.99 160
ML Guide $44.99 115
Python Book $29.99 199
Web Dev $34.99 175
Sports:
--------------------------------------------------------------------------------
Product Name Price Stock
--------------------------------------------------------------------------------
Basketball $29.99 70
Dumbbells $99.99 27
Football $34.99 46
Tennis Racket $79.99 25
Yoga Mat $24.99 81
=========================================================================
=======
Categories:
1. Electronics
2. Clothing
3. Books
4. Home & Garden
5. Sports
0. Proceed to payment
Select a category by number (0 to checkout): 2
Products in Clothing:
1. Dress - $39.99 (Stock: 53)
2. Jacket - $79.99 (Stock: 45)
3. Jeans - $49.99 (Stock: 58)
4. Shoes - $89.99 (Stock: 35)
5. T-Shirt - $19.99 (Stock: 98)
0. Back to categories
Select a product by number: 3
Available sizes:
1. XS
2. S
3. M
4. L
5. XL
6. XXL
Select size by number: 3
Selected size: M
Enter quantity: 2
Selected -> var: clothing_jeans, product: Jeans, size: M, qty: 2
Categories:
1. Electronics
2. Clothing
3. Books
4. Home & Garden
5. Sports
0. Proceed to payment
Select a category by number (0 to checkout): 0
Cart:
1. Jeans (Size: M) x 2 @ $49.99 = $99.98
Subtotal: $99.98
Payment methods:
1. Cash
2. Card
3. UPI
Choose payment method: 2
Selected payment: Card
------------------------------------------------------------
CUSTOMER INFORMATION
------------------------------------------------------------
Enter your name: haze
Enter your phone number: 6967595938
Enter delivery address: skp
=========================================================================
=======
GOBHIMART
RECEIPT / INVOICE
=========================================================================
=======
Transaction ID: TXN20251207170735
Date: 2025-12-07 17:07:35
--------------------------------------------------------------------------------
CUSTOMER INFORMATION:
Name: haze
Phone: 6967595938
Address: skp
--------------------------------------------------------------------------------
ITEMS PURCHASED:
Item Qty Unit Price Total
--------------------------------------------------------------------------------
Jeans (Size: M) 2 $49.99 $99.98
--------------------------------------------------------------------------------
SUBTOTAL: $99.98
PAYMENT METHOD: Card
=========================================================================
=======
THANK YOU FOR SHOPPING!
Visit us again at GobhiMart
=========================================================================
=======
=========================================================================
=======
PRODUCT LIST
=========================================================================
=======
Electronics:
--------------------------------------------------------------------------------
Product Name Price Stock
--------------------------------------------------------------------------------
Headphones $199.99 74
Laptop $899.99 27
Smart Watch $149.99 40
Smartphone $299.99 50
Tablet $249.99 60
Clothing:
--------------------------------------------------------------------------------
Product Name Price Stock
--------------------------------------------------------------------------------
Dress $39.99 53
Jacket $79.99 45
Jeans $49.99 56
Shoes $89.99 35
T-Shirt $19.99 98
Books:
--------------------------------------------------------------------------------
Product Name Price Stock
--------------------------------------------------------------------------------
Data Science $24.21 145
Database $24.99 160
ML Guide $44.99 115
Python Book $29.99 199
Web Dev $34.99 175
Sports:
--------------------------------------------------------------------------------
Product Name Price Stock
--------------------------------------------------------------------------------
Basketball $29.99 70
Dumbbells $99.99 27
Football $34.99 46
Tennis Racket $79.99 25
Yoga Mat $24.99 81
=========================================================================
=======
Select an option:
s - Shopping
w - View Stock and Sales
m - Switch to Manager Mode
x - Exit Program
Manager :-
============================================================
MODE SELECTION
============================================================
Select mode:
1. Manager
2. Customer
3. Exit Program
============================================================
MANAGER MENU
============================================================
1. View Stock (Tabular Format)
2. Change Customer Entry Password
3. Change Product Price
4. Switch to Customer Mode
5. Exit Program
=========================================================================
=======
CURRENT STOCK INVENTORY
=========================================================================
=======
Electronics:
--------------------------------------------------------------------------------
ID Product Name Price Stock
--------------------------------------------------------------------------------
3 Headphones $199.99 74
2 Laptop $899.99 27
4 Smart Watch $149.99 40
1 Smartphone $299.99 50
5 Tablet $249.99 60
Clothing:
--------------------------------------------------------------------------------
ID Product Name Price Stock
--------------------------------------------------------------------------------
5 Dress $39.99 53
3 Jacket $79.99 45
2 Jeans $49.99 56
4 Shoes $69.99 35
1 T-Shirt $19.99 98
Books:
--------------------------------------------------------------------------------
ID Product Name Price Stock
--------------------------------------------------------------------------------
2 Data Science $24.21 145
5 Database $24.99 160
4 ML Guide $44.99 115
1 Python Book $29.99 199
3 Web Dev $34.99 175
Sports:
--------------------------------------------------------------------------------
ID Product Name Price Stock
--------------------------------------------------------------------------------
1 Basketball $29.99 70
4 Dumbbells $99.99 27
5 Football $34.99 46
2 Tennis Racket $79.99 25
3 Yoga Mat $24.99 81
=========================================================================
=======
============================================================
MANAGER MENU
============================================================
1. View Stock (Tabular Format)
2. Change Customer Entry Password
3. Change Product Price
4. Switch to Customer Mode
5. Exit Program
============================================================
CHANGE CUSTOMER ENTRY PASSWORD
============================================================
Current customer password: ***********
Warning: Password input may be echoed.
Enter new customer password: haze123
Warning: Password input may be echoed.
Confirm new customer password: haze123
Customer password updated successfully!
============================================================
MANAGER MENU
============================================================
1. View Stock (Tabular Format)
2. Change Customer Entry Password
3. Change Product Price
4. Switch to Customer Mode
5. Exit Program
============================================================
MODE SELECTION
============================================================
Select mode:
1. Manager
2. Customer
3. Exit Program
Select an option:
s - Shopping
w - View Stock and Sales
m - Switch to Manager Mode
x - Exit Program
============================================================
MODE SELECTION
============================================================
Select mode:
1. Manager
2. Customer
3. Exit Program
============================================================
MANAGER MENU
============================================================
1. View Stock (Tabular Format)
2. Change Customer Entry Password
3. Change Product Price
4. Switch to Customer Mode
5. Exit Program
Enter your choice (1-5): 3
============================================================
CHANGE PRODUCT PRICE
============================================================
Categories:
1. Electronics
2. Clothing
3. Books
4. Home & Garden
5. Sports
Products in Sports:
ID Product Name Current Price Stock
------------------------------------------------------------
1 Basketball $29.99 70
4 Dumbbells $99.99 27
5 Football $34.99 46
2 Tennis Racket $79.99 25
3 Yoga Mat $24.99 81
============================================================
MANAGER MENU
============================================================
1. View Stock (Tabular Format)
2. Change Customer Entry Password
3. Change Product Price
4. Switch to Customer Mode
5. Exit Program