-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.py
518 lines (473 loc) · 12.5 KB
/
1.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
#importing necessary header files
import getpass
from os import system, name
from tqdm.auto import tqdm
from time import sleep
import sqlite3
import sys
#creating database
def db():
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.executescript('''
DROP TABLE IF EXISTS admin;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS items;
DROP TABLE IF EXISTS bill;
DROP TABLE IF EXISTS dealer;
CREATE TABLE admin (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
uname TEXT UNIQUE,
pass TEXT UNIQUE
);
CREATE TABLE items (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT UNIQUE,
price INTEGER,
qty INTEGER,
dealer TEXT
);
CREATE TABLE bill (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
prod_id INTEGER,
u_id INTEGER,
status INTEGER
);
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
uname TEXT UNIQUE,
pass TEXT UNIQUE
);
''')
conn.commit()
#some function for designs:
def clear():
if name == 'nt':
_ = system('cls')
else:
_ = system('clear')
def load():
print("\n"*2)
print(" "*4,"LOADING.....")
print()
for i in tqdm(range(80)):
print("", end="\r")
sleep(0.025)
def drawline():
print("_"*168)
#home is startin menu 1
def home():
clear()
drawline()
print()
print(" "*74,"LOGIN MENU")
drawline()
print("\n"*2)
print(" "*4,"LOGIN AS :")
print(" "*4,"1. ADMIN")
print(" "*4,"2. USER ")
print()
choice=int(input(" enter your choice:"))
print()
drawline()
if choice == 1:
load()
admin()
elif choice== 2:
load()
user()
else:
print("\n"*2)
print(" "*70,"!!!!!!! INVALID !!!!!!!")
home()
#admin is admin login menu:
def admin():
clear()
drawline()
print()
print(" "*74,"ADMIN LOGIN")
drawline()
print("\n"*2)
print(" ->Enter Your Credentials")
print()
username=input(" USERNAME: ")
password=getpass.getpass(" PASSWORD: ")
print("\n"*2)
drawline()
load()
print()
drawline()
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
command="SELECT uname, pass from admin"
cur.execute(command)
data=cur.fetchall()
for i in data:
if(username==i[0] and password==i[1]):
access=1
break
access=0
if(access==1):
print("ACCESS GRANTED")
amenu()
else :
print("\n"*2)
print(" INVALID PASSWORD")
admin()
conn.commit()
#these 3 function will take care of user login menu
def user():
clear()
drawline()
print()
print(" "*74," USER LOGIN")
drawline()
print("\n"*2)
print(" 1. REGISTER")
print(" 2. LOGIN")
print()
choice=int(input(" enter your choice:"))
print()
drawline()
if choice == 1:
load()
signup()
elif choice== 2:
load()
signin()
else:
print("\n"*2)
print(" "*70,"!!!!!!! INVALID !!!!!!!")
user()
def signin():
clear()
drawline()
print()
print(" "*74," LOGIN MENU")
drawline()
print("\n"*2)
print(" ->Enter Your Credentials")
print()
username=input(" USERNAME: ")
password=getpass.getpass(" PASSWORD: ")
print("\n"*2)
drawline()
load()
print()
drawline()
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
command="SELECT uname, pass from users"
cur.execute(command)
data=cur.fetchall()
for i in data:
if(username==i[0] and password==i[1]):
access=1
break
access=0
if(access==1):
print("ACCESS GRANTED")
umenu()
else :
print("\n"*2)
print(" INVALID PASSWORD")
signin()
conn.commit()
def signup():
clear()
drawline()
print()
print(" "*74," REGISTER MENU")
drawline()
print("\n"*2)
print(" ->Enter Your Credentials")
print()
username=input(" USERNAME: ")
password=input(" PASSWORD: ")
print("\n"*2)
drawline()
print()
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute('''INSERT OR IGNORE INTO users (uname, pass) VALUES ( ?, ? )''', ( username, password) )
print(" Registered successfully.........")
conn.commit()
user()
#admin menu for controling
def amenu():
clear()
drawline()
print()
print(" "*74,"ADMIN MENU")
drawline()
print("\n"*2)
print(" 1.ADD AN ITEM")
print(" 2.UPDATE PRICE OF AN ITEM")
print(" 3.UPDATE QUANTITY OF AN ITEM")
print(" 4.DELETE AN ITEM")
print(" 5.ITEMS OUT OF STOCK")
print(" 6.UPDATE DEALER ")
print(" 7.DISPLAY ITEM LIST")
print(" 8.EXIT")
choice=int(input(" enter your choice:"))
print("\n"*2)
drawline()
load()
if(choice==1):
add()
elif(choice==2):
uprice()
elif(choice==3):
uquantity()
elif(choice==4):
ditem()
elif(choice==5):
oos()
elif(choice==6):
dispdealer()
elif(choice==7):
dispitem()
elif choice==8:
sys.exit(0)
else:
print("\n"*2)
print(" INVALID ")
amenu()
#add an item
def add():
clear()
drawline()
print()
print(" "*74,"ADD AN ITEM")
drawline()
print("\n"*2)
name=input(" enter product name:")
price=int(input(" enter product price:"))
quantity=int(input(" enter product quantity:"))
dealer=input(" enter dealer name:")
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute('''INSERT OR IGNORE INTO items (name,price,qty,dealer)
VALUES ( ?,?,?,?)''', ( name,price,quantity,dealer ) )
conn.commit()
drawline()
print(" database updated.......")
amenu()
#update PRICE
def uprice():
clear()
drawline()
print()
print(" "*74,"UPDATE PRICE")
drawline()
print("\n"*2)
pid=int(input(" enter product id:"))
price=int(input(" enter updated price:"))
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute('UPDATE items SET price = ? WHERE id = ?',
(price,pid))
conn.commit()
drawline()
print(" database updated.......")
amenu()
#update QUANTITY
def uquantity():
clear()
drawline()
print()
print(" "*74,"UPDATE QUANTITY")
drawline()
print("\n"*2)
pid=int(input(" enter product id:"))
quantity=int(input(" enter updated quantity:"))
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute('UPDATE items SET qty = ? WHERE id = ?',
(quantity,pid))
conn.commit()
drawline()
print(" database updated.......")
amenu()
#delete an item
def ditem():
clear()
drawline()
print()
print(" "*74,"DELETE AN ITEM")
drawline()
print("\n"*2)
pid=int(input(" enter product id:"))
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute('DELETE from items WHERE id = ?',
(pid,))
conn.commit()
drawline()
print(" database updated.......")
amenu()
#display OUT OF STOCK
def oos():
clear()
drawline()
print()
print(" "*59,"OUT OF STOCK ITEM")
drawline()
print("\n"*2)
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute('SELECT name from items where qty=?',
(0,))
a=cur.fetchall()
print(" items that are out of stock:")
for i in a:
print(" "*4,i[0])
conn.commit()
drawline()
if int(input(" DO You WANNA GO TO MENU:"))==1:
amenu()
#update dealer name
def dispdealer():
clear()
drawline()
print()
print(" "*74,"UPDATE DEALER")
drawline()
print("\n"*2)
pid=int(input(" enter product id:"))
quantity=input(" enter new product dealer:")
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute('UPDATE items SET dealer = ? WHERE id = ?',
(quantity,pid))
conn.commit()
drawline()
print(" database updated.......")
amenu()
#display items
def dispitem():
clear()
drawline()
print()
print(" "*74,"DISPLAY ITEMS")
drawline()
print("\n"*2)
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute('select * from items ')
a=cur.fetchall()
for i in a:
print(" "*4,"ID:",i[0]," name:",i[1]," price:",i[2]," qty: ",i[3], " DEALER:",i[4])
conn.commit()
drawline()
x=input(" DO You WANNA GO TO MENU(press 1):")
if x =="1":
amenu()
#user menu for its functions
def umenu():
clear()
drawline()
print()
print(" "*74,"USER MENU")
drawline()
print("\n"*2)
print(" 1.BUY PRODUCT")
print(" 2.CHECKOUT ")
print(" 3.EXIT")
choice=int(input(" Enter your choice:"))
print("\n"*2)
drawline()
print()
if(choice==1):
buy()
elif(choice==2):
bill()
elif(choice==3):
sys.exit(0)
else:
print("\n"*2)
print(" INVALID PASSWORD")
umenu()
#helps in ordering and CHECKOUT
def buy():
clear()
drawline()
print()
print(" "*74,"PURCHASE PRODUCT ")
drawline()
print("\n"*2)
while True :
pid=int(input(" enter product id"))
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute("select qty from items where id=?",(pid,))
if(cur.fetchone()[0] > 0):
cur.execute(' insert or ignore into bill (prod_id,status) values(?,?)',(pid,0))
cur.execute(" update items set qty= qty - 1 where id = ?",(pid,))
else:
print(" item out of stock cant be added..")
conn.commit()
x=input(" press 0 to exit:")
if x == '0':
break
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
print(" enter your uresname and password to proceed")
uname=input(" USERNAME:")
password=getpass.getpass(" password")
cur.execute("select id from users where uname=? and pass=?",(uname,password))
uid=cur.fetchone()[0]
cur.execute("update bill set u_id = ? where prod_id = ? and status= ?",(uid,pid,0))
print(" order place please pay..")
conn.commit()
drawline()
umenu()
#used for bill receipt
def bill():
clear()
drawline()
print()
print(" "*68," BILL RECEIPT")
drawline()
print()
name=input(" BILLER NAME:")
phone=input(" phone number:")
drawline()
load()
clear()
drawline()
print()
print(" "*68," BILL RECEIPT")
drawline()
print()
print(" NAME OF BUYER:" , name)
drawline()
print()
print(" PHONE NUMBER:", phone)
drawline()
print(" BILL DETAILS:")
conn = sqlite3.connect('project.sqlite')
cur = conn.cursor()
cur.execute(" select bill.id,bill.u_id,items.name,items.price from bill join items on bill.prod_id=items.id where bill.status=?",(0,))
t=cur.fetchall()
print()
print()
print()
for i in t:
print("1. BILL ID :",i[0]," USER ID:", i[1], " ITEM NAME:", i[2], " ITEM PRICE",i[3] )
drawline()
total=0
for i in t:
total=total+i[3]
print()
print(" "*100," TOTAL AMOUNT TO BE PAID :"," "*5, total)
drawline()
pay=int(input("PRESS 1 TO PAY ->"))
drawline()
print()
if pay==1:
cur.execute("update bill set status = ?",(1,))
print(" "*68,"SHOP AGAIN THANKS")
conn.commit()
umenu()
home()