-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
264 lines (210 loc) · 9.42 KB
/
dashboard.py
File metadata and controls
264 lines (210 loc) · 9.42 KB
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
from tkinter import *
from PIL import Image, ImageTk
from tkinter import messagebox
import time
import sqlite3
import os
import bcrypt
from employee import employeeClass
from supplier import supplierClass
from category import categoryClass
from product import productClass
from sales import salesClass
# ------------------ BASE PATH SETUP ------------------
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
IMAGE_DIR = os.path.join(BASE_DIR, "images")
BILL_DIR = os.path.join(BASE_DIR, "bill")
os.makedirs(BILL_DIR, exist_ok=True)
# ---------------------------------------------------
class IMS:
def __init__(self, root):
self.root = root
self.root.geometry("1350x800+110+80")
self.root.resizable(False, False)
self.root.config(bg="white")
self._is_logged_in = False
self._dash_container = Frame(self.root)
self._login_container = Frame(self.root)
self.icon_title = PhotoImage(file=os.path.join(IMAGE_DIR, "logo1.png"))
# ------------ login screen ------------
self._init_login()
# ------------- dasboard ---------------
self._init_dashboard()
self.to_login()
#---------------------- init functions -----------------------------
def _init_title(self, root):
title = Label(
root,
text="Inventory Management System",
image=self.icon_title,
compound=LEFT,
font=("times new roman", 40, "bold"),
bg="#010c48",
fg="white",
anchor="w",
padx=20
).place(x=0, y=0, relwidth=1, height=70)
def _init_left_menu(self):
self.MenuLogo = Image.open(os.path.join(IMAGE_DIR, "menu_im.png"))
self.MenuLogo = self.MenuLogo.resize((200, 200))
self.MenuLogo = ImageTk.PhotoImage(self.MenuLogo)
LeftMenu = Frame(self._dash_container, bd=2, relief=RIDGE, bg="white")
LeftMenu.place(x=0, y=102, width=200, height=565)
lbl_menuLogo = Label(LeftMenu, image=self.MenuLogo)
lbl_menuLogo.pack(side=TOP, fill=X)
lbl_menu = Label(
LeftMenu, text="Menu",
font=("times new roman", 20),
bg="#009688"
).pack(side=TOP, fill=X)
self.icon_side = PhotoImage(master=self.root,file=os.path.join(IMAGE_DIR, "side.png"))
def _get_button(text, command):
button = Button(
LeftMenu, text=text, command=command,
image=self.icon_side, compound=LEFT,
padx=5, anchor="w",
font=("times new roman", 20, "bold"),
bg="white", bd=3, cursor="hand2"
)
button.pack(side=TOP, fill=X)
return button
btn_employee = _get_button(text="Employee",command=self.employee)
btn_supplier = _get_button(text="Supplier",command=self.supplier)
btn_category = _get_button(text="Category",command=self.category)
btn_product = _get_button(text="Products",command=self.product)
btn_sales = _get_button(text="Sales",command=self.sales)
btn_exit = _get_button(text="Exit",command=self.root.destroy)
def _init_content(self):
def _get_label(text, bg, x, y, width, height):
label = Label(
self._dash_container, text=text,
bd=5, relief=RIDGE, bg=bg,
fg="white", font=("goudy old style", 20, "bold")
)
label.place(x=x, y=y, width=width, height=height)
return label
self.lbl_employee = _get_label(text="Total Employee\n{ 0 }", bg="#33bbf9", x=300, y=120, height=150, width=300)
self.lbl_supplier = _get_label(text="Total Supplier\n{ 0 }", bg="#ff5722", x=650, y=120, height=150, width=300)
self.lbl_category = _get_label(text="Total Category\n{ 0 }", bg="#009688", x=1000, y=120, height=150, width=300)
self.lbl_product = _get_label(text="Total Product\n{ 0 }", bg="#607d8b", x=300, y=300, height=150, width=300)
self.lbl_sales = _get_label(text="Total Sales\n{ 0 }", bg="#ffc107", x=650, y=300, height=150, width=300)
def _init_dashboard(self):
# ------------- title --------------
self._init_title(self._dash_container)
# ------------ logout button -----------
btn_logout = Button(
self._dash_container, text="Logout",
font=("times new roman", 15, "bold"),
bg="yellow", cursor="hand2",
command=self.logout
).place(x=1150, y=10, height=50, width=150)
# ------------ clock -----------------
self.lbl_clock = Label(
self._dash_container,
text="Welcome to Inventory Management System\t\t Date: DD:MM:YYYY\t\t Time: HH:MM:SS",
font=("times new roman", 15),
bg="#4d636d", fg="white"
)
self.lbl_clock.place(x=0, y=70, relwidth=1, height=30)
# ---------------- left menu ---------------
self._init_left_menu()
# ----------- content ----------------
self._init_content()
# ------------ footer -----------------
lbl_footer = Label(
self._dash_container,
text="IMS-Inventory Management System",
font=("times new roman", 12),
bg="#4d636d", fg="white"
).pack(side=BOTTOM, fill=X)
def _init_login(self):
self.var_name = StringVar()
self.var_pass = StringVar()
font=("goudy old style", 20, "bold")
self._init_title(self._login_container)
form_frame = Frame(self._login_container)
form_frame.place(relx= 0.5, rely=0.5, anchor="center")
lbl_name = Label(form_frame, text="Username:", font=font)
lbl_name.grid(row=0, column=0, padx=40, pady=20, sticky="e")
txt_name = Entry(form_frame, textvariable=self.var_name, font=font, width=15)
txt_name.grid(row=0, column=1, padx=40, pady=20)
lbl_pass = Label(form_frame, text="Password:", font=font)
lbl_pass.grid(row=1, column=0, padx=40, pady=20, sticky="e")
txt_pass = Entry(form_frame, textvariable=self.var_pass, show="*", font=font, width=15)
txt_pass.grid(row=1, column=1, padx=40, pady=20)
login_button = Button(form_frame, text="Login", font=font, command=self.login)
login_button.grid(row=2, column=0, columnspan=2, pady=40)
#---------------------- all functions ------------------------------
def to_login(self):
self._dash_container.pack_forget()
self._login_container.pack(fill="both", expand=True)
def to_dashboard(self):
self._login_container.pack_forget()
self._dash_container.pack(fill="both", expand=True)
self.update_content()
def login(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
cur.execute("SELECT Password_hash FROM user WHERE Username=?", (self.var_name.get(),))
result = cur.fetchone()
con.close()
if result is None:
messagebox.showerror("Error","User does not exist",parent=self.root)
return
stored_hash = result[0]
password = self.var_pass.get()
if not bcrypt.checkpw(password.encode(), stored_hash.encode()):
messagebox.showerror("Error","Incorrect password",parent=self.root)
return
self.var_name.set("")
self.var_pass.set("")
self._is_logged_in = True
self.to_dashboard()
def logout(self):
self._is_logged_in = False
self.to_login()
def employee(self):
self.new_win = Toplevel(self.root)
self.new_obj = employeeClass(self.new_win)
def supplier(self):
self.new_win = Toplevel(self.root)
self.new_obj = supplierClass(self.new_win)
def category(self):
self.new_win = Toplevel(self.root)
self.new_obj = categoryClass(self.new_win)
def product(self):
self.new_win = Toplevel(self.root)
self.new_obj = productClass(self.new_win)
def sales(self):
self.new_win = Toplevel(self.root)
self.new_obj = salesClass(self.new_win)
def update_content(self):
con = sqlite3.connect(database=os.path.join(BASE_DIR, 'ims.db'))
cur = con.cursor()
try:
cur.execute("select * from product")
product = cur.fetchall()
self.lbl_product.config(text=f"Total Product\n[ {len(product)} ]")
cur.execute("select * from category")
category = cur.fetchall()
self.lbl_category.config(text=f"Total Category\n[ {len(category)} ]")
cur.execute("select * from employee")
employee = cur.fetchall()
self.lbl_employee.config(text=f"Total Employee\n[ {len(employee)} ]")
cur.execute("select * from supplier")
supplier = cur.fetchall()
self.lbl_supplier.config(text=f"Total Supplier\n[ {len(supplier)} ]")
bill = len(os.listdir(BILL_DIR))
self.lbl_sales.config(text=f"Total Sales\n[ {bill} ]")
time_ = time.strftime("%I:%M:%S")
date_ = time.strftime("%d-%m-%Y")
self.lbl_clock.config(
text=f"Welcome to Inventory Management System\t\t Date: {date_}\t\t Time: {time_}"
)
self.lbl_clock.after(200, self.update_content)
except Exception as ex:
messagebox.showerror("Error", f"Error due to : {str(ex)}", parent=self.root)
if __name__ == "__main__":
root = Tk()
obj = IMS(root)
root.mainloop()