-
Notifications
You must be signed in to change notification settings - Fork 1
/
admins.py
187 lines (161 loc) · 5.23 KB
/
admins.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
import db_connection
# import home
cur = db_connection.db.cursor()
def admin_panel():
print("\nAdmin Panel")
print("===========\n")
print('''
1. Add Item
2. Update Item
3. Delete Item
4. Total sale
5. Customers Details
6. Product summary
7. Logout
''')
inp = int(input())
if inp == 1:
add_item()
elif inp == 2:
update_item()
elif inp == 3:
delete_item()
elif inp == 4:
total_sales()
elif inp == 5:
customer_details()
elif inp == 6:
product_details()
elif inp == 7:
logout()
else:
print("Wrong choice!")
def add_item():
print("---ADD ITEM SECTION---")
product_name = input("Enter Product Name: ")
product_price = int(input("Enter Product Price: "))
product_cat = input("Enter Product category: ")
product_desc = input("Description about the product: ")
query = "INSERT INTO products(product_name, product_price, product_cat, product_desc) VALUES (%s, %s, %s, %s)"
args = (product_name,product_price,product_cat,product_desc)
cur.execute(query, args)
db_connection.db.commit()
inpp = input("\nEnter 1 to go back to user panel: ")
if inpp == '1':
admin_panel()
else:
pass
def update_item():
print("---UPDATE ITEM SECTION---")
product_id = int(input("Enter the item product id you want to update: "))
print('''
1. Update Name
2. Update Price
3. Update category
4. Update desc
''')
inp = int(input())
if inp == 1:
product_name = input()
cur.execute("UPDATE products SET product_name = %s WHERE product_id = %s ;", (product_name, product_id))
elif inp == 2:
product_price = int(input())
cur.execute("UPDATE products SET product_price = %s WHERE product_id = %s ;", (product_price, product_id))
elif inp == 3:
product_cat = input()
cur.execute("UPDATE products SET product_cat = %s WHERE product_id = %s ;", (product_cat, product_id))
elif inp == 4:
product_desc = input()
cur.execute("UPDATE products SET product_desc = %s WHERE product_id = %s ;", (product_desc, product_id))
else:
print("Wrong choice.")
db_connection.db.commit()
print("Item updated successfully.")
inpp = input("\nEnter 1 to go back to user panel: ")
if inpp == '1':
admin_panel()
else:
pass
def delete_item():
print("---DELETE ITEM SECTION---")
product_name = input("Enter Product Name: ")
product_cat = input("Enter Product category: ")
query = "DELETE FROM products where (product_name = %s AND product_cat = %s)"
args = (product_name,product_cat)
cur.execute(query, args)
db_connection.db.commit()
inpp = input("\nEnter 1 to go back to user panel: ")
if inpp == '1':
admin_panel()
else:
pass
def total_sales():
print("---TOTAL SALES OF ITEM SECTION---")
product_name = input("Enter Product Name: ")
product_cat = input("Enter Product category: ")
query = "SELECT product_sales FROM products where (product_name = %s AND product_cat = %s)"
args = (product_name,product_cat)
cur.execute(query, args)
sales = cur.fetchone()
if sales == None:
print("No product found with this name and category.")
else:
print(f"Number of sales for {product_name} is: ",sales[0])
inpp = input("\nEnter 1 to go back to user panel: ")
if inpp == '1':
admin_panel()
else:
pass
def customer_details():
print("---CUSTOMER DETAIL SECTION---")
user_id = int(input("Enter the user id of customer: "))
query = f"select * FROM user_registration WHERE (user_id = {user_id})"
cur.execute(query)
user = cur.fetchmany()
print(user)
if user == []:
print("No user found with this user id.")
else:
print("Customer's Id:", user[0][0])
print("Customer's First Name:", user[0][1])
print("Customer's Last Name:", user[0][2])
print("Customer's Phone number:", user[0][3])
print("Customer's Address:", user[0][4])
print("Customer's Email:", user[0][5])
print("Customer's Registration date:", user[0][7])
inpp = input("\nEnter 1 to go back to user panel: ")
if inpp == '1':
admin_panel()
else:
pass
def product_details():
print("---PRODUCT DETAIL SECTION---")
product_id = int(input("Enter the Product id: "))
query = f"select * FROM products WHERE (product_id = {product_id})"
cur.execute(query)
product = cur.fetchmany()
if product == []:
print("No product found with this Product id.")
# print(product)
else:
print("Product Id:", product[0][0])
print("Product name:", product[0][1])
print("Product price:", product[0][2])
print("Product category:", product[0][3])
print("Product description:", product[0][4])
print("Product sales:", product[0][5])
inpp = input("\nEnter 1 to go back to user panel: ")
if inpp == '1':
admin_panel()
else:
pass
def logout():
print("You are successfully Logged out!")
# home.prog_execution()
# admin_panel()
# logout()
# product_details()
# customer_details()
# total_sales()
# delete_item()
# add_item()