import sqlite3
from datetime import date,time
curr_date = date.today()
conn = sqlite3.connect( 'mydatabase.db' )
cursor = conn.cursor ()
v = input("enter itemname ")
cursor.execute("SELECT basicquantity FROM local WHERE `itamname`=?",[v])
itamname = cursor.fetchone()[0]
date = curr_date.strftime('%Y-%m-%d')
cursor.execute("SELECT basicquantity from local WHERE itamname=?",[v,])
result = cursor.fetchone()[0]
cursor.execute("SELECT SUM(userquantity) FROM local WHERE itamname=?",[v,])
c = cursor.fetchall()[0][0]
print("SUM",c)
o = result - c
print("subtraction",o)
if itamname:
r = int(input("enter quantity"))
if r < o or r == o:
conn.execute('''insert into local
select ? ,po , itamno,itamname,basicquantity,rate, ?
from local
where itamname= ? ORDER BY itamname DESC LIMIT 1;''',[date, r,v])
else:
print("quantity grater than inventry")
else:
print("insert valid itemname ")
conn.commit()
conn.close()