-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibFinePayment.py
206 lines (165 loc) · 7.24 KB
/
LibFinePayment.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
from tkinter import *
from PIL import ImageTk,Image
from tkinter import messagebox
import pymysql
from tkinter import font
###main
##root = Tk()
##root.title("Library")
##helv30 = font.Font(family='Helvetica', size=30)
##helv23 = font.Font(family='Helvetica', size=23)
##
###photo
##canv = Canvas(root, width=1000, height=1000, bg='white')
##canv.grid(row=0, column=0)
##resized_image2=Image.open("fine-clipart.jpeg").resize((500,550), Image.ANTIALIAS)
##image2 = ImageTk.PhotoImage(resized_image2)
##canv.create_image(100, 175, anchor=NW, image=image2)
##
###heading
##canv.create_text(500, 100, text="Fines", fill="black", font=('Roman 70 bold'))
##canv.pack()
##
##canv.create_text(750, 300, text="Please select an option:", fill="black", font=('Helvetica 20 bold'))
##canv.pack()
##
##
###FUNCTIONS
##def Back():
## textentry = Entry(root, width = 20)
## textentry.place(relx=0.25,rely=0.1, relwidth=0.5, relheight=0.8)
#FINEPAYMENT
def finePayment():
global en1, en2, en3, Canvas1, connection, cursor, bookTable, root
root = Tk()
root.title("library")
root.minsize(width=400,height=400)
root.geometry("600x500")
#add your own database name and password here to reflect in the code
mypass = "pw"
mydatabase = "library"
connection = pymysql.connect(host="localhost", user="root", password=mypass, database=mydatabase)
cursor = connection.cursor()
# Create the canvas for info
Canvas1 = Canvas(root)
Canvas1.config(bg="RosyBrown1")
Canvas1.pack(expand=True, fill=BOTH)
# Add a heading Frame
headingFrame1 = Frame(root, bg="RosyBrown1", bd=5)
headingFrame1.place(relx=0.25, rely=0.1, relwidth=0.5, relheight=0.13)
headingLabel = Label(headingFrame1, text="Fine Payment", bg="white", fg="black", font=('Courier',30))
headingLabel.place(relx=0, rely=0, relwidth=1, relheight=1)
# Frame for form
LabelFrame1 = Frame(root, bg="RosyBrown1")
LabelFrame1.place(relx=0.03, rely=0.3, relwidth=1, relheight=0.6)
lb = Label(LabelFrame1, text="To pay a fine, please enter the required information below: ", bg="RosyBrown1", fg="black")
lb.place(relx=0, rely=0, relheight=0.08)
lb.config(font=("Courier", 14))
# Frame for form
LabelFrame = Frame(root, bg="RosyBrown3")
LabelFrame.place(relx=0.1, rely=0.37, relwidth=0.8, relheight=0.4)
# Membership ID
lb1 = Label(LabelFrame, text="Membership ID: ", bg="RosyBrown3", fg="black")
lb1.place(relx=0.05, rely=0.2, relheight=0.15)
# Entry label for Membership ID
en1 = Entry(LabelFrame)
en1.place(relx=0.35, rely=0.2, relwidth=0.62, relheight=0.15)
# Payment Date
lb2 = Label(LabelFrame, text="Payment Date \n (YYYY-MM-DD): ", bg="RosyBrown3", fg="black")
lb2.place(relx=0.05, rely=0.4, relheight=0.15)
# Entry label for Payment Date
en2 = Entry(LabelFrame)
en2.place(relx=0.35, rely=0.4, relwidth=0.62, relheight=0.15)
# Payment Amount
lb3 = Label(LabelFrame, text="Payment Amount: ", bg="RosyBrown3", fg="black")
lb3.place(relx=0.05, rely=0.6, relheight=0.15)
# Entry label for Payment Amount
en3 = Entry(LabelFrame)
en3.place(relx=0.35, rely=0.6, relwidth=0.62, relheight=0.15)
# Submit Button
SubmitBtn = Button(root, text="Pay Fine", bg="#d1ccc0", fg="black", command=confirmFineDetails)
SubmitBtn.place(relx=0.17, rely=0.85, relwidth=0.25, relheight=0.09)
# Quit Button
QuitBtn = Button(root, text="Back to \n Fines Menu", bg="#f7f1e3", fg="black", command=root.destroy)
QuitBtn.place(relx=0.60, rely=0.85, relwidth=0.25, relheight=0.09)
root.mainloop()
#CONFIRMFINEDETAILS
def confirmFineDetails():
global root
root = Tk()
root.title("library")
root.minsize(width=400, height=400)
root.geometry("250x200")
Canvas1 = Canvas(root)
Canvas1.config(bg="RosyBrown1")
Canvas1.pack(expand=True, fill=BOTH)
MemberID = en1.get()
PaymentDate = en2.get()
PaymentAmountStr = en3.get()
try:
cursor.execute("SELECT * FROM Fine WHERE MemberID = '" + MemberID + "'")
records = cursor.fetchall()
ActualFineAmount = records[0][1]
except:
messagebox.showinfo("Error", "Invalid Membership ID.")
root.withdraw()
try:
PaymentAmountInt = int(en3.get())
ActualFineAmount = records[0][1]
if ActualFineAmount == 0:
messagebox.showinfo("Error!", "Member has no fine")
root.withdraw()
elif PaymentAmountInt != ActualFineAmount:
messagebox.showinfo("Error!", "Incorrect fine payment amount")
root.withdraw()
else:
headingFrame1 = Frame(root, bg="RosyBrown1", bd=5)
headingFrame1.place(relx=0.25, rely=0.1, relwidth=0.5, relheight=0.13)
# Add a leabel to heading Frame
headingLabel = Label(headingFrame1, text="Confirm details", bg="white", fg="black", font=('Courier',15))
headingLabel.place(relx=0, rely=0, relwidth=1, relheight=1)
# Add a label frame to canvas
LabelFrame = Frame(root, bg="RosyBrown3")
LabelFrame.place(relx=0.02, rely=0.35, relwidth=0.96, relheight=0.4)
lb1 = Label(LabelFrame, text="Member ID: " + MemberID, bg="RosyBrown3", fg="black")
lb1.place(relx=0.01, rely=0.05)
lb1.config(font=("Courier", 11))
lb2 = Label(LabelFrame, text="Payment Amount: " + PaymentAmountStr, bg="RosyBrown3", fg="black")
lb2.place(relx=0.01, rely=0.2)
lb2.config(font=("Courier", 11))
lb3 = Label(LabelFrame, text="Payment Date (YYYY-MM-DD): " + PaymentDate, bg="RosyBrown3", fg="black")
lb3.place(relx=0.01, rely=0.35)
lb3.config(font=("Courier", 11))
Confirm = Button(root, text="Confirm Payment", bg="RosyBrown3", fg="black", command=confirmPayment)
Confirm.place(relx=0.04, rely=0.86, relwidth=0.35, relheight=0.10)
Back = Button(root, text="Return to \n Payment Function", bg="#f7f1e3", fg="black", command=root.destroy)
Back.place(relx=0.52, rely=0.86, relwidth=0.45, relheight=0.10)
except:
messagebox.showinfo("Error", "Invalid Payment Amount.")
root.withdraw()
root.mainloop()
#CONFIRMPAYMENT
def confirmPayment():
MemberID = en1.get()
PaymentDate = en2.get()
try:
# Update Fine Amount & DatePaid
sql_update_query = """Update Fine SET Amount = 0, DatePaid = %s WHERE MemberID = %s"""
val = (PaymentDate, MemberID)
cursor.execute(sql_update_query,val)
connection.commit()
messagebox.showinfo("Success!", "Payment successfully made")
except:
# Checking for invalid payment date input
messagebox.showinfo("Error", "Invalid Payment Date. Please key in YYYY-MM-DD format.")
root.withdraw()
root.mainloop()
###Buttons
##btnReservation = Button(root,text="Fine Payment",bg='black', fg='black',command=finePayment)
##btnReservation.place(relx=0.6,rely=0.45, relwidth=0.3, relheight=0.1)
##btnReservation['font'] = helv30
##
##btnBack = Button(root,text="Back to Main Menu",bg='black', fg='black',command=Back)
##btnBack.place(relx=0.4,rely=0.925, relwidth=0.2, relheight=0.05)
##
##root.mainloop()