from tkinter import *
from PIL import ImageTk, Image
from sqlite3 import *
from tkinter import ttk
from tkinter import messagebox
import time



def create():
    global BILL_N,BILL_A,BILL_A_DUE,BILL_UNITS
    conn = connect('database.db')#

    c = conn.cursor()
   
    # c.execute('''CREATE TABLE K_BILL (account_number integer PRIMARY KEY,

    #  name text,

    #  units integer,

    #  amount_due integer,
   
    #  amount integer)''')
   
   

    # c.execute(''' INSERT INTO K_Bill VALUES (4902233658724, 'SAMIULLAH', 800 , 20267,800*13)''')
    # c.execute(''' INSERT INTO K_Bill VALUES (3769186408275, 'Ali', 25000, 25267,436*13)''')
    # c.execute(''' INSERT INTO K_Bill VALUES (9863867106183, 'Faez', 22000, 22567,658*13)''')
    c.execute(''' UPDATE K_BILL set units=436 where account_number=3769186408275''' )
    c.execute(''' UPDATE K_BILL set units=658 where account_number=9863867106183''' )
    c.execute(''' UPDATE K_BILL set amount_due=amount+267 where account_number=4902233658724''' )
    c.execute(''' UPDATE K_BILL set amount_due=amount+267 where account_number=3769186408275''' )
    c.execute(''' UPDATE K_BILL set amount_due=amount+267 where account_number=9863867106183''' )
    a_n= c.execute('''SELECT account_number FROM K_Bill''')
    a_n1=a_n.fetchall()
    print(a_n1)
    name=c.execute('''SELECT name FROM K_BILL''')
    name_1=name.fetchall()
    print(name_1)
    amount=c.execute('''SELECT amount  FROM K_BILL''')
    amount_1=amount.fetchall()
    print(amount_1)
    a_due=c.execute('''SELECT amount_due FROM K_BILL''')
    a_due1=a_due.fetchall()
    print(a_due1)
    units=c.execute('''SELECT units FROM K_BILL''')
    units_1=units.fetchall()
    print(units_1)


   

   

   
    print(a_n1[0][0])
    print(a_n1[1][0])
    print(a_n1[2][0])
   

   

       
    if cb.get()==a_n1[0][0]:
        BILL_N=name_1[0][0]
        BILL_A=amount_1[0][0]
        BILL_A_DUE=a_due1[0][0]
        BILL_UNITS=units_1[0][0]
        print(BILL_N,BILL_A,BILL_A_DUE,BILL_UNITS)

    elif cb.get()==a_n1[1][0]:
        BILL_N=name_1[1][0]
        BILL_A=amount_1[1][0]
        BILL_A_DUE=a_due1[1][0]
        BILL_UNITS=units_1[1][0]
        print(BILL_N,BILL_A,BILL_A_DUE,BILL_UNITS)

         

    elif cb.get()==a_n1[2][0]:
        BILL_N=name_1[2][0]
        BILL_A=amount_1[2][0]
        BILL_A_DUE=a_due1[2][0]
        BILL_UNITS=units_1[2][0]
        print(BILL_N,BILL_A,BILL_A_DUE,BILL_UNITS)
       

   


    conn.commit()
    c.close()

    conn.close()

def view_bill():

    email_get=Email_e3.get()
    email_check1="@gmail.com"
    email_check2="@yahoo.com"
    try:
        C1=int(Consumer_Number_Var.get())
        C2=True
    except ValueError:
        C2=False
   
   
   
    if len(Consumer_Number_Var.get()) ==8 and C2==True:
          pass
    else:
          mb1=messagebox.showerror(title='ERROR!',message='Please enter valid consumer number')
          CN_e2.delete(0,END)
          return
    if email_get.endswith(email_check1) or email_get.endswith(email_check2):
       pass
    else:
          mb2=messagebox.showerror(title='ERROR!',message='Please enter valid email address')
          Email_e3.delete(0,END)
          return
    if ContactVar.get().startswith("03") and len(ContactVar.get())==11 and ContactVar.get().isdigit:
        pass
    else:
        mb3=messagebox.showerror(title='ERROR!',message='Please enter valid contact number')
        MN_e3.delete(0,END)
        return
    bar = ttk.Progressbar(m,orient=HORIZONTAL,length=300)
    bar.place(x=550,y=550)
    KB = 100
    download = 0
    speed = 1
    percent = StringVar()
    percentLabel = Label(m,textvariable=percent,bg="orange").place(x=850,y=550)
    generatingLabel = Label(m,text="Generating Duplicate Bill",bg="orange").place(x=650,y=570)
   
    while(download<KB):
        time.sleep(0.025)
        bar['value']+=(speed/KB)*100
        download+=speed
        percent.set(str(int((download/KB)*100))+"%")
        m.update_idletasks()#shows updating of  progressbar otherwise it would complete and show
   

   

   


    m.destroy()
    m1 = Tk()
    photo = PhotoImage(file = 'k-electric-vector-logo.png')
    m1.wm_iconphoto(False, photo)
    m1.geometry('500x640')
    m1.config(bg="orange")
    m1.title("K-Electric Duplicate Bill Front Page")
   


    bill_front1 = PhotoImage(file="bill front.png")
    bill_front=bill_front1.subsample(2,2)
    bill_front_label = Label(m1,image=bill_front)
    bill_front_label.place(x=25, y=0)

    invoice_label=Label(m1,text="440006032688",bg="white",font=("",7))
    invoice_label.place(x=255,y=155)

    issue_label=Label(m1,text="13-Jan-23",bg="white",font=("",6))
    issue_label.place(x=345,y=156)

    billmonth_label=Label(m1,text="Jan-23",bg="white",font=("",6))
    billmonth_label.place(x=420,y=156)

    duedate_label=Label(m1,text="13\nFebruary\n2023",font=("",7,"bold"),bg="#bcd0ea")
    duedate_label.place(x=403,y=246)
   
    save_rslabel=Label(m1,text="Rs 267",font=("",9,"bold"),bg="#bcd0ea")
    save_rslabel.place(x=290,y=260)

    mm_yy_rslabel=Label(m1,text="08/22\n09/22\n10/22\n11/22\n12/22\n02/24",font=("",6),bg='white')
    mm_yy_rslabel.place(x=45,y=410)

    biledamountlabel=Label(m1,text="32,000.05\n42,898.76\n22,989.98\n38,787.98\n61,343.82\n28,500.56",font=("",6),bg='white')
    biledamountlabel.place(x=90,y=410)


    pay_datelabel=Label(m1,text="28-Dec-22\n22-Nov-22\n23-Oct-22\n26-Sep-22\n20-Aug-22\n28-Feb-22",font=("",6),bg="white")
    pay_datelabel.place(x=140,y=410)

    paymentlabel=Label(m1,text="32,000.00\n42,899.00\n22,989.00\n38,788.00\n61,344.00\n28,501",font=("",6),bg="white")
    paymentlabel.place(x=200,y=410)

    create()
    units_label=Label(m1,text=str(BILL_UNITS)+"  Units",font=('',11,"bold"),bg="#e6f0d8")
    units_label.place(x=40,y=188)

    name_label=Label(m1,text=BILL_N,bg="white",font=("",11,"bold"))
    name_label.place(x=39,y=69)

    n_address_lb=Label(m1,text="MISS ASMA APARTMENT F/C/34 PLOT 24/F/6 PECHS.",font=("",6,""),bg="white")
    n_address_lb.place(x=40,y=88)
    n_address_lb2=Label(m1,text="Contract No. 31236827\nDispatch ID: 071491710\nConsumer No.: LA034130",font=("",6,""),bg="white",justify= LEFT)
    n_address_lb2.place(x=40,y=99)

    amount_label=Label(m1,text="Rs. "+str(BILL_A),font=('',11,"bold"),bg="#8bc442")
    amount_label.place(x=258,y=188)

    amount_due_label=Label(m1,text="Rs. "+str(BILL_A_DUE),font=('',11,"bold"),bg="#ffe5ca")
    amount_due_label.place(x=258,y=321)

    Lastmonth_units_label=Label(m1,text="330"+"  Units       ⬇11%",font=('',7,"bold"),bg="#e6f0d8")
    Lastmonth_units_label.place(x=39,y=242)

    Lastyear_units_label=Label(m1,text="310"+"  Units       ⬇4%",font=('',7,"bold"),bg="#e6f0d8")
    Lastyear_units_label.place(x=142,y=242)

    AccountNo_label=Label(m1,text=cb.get(),font=('',7,"bold"),bg="white")
    AccountNo_label.place(x=256,y=130)

    message_board=Label(m1,text="Switch off and unplug when appliance are \nnot being use to save energy",font=("",7),justify=LEFT,bg="#e8e8e8")
    message_board.place(x=260,y=366)

    invoice_lb=Label(m1, text="440006032688                                                        13-Feb-23",bg="white",font=("",6))
    invoice_lb.place(x=258,y=536)

    without_due_lb=Label(m1,text="RS. "+str(BILL_A),bg="white",font=("",6))
    without_due_lb.place(x=258,y=566)

    with_due_lb=Label(m1,text="RS. "+str(BILL_A_DUE),bg="white",font=("",6))
    with_due_lb.place(x=410,y=566)

    customername_label=Label(m1,text=str(BILL_N),font=("",6,'bold'),bg='white')
    customername_label.place(x=188,y=558)

    accountNo_label=Label(m1,text=str(cb.get())+'\n31236827',font=("",6,'bold'),bg='white',justify=RIGHT)
    accountNo_label.place(x=183,y=570)











   


    m1.mainloop()
   
def window():
    global m,cb,Consumer_Number_Var,Email_e3, ContactVar,CN_e2,MN_e3
    mw.destroy()
    m = Tk()

    m.config(bg="orange")
    photo = PhotoImage(file = 'k-electric-vector-logo.png')
    m.wm_iconphoto(False, photo)
    m.title("K-Electric Duplicate Bill")
    m.geometry("1020x600")
    KE_image =  ImageTk.PhotoImage(Image.open("K-Electric-Duplicate-Bill front page(2).jpg"))
    KE_label = Label(m,image=KE_image)
    KE_label.place(x=0,y=0)

    ac_lb=Label(m,text="Account Number *",fg="#00008B",bg="orange",font="Bold")
    ac_lb.place(x=40,y=250)

    under_Account_label = Label(m,text="13-digits Account Number written on top right hand of KE Bill",fg="#00008B",bg='orange',font=("",10))
    under_Account_label.place(x=40,y=310)

    Email_label = Label(m,text="Email",fg="#00008B",bg='orange',font="BOLD")
    Email_label.place(x=40,y=425)
    under_Email_label = Label(m,text="(Please provide a valid email address to receive your KE bill by Email)",fg="#00008B",bg='orange',font=("",10))
    under_Email_label.place(x=40,y=485)

    Consumer_label = Label(m,text="Consumer Number  *",bg='orange',fg="#00008B",font="BOLD")
    Consumer_label.place(x=600,y=250)
    under_Consumer_label = Label(m,text="8 digits",fg="#00008B",bg='orange',font=("",10))
    under_Consumer_label.place(x=600,y=310)

    Mobile_label = Label(m,text="Mobile Number  *",fg="#00008B",bg='orange',font="BOLD")
    Mobile_label.place(x=600,y=425)
    under_Mobile_label = Label(m,text="eg: 03xx-xxxxxxx. Please provide your active mobile number",fg="#00008B",bg='orange',font=("",10))
    under_Mobile_label.place(x=600,y=485)
    cb=IntVar()
    combobox=ttk.Combobox(m,values=["3769186408275","4902233658724","9863867106183"],width=62,textvariable=cb)
    combobox.set("3769186408275")

    combobox.place(x=40,y=290)

    Consumer_Number_Var=StringVar()
    CN_e2=Entry(m,width=65,textvariable=Consumer_Number_Var)
    CN_e2.place(x=600,y=290)

    Email_e3=Entry(m,width=65)
    Email_e3.place(x=40,y=465)

    ContactVar=StringVar()
    MN_e3=Entry(m,width=65,textvariable=ContactVar)
    MN_e3.place(x=600,y=465)

    Enter_Btn=Button(m,text="view bill",fg="white",bg="green",padx=30,relief=RAISED,highlightbackground = "black", highlightthickness = 2,command=view_bill)
    Enter_Btn.place(x=882,y=550)

    m.mainloop()

mw=Tk()
mw.title('Welcome to KE-Bill generator app by Dual-Coderz')
photo = PhotoImage(file = 'k-electric-vector-logo.png')
mw.wm_iconphoto(False, photo)

mw.geometry("1020x600")
Titleimage=PhotoImage(file='titlepage.png')
Titleimage2=Titleimage.subsample(2,2)
title_label=Label(mw,image=Titleimage)
title_label.place(x=0,y=0)
Duplicate_bill_Btn=Button(mw,text="Duplicate  Bill ",fg="#3792cb",bg="orange",command=window,relief=RIDGE,bd=5,font=("",12,'bold'))
Duplicate_bill_Btn.place(x=60,y=300)


mw.mainloop()

Comments

Popular posts from this blog