-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
596 lines (511 loc) · 25.6 KB
/
main.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
# FLOWDO
# FlowDo is an application created for the purpose of managing business activities like Inventory Maintenance, Billing, Sales analysis and other business functions.
# Developed by:
# Moulishankar M R (@Moulishankar10)
# Vigneshwar K R (@ToastCoder)
# REQUIRED MODULES
import numpy as np
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
# VISUALIZER FUNCTIONS:
# Used to display keymaps for main menu and every submenu
# LIST OF KEYMAPS TO BE DISPLAYED IN MAIN MENU
def mainOptionsVisualizer():
print("""
\n******************************************** MAIN MENU ***********************************************\n
Press 1 to take a New Order
Press 2 to explore the Revenue options
Press 3 to explore the Inventory properties
Press 9 for exit
\n******************************************************************************************************\n
""")
# LIST OF KEYMAPS TO BE DISPLAYED IN ORDER OPTIONS
def orderOptionsVisualizer():
print("""
\n******************************************** ORDER MENU **********************************************\n
Press 1 to add a new product
Press 2 to remove a product
Press 3 to view the bill
Press 4 to modify your order
Press 5 to proceed your order
Press 9 for exit
\n******************************************************************************************************\n
""")
# LIST OF KEYMAPS TO BE DISPLAYED IN REVENUE OPTIONS
def revenueOptionsVisualizer():
print("""
\n******************************************* REVENUE MENU *********************************************\n
Press 1 to view the Revenue Database
Press 2 to view a Month's Total Revenue
Press 3 to view the product which generated the Maximum Profit in any month
Press 4 to view the product which generated the Minimum Profit in any month
Press 5 to view the Revenue Trend Graph for any year
Press 9 for exit
\n******************************************************************************************************\n
""")
# LIST OF KEYMAPS TO BE DISPLAYED IN INVENTORY OPTIONS
def inventoryOptionsVisualizer():
print("""
\n****************************************** INVENTORY MENU *********************************************\n
Press 1 to view the Stock Inventory
Press 2 to add a new product to your inventory
Press 3 to remove a product from your inventory
Press 4 to modify the properties of existing products
Press 9 for exit
\n*******************************************************************************************************\n
""")
# USED TO CHECK IF THE COLUMN FOR THE MONTH IS CREATED OR NOT
def revMonthChecker():
today = datetime.now()
frmt = today.strftime('%m-%Y')
rev_data = pd.read_csv('data/revenue.csv')
header = list(rev_data.columns)
if frmt not in header:
x = [0]*len(rev_data)
rev_data[frmt] = x
rev_data.to_csv("data/revenue.csv", index = False)
# CLASS FOR BILLING OPERATIONS
class Biller:
def __init__(self,l):
self.prod_name=[]
self.quantity=[]
self.price=[]
self.total_price=[]
self.limit=l
self.ordered = False
self.item_selected = False
def isFull(self):
return len(self.prod_name) == self.limit
def isEmpty(self):
return len(self.prod_name) == 0
# FUNCTION TO ADD A NEW PRODUCT TO THE BILL
def enqueue(self,ele,qn):
if self.isFull():
print("\nMaximum limit reached !")
elif ele.upper() in self.prod_name:
print(f"\n!! '{ele.upper()}' is already in the ordered list !!")
print("\n--- Please refer the 'ORDER MENU' to modify the ordered items ---\n")
else:
inv_data = pd.read_csv('data/inventory.csv')
flag = 0
for i in range(len(inv_data)):
flag = 0
if inv_data["Product_Name"][i] == ele.upper():
if qn.isnumeric() == True:
if int(qn) <= inv_data["Available_Stock"][i]:
self.prod_name.append(ele.upper())
self.quantity.append(int(qn))
self.price.append(inv_data["Selling_Price"][i])
self.item_selected = True
print("\n>>>>>>>> Product is Added to the Order <<<<<<<<\n")
break
else:
print("\n!! Sorry for the inconvenience... Your required product is Out of Stock !!")
break
else:
print("\n!! Invalid Amount of Quantity !!")
break
else:
flag = 1
if flag == 1:
print("\n!! Unavailable Product or Invalid Product !!")
# FUNCTION TO REMOVE A PRODUCT FROM THE BILL
def remove(self):
if self.isEmpty():
print("\n!!! You haven't ordered any product(s) yet to remove !!!\n")
else:
ele = input("\nEnter the product name : ").upper()
if ele in self.prod_name:
ind = self.prod_name.index(ele)
del self.prod_name[ind]
del self.quantity[ind]
del self.price[ind]
del self.total_price[ind]
print("\n>>>>>>>> Product is Removed from the Order <<<<<<<<\n")
else:
print("\n!!! The Specified Product is not in the Order !!!\n")
# FUNCTION TO DISPLAY CONTENTS OF THE BILL
def display(self):
if self.isEmpty():
print("\n!!! You haven't ordered any product(s) yet to generate bill !!!\n")
else:
self.total_price = list(np.array(self.quantity)*np.array(self.price))
form = {'Product Name':self.prod_name,'Quantity':self.quantity,'Cost(1)':self.price,'Total Cost':self.total_price}
res = pd.DataFrame(form)
res.index=list(range(1,len(self.prod_name)+1))
print(res)
print("\n=============================================================\n")
print(f"Total Items : {len(self.prod_name)}")
print(f"Total Quantities : {sum(self.quantity)}")
print(f"Grand Total : Rs.{sum(self.total_price)}")
print("\n=============================================================\n")
# FUNCTION TO MODIFY A PRODUCT NAME OR QUANTITY IN THE BILL
def modify(self):
if self.isEmpty():
print("\n!!! You haven't ordered any product(s) yet to modify !!!\n")
else:
ele = input("\nEnter the product name : ").upper()
if ele in self.prod_name:
ind = self.prod_name.index(ele.upper())
key = int(input("\n Press 1 to modify the product name ..... \n\n Press 2 to modify the quantity .....\n\nYour Option : "))
if key == 1:
self.prod_name[ind] = input("\nEnter the new product name : ").upper()
elif key == 2:
self.quantity[ind] = int(input("\nEnter the new amount of quantity : "))
print("\n>>>>>>>> Updated the Order <<<<<<<<\n")
else:
print("\n!!! The Specified Product is not in the Order !!!\n")
# FUNCTION TO PERFORM THE POST PROCESSING ACTIVITIES ONCE THE BILL IS CONFIRMED
def postProcessor(self):
today = datetime.now()
frmt = today.strftime('%m-%Y')
inv_data = pd.read_csv('data/inventory.csv')
rev_data = pd.read_csv("data/revenue.csv")
for i in range(len(inv_data)):
for j in range(len(self.prod_name)):
if inv_data["Product_Name"][i] == self.prod_name[j]:
inv_data["Available_Stock"][i] -= self.quantity[j]
inv_data.to_csv('data/inventory.csv', index=False)
for i in range(len(rev_data)):
for j in range(len(self.prod_name)):
if rev_data["Product_Name"][i] == self.prod_name[j]:
rev_data[str(frmt)][i] += self.total_price[j]
rev_data.to_csv('data/revenue.csv', index=False)
self.ordered = True
print("\n\n\n -------- Updated the Inventory Data ! -------- \n")
#INDIVIDUAL FUNCTIONS USED IN REVENUE SUB MENU
month = ["January","February","March","April","May","June","July","August","September","October","November","December"]
# FUNCTION TO VIEW THE REVENUE DATABASE
def viewRevenue():
rev_data = pd.read_csv('data/revenue.csv')
print("\n------------------------------------------ REVENUE DATABASE --------------------------------------------\n\n",rev_data.to_string(index=False))
# FUNCTION TO DISPLAY THE REVENUE GENERATED BY THIS MONTH
def viewMonthRevenue():
rev_data = pd.read_csv('data/revenue.csv')
frmt = input("\nEnter the time period (MM-YYYY) : ")
if frmt[:2] in ['01','02','03','04','05','06','07','08','09','10','11','12'] and frmt in rev_data.columns:
month_revenue = sum(list(rev_data[frmt]))
print(f"\n The revenue generated in {month[int(frmt[:2])-1]} {int(frmt[-4:])} -- Rs.{month_revenue}")
else:
print("\n!!!! Invalid Time Period or Non-Entried Time Period !!!!\n")
# FUNCTION TO DISPLAY THE MAXIMUM PROFIT GENERATED PRODUCTS
def maxProfit():
rev_data = pd.read_csv('data/revenue.csv')
frmt = input("\nEnter the time period (MM-YYYY) : ")
if frmt[:2] in ['01','02','03','04','05','06','07','08','09','10','11','12'] and frmt in rev_data.columns:
if list(rev_data[frmt]) == [0 for i in range(len(rev_data))]:
today = datetime.now()
if frmt[:2] == today.strftime('%m'):
print(f"\n\n!! No Products are sold in {month[int(frmt[:2])-1]} {int(frmt[-4:])} !!\n")
else:
print(f"\n\n!! No Products were sold in {month[int(frmt[:2])-1]} {int(frmt[-4:])} !!\n")
else:
max_amt = max(list(rev_data[frmt]))
print(f"\n The following product(s) generated the maximum profit on {month[int(frmt[:2])-1]} {int(frmt[-4:])} : \n")
for i in range(len(rev_data)):
if rev_data[frmt][i] == max_amt:
print(" * {} - Rs.{}".format(rev_data["Product_Name"][i],max_amt))
else:
print("\n\n!!!! Invalid Time Period or Non-Entried Time Period !!!!\n")
# FUNCTION TO DISPLAY THE MINIMUM PROFIT GENERATED PRODUCTS
def minProfit():
rev_data = pd.read_csv('data/revenue.csv')
frmt = input("\nEnter the time period (MM-YYYY) : ")
if frmt[:2] in ['01','02','03','04','05','06','07','08','09','10','11','12'] and frmt in rev_data.columns:
if list(rev_data[frmt]) == [0 for i in range(len(rev_data))]:
today = datetime.now()
if frmt[:2] == today.strftime('%m'):
print(f"\n\n!! No Products are sold in {month[int(frmt[:2])-1]} {int(frmt[-4:])} !!\n")
else:
print(f"\n\n!! No Products were sold in {month[int(frmt[:2])-1]} {int(frmt[-4:])} !!\n")
else:
min_amt = min(list(rev_data[frmt]))
print(f"\n The following product(s) generated the least profit on {month[int(frmt[:2])-1]} {int(frmt[-4:])} : \n")
for i in range(len(rev_data)):
if rev_data[frmt][i] == min_amt:
print(" * {} - Rs.{}".format(rev_data["Product_Name"][i],min_amt))
else:
print("\n\n!!!! Invalid Time Period or Non-Entried Time Period !!!!\n")
# FUNCTION TO VISUALIZE THE REVENUE GENERATED BY MONTHS THROUGH A GRAPH
def viewRevenueGraph():
rev_data = pd.read_csv('data/revenue.csv')
profits =[]
months = []
year = input("\nEnter the Year (YYYY) : ")
for i in rev_data.columns:
if year in i:
rev_data = pd.read_csv("data/revenue.csv")
for i in rev_data.columns:
if year in i:
months.append(month[int(i[:2])-1])
profits.append(sum(list(rev_data[i])))
plt.scatter(months, profits,color ='red',linewidths=3)
plt.plot(months,profits,color="blue")
plt.bar(months,profits,color="green",width = 0.2)
plt.xlabel("Month")
plt.ylabel("Revenue Generated (INR)")
plt.title("Revenue for the year {}".format(year))
plt.show()
flag = 1
break
elif year not in i:
flag = 0
if flag == 0:
print("\n\n!!!! Invalid Year or Non-Entried Year !!!!\n")
#INDIVIDUAL FUNCTIONS USED IN INVENTORY SUB MENU
# FUNCTION TO VIEW THE STOCK INVENTORY
def viewInventory():
inv_data = pd.read_csv("data/inventory.csv")
print("\n------------------------------------------ STOCK INVENTORY --------------------------------------------\n\n",inv_data.to_string(index=False))
# FUNCTION TO ADD A NEW PRODUCT TO THE INVENTORY
def addProdInventory():
inv_data = pd.read_csv("data/inventory.csv")
rev_data = pd.read_csv("data/revenue.csv")
l = list(inv_data["Product_Name"])
if len(inv_data) == 0:
snum = 0
else:
snum = len(inv_data)
snum += 1
prod_code = input("\nEnter the Product Code : ").upper()
prod_name = input("\nEnter the Product Name : ").upper()
if prod_name not in l:
max_stock = int(input("\nEnter the Maximum Stock : "))
avail_stock = int(input("\nEnter the Available Stock : "))
cost_price = int(input("\nEnter the Cost Price : "))
selling_price = int(input("\nEnter the Selling Price : "))
inv_data.loc[len(inv_data.index)] = [snum,prod_code,prod_name,avail_stock,max_stock,cost_price,selling_price]
inv_data.to_csv("data/inventory.csv",index=False)
print("\n>>>>>>>> Product added to the Inventory <<<<<<<<\n")
temp_list = [0]*(len(rev_data.columns)-2)
new_row = [prod_code,prod_name]
rev_data.loc[len(rev_data.index)] = new_row + temp_list
rev_data.to_csv("data/revenue.csv",index = False)
else:
print("\n!!! The Specified Product is already in the Inventory !!!\n")
# FUNCTION TO REMOVE A PRODUCT FROM THE INVENTORY
def removeProdInventory():
inv_data = pd.read_csv("data/inventory.csv")
rev_data = pd.read_csv("data/revenue.csv")
l = list(inv_data["Product_Name"])
prod_name = input("\nEnter the product name to remove : ").upper()
if prod_name in l:
for i in range(len(inv_data)):
if inv_data["Product_Name"][i] == prod_name:
ind = i
inv_data.drop([ind],axis = 0,inplace = True)
inv_data.to_csv("data/inventory.csv",index = False)
print("\n>>>>>>>> Product removed from the Inventory. <<<<<<<<\n")
else:
print("\n!!!! The Specified Product is not in the Inventory !!!!\n")
l2 = list(rev_data["Product_Name"])
if prod_name in l2:
for j in range(len(rev_data)):
if rev_data["Product_Name"][j] == prod_name:
ind2 = j
rev_data.drop([ind2],axis = 0,inplace = True)
rev_data.to_csv("data/revenue.csv",index = False)
# FUNCTION TO MODIFY THE EXISTING VALUES OF A PRODUCT IN THE INVENTORY
def modifyProduct():
inv_data = pd.read_csv("data/inventory.csv")
l = list(inv_data["Product_Name"])
prod_name = input("\nEnter the product name to modify : ").upper()
if prod_name in l:
for i in range(len(inv_data)):
if inv_data["Product_Name"][i] == prod_name:
ind = i
print("\n-------------------------------------------------\n")
print("\nPress 1 to modify Product Code")
print("\nPress 2 to modify Product Name")
print("\nPress 3 to modify Available Stock")
print("\nPress 4 to modify Maximum Stock")
print("\nPress 5 to modify Cost Price")
print("\nPress 6 to modify Selling Price\n")
print("\n-------------------------------------------------\n")
option = int(input("\nEnter your Option : "))
if option == 1:
inv_data["Product_Code"][ind] = input("\nEnter the new Product Code for this product : ")
elif option == 2:
inv_data["Product_Name"][ind] = input("\nEnter the new Product Name for this product : ").upper()
elif option == 3:
inv_data["Available_Stock"][ind] = int(input("\nEnter the new value for Available Stock : "))
elif option == 4:
inv_data["Maximum_Stock"][ind] = int(input("\nEnter the new value for Maximum Stock : "))
elif option == 5:
inv_data["Cost_Price"][ind] = int(input("\nEnter the new value for Cost Price : "))
elif option == 6:
inv_data["Selling_Price"][ind] = int(input("\nEnter the new value for Selling Pric e: "))
elif option not in [1,2,3,4,5,6]:
print("\n!!!!! Please enter the valid option !!!!!\n")
inv_data.to_csv("data/inventory.csv",index=False)
print("\n\n>>>>>>>> Updated the Inventory <<<<<<<<\n")
else:
print("\n!!!! The Specified Product is not in the Inventory !!!!\n")
# FUNCTIONS FOR THE SUB MENU
# Order() - A FUNCTION WHICH PROVIDES THE ACCESSIBILITY TO THE CUSTOMER'S ORDER LIST TO PERFORM ALL THE ACTIONS.
def Order():
l = int(input("\nEnter the number of products : "))
b = Biller(l)
now = datetime.now()
def proceed():
print("\n--------------------- YOUR FINAL BILL -----------------------\n")
print(f"Bill Date : {now.strftime('%d-%m-%Y')} Time : {now.strftime('%I:%M %p')}")
print("\n-------------------------------------------------------------\n")
b.display()
print("\n\t *** THANK YOU - HAVE A NICE DAY ***\n")
print("\n-------------------------------------------------------------\n")
proceed.key = input("\nDo you want to make any changes in the Order? (y/n) : ").lower()
print("\n")
while True:
orderOptionsVisualizer()
option = input("\nEnter your option : ")
if option not in '123459':
print("\n!!!!! Please enter the valid option !!!!!\n")
else:
order_opt = int(option)
if order_opt == 1:
if b.isFull():
print("\n\n!!! Maximum Limit Reached !!!\n")
else:
ele = input("\nEnter the product name : ").upper()
qn = input("\nEnter the quantity : ")
b.enqueue(ele,qn)
elif order_opt == 2:
b.remove()
elif order_opt == 3:
if b.isEmpty():
print("\n!!! You haven't ordered any product(s) yet to generate bill !!!\n")
else:
print("\n------------------------- BILL ------------------------------\n")
print(f"Bill Date : {now.strftime('%d-%m-%Y')} Time : {now.strftime('%I:%M %p')}")
print("\n-------------------------------------------------------------\n")
b.display()
elif order_opt == 4:
b.modify()
elif order_opt == 5:
if b.isEmpty():
print("\n!!! Couldn't proceed the Order - No Product(s) is/are Ordered !!!\n")
else:
if len(b.quantity) != l:
print(f"\n\n!! You didn't ordered {l} number of products !!\n\n")
usr_res = input("Do you want to proceed the order (y/n) : ").lower()
print("\n")
if usr_res == 'y':
proceed()
elif usr_res == 'n':
continue
else:
print("\n\n!!! Invalid Response !!!\n")
continue
else:
proceed()
key = proceed.key
if key == "y":
continue
elif key == "n":
b.postProcessor()
else:
print("\n\n!!! Invalid Response !!!\n\n")
continue
print("\n\n ||||| Thanks for the Order ||||| \n")
break
elif order_opt == 9:
if not b.item_selected or b.ordered:
break
else:
print("\n\n!!! You haven't confirmed the Order !!!")
opt = input("\nAre you sure want to exit from the 'ORDER MENU'? (y/n) : ").lower()
if opt:
break
else:
continue
# Revenue() - A FUNCTION WHICH PROVIDES ANY KIND OF INFORMATION REGARDING THE OWNER'S REVENUE.
def Revenue():
# SUB FUNCTIONS SHOULD BE ADDED
while True:
revenueOptionsVisualizer()
option = input("\nEnter your option : ")
if option not in '123459':
print("\n!!!!! Please enter the valid option !!!!!\n")
else:
rev_opt = int(option)
if rev_opt == 1:
viewRevenue()
elif rev_opt == 2:
viewMonthRevenue()
elif rev_opt == 3:
maxProfit()
elif rev_opt == 4:
minProfit()
elif rev_opt == 5:
viewRevenueGraph()
elif rev_opt == 9:
break
# Inventory() - A FUNCTION WHICH PROVIDES THE ACCESSIBILITY TO THE INVENTORY LIST TO PERFORM IT'S REALTED FUNCTIONS.
def Inventory():
# SUB FUNCTIONS SHOULD BE ADDED
while True:
inventoryOptionsVisualizer()
option = input("\nEnter your option : ")
if option not in '12349':
print("\n!!!!! Please enter the valid option !!!!!\n")
else:
inv_opt = int(option)
if inv_opt == 1:
viewInventory()
elif inv_opt == 2:
addProdInventory()
elif inv_opt == 3:
removeProdInventory()
elif inv_opt == 4:
modifyProduct()
elif inv_opt == 9:
break
# MAIN FUNCTION
if __name__ == "__main__":
print("""
\n======================================== WELCOME TO FLOWDO =========================================\n
LET'S HAVE YOUR BUSINESS WITH EASE BY FLOWDO
_______________________________________________________________________
| |
| FIRST, SETUP YOUR INVENTORY TO PROCEED THE ORDERS |
| |
| ``````````````````````````````````````````````````````` |
| |
| IF IT IS ALL SET, PLEASE ENSURE THAT ALL THE PRODUCTS |
| |
| ARE IN SUFFICIENT QUANTITY TO PROCEED |
| |
| THE ORDERS |
| |
| ``````````````````````````````````````````````````````` |
| |
| THEN, LET'S MOVE ON! |
| |
|_______________________________________________________________________|
""")
today = datetime.today()
revMonthChecker()
while True:
mainOptionsVisualizer()
option = input("\nEnter your option : ")
if option not in '1239':
print("\n!!!!! Please enter the valid option !!!!!\n")
else:
opt = int(option)
if opt == 1:
Order()
elif opt == 2:
Revenue()
elif opt == 3:
Inventory()
elif opt == 9:
final_opt = input("\nDo you really want to exit FlowDo (y/n) : ").lower()
if final_opt == "y":
print("\n\n\t\t\t\t\t ~~~~~~ THANK YOU FOR USING FLOWDO ~~~~~~ \n\n")
break
elif final_opt == 'n':
continue
else:
print("\n\n\n\n!!!! Invalid Response !!!!\n")