0% found this document useful (0 votes)
41 views25 pages

Grocery Management Project

grocery management project with python class 12

Uploaded by

roydeadmanx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views25 pages

Grocery Management Project

grocery management project with python class 12

Uploaded by

roydeadmanx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

CERTIFICATE

pg. 1
This is to certify that the
project work entitled
"Grocery Management
System" Carried out by
TANISH ROY of Class XII
(Science) during academic
session 2024-2025 is an
original work, as per the
rules, regulations and
guidelines issued by the
Central Board of Secondary
Education.

EXTERNAL
INTERNAL

PRINCIPAL

pg. 2
TABLE OF CONTENTS 25
SERIAL NUMBER Bibliography PAGE NUMBER
DESCRIPTION

1 Acknowledgement 4

2 Introduction 5

3 Contents of 6

syllabus used
4 Hardware and 7
Software
specifications
5 Working description 8

6 Source code 10

7 Explanation 20

8 Output 21

pg. 3
ACKNOWLEDGEMENT
The successful completion of this project would not have been
possible without the support and encouragement of many
individuals. It is with immense gratitude that I take this
opportunity to thank everyone who contributed to making this
endeavor a success.
First and foremost, I express my heartfelt gratitude to my
parents for their unwavering encouragement and belief in me
throughout this journey. Their constant support served as my
greatest motivation.
I would like to sincerely thank the Principal of Oriental Public
School for their continuous motivation and invaluable guidance,
which inspired me to strive for excellence.
My deepest appreciation goes to my Computer Science teacher,
Mrs. Ananya Banerjee, who has been not just a guide but also a
mentor and friend. Her critical insights, unwavering patience,
and dedication in helping me overcome every challenge during
the project’s implementation were truly instrumental in its
success.
I am also profoundly grateful to everyone else who contributed
to this project, directly or indirectly. Their guidance,
encouragement, and support played a vital role in shaping this
project into what it is today. Thank you all for your invaluable
contributions.

pg. 4
PROJECT ON GROCERY
MANAGEMENT SYSTEM
INTRODUCTION
This project focuses on the methods and
processes involved in managing the billing
and inventory systems in grocery stores.
Specifically, it aims to simplify and automate
daily operations for grocery store owners. By
digitizing sales and stock management, the
system helps maintain accurate records of
transactions for specific days, months, or
even entire years. It also assists in calculating
profits efficiently. This software allows
administrators to add, update, and review file
contents securely in a password-protected
environment, ensuring data integrity and
confidentiality.

pg. 5
CONTENT OF SYLLABUS
USED:
1) Python fundamentals
2) Loops and conditional
statements 3) Fundamentals of
Structured Query Language(SQL)
4) Table creation and data
manipulation in MySQL
5) Interface Python with MySQL
connectivity

pg. 6
Hardware and software
specifications
The following hardware and
software were used during the
compilation and implementation of
the project:
1) Operating system:- Windows 10
2) Python IDLE version 3.11 64-bit
3) MysQL 8.0 server and client

pg. 7
Working Description:
The project aimed to develop a Python-based
program script that enables the shop admin to
manage customer and product details within a
Grocery Management System. It allows the
admin to add customer and grocery item details to
a database management system and retrieve them
as needed.
Python displays the menu for the GROCERY
MANAGEMENT SYSTEM program:
1. Enter Customer and Grocery Details:
The system prompts the admin to input
customer details such as customer name,
phone number, and address. Additionally,
grocery item details such as item code
(primary key), item name, quantity, price per
unit, and total amount are recorded in the
database.
2. Show Customer and Grocery Details:
Python requests the admin to input the unique
item code or customer name to retrieve
specific data. Using this input, a
parameterized
pg. 8
3. SQL query is executed to fetch and
display the corresponding details from the
database.
This project seamlessly integrates the concepts of
Python-MySQL connectivity with core Python
programming and MySQL database management
to create a user-friendly and efficient application.
Internally, the project creates a table named
grocery_details within the database
grocery_management, containing fields as
described in the first menu option. Utilizing the
"mysql.connector" module, Python connects to
the database to perform operations. The program
employs conditional statements and SQL query
execution to append, update, and retrieve data,
ensuring a smooth workflow for managing
grocery store operations.

pg. 9
Source code
Creating a Programme using Python, MySQL, and CSV
file handling is an excellent way to handle inventory
management, track customer purchases, and generate
reports. Below is a step-by-step guide to building such a
system.
Steps to Implement the Grocery Management System:
1.Setting up MySQL Database:

o Create a MySQL database to store grocery product


details, customer orders, and payment records.
o Example schema for the Grocery Management
System:
sql
Copy code
CREATE DATABASE grocery_management;

USE grocery_management;

CREATE TABLE products (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
category VARCHAR(100),
price DECIMAL(10, 2),
stock_quantity INT
);

CREATE TABLE customer_orders (


id INT AUTO_INCREMENT PRIMARY KEY,
pg. 10
customer_name VARCHAR(255),
product_id INT,
quantity INT,
order_time DATETIME,
payment_status VARCHAR(50),
total_amount DECIMAL(10, 2),
FOREIGN KEY (product_id) REFERENCES
products(id)
);

2.Install Required Python Packages:

o Install mysql-connector for MySQL connectivity


and pandas for handling CSV files.
bash
Copy code
pip install mysql-connector pandas

3.Python Script:
o The following Python script handles MySQL

connectivity, CSV file reading/writing, and


managing products and customer orders.
Python Code
python
Copy code
import mysql.connector
import pandas as pd
from datetime import datetime

# MySQL Connection
def connect_to_database():
try:

pg. 11
conn = mysql.connector.connect(
host="localhost", # MySQL
host
user="root", # MySQL
user
password="password", # MySQL
password
database="grocery_management" #
Database name
)
if conn.is_connected():
print("Successfully connected to the
database.")
return conn
except mysql.connector.Error as err:
print(f"Error: {err}")
return None

# Create and Insert Sample Data (Products and


Orders)
def create_and_insert_sample_data():
conn = connect_to_database()
if conn is not None:
cursor = conn.cursor()

# Create products table and


customer_orders table if they don't exist
cursor.execute("""
CREATE TABLE IF NOT EXISTS products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
category VARCHAR(100),
price DECIMAL(10, 2),
stock_quantity INT
);
""")

pg. 12
cursor.execute("""
CREATE TABLE IF NOT EXISTS
customer_orders (
id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(255),
product_id INT,
quantity INT,
order_time DATETIME,
payment_status VARCHAR(50),
total_amount DECIMAL(10, 2),
FOREIGN KEY (product_id) REFERENCES
products(id)
);
""")

# Insert sample products


cursor.execute("""
INSERT INTO products (name, category,
price, stock_quantity)
VALUES
('Milk', 'Dairy', 1.50, 100),
('Bread', 'Bakery', 2.00, 150),
('Eggs', 'Dairy', 3.00, 50),
('Apple', 'Fruits', 2.50, 200),
('Tomato', 'Vegetables', 1.20, 80);
""")

conn.commit()
print("Sample data inserted.")
cursor.close()
conn.close()

# Fetch data from MySQL (Products and Orders)


def fetch_data_from_db():
conn = connect_to_database()
if conn is not None:
cursor = conn.cursor(dictionary=True)

pg. 13
# Fetch products
cursor.execute("SELECT * FROM
products;")
products = cursor.fetchall()

print("\nProducts:")
for product in products:
print(product)

# Fetch customer orders


cursor.execute("SELECT * FROM
customer_orders;")
orders = cursor.fetchall()

print("\nCustomer Orders:")
for order in orders:
print(order)
cursor.close()
conn.close()

# Export Product and Order Data to CSV


def export_to_csv():
conn = connect_to_database()
if conn is not None:
cursor = conn.cursor(dictionary=True)
# Export Products Data
cursor.execute("SELECT * FROM
products;")
products = cursor.fetchall()
products_df = pd.DataFrame(products)
products_df.to_csv("products.csv",
index=False)
print("Products data exported to
'products.csv'.")
# Export Orders Data

pg. 14
cursor.execute("SELECT * FROM
customer_orders;")
orders = cursor.fetchall()
orders_df = pd.DataFrame(orders)
orders_df.to_csv("orders.csv",
index=False)
print("Orders data exported to
'orders.csv'.")
cursor.close()
conn.close()

# Import Data from CSV to MySQL


def import_from_csv():
try:
# Read CSV files
products_df =
pd.read_csv('products.csv')
orders_df = pd.read_csv('orders.csv')
# Connect to MySQL database
conn = connect_to_database()
if conn is not None:
cursor = conn.cursor()

# Insert products from CSV


for index, row in
products_df.iterrows():
cursor.execute("""
INSERT INTO products (name,
category, price, stock_quantity)
VALUES (%s, %s, %s, %s)
""", (row['name'],
row['category'], row['price'],
row['stock_quantity']))
# Insert orders from CSV

pg. 15
for index, row in
orders_df.iterrows():
cursor.execute("""
INSERT INTO customer_orders
(customer_name, product_id, quantity,
order_time, payment_status, total_amount)
VALUES (%s, %s, %s, %s, %s, %s)
""", (row['customer_name'],
row['product_id'], row['quantity'],
row['order_time'], row['payment_status'],
row['total_amount']))

conn.commit()
print("Data imported from CSV to
MySQL.")
cursor.close()
conn.close()
except FileNotFoundError:
print("CSV file not found.")
except Exception as e:
print(f"Error: {e}")

# Place a Customer Order


def place_order(customer_name, product_name,
quantity):
conn = connect_to_database()
if conn is not None:
cursor = conn.cursor()

# Check if the product is available


cursor.execute("SELECT * FROM products
WHERE name = %s;", (product_name,))
product = cursor.fetchone()

if product and product['stock_quantity']


>= quantity:
# Calculate total amount

pg. 16
total_amount = product['price'] *
quantity
order_time =
datetime.now().strftime('%Y-%m-%d %H:%M:%S')

# Insert the customer order into the


database
cursor.execute("""
INSERT INTO customer_orders
(customer_name, product_id, quantity,
order_time, payment_status, total_amount)
VALUES (%s, %s, %s, %s, %s, %s)
""", (customer_name, product['id'],
quantity, order_time, 'Pending', total_amount))
# Update product stock
new_stock_quantity =
product['stock_quantity'] - quantity
cursor.execute("""
UPDATE products
SET stock_quantity = %s
WHERE id = %s
""", (new_stock_quantity,
product['id']))

conn.commit()
print(f"Order placed for
{customer_name}: {quantity} x {product_name} -
Total: {total_amount:.2f}")
else:
print(f"Product '{product_name}' not
available in sufficient quantity.")
cursor.close()
conn.close()

# Update Payment Status after Payment

pg. 17
def update_payment_status(order_id,
payment_status):
conn = connect_to_database()
if conn is not None:
cursor = conn.cursor()

# Update the payment status of the order


cursor.execute("UPDATE customer_orders
SET payment_status = %s WHERE id = %s;",
(payment_status, order_id))
conn.commit()

if payment_status == "Paid":
print(f"Order {order_id} marked as
paid.")
else:
print(f"Payment for order {order_id}
is pending.")
cursor.close()
conn.close()

# Main Menu to execute functions


def main():
while True:
print("\nGrocery Management System")
print("1. Place an Order")
print("2. Update Payment Status")
print("3. Fetch Data from Database")
print("4. Export Data to CSV")
print("5. Import Data from CSV")
print("6. Create and Insert Sample
Data")
print("7. Exit")
choice = input("Enter your choice: ")
if choice == '1':

pg. 18
customer_name = input("Enter
customer name: ")
product_name = input("Enter product
name: ")
quantity = int(input("Enter
quantity: "))
place_order(customer_name,
product_name, quantity)
elif choice == '2':
order_id = int(input("Enter order
ID: "))
payment_status = input("Enter
payment status (Paid/Pending): ")
update_payment_status(order_id,
payment_status)
elif choice == '3':
fetch_data_from_db()
elif choice == '4':
export_to_csv()
elif choice == '5':
import_from_csv()
elif choice == '6':
create_and_insert_sample_data()
elif choice == '7':
break
else:
print("Invalid choice! Please try
again.")

if __name__ == "__main__":
main()

Explanation:
1. Database Setup:

pg. 19
The script creates a grocery_management database with
o

products and customer_orders tables.


o products stores information about grocery items such

as name, category, price, and stock quantity.


o customer_orders stores customer orders, including the

customer’s name, product ID, quantity, order time,


payment status, and total amount.
2. Features:
o Place an Order: Customers can place orders for

grocery items. The system checks for stock availability


and updates the stock quantity accordingly.
o Update Payment Status: The system allows updating

the payment status for orders (e.g., "Paid" or


"Pending").
o Export/Import Data: The system can export product

and order data to CSV files and import data from CSV
files.
o Sample Data: The script can insert sample product data

into the database for testing purposes.


3. CSV Handling:
o The system supports exporting and importing product

and order data to/from CSV files using pandas.

Output
pg. 20
1. Connection Output
When you run the script, the first thing that will happen is that it will try
to establish a connection to the MySQL database. If successful, you'll
see:
arduino
Copy code
Successfully connected to the database.

2. Create and Insert Sample Data Output


When you choose option 6 (Create and Insert Sample Data), the
following will happen:
 The products and customer_orders tables will be created
if they do not already exist.
 Sample data will be inserted into the products table.
 You'll see this message:
kotlin
Copy code
Sample data inserted.

3. Fetch Data from Database Output


When you choose option 3 (Fetch Data from Database), the system will:

 Fetch all products from the products table and display them.
 Fetch all customer orders from the customer_orders table and
display them. Output will look something like this:
css
Copy code
Products:
{'id': 1, 'name': 'Milk', 'category': 'Dairy',
'price': 1.50, 'stock_quantity': 100}
{'id': 2, 'name': 'Bread', 'category': 'Bakery',
'price': 2.00, 'stock_quantity': 150}

pg. 21
{'id': 3, 'name': 'Eggs', 'category': 'Dairy',
'price': 3.00, 'stock_quantity': 50}
{'id': 4, 'name': 'Apple', 'category': 'Fruits',
'price': 2.50, 'stock_quantity': 200}
{'id': 5, 'name': 'Tomato', 'category':
'Vegetables', 'price': 1.20, 'stock_quantity':
80}

Customer Orders:

There will be no orders at first, so this will be empty unless you have
placed an order.
4. Export to CSV Output
When you choose option 4 (Export Data to CSV), the system will:

 Export the products table to products.csv.


 Export the customer_orders table to orders.csv.

You'll see:
kotlin
Copy code
Products data exported to 'products.csv'.
Orders data exported to 'orders.csv'.

5. Import from CSV Output


When you choose option 5 (Import Data from CSV), the script will try
to import data from the products.csv and orders.csv files into
the database. You'll see this message if successful:
css
Copy code
Data imported from CSV to MySQL.

If the CSV files do not exist, you'll see:


Copy code

pg. 22
CSV file not found.

6. Place an Order Output


When you choose option 1 (Place an Order), the system will:

 Check if the product is available in stock.


 If the stock is sufficient, the order will be placed and the stock
quantity will be updated.
For example:
mathematica
Copy code
Enter customer name: John Doe
Enter product name: Milk
Enter quantity: 2
Order placed for John Doe: 2 x Milk - Total:
3.00

If the product is not available in sufficient quantity:


arduino
Copy code
Product 'Milk' not available in sufficient
quantity.

7. Update Payment Status Output


When you choose option 2 (Update Payment Status), you'll be asked for
an order ID and the payment status (Paid/Pending). For example:
mathematica
Copy code
Enter order ID: 1
Enter payment status (Paid/Pending): Paid
Order 1 marked as paid.

8. Exit Output

pg. 23
When you choose option 7 (Exit), the system will exit the loop and
terminate the program:
Copy code
Exiting the program...

pg. 24
BIBLIOGRAPHY
For completing this project, I took help from
following references which I have mentioned
below:
Book:
1. Computer Science with Python- Class XI By:
Sumita Arora
2. Computer Science with Python- Class XIl By:
Sumita Arora
Website:google.com

pg. 25

You might also like