Advertisement
Guest User

mobileAccount.py

a guest
Apr 8th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 63.98 KB | None | 0 0
  1. from decimal import *
  2. from calendar import *
  3. import datetime
  4. import time
  5. import os
  6. ##import pyttsx
  7. ##import pyautogui
  8. import sys
  9. import xlwt
  10. from xlutils.copy import copy
  11. from xlwt import easyxf
  12. from xlrd import open_workbook
  13. import xlsxwriter
  14. #import Tkinter as tk
  15. #try:
  16.    # from tkinter import *   # Python 3.x
  17. #except:
  18.  #   from Tkinter import *   # Python 2.x
  19.    
  20. ##def locate(imageName):
  21. ##
  22. ##    try:
  23. ##        buttonPos = pyautogui.locateOnScreen(imageName,5)
  24. ##        if buttonPos != None:
  25. ##            x,y,a,b = buttonPos
  26. ##            pyautogui.moveTo(x,y,3)
  27. ##            pyautogui.moveRel(5,5,1)
  28. ##    except:
  29. ##        pass
  30. ##        
  31. ##def tutorial(self, tEnt):
  32. ##
  33. ##    tutWindow = Tk()
  34. ##    tutWindow.title("Accountant Guide")
  35. ##    tutWindow.wm_attributes("-topmost",1)
  36. ##    tutWindowFrame = Frame(tutWindow, width=300,height=5)
  37. ##    tutWindowFrame.grid()
  38. ##    tutWindowFrame.pack()
  39. ##    
  40. ##    txtFrame = Frame(tutWindow, width=300, height=600)
  41. ##    txtFrame.pack(fill="both", expand=True)
  42. ##    txtFrame.grid_propagate(False)
  43. ##    txtFrame.grid_rowconfigure(0, weight=1)
  44. ##    txtFrame.grid_columnconfigure(0, weight=1)
  45. ##
  46. ##    text = Text(txtFrame, borderwidth=3, relief="sunken")
  47. ##    text.config(font=("consola", 12),undo=True, wrap='word')
  48. ##    text.grid(row=1,column=0,sticky="nsew",padx=2,pady=2)
  49. ##    
  50. ##    scrollb = Scrollbar(txtFrame, command=text.yview)
  51. ##    scrollb.grid(row=1,column=1,sticky='nsew')
  52. ##    text['yscrollcommand'] = scrollb.set
  53. ##    
  54. ##    #Assigning position of window to bottom rightside of screen
  55. ##    windowWidth = 400
  56. ##    windowHeight = 600
  57. ##    positionRight = int(tutWindow.winfo_screenwidth()-windowWidth)
  58. ##    positionDown = int(tutWindow.winfo_screenheight()-windowHeight)
  59. ##    tutWindow.geometry("400x600")
  60. ##    tutWindow.geometry("+{}+{}".format(positionRight, positionDown))
  61. ##
  62. ##    startButton = Button(tutWindowFrame, text="Start Tutorial")
  63. ##    startButton['command'] = lambda a=text, b=tutWindow, c=self, d=tEnt: warningFirst(a,b,c,d)
  64. ##    startButton.grid(row=0,column=0)
  65. ##
  66. ##    tutWindow.update_idletasks()
  67. ##
  68. ##def warningFirst(text, tutWindow, self, tEnt):
  69. ##    
  70. ##    noTouch = Tk()
  71. ##    noTouchFrame = Frame(noTouch, width=300,height=100)
  72. ##    textToTouch = Label(noTouch, text = "DO NOT TOUCH THE MOUSE DURING THIS TUTORIAL")
  73. ##    textToTouch.grid(row=0,column=0)
  74. ##
  75. ##    textToTouch = Label(noTouch, text = "Sit back and enjoy the Show!")
  76. ##    textToTouch.grid(row=1,column=0)
  77. ##
  78. ##    continueBut = Button(noTouch, text="continue")
  79. ##    continueBut['command'] = lambda a=text,b=tutWindow,c=noTouch,d=self,e=tEnt:startSeq(a,b,c,d,e)
  80. ##    continueBut.grid(row=2,column=0)
  81. ##    
  82. ##def startSeq(text, tutWindow, noTouch, self, tEnt):
  83. ##
  84. ##    
  85. ##    noTouch.destroy()
  86. ##    
  87. ##    textAdd = "Welcome to the interactive tutorial for my accountant"
  88. ##    addText(textAdd, text, tutWindow)
  89. ##    
  90. ##    
  91. ##    textAdd = "This guide will walk you through how to set up your accountant program"  
  92. ##    addText(textAdd, text, tutWindow)
  93. ##  
  94. ##    imageName = "screenshots/billCalMainWin.PNG"
  95. ##    locate(imageName)
  96. ##    
  97. ##    textAdd = "In this window you can cycle through the months"  
  98. ##    addText(textAdd, text, tutWindow)
  99. ##      
  100. ##    textAdd = "Add bills and income and much more"  
  101. ##    addText(textAdd, text, tutWindow)
  102. ##    
  103. ##    
  104. ##    imageName = 'screenshots/monthLeft.PNG'
  105. ##    locate(imageName)  
  106. ##    textAdd = "This button will take you through previous months"
  107. ##    addText(textAdd, text, tutWindow)
  108. ##    self.prevMonth()
  109. ##    tutWindow.update()
  110. ##    
  111. ##    imageName = 'screenshots/monthRight.PNG'
  112. ##    locate(imageName)  
  113. ##    textAdd = "This button will take you through following months"
  114. ##    addText(textAdd, text, tutWindow)
  115. ##    self.nextMonth()
  116. ##    tutWindow.update()
  117. ##    
  118. ##    imageName = 'screenshots/monthButton5.PNG'
  119. ##    locate(imageName)  
  120. ##    textAdd = "Clicking a day of the month will allow you to add bills or income"
  121. ##    addText(textAdd, text, tutWindow)
  122. ##      
  123. ##    textAdd = "Lets add some bills"
  124. ##    addText(textAdd, text, tutWindow)
  125. ##    self.addBill(day=4,weekDay=1)
  126. ##    tutWindow.update()
  127. ##
  128. ##    imageName = 'screenshots/nameOfWorkBook.png'
  129. ##    locate(imageName)  
  130. ##    textAdd = "Here you will find the name of the file holding your bill"
  131. ##    addText(textAdd, text, tutWindow)
  132. ##      
  133. ##    textAdd = "!!DO NOT EVER CHANGE THIS!!"
  134. ##    addText(textAdd, text, tutWindow)
  135. ##    
  136. ##
  137. ##    imageName = 'screenshots/billName.png'
  138. ##    locate(imageName)
  139. ##    pyautogui.moveRel(100,0,2)
  140. ##    textAdd = "Type the name of your bill here"
  141. ##    addText(textAdd, text, tutWindow)
  142. ##    
  143. ##    pyautogui.doubleClick()
  144. ##    tutWindow.update()
  145. ##    pyautogui.typewrite(["R","e","n","t"], interval=1)
  146. ##    tutWindow.update()
  147. ##
  148. ##    imageName = 'screenshots/billCost.png'
  149. ##    locate(imageName)
  150. ##    pyautogui.moveRel(100,0,2)
  151. ##    textAdd = "Type the cost of your bill here"
  152. ##    addText(textAdd, text, tutWindow)
  153. ##    
  154. ##    pyautogui.doubleClick()
  155. ##    tutWindow.update()
  156. ##    pyautogui.typewrite(["8","0","0"], interval=1)
  157. ##    tutWindow.update()
  158. ##
  159. ##    imageName = 'screenshots/billSubmit.png'
  160. ##    locate(imageName)
  161. ##    textAdd = "After entering the info you will click here to create the bill"
  162. ##    addText(textAdd, text, tutWindow)
  163. ##    click()
  164. ##    tutWindow.update()
  165. ##
  166. ##    imageName = 'screenshots/billName.png'
  167. ##    locate(imageName)
  168. ##    pyautogui.moveRel(100,0,2)  
  169. ##    textAdd = "Type the name of your bill here"
  170. ##    addText(textAdd, text, tutWindow)
  171. ##    
  172. ##    pyautogui.doubleClick()
  173. ##    tutWindow.update()
  174. ##    pyautogui.typewrite(["p","o","w","e","r","b","i","l","l"], interval=1)
  175. ##    tutWindow.update()
  176. ##
  177. ##    imageName = 'screenshots/billCost.png'
  178. ##    locate(imageName)
  179. ##    pyautogui.moveRel(100,0,2)  
  180. ##    textAdd = "Type the cost of your bill here"
  181. ##    addText(textAdd, text, tutWindow)
  182. ##    
  183. ##    pyautogui.doubleClick()
  184. ##    tutWindow.update()
  185. ##    pyautogui.typewrite(["6","5"], interval=1)
  186. ##    tutWindow.update()
  187. ##    
  188. ##    imageName = 'screenshots/billSubmit.png'
  189. ##    locate(imageName)
  190. ##    
  191. ##    textAdd = "After entering the info you will click here to create the bill"
  192. ##    addText(textAdd, text, tutWindow)    
  193. ##    click()
  194. ##    tutWindow.update()
  195. ##
  196. ##    textAdd = "To see all bills for the current day you click search"
  197. ##    addText(textAdd, text, tutWindow)
  198. ##    imageName = 'screenshots/billSearch.png'
  199. ##    locate(imageName)
  200. ##    global c
  201. ##    c = 1
  202. ##    click()
  203. ##    tutWindow.update()
  204. ##    
  205. ##    imageName = 'screenshots/billPurge.png'
  206. ##    locate(imageName)
  207. ##    
  208. ##    textAdd = "If you need to get rid of a bill simply click Purge"
  209. ##    addText(textAdd, text, tutWindow)
  210. ##    tutWindow.update()
  211. ##    
  212. ##    textAdd = "But know that this will delete ALL bills on that given day"
  213. ##    addText(textAdd, text, tutWindow)
  214. ##    tutWindow.update()
  215. ##
  216. ##    imageName = 'screenshots/incomeButton.png'
  217. ##    locate(imageName)
  218. ##    
  219. ##    textAdd = "Clicking income will allow you to add an income"
  220. ##    addText(textAdd, text, tutWindow)
  221. ##    
  222. ##    textAdd = "Lets add income"    
  223. ##    addText(textAdd, text, tutWindow)
  224. ##    
  225. ##    tEnt.incomeCol()
  226. ##    tutWindow.update()
  227. ##
  228. ##    imageName = 'screenshots/incomePayRate.png'
  229. ##    locate(imageName)
  230. ##    textAdd = "Here you enter your Hourly Rate"
  231. ##    addText(textAdd, text, tutWindow)
  232. ##    
  233. ##    pyautogui.moveRel(100,5,2)
  234. ##    pyautogui.doubleClick()
  235. ##    pyautogui.typewrite('12.50', interval=1)
  236. ##    tutWindow.update()
  237. ##
  238. ##    imageName = 'screenshots/incomeHours.png'
  239. ##    locate(imageName)
  240. ##    textAdd = "Here you enter how many hours you work per week"  
  241. ##    addText(textAdd, text, tutWindow)
  242. ##    
  243. ##    pyautogui.moveRel(100,0,2)
  244. ##    pyautogui.doubleClick()
  245. ##    pyautogui.typewrite('35', interval=1)
  246. ##    tutWindow.update()
  247. ##
  248. ##    imageName = 'screenshots/incomeWeeks.png'
  249. ##    locate(imageName)
  250. ##    
  251. ##    textAdd = "Here you will select how many weeks are in a pay period"
  252. ##    addText(textAdd, text, tutWindow)
  253. ##  
  254. ##    textAdd = "If you select 0, you will add pay for that single day"  
  255. ##    addText(textAdd, text, tutWindow)
  256. ##    
  257. ##    textAdd = "Also note that you cannot create two paychecks on a single day"
  258. ##    addText(textAdd, text, tutWindow)
  259. ##      
  260. ##    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"  
  261. ##    addText(textAdd, text, tutWindow)
  262. ##    
  263. ##    imageName = 'screenshots/incomeWeeks2.png'
  264. ##    locate(imageName)
  265. ##    
  266. ##    textAdd = "Selecting 2 for weeks in payperiod means you are paid biweekly"  
  267. ##    addText(textAdd, text, tutWindow)
  268. ##
  269. ##    imageName = 'screenshots/incomeSubmit.png'
  270. ##    locate(imageName)
  271. ##    click()
  272. ##    
  273. ##    textAdd = "Click submit when finished"
  274. ##    addText(textAdd, text, tutWindow)
  275. ##  
  276. ##    textAdd = "Congradulations!! You have successfully gone through the entire tutorial!!"  
  277. ##    addText(textAdd, text, tutWindow)
  278. ##    
  279. ##    textAdd = "There is more to explore, add some more bills, but dont forget to purge the already created bills and income before continuing"
  280. ##    addText(textAdd, text, tutWindow)
  281. ##    
  282. ##    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!"
  283. ##    addText(textAdd, text, tutWindow)
  284. ##    tutWindow.destroy()
  285. ##    
  286. ##def click():
  287. ##    
  288. ##    pyautogui.click()
  289. ##    
  290. ##def addText(textAdd, text, tutWindow):
  291. ####    engine = pyttsx.init()
  292. ####    engine.say(str(textAdd))
  293. ##    text.insert(1.0,"\n"+textAdd+"\n")
  294. ####    engine.runAndWait()
  295. ##    tutWindow.update()
  296.  
  297. ##class log_in(Frame):
  298. ##
  299. ##    def __init__(logIn, master=None):
  300. ##        
  301. ##        Frame.__init__(logIn, master)
  302. ##        logIn.grid(row=0, column=0, sticky='news')
  303. ##        label = Label(logIn, text = "Username: ")
  304. ##        label.grid(row=0,column=0)
  305. ##        user_name = StringVar()
  306. ##        userName = Entry(logIn, textvariable = user_name)
  307. ##        userName.pack()
  308. ##        userName.insert(0,"Enter User Name")
  309. ##        userName.grid(row=0,column=1)
  310. ##
  311. ##        label = Label(logIn, text = "Password: ")
  312. ##        label.grid(row=1,column=0)
  313. ##        pass_word = StringVar()
  314. ##        passWord = Entry(logIn, textvariable = pass_word)
  315. ##        passWord.pack()
  316. ##        passWord.insert(0,"Enter Password")
  317. ##        passWord.grid(row=1,column=1)
  318. ##
  319. ##        logInButton = Button(logIn, text= "Log In")
  320. ##        logInButton['command'] = lambda a=user_name, b=pass_word: logIn.chckCred(a,b)
  321. ##        logInButton.grid(row=2,column=1)
  322. ##
  323. ##        registerButton = Button(logIn, text= "Register")
  324. ##        registerButton['command'] = lambda a=user_name, b=pass_word: logIn.registerCred(a,b)
  325. ##        registerButton.grid(row=2,column=2)
  326. ##
  327. ##    def chckCred(logIn, user_name, pass_word):
  328. ##
  329. ##        folderName = '/'+str(user_name)
  330. ##        os.path.exists(folderName)
  331. ##        if os.path.exists(folderName) == False:
  332. ##            os.makedirs(os.path.dirname(folderName))
  333. ##            
  334. ##        else:
  335. ##            print "try logging in"
  336. ##      
  337. ##    def registerCred(log_in, user_name, pass_word):
  338. ##
  339. ##        folderName = '/'+str(user_name)
  340. ##        os.path.exists(folderName)
  341. ##        if os.path.exists(folderName) == False:
  342. ##            os.makedirs(os.path.dirname(folderName))
  343. ##            
  344. ##        else:
  345. ##            print "try logging in"
  346. ##            
  347. ##logWindow = Tk()
  348. ##logWindow.lift()
  349. ##logWindow.geometry("300x150")
  350. ##logWindow.title("Accountant Log In")
  351. ##obj = log_in(logWindow)
  352. ##logWindow.mainloop()        
  353.    
  354. class Application(Frame):
  355.  
  356.     def __init__(self, master=None):
  357.      
  358.         global c
  359.         c = 1
  360.         Frame.__init__(self, master)
  361.         self.grid(row=0, column=0, sticky='news')
  362.         DateNow = datetime.datetime.now()
  363.         self.month = int(DateNow.month)
  364.         self.year = int(DateNow.year)
  365.         self.day = int(DateNow.day)
  366.         self.createDaysOfWeekLabels()
  367.         self.dayNum = []
  368.         # Create frames and button controls for previous, current and next month.
  369.         self.frameList = []    # List that contains the frame objects.
  370.         self.buttonList = []   # List that contains the button objects.
  371.         self.toPayFrameList = []
  372.         self.split()
  373.        
  374.     def split(self):
  375.        
  376.         global c
  377.         month_name = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  378.         leftArrow = Button(self, text="<", command=self.prevMonth)
  379.         leftArrow.grid(row = 1, column = 0)
  380.         rightArrow = Button(self, text=">", command=self.nextMonth)
  381.         rightArrow.grid(row = 1, column = 2)
  382.         mFrame = Frame(self)
  383.         self.createMonth(mFrame)
  384.         self.frameList.append(mFrame)
  385.         mButton = Button(self, text=month_name[self.month-1])
  386.         mButton['command'] = lambda f=mFrame, b=mButton: self.showMonth(f, b)
  387.         mButton.grid(row=1, column=1)
  388.         tButton = Button(self, text="Month Bills:", relief=RIDGE)
  389.         tButton['command'] = lambda f=mFrame, b=mButton:self.getAllTotals(f,b)
  390.         tButton.grid(row=1, column=8)
  391.         iButton = Button(self, text="Month Inc:", relief=RIDGE)
  392.         iButton['command'] = lambda f=mFrame, b=mButton:self.findIncome(f,b)
  393.         iButton.grid(row=2, column=8)
  394.         iButton = Button(self, text="When to pay bills?", relief=RIDGE)
  395.         iButton['command'] = self.whenToPay
  396.         iButton.grid(row=3, column=8)
  397.         # Grid each frame
  398.         mFrame.grid(row=3, column=0, columnspan=7, sticky='news')
  399.         mButton['relief'] = 'flat'        
  400.         self.buttonList.append(mButton)
  401.         # Create year widget at top right of top frame
  402.         label = Label(self, text=self.year)#displaying year
  403.         label.grid(row=0, column=1)
  404.         label = Label(self,bg = 'yellow', text='income&bill')
  405.         label.grid(row=8, column=8)
  406.         label = Label(self,bg = 'red', text='bill')
  407.         label.grid(row=9, column=8)
  408.         label = Label(self,bg = 'green', text='income')
  409.         label.grid(row=10, column=8)
  410.         self.mFrame = mFrame
  411.         self.mButton = mButton
  412.         if c == 1:
  413.             self.addBill(day=5, weekDay=1)
  414.            
  415.         self.getAllTotals(mFrame,mButton)
  416.         self.findIncome(mFrame,mButton)
  417.  
  418.     def getMonth(self, foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempMonth, tempDay, tempYear):
  419.         x=0
  420.         iterMonth = self.storeCurrMonth
  421.  
  422.         for i in month_name:
  423.             if i == tempMonth.get():
  424.                 month = x
  425.  
  426.                 toPay.destroy()
  427.                 toPay = Tk()
  428.                 self.findPayDays(foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempDay, tempYear, tempMonth)
  429.                
  430.             else:    
  431.                 self.storeCurrMonth = iterMonth
  432.  
  433.             x += 1
  434.  
  435.     def getDay(self, foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempMonth, tempDay, tempYear):
  436.         x=0
  437.         iterDay = self.storeCurrDay
  438.         weekday, numDays = monthrange(year, month)
  439.         foundPrev = False
  440.         for i in range(0,numDays+1):
  441.             if i == tempDay.get():
  442.                 day = x
  443.                 toPay.destroy()
  444.                 toPay = Tk()
  445.                 self.findPayDays(foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempDay, tempYear, tempMonth)
  446.                
  447.             else:
  448.                self.storeCurrDay = iterDay
  449.  
  450.             x += 1
  451.  
  452.     def whenToPay(self):
  453.        
  454.         toPay = Tk()
  455.         month_name = ['January',
  456.                       'February',
  457.                       'March',
  458.                       'April',
  459.                       'May',
  460.                       'June',
  461.                       'July',
  462.                       'August',
  463.                       'September',
  464.                       'October',
  465.                       'November',
  466.                       'December']
  467.         month_number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
  468.         currDate = datetime.datetime.now()
  469.         day = int(currDate.day)
  470.         month = int(currDate.month)
  471.         year = int(currDate.year)
  472.         self.storeCurrMonth = month
  473.         self.storeCurrDay = day
  474.         self.storeCurrYear = year
  475.         weekday, numDays = monthrange(year, month)
  476.         tempMonth = month
  477.         tempDay = day
  478.         tempYear = year
  479.         tempStrMonth = str(month_name[month-1])
  480.         foundPrev = False
  481.         foundNextPrev = False
  482.         foundNext = False
  483.         foundNextNext = False
  484.  
  485.         self.findPayDays(foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempDay, tempYear, tempMonth)
  486.  
  487.     def findPayDays(self, foundPrev, day, month, currDate, toPay, foundNextPrev, foundNext, foundNextNext, year, tempDay, tempYear, tempMonth):
  488.  
  489.         daysInPeriod = 0
  490.         theWorkingMonth = month
  491.         theWorkingDay = day
  492.         weekday, numDays = monthrange(year, month)
  493.         month_name = ['January',
  494.                       'February',
  495.                       'March',
  496.                       'April',
  497.                       'May',
  498.                       'June',
  499.                       'July',
  500.                       'August',
  501.                       'September',
  502.                       'October',
  503.                       'November',
  504.                       'December']
  505.        
  506.         label = Label(toPay, text=year)#displaying year
  507.         label.grid(row=1, column=4)
  508.  
  509.         tempDay = IntVar(toPay)
  510.         tempDay.set(day)
  511.         x = 0
  512.         #DAY    
  513.         op = tk.OptionMenu(toPay, tempDay, *range(1,numDays+1),command=lambda
  514.                            a=foundPrev, b=day,
  515.                            c=month, d=currDate,
  516.                            e=toPay, f=foundNextPrev,
  517.                            g=foundNext, h=foundNextNext,
  518.                            i=year,j=tempMonth,
  519.                            k=tempDay, l=tempYear:self.getDay(a,b,c,d,e,f,g,h,i,j,k,l))
  520.         op.grid(row=1, column=3)
  521.        
  522.        
  523.         tempMonth = StringVar(toPay)
  524.         tempMonth.set(month_name[month-1])
  525.         x = 0
  526.         #MONTH    
  527.         op = tk.OptionMenu(toPay, tempMonth, *month_name,command=lambda
  528.                            a=foundPrev, b=day,
  529.                            c=month, d=currDate,
  530.                            e=toPay, f=foundNextPrev,
  531.                            g=foundNext, h=foundNextNext,
  532.                            i=year,j=tempMonth,
  533.                            k=tempDay, l=tempYear:self.getMonth(a,b,c,d,e,f,g,h,i,j,k,l))
  534.         op.grid(row=1, column=2)
  535.        
  536.         label = Label(toPay, text="Today is: ")#displaying month
  537.         label.grid(row=1, column=1)
  538.  
  539.         label = Label(toPay, text="Previous Check:")
  540.         label.grid(row=50, column=0)
  541.  
  542.         label = Label(toPay, text="Most Recent Check:")
  543.         label.grid(row=4, column=0)
  544.  
  545.         label = Label(toPay, text="Upcoming Check:")
  546.         label.grid(row=4, column=5)
  547.  
  548.         label = Label(toPay, text="Following Check:")
  549.         label.grid(row=50, column=5)
  550.        
  551.         while foundPrev != True:  ##Listed as MOST RECENT CHECK
  552.            
  553.             try:
  554.                 day -= 1
  555.                 incFileName = str('{:02d}'.format(month))+str('{:02d}'.format(day))+str(year)+'inc.txt'
  556.                 iFN = open(incFileName, 'r')
  557.                 prevPay = str('{:02d}'.format(month))+'/'+str('{:02d}'.format(day))+'/'+str(year)
  558.                 pPCalc = str('{:02d}'.format(day))
  559.                 label = Label(toPay, text=prevPay)
  560.                 label.grid(row=4, column=1)
  561.                 fileData = iFN.read()
  562.                 foundPrev = True
  563.                 r = 4
  564.                 c = 1
  565.                 self.getTotalPay(incFileName, toPay, r, c)
  566.                    
  567.             except:
  568.                
  569.                 if day < 1:
  570.                     month = month - 1
  571.                     day = 31
  572.                     if month == theWorkingMonth - 2:
  573.                         pPCalc = str('{:02d}'.format(day))
  574.                         prevPay = "Cannot locate suitable paycheck"
  575.                         label = Label(toPay, text=prevPay)
  576.                         label.grid(row=4, column=1)
  577.                         foundPrev = True
  578.                        
  579.         while foundNextPrev != True:  ##Listed as PREVIOUS CHECK
  580.             try:
  581.                 day -= 1
  582.                 incFileName = str('{:02d}'.format(month))+str('{:02d}'.format(day))+str(year)+'inc.txt'
  583.                 iFN = open(incFileName, 'r')
  584.                 nextPrevPay = str('{:02d}'.format(month))+'/'+str('{:02d}'.format(day))+'/'+str(year)
  585.                 nPPCalc = str('{:02d}'.format(day))
  586.                 label = Label(toPay, text=nextPrevPay)
  587.                 label.grid(row=50, column=1)
  588.                 fileData = iFN.read()
  589.                 foundNextPrev = True
  590.                 r = 50
  591.                 c = 1
  592.                 self.getTotalPay(incFileName, toPay, r, c)
  593.                    
  594.             except:
  595.                 daysInPeriod += 1
  596.                 if day < 1:
  597.                     month = month - 1
  598.                     day = 31
  599.                     if month == theWorkingMonth - 3:
  600.                         nPPCalc = str('{:02d}'.format(day))
  601.                         nextPrevPay = "None found"
  602.                         label = Label(toPay, text=nextPrevPay)
  603.                         label.grid(row=50, column=1)
  604.                         foundNextPrev = True
  605.        
  606.         day = int(theWorkingDay)#reseting day to current day
  607.         month = int(theWorkingMonth)
  608.         year = int(currDate.year)
  609.    
  610.         while foundNext != True:  ##Listed as UPCOMING CHECK
  611.             try:
  612.                 incFileName = str('{:02d}'.format(month))+str('{:02d}'.format(day))+str(year)+'inc.txt'
  613.                 iFN = open(incFileName, 'r')
  614.                 nextPay = str('{:02d}'.format(month))+'/'+str('{:02d}'.format(day))+'/'+str(year)
  615.                 nPCalc = str('{:02d}'.format(day))
  616.                 label = Label(toPay, text=nextPay)
  617.                 label.grid(row=4, column=6)
  618.                 fileData = iFN.read()
  619.                 day += 1
  620.                 foundNext = True
  621.                 r = 4
  622.                 c = 6
  623.                 self.getTotalPay(incFileName, toPay, r, c)
  624.                
  625.             except:
  626.                 day += 1
  627.                 if day > 31:
  628.                     month = month + 1
  629.                     day = 1
  630.                     if month == theWorkingMonth + 2:
  631.                         nPCalc = str('{:02d}'.format(day))
  632.                         nextPay = "Cannot locate suitable paycheck"
  633.                         label = Label(toPay, text=nextPay)
  634.                         label.grid(row=4, column=6)
  635.                         foundNext = True
  636.    
  637.         while foundNextNext != True: ##Listed as FOLLOWING CHECK
  638.             try:
  639.                 incFileName = str('{:02d}'.format(month))+str('{:02d}'.format(day))+str(year)+'inc.txt'
  640.                 iFN = open(incFileName, 'r')
  641.                 nextNextPay = str('{:02d}'.format(month))+'/'+str('{:02d}'.format(day))+'/'+str(year)
  642.                 nNPCalc = str('{:02d}'.format(day))
  643.                 label = Label(toPay, text=nextNextPay)
  644.                 label.grid(row=50, column=6)
  645.                 fileData = iFN.read()
  646.                 foundNextNext = True
  647.                 r = 50
  648.                 c = 6
  649.                 self.getTotalPay(incFileName, toPay, r, c)
  650.                
  651.             except:
  652.                 day += 1
  653.                 if day > 31:
  654.                     month = month + 1
  655.                     day = 1
  656.                     if month == theWorkingMonth + 3:
  657.                         nNPCalc = str('{:02d}'.format(day))
  658.                         nextNextPay = "Cannot locate suitable paycheck"
  659.                         label = Label(toPay, text=nextNextPay)
  660.                         label.grid(row=50, column=6)
  661.                         foundNextNext = True
  662.        
  663.         self.addToWhen(pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod)
  664.         self.payNow(pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod)
  665.         self.paidPreviously(pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod)
  666.         self.upComing(pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod)
  667.    
  668.         toPay.title("When to Pay")
  669.         toPay.geometry("700x500")
  670.         toPay.lift()
  671.         toPay.update()
  672.  
  673.     def getTotalPay(self, incFileName, toPay, r, c):
  674.        
  675.         incFile = open(incFileName, 'r')
  676.         data = incFile.read()
  677.         data = float(data)
  678.         toPay.income = data
  679.         label = Label(toPay, text="${0:.2f}".format(data))
  680.         label.grid(row=r, column=c+1)
  681.         self.payData = data
  682.         incFile.close()
  683.  
  684.     def upComing(self, pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod): #FOLLOWING
  685.  
  686.         currDate = datetime.datetime.now()
  687.         day = int(currDate.day)
  688.         month = int(currDate.month)
  689.         year = int(currDate.year)
  690.         weekday, numDays = monthrange(year, month)
  691.         nNPCalc = int(nNPCalc)
  692.         daysInPeriod = int(daysInPeriod)
  693.         total = 0
  694.         billListName = []
  695.         billListCost = []
  696.         billListDate = []
  697.         passRow = 51
  698.         passCol = 5
  699.         for i in range(nNPCalc, nNPCalc + daysInPeriod):
  700.             if i > numDays:
  701.                 i = i - numDays  
  702.             try:
  703.                 bookName = str('{:02d}'.format(i))+str(self.year)+'.xlsx'
  704.                 dateDiplay = str('{:02d}'.format(i))+"/"+str(self.year)
  705.                 rb = open_workbook(bookName)
  706.                 wb = copy(rb)
  707.                 s = wb.get_sheet(0)
  708.                 if rb != None:
  709.                     for sheet in rb.sheets():
  710.                         for columns in range(sheet.ncols):
  711.                             for rows in range(sheet.nrows):
  712.                                 data = sheet.cell(rows,columns).value
  713.                                 if columns == 0:
  714.                                     if rows >= 1:
  715.                                         billListDate.append(dateDiplay)
  716.                                         billListName.append(data)
  717.                                 if columns == 1:
  718.                                     if rows >= 1:
  719.                                         billListCost.append(data)
  720.  
  721.             except:
  722.                 None
  723.  
  724.         for i in billListCost:
  725.             total += float(i)
  726.  
  727.         self.toWindow(total, billListName, billListCost, toPay, passRow, passCol, billListDate)
  728.        
  729.     def paidPreviously(self, pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod):#PREVIOUS PAY
  730.  
  731.         daysInPeriod = int(daysInPeriod) - 1
  732.         currDate = datetime.datetime.now()
  733.         day = int(currDate.day)
  734.         month = int(currDate.month)
  735.         year = int(currDate.year)
  736.         weekday, numDays = monthrange(year, month)
  737.         nPPCalc = int(nPPCalc)
  738.         pPCalc = int(pPCalc)
  739.         if pPCalc < nPPCalc:
  740.             pPCalc += nPPCalc
  741.         if pPCalc - nPPCalc < 7:
  742.             pPCalc += daysInPeriod
  743.         total = 0
  744.         billListName = []
  745.         billListCost = []
  746.         billListDate = []
  747.         passRow = 51
  748.         passCol = 0
  749.         for i in range(nPPCalc, pPCalc):
  750.             if i > numDays:
  751.                 i = i - numDays
  752.             try:
  753.                 bookName = str('{:02d}'.format(i))+str(self.year)+'.xlsx'
  754.                 dateDiplay = str('{:02d}'.format(i))+"/"+str(self.year)
  755.                 rb = open_workbook(bookName)
  756.                 wb = copy(rb)
  757.                 s = wb.get_sheet(0)
  758.                 if rb != None:
  759.                     for sheet in rb.sheets():
  760.                         for columns in range(sheet.ncols):
  761.                             for rows in range(sheet.nrows):
  762.                                 data = sheet.cell(rows,columns).value
  763.                                 if columns == 0:
  764.                                     if rows >= 1:
  765.                                         billListDate.append(dateDiplay)
  766.                                         billListName.append(data)
  767.                                 if columns == 1:
  768.                                     if rows >= 1:
  769.                                         billListCost.append(data)
  770.                    
  771.             except:
  772.                 None
  773.         for i in billListCost:
  774.             total += float(i)
  775.  
  776.         self.toWindow(total, billListName, billListCost, toPay, passRow, passCol, billListDate)
  777.        
  778.     def payNow(self, pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod):#UPCOMING
  779.  
  780.         daysInPeriod = int(daysInPeriod) - 1
  781.         currDate = datetime.datetime.now()
  782.         day = int(currDate.day)
  783.         month = int(currDate.month)
  784.         year = int(currDate.year)
  785.         weekday, numDays = monthrange(year, month)
  786.         nPCalc = int(nPCalc)
  787.         nNPCalc = int(nNPCalc)
  788.         if nNPCalc < nPCalc:
  789.             nNPCalc += nPCalc
  790.         if nNPCalc - nPCalc < 7:
  791.             nNPCalc += daysInPeriod
  792.         total = 0
  793.         billListName = []
  794.         billListCost = []
  795.         billListDate = []
  796.         passRow = 5
  797.         passCol = 5
  798.         for i in range(nPCalc, nNPCalc):
  799.             if i > numDays:
  800.                 i = i - numDays
  801.             try:
  802.                 bookName = str('{:02d}'.format(i))+str(self.year)+'.xlsx'
  803.                 dateDiplay = str('{:02d}'.format(i))+"/"+str(self.year)
  804.                 rb = open_workbook(bookName)
  805.                 wb = copy(rb)
  806.                 s = wb.get_sheet(0)
  807.                 if rb != None:
  808.                     for sheet in rb.sheets():
  809.                         for columns in range(sheet.ncols):
  810.                             for rows in range(sheet.nrows):
  811.                                 data = sheet.cell(rows,columns).value
  812.                                 if columns == 0:
  813.                                     if rows >= 1:
  814.                                         billListDate.append(dateDiplay)
  815.                                         billListName.append(data)
  816.                                 if columns == 1:
  817.                                     if rows >= 1:
  818.                                         billListCost.append(data)
  819.                      
  820.             except:
  821.                 None
  822.                
  823.         for i in billListCost:
  824.             total += float(i)
  825.  
  826.         self.toWindow(total, billListName, billListCost, toPay, passRow, passCol, billListDate)
  827.                
  828.     def addToWhen(self, pPCalc, nPCalc, nNPCalc, nPPCalc, toPay, daysInPeriod):#MOST RECENT
  829.  
  830.         daysInPeriod = int(daysInPeriod) - 1
  831.         currDate = datetime.datetime.now()
  832.         day = int(currDate.day)
  833.         month = int(currDate.month)
  834.         year = int(currDate.year)
  835.         weekday, numDays = monthrange(year, month)
  836.         pPCalc = int(pPCalc)
  837.         nPCalc = int(nPCalc)
  838.         if nPCalc < pPCalc:
  839.             nPCalc += pPCalc
  840.         if nPCalc - pPCalc < 7:
  841.             nPCalc += daysInPeriod
  842.         total = 0
  843.         billListName = []
  844.         billListCost = []
  845.         billListDate = []
  846.         passRow = 5
  847.         passCol = 0
  848.         for i in range(pPCalc, nPCalc):
  849.             if i > numDays:
  850.                 i = i - numDays
  851.             try:
  852.                 bookName = str('{:02d}'.format(i))+str(self.year)+'.xlsx'
  853.                 dateDiplay = str('{:02d}'.format(i))+"/"+str(self.year)
  854.                 rb = open_workbook(bookName)
  855.                 wb = copy(rb)
  856.                 s = wb.get_sheet(0)
  857.                 if rb != None:
  858.                     for sheet in rb.sheets():
  859.                         for columns in range(sheet.ncols):
  860.                             for rows in range(sheet.nrows):
  861.                                 data = sheet.cell(rows,columns).value
  862.                                 if columns == 0:
  863.                                     if rows >= 1:
  864.                                         billListDate.append(dateDiplay)
  865.                                         billListName.append(data)
  866.                                 if columns == 1:
  867.                                     if rows >= 1:
  868.                                         billListCost.append(data)
  869.      
  870.             except:
  871.                 None
  872.                
  873.         for i in billListCost:
  874.             total += float(i)
  875.  
  876.         self.toWindow(total, billListName, billListCost, toPay, passRow, passCol, billListDate)
  877.                  
  878.     def toWindow(self, total, billListName, billListCost, toPay, passRow, passCol, billListDate):
  879.  
  880. ##        old_frame = tk.Frame(toPay)
  881. ##        toPay = tk.Frame(toPay)
  882.        
  883.         label = Label(toPay, text = "Bill Name")
  884.         label.grid(row=passRow, column=passCol)
  885.  
  886.         saveOrBorrow = self.payData + total
  887.        
  888.         if saveOrBorrow < 0:
  889.             borrow = float(saveOrBorrow)*-1
  890.             billListName.append("NEED to Borrow:")
  891.             billListCost.append("{0:.2f}".format(borrow))
  892.  
  893.         if saveOrBorrow > 0:
  894.             save = float(saveOrBorrow)
  895.             billListName.append("Can Save:")
  896.             billListCost.append("{0:.2f}".format(save))
  897.  
  898.         x = passRow
  899.         label = Label(toPay, text = "Bill Cost")
  900.         label.grid(row=passRow, column= passCol + 1)
  901.         for i in billListName:
  902.             passRow += 1
  903.             label = Label(toPay, text = "                              ")
  904.             label.grid(row=passRow, column=passCol)
  905.             label = Label(toPay, text = i)
  906.             label.grid(row=passRow, column=passCol)
  907.  
  908.         passRow = x
  909.         for i in billListCost:
  910.             passRow += 1
  911.             label = Label(toPay, text = "                               ")
  912.             label.grid(row=passRow, column=passCol + 1)
  913.             label = Label(toPay, text = i)
  914.             label.grid(row=passRow, column=passCol + 1)
  915.  
  916.         passRow = x
  917.         for i in billListDate:
  918.             passRow += 1
  919.             label = Label(toPay, text = "                               ")
  920.             label.grid(row=passRow, column=passCol + 2)
  921.             label = Label(toPay, text = i)
  922.             label.grid(row=passRow, column=passCol + 2)
  923.      
  924.         if x > 50:
  925.             label = Label(toPay, text = "Total Cost")
  926.             label.grid(row=100, column=passCol)
  927.             label = Label(toPay, text = "{0:.2f}".format(total))
  928.             label.grid(row=100, column=passCol + 1)
  929.              
  930.         else:
  931.             total = total
  932.             label = Label(toPay, text = "Total Cost")
  933.             label.grid(row=30, column=passCol)
  934.             label = Label(toPay, text = "{0:.2f}".format(total))
  935.             label.grid(row=30, column=passCol + 1)
  936.        
  937.     def prevMonth(self):
  938.        
  939.         self.month -= 1
  940.         if self.month <= 0:
  941.             self.month = 12
  942.             self.year -= 1
  943.         elif self.month >= 13:
  944.             self.month = 0
  945.             self.year += 1
  946.  
  947.         self.button = Label(self, text='               ')
  948.         self.button.grid(row=1,column=9)
  949.         self.button = Label(self, text='               ')
  950.         self.button.grid(row=2,column=9)
  951.         self.split()
  952.  
  953.     def nextMonth(self):
  954.                  
  955.         self.month += 1
  956.         for frame in self.frameList:
  957.             frame.grid_remove()
  958.        
  959.         if self.month <= -1:
  960.             self.month = 11
  961.             self.year -= 1
  962.         elif self.month >= 13:
  963.             self.month = 1
  964.             self.year += 1
  965.  
  966.         self.button = Label(self, text='               ')
  967.         self.button.grid(row=1,column=9)
  968.         self.button = Label(self, text='               ')
  969.         self.button.grid(row=2,column=9)
  970.         self.split()
  971.        
  972.     def createDaysOfWeekLabels(self):
  973.        
  974.         days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
  975.         for i in range(7):
  976.             label = Label(self, text=days[i], width = 3)
  977.             label.grid(row = 2, column = i)
  978.  
  979.     def showMonth(self, mFrame, mButton):
  980.        
  981.         # Display all buttons normally
  982.         for button in self.buttonList:
  983.             button['relief'] = 'raised'
  984.            
  985.         # Set this month's button relief to flat
  986.         mButton['relief'] = 'flat'
  987.  
  988.         # Hide all frames
  989.         for mframe in self.frameList:
  990.             mframe.grid_remove()
  991.  
  992.        
  993.         mFrame.grid()
  994.  
  995.     def createMonth(self, mFrame):
  996.        
  997.         try:
  998.             self.dayNum_remove()
  999.         except:
  1000.             pass
  1001.         weekday, numDays = monthrange(self.year, self.month)
  1002.         week = 0
  1003.        
  1004.         for i in range(1, numDays + 1):
  1005.            
  1006.             self.button = Button(mFrame, text = str(i), width=3,
  1007.                                  command=lambda day=i, weekDay = weekday:self.addBill(day, weekDay))
  1008.             self.button.grid(row = week, column = weekday)
  1009.            
  1010.             weekday += 1
  1011.             if weekday > 6:
  1012.                 week += 1
  1013.                 weekday = 0
  1014.                            
  1015.     def getAllTotals(self, mFrame, mButton):
  1016.        
  1017.         weekday, numDays = monthrange(self.year, self.month)
  1018.         week = 0
  1019.         totalCost = []
  1020.         day = 1
  1021.         theTotal = 0
  1022.         foundbill = False
  1023.         for i in range(1, numDays + 1):
  1024.             bookName = str('{:02d}'.format(day))+str(self.year)+'.xlsx'
  1025.             day += 1
  1026.             try:
  1027.                 rb = open_workbook(bookName)
  1028.                 foundbill = True
  1029.                 if foundbill == True:
  1030.                     self.button = Button(mFrame, text = str(i), bg = 'red', width=3, relief = SUNKEN,
  1031.                                          command=lambda day=i, weekDay = weekday:
  1032.                                          self.addBill(day, weekDay))
  1033.                     self.button.grid(row = week, column = weekday)
  1034.                    
  1035.                 weekday += 1
  1036.                 if weekday > 6:
  1037.                     week += 1
  1038.                     weekday = 0
  1039.                            
  1040.                 wb = copy(rb)
  1041.                 s = wb.get_sheet(0)
  1042.                 for sheet in rb.sheets():
  1043.                     for columns in range(sheet.ncols):
  1044.                         for rows in range(sheet.nrows):  
  1045.                             data = sheet.cell(rows,columns).value
  1046.                             if columns == 1:
  1047.                                 if rows >= 1:
  1048.                                     sheetTotal = float(data)
  1049.                                     totalCost.append(sheetTotal)
  1050.                                     theTotal = sheetTotal + theTotal
  1051.                                     label = Label(self, text="{0:.2f}".format(theTotal))
  1052.                                     label.grid(row=1,column=9)
  1053.                 foundbill = False
  1054.             except:
  1055.                 foundbill = False
  1056.                 weekday += 1
  1057.                 if weekday > 6:
  1058.                     week += 1
  1059.                     weekday = 0
  1060.                    
  1061.         self.findIncome(mFrame, mButton)
  1062.            
  1063.     def findIncome(self, mFrame, mButton):
  1064.        
  1065.         weekday, numDays = monthrange(self.year, self.month)
  1066.         week = 0
  1067.         incomeList = []
  1068.         totalIncome = 0
  1069.         day = 1
  1070.         foundinc = True
  1071.         foundbill = False
  1072.         for i in range(1, numDays + 1):
  1073.             bookName = str('{:02d}'.format(day))+str(self.year)+'.xlsx'
  1074.             incFileName = str('{:02d}'.format(self.month))+str('{:02d}'.format(i))+str(self.year)+'inc.txt'
  1075.             day += 1
  1076.             try:
  1077.                 iFN = open(incFileName, "r")
  1078.                 foundinc = True
  1079.                 try:
  1080.                     rb = open_workbook(bookName)
  1081.                     foundbill = True
  1082.                 except:
  1083.                     foundbill = False
  1084.                 if foundinc and foundbill == True:
  1085.                     self.button = Button(mFrame, text = str(i), bg = 'yellow', width=3, relief = SUNKEN,
  1086.                                          command=lambda day=i, weekDay = weekday:
  1087.                                          self.addBill(day, weekDay))
  1088.                     self.button.grid(row = week, column = weekday)
  1089.                     fileData = iFN.read()
  1090.                     incomeList.append(fileData)
  1091.                     foundinc = False
  1092.                     foundbill = False
  1093.                 if foundinc == True:
  1094.                     self.button = Button(mFrame, text = str(i), bg = 'green', width=3, relief = SUNKEN,
  1095.                                          command=lambda day=i, weekDay = weekday:
  1096.                                          self.addBill(day, weekDay))
  1097.                     self.button.grid(row = week, column = weekday)
  1098.                     fileData = iFN.read()
  1099.                     incomeList.append(fileData)
  1100.                 weekday += 1
  1101.                 if weekday > 6:
  1102.                     week += 1
  1103.                     weekday = 0
  1104.                            
  1105.                 foundinc = False
  1106.             except:
  1107.                 foundinc = False
  1108.                 weekday += 1
  1109.                 if weekday > 6:
  1110.                     week += 1
  1111.                     weekday = 0
  1112.         for i in incomeList:
  1113.             totalIncome = totalIncome + Decimal(i)
  1114.             label = Label(self, text="{0:.2f}".format(totalIncome))
  1115.             label.grid(row=2,column=9)
  1116.            
  1117.     def addBill(self, day, weekDay):
  1118.        
  1119.         daysNames = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
  1120.         indexes = [0,1,2,3,4,5,6]
  1121.        
  1122.         bookName = str('{:02d}'.format(day))+str(self.year)+'.xlsx'
  1123.         frameName = str('{:02d}'.format(self.month))+str('{:02d}'.format(day))+str(self.year)
  1124.         self.day = day
  1125.        
  1126.        
  1127.         class textEntry(Frame):
  1128.            
  1129.             def __init__(tEnt, master=None):
  1130.                
  1131.                 Frame.__init__(tEnt, master)
  1132.                 tEnt.pSV = 0
  1133.                 tEnt.grid(row=0, column=0, sticky='news')
  1134.                 tEnt.day = self.day
  1135.                
  1136.                 tutOption = Button(self, text="First time? click for Tutorial", command=lambda a=self,b=tEnt:tutorial(a,b))
  1137.                 tutOption.grid(row = 0, column = 8)
  1138.                 tEnt.createWidgets()
  1139.  
  1140.             def createWidgets(tEnt):
  1141.                
  1142.                 global c
  1143.                 Label(tEnt, text="Name of Workbook: ").grid(row=0, column=0)
  1144.                 Label(tEnt, text="Name of Bill: ").grid(row=2, column=0)
  1145.                 Label(tEnt, text="Cost of Bill: ").grid(row=3, column=0)
  1146.                
  1147.                 nameOfBook = StringVar()
  1148.                 nameOB = Entry(tEnt, textvariable=nameOfBook)
  1149.                 nameOB.pack()
  1150.                 nameOB.insert(0,frameName)
  1151.                 nameOB.grid(row=0, column=1)
  1152.  
  1153.                 tEnt.billNameSV = StringVar()
  1154.                 billName = Entry(tEnt, textvariable=tEnt.billNameSV)
  1155.                 billName.pack()
  1156.                 billName.insert(0,"NameofBill")
  1157.                 billName.grid(row=2,column=1)
  1158.  
  1159.                 tEnt.billCostSV = IntVar()
  1160.                 billCost = Entry(tEnt, textvariable=tEnt.billCostSV)
  1161.                 billCost.pack()
  1162.                 billCost.insert(0,"0.00")
  1163.                 billCost.grid(row=3,column=1)
  1164.  
  1165.                 submitButt = Button(tEnt, text="Submit",
  1166.                                     command= lambda billCost=billCost,
  1167.                                     billName=billName,bookName=bookName:
  1168.                                     tEnt.addToWorkBook(billCost,billName,bookName))
  1169.                 submitButt.grid(row=5,column=3)
  1170.  
  1171.                 addIncome = Button(tEnt, text="Income",
  1172.                                     command= tEnt.incomeCol)
  1173.                 addIncome.grid(row=1,column=0)
  1174.  
  1175.                 salaryPay = Button(tEnt, text="Select for Salary Pay",
  1176.                                     command= tEnt.salaryPay)
  1177.                 salaryPay.grid(row=1,column=1)
  1178.                
  1179.                 nOBSearch = Button(tEnt, text="Search",
  1180.                                    command= lambda bookName=bookName:
  1181.                                    tEnt.searchForBook(bookName))
  1182.                 nOBSearch.grid(row=0,column=3)
  1183.            
  1184.                 createBook = Button(tEnt, text="Create",
  1185.                                     command= lambda bookName=bookName:
  1186.                                     tEnt.createNewBook(bookName))
  1187.                 createBook.grid(row=1,column=3)
  1188.  
  1189.                 purgeBook = Button(tEnt, text="Purge",
  1190.                                     command= lambda bookName=bookName:
  1191.                                    tEnt.purgeBook(bookName))
  1192.                 purgeBook.grid(row=2,column=3)
  1193.  
  1194.                 if c == 1:
  1195.                     c = 0
  1196.                     billInp.destroy()
  1197.                     return
  1198.            
  1199.             def salaryPay(tEnt):
  1200.  
  1201.                 salaryFrame = Tk()
  1202.                 salaryFrame.title("Salary Income")
  1203.                 entryFrame = LabelFrame(salaryFrame)
  1204.                 entryFrame.grid(rowspan=7,columnspan=3, sticky=NS)
  1205.  
  1206.                 ##making labels for income##
  1207.                 payRate = Label(entryFrame, text="Pay Per Check:")
  1208.                 payRate.grid(row=1,column=0)
  1209.  
  1210.                 payEntryVar = DoubleVar()
  1211.                 payEntry = Entry(entryFrame, textvariable=payEntryVar)
  1212.                 payEntry.pack()
  1213.                 payEntry.insert(0,"1250.35")
  1214.                 payEntry.grid(row=1,column=1)
  1215.  
  1216.                 payFreq = Label(entryFrame, text="Frequency of Pay(in weeks):")
  1217.                 payFreq.grid(row=3,column=0)
  1218.                
  1219.                 payFreqOpt = [0,1,2,4]
  1220.                 payFreq = IntVar(entryFrame)
  1221.                 payFreq.set(payFreqOpt[2])
  1222.  
  1223.                 w = apply(OptionMenu, (entryFrame, payFreq) + tuple(payFreqOpt))
  1224.                 w.grid(row=3,column=1)
  1225.  
  1226.                 label = Label(entryFrame, text="Bonus:")
  1227.                 label.grid(row=4,column=0)
  1228.  
  1229.                 bonusEntryVar = IntVar()
  1230.                 bonusEntry = Entry(entryFrame, textvariable=bonusEntryVar)
  1231.                 bonusEntry.pack()
  1232.                 bonusEntry.insert(0,"0.00")
  1233.                 bonusEntry.grid(row=4,column=1)
  1234.                
  1235.                 submitButt = Button(entryFrame, text="Submit",
  1236.                                     command= lambda a=payEntry,b=payFreq,
  1237.                                     c=bonusEntry:
  1238.                                     tEnt.salaryPayCalculate(a,b,c))
  1239.                 submitButt.grid(row=6,column=0)
  1240.  
  1241.                 ridIncome = Button(entryFrame, text="Purge",
  1242.                                     command= tEnt.purgeIncome)
  1243.                 ridIncome.grid(row=6,column=1)
  1244.                
  1245.                 warningLabel = Label(salaryFrame, text="DO NOT enter a bonus amount with Frequency greater than 0")
  1246.                 warningLabel.grid(row=8,column=0, columnspan=3, sticky=NS)
  1247.                 warningLabel.config(font=('Arial','8','bold','italic'))
  1248.  
  1249.                 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")
  1250.                 warningLabel.grid(row=9,column=0, columnspan=3, sticky=NS)
  1251.                 warningLabel.config(font=('Arial','8','bold','italic'))
  1252.                
  1253.                 salaryFrame.geometry("350x175")
  1254.                 salaryFrame.lift()
  1255.                 salaryFrame.update()
  1256.  
  1257.             def salaryPayCalculate(tEnt, payEntry, payFreq, bonusEntry):
  1258.  
  1259.                 self.button = Label(self, text='                   ')
  1260.                 self.button.grid(row=2,column=9)
  1261.                 payEntry = Decimal(payEntry.get())
  1262.                 payFreq = int(payFreq.get())
  1263.                 bonusEntry = Decimal(bonusEntry.get())
  1264.                 if payFreq == 0:
  1265.                     toDecide = 1
  1266.                     multiplier = 1
  1267.                 else:
  1268.                     toDecide = 0
  1269.                     multiplier = payFreq
  1270.                    
  1271.                 monthlyInc = payEntry + bonusEntry
  1272.                 if toDecide == 1:
  1273.                     tEnt.createSinglePayDay(monthlyInc)
  1274.                 if toDecide != 1:    
  1275.                     tEnt.storeIncome(monthlyInc, payFreq)
  1276.                    
  1277.             def incomeCol(tEnt):
  1278.                
  1279.                 incFrame = Tk()
  1280.                 incFrame.title("Income Collection")
  1281.                 entryFrame = LabelFrame(incFrame)
  1282.                 entryFrame.grid(rowspan=7,columnspan=3, sticky=NS)
  1283.                
  1284.  
  1285.                 ##making labels for income##
  1286.                 payRate = Label(entryFrame, text="Pay Rate:")
  1287.                 payRate.grid(row=1,column=0)
  1288.  
  1289.                 payEntryVar = DoubleVar()
  1290.                 payEntry = Entry(entryFrame, textvariable=payEntryVar)
  1291.                 payEntry.pack()
  1292.                 payEntry.insert(0,"10.00")
  1293.                 payEntry.grid(row=1,column=1)
  1294.  
  1295.                 payFreq = Label(entryFrame, text="Weeks in Payperiod:")
  1296.                 payFreq.grid(row=3,column=0)
  1297.                
  1298.                 payFreqOpt = [0,1,2,4]
  1299.                 payFreq = IntVar(entryFrame)
  1300.                 payFreq.set(payFreqOpt[0])
  1301.  
  1302.                 w = apply(OptionMenu, (entryFrame, payFreq) + tuple(payFreqOpt))
  1303.                 w.grid(row=3,column=1)
  1304.                
  1305.                 label = Label(entryFrame, text="Hours Per Week:")
  1306.                 label.grid(row=2,column=0)
  1307.  
  1308.                 hoursEntryVar = IntVar()
  1309.                 hoursEntry = Entry(entryFrame, textvariable=hoursEntryVar)
  1310.                 hoursEntry.pack()
  1311.                 hoursEntry.insert(0,"40")
  1312.                 hoursEntry.grid(row=2,column=1)
  1313.  
  1314.                 label = Label(entryFrame, text="Tax Factor:")
  1315.                 label.grid(row=5,column=0)
  1316.  
  1317.                 taxEntryVar = IntVar()
  1318.                 taxEntry = Entry(entryFrame, textvariable=taxEntryVar)
  1319.                 taxEntry.pack()
  1320.                 taxEntry.insert(0,".25")
  1321.                 taxEntry.grid(row=5,column=1)
  1322.  
  1323.                 label = Label(entryFrame, text="Bonus:")
  1324.                 label.grid(row=7,column=0)
  1325.  
  1326.                 bonusEntryVar = IntVar()
  1327.                 bonusEntry = Entry(entryFrame, textvariable=bonusEntryVar)
  1328.                 bonusEntry.pack()
  1329.                 bonusEntry.insert(0,"0.00")
  1330.                 bonusEntry.grid(row=7,column=1)
  1331.                
  1332.                 submitButt = Button(entryFrame, text="Submit",
  1333.                                     command= lambda a=payEntry,b=payFreq,
  1334.                                     c=hoursEntry,d=incFrame, e=taxEntry, f=bonusEntry:
  1335.                                     tEnt.calculatePay(a,b,c,d,e,f))
  1336.                 submitButt.grid(row=6,column=0)
  1337.  
  1338.                 ridIncome = Button(entryFrame, text="Purge",
  1339.                                     command= tEnt.purgeIncome)
  1340.                 ridIncome.grid(row=6,column=1)
  1341.  
  1342.                 warningLabel = Label(incFrame, text="DO NOT enter a bonus amount with Frequency greater than 0")
  1343.                 warningLabel.grid(row=8,column=0, columnspan=3, sticky=NS)
  1344.                 warningLabel.config(font=('Arial','8','bold','italic'))
  1345.  
  1346.                 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")
  1347.                 warningLabel.grid(row=9,column=0, columnspan=3, sticky=NS)
  1348.                 warningLabel.config(font=('Arial','8','bold','italic'))
  1349.                
  1350.                 incFrame.geometry("350x250")
  1351.                 incFrame.lift()
  1352.                 incFrame.update()
  1353.  
  1354.             def purgeIncome(tEnt):
  1355.  
  1356.                 root = Tk()
  1357.                 root.title("WARNING MESSAGE")
  1358.  
  1359.                 label = Label(root, text="WARNING!!! This will purge the current Income File!")
  1360.                 label.grid(row=0,column=0)
  1361.  
  1362.                 continueButt = Button(root, text="Continue",
  1363.                                       command= lambda root=root: tEnt.destroyIncome(root))
  1364.                 continueButt.grid(row=1,column=0)
  1365.                 cancelButt = Button(root, text="Cancel",
  1366.                                       command= root.destroy)
  1367.                 cancelButt.grid(row=1,column=1)
  1368.                 root.lift()
  1369.                 root.update()
  1370.  
  1371.             def destroyIncome(tEnt, root):
  1372.                
  1373.                 mFrame = self.mFrame
  1374.                 mButton = self.mButton
  1375.                 weekday, numDays = monthrange(self.year, self.month)
  1376.                 fileName = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)+'inc'
  1377.                 day = 1
  1378.                 week = 0
  1379.                 os.remove(fileName+'.txt')
  1380.                 for i in range(1, numDays + 1):
  1381.                     if i == tEnt.day:
  1382.                         self.button = Button(mFrame, text = str(i), width=3,
  1383.                                          command=lambda day=i, weekDay = weekday:
  1384.                                          self.addBill(day, weekDay))
  1385.                         self.button.grid(row = week, column = weekday)
  1386.                            
  1387.                     weekday += 1
  1388.                     if weekday > 6:
  1389.                         week += 1
  1390.                         weekday = 0
  1391.  
  1392.                 self.button = Label(self, text='               ')
  1393.                 self.button.grid(row=2,column=9)
  1394.                 self.findIncome(mFrame,mButton)
  1395.                 tEnt.lift()
  1396.                 root.destroy()
  1397.                
  1398.             def calculatePay(tEnt, payEntry, payFreq, hoursEntry, incFrame, taxEntry, bonusEntry):
  1399.  
  1400.                 self.button = Label(self, text='                   ')
  1401.                 self.button.grid(row=2,column=9)
  1402.                 payEntry = Decimal(payEntry.get())
  1403.                 payFreq = int(payFreq.get())
  1404.                 bonusEntry = Decimal(bonusEntry.get())
  1405.                 if payFreq == 0:
  1406.                     toDecide = 1
  1407.                     multiplier = 1
  1408.                 else:
  1409.                     toDecide = 0
  1410.                     multiplier = payFreq
  1411.                 hoursEntry = int(hoursEntry.get())
  1412.                 taxEntry = Decimal(taxEntry.get())
  1413.                 monthlyIncTax = (payEntry * (hoursEntry * multiplier) * taxEntry)
  1414.                 monthlyInc = ((payEntry * (hoursEntry * multiplier)) - monthlyIncTax) + bonusEntry
  1415.                
  1416.                 if toDecide == 1:
  1417.                     tEnt.createSinglePayDay(monthlyInc)
  1418.                 if toDecide != 1:    
  1419.                     tEnt.storeIncome(monthlyInc, payFreq)
  1420.  
  1421.             def createSinglePayDay(tEnt, monthlyInc):
  1422.                
  1423.                 mFrame = self.mFrame
  1424.                 mButton = self.mButton
  1425.                 currentDate = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)
  1426.                 excluPayDay = tEnt.day
  1427.                 excluYear = self.year
  1428.                 excluMonth = self.month
  1429.                 startYear = excluYear
  1430.                 workingDate = str('{:02d}'.format(excluMonth))+str('{:02d}'.format(excluPayDay))+str(excluYear)+'inc'
  1431.                 incFile = open(workingDate+".txt", 'w')
  1432.                 incFile.write(str(monthlyInc))
  1433.                 incFile.close()
  1434.                 self.findIncome(mFrame,mButton)
  1435.  
  1436.             def createPayDays(tEnt, payFreq, monthlyInc):
  1437.  
  1438.                 currentDate = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)
  1439.                 excluPayDay = tEnt.day
  1440.                 excluYear = self.year
  1441.                 excluMonth = self.month
  1442.                 startYear = excluYear
  1443.                 x = 7 * payFreq
  1444.                 while excluYear == startYear:
  1445.                     weekday, numDays = monthrange(excluYear, excluMonth)
  1446.                     excluPayDay += x
  1447.                     if excluPayDay > numDays:
  1448.                         excluPayDay -= x
  1449.                         leftOver = numDays - excluPayDay
  1450.                         excluPayDay = x - leftOver
  1451.                         excluMonth += 1
  1452.                         if excluMonth > 12:
  1453.                             excluMonth = 1
  1454.                             excluYear += 1
  1455.                             return
  1456.                     if excluYear == self.year:                            
  1457.                         workingDate = str('{:02d}'.format(excluMonth))+str('{:02d}'.format(excluPayDay))+str(excluYear)+'inc'
  1458.                         incFile = open(workingDate+".txt", 'w')
  1459.                         incFile.write(str(monthlyInc))
  1460.                         incFile.close()
  1461.                     else:
  1462.                         pass
  1463.                 return
  1464.                        
  1465.             def storeIncome(tEnt, monthlyInc, payFreq):
  1466.                
  1467.                 mFrame = self.mFrame
  1468.                 mButton = self.mButton
  1469.                 weekday, numDays = monthrange(self.year, self.month)
  1470.                 day = 1
  1471.                 week = 0
  1472.                 fileName = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)+'inc'
  1473.                 incFile = open(fileName+".txt", "w")
  1474.                 incFile.write(str(monthlyInc))
  1475.                 incFile.close()
  1476.                 tEnt.createPayDays(payFreq, monthlyInc)
  1477.                 self.findIncome(mFrame,mButton)
  1478.                
  1479.             def purgeBook(tEnt, bookName):
  1480.                
  1481.                 root = Tk()
  1482.                 root.title("WARNING MESSAGE")
  1483.                
  1484.                 label = Label(root, text="WARNING!!! This will purge the current workbook!")
  1485.                 label.grid(row=0,column=0)
  1486.  
  1487.                 continueButt = Button(root, text="Continue",
  1488.                                       command= lambda root=root: tEnt.destroyBook(root))
  1489.                 continueButt.grid(row=1,column=0)
  1490.                 cancelButt = Button(root, text="Cancel",
  1491.                                       command= root.destroy)
  1492.                 cancelButt.grid(row=1,column=1)
  1493.                 root.lift()
  1494.                 root.update()
  1495.  
  1496.             def destroyBook(tEnt, root):
  1497.                
  1498.                 mFrame = self.mFrame
  1499.                 mButton = self.mButton
  1500.                 weekday, numDays = monthrange(self.year, self.month)
  1501.                 fileName = str('{:02d}'.format(self.month))+str('{:02d}'.format(tEnt.day))+str(self.year)+'inc'
  1502.                 day = 1
  1503.                 week = 0
  1504.                 os.remove(bookName)
  1505.                 for i in range(1, numDays + 1):
  1506.                     if i == tEnt.day:
  1507.                         self.button = Button(mFrame, text = str(i), width=3,
  1508.                                          command=lambda day=i, weekDay = weekday:
  1509.                                          self.addBill(day, weekDay))
  1510.                         self.button.grid(row = week, column = weekday)
  1511.                            
  1512.                     weekday += 1
  1513.                     if weekday > 6:
  1514.                         week += 1
  1515.                         weekday = 0
  1516.                 tEnt.lift()
  1517.                 root.destroy()
  1518.                 self.button = Label(self, text='               ')
  1519.                 self.button.grid(row=1,column=9)
  1520.                 self.getAllTotals(mFrame,mButton)
  1521.            
  1522.             def addToWorkBook(tEnt, billCost, billName, bookName):
  1523.                
  1524.                 tEnt.checkForWorkBook(bookName)
  1525.                 if tEnt.found == True:
  1526.                     rb = open_workbook(bookName)
  1527.                
  1528.                     for sheet in rb.sheets():
  1529.                         for columns in range(sheet.ncols):
  1530.                             for rows in range(sheet.nrows):  
  1531.                                 o = 0      
  1532.                     billName = billName.get()
  1533.                     billCost = billCost.get()
  1534.                    
  1535.                     wb = copy(rb)
  1536.                     sheet = wb.get_sheet(0)
  1537.                     row = rows+1
  1538.                     col = 0
  1539.                     sheet.write(row, col, str(billName))
  1540.                     col += 1
  1541.                     billCost = float(billCost) * -1
  1542.                     sheet.write(row, col, float(billCost))
  1543.                     wb.save(bookName)
  1544.                     mFrame = self.mFrame
  1545.                     mButton = self.mButton
  1546.                     self.getAllTotals(mFrame,mButton)
  1547.                 else:
  1548.                     tEnt.createNewBook(bookName)
  1549.                     tEnt.addToWorkBook(billCost, billName, bookName)
  1550.            
  1551.             def createNewBook(tEnt, bookName):
  1552.                
  1553.                 try:
  1554.                     tEnt.checkForWorkBook(bookName)
  1555.                     if tEnt.found == True:
  1556.                        
  1557.                         return
  1558.                    
  1559.                 except:
  1560.                     tEnt.found = False
  1561.                 if tEnt.found == False:
  1562.                     try:
  1563.                         nameOfBook = bookName
  1564.                         workbook = xlsxwriter.Workbook(nameOfBook)
  1565.                         worksheet1 = workbook.add_worksheet()
  1566.                         worksheet1.write(0,0,"Bill Name")
  1567.                         worksheet1.write(0,1,"Bill Cost")
  1568.                         workbook.close()
  1569.                        
  1570.                     except:
  1571.                         o=0
  1572.                         pass
  1573.                    
  1574.             def checkForWorkBook(tEnt, bookName):
  1575.  
  1576.                 billListName = []
  1577.                 billListCost = []
  1578.                 total = 0
  1579.                 try:
  1580.                     rb = open_workbook(bookName)
  1581.                     wb = copy(rb)
  1582.                     s = wb.get_sheet(0)
  1583.                     wb.save(bookName)
  1584.                    
  1585.                     for sheet in rb.sheets():
  1586.                         for columns in range(sheet.ncols):
  1587.                             for rows in range(sheet.nrows):
  1588.                                 data = sheet.cell(rows,columns).value
  1589.                                 if columns == 0:
  1590.                                     billListName.append(data)
  1591.                                 if columns == 1:
  1592.                                     if rows >= 1:
  1593.                                         billListCost.append(data)  
  1594.                                
  1595.                     tEnt.found = True
  1596.                     return bookName
  1597.                
  1598.                 except:
  1599.                     tEnt.found = False
  1600.                     pass
  1601.                    
  1602.  
  1603.             def searchForBook(tEnt, bookName):
  1604.                
  1605.                 billListName = []
  1606.                 billListCost = []
  1607.                 total = 0
  1608.                
  1609.                 try:
  1610.                     rb = open_workbook(bookName)
  1611.                     wb = copy(rb)
  1612.                     s = wb.get_sheet(0)
  1613.                     wb.save(bookName)
  1614.                    
  1615.                     for sheet in rb.sheets():
  1616.                         for columns in range(sheet.ncols):
  1617.                             for rows in range(sheet.nrows):
  1618.                                 data = sheet.cell(rows,columns).value
  1619.                                 if columns == 0:
  1620.                                     billListName.append(data)
  1621.                                 if columns == 1:
  1622.                                     if rows >= 1:
  1623.                                         billListCost.append(data)  
  1624.                                
  1625.                     tEnt.found = True
  1626.                     tEnt.printWindow(bookName, total, columns, rows, data, billListName, billListCost)
  1627.  
  1628.                
  1629.                 except:
  1630.                     tEnt.found = False
  1631.                     pass
  1632.                    
  1633.  
  1634.             def printWindow(tEnt, bookName, total, columns, rows, data, billListName, billListCost):
  1635.  
  1636.                 global c
  1637.                  
  1638.                 printScreen = Tk()
  1639.                 printScreen.title("Message Window")
  1640.                 printScreen.geometry("300x400")
  1641.                 printScreen.lift()
  1642.    
  1643.                 label = Label(printScreen, text = "BookName: " + str(frameName))
  1644.                 label.grid(row=0, column=0)
  1645.                    
  1646.                 x = 0
  1647.                 for i in billListName:
  1648.                     x += 1
  1649.                     label = Label(printScreen, text = i)
  1650.                     label.grid(row=x, column=0)
  1651.  
  1652.                 label = Label(printScreen, text = "Bill Cost")
  1653.                 label.grid(row=1, column=1)
  1654.                
  1655.                 x = 1
  1656.                 for i in billListCost:
  1657.                     x += 1
  1658.                     total = total + float(i)
  1659.                     label = Label(printScreen, text = i)
  1660.                     label.grid(row=x, column=1)
  1661.  
  1662.                 label = Label(printScreen, text = "Total Cost")
  1663.                 label.grid(row=1, column=2)
  1664.                 label = Label(printScreen, text = "{0:.2f}".format(total))
  1665.                 label.grid(row=2, column=2)
  1666.                 if c == 1:
  1667.                     for i in range(0,6):
  1668.                         label = Label(printScreen, text = str(i))
  1669.                         label.grid(row=0,column=4)
  1670.                         printScreen.update()
  1671.                         time.sleep(1)
  1672.                     c += 1
  1673.                     printScreen.destroy()
  1674.                    
  1675.         try:        
  1676.             billInp = Tk()
  1677.             billInp.title(frameName)
  1678.             obj = textEntry(billInp)
  1679.             billInp.lift()
  1680.             billInp.update()      
  1681.         except:
  1682.             global c
  1683.             c = 0
  1684.             return
  1685.            
  1686.  
  1687. mainWindow = Tk()
  1688. mainWindow.lift()
  1689. mainWindow.geometry("450x300")
  1690. mainWindow.title("Bill Keeper")
  1691. obj = Application(mainWindow)
  1692. mainWindow.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement