Coding... Pythonnn
Coding... Pythonnn
Coding... Pythonnn
# Imports
print("loading...")
import sys, os, webbrowser, datetime
try:
from tkinter import * #using tkinter to make a graphic
interface
except:
os.system('cmd /c "python -m pip install tkinter"')
from tkinter import *
try:
import tkcalendar
except:
os.system('cmd /c "python -m pip install tkcalendar"')
import tkcalendar
from tkinter import font
import tkinter.messagebox
from tkinter import ttk
from tkinter.tix import *
import glob
import _thread
#mysql importing and handling
try:
import mysql.connector as sql
except:
#mysql installing from buildin setup or web, if not exists
if tkinter.messagebox.askyesno("Error", "MySQL is not
installed\nYou need to install MySQL\nWould you like to
run MySQL installer?"):
try:
os.system(r".\additionals\mysql.msi")
except:
tkinter.messagebox.showerror("Error", "Sorry
application N.A.\nKindly download mysql youself.")
sys.exit(0)
else:
if tkinter.messagebox.askyesno("Query", "Do you want
to continue installing from web? \nKindly start program
after installing mysql."):
webbrowser.open(r"https://dev.mysql.com/downloads/file/?
id=508935")
sys.exit(0)
#============================================
=============================================
=============================================
=======
user= uname_e.get()
pwdd= pwd_e.get()
#window for choosing between option 1 & 2, i.e.create
or load
global deff
deff=Toplevel()
deff.focus()
entry.eval(f'tk::PlaceWindow {str(deff)} center')
#placing the window at the center of screen
deff.wm_iconbitmap(r".\additionals\icon.ico")
deff.config(bg="beige")
deff.title("Load Database")
deff.geometry("350x230")
deff.resizable(False, False)
inf= Label(deff, text="Database Does Not Exist \
nCreate the database \nor Load from any Local Path\nif this
is your 1st time u can create!",bg="beige" ,font=("Arial",
16, "bold"))
inf.place(x=0, y=20)
btn_createdb= Button(deff, text="Create", width=13,
height=2, bg="#20bebe",font=("arial 10 bold"),
cursor="hand2", command=create_fun)
btn_createdb.place(x=60, y=140)
btn_loaddb= Button(deff, text="Load", width=13,
height=2, bg="#20bebe",font=("arial 10 bold"),
cursor="hand2", command=load_fun)
btn_loaddb.place(x=200, y=140)
deff.mainloop()
#ENTRY WINDOW
entry=Tk()
entry.title("STORE MANAGEMENT-RAJA.enter")
#putting title name of window
entry.wm_iconbitmap(r".\additionals\icon.ico") #title
icon
entry.geometry("550x500+160+15") #size of window
in pixels
entry.configure(background="beige")
entry.resizable(False, False) #making the window Non-
extendable
#getting all the ids to make the id for the next stock addition
item
def get_ids(*args, **kwargs):
conn= sql.connect(host="localhost", user=uname,
passwd=pwd, database=dbName)
c=conn.cursor()
c.execute(f"select ID from {TableName} order by id;")
global ids_list
ids_list=[]
x= c.fetchall()
if x!=[]:
for i in x:
ids_list.append(i[0])
else:
ids_list.append(0)
global ids_len
ids_len= int(len(ids_list))
get_ids()
self.a=i[1]
self.name_e.insert(END,self.a)
self.b= i[2]
self.stock_e.insert(END,self.b)
self.c=i[3]
self.cp_e.insert(END, self.c)
self.d=i[4]
self.sp_e.insert(END, self.d)
self.a1= i[5]
self.a2= i[6]
self.a3= i[7]
self.e=i[8]
self.vendor_e.insert(END, self.e)
if self.name_e.get()=="":
prr()
else:
self.clear()
prr()
else:
tkinter.messagebox.showerror("Error!!!",
"Product ID not present in database \nYou can add the
product from the stock addition section.")
self.clear()
self.textt.place_forget()
# self.searche.delete(0, END)
# self.searche.focus()
except ValueError:
tkinter.messagebox.showerror("Error", "Enter
valid ID")
c= self.conn.cursor()
c.execute(f"use {dbName};")
c.execute(f"select * from {TableName};")
self.rows= []
for x in c:
self.rows.append(x)
scrollbar= Scrollbar(master)
scrollbar.place(x=1043, y=72, height=475)
style = ttk.Style(master)
style.theme_use('clam')
self.trees= ttk.Treeview(master,
selectmode="browse")
self.profit= Label(master, text="", font=('ariel', 20,
'bold'), fg="darkred",bg="#88BDBC")
self.profit.place(x=280, y=570)
self.trees.config(yscrollcommand=scrollbar.set)
scrollbar.config(command= self.trees.yview)
def close(*args, **kwargs):
closer()
sys.exit(0)
def back(*args, **kwargs):
root1.title("STORE MANAGEMENT-
RAJA.Billing")
style = ttk.Style(root1)
style.theme_use("classic")
style.configure("Treeview", background="silver",
fieldbackground="#55BDCA", foreground="black")
style.map("Treeview", background=[('selected',
'aliceblue')])
root1.geometry("1260x645")
center(root1)
right.pack(side=RIGHT)
try:
btn.destroy()
except:
pass
master.destroy()
bill_btn()
btn1= Button(master, text="CLOSE", padx=20,
pady=10, command=close, bg="brown", cursor="hand2")
btn1.place(x=940, y=600)
btn_back= Button(master, text="Back", padx=20,
pady=10, command=back, bg="brown", cursor="hand2")
btn_back.place(x=850, y=600)
self.count=0
self.setup()
#function for sorting the table data
def callback(selection, *args, **kwargs):
if selection=="By Date":
sortbyoptions.place_forget()
ll1.config(text="Sort By Date")
dump_btn.place_forget()
now = datetime.datetime.now()
y= int(now.strftime("%Y"))
m= int(now.strftime("%m"))
d= int(now.strftime("%d"))
cal= tkcalendar.Calendar(master,
selectmode="day", year=y, day=d, month=m)
cal.place(x=190, y=10)
def calp(*args, **kwargs):
cal.place(x=190, y=10)
btt2.config(text="Hide Calendar")
btt2.config(command=calf)
def calf(*args, **kwargs):
cal.place_forget()
btt2.config(text="Show Calendar")
btt2.config(command= calp)
def btt_fun(*args, **kwargs):
self.ll.place_forget()
cal.config(date_pattern='dd.MM.yyyy')
date=cal.get_date()
self.trees.delete(*self.trees.get_children())
c.execute(f"select * from {TableName}
WHERE date='{date}'")
data=c.fetchall()
self.count=0
if data!=[]:
for i in data:
self.trees.insert(parent='', index='end',
iid=self.count, text="", values=(f"{i[0]}",f"{i[1]}",f"{i[2]}",
f"{i[3]}", f"{i[4]}", f"{i[5]}", f"{i[6]}", f"{i[7]}", f"{i[8]}",
f"{i[9]}", f"{i[10]}"))
self.count+=1
else:
self.ll.config(text=f"No Data Found on
{date}")
self.ll.place(x=400, y=300)
pro=[]
for i in self.trees.get_children():
pro.append(int(self.trees.item(i)['values']
[7]))
self.profit.config(text=f"Total Assumed
Profit= Rs.{sum(pro)}/-")
def callcan(*args, **kwargs):
self.trees.delete(*self.trees.get_children())
self.setup()
btt.destroy()
btt2.destroy()
cal.destroy()
btt3.destroy()
ll1.config(text="Sort By")
sortbyoptions.place(x=120, y=15)
dump_btn.place(x=930, y=10)
self.ll.place_forget()
self.count=0
value_inside.set("Select an option")
btt= Button(master, text="Sort", font=('ariel',
17, 'bold'), bg="lightgreen", command=btt_fun)
btt.place(x=480,y=10 )
btt2= Button(master, text="Hide
Calendar",font=('ariel', 17, 'bold'), bg="lightgreen",
command=calf)
btt2.place(x=600, y=10)
btt3= Button(master, text="Cancel
Sort",font=('ariel', 17, 'bold'), bg="lightgreen",
command=callcan)
btt3.place(x=820, y=10)
value_in = StringVar(master)
val=["January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December"]
realm=['01','02','03','04', '05', '06', '07', '08', '09',
'10', '11', '12']
me= tkinter.ttk.Combobox(master,
textvariable=value_in, values=val, state='readonly')
me.place(x=210, y=20)
value_in.set("select month")
me.bind("<<ComboboxSelected>>", callme)
me.configure(width=20)
me.config(height=25)
me.config(font=("arial", 17, "bold"))
me.bind("<Return>", callme)
me.focus()
val_s= IntVar()
s= Spinbox(master, from_=2018, to=2025,
textvariable=val_s, width=9, font=("Ariel", 15, "bold"))
s.place(x=530, y=20)
val_s.set("2021")
s.bind("<Return>", callme)
def callcanc(*args, **kwargs):
self.trees.delete(*self.trees.get_children())
value_inside.set("Select an option")
self.setup()
me.destroy()
s.destroy()
btc.destroy()
bts.destroy()
self.ll.place_forget()
self.count=0
pro=[]
for i in self.trees.get_children():
pro.append(int(self.trees.item(i)['values']
[7]))
self.profit.config(text=f"Total Assumed
Profit= Rs.{sum(pro)}/-")
ll1.config(text="Sort By")
sortbyoptions.place(x=120, y=15)
dump_btn.place(x=930, y=10)
bts= Button(master, text="SORT",font=('ariel',
17, 'bold'), bg="lightgreen", command=callme)
bts.place(x=700, y=10)
btc= Button(master, text="Cancel
Sort",font=('ariel', 17, 'bold'), bg="lightgreen",
command=callcanc)
btc.place(x=840, y=10)
elif selection=="By Year":
sortbyoptions.place_forget()
ll1.config(text="Sort By Year")
dump_btn.place_forget()
def callme(*args, **kwargs):
self.ll.place_forget()
sel=s.get()
self.trees.delete(*self.trees.get_children())
c.execute(f"select * from {TableName}")
check=()
for i in c.fetchall():
if i[9][6:]==sel:
if i[9] not in check:
check+=(i[9],)
data= None
if check!=():
c.execute(f"select * from {TableName}
where date in {check}")
data = c.fetchall()
else:
self.ll.config(text=f"No Data Found for
{sel}")
self.ll.place(x=300, y=300)
self.count=0
if data!=[] and data!=None:
for i in data:
self.trees.insert(parent='', index='end',
iid=self.count, text="", values=(f"{i[0]}",f"{i[1]}",f"{i[2]}",
f"{i[3]}", f"{i[4]}", f"{i[5]}", f"{i[6]}", f"{i[7]}", f"{i[8]}",
f"{i[9]}", f"{i[10]}"))
self.count+=1
pro=[]
for i in self.trees.get_children():
pro.append(int(self.trees.item(i)['values']
[7]))
self.profit.config(text=f"Total Assumed
Profit= Rs.{sum(pro)}/-")
val_s= IntVar()
s= Spinbox(master, from_=2018, to=2025,
textvariable=val_s, width=9, font=("Ariel", 15, "bold"))
s.place(x=210, y=20)
s.bind("<Return>", callme)
val_s.set("2021")
s.focus()
def callcanc(*args, **kwargs):
self.trees.delete(*self.trees.get_children())
value_inside.set("Select an option")
self.setup()
s.destroy()
btc.destroy()
bts.destroy()
self.ll.place_forget()
self.count=0
pro=[]
for i in self.trees.get_children():
pro.append(int(self.trees.item(i)['values']
[7]))
self.profit.config(text=f"Total Assumed
Profit= Rs.{sum(pro)}/-")
ll1.config(text="Sort By")
sortbyoptions.place(x=120, y=15)
dump_btn.place(x=930, y=10)
bts= Button(master, text="SORT",font=('ariel',
17, 'bold'), bg="lightgreen", command=callme)
bts.place(x=400, y=10)
btc= Button(master, text="Cancel
Sort",font=('ariel', 17, 'bold'), bg="lightgreen",
command=callcanc)
btc.place(x=540, y=10)
c= self.conn.cursor()
c.execute(f"use {dbName};")
c.execute(f"select * from transactions;")
self.rows= []
for x in c:
self.rows.append(x)
scrollbar= Scrollbar(master)
scrollbar.place(x=723, y=75, height=470)
style = ttk.Style(root1)
style.theme_use('clam')
self.trees= ttk.Treeview(master,
selectmode="browse")
self.trees.config(yscrollcommand=scrollbar.set)
self.profitt= Label(master, text="", font=('ariel', 19,
'bold'), fg="darkred",bg="#88BDBC")
self.profitt.place(x=245, y=570)
scrollbar.config(command= self.trees.yview)
self.count=0
self.setup()
#showing bill functions
def hide_bill(*args, **kwargs):
txt.destroy()
root1.geometry("900x620+160+5")
center(root1)
canvas.config(width=900, height=620)
btn_showbill.config(text="Show Bill",
command=show_bill)
def show_bill(*args, **kwargs):
selc= self.trees.selection()
if selc!=():
root1.geometry("1200x620+20+5")
center(root1)
canvas.config(width=1200, height=620)
global txt
txt= Text(master, width=53, height=27)
txt.place(x=750, y=50)
invoiceid=self.trees.item(int(selc[0]))["values"]
[7]
date=self.trees.item(int(selc[0]))["values"][5]
time=self.trees.item(int(selc[0]))["values"][6]
invoicedate=date[6:]+"-"+date[3:5]+"-"+date[:2]
dr=f".\\additionals\\Invoices\\{invoicedate}\\
{invoiceid}.rtf"
def open_bill(*args, **kwargs):
try:
def inside(*args, **kwargs):
os.system(dr)
_thread.start_new_thread(inside,())
except:
tkinter.messagebox.showerror("Error",
"Operation is not working")
open_btn= Button(master, text="Open Original
Bill File", font=('ariel', 17, 'bold'), bg="lightgreen",
command=open_bill)
open_btn.place(x=900, y=500)
try:
f= open(dr, "r")
read=f.readlines()
file=[]
for i in range(9, len(read)):
file.append(read[i][3:])
f.close()
except:
hide_bill()
tkinter.messagebox.showinfo("Error", "Bill
Not Found!")
return
file.insert(-7, "\n")
txt.insert(END,"\t\tRaja Store Management\n")
txt.insert(END, "\t\t Roorkee-India\n")
txt.insert(END, "\t\t phone-xxxxxxxxx\n")
txt.insert(END, "\t\t\tInvoice\n\n")
txt.insert(END, f"Date:{date}\t\t\t\tTime-
{time}")
txt.insert(END, '''
=============================================
===
Sno. Product Name Qty Amount
=============================================
===\n''')
for i in file:
txt.insert(END, i)
btn_showbill.config(text="Hide Bill",
command= hide_bill)
#showing bill
btn_showbill= Button(master, text="Show
Bill",font=('ariel', 17, 'bold'), bg="lightgreen", command=
show_bill)
btn_showbill.place(x=745, y=500)
value_in = StringVar(master)
val=["January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December"]
realm=['01','02','03','04', '05', '06', '07', '08', '09',
'10', '11', '12']
me= tkinter.ttk.Combobox(master,
textvariable=value_in, values=val, state='readonly')
me.place(x=40, y=20)