Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from decimal import *
- from calendar import *
- import datetime
- import time
- import os
- ##import pyttsx
- ##import pyautogui
- import sys
- import xlwt
- from xlutils.copy import copy
- from xlwt import easyxf
- from xlrd import open_workbook
- import xlsxwriter
- #import Tkinter as tk
- #try:
- # from tkinter import * # Python 3.x
- #except:
- # from Tkinter import * # Python 2.x
- ##def locate(imageName):
- ##
- ## try:
- ## buttonPos = pyautogui.locateOnScreen(imageName,5)
- ## if buttonPos != None:
- ## x,y,a,b = buttonPos
- ## pyautogui.moveTo(x,y,3)
- ## pyautogui.moveRel(5,5,1)
- ## except:
- ## pass
- ##
- ##def tutorial(self, tEnt):
- ##
- ## tutWindow = Tk()
- ## tutWindow.title("Accountant Guide")
- ## tutWindow.wm_attributes("-topmost",1)
- ## tutWindowFrame = Frame(tutWindow, width=300,height=5)
- ## tutWindowFrame.grid()
- ## tutWindowFrame.pack()
- ##
- ## txtFrame = Frame(tutWindow, width=300, height=600)
- ## txtFrame.pack(fill="both", expand=True)
- ## txtFrame.grid_propagate(False)
- ## txtFrame.grid_rowconfigure(0, weight=1)
- ## txtFrame.grid_columnconfigure(0, weight=1)
- ##
- ## text = Text(txtFrame, borderwidth=3, relief="sunken")
- ## text.config(font=("consola", 12),undo=True, wrap='word')
- ## text.grid(row=1,column=0,sticky="nsew",padx=2,pady=2)
- ##
- ## scrollb = Scrollbar(txtFrame, command=text.yview)
- ## scrollb.grid(row=1,column=1,sticky='nsew')
- ## text['yscrollcommand'] = scrollb.set
- ##
- ## #Assigning position of window to bottom rightside of screen
- ## windowWidth = 400
- ## windowHeight = 600
- ## positionRight = int(tutWindow.winfo_screenwidth()-windowWidth)
- ## positionDown = int(tutWindow.winfo_screenheight()-windowHeight)
- ## tutWindow.geometry("400x600")
- ## tutWindow.geometry("+{}+{}".format(positionRight, positionDown))
- ##
- ## startButton = Button(tutWindowFrame, text="Start Tutorial")
- ## startButton['command'] = lambda a=text, b=tutWindow, c=self, d=tEnt: warningFirst(a,b,c,d)
- ## startButton.grid(row=0,column=0)
- ##
- ## tutWindow.update_idletasks()
- ##
- ##def warningFirst(text, tutWindow, self, tEnt):
- ##
- ## noTouch = Tk()
- ## noTouchFrame = Frame(noTouch, width=300,height=100)
- ## textToTouch = Label(noTouch, text = "DO NOT TOUCH THE MOUSE DURING THIS TUTORIAL")
- ## textToTouch.grid(row=0,column=0)
- ##
- ## textToTouch = Label(noTouch, text = "Sit back and enjoy the Show!")
- ## textToTouch.grid(row=1,column=0)
- ##
- ## continueBut = Button(noTouch, text="continue")
- ## continueBut['command'] = lambda a=text,b=tutWindow,c=noTouch,d=self,e=tEnt:startSeq(a,b,c,d,e)
- ## continueBut.grid(row=2,column=0)
- ##
- ##def startSeq(text, tutWindow, noTouch, self, tEnt):
- ##
- ##
- ## noTouch.destroy()
- ##
- ## textAdd = "Welcome to the interactive tutorial for my accountant"
- ## addText(textAdd, text, tutWindow)
- ##
- ##
- ## textAdd = "This guide will walk you through how to set up your accountant program"
- ## addText(textAdd, text, tutWindow)
- ##
- ## imageName = "screenshots/billCalMainWin.PNG"
- ## locate(imageName)
- ##
- ## textAdd = "In this window you can cycle through the months"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "Add bills and income and much more"
- ## addText(textAdd, text, tutWindow)
- ##
- ##
- ## imageName = 'screenshots/monthLeft.PNG'
- ## locate(imageName)
- ## textAdd = "This button will take you through previous months"
- ## addText(textAdd, text, tutWindow)
- ## self.prevMonth()
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/monthRight.PNG'
- ## locate(imageName)
- ## textAdd = "This button will take you through following months"
- ## addText(textAdd, text, tutWindow)
- ## self.nextMonth()
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/monthButton5.PNG'
- ## locate(imageName)
- ## textAdd = "Clicking a day of the month will allow you to add bills or income"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "Lets add some bills"
- ## addText(textAdd, text, tutWindow)
- ## self.addBill(day=4,weekDay=1)
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/nameOfWorkBook.png'
- ## locate(imageName)
- ## textAdd = "Here you will find the name of the file holding your bill"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "!!DO NOT EVER CHANGE THIS!!"
- ## addText(textAdd, text, tutWindow)
- ##
- ##
- ## imageName = 'screenshots/billName.png'
- ## locate(imageName)
- ## pyautogui.moveRel(100,0,2)
- ## textAdd = "Type the name of your bill here"
- ## addText(textAdd, text, tutWindow)
- ##
- ## pyautogui.doubleClick()
- ## tutWindow.update()
- ## pyautogui.typewrite(["R","e","n","t"], interval=1)
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/billCost.png'
- ## locate(imageName)
- ## pyautogui.moveRel(100,0,2)
- ## textAdd = "Type the cost of your bill here"
- ## addText(textAdd, text, tutWindow)
- ##
- ## pyautogui.doubleClick()
- ## tutWindow.update()
- ## pyautogui.typewrite(["8","0","0"], interval=1)
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/billSubmit.png'
- ## locate(imageName)
- ## textAdd = "After entering the info you will click here to create the bill"
- ## addText(textAdd, text, tutWindow)
- ## click()
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/billName.png'
- ## locate(imageName)
- ## pyautogui.moveRel(100,0,2)
- ## textAdd = "Type the name of your bill here"
- ## addText(textAdd, text, tutWindow)
- ##
- ## pyautogui.doubleClick()
- ## tutWindow.update()
- ## pyautogui.typewrite(["p","o","w","e","r","b","i","l","l"], interval=1)
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/billCost.png'
- ## locate(imageName)
- ## pyautogui.moveRel(100,0,2)
- ## textAdd = "Type the cost of your bill here"
- ## addText(textAdd, text, tutWindow)
- ##
- ## pyautogui.doubleClick()
- ## tutWindow.update()
- ## pyautogui.typewrite(["6","5"], interval=1)
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/billSubmit.png'
- ## locate(imageName)
- ##
- ## textAdd = "After entering the info you will click here to create the bill"
- ## addText(textAdd, text, tutWindow)
- ## click()
- ## tutWindow.update()
- ##
- ## textAdd = "To see all bills for the current day you click search"
- ## addText(textAdd, text, tutWindow)
- ## imageName = 'screenshots/billSearch.png'
- ## locate(imageName)
- ## global c
- ## c = 1
- ## click()
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/billPurge.png'
- ## locate(imageName)
- ##
- ## textAdd = "If you need to get rid of a bill simply click Purge"
- ## addText(textAdd, text, tutWindow)
- ## tutWindow.update()
- ##
- ## textAdd = "But know that this will delete ALL bills on that given day"
- ## addText(textAdd, text, tutWindow)
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/incomeButton.png'
- ## locate(imageName)
- ##
- ## textAdd = "Clicking income will allow you to add an income"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "Lets add income"
- ## addText(textAdd, text, tutWindow)
- ##
- ## tEnt.incomeCol()
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/incomePayRate.png'
- ## locate(imageName)
- ## textAdd = "Here you enter your Hourly Rate"
- ## addText(textAdd, text, tutWindow)
- ##
- ## pyautogui.moveRel(100,5,2)
- ## pyautogui.doubleClick()
- ## pyautogui.typewrite('12.50', interval=1)
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/incomeHours.png'
- ## locate(imageName)
- ## textAdd = "Here you enter how many hours you work per week"
- ## addText(textAdd, text, tutWindow)
- ##
- ## pyautogui.moveRel(100,0,2)
- ## pyautogui.doubleClick()
- ## pyautogui.typewrite('35', interval=1)
- ## tutWindow.update()
- ##
- ## imageName = 'screenshots/incomeWeeks.png'
- ## locate(imageName)
- ##
- ## textAdd = "Here you will select how many weeks are in a pay period"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "If you select 0, you will add pay for that single day"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "Also note that you cannot create two paychecks on a single day"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "When adding a bonus that lands on day that already has a paycheck, make sure you fill in ALL fields like you would for a paycheck, fill in the bonus field, BUT select 0 for weeks in payperiod"
- ## addText(textAdd, text, tutWindow)
- ##
- ## imageName = 'screenshots/incomeWeeks2.png'
- ## locate(imageName)
- ##
- ## textAdd = "Selecting 2 for weeks in payperiod means you are paid biweekly"
- ## addText(textAdd, text, tutWindow)
- ##
- ## imageName = 'screenshots/incomeSubmit.png'
- ## locate(imageName)
- ## click()
- ##
- ## textAdd = "Click submit when finished"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "Congradulations!! You have successfully gone through the entire tutorial!!"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "There is more to explore, add some more bills, but dont forget to purge the already created bills and income before continuing"
- ## addText(textAdd, text, tutWindow)
- ##
- ## textAdd = "Once you have added all your bills and income try selecting the 'When to pay?' button located on the calendar window for the main feature of the Accountant!"
- ## addText(textAdd, text, tutWindow)
- ## tutWindow.destroy()
- ##
- ##def click():
- ##
- ## pyautogui.click()
- ##
- ##def addText(textAdd, text, tutWindow):
- #### engine = pyttsx.init()
- #### engine.say(str(textAdd))
- ## text.insert(1.0,"\n"+textAdd+"\n")
- #### engine.runAndWait()
- ## tutWindow.update()
- ##class log_in(Frame):
- ##
- ## def __init__(logIn, master=None):
- ##
- ## Frame.__init__(logIn, master)
- ## logIn.grid(row=0, column=0, sticky='news')
- ## label = Label(logIn, text = "Username: ")
- ## label.grid(row=0,column=0)
- ## user_name = StringVar()
- ## userName = Entry(logIn, textvariable = user_name)
- ## userName.pack()
- ## userName.insert(0,"Enter User Name")
- ## userName.grid(row=0,column=1)
- ##
- ## label = Label(logIn, text = "Password: ")
- ## label.grid(row=1,column=0)
- ## pass_word = StringVar()
- ## passWord = Entry(logIn, textvariable = pass_word)
- ## passWord.pack()
- ## passWord.insert(0,"Enter Password")
- ## passWord.grid(row=1,column=1)
- ##
- ## logInButton = Button(logIn, text= "Log In")
- ## logInButton['command'] = lambda a=user_name, b=pass_word: logIn.chckCred(a,b)
- ## logInButton.grid(row=2,column=1)
- ##
- ## registerButton = Button(logIn, text= "Register")
- ## registerButton['command'] = lambda a=user_name, b=pass_word: logIn.registerCred(a,b)
- ## registerButton.grid(row=2,column=2)
- ##
- ## def chckCred(logIn, user_name, pass_word):
- ##
- ## folderName = '/'+str(user_name)
- ## os.path.exists(folderName)
- ## if os.path.exists(folderName) == False:
- ## os.makedirs(os.path.dirname(folderName))
- ##
- ## else:
- ## print "try logging in"
- ##
- ## def registerCred(log_in, user_name, pass_word):
- ##
- ## folderName = '/'+str(user_name)
- ## os.path.exists(folderName)
- ## if os.path.exists(folderName) == False:
- ## os.makedirs(os.path.dirname(folderName))
- ##
- ## else:
- ## print "try logging in"
- ##
- ##logWindow = Tk()
- ##logWindow.lift()
- ##logWindow.geometry("300x150")
- ##logWindow.title("Accountant Log In")
- ##obj = log_in(logWindow)
- ##logWindow.mainloop()
- class Application(Frame):
- def __init__(self, master=None):
- global c
- c = 1
- Frame.__init__(self, master)
- self.grid(row=0, column=0, sticky='news')
- DateNow = datetime.datetime.now()
- self.month = int(DateNow.month)
- self.year = int(DateNow.year)
- self.day = int(DateNow.day)
- self.createDaysOfWeekLabels()
- self.dayNum = []
- # Create frames and button controls for previous, current and next month.
- self.frameList = [] # List that contains the frame objects.
- self.buttonList = [] # List that contains the button objects.
- self.toPayFrameList = []
- self.split()
- def split(self):
- global c
- month_name = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
- leftArrow = Button(self, text="<", command=self.prevMonth)
- leftArrow.grid(row = 1, column = 0)
- rightArrow = Button(self, text=">", command=self.nextMonth)
- rightArrow.grid(row = 1, column = 2)
- mFrame = Frame(self)
- self.createMonth(mFrame)
- self.frameList.append(mFrame)
- mButton = Button(self, text=month_name[self.month-1])
- mButton['command'] = lambda f=mFrame, b=mButton: self.showMonth(f, b)
- mButton.grid(row=1, column=1)
- tButton = Button(self, text="Month Bills:", relief=RIDGE)
- tButton['command'] = lambda f=mFrame, b=mButton:self.getAllTotals(f,b)
- tButton.grid(row=1, column=8)
- iButton = Button(self, text="Month Inc:", relief=RIDGE)
- iButton['command'] = lambda f=mFrame, b=mButton:self.findIncome(f,b)
- iButton.grid(row=2, column=8)
- iButton = Button(self, text="When to pay bills?", relief=RIDGE)
- iButton['command'] = self.whenToPay
- iButton.grid(row=3, column=8)
- # Grid each frame
- mFrame.grid(row=3, column=0, columnspan=7, sticky='news')
- mButton['relief'] = 'flat'
- self.buttonList.append(mButton)
- # Create year widget at top right of top frame
- label = Label(self, text=self.year)#displaying year
- label.grid(row=0, column=1)
- label = Label(self,bg = 'yellow', text='income&bill')
- label.grid(row=8, column=8)
- label = Label(self,bg = 'red', text='bill')
- label.grid(row=9, column=8)
- label = Label(self,bg = 'green', text='income')
- label.grid(row=10, column=8)
- self.mFrame = mFrame
- self.mButton = mButton
- if c == 1:
- self.addBill(day=5, weekDay=1)
- self.getAllTotals(mFrame,mButton)
- self.findIncome(mFrame,mButton)
- def getMonth(self, foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempMonth, tempDay, tempYear):
- x=0
- iterMonth = self.storeCurrMonth
- for i in month_name:
- if i == tempMonth.get():
- month = x
- toPay.destroy()
- toPay = Tk()
- self.findPayDays(foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempDay, tempYear, tempMonth)
- else:
- self.storeCurrMonth = iterMonth
- x += 1
- def getDay(self, foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempMonth, tempDay, tempYear):
- x=0
- iterDay = self.storeCurrDay
- weekday, numDays = monthrange(year, month)
- foundPrev = False
- for i in range(0,numDays+1):
- if i == tempDay.get():
- day = x
- toPay.destroy()
- toPay = Tk()
- self.findPayDays(foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempDay, tempYear, tempMonth)
- else:
- self.storeCurrDay = iterDay
- x += 1
- def whenToPay(self):
- toPay = Tk()
- month_name = ['January',
- 'February',
- 'March',
- 'April',
- 'May',
- 'June',
- 'July',
- 'August',
- 'September',
- 'October',
- 'November',
- 'December']
- month_number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
- currDate = datetime.datetime.now()
- day = int(currDate.day)
- month = int(currDate.month)
- year = int(currDate.year)
- self.storeCurrMonth = month
- self.storeCurrDay = day
- self.storeCurrYear = year
- weekday, numDays = monthrange(year, month)
- tempMonth = month
- tempDay = day
- tempYear = year
- tempStrMonth = str(month_name[month-1])
- foundPrev = False
- foundNextPrev = False
- foundNext = False
- foundNextNext = False
- self.findPayDays(foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempDay, tempYear, tempMonth)
- def findPayDays(self, foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempDay, tempYear, tempMonth):
- daysInPeriod = 0
- theWorkingMonth = month
- theWorkingDay = day
- weekday, numDays = monthrange(year, month)
- month_name = ['January',
- 'February',
- 'March',
- 'April',
- 'May',
- 'June',
- 'July',
- 'August',
- 'September',
- 'October',
- 'November',
- 'December']
- label = Label(toPay, text=year)#displaying year
- label.grid(row=1, column=4)
- tempDay = IntVar(toPay)
- tempDay.set(day)
- x = 0
- #DAY
- op = tk.OptionMenu(toPay, tempDay, *range(1,numDays+1),command=lambda
- a=foundPrev, b=day,
- c=month, d=currDate,
- e=toPay, f=foundNextPrev,
- g=foundNext, h=foundNextNext,
- i=year,j=tempMonth,
- k=tempDay, l=tempYear:self.getDay(a,b,c,d,e,f,g,h,i,j,k,l))
- op.grid(row=1, column=3)
- tempMonth = StringVar(toPay)
- tempMonth.set(month_name[month-1])
- x = 0
- #MONTH
- op = tk.OptionMenu(toPay, tempMonth, *month_name,command=lambda
- a=foundPrev, b=day,
- c=month, d=currDate,
- e=toPay, f=foundNextPrev,
- g=foundNext, h=foundNextNext,
- i=year,j=tempMonth,
- k=tempDay, l=tempYear:self.getMonth(a,b,c,d,e,f,g,h,i,j,k,l))
- op.grid(row=1, column=2)
- label = Label(toPay, text="Today is: ")#displaying month
- label.grid(row=1, column=1)
- label = Label(toPay, text="Previous Check:")
- label.grid(row=50, column=0)
- label = Label(toPay, text="Most Recent Check:")
- label.grid(row=4, column=0)
- label = Label(toPay, text="Upcoming Check:")
- label.grid(row=4, column=5)
- label = Label(toPay, text="Following Check:")
- label.grid(row=50, column=5)
- while foundPrev != True: ##Listed as MOST RECENT CHECK
- try:
- day -= 1
- incFileName = str('{:02d}'.format(month))+str('{:02d}'.format(day))+str(year)+'inc.txt'
- iFN = open(incFileName, 'r')
- prevPay = str('{:02d}'.format(month))+'/'+str('{:02d}'.format(day))+'/'+str(year)
- pPCalc = str('{:02d}'.format(day))
- label = Label(toPay, text=prevPay)
- label.grid(row=4, column=1)
- fileData = iFN.read()
- foundPrev = True
- r = 4
- c = 1
- self.getTotalPay(incFileName, toPay, r, c)
- except:
- if day < 1:
- month = month - 1
- day = 31
- if month == theWorkingMonth - 2:
- pPCalc = str('{:02d}'.format(day))
- prevPay = "Cannot locate suitable paycheck"
- label = Label(toPay, text=prevPay)
- label.grid(row=4, column=1)
- foundPrev = True
- while foundNextPrev != True: ##Listed as PREVIOUS CHECK
- try:
- day -= 1
- incFileName = str('{:02d}'.format(month))+str('{:02d}'.format(day))+str(year)+'inc.txt'
- iFN = open(incFileName, 'r')
- nextPrevPay = str('{:02d}'.format(month))+'/'+str('{:02d}'.format(day))+'/'+str(year)
- nPPCalc = str('{:02d}'.format(day))
- label = Label(toPay, text=nextPrevPay)
- label.grid(row=50, column=1)
- fileData = iFN.read()
- foundNextPrev = True
- r = 50
- c = 1
- self.getTotalPay(incFileName, toPay, r, c)
- except:
- daysInPeriod += 1
- if day < 1:
- month = month - 1
- day = 31
- if month == theWorkingMonth - 3:
- nPPCalc = str('{:02d}'.format(day))
- nextPrevPay = "None found"
- label = Label(toPay, text=nextPrevPay)
- label.grid(row=50, column=1)
- foundNextPrev = True
- day = int(theWorkingDay)#reseting day to current day
- month = int(theWorkingMonth)
- year = int(currDate.year)
- while foundNext != True: ##Listed as UPCOMING CHECK
- try:
- incFileName = str('{:02d}'.format(month))+str('{:02d}'.format(day))+str(year)+'inc.txt'
- iFN = open(incFileName, 'r')
- nextPay = str('{:02d}'.format(month))+'/'+str('{:02d}'.format(day))+'/'+str(year)
- nPCalc = str('{:02d}'.format(day))
- label = Label(toPay, text=nextPay)
- label.grid(row=4, column=6)
- fileData = iFN.read()
- day += 1
- foundNext = True
- r = 4
- c = 6
- self.getTotalPay(incFileName, toPay, r, c)
- except:
- day += 1
- if day > 31:
- month = month + 1
- day = 1
- if month == theWorkingMonth + 2:
- nPCalc = str('{:02d}'.format(day))
- nextPay = "Cannot locate suitable paycheck"
- label = Label(toPay, text=nextPay)
- label.grid(row=4, column=6)
- foundNext = True
- while foundNextNext != True: ##Listed as FOLLOWING CHECK
- try:
- incFileName = str('{:02d}'.format(month))+str('{:02d}'.format(day))+str(year)+'inc.txt'
- iFN = open(incFileName, 'r')
- nextNextPay = str('{:02d}'.format(month))+'/'+str('{:02d}'.format(day))+'/'+str(year)
- nNPCalc = str('{:02d}'.format(day))
- label = Label(toPay, text=nextNextPay)
- label.grid(row=50, column=6)
- fileData = iFN.read()
- foundNextNext = True
- r = 50
- c = 6
- self.getTotalPay(incFileName, toPay, r, c)
- except:
- day += 1
- if day > 31:
- month = month + 1
- day = 1
- if month == theWorkingMonth + 3:
- nNPCalc = str('{:02d}'.format(day))
- nextNextPay = "Cannot locate suitable paycheck"
- label = Label(toPay, text=nextNextPay)
- label.grid(row=50, column=6)
- foundNextNext = True
- self.addToWhen(pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod)
- self.payNow(pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod)
- self.paidPreviously(pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod)
- self.upComing(pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod)
- toPay.title("When to Pay")
- toPay.geometry("700x500")
- toPay.lift()
- toPay.update()
- def getTotalPay(self, incFileName, toPay, r, c):
- incFile = open(incFileName, 'r')
- data = incFile.read()
- data = float(data)
- toPay.income = data
- label = Label(toPay, text="${0:.2f}".format(data))
- label.grid(row=r, column=c+1)
- self.payData = data
- incFile.close()
- def upComing(self, pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod): #FOLLOWING
- currDate = datetime.datetime.now()
- day = int(currDate.day)
- month = int(currDate.month)
- year = int(currDate.year)
- weekday, numDays = monthrange(year, month)
- nNPCalc = int(nNPCalc)
- daysInPeriod = int(daysInPeriod)
- total = 0
- billListName = []
- billListCost = []
- billListDate = []
- passRow = 51
- passCol = 5
- for i in range(nNPCalc, nNPCalc + daysInPeriod):
- if i > numDays:
- i = i - numDays
- try:
- bookName = str('{:02d}'.format(i))+str(self.year)+'.xlsx'
- dateDiplay = str('{:02d}'.format(i))+"/"+str(self.year)
- rb = open_workbook(bookName)
- wb = copy(rb)
- s = wb.get_sheet(0)
- if rb != None:
- for sheet in rb.sheets():
- for columns in range(sheet.ncols):
- for rows in range(sheet.nrows):
- data = sheet.cell(rows,columns).value
- if columns == 0:
- if rows >= 1:
- billListDate.append(dateDiplay)
- billListName.append(data)
- if columns == 1:
- if rows >= 1:
- billListCost.append(data)
- except:
- None
- for i in billListCost:
- total += float(i)
- self.toWindow(total, billListName, billListCost, toPay, passRow, passCol, billListDate)
- def paidPreviously(self, pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod):#PREVIOUS PAY
- daysInPeriod = int(daysInPeriod) - 1
- currDate = datetime.datetime.now()
- day = int(currDate.day)
- month = int(currDate.month)
- year = int(currDate.year)
- weekday, numDays = monthrange(year, month)
- nPPCalc = int(nPPCalc)
- pPCalc = int(pPCalc)
- if pPCalc < nPPCalc:
- pPCalc += nPPCalc
- if pPCalc - nPPCalc < 7:
- pPCalc += daysInPeriod
- total = 0
- billListName = []
- billListCost = []
- billListDate = []
- passRow = 51
- passCol = 0
- for i in range(nPPCalc, pPCalc):
- if i > numDays:
- i = i - numDays
- try:
- bookName = str('{:02d}'.format(i))+str(self.year)+'.xlsx'
- dateDiplay = str('{:02d}'.format(i))+"/"+str(self.year)
- rb = open_workbook(bookName)
- wb = copy(rb)
- s = wb.get_sheet(0)
- if rb != None:
- for sheet in rb.sheets():
- for columns in range(sheet.ncols):
- for rows in range(sheet.nrows):
- data = sheet.cell(rows,columns).value
- if columns == 0:
- if rows >= 1:
- billListDate.append(dateDiplay)
- billListName.append(data)
- if columns == 1:
- if rows >= 1:
- billListCost.append(data)
- except:
- None
- for i in billListCost:
- total += float(i)
- self.toWindow(total, billListName, billListCost, toPay, passRow, passCol, billListDate)
- def payNow(self, pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod):#UPCOMING
- daysInPeriod = int(daysInPeriod) - 1
- currDate = datetime.datetime.now()
- day = int(currDate.day)
- month = int(currDate.month)
- year = int(currDate.year)
- weekday, numDays = monthrange(year, month)
- nPCalc = int(nPCalc)
- nNPCalc = int(nNPCalc)
- if nNPCalc < nPCalc:
- nNPCalc += nPCalc
- if nNPCalc - nPCalc < 7:
- nNPCalc += daysInPeriod
- total = 0
- billListName = []
- billListCost = []
- billListDate = []
- passRow = 5
- passCol = 5
- for i in range(nPCalc, nNPCalc):
- if i > numDays:
- i = i - numDays
- try:
- bookName = str('{:02d}'.format(i))+str(self.year)+'.xlsx'
- dateDiplay = str('{:02d}'.format(i))+"/"+str(self.year)
- rb = open_workbook(bookName)
- wb = copy(rb)
- s = wb.get_sheet(0)
- if rb != None:
- for sheet in rb.sheets():
- for columns in range(sheet.ncols):
- for rows in range(sheet.nrows):
- data = sheet.cell(rows,columns).value
- if columns == 0:
- if rows >= 1:
- billListDate.append(dateDiplay)
- billListName.append(data)
- if columns == 1:
- if rows >= 1:
- billListCost.append(data)
- except:
- None
- for i in billListCost:
- total += float(i)
- self.toWindow(total, billListName, billListCost, toPay, passRow, passCol, billListDate)
- def addToWhen(self, pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod):#MOST RECENT
- daysInPeriod = int(daysInPeriod) - 1
- currDate = datetime.datetime.now()
- day = int(currDate.day)
- month = int(currDate.month)
- year = int(currDate.year)
- weekday, numDays = monthrange(year, month)
- pPCalc = int(pPCalc)
- nPCalc = int(nPCalc)
- if nPCalc < pPCalc:
- nPCalc += pPCalc
- if nPCalc - pPCalc < 7:
- nPCalc += daysInPeriod
- total = 0
- billListName = []
- billListCost = []
- billListDate = []
- passRow = 5
- passCol = 0
- for i in range(pPCalc, nPCalc):
- if i > numDays:
- i = i - numDays
- try:
- bookName = str('{:02d}'.format(i))+str(self.year)+'.xlsx'
- dateDiplay = str('{:02d}'.format(i))+"/"+str(self.year)
- rb = open_workbook(bookName)
- wb = copy(rb)
- s = wb.get_sheet(0)
- if rb != None:
- for sheet in rb.sheets():
- for columns in range(sheet.ncols):
- for rows in range(sheet.nrows):
- data = sheet.cell(rows,columns).value
- if columns == 0:
- if rows >= 1:
- billListDate.append(dateDiplay)
- billListName.append(data)
- if columns == 1:
- if rows >= 1:
- billListCost.append(data)
- except:
- None
- for i in billListCost:
- total += float(i)
- self.toWindow(total, billListName, billListCost, toPay, passRow, passCol, billListDate)
- def toWindow(self, total, billListName, billListCost, toPay, passRow, passCol, billListDate):
- ## old_frame = tk.Frame(toPay)
- ## toPay = tk.Frame(toPay)
- label = Label(toPay, text = "Bill Name")
- label.grid(row=passRow, column=passCol)
- saveOrBorrow = self.payData + total
- if saveOrBorrow < 0:
- borrow = float(saveOrBorrow)*-1
- billListName.append("NEED to Borrow:")
- billListCost.append("{0:.2f}".format(borrow))
- if saveOrBorrow > 0:
- save = float(saveOrBorrow)
- billListName.append("Can Save:")
- billListCost.append("{0:.2f}".format(save))
- x = passRow
- label = Label(toPay, text = "Bill Cost")
- label.grid(row=passRow, column= passCol + 1)
- for i in billListName:
- passRow += 1
- label = Label(toPay, text = " ")
- label.grid(row=passRow, column=passCol)
- label = Label(toPay, text = i)
- label.grid(row=passRow, column=passCol)
- passRow = x
- for i in billListCost:
- passRow += 1
- label = Label(toPay, text = " ")
- label.grid(row=passRow, column=passCol + 1)
- label = Label(toPay, text = i)
- label.grid(row=passRow, column=passCol + 1)
- passRow = x
- for i in billListDate:
- passRow += 1
- label = Label(toPay, text = " ")
- label.grid(row=passRow, column=passCol + 2)
- label = Label(toPay, text = i)
- label.grid(row=passRow, column=passCol + 2)
- if x > 50:
- label = Label(toPay, text = "Total Cost")
- label.grid(row=100, column=passCol)
- label = Label(toPay, text = "{0:.2f}".format(total))
- label.grid(row=100, column=passCol + 1)
- else:
- total = total
- label = Label(toPay, text = "Total Cost")
- label.grid(row=30, column=passCol)
- label = Label(toPay, text = "{0:.2f}".format(total))
- label.grid(row=30, column=passCol + 1)
- def prevMonth(self):
- self.month -= 1
- if self.month <= 0:
- self.month = 12
- self.year -= 1
- elif self.month >= 13:
- self.month = 0
- self.year += 1
- self.button = Label(self, text=' ')
- self.button.grid(row=1,column=9)
- self.button = Label(self, text=' ')
- self.button.grid(row=2,column=9)
- self.split()
- def nextMonth(self):
- self.month += 1
- for frame in self.frameList:
- frame.grid_remove()
- if self.month <= -1:
- self.month = 11
- self.year -= 1
- elif self.month >= 13:
- self.month = 1
- self.year += 1
- self.button = Label(self, text=' ')
- self.button.grid(row=1,column=9)
- self.button = Label(self, text=' ')
- self.button.grid(row=2,column=9)
- self.split()
- def createDaysOfWeekLabels(self):
- days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
- for i in range(7):
- label = Label(self, text=days[i], width = 3)
- label.grid(row = 2, column = i)
- def showMonth(self, mFrame, mButton):
- # Display all buttons normally
- for button in self.buttonList:
- button['relief'] = 'raised'
- # Set this month's button relief to flat
- mButton['relief'] = 'flat'
- # Hide all frames
- for mframe in self.frameList:
- mframe.grid_remove()
- mFrame.grid()
- def createMonth(self, mFrame):
- try:
- self.dayNum_remove()
- except:
- pass
- weekday, numDays = monthrange(self.year, self.month)
- week = 0
- for i in range(1, numDays + 1):
- self.button = Button(mFrame, text = str(i), width=3,
- command=lambda day=i, weekDay = weekday:self.addBill(day, weekDay))
- self.button.grid(row = week, column = weekday)
- weekday += 1
- if weekday > 6:
- week += 1
- weekday = 0
- def getAllTotals(self, mFrame, mButton):
- weekday, numDays = monthrange(self.year, self.month)
- week = 0
- totalCost = []
- day = 1
- theTotal = 0
- foundbill = False
- for i in range(1, numDays + 1):
- bookName = str('{:02d}'.format(day))+str(self.year)+'.xlsx'
- day += 1
- try:
- rb = open_workbook(bookName)
- foundbill = True
- if foundbill == True:
- self.button = Button(mFrame, text = str(i), bg = 'red', width=3, relief = SUNKEN,
- command=lambda day=i, weekDay = weekday:
- self.addBill(day, weekDay))
- self.button.grid(row = week, column = weekday)
- weekday += 1
- if weekday > 6:
- week += 1
- weekday = 0
- wb = copy(rb)
- s = wb.get_sheet(0)
- for sheet in rb.sheets():
- for columns in range(sheet.ncols):
- for rows in range(sheet.nrows):
- data = sheet.cell(rows,columns).value
- if columns == 1:
- if rows >= 1:
- sheetTotal = float(data)
- totalCost.append(sheetTotal)
- theTotal = sheetTotal + theTotal
- label = Label(self, text="{0:.2f}".format(theTotal))
- label.grid(row=1,column=9)
- foundbill = False
- except:
- foundbill = False
- weekday += 1
- if weekday > 6:
- week += 1
- weekday = 0
- self.findIncome(mFrame, mButton)
- def findIncome(self, mFrame, mButton):
- weekday, numDays = monthrange(self.year, self.month)
- week = 0
- incomeList = []
- totalIncome = 0
- day = 1
- foundinc = True
- foundbill = False
- for i in range(1, numDays + 1):
- bookName = str('{:02d}'.format(day))+str(self.year)+'.xlsx'
- incFileName = str('{:02d}'.format(self.month))+str('{:02d}'.format(i))+str(self.year)+'inc.txt'
- day += 1
- try:
- iFN = open(incFileName, "r")
- foundinc = True
- try:
- rb = open_workbook(bookName)
- foundbill = True
- except:
- foundbill = False
- if foundinc and foundbill == True:
- self.button = Button(mFrame, text = str(i), bg = 'yellow', width=3, relief = SUNKEN,
- command=lambda day=i, weekDay = weekday:
- self.addBill(day, weekDay))
- self.button.grid(row = week, column = weekday)
- fileData = iFN.read()
- incomeList.append(fileData)
- foundinc = False
- foundbill = False
- if foundinc == True:
- self.button = Button(mFrame, text = str(i), bg = 'green', width=3, relief = SUNKEN,
- command=lambda day=i, weekDay = weekday:
- self.addBill(day, weekDay))
- self.button.grid(row = week, column = weekday)
- fileData = iFN.read()
- incomeList.append(fileData)
- weekday += 1
- if weekday > 6:
- week += 1
- weekday = 0
- foundinc = False
- except:
- foundinc = False
- weekday += 1
- if weekday > 6:
- week += 1
- weekday = 0
- for i in incomeList:
- totalIncome = totalIncome + Decimal(i)
- label = Label(self, text="{0:.2f}".format(totalIncome))
- label.grid(row=2,column=9)
- def addBill(self, day, weekDay):
- daysNames = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
- indexes = [0,1,2,3,4,5,6]
- bookName = str('{:02d}'.format(day))+str(self.year)+'.xlsx'
- frameName = str('{:02d}'.format(self.month))+str('{:02d}'.format(day))+str(self.year)
- self.day = day
- class textEntry(Frame):
- def __init__(tEnt, master=None):
- Frame.__init__(tEnt, master)
- tEnt.pSV = 0
- tEnt.grid(row=0, column=0, sticky='news')
- tEnt.day = self.day
- tutOption = Button(self, text="First time? click for Tutorial", command=lambda a=self,b=tEnt:tutorial(a,b))
- tutOption.grid(row = 0, column = 8)
- tEnt.createWidgets()
- def createWidgets(tEnt):
- global c
- Label(tEnt, text="Name of Workbook: ").grid(row=0, column=0)
- Label(tEnt, text="Name of Bill: ").grid(row=2, column=0)
- Label(tEnt, text="Cost of Bill: ").grid(row=3, column=0)
- nameOfBook = StringVar()
- nameOB = Entry(tEnt, textvariable=nameOfBook)
- nameOB.pack()
- nameOB.insert(0,frameName)
- nameOB.grid(row=0, column=1)
- tEnt.billNameSV = StringVar()
- billName = Entry(tEnt, textvariable=tEnt.billNameSV)
- billName.pack()
- billName.insert(0,"NameofBill")
- billName.grid(row=2,column=1)
- tEnt.billCostSV = IntVar()
- billCost = Entry(tEnt, textvariable=tEnt.billCostSV)
- billCost.pack()
- billCost.insert(0,"0.00")
- billCost.grid(row=3,column=1)
- submitButt = Button(tEnt, text="Submit",
- command= lambda billCost=billCost,
- billName=billName,bookName=bookName:
- tEnt.addToWorkBook(billCost,billName,bookName))
- submitButt.grid(row=5,column=3)
- addIncome = Button(tEnt, text="Income",
- command= tEnt.incomeCol)
- addIncome.grid(row=1,column=0)
- salaryPay = Button(tEnt, text="Select for Salary Pay",
- command= tEnt.salaryPay)
- salaryPay.grid(row=1,column=1)
- nOBSearch = Button(tEnt, text="Search",
- command= lambda bookName=bookName:
- tEnt.searchForBook(bookName))
- nOBSearch.grid(row=0,column=3)
- createBook = Button(tEnt, text="Create",
- command= lambda bookName=bookName:
- tEnt.createNewBook(bookName))
- createBook.grid(row=1,column=3)
- purgeBook = Button(tEnt, text="Purge",
- command= lambda bookName=bookName:
- tEnt.purgeBook(bookName))
- purgeBook.grid(row=2,column=3)
- if c == 1:
- c = 0
- billInp.destroy()
- return
- def salaryPay(tEnt):
- salaryFrame = Tk()
- salaryFrame.title("Salary Income")
- entryFrame = LabelFrame(salaryFrame)
- entryFrame.grid(rowspan=7,columnspan=3, sticky=NS)
- ##making labels for income##
- payRate = Label(entryFrame, text="Pay Per Check:")
- payRate.grid(row=1,column=0)
- payEntryVar = DoubleVar()
- payEntry = Entry(entryFrame, textvariable=payEntryVar)
- payEntry.pack()
- payEntry.insert(0,"1250.35")
- payEntry.grid(row=1,column=1)
- payFreq = Label(entryFrame, text="Frequency of Pay(in weeks):")
- payFreq.grid(row=3,column=0)
- payFreqOpt = [0,1,2,4]
- payFreq = IntVar(entryFrame)
- payFreq.set(payFreqOpt[2])
- w = apply(OptionMenu, (entryFrame, payFreq) + tuple(payFreqOpt))
- w.grid(row=3,column=1)
- label = Label(entryFrame, text="Bonus:")
- label.grid(row=4,column=0)
- bonusEntryVar = IntVar()
- bonusEntry = Entry(entryFrame, textvariable=bonusEntryVar)
- bonusEntry.pack()
- bonusEntry.insert(0,"0.00")
- bonusEntry.grid(row=4,column=1)
- submitButt = Button(entryFrame, text="Submit",
- command= lambda a=payEntry,b=payFreq,
- c=bonusEntry:
- tEnt.salaryPayCalculate(a,b,c))
- submitButt.grid(row=6,column=0)
- ridIncome = Button(entryFrame, text="Purge",
- command= tEnt.purgeIncome)
- ridIncome.grid(row=6,column=1)
- warningLabel = Label(salaryFrame, text="DO NOT enter a bonus amount with Frequency greater than 0")
- warningLabel.grid(row=8,column=0, columnspan=3, sticky=NS)
- warningLabel.config(font=('Arial','8','bold','italic'))
- warningLabel = Label(salaryFrame, text="If a bonus is included with a paycheck\nsimply enter the amount you will be paid\nselect 0 for frequency and enter your bonus amount")
- warningLabel.grid(row=9,column=0, columnspan=3, sticky=NS)
- warningLabel.config(font=('Arial','8','bold','italic'))
- salaryFrame.geometry("350x175")
- salaryFrame.lift()
- salaryFrame.update()
- def salaryPayCalculate(tEnt, payEntry, payFreq, bonusEntry):
- self.button = Label(self, text=' ')
- self.button.grid(row=2,column=9)
- payEntry = Decimal(payEntry.get())
- payFreq = int(payFreq.get())
- bonusEntry = Decimal(bonusEntry.get())
- if payFreq == 0:
- toDecide = 1
- multiplier = 1
- else:
- toDecide = 0
- multiplier = payFreq
- monthlyInc = payEntry + bonusEntry
- if toDecide == 1:
- tEnt.createSinglePayDay(monthlyInc)
- if toDecide != 1:
- tEnt.storeIncome(monthlyInc, payFreq)
- def incomeCol(tEnt):
- incFrame = Tk()
- incFrame.title("Income Collection")
- entryFrame = LabelFrame(incFrame)
- entryFrame.grid(rowspan=7,columnspan=3, sticky=NS)
- ##making labels for income##
- payRate = Label(entryFrame, text="Pay Rate:")
- payRate.grid(row=1,column=0)
- payEntryVar = DoubleVar()
- payEntry = Entry(entryFrame, textvariable=payEntryVar)
- payEntry.pack()
- payEntry.insert(0,"10.00")
- payEntry.grid(row=1,column=1)
- payFreq = Label(entryFrame, text="Weeks in Payperiod:")
- payFreq.grid(row=3,column=0)
- payFreqOpt = [0,1,2,4]
- payFreq = IntVar(entryFrame)
- payFreq.set(payFreqOpt[0])
- w = apply(OptionMenu, (entryFrame, payFreq) + tuple(payFreqOpt))
- w.grid(row=3,column=1)
- label = Label(entryFrame, text="Hours Per Week:")
- label.grid(row=2,column=0)
- hoursEntryVar = IntVar()
- hoursEntry = Entry(entryFrame, textvariable=hoursEntryVar)
- hoursEntry.pack()
- hoursEntry.insert(0,"40")
- hoursEntry.grid(row=2,column=1)
- label = Label(entryFrame, text="Tax Factor:")
- label.grid(row=5,column=0)
- taxEntryVar = IntVar()
- taxEntry = Entry(entryFrame, textvariable=taxEntryVar)
- taxEntry.pack()
- taxEntry.insert(0,".25")
- taxEntry.grid(row=5,column=1)
- label = Label(entryFrame, text="Bonus:")
- label.grid(row=7,column=0)
- bonusEntryVar = IntVar()
- bonusEntry = Entry(entryFrame, textvariable=bonusEntryVar)
- bonusEntry.pack()
- bonusEntry.insert(0,"0.00")
- bonusEntry.grid(row=7,column=1)
- submitButt = Button(entryFrame, text="Submit",
- command= lambda a=payEntry,b=payFreq,
- c=hoursEntry,d=incFrame, e=taxEntry, f=bonusEntry:
- tEnt.calculatePay(a,b,c,d,e,f))
- submitButt.grid(row=6,column=0)
- ridIncome = Button(entryFrame, text="Purge",
- command= tEnt.purgeIncome)
- ridIncome.grid(row=6,column=1)
- warningLabel = Label(incFrame, text="DO NOT enter a bonus amount with Frequency greater than 0")
- warningLabel.grid(row=8,column=0, columnspan=3, sticky=NS)
- warningLabel.config(font=('Arial','8','bold','italic'))
- warningLabel = Label(incFrame, text="If a bonus is included with a paycheck\nsimply enter the amount you will be paid\nselect 0 for frequency and enter your bonus amount")
- warningLabel.grid(row=9,column=0, columnspan=3, sticky=NS)
- warningLabel.config(font=('Arial','8','bold','italic'))
- incFrame.geometry("350x250")
- incFrame.lift()
- incFrame.update()
- def purgeIncome(tEnt):
- root = Tk()
- root.title("WARNING MESSAGE")
- label = Label(root, text="WARNING!!! This will purge the current Income File!")
- label.grid(row=0,column=0)
- continueButt = Button(root, text="Continue",
- command= lambda root=root: tEnt.destroyIncome(root))
- continueButt.grid(row=1,column=0)
- cancelButt = Button(root, text="Cancel",
- command= root.destroy)
- cancelButt.grid(row=1,column=1)
- root.lift()
- root.update()
- def destroyIncome(tEnt, root):
- mFrame = self.mFrame
- mButton = self.mButton
- weekday, numDays = monthrange(self.year, self.month)
- fileName = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)+'inc'
- day = 1
- week = 0
- os.remove(fileName+'.txt')
- for i in range(1, numDays + 1):
- if i == tEnt.day:
- self.button = Button(mFrame, text = str(i), width=3,
- command=lambda day=i, weekDay = weekday:
- self.addBill(day, weekDay))
- self.button.grid(row = week, column = weekday)
- weekday += 1
- if weekday > 6:
- week += 1
- weekday = 0
- self.button = Label(self, text=' ')
- self.button.grid(row=2,column=9)
- self.findIncome(mFrame,mButton)
- tEnt.lift()
- root.destroy()
- def calculatePay(tEnt, payEntry, payFreq, hoursEntry, incFrame, taxEntry, bonusEntry):
- self.button = Label(self, text=' ')
- self.button.grid(row=2,column=9)
- payEntry = Decimal(payEntry.get())
- payFreq = int(payFreq.get())
- bonusEntry = Decimal(bonusEntry.get())
- if payFreq == 0:
- toDecide = 1
- multiplier = 1
- else:
- toDecide = 0
- multiplier = payFreq
- hoursEntry = int(hoursEntry.get())
- taxEntry = Decimal(taxEntry.get())
- monthlyIncTax = (payEntry * (hoursEntry * multiplier) * taxEntry)
- monthlyInc = ((payEntry * (hoursEntry * multiplier)) - monthlyIncTax) + bonusEntry
- if toDecide == 1:
- tEnt.createSinglePayDay(monthlyInc)
- if toDecide != 1:
- tEnt.storeIncome(monthlyInc, payFreq)
- def createSinglePayDay(tEnt, monthlyInc):
- mFrame = self.mFrame
- mButton = self.mButton
- currentDate = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)
- excluPayDay = tEnt.day
- excluYear = self.year
- excluMonth = self.month
- startYear = excluYear
- workingDate = str('{:02d}'.format(excluMonth))+str('{:02d}'.format(excluPayDay))+str(excluYear)+'inc'
- incFile = open(workingDate+".txt", 'w')
- incFile.write(str(monthlyInc))
- incFile.close()
- self.findIncome(mFrame,mButton)
- def createPayDays(tEnt, payFreq, monthlyInc):
- currentDate = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)
- excluPayDay = tEnt.day
- excluYear = self.year
- excluMonth = self.month
- startYear = excluYear
- x = 7 * payFreq
- while excluYear == startYear:
- weekday, numDays = monthrange(excluYear, excluMonth)
- excluPayDay += x
- if excluPayDay > numDays:
- excluPayDay -= x
- leftOver = numDays - excluPayDay
- excluPayDay = x - leftOver
- excluMonth += 1
- if excluMonth > 12:
- excluMonth = 1
- excluYear += 1
- return
- if excluYear == self.year:
- workingDate = str('{:02d}'.format(excluMonth))+str('{:02d}'.format(excluPayDay))+str(excluYear)+'inc'
- incFile = open(workingDate+".txt", 'w')
- incFile.write(str(monthlyInc))
- incFile.close()
- else:
- pass
- return
- def storeIncome(tEnt, monthlyInc, payFreq):
- mFrame = self.mFrame
- mButton = self.mButton
- weekday, numDays = monthrange(self.year, self.month)
- day = 1
- week = 0
- fileName = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)+'inc'
- incFile = open(fileName+".txt", "w")
- incFile.write(str(monthlyInc))
- incFile.close()
- tEnt.createPayDays(payFreq, monthlyInc)
- self.findIncome(mFrame,mButton)
- def purgeBook(tEnt, bookName):
- root = Tk()
- root.title("WARNING MESSAGE")
- label = Label(root, text="WARNING!!! This will purge the current workbook!")
- label.grid(row=0,column=0)
- continueButt = Button(root, text="Continue",
- command= lambda root=root: tEnt.destroyBook(root))
- continueButt.grid(row=1,column=0)
- cancelButt = Button(root, text="Cancel",
- command= root.destroy)
- cancelButt.grid(row=1,column=1)
- root.lift()
- root.update()
- def destroyBook(tEnt, root):
- mFrame = self.mFrame
- mButton = self.mButton
- weekday, numDays = monthrange(self.year, self.month)
- fileName = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)+'inc'
- day = 1
- week = 0
- os.remove(bookName)
- for i in range(1, numDays + 1):
- if i == tEnt.day:
- self.button = Button(mFrame, text = str(i), width=3,
- command=lambda day=i, weekDay = weekday:
- self.addBill(day, weekDay))
- self.button.grid(row = week, column = weekday)
- weekday += 1
- if weekday > 6:
- week += 1
- weekday = 0
- tEnt.lift()
- root.destroy()
- self.button = Label(self, text=' ')
- self.button.grid(row=1,column=9)
- self.getAllTotals(mFrame,mButton)
- def addToWorkBook(tEnt, billCost, billName, bookName):
- tEnt.checkForWorkBook(bookName)
- if tEnt.found == True:
- rb = open_workbook(bookName)
- for sheet in rb.sheets():
- for columns in range(sheet.ncols):
- for rows in range(sheet.nrows):
- o = 0
- billName = billName.get()
- billCost = billCost.get()
- wb = copy(rb)
- sheet = wb.get_sheet(0)
- row = rows+1
- col = 0
- sheet.write(row, col, str(billName))
- col += 1
- billCost = float(billCost) * -1
- sheet.write(row, col, float(billCost))
- wb.save(bookName)
- mFrame = self.mFrame
- mButton = self.mButton
- self.getAllTotals(mFrame,mButton)
- else:
- tEnt.createNewBook(bookName)
- tEnt.addToWorkBook(billCost, billName, bookName)
- def createNewBook(tEnt, bookName):
- try:
- tEnt.checkForWorkBook(bookName)
- if tEnt.found == True:
- return
- except:
- tEnt.found = False
- if tEnt.found == False:
- try:
- nameOfBook = bookName
- workbook = xlsxwriter.Workbook(nameOfBook)
- worksheet1 = workbook.add_worksheet()
- worksheet1.write(0,0,"Bill Name")
- worksheet1.write(0,1,"Bill Cost")
- workbook.close()
- except:
- o=0
- pass
- def checkForWorkBook(tEnt, bookName):
- billListName = []
- billListCost = []
- total = 0
- try:
- rb = open_workbook(bookName)
- wb = copy(rb)
- s = wb.get_sheet(0)
- wb.save(bookName)
- for sheet in rb.sheets():
- for columns in range(sheet.ncols):
- for rows in range(sheet.nrows):
- data = sheet.cell(rows,columns).value
- if columns == 0:
- billListName.append(data)
- if columns == 1:
- if rows >= 1:
- billListCost.append(data)
- tEnt.found = True
- return bookName
- except:
- tEnt.found = False
- pass
- def searchForBook(tEnt, bookName):
- billListName = []
- billListCost = []
- total = 0
- try:
- rb = open_workbook(bookName)
- wb = copy(rb)
- s = wb.get_sheet(0)
- wb.save(bookName)
- for sheet in rb.sheets():
- for columns in range(sheet.ncols):
- for rows in range(sheet.nrows):
- data = sheet.cell(rows,columns).value
- if columns == 0:
- billListName.append(data)
- if columns == 1:
- if rows >= 1:
- billListCost.append(data)
- tEnt.found = True
- tEnt.printWindow(bookName, total, columns, rows, data, billListName, billListCost)
- except:
- tEnt.found = False
- pass
- def printWindow(tEnt, bookName, total, columns, rows, data, billListName, billListCost):
- global c
- printScreen = Tk()
- printScreen.title("Message Window")
- printScreen.geometry("300x400")
- printScreen.lift()
- label = Label(printScreen, text = "BookName: " + str(frameName))
- label.grid(row=0, column=0)
- x = 0
- for i in billListName:
- x += 1
- label = Label(printScreen, text = i)
- label.grid(row=x, column=0)
- label = Label(printScreen, text = "Bill Cost")
- label.grid(row=1, column=1)
- x = 1
- for i in billListCost:
- x += 1
- total = total + float(i)
- label = Label(printScreen, text = i)
- label.grid(row=x, column=1)
- label = Label(printScreen, text = "Total Cost")
- label.grid(row=1, column=2)
- label = Label(printScreen, text = "{0:.2f}".format(total))
- label.grid(row=2, column=2)
- if c == 1:
- for i in range(0,6):
- label = Label(printScreen, text = str(i))
- label.grid(row=0,column=4)
- printScreen.update()
- time.sleep(1)
- c += 1
- printScreen.destroy()
- try:
- billInp = Tk()
- billInp.title(frameName)
- obj = textEntry(billInp)
- billInp.lift()
- billInp.update()
- except:
- global c
- c = 0
- return
- mainWindow = Tk()
- mainWindow.lift()
- mainWindow.geometry("450x300")
- mainWindow.title("Bill Keeper")
- obj = Application(mainWindow)
- mainWindow.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement