-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.py
More file actions
310 lines (309 loc) · 10.6 KB
/
Copy pathInventory.py
File metadata and controls
310 lines (309 loc) · 10.6 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
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
import pandas as pd
from tabulate import tabulate
import mysql.connector as sqlt
con=sqlt.connect(host="localhost",user="root",password="MPM_772005",database="inventory")
cursor=con.cursor()
def add_item():
ino=int(input("enter the item number"))
iname=input("ënter the item name")
srate=float(input("enter the sales rate"))
prate=float(input("enter the purchase rate"))
qoh=int(input("enter the qty on hand"))
q="insert into item values({},'{}',{},{},{});".format(ino,iname,prate,srate,qoh)
cursor.execute(q)
con.commit()
print("item added")
def edit_item():
ino=int(input("enter item number"))
q="select*from item where ino={};"
cursor.execute(q)
if cursor.fetchone():
iname=input("enter the item name")
cursor.execute("update item set iname= '{}' wehre ino={};".format(iname,ino))
con.commit()
print("iteam edited")
else:
print("item not found")
def fix_rate():
ino=int(input("enter item number"))
q="select*from item where ino={};".format(ino)
cursor.execute(q)
if cursor.fetchone():
prate=int(input("enter new purchase rate"))
srate=int(input("enter new sales rate"))
cursor.execute("update item set srate= {},prate={} wehre ino={};".format(srate,prate))
con.commit()
print("new rate applied")
else:
print("item not found")
def search_item():
ino=int(input("enter item number"))
q="select*from item where ino={};".format(ino)
cursor.execute(q)
if cursor.fetchone():
df=pd.read_sql(q,con)
print(tabulate(df,header="keys",tablefmt="psql",showindex=False))
def delete_item():
ino=int(input("enter item number"))
q="select*from item where ino={};".format(ino)
cursor.execute(q)
if cursor.fetchone():
cursor.execute("delete from item where ino={};".format(ino))
con.cummit()
print("item deleted")
else:
print("item not found")
def add_customer():
cid=int(input("enter customer ID"))
cname=input("enter customer name")
cadd=input("enter address")
mobile=int(input("enter mobile"))
q="insert into customer values({},'{}','{}',{});".format(cid,cname,cadd,mobile)
cursor.execute(q)
con.commit()
print("customer added")
def edit_customer():
cid=int(input("enter customer ID"))
q="select*from customer where cid={};".format(cid)
if cursor.fetchone():
cadd=input("enter customer address")
cursor.execute("update customer set cadd='{}'wehre cid={};".format(cadd,cid))
con.commit()
print("customer edited")
else:
print("customer not found")
def search_customer():
cname=input("enter customer name")
q="select*from customer where cname like'%{}%';".format(cname)
cursor.execute(q)
if cursor.fetchall():
df=pd.read_sql(q,con)
print(tabulate(df,headers='keys',tablefmt='psql',showindex=False))
else:
print("customer not found")
def delete_customer():
cid=int(input("enter customer ID"))
q="select*from customer where cid={};".format(cid)
if cursor.fetchone():
cursor.execute("delete from customer wehre cid={};".format(cid))
con.commit()
print("customer deleted")
else:
print("customer not found")
def add_supplier():
sid=int(input("enter supplier ID"))
sname=input("enter supplier name")
sadd=input("enter address")
mobile=int(input("enter mobile"))
q="insert into supplier values({},'{}','{}',{});".format(sid,sname,sadd,mobile)
cursor.execute(q)
con.commit()
print("supplier added")
def edit_supplier():
sid=int(input("enter supplier ID"))
q="select*from supplier where sid={};".format(sid)
cursor.execute(q)
if cursor.fetchone():
sadd=input("enter supplier address")
cursor.execute("update supplier set sadd='{}'wehre sid={};".format(sadd,sid))
con.commit()
print("supplier edited")
else:
print("supplier not found")
def search_supplier():
sid=int(input("enter supplier name"))
q="select*from supplier where sid={};".format(sid)
cursor.execute(q)
if cursor.fetchone():
df=pd.read_sql(q,con)
print(tabulate(df,headers='keys',tablefmt='psql',showindex=False))
else:
print("supplier not found")
def delete_supplier():
sid=int(input("enter supplier ID"))
q="select*from supplier where sid={};".format(sid)
if cursor.fetchone():
cursor.execute("delete from supplier wehre sid={};".format(sid))
con.commit()
print("supplier deleted")
else:
print("supplier not found")
def purchase():
pid=0
total=0
grand=0
l=[]
ch='y'
q="select max(pid) from pmaster"
cursor.execute(q)
r=cursor.fetchone()[0]
if r:
pid=r+1
else:
pid=1
pdate=input("enter purchase date")
sid=int(input("enter supplier ID"))
cursor.execute("select * from supplier where sid={};,format(sid)")
if cursor.fetchone():
print("item deatils")
df=pd.read_sql("select*from item;",con)
print(tabulate(df,headers='keys',tablefmt='psql',showindex=False))
ino=int(int("enter item number"))
while(ch=='y'):
cursor.execute("select * from item where ino={};",format(ino))
r1=cursor.fetchone()
if r:
qty=int(input("enter qty"))
rate = r1[2]
total=qty*rate
grand=grand+total
t=(pid,ino,qty,rate,total)
l.append(t)
else:
print("item not found")
ch=input("do you want to enter more item in bucket y/n")
q1=("insert into pmaster values({},{},{},'{}','{}');",format(pid,pdate,sid,grand))
cursor.execute(q1)
con.commit()
q2=("insert into pdetail values(%s,%s,%s,%s,%s);")
cursor.executemany(q2,l)
con.commit()
else:
print("supplier not found")
def sale():
saleid=0
total=0
grand=0
l=[]
ch='y'
q="select max(saleid) from smaster"
cursor.execute(q)
r=cursor.fetchone()[0]
if r:
saleid=r+1
else:
saleid=1
sdate=input("enter sale date")
sid=int(input("enter supplier ID"))
cursor.execute("select * from supplier where sid={};,format(sid)")
if cursor.fetchone():
print("item deatils")
df=pd.read_sql("select*from item;",con)
print(tabulate(df,headers='keys',tablefmt='psql',showindex=False))
ino=int(int("enter item number"))
while(ch=='y'):
cursor.execute("select * from item where ino={};",format(ino))
r1=cursor.fetchone()
if r:
qty=int(input("enter qty"))
rate = r1[2]
total=qty*rate
grand=grand+total
t=(saleid,ino,qty,rate,total)
l.append(t)
else:
print("item not found")
ch=input("do you want to enter more item in bucket y/n")
q1=("insert into smaster values({},{},{},'{}','{}');",format(saleid,sdate,sid,grand))
cursor.execute(q1)
con.commit()
q2=("insert into pdetail values(%s,%s,%s,%s,%s);")
cursor.executemany(q2,l)
con.commit()
else:
print("supplier not found")
def show_item():
df=pd.read_sql("select*from item",con)
print(tabulate(df,header="keys",tablefmt="psql",showindex=False))
def show_customer():
df=pd.read_sql("select*from customer",con)
print(tabulate(df,header="keys",tablefmt="psql",showindex=False))
def show_supplier():
df=pd.read_sql("select*from supplier",con)
print(tabulate(df,header="keys",tablefmt="psql",showindex=False))
def show_sale():
bdate=input("enter beginning date")
edate=input("enter end date")
df=pd.read_sql("select*from smaster wehre sdate between '{}', and '{}';".format(bdate,edate),con)
print(tabulate(df,header="keys",tablefmt="psql",showindex=False))
def show_purchase():
bdate=input("enter beginning date")
edate=input("enter end date")
df=pd.read_sql("select*from pmaster wehre pdate between '{}', and '{}';".format(bdate,edate),con)
print(tabulate(df,header="keys",tablefmt="psql",showindex=False))
while(True):
print("\nenter your choice\n1.items\n2.customer\n3.supplier\n4.transaction\n5.delete item\n6.exit")
ch=int (input())
if ch==1:
while(True):
print("\nenter your choice\n1.add item\n2.edit item\n3.fix rate\n4.search item\n5.delete item\n6.exit")
ch=int(input())
if ch==1:
add_item()
elif ch==2:
edit_item()
elif ch==3:
fix_rate
elif ch==4:
search_item
elif ch==5:
delete_item
elif ch==6:
break
if ch==2:
while(True):
print("\nenter your choice\n1.add customer\n2.edit customer\n3.search customer\n4.delete customer\n5.exit")
ch=int(input())
if ch==1:
add_customer()
elif ch==2:
edit_customer()
elif ch==3:
search_customer()
elif ch==4:
delete_customer()
elif ch==5:
break
if ch==3:
while(True):
print("\nenter your choice\n1.add supplier\n2.edit supplier\n3.search supplier\n4.delete supplier\n5.exit")
ch=int(input())
if ch==1:
add_supplier()
elif ch==2:
edit_supplier()
elif ch==3:
search_item()
elif ch==4:
delete_supplier
elif ch==5:
break
if ch==4:
while(True):
print("\nenter your choice\n1.sales\n2.purchase\n3.exit")
ch=int(input())
if ch==1:
sale()
elif ch==2:
purchase()
elif ch==3:
break
if ch==5:
while(True):
print("\nenter your choice\n1.item details\n2.customer details\n3.supplier details\n4.sales report\n5.purchase report\n6.exit")
ch=int(input())
if ch==1:
show_item()
elif ch==2:
show_customer()
elif ch==3:
show_supplier()
elif ch==4:
show_sale()
elif ch==5:
show_purchase
elif ch==6:
break
elif ch==6:
print("Have a good day")
break