-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.py
214 lines (195 loc) · 8.26 KB
/
transaction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import mysql.connector as mycon
from mysql.connector.errors import Error
from mysql.connector import errorcode
con=mycon.connect(host="localhost", user="root",password="tanish",database="CARRENTAL")
cur=con.cursor()
def createtable():
global con,cur
cur.execute("create table if not exists transaction(TNo int PRIMARY KEY ,CarID int,CID int,cname varchar(15),DOI date,DOR date,Fine int,TOR int, FOREIGN KEY(CarID) REFERENCES Cars (CarID),FOREIGN KEY(cid) REFERENCES customer(cid))")
con.commit()
cur.execute("show tables")
for x in cur:
print(x)
#createtable()
def addtransaction():
global con,cur
try:
TNo=int(input('Enter Transaction No. : '))
CarID=int(input('Enter car id. : '))
cid=int(input('Enter customer id. : '))
cname=input("Enter customer name : ")
DOI=input("Enter date of issue of car : ")
DOR='0000-00-00'
Fine=int(input('Enter Fine (caution deposit) : '))
TOR=int(input("Enter time of rental of car (no. of days) : "))
query="insert into transaction values(%s,%s,%s,%s,%s,%s,%s,%s)"
data=(str(TNo),str(CarID),str(cid),cname,DOI,DOR,str(Fine),str(TOR))
cur.execute(query,data)
con.commit()
print('NEW TRANSACTION ADDED SUCCESSFULLY')
query="update cars set Status= 'NOT AVAILABLE' where CarID ='{}'".format(CarID)
cur.execute(query)
con.commit()
except ValueError:
print('Unable to add data because of incorrect data type ')
except mysql.connector.Error as err:
if err.errno==errcode.ER_BAD_DB_ERROR:
print('Wrong database selected ',err)
elif err.errno==errcode.ER_BAD_TABLE_ERROR:
print('Wrong table selected')
else:
print('Other error',err)
#addtransaction()
def returntransaction():
global con,cur
TNo=int(input("Enter Transaction number of car to be returned : "))
print()
print("************************RETURN TRANSACTION DETAILS****************************")
query="select * from transaction where TNo={}".format(TNo)
cur.execute(query)
results=cur.fetchall()
if cur.rowcount<=0:
print("\n#### SORRY! No Matching Details Available####")
else:
print('*'*78)
print('%5s'%'TNo','%5s'%'CarID','%5s'%'CID','%15s'%'Customer Name','%15s'%'DOI','%15s'%'DOR','%5s'%'Fine','%5s'%'TOR')
print('*'*78)
for row in results:
print('%5s'% row[0],'%5s'% row[1],'%5s'% row[2],'%15s'% row[3],'%15s'% row[4],'%15s'%row[5],'%5s'%row[6],'%5s'%row[7])
print('*'*78)
ans=input("Are you sure to return(y/n)?")
if ans=="y" or ans=="Y":
DOR=input("Enter date of return : ")
Fine=int(input("Enter Fine Imposed : "))
query="update transaction set DOR='{}',Fine={} where TNo={}".format(DOR,Fine,TNo)
cur.execute(query)
con.commit()
print("\n##Transaction Updated##")
print()
print('\t','-'*37)
print('\t\t CAR RENTAL')
print('\t','-'*37)
print()
print('\t\t Tax Invoice')
print()
print('\t\t\t Date :',DOR)
print('\t Transaction Number :',TNo)
print('\t Car ID :',row[1])
print('\t Customer ID :',row[2])
print('\t Fine : Dhs.',Fine)
print()
print('\t','-'*37)
print('\t Mobile No. : 050-4524242')
print('\t Telephone No. : 02-6555313')
print('\t Email Id : [email protected]')
print('\t','-'*37)
#returntransaction()
def displaytransaction():
global con,cur
print("***************************DISPLAY CARS RENTED********************************")
query="select * from transaction"
cur.execute(query)
results=cur.fetchall()
if cur.rowcount<=0:
print("\n#### SORRY! No Matching Details Available####")
else:
print('*'*78)
print('%5s'%'TNo','%5s'%'CarID','%5s'%'CID','%15s'%'Customer Name','%15s'%'DOI','%15s'%'DOR','%5s'%'Fine','%5s'%'TOR')
print('*'*78)
cnt=0
for row in results:
print('%5s'% row[0],'%5s'% row[1],'%5s'% row[2],'%15s'% row[3],'%15s'% row[4],'%15s'%row[5],'%5s'%row[6],'%5s'%row[7])
cnt+=1
print("*"*27,'No of Transactions :',cnt,"*"*27)
#displaytransaction()
def displaytransactioncustomer():
global con,cur
cid=int(input("Enter customer id to display transaction : "))
print()
print("***************************DISPLAY CARS RENTED********************************")
query="select * from transaction where cid ={}".format(cid)
cur.execute(query)
results=cur.fetchall()
if cur.rowcount<=0:
print("\n#### SORRY! No Matching Details Available####")
else:
print('*'*78)
print('%5s'%'TNo','%5s'%'CarID','%5s'%'CID','%15s'%'Customer Name','%15s'%'DOI','%15s'%'DOR','%5s'%'Fine','%5s'%'TOR')
print('*'*78)
cnt=0
for row in results:
print('%5s'% row[0],'%5s'% row[1],'%5s'% row[2],'%15s'% row[3],'%15s'% row[4],'%15s'%row[5],'%5s'%row[6],'%5s'%row[7])
cnt+=1
print("*"*27,'No of Transactions :',cnt,"*"*27)
#displaytransactioncustomer()
def displaytransactioncar():
global con,cur
CarID=int(input("Enter car id to display transaction : "))
print()
print("***************************DISPLAY CARS RENTED********************************")
query="select * from transaction where CarID ={}".format(CarID)
cur.execute(query)
results=cur.fetchall()
if cur.rowcount<=0:
print("\n#### SORRY! No Matching Details Available####")
else:
print('*'*78)
print('%5s'%'TNo','%5s'%'CarID','%5s'%'CID','%15s'%'Customer Name','%15s'%'DOI','%15s'%'DOR','%5s'%'Fine','%5s'%'TOR')
print('*'*78)
cnt=0
for row in results:
print('%5s'% row[0],'%5s'% row[1],'%5s'% row[2],'%15s'% row[3],'%15s'% row[4],'%15s'%row[5],'%5s'%row[6],'%5s'%row[7])
cnt+=1
print("*"*27,'No of Transactions :',cnt,"*"*27)
#displaytransactioncar()
def updatetransaction():
global con,cur
TNo=int(input("Enter Transaction number to be updated : "))
print()
print("************************UPDATE TRANSACTION DETAILS***************************")
query="select * from transaction where TNo={}".format(TNo)
cur.execute(query)
results=cur.fetchall()
if cur.rowcount<=0:
print("\n#### SORRY! No Matching Details Available####")
else:
print('*'*78)
print('%5s'%'TNo','%5s'%'CarID','%5s'%'CID','%15s'%'Customer Name','%15s'%'DOI','%15s'%'DOR','%5s'%'Fine','%5s'%'TOR')
print('*'*78)
for row in results:
print('%5s'% row[0],'%5s'% row[1],'%5s'% row[2],'%15s'% row[3],'%15s'% row[4],'%15s'%row[5],'%5s'%row[6],'%5s'%row[7])
print('*'*78)
ans=input("Are you sure to update(y/n)?")
if ans=="y" or ans=="Y":
DOR=input("Enter updated date of return : ")
Fine=int(input("Enter Fine Imposed : "))
TOR=int(input("enter updated time of rental"))
query="update transaction set DOR='{}',Fine={},TOR={} where TNo={}".format(DOR,Fine,TOR,TNo)
cur.execute(query)
con.commit()
print("\n##Transaction Updated##")
#updatetransaction()
def deletetransaction():
global con,cur
TNo=int(input("Enter Transaction Number to be deleted : "))
print()
print("*****************************DELETE TRANSACTION*******************************")
query="select * from transaction where TNo={}".format(TNo)
cur.execute(query)
results=cur.fetchall()
if cur.rowcount<=0:
print("\n##Sorry! No Matching details available##")
else:
print('*'*78)
print('%5s'%'TNo','%5s'%'CarID','%5s'%'CID','%15s'%'Customer Name','%15s'%'DOI','%15s'%'DOR','%5s'%'Fine','%5s'%'TOR')
print('*'*78)
for row in results:
print('%5s'% row[0],'%5s'% row[1],'%5s'% row[2],'%15s'% row[3],'%15s'% row[4],'%15s'%row[5],'%5s'%row[6],'%5s'%row[7])
print('*'*78)
ans=input("Are you sure to delete?(y/n)")
if ans=='y' or ans=='Y':
query="delete from transaction where TNo={}".format(TNo)
cur.execute(query)
con.commit()
print("\n##Record Deleted##")
#deletetransaction()