-
Notifications
You must be signed in to change notification settings - Fork 7
/
gym.py
6322 lines (5060 loc) · 259 KB
/
gym.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import customtkinter as ctk
import tkinter as tk
from tkinter import messagebox, simpledialog, ttk
from PIL import Image, ImageTk
from tkcalendar import DateEntry
import os
import io
import shutil
import sqlite3
import random
import string
import qrcode
import cv2
import datetime
import requests
import calendar
import numpy as np
from datetime import datetime
from dateutil.relativedelta import relativedelta
from datetime import timedelta
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from tkinter import filedialog, PhotoImage
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("green")
def change_appearance_mode_event(new_appearance_mode):
ctk.set_appearance_mode(new_appearance_mode)
def send_sms_notification(to_phone_number, message):
print("PHONE NUMBER", to_phone_number)
print("MESSAGE", message)
# Use environment variables or a configuration file to manage API keys
api_key=''
# Change this URL based on your requirements
url='https://api.semaphore.co/api/v4/priority'
payload={
'apikey': api_key,
'number': to_phone_number,
'message': message
}
# Handle specific exceptions
try:
response=requests.post(url, data=payload)
if response.status_code == 200:
print("SEND MESSAGE SUCCESS")
print(response.json())
else:
print(response.text)
print("ERROR SENDING MESSAGE")
print("STATUS CODE", response.status_code)
except requests.exceptions.RequestException as req_exc:
print("Request Exception:", req_exc)
except Exception as e:
print("Failed to send message", e)
def check_date():
current_date=datetime.now()
# Get all instances in the registration table
conn=sqlite3.connect('SQLite db/registration_form.db')
cursor=conn.cursor()
cursor.execute("SELECT * FROM registration")
registrations=cursor.fetchall()
for registration in registrations:
# Get the end_date and contact_no from the registration
end_date=registration[15]
contact_no=registration[9]
print("Testing: ", end_date)
if datetime.strptime(end_date, '%Y-%m-%d') < current_date:
print("Expired")
# Update the status of the registration to "Expired"
cursor.execute("UPDATE registration SET status=? WHERE id=?", ("Expired", registration[0]))
conn.commit()
# Send SMS to the member
sms_message="Your gym membership has expired. Renew your subscription to continue accessing D'GRIT GYM."
send_sms_notification(contact_no, sms_message)
# create a function that sends sms for 3 days before expiration
def send_sms_for_expiration():
current_date=datetime.now()
# Get all instances in the registration table
conn=sqlite3.connect('SQLite db/registration_form.db')
cursor=conn.cursor()
cursor.execute("SELECT * FROM registration")
registrations=cursor.fetchall()
for registration in registrations:
# Get the end_date and contact_no from the registration
end_date=registration[15]
contact_no=registration[9]
# Check if the end_date is 3 days from the current date
if datetime.strptime(end_date, '%Y-%m-%d') == current_date + timedelta(days=3):
print("3 days before expiration")
# Send SMS to the member
sms_message="Your gym membership will expire in 3 days. Renew your subscription to continue accessing D'GRIT GYM."
send_sms_notification(contact_no, sms_message)
# MAIN APPLICATION
class MainApp(ctk.CTk):
def __init__(self):
super().__init__()
# Fixed size of the window, and cannot be resized
self.resizable(False, False)
self.title("D'Grit Gym")
self.geometry("1240x600")
# Calculate the screen width and height
screen_width=self.winfo_screenwidth()
screen_height=self.winfo_screenheight()
# Calculate the position to center the window
x=(screen_width - 1240) // 2
y=(screen_height - 600) // 2.5
# Set the window's position
self.geometry(f"1240x600+{x}+{y}")
# Set grid layout 1x2
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=1)
# load images with light and dark mode image
image_path=os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates/test_images")
self.logo_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "gym_dark.png")),
dark_image=Image.open(os.path.join(image_path, "gym_dark.png")),
size=(150, 60))
self.gym_image=ctk.CTkImage(
Image.open(os.path.join(image_path, "gym_cover.png")),
size=(500, 150))
self.image_icon_image=ctk.CTkImage(
Image.open(os.path.join(image_path, "image_icon_light.png")),
size=(20, 20))
self.home_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "home_dark.png")),
dark_image=Image.open(os.path.join(image_path, "home_light.png")), size=(20, 20))
self.chat_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "chat_dark.png")),
dark_image=Image.open(os.path.join(image_path, "chat_light.png")), size=(20, 20))
self.add_user_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "add_user_dark.png")),
dark_image=Image.open(os.path.join(image_path, "add_user_light.png")), size=(20, 20))
self.add_equipment_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "dumbell_dark.png")),
dark_image=Image.open(os.path.join(image_path, "dumbell_light.png")), size=(20, 20))
self.visitor_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "visitor_dark.png")),
dark_image=Image.open(os.path.join(image_path, "visitor_light.png")), size=(20, 20))
self.employee_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "employee_black.png")),
dark_image=Image.open(os.path.join(image_path, "employee_white.png")), size=(20, 20))
self.trainer_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "trainer_black.png")),
dark_image=Image.open(os.path.join(image_path, "trainer_white.png")), size=(20, 20))
self.attendance_image=ctk.CTkImage(
light_image=Image.open(os.path.join(image_path, "scan_black.png")),
dark_image=Image.open(os.path.join(image_path, "scan_white.png")), size=(20, 20))
# create navigation frame
self.navigation_frame=ctk.CTkFrame(self, corner_radius=0)
self.navigation_frame.grid(row=0, column=0, sticky="nsew")
self.navigation_frame.grid_rowconfigure(12, weight=1)
self.navigation_frame_label=ctk.CTkLabel(
self.navigation_frame, text="", image=self.logo_image,
compound="left", font=ctk.CTkFont(size=15, weight="bold"))
self.navigation_frame_label.grid(row=0, column=0, padx=20, pady=20)
self.home_button=ctk.CTkButton(
self.navigation_frame, corner_radius=0, height=50, border_spacing=10,
text="Home",
fg_color="transparent", text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
image=self.home_image, anchor="w", command=self.home_button_event)
self.home_button.grid(row=1, column=0, sticky="ew")
self.frame_2_button=ctk.CTkButton(
self.navigation_frame, corner_radius=0, height=50, border_spacing=10,
text="Membership",
fg_color="transparent", text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
image=self.add_user_image, anchor="w", command=self.frame_2_button_event)
self.frame_2_button.grid(row=2, column=0, sticky="ew")
self.frame_3_button=ctk.CTkButton(
self.navigation_frame, corner_radius=0, height=50, border_spacing=10,
text="Take Attendance",
fg_color="transparent", text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
image=self.attendance_image, anchor="w", command=self.frame_3_button_event)
self.frame_3_button.grid(row=3, column=0, sticky="ew")
self.frame_4_button=ctk.CTkButton(
self.navigation_frame, corner_radius=0, height=50, border_spacing=10,
text="Gym Equipment",
fg_color="transparent", text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
image=self.add_equipment_image, anchor="w", command=self.frame_4_button_event)
self.frame_4_button.grid(row=4, column=0, sticky="ew")
self.frame_5_button=ctk.CTkButton(
self.navigation_frame, corner_radius=0, height=50, border_spacing=10,
text="Trainers",
fg_color="transparent", text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
image=self.trainer_image, anchor="w", command=self.frame_5_button_event)
self.frame_5_button.grid(row=5, column=0, sticky="ew")
self.frame_6_button=ctk.CTkButton(
self.navigation_frame, corner_radius=0, height=50, border_spacing=10,
text="Gymers",
fg_color="transparent", text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
image=self.visitor_image, anchor="w", command=self.frame_6_button_event)
self.frame_6_button.grid(row=6, column=0, sticky="ew")
self.frame_7_button=ctk.CTkButton(
self.navigation_frame, corner_radius=0, height=50, border_spacing=10,
text="Employees",
fg_color="transparent", text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
image=self.employee_image, anchor="w", command=self.frame_7_button_event)
self.frame_7_button.grid(row=7, column=0, sticky="ew")
self.frame_8_button=ctk.CTkButton(
self.navigation_frame, corner_radius=0, height=50, border_spacing=10,
text="Create User Account",
fg_color="transparent", text_color=("gray10", "gray90"),
hover_color=("gray70", "gray30"),
image=self.add_user_image, anchor="w", command=self.frame_8_button_event)
self.frame_8_button.grid(row=8, column=0, sticky="ew")
self.appearance_mode_menu=ctk.CTkOptionMenu(
self.navigation_frame, values=["Dark", "Light"],
command=change_appearance_mode_event)
self.appearance_mode_menu.grid(row=10, column=0, padx=20, pady=10, sticky="s")
self.logout_button=ctk.CTkButton(
self.navigation_frame,
text="Logout",
fg_color="Red", text_color=("gray10", "gray90"),
hover_color=("red3", "red4"),
command=self.logout)
self.logout_button.grid(row=11, column=0, padx=20, pady=5, sticky="ew")
# create home frame
self.home_frame=ctk.CTkFrame(self, corner_radius=0, fg_color="transparent")
self.home_frame.grid_columnconfigure(0, weight=1)
# self.large_image_label=ctk.CTkLabel(self.home_frame, text="", image=large_image)
# self.large_image_label.grid(row=4, column=0, padx=20, pady=10)
# create frames
# 2
self.second_frame=ctk.CTkFrame(self, corner_radius=0, fg_color="transparent")
# 3
self.third_frame=ctk.CTkFrame(self, corner_radius=0, fg_color="transparent")
# 4
self.fourth_frame=ctk.CTkFrame(self, corner_radius=0, fg_color="transparent")
# 5
self.fifth_frame=ctk.CTkFrame(self, corner_radius=0, fg_color="transparent")
# 6
self.sixth_frame=ctk.CTkFrame(self, corner_radius=0, fg_color="transparent")
# 7
self.seventh_frame=ctk.CTkFrame(self, corner_radius=0, fg_color="transparent")
# 8
self.eighth_frame=ctk.CTkFrame(self, corner_radius=0, fg_color="transparent")
# select default frame
self.select_frame_by_name("home")
create_home_frame(self.home_frame) # Call the function to create home frame
create_gym_membership_frame(self.second_frame) # Call the function to create gym membership frame
create_take_attendance_frame(self.third_frame)
create_gym_equipment_frame(self.fourth_frame)
create_trainers_frame(self.fifth_frame)
create_visitors_frame(self.sixth_frame)
create_employee_frame(self.seventh_frame)
create_account_management_frame(self.eighth_frame)
def select_frame_by_name(self, name):
# set button color for selected button
self.home_button.configure(fg_color=("gray75", "gray25") if name == "home" else "transparent")
self.frame_2_button.configure(fg_color=("gray75", "gray25") if name == "frame_2" else "transparent")
self.frame_3_button.configure(fg_color=("gray75", "gray25") if name == "frame_3" else "transparent")
self.frame_4_button.configure(fg_color=("gray75", "gray25") if name == "frame_4" else "transparent")
self.frame_5_button.configure(fg_color=("gray75", "gray25") if name == "frame_5" else "transparent")
self.frame_6_button.configure(fg_color=("gray75", "gray25") if name == "frame_6" else "transparent")
self.frame_7_button.configure(fg_color=("gray75", "gray25") if name == "frame_7" else "transparent")
self.frame_8_button.configure(fg_color=("gray75", "gray25") if name == "frame_8" else "transparent")
# show selected frame
if name == "home":
self.home_frame.grid(row=0, column=1, sticky="nsew")
else:
self.home_frame.grid_forget()
if name == "frame_2":
self.second_frame.grid(row=0, column=1, sticky="nsew")
else:
self.second_frame.grid_forget()
if name == "frame_3":
self.third_frame.grid(row=0, column=1, sticky="nsew")
else:
self.third_frame.grid_forget()
if name == "frame_4":
self.fourth_frame.grid(row=0, column=1, sticky="nsew")
else:
self.fourth_frame.grid_forget()
if name == "frame_5":
self.fifth_frame.grid(row=0, column=1, sticky="nsew")
else:
self.fifth_frame.grid_forget()
if name == "frame_6":
self.sixth_frame.grid(row=0, column=1, sticky="nsew")
else:
self.sixth_frame.grid_forget()
if name == "frame_7":
self.seventh_frame.grid(row=0, column=1, sticky="nsew")
else:
self.seventh_frame.grid_forget()
if name == "frame_8":
self.eighth_frame.grid(row=0, column=1, sticky="nsew")
else:
self.eighth_frame.grid_forget()
def home_button_event(self):
self.select_frame_by_name("home")
def frame_2_button_event(self):
self.select_frame_by_name("frame_2")
def frame_3_button_event(self):
self.select_frame_by_name("frame_3")
def frame_4_button_event(self):
self.select_frame_by_name("frame_4")
def frame_5_button_event(self):
self.select_frame_by_name("frame_5")
def frame_6_button_event(self):
self.select_frame_by_name("frame_6")
def frame_7_button_event(self):
self.select_frame_by_name("frame_7")
def frame_8_button_event(self):
self.select_frame_by_name("frame_8")
# Add a logout method to the MainApp class
def logout(self):
# Close the main application window
self.destroy()
# Reopen the login window
create_login_window()
# ------------HOME FRAME----------------------#
def create_home_frame(home):
dashboard_frame=ctk.CTkScrollableFrame(home)
dashboard_frame.pack(pady=10, padx=10, fill="both", expand=True)
# label frame
label_frame=ctk.CTkFrame(dashboard_frame)
label_frame.pack(pady=5, padx=10, fill="both", expand=True)
# dashboard label align left
dashboard_label=ctk.CTkLabel(label_frame, text="Dashboard | Overview", font=("Arial bold", 30))
dashboard_label.pack(pady=5, padx=10, side=tk.LEFT)
# Display the current time on the left side of the dashboard label
current_time=datetime.now().strftime("%I:%M:%S %p")
current_time_label=ctk.CTkLabel(label_frame, text=current_time, font=("Agency FB bold", 46))
current_time_label.pack(pady=5, padx=10, side=tk.RIGHT)
# Function to update the clock
def update_clock():
current_time=datetime.now().strftime("%I:%M:%S %p")
current_time_label.configure(text=current_time)
home.after(1000, update_clock) # Schedule the next update after 1000 milliseconds (1 second)
# Start the clock update
update_clock()
# frame
panel_frame=ctk.CTkFrame(dashboard_frame)
panel_frame.pack(pady=5, padx=10, fill="both", expand=True)
# member panel frame
member_panel_frame=ctk.CTkFrame(panel_frame, fg_color="#434343")
member_panel_frame.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
# create a small rectangular label to display the no. of members
members_label=ctk.CTkLabel(member_panel_frame, text="Members", font=("Arial bold", 14))
members_label.pack(pady=5, padx=60, anchor="w")
# create a counter label to display the no. of members
members_counter_label=ctk.CTkLabel(member_panel_frame, text="", font=("Arial bold", 50))
members_counter_label.pack(pady=10, padx=10, anchor="center")
def get_members_count():
# get the no. of members from the database
conn=sqlite3.connect('SQLite db/registration_form.db')
cursor=conn.cursor()
cursor.execute("SELECT COUNT(*) FROM registration")
members_count=cursor.fetchone()[0]
members_counter_label.configure(text=members_count)
conn.close()
home.after(1000, get_members_count)
get_members_count()
# visitor panel frame
visitors_panel_frame=ctk.CTkFrame(panel_frame, fg_color="#434343")
visitors_panel_frame.grid(row=0, column=1, padx=10, pady=10, sticky="nsew")
# create a small rectangular label to display the no. of members
visitors_label=ctk.CTkLabel(visitors_panel_frame, text="Gymers", font=("Arial bold", 14))
visitors_label.pack(pady=5, padx=65, anchor="w")
# create a counter label to display the no. of members
visitor_counter_label=ctk.CTkLabel(visitors_panel_frame, text="", font=("Arial bold", 50))
visitor_counter_label.pack(pady=10, padx=10, anchor="center")
def get_visitors_count():
# get the no. of members from the database
conn=sqlite3.connect('SQLite db/visitors_log.db')
cursor=conn.cursor()
cursor.execute("SELECT COUNT(*) FROM visitors")
visitors_count=cursor.fetchone()[0]
visitor_counter_label.configure(text=visitors_count)
conn.close()
home.after(1000, get_visitors_count)
get_visitors_count()
# employee panel frame
employee_panel_frame=ctk.CTkFrame(panel_frame, fg_color="#434343")
employee_panel_frame.grid(row=0, column=2, padx=10, pady=10, sticky="nsew")
# create a small rectangular label to display the no. of employees
employee_label=ctk.CTkLabel(employee_panel_frame, text="Employees", font=("Arial bold", 14))
employee_label.pack(pady=5, padx=50, anchor="w")
# create a counter label to display the no. of employees
employee_counter_label=ctk.CTkLabel(employee_panel_frame, text="", font=("Arial bold", 50))
employee_counter_label.pack(pady=10, padx=10, anchor="center")
def get_employee_count():
# get the no. of members from the database
conn=sqlite3.connect('SQLite db/register_employee.db')
cursor=conn.cursor()
cursor.execute("SELECT COUNT(*) FROM employees")
employee_count=cursor.fetchone()[0]
employee_counter_label.configure(text=employee_count)
conn.close()
home.after(1000, get_employee_count)
get_employee_count()
# trainer panel frame
trainer_panel_frame=ctk.CTkFrame(panel_frame, fg_color="#434343")
trainer_panel_frame.grid(row=0, column=3, padx=10, pady=10, sticky="nsew")
# create a small rectangular label to display the no. of trainers
trainer_label=ctk.CTkLabel(trainer_panel_frame, text="Trainers", font=("Arial bold", 14))
trainer_label.pack(pady=5, padx=60, anchor="w")
# create a counter label to display the no. of trainers
trainer_counter_label=ctk.CTkLabel(trainer_panel_frame, text="", font=("Arial bold", 50))
trainer_counter_label.pack(pady=10, padx=10, anchor="center")
def get_trainer_count():
# get the no. of members from the database
conn=sqlite3.connect('SQLite db/register_trainer.db')
cursor=conn.cursor()
cursor.execute("SELECT COUNT(*) FROM trainer")
trainer_count=cursor.fetchone()[0]
trainer_counter_label.configure(text=trainer_count)
conn.close()
home.after(1000, get_trainer_count)
get_trainer_count()
# gym equipment panel frame
gym_equipment_panel_frame=ctk.CTkFrame(panel_frame, fg_color="#434343")
gym_equipment_panel_frame.grid(row=0, column=4, padx=10, pady=10, sticky="nsew")
# create a small rectangular label to display the no. of gym equipment
gym_equipment_label=ctk.CTkLabel(gym_equipment_panel_frame, text="Gym Equipment", font=("Arial bold", 14))
gym_equipment_label.pack(pady=5, padx=30, anchor="w")
# create a counter label to display the no. of gym equipment
gym_equipment_counter_label=ctk.CTkLabel(gym_equipment_panel_frame, text="", font=("Arial bold", 50))
gym_equipment_counter_label.pack(pady=10, padx=10, anchor="center")
def get_gym_equipment_count():
# get the no. of members from the database
conn=sqlite3.connect('SQLite db/register_equipment.db')
cursor=conn.cursor()
cursor.execute("SELECT COUNT(*) FROM equipment")
gym_equipment_count=cursor.fetchone()[0]
gym_equipment_counter_label.configure(text=gym_equipment_count)
conn.close()
home.after(1000, get_gym_equipment_count)
get_gym_equipment_count()
# -------------------FRAME 1 ----------------------#
graph_frame=ctk.CTkFrame(dashboard_frame)
graph_frame.pack(pady=5, padx=10, fill="both", expand=True)
# Monthly Income Report Graph
income_frame=ctk.CTkFrame(graph_frame)
income_frame.grid(row=0, column=0, padx=20, pady=10, sticky="nsew")
# Create a small rectangular label for the income report
income_label=ctk.CTkLabel(income_frame, text="Membership Monthly Income (PHP)", font=("Arial bold", 16))
income_label.pack(pady=5, padx=10, anchor="w")
# Create a figure and axis for the income report graph
fig, ax=plt.subplots(figsize=(7, 4), dpi=100)
canvas=FigureCanvasTkAgg(fig, master=income_frame)
canvas_widget=canvas.get_tk_widget()
canvas_widget.pack(fill="both", expand=True)
# Update the income report graph
update_income_report(home, ax, canvas)
canvas.draw()
# Make the rows and columns resizable
for i in range(5):
panel_frame.grid_columnconfigure(i, weight=1)
panel_frame.grid_rowconfigure(0, weight=1)
# ------------FRAME 2----------------------#
graph_frame2=ctk.CTkFrame(graph_frame)
graph_frame2.grid(row=0, column=1, padx=10, pady=10, sticky="nsew")
# Create a small rectangular label for the income report
income_label2=ctk.CTkLabel(graph_frame2, text="Gymers Monthly Income (PHP)", font=("Arial bold", 16))
income_label2.pack(pady=5, padx=10, anchor="w")
# Create a figure and axis for the income report graph
fig, ax=plt.subplots(figsize=(7, 4), dpi=100)
canvas=FigureCanvasTkAgg(fig, master=graph_frame2)
canvas_widget=canvas.get_tk_widget()
canvas_widget.pack(fill="both", expand=True)
# Update the income report graph
update_visitors_income_report(home, ax, canvas)
canvas.draw()
# Graph
def update_income_report(root, ax, canvas):
# pass
current_month=datetime.now().strftime('%Y-%m')
# Connect to the members database
conn_members=sqlite3.connect('SQLite db/registration_form.db')
cursor_members=conn_members.cursor()
# Retrieve monthly member count
cursor_members.execute("SELECT strftime('%Y-%m', start_date) as month, COUNT(*) FROM registration GROUP BY month")
members_data=cursor_members.fetchall()
conn_members.close()
# Process member data
merged_data={}
for month, members_count in members_data:
merged_data[month]={'members': members_count * 700}
# Extract month labels and total member incomes
months, member_incomes=zip(
*[(month, data['members']) for month, data in merged_data.items()])
# Convert months to a NumPy array with a specific data type (e.g., float)
months_array=np.array(months, dtype=str)
# Plot the monthly income report with inverted colors
ax.clear()
members_bar=ax.bar(months_array, member_incomes, color='green', alpha=0.7, label='Members')
ax.set_ylabel('Income (PHP)')
# Update the title based on the current month
ax.set_title(
f'Monthly Income Report ({calendar.month_name[int(current_month.split("-")[1])]} {current_month.split("-")[0]})')
# Show legend
ax.legend()
# Annotate each bar with the total income value
for bar, members_income in zip(members_bar, member_incomes):
ax.text(bar.get_x() + bar.get_width() / 2, members_income,
f'{members_income} PHP', ha='center', va='bottom', color='black', fontweight='bold')
ax.grid(True)
# Redraw the canvas
canvas.draw()
# Schedule the next update
root.after(1000, update_income_report, root, ax, canvas)
def update_visitors_income_report(root, ax, canvas):
# pass
current_month=datetime.now().strftime('%Y-%m')
# Connect to the members database
conn_visitors=sqlite3.connect('SQLite db/visitors_log.db')
cursor_visitors=conn_visitors.cursor()
# Retrieve monthly member count
cursor_visitors.execute("SELECT strftime('%Y-%m', time_start) as month, COUNT(*) FROM visitors GROUP BY month")
visitors_data=cursor_visitors.fetchall()
conn_visitors.close()
# Process member data
merged_data={}
for month, visitors_count in visitors_data:
merged_data[month]={'Gymers': visitors_count * 50}
# Extract month labels and total member incomes
months, visitor_incomes=zip(
*[(month, data['Gymers']) for month, data in merged_data.items()])
# Convert months to a NumPy array with a specific data type (e.g., float)
months_array=np.array(months, dtype=str)
# Plot the monthly income report with inverted colors
ax.clear()
visitor_bar=ax.bar(months_array, visitor_incomes, color='orange', alpha=0.7, label='Gymers')
ax.set_ylabel('Income (PHP)')
# Update the title based on the current month
ax.set_title(
f'Monthly Income Report ({calendar.month_name[int(current_month.split("-")[1])]} {current_month.split("-")[0]})')
# Show legend
ax.legend()
# Annotate each bar with the total income value
for bar, visitors_income in zip(visitor_bar, visitor_incomes):
ax.text(bar.get_x() + bar.get_width() / 2, visitors_income,
f'{visitors_income} PHP', ha='center', va='bottom', color='black', fontweight='bold')
ax.grid(True)
# Redraw the canvas
canvas.draw()
# Schedule the next update
root.after(1000, update_visitors_income_report, root, ax, canvas)
# ------------FRAME_2----------------------#
def create_gym_membership_frame(frame_2):
# Define the desired button width and height
button_width=300
button_height=300
# Define the path to the directory containing your image files
frame_2_icons=os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates/frame_2_icons")
# Load and resize the images
register_image=Image.open(os.path.join(frame_2_icons, 'register_black.png'))
register_image=register_image.resize((button_width, button_height), Image.LANCZOS)
view_image=Image.open(os.path.join(frame_2_icons, 'list_black.png'))
view_image=view_image.resize((button_width, button_height), Image.LANCZOS)
def register_member():
# When the "Register Members" button is clicked, create and show the registration frame
registration_frame=RegistrationFrame(frame_2)
registration_frame.pack(fill='both', expand=True)
def view_member():
# When the "View Members" button is clicked, create and show the view members frame
view_member_frame=ViewFrame(frame_2)
view_member_frame.pack(fill='both', expand=True)
# Create the buttons with the resized images
register_member_button=ctk.CTkButton(
master=frame_2,
text="Register Members",
image=ImageTk.PhotoImage(register_image),
compound=tk.TOP,
command=register_member, # Call the function to open the frame
width=button_width,
height=button_height,
fg_color="#00C957",
text_color=("gray10", "gray90")
)
register_member_button.place(x=150, y=150)
view_member_button=ctk.CTkButton(
master=frame_2,
text="View Members",
image=ImageTk.PhotoImage(view_image),
compound=tk.TOP,
command=view_member,
width=button_width,
height=button_height,
fg_color="#00C957",
text_color=("gray10", "gray90"),
)
view_member_button.place(x=600, y=150)
class RegistrationFrame(ctk.CTkFrame):
def __init__(self, master, data=None, **kwargs):
super().__init__(master, **kwargs)
# Create a connection to the database
self.conn=sqlite3.connect('SQLite db/registration_form.db')
self.cursor=self.conn.cursor()
# STEP 1: PERSONAL INFORMATION
# Define and configure widgets within the frame
label=ctk.CTkLabel(self, text="D'Grit Gym Membership Registration", font=("Arial bold", 26))
label.pack(pady=20, padx=10)
# outer frame
outer_frame=ctk.CTkFrame(self)
outer_frame.pack(pady=20, padx=10)
# create frame to hold all the widget frames
widget_frames=ctk.CTkFrame(outer_frame)
widget_frames.pack(pady=10, padx=10)
# Create a frame to hold the form fields
first_frame=ctk.CTkFrame(widget_frames)
first_frame.grid(row=0, column=0, padx=10, pady=10)
personal_info_frame=ctk.CTkFrame(first_frame)
personal_info_frame.pack(pady=10, padx=10)
# Create a custom font for labels
label_font=ctk.CTkFont(family="Arial bold", size=16) # Adjust the size as
# Name
first_name_label=ctk.CTkLabel(personal_info_frame, text="First Name:", font=label_font)
first_name_label.grid(row=2, column=0, padx=20, pady=5, sticky="w")
self.first_name_entry=ctk.CTkEntry(personal_info_frame, placeholder_text="Enter your first name")
self.first_name_entry.grid(row=2, column=1, padx=20, pady=5)
middle_name_label=ctk.CTkLabel(personal_info_frame, text="Middle Name:", font=label_font)
middle_name_label.grid(row=3, column=0, padx=20, pady=5, sticky="w")
self.middle_name_entry=ctk.CTkEntry(personal_info_frame, placeholder_text="Enter your middle name")
self.middle_name_entry.grid(row=3, column=1, padx=20, pady=5)
last_name_label=ctk.CTkLabel(personal_info_frame, text="Last Name:", font=label_font)
last_name_label.grid(row=4, column=0, padx=20, pady=5, sticky="w")
self.last_name_entry=ctk.CTkEntry(personal_info_frame, placeholder_text="Enter your last name")
self.last_name_entry.grid(row=4, column=1, padx=20, pady=5)
# If data is provided, populate the entry fields
if data:
self.first_name_entry.insert(0, data[0]) # First Name
self.middle_name_entry.insert(0, data[1]) # Middle Name
self.last_name_entry.insert(0, data[2]) # Last Name
# Age
age_label=ctk.CTkLabel(personal_info_frame, text="Age:", font=label_font)
age_label.grid(row=6, column=0, padx=20, pady=5, sticky="w")
age_entry=ctk.CTkEntry(personal_info_frame, placeholder_text="Enter your age")
age_entry.grid(row=6, column=1, padx=20, pady=5)
# Sex
sex_label=ctk.CTkLabel(personal_info_frame, text="Sex:", font=label_font)
sex_label.grid(row=7, column=0, padx=20, pady=5, sticky="w")
sex_entry=ctk.CTkComboBox(personal_info_frame, values=["Male", "Female", "Other"])
sex_entry.grid(row=7, column=1, padx=20, pady=5)
# Create a DateEntry widget for the birthdate
birth_date_label=ctk.CTkLabel(personal_info_frame, text="Date of Birth:", font=label_font)
birth_date_label.grid(row=5, column=0, padx=20, pady=5, sticky="w")
# Use the existing birth_date_entry you created
self.birth_date_entry=DateEntry(personal_info_frame, width=20, date_pattern="yyyy-mm-dd")
self.birth_date_entry.grid(row=5, column=1, padx=20, pady=15, sticky="w")
# Bind the function to the <<DateEntrySelected>> event
self.birth_date_entry.bind("<<DateEntrySelected>>", self.calculate_age)
# Address
address_label=ctk.CTkLabel(personal_info_frame, text="Address:", font=label_font)
address_label.grid(row=8, column=0, padx=20, pady=5, sticky="w")
address_entry=ctk.CTkEntry(personal_info_frame, placeholder_text="Enter your address")
address_entry.grid(row=8, column=1, padx=20, pady=5)
second_frame=ctk.CTkFrame(widget_frames)
second_frame.grid(row=0, column=1, padx=10, pady=10)
contact_frame=ctk.CTkFrame(second_frame)
contact_frame.pack(pady=10, padx=10)
# Create a custom font for labels
label_font=ctk.CTkFont(family="Arial bold", size=16) # Adjust the size as
# Assuming you have a list of nationalities
nationalities_list=["Select Nationality", "Filipino", "American", "Chinese", "Japanese", "Korean", "Other"]
# Nationality Label
nationality_label=ctk.CTkLabel(contact_frame, text="Nationality:", font=label_font)
nationality_label.pack(pady=5, padx=10, anchor="w")
# Create a CTkComboBox widget for nationalities
nationality_combo=ctk.CTkComboBox(contact_frame, values=nationalities_list)
nationality_combo.pack(pady=5, padx=10, fill="x")
nationality_combo.set("Select Nationality") # Set a default selection
# Contact No
contact_no_label=ctk.CTkLabel(contact_frame, text="Contact No:", font=label_font)
contact_no_label.pack(pady=3, padx=10, anchor="w")
contact_no_entry=ctk.CTkEntry(contact_frame, placeholder_text="+63 9123456789")
contact_no_entry.pack(pady=0, padx=10, fill="x")
# Email Address
email_label=ctk.CTkLabel(contact_frame, text="Email Address:", font=label_font)
email_label.pack(pady=0, padx=10, anchor="w")
email_entry=ctk.CTkEntry(contact_frame, placeholder_text="example@gmail.com")
email_entry.pack(pady=0, padx=10, fill="x")
# Emergency Contact No
emergency_contact_label=ctk.CTkLabel(contact_frame, text="Emergency Contact No:", font=label_font)
emergency_contact_label.pack(pady=0, padx=10, anchor="w")
emergency_contact_entry=ctk.CTkEntry(contact_frame, placeholder_text="+63 9123456789")
emergency_contact_entry.pack(pady=10, padx=10, fill="x")
# Create a frame to hold the form fields
third_frame=ctk.CTkFrame(widget_frames)
third_frame.grid(row=0, column=2, padx=10, pady=10)
subscription_frame=ctk.CTkFrame(third_frame)
subscription_frame.pack(pady=10, padx=10)
# Create a custom font for labels
label_font=ctk.CTkFont(family="Arial bold", size=16) # Adjust the size as needed
# Subscription ID
subscription_id_label=ctk.CTkLabel(subscription_frame, text="Subscription ID:", font=label_font)
subscription_id_label.grid(row=1, column=0, padx=20, pady=15, sticky="w")
# Subscription ID entry (read-only)
self.subscription_id_entry=ctk.CTkEntry(subscription_frame, placeholder_text="DG-XXXXXXXX")
self.subscription_id_entry.grid(row=1, column=1, padx=20, pady=15)
self.subscription_id_entry.configure(state="disabled")
# Set the subscription ID based on the last inserted ID
self.set_subscription_id()
# Create the widgets for subscription plan, start date, and end date
subscription_plan_label=ctk.CTkLabel(subscription_frame, text="Subscription Plan:", font=label_font)
subscription_plan_label.grid(row=2, column=0, padx=20, pady=10, sticky="w")
subscription_plan_options=["Weekly", "Monthly", "Yearly"]
self.subscription_plan_entry=ctk.CTkComboBox(subscription_frame, values=subscription_plan_options)
# Set "Monthly" as the default value
self.subscription_plan_entry.set("Monthly")
self.subscription_plan_entry.grid(row=2, column=1, padx=20, pady=15)
# Bind the function to the <<ComboboxSelected>> event
self.subscription_plan_entry.bind("<<ComboboxSelected>>", self.update_dates_on_subscription_change)
# Button to trigger photo upload
upload_button=ctk.CTkButton(subscription_frame, text="Upload Photo", command=self.upload_photo)
upload_button.grid(row=3, column=0, padx=20, pady=10, sticky="w")
# Uploaded photo entry
self.uploaded_photo_entry=ctk.CTkEntry(subscription_frame, placeholder_text=".png/.jpg/etc")
self.uploaded_photo_entry.grid(row=3, column=1, padx=20, pady=10)
# Reference to the user who owns the subscription
user_reference_label=ctk.CTkLabel(subscription_frame, text="User Reference:", font=label_font)
user_reference_label.grid(row=5, column=0, padx=20, pady=15, sticky="w")
user_reference_entry=ctk.CTkEntry(subscription_frame, placeholder_text="User ID or Name")
user_reference_entry.grid(row=5, column=1, padx=20, pady=15)
# Create a "Register" button
register_button=ctk.CTkButton(outer_frame, text="Register", fg_color="Green",
text_color=("gray10", "gray90"),
hover_color=("green3", "green4"),
command=self.register_subscription)
register_button.pack(pady=20, side=tk.TOP)
# create a back button to return to the previous frame
back_button=ctk.CTkButton(self, text="Back", fg_color="Red", text_color=("gray10", "gray90"),
hover_color=("red3", "red4"), command=self.back_button_event)
back_button.place(x=450, y=550)
# Store the Entry fields and other widgets as instance attributes
self.first_name_entry=self.first_name_entry
self.middle_name_entry=self.middle_name_entry
self.last_name_entry=self.last_name_entry
self.age_entry=age_entry
self.sex_entry=sex_entry
self.address_entry=address_entry
self.nationality_combo=nationality_combo
self.contact_no_entry=contact_no_entry
self.email_entry=email_entry
self.emergency_contact_entry=emergency_contact_entry
self.subscription_id_entry=self.subscription_id_entry
# self.start_timestamp_entry=self.start_timestamp_entry
# self.end_timestamp_entry=self.end_timestamp_entry
self.user_reference_entry=user_reference_entry
with sqlite3.connect('SQLite db/registration_form.db') as conn:
cursor=conn.cursor()
# Create a table to store registration information
cursor.execute('''
CREATE TABLE IF NOT EXISTS registration (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT,
middle_name TEXT,
last_name TEXT,
age INTEGER,
sex TEXT,
birth_date DATE,
address TEXT,
nationality TEXT,
contact_no TEXT,
email TEXT,
emergency_contact_no TEXT,
subscription_id TEXT,
subscription_plan TEXT,
start_date DATE,
end_date DATE,
user_reference TEXT,
status TEXT DEFAULT 'Ongoing',
photo_data BLOB
)
''')
# # to Add a new column to the table/ alter the name of the column, uncomment this.
# cursor.execute("ALTER TABLE registration ADD COLUMN photo_data TEXT")
# Commit the changes and close the database connection
conn.commit()
conn.close()
def check_column_exists(self, registration, photo_data):
conn=sqlite3.connect(registration_form)
cursor=conn.cursor()
cursor.execute(f"PRAGMA table_info({registration})")
columns=cursor.fetchall()
for column in columns:
if column[1] == photo_data:
return True
return False
# Function to handle photo upload
def upload_photo(self):
filename=filedialog.askopenfilename(initialdir="/", title="Select Photo")
if filename:
try:
# Move the uploaded photo to the member_profile directory
member_profile_dir="templates/member_profile"
os.makedirs(member_profile_dir, exist_ok=True)
photo_path=os.path.join(member_profile_dir, os.path.basename(filename))
shutil.copy(filename, photo_path)
# Update the entry widget to display the filename
self.uploaded_photo_entry.delete(0, tk.END)
self.uploaded_photo_entry.insert(0, os.path.basename(photo_path))
except Exception as e:
messagebox.showerror("Error", f"Failed to upload photo: {str(e)}")
def calculate_age(self, event):
# Get the selected birthdate
birth_date_str=self.birth_date_entry.get()