0% found this document useful (0 votes)
10 views5 pages

MySQL Report Generation in Python

This Python code defines functions for a parking management system. It connects to a MySQL database and defines functions for user login, vehicle login/logout, searching the database, generating reports on parking types, space availability, vehicle status, and money collected. The main menu calls these functions to allow users to interact with the parking management system.

Uploaded by

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

MySQL Report Generation in Python

This Python code defines functions for a parking management system. It connects to a MySQL database and defines functions for user login, vehicle login/logout, searching the database, generating reports on parking types, space availability, vehicle status, and money collected. The main menu calls these functions to allow users to interact with the parking management system.

Uploaded by

Shreyas Mishra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Code

April 3, 2022

[ ]: import [Link]
import time
from datetime import date

global conn,cursor
conn = [Link]( port = '3306',
host='localhost', database=' parking_system', user='root',␣
,→password='12345678')

cursor = [Link]()

def introduction():
print( '''___________________________________________\nWelcome to the␣
,→Parking Management Software \n___________________________________________''')

def display_parking_type_records():
[Link]('select * from parking_type;')
records = [Link]()
for row in records:
print(row)

def login():
while True:
uname = input('Enter your ID :')
upass = input('Enter your Password :')
[Link]('select * from login where name="{}" and pwd ="{}"'.
,→format(uname,upass))

[Link]()
rows = [Link]
if rows!=1:
print('Invalid Login details. Try again!')
else:

1
print('Login Successfull')
break

def add_new_vehicle():
print('Vehicle Login Screen ')
print('_'*100)
vehicle_id = input('Enter Vehicle Number :' )
parking_id = input('Enter Parking ID :')
entry_date = [Link]()
sql = 'insert into transaction(vehicle_id,parking_id,entry_date) values \
("{}","{}","{}");'.format(vehicle_id,parking_id,entry_date)
[Link](sql)
[Link]('update parking_space set status ="full" where id ={}'.
,→format(parking_id))

print('Record added successfully.')

def remove_vehicle():
print('Vehicle Logout Screen')
print('_'*100)
vehicle_id = input('Enter Vehicle No :')
exit_date = [Link]()
sql = 'select parking_id,price,entry_date from transaction tr,parking_space␣
,→ps, parking_type pt \

where tr.parking_id = [Link] and ps.type_id = [Link] and \


vehicle_id ="'+vehicle_id+'" and exit_date is NULL;'
[Link](sql)
record = [Link]()
days = (exit_date-record[2]).days
if days ==0:
days = days+1
amount = record[1]*days

print('BILL ')
print('_'*100)
print('Parking ID : {}'.format(record[0]))
print('Vehicle ID : {}'.format(vehicle_id))
print('Parking Date : {}'.format(record[2]))
print('Current Date : {}'.format(exit_date))
print('Amount Payable : {}'.format(amount))
wait = input('Press any key to continue.')

2
sql1 = 'update transaction set exit_date ="{}" , amount ={} where vehicle_id␣
,→="{}" \
and exit_date is NULL;'.format(exit_date,amount, vehicle_id)
sql2 = 'update parking_space set status ="open" where id = {}'.
,→format(record[0])

[Link](sql1)
[Link](sql2)

def search_menu():
print('_'*43 + '\nSEARCH\n'+'_'*43)
print('[Link] for Parking ID \n'+'_'*43)
print('[Link] for Vehicle Parked\n'+'_'*43)
choice = int(input())
field = ''
if choice == 1:
field = 'id'
if choice == 2:
field = 'vehicle No'
value = input('Enter value to search :')
if choice == 1:
sql = 'select [Link],name,price, status \
from parking_space ps , parking_type pt where [Link] = [Link] AND [Link]␣
,→={}'.format(value)

else:
sql = 'select id,vehicle_id,parking_id,entry_date from transaction where␣
,→exit_date is NULL;'

[Link](sql)
results = [Link]()
records = [Link]
for row in results:
print(row)
if records < 1:
print('Record not found.')
wait = input('Press any key to continue.')

def parking_status(status):
print('Parking Status :',status)
print('-'*100)
sql ="select * from parking_space where status ='{}'".format(status)
[Link](sql)
records = [Link]()
for row in records:
print(row)
wait =input('Press any key to continue.')

3
def vehicle_status_report():
print('Vehicle Status - Currently Parked')
print('-'*100)
sql='select * from transaction where exit_date is NULL;'
[Link](sql)
records = [Link]()
for row in records:
print(row)
wait =input('Press any key to continue.')

def money_collected():
start_date = input('Enter start Date(yyyy-mm-dd): ')
end_date = input('Enter End Date(yyyy-mm-dd): ')
sql = "select sum(amount) from transaction where \
entry_date ='{}' and exit_date ='{}'".format(start_date,end_date)
[Link](sql)
result = [Link]()
print('Total money Collected from {} to {}'.format(start_date,end_date))
print('-'*100)
print(result[0])
wait =input('Press any key to continue.')

def report_menu():
while True:
print('REPORTS\n'+'_'*43)
print('[Link] Types\n'+'_'*43)
print('[Link] Space\n'+'_'*43)
print('[Link] Space\n'+'_'*43)
print('[Link] Status \n'+'_'*43)
print('[Link] Collected\n'+'_'*43)
print('[Link]\n'+'_'*43)
choice = int(input())
field = ''
if choice == 1:
display_parking_type_records()
if choice == 2:
parking_status("open")
if choice == 3:
parking_status("full")
if choice == 4:
vehicle_status_report()
if choice == 5:
money_collected()
if choice ==6:
break

4
def main_menu():
login()
introduction()

while True:
print('MENU')
print('_'*43)
print('1. Vehicle Login\n'+'_'*43)
print('2. Vehicle Logout\n'+'_'*43)
print('3. Search\n'+'_'*43)
print('4. Reports\n'+'_'*43)
choice = int(input())

if choice == 1:
add_new_vehicle()

if choice == 2:
remove_vehicle()

if choice == 3:
search_menu()

if choice == 4:
report_menu()

if __name__ == "__main__":
main_menu()

You might also like