`
TABLE OF CONTENT:
[Link]
[Link] CONFIGURATION
[Link]
[Link] OF THE PROJECT
[Link] SYSTEM
[Link] AND FUNCTIONS USED
[Link]
[Link]
[Link] (SCREENSHOT)
[Link]
[Link]
`4
`
INTRODUCTION
"BAKERY MANAGEMENT SYSTEM" This project is useful for the bakery
employees as well as customers to keep a track of shop details. The emerging of
digital system made information available on finger tips. By automating the
transactions one can view the details as and when required in no time. This
project emphases on creation of new customer records,new items in the
menu,no. of items, by making digital system one can generate daily reports,
monthly reports and annual reports which can enhance the system.
OBJECTIVES OF THE PROJECT
The objective of this project is to let the students apply the programming
knowledge into a real- world situation/problem and exposed the students how
programming skills helps in developing a good software.
1. Write programs utilizing modern software tools.
2. Apply object oriented programming principles effectively when developing
small to medium sized projects.
3. Write effective procedural code to solve small to medium sized problems.
4. Students will demonstrate a breadth of knowledge in computer science, as
exemplified in the areas of systems, theory and software development.
5. Students will demonstrate ability to conduct a research or applied Computer
Science project, requiring writing and presentation skills which exemplify
scholarly style in computer science.
BACKGROUND
The system used by the bakery was not automated. The transaction that were
carried out were done manually and recoding of data and stock entering were
kept in register or in paper that was time consuming and lot of data used to get
`7
`
lost. We automated the system by observed all the procedure done in the bakery
and made the system according to the step taken manually so that the users can
operate the system easily and quicker as the user now has to just select the
options and record transactions simultaneously unlike before when the
transactions had to be written down by hand at the end of each day.
FLAWS:
The manual system is unable to keep whole record of customers and product
and sales in bakery. There is a lot of chances of mistakes and miscalculation of
expenses and profits. So this all consumes a lot of time of users and lot of paper
work to handled.
PROPOSED SYSTEM:
Bakery doesn't have any proper recording system where they store their data,
they use to save their data on register or paper which can be lost or misplace
easily.
Bakery donot have the automatic way of generated bills. All the bills were
manually made there is lot of chance of mistake in calculating the data.
Structured Analysis
Structured Analysis is a subset of procedural programming that enforces a
logical structure on the program being written to make it more efficient and
easier to understand and modify.
A technique for analyzing a company's needs in which a hierarchy of modules is
used, cach having a single entry and a single exit point, and in which a control is
passed downward through the structure. A module cannot start till the previous
module is completed.
Advantages of Structured Analysis
`8
`
Easy to write Structure Program:
1. Modular design increases the programmer's productivity by allowing
them to look at the big picture.
2. Several Programmers can work on a single large program, each working
on a different module
3. Studies show that structured programs take less time to write than
standard programs.
4. Procedures written for one program can be reused in other programs
requiring the same task.
A procedure that can be used in many programs is said to be reusable.
Easy to debug a Structure Program:
Since each procedure is specialized to perform just one task, a procedure can be
checked individually. Older unstructured programs consist of a sequence of
instructions that are not grouped for specific tasks. The logic of such programs
is cluttered with details and therefore difficult to follow
Easy to Understand:
1. The relationship between the procedures shows the modular design of the
program.
2. Meaningful procedure names and clear documentation identify the task
performed
by each module. 3. Meaningful variable names help the programmer identify
the purpose of each variable.
`9
`
Disadvantages of Structured Analysis:
1. All errors need to be identified at cach stage.
2. Lack of opportunity to upgrade according to the drastically changing industry.
A project may take 2 years to be developed and get obsolete by the time it hits
the market.
3. Any changes if needed to be made to the previous module will affect the
whole project.
4. Any changes are costly.
5. The team members are not utilized correctly. While one team works others
are free.
LIBRARIES AND FUNCTIONS USED:
Libraries and Modules
1. json Library:
o Purpose: Used for working with JSON data, which is a common format for
data storage and exchange.
o Functions:
▪ [Link](): Writes a Python object (e.g., a dictionary) to a
file in JSON format.
▪ [Link](): Reads JSON data from a file and converts it into
a Python object (e.g., a dictionary).
`10
`
Functions and Methods Used
1. print() Function:
o Purpose: Outputs text to the console. o Usage: Used for displaying messages,
product information, and menus.
2. input() Function:
o Purpose: Reads a line of text from the user. o Usage: Used for
gathering user input, such as product names, prices, and quantities.
3. float() Function:
o Purpose: Converts a string to a floating-point number. o Usage:
Used to convert user input for product prices from string to float.
4. int() Function:
o Purpose: Converts a string to an integer. o Usage: Used to
convert user input for product quantities from string to integer.
5. Exception Handling:
o Purpose: Manages errors that may occur during file operations.
o Usage:
▪ try and except blocks are used to handle potential
FileNotFoundError exceptions when loading data from a
file.
MYSQL QUERIES USED IN THE PROJECT:
`11
`
In the bakery management system example provided earlier, no MySQL queries
are used because the data is handled using Python dictionaries and JSON files
for persistence. However, if you wanted to extend the system to use a MySQL
database, you would need to integrate SQL queries to interact with the database.
Here’s how you might structure MySQL queries for similar functionality:
Setting Up the MySQL Database
First, you need to set up a MySQL database and table to store the bakery’s
product information. Here’s a basic SQL script to create a table:
SQL Query:
INSERT INTO products (name, price, quantity)
VALUES (%s, %s, %s)
ON DUPLICATE KEY UPDATE
price = VALUES(price), quantity = quantity + VALUES(quantity);
Python Code:
import [Link]
def add_product(cursor, name, price, quantity):
query = """
INSERT INTO products (name, price, quantity)
VALUES (%s, %s, %s)
ON DUPLICATE KEY UPDATE
`12
`
price = VALUES(price), quantity = quantity + VALUES(quantity);
"""
[Link](query, (name, price, quantity)) print("Product
'{name}' added/updated successfully.")
View Products:
• SQL Query:
SELECT name, price, quantity FROM products;
• Python Code:
def view_products(cursor):
query = "SELECT name, price, quantity FROM products;"
[Link](query) results = [Link]() if not
results:
print("No products available.")
return print("Name':<15
,'Price':<10,'Quantity':<10") print("-" * 35)
for name, price, quantity in results:
print(“name:<15,price:<10,quantity:<10")
Update Quantity:
• SQL Query:
UPDATE products
`13
`
SET quantity = quantity - %s WHERE
name = %s AND quantity >= %s;
• Python Code:
def update_quantity(cursor, name, quantity):
query = """
UPDATE products
SET quantity = quantity - %s
WHERE name = %s AND quantity >= %s;
"""
[Link](query, (quantity, name, quantity))
if [Link]> 0:
print("Quantity of “,name,” updated successfully.")
else:
print("Insufficient quantity for '{name}' or product not found.")
Remove Product:
• SQL Query:
DELETE FROM products WHERE name = %s;
• Python Code:
def remove_product(cursor, name): query = "DELETE
FROM products WHERE name = %s;"
[Link](query, (name,))
if [Link]> 0:
print("Product '’,name,’' removed successfully.")
else:
print("Product “,name,” not found."
`14
`
SOURCE CODE:
import [Link]
from datetime import datetime
# ======================================================
# Database Connection
# ======================================================
def get_db_connection():
"""
Establish and return a database connection.
Update host, user, password, and database
according to your MySQL configuration.
"""
return [Link](
host="localhost",
user="your_username", # Replace with your MySQL username
password="your_password", # Replace with your MySQL password
database="bakery_db" # Replace with your database name
)
# ======================================================
# Query Execution Functions
# ======================================================
def execute_query(query, params=()):
"""
`15
`
Executes queries that modify the database.
Example: INSERT, UPDATE, DELETE.
"""
try:
conn = get_db_connection()
cursor = [Link]()
[Link](query, params)
[Link]()
except Exception as e:
print("Error executing query:", e)
finally:
[Link]()
[Link]()
def fetch_query(query, params=()):
"""
Executes queries that fetch data from the database.
Example: SELECT queries.
"""
try:
conn = get_db_connection()
cursor = [Link]()
[Link](query, params)
results = [Link]()
return results
except Exception as e:
`16
`
print("Error fetching data:", e)
return []
finally:
[Link]()
[Link]()
# ======================================================
# Product Management
# ======================================================
def add_product():
""" Add a new product to the bakery. """
name = input("Enter product name: ")
price = float(input("Enter product price: "))
quantity = int(input("Enter product quantity: "))
category = input("Enter product category (e.g., Bread, Cake, Cookies): ")
query = """
INSERT INTO products (name, price, quantity, category)
VALUES (%s, %s, %s, %s)
ON DUPLICATE KEY UPDATE
price = VALUES(price), quantity = quantity + VALUES(quantity);
"""
execute_query(query, (name, price, quantity, category))
print(f" Product '{name}' added/updated successfully!")
`17
`
def view_products():
""" Display all products with details. """
query = "SELECT id, name, price, quantity, category FROM products;"
results = fetch_query(query)
if not results:
print("No products available in inventory.")
return
print(f"{'ID':<5}{'Name':<20}{'Price':<12}{'Quantity':<10}{'Category':<15}")
print("-" * 65)
for pid, name, price, quantity, category in results:
print(f"{pid:<5}{name:<20}{price:<12}{quantity:<10}{category:<15}")
def update_quantity():
""" Update the stock quantity of a product. """
name = input("Enter product name: ")
qty = int(input("Enter quantity to remove: "))
query = """
UPDATE products
SET quantity = quantity - %s
WHERE name = %s AND quantity >= %s;
"""
execute_query(query, (qty, name, qty))
print(f" Quantity updated for '{name}'.")
`18
`
def remove_product():
""" Delete a product permanently. """
name = input("Enter product name to remove: ")
query = "DELETE FROM products WHERE name = %s;"
execute_query(query, (name,))
print(f" Product '{name}' removed successfully.")
def search_product():
""" Search for a product using partial name. """
keyword = input("Enter product name to search: ")
query = "SELECT id, name, price, quantity, category FROM products
WHERE name LIKE %s;"
results = fetch_query(query, (f"%{keyword}%",))
if not results:
print(f"No products found with name containing '{keyword}'.")
return
print(f"{'ID':<5}{'Name':<20}{'Price':<12}{'Quantity':<10}{'Category':<15}")
print("-" * 65)
for pid, name, price, quantity, category in results:
print(f"{pid:<5}{name:<20}{price:<12}{quantity:<10}{category:<15}")
`19
`
def update_price():
""" Update the price of a product. """
name = input("Enter product name to update price: ")
new_price = float(input("Enter new price: "))
query = "UPDATE products SET price = %s WHERE name = %s;"
execute_query(query, (new_price, name))
print(f" Price of '{name}' updated successfully.")
def view_product_by_id():
""" Search product by unique ID. """
pid = int(input("Enter product ID: "))
query = "SELECT id, name, price, quantity, category FROM products
WHERE id = %s;"
result = fetch_query(query, (pid,))
if not result:
print(f"No product found with ID {pid}.")
return
print(f"{'ID':<5}{'Name':<20}{'Price':<12}{'Quantity':<10}{'Category':<15}")
print("-" * 65)
for product in result:
print(f"{product[0]:<5}{product[1]:<20}{product[2]:<12}{product[3]:<10}{pr
oduct[4]:<15}")
`20
`
def view_low_stock():
""" Show products below a stock threshold. """
threshold = int(input("Enter the stock threshold: "))
query = "SELECT id, name, price, quantity, category FROM products
WHERE quantity < %s;"
results = fetch_query(query, (threshold,))
if not results:
print("No products are below the stock threshold.")
return
print(f"{'ID':<5}{'Name':<20}{'Price':<12}{'Quantity':<10}{'Category':<15}")
print("-" * 65)
for pid, name, price, qty, category in results:
print(f"{pid:<5}{name:<20}{price:<12}{qty:<10}{category:<15}")
# ======================================================
# Sales Management
# ======================================================
def record_sale():
""" Record a sale (like billing). """
product_id = int(input("Enter product ID: "))
qty = int(input("Enter quantity sold: "))
sale_time = [Link]().strftime("%Y-%m-%d %H:%M:%S")
# Deduct from stock
`21
`
query = "UPDATE products SET quantity = quantity - %s WHERE id = %s
AND quantity >= %s;"
execute_query(query, (qty, product_id, qty))
# Insert into sales table
query = "INSERT INTO sales (product_id, quantity, sale_time) VALUES
(%s, %s, %s);"
execute_query(query, (product_id, qty, sale_time))
print(f" Sale recorded for product ID {product_id}.")
def view_sales_report():
""" Display sales history. """
query = """
SELECT [Link], [Link], [Link], s.sale_time
FROM sales s
JOIN products p ON s.product_id = [Link];
"""
results = fetch_query(query)
if not results:
print("No sales recorded yet.")
return
print(f"{'SaleID':<8}{'Product':<20}{'Quantity':<10}{'Time':<20}")
print("-" * 60)
for sid, pname, qty, time in results:
`22
`
print(f"{sid:<8}{pname:<20}{qty:<10}{time:<20}")
# ======================================================
# Main Program Menu
# ======================================================
def main():
while True:
print("\n========= Bakery Management System =========")
print("1. Add Product")
print("2. View All Products")
print("3. Update Product Quantity")
print("4. Remove Product")
print("5. Search Product by Name")
print("6. Update Product Price")
print("7. View Product by ID")
print("8. View Low Stock Products")
print("9. Record Sale")
print("10. View Sales Report")
print("11. Exit")
print("============================================")
choice = input("Enter your choice: ")
if choice == '1':
add_product()
elif choice == '2':
`23
`
view_products()
elif choice == '3':
update_quantity()
elif choice == '4':
remove_product()
elif choice == '5':
search_product()
elif choice == '6':
update_price()
elif choice == '7':
view_product_by_id()
elif choice == '8':
view_low_stock()
elif choice == '9':
record_sale()
elif choice == '10':
view_sales_report()
elif choice == '11':
confirm = input("Are you sure you want to exit? (y/n): ")
if [Link]() == 'y':
print("Exiting the system. Goodbye!")
break
else:
print("Invalid choice. Please enter a valid option (1-11).")
# ======================================================
`24
`
# Run the program
# ======================================================
if __name__ == "__main__":
main()
OUTPUT(SCREENSHOTS):
Here’s a sample of what the output might look like when running the bakery
management system with MySQL integration. For simplicity, I'll illustrate
typical outputs for various operations based on the command-line interface
provided in the program.
1. Main Menu
.
2. Add Product
`25
`
OUTPUT:
3. View Products
If you choose to view products:
Output (assuming "Chocolate Cake" is the only product):
4. Update Quantity
If you decide to update the quantity of a product:
`26
`
Output:
5. View Products Again
To verify the update:
Output:
6. Remove Product
If you want to remove a product:
`27
`
OUTPUT
7. View Products After Removal
To check if the product was removed:
OUTPUT
8. Exit Program
To exit the program:
OUTPUT
`28
`
CompleteRun of program
Here’s a complete example of how a session might look from start to finish:
`29
`
`30
`
Summary
The output shows typical interactions with the bakery management system,
reflecting the addition, viewing, updating, and removal of products. It also
demonstrates how the system responds to these actions and provides feedback to
the user.
Conclusion
The bakery management system developed using Python and MySQL provides
a robust foundation for managing inventory in a bakery setting. The system
allows users to perform essential operations such as adding new products,
updating product quantities, viewing current inventory, and removing products.
This computerized system store all the data in the database which makes it easy
to fetch and update whenever needed.
`31
`
BIBILOGRAPHY:
Computer Science With Python by Sumita Arora for Class 11 AND 12
HTTPS://[Link]/PYTHON/PYTHON_MYSQL_
[Link]
HTTPS://[Link]/PYTHON/PYTHON_DATABA
SE_ACCESS.HTM HTTPS://[Link]/MYSQL-WITH-
PYTHON/
`32