def initUI(self): #portable p = Panedwindow(self.parent, orient=HORIZONTAL) leftFrame = LabelFrame(p) rightFrame = LabelFrame(p) p.add(leftFrame, weight=60) p.add(rightFrame, weight=40) p.pack(fill=BOTH, expand=1) p.pack_propagate(0) leftFrame.pack_propagate(0) rightFrame.pack_propagate(0) self.saveFrame = saveFrame = Frame(leftFrame) self.treeFrame = treeFrame = Frame(leftFrame) self.xScrollFrame = xScrollFrame = Frame(leftFrame) self.totalFrame = totalFrame = Frame(leftFrame) saveFrame.pack(expand=0, fill=X, side=TOP) totalFrame.pack(expand=0, fill=X, side=BOTTOM) xScrollFrame.pack(expand=0, fill=X, side=BOTTOM) treeFrame.pack(expand=1, fill=BOTH, side=TOP) self.saveDeleteFrame = Frame(rightFrame) self.fieldsFrame = VerticalScrolledFrame(rightFrame) self.saveDeleteFrame.pack(expand=0, fill=X, side=BOTTOM) self.fieldsFrame.pack(expand=1, fill=BOTH, side=TOP) self.generateNewButton()
def initUI(self): self.printFrame = Frame(self) self.printFrame.pack(fill=X,expand=0,side=TOP) self.printButton = Button(self.printFrame,text="Export to docx",command=self.exportCallback) self.printButton.pack(fill=NONE,expand=0,side=LEFT) self.mainFrame = VerticalScrolledFrame(self) self.mainFrame.pack(fill=BOTH,expand=1,side=TOP) self.headerField = Text(self.mainFrame.interior,bd=0,width=0,state='disabled',height=3) self.headerField.tag_configure("center",justify="center") self.boldFont = f = Font(self.headerField,self.headerField.cget('font')) f.configure(weight='bold') self.headerField.configure(font=f) self.headerField.pack(fill=X,expand=0,side=TOP) self.cashFlowsText = TextTable(self.mainFrame.interior, aligns=['left','left','right','right','right','right'], weights=[4,4,1,1,1,1], width=500) self.cashFlowsText.pack(expand=1,fill=BOTH,side=TOP) self.oalText = Text(self.mainFrame.interior,bd=0,width=0,state='disabled',height=0) self.oalText.tag_configure("bold",font=f) self.oalText.pack(fill=X,expand=0,side=TOP) self.noteChunk=NoteChunk(self.mainFrame.interior,self.app) self.noteChunk.pack(fill=BOTH,expand=1,side=TOP) self.noteBlocks = self.noteChunk.noteBlocks
def initUI(self): #portable p = Panedwindow(self.parent,orient=HORIZONTAL) leftFrame = LabelFrame(p) rightFrame = LabelFrame(p) p.add(leftFrame,weight=60) p.add(rightFrame,weight=40) p.pack(fill=BOTH,expand=1) p.pack_propagate(0) leftFrame.pack_propagate(0) rightFrame.pack_propagate(0) self.saveFrame = saveFrame = Frame(leftFrame) self.treeFrame = treeFrame = Frame(leftFrame) self.xScrollFrame = xScrollFrame = Frame(leftFrame) self.totalFrame = totalFrame = Frame(leftFrame) saveFrame.pack(expand=0,fill=X,side=TOP) totalFrame.pack(expand=0,fill=X,side=BOTTOM) xScrollFrame.pack(expand=0,fill=X,side=BOTTOM) treeFrame.pack(expand=1,fill=BOTH,side=TOP) self.saveDeleteFrame = Frame(rightFrame) self.fieldsFrame = VerticalScrolledFrame(rightFrame) self.saveDeleteFrame.pack(expand=0,fill=X,side=BOTTOM) self.fieldsFrame.pack(expand=1,fill=BOTH,side=TOP) self.generateNewButton()
def initUI(self): self.printFrame = Frame(self) self.printFrame.pack(fill=X, expand=0, side=TOP) self.printButton = Button(self.printFrame, text="Export to docx", command=self.exportCallback) self.printButton.pack(fill=NONE, expand=0, side=LEFT) self.mainFrame = VerticalScrolledFrame(self) self.mainFrame.pack(fill=BOTH, expand=1, side=TOP) self.headerField = Text(self.mainFrame.interior, bd=0, width=0, state='disabled', height=3) self.headerField.tag_configure("center", justify="center") self.boldFont = f = Font(self.headerField, self.headerField.cget('font')) f.configure(weight='bold') self.headerField.configure(font=f) self.headerField.pack(fill=X, expand=0, side=TOP) self.cashFlowsText = TextTable( self.mainFrame.interior, aligns=['left', 'left', 'right', 'right', 'right', 'right'], weights=[4, 4, 1, 1, 1, 1], width=500) self.cashFlowsText.pack(expand=1, fill=BOTH, side=TOP) self.oalText = Text(self.mainFrame.interior, bd=0, width=0, state='disabled', height=0) self.oalText.tag_configure("bold", font=f) self.oalText.pack(fill=X, expand=0, side=TOP) self.noteChunk = NoteChunk(self.mainFrame.interior, self.app) self.noteChunk.pack(fill=BOTH, expand=1, side=TOP) self.noteBlocks = self.noteChunk.noteBlocks
def initUI(self): self.parent.title("Test UI") menubar = Menu(self.parent) self.parent.config(menu=menubar) self.parent.geometry("700x500") #menu usersMenu = Menu(menubar) usersMenu.add_command(label="Create User") preferencesMenu = Menu(menubar) preferencesMenu.add_command(label="Settings") menubar.add_cascade(label="User", menu=usersMenu) menubar.add_cascade(label="Preferences", menu=preferencesMenu) menubar.add_command(label="About", command=self.clickAbout) #notebook n = Notebook(self.parent) f1 = Frame(n) f2 = Frame(n) n.add(f1, text='One') n.add(f2, text='Two') n.pack(fill=BOTH, expand=1) n.pack_propagate(0) #panedwindow p = Panedwindow(f1, orient=HORIZONTAL) lf1 = LabelFrame(p, text="Pane1") lf2 = VerticalScrolledFrame(p) p.add(lf1, weight=60) p.add(lf2, weight=40) p.pack(fill=BOTH, expand=1) p.pack_propagate(0) lf1.pack_propagate(0) lf2.pack_propagate(0) #listbox listFrame = Frame(lf1) scrollBar = Scrollbar(listFrame, orient=VERTICAL) listBox = Listbox(listFrame, yscrollcommand=scrollBar.set) scrollBar.config(command=listBox.yview) scrollBar.pack(side=RIGHT, fill=Y) listBox.pack(side=LEFT, fill=BOTH, expand=1) listFrame.pack(fill=BOTH, expand=1) for i in range(0, 500): listBox.insert(END, i) #add some datafield boxes for i in range(0, 7): dfb = TextFieldBox(lf2.interior, label=str(i), toolTip="Tooltip " + str(i)) print dfb.text dfb.text = str(i) dfb.pack(expand=1, fill=X) self.autocomplete = AutocompleteBox(lf2.interior, label="autocomplete") self.autocomplete.initComboBox("payors") self.autocomplete.text = "autocomplete" self.autocomplete.pack(expand=1, fill=X) self.calendarBox = calendarBox = CalendarBox(lf2.interior, label="Calendar", toolTip="Sample calendar") calendarBox.pack(expand=1, fill=X) options = ["option1", "two", "tres"] self.dropdown = AutocompleteBox(lf2.interior, label="Dropdown") self.dropdown.initDropDown() self.dropdown.pack(expand=1, fill=X) # self.dropdown = DropDownBox(lf2.interior, label="dropdown1", toolTip="dropdown!", options=options) # self.dropdown.pack(expand=1, fill=None) button = Button(lf1, text='Press', command=self.clickPress) button.pack(pady=20, padx=20)
def initUI(self): self.parent.title("Test UI") menubar = Menu(self.parent) self.parent.config(menu=menubar) self.parent.geometry("700x500") #menu usersMenu=Menu(menubar) usersMenu.add_command(label="Create User") preferencesMenu = Menu(menubar) preferencesMenu.add_command(label="Settings") menubar.add_cascade(label="User",menu=usersMenu) menubar.add_cascade(label="Preferences",menu=preferencesMenu) menubar.add_command(label="About",command=self.clickAbout) #notebook n = Notebook(self.parent) f1 = Frame(n) f2 = Frame(n) n.add(f1,text='One') n.add(f2,text='Two') n.pack(fill=BOTH,expand=1) n.pack_propagate(0) #panedwindow p = Panedwindow(f1,orient=HORIZONTAL) lf1=LabelFrame(p,text="Pane1") lf2=VerticalScrolledFrame(p) p.add(lf1,weight=60) p.add(lf2,weight=40) p.pack(fill=BOTH,expand=1) p.pack_propagate(0) lf1.pack_propagate(0) lf2.pack_propagate(0) #listbox listFrame = Frame(lf1) scrollBar = Scrollbar(listFrame,orient=VERTICAL) listBox = Listbox(listFrame,yscrollcommand=scrollBar.set) scrollBar.config(command=listBox.yview) scrollBar.pack(side=RIGHT,fill=Y) listBox.pack(side=LEFT,fill=BOTH,expand=1) listFrame.pack(fill=BOTH,expand=1) for i in range(0,500): listBox.insert(END,i) #add some datafield boxes for i in range(0,7): dfb = TextFieldBox(lf2.interior,label=str(i),toolTip="Tooltip "+str(i)) print dfb.text dfb.text=str(i) dfb.pack(expand=1,fill=X) self.autocomplete = AutocompleteBox(lf2.interior, label="autocomplete") self.autocomplete.initComboBox("payors") self.autocomplete.text = "autocomplete" self.autocomplete.pack(expand=1, fill=X) self.calendarBox = calendarBox = CalendarBox(lf2.interior,label="Calendar",toolTip="Sample calendar") calendarBox.pack(expand=1,fill=X) options = ["option1", "two", "tres"] self.dropdown = AutocompleteBox(lf2.interior,label="Dropdown") self.dropdown.initDropDown() self.dropdown.pack(expand=1,fill=X) # self.dropdown = DropDownBox(lf2.interior, label="dropdown1", toolTip="dropdown!", options=options) # self.dropdown.pack(expand=1, fill=None) button = Button(lf1, text = 'Press', command = self.clickPress) button.pack(pady=20, padx = 20)
class StatementWindow(Frame,object): def __init__(self,parent,app,deletedVar,**kwargs): Frame.__init__(self,parent,**kwargs) self.app = app self.parent = parent self.initUI() def initUI(self): self.printFrame = Frame(self) self.printFrame.pack(fill=X,expand=0,side=TOP) self.printButton = Button(self.printFrame,text="Export to docx",command=self.exportCallback) self.printButton.pack(fill=NONE,expand=0,side=LEFT) self.mainFrame = VerticalScrolledFrame(self) self.mainFrame.pack(fill=BOTH,expand=1,side=TOP) self.headerField = Text(self.mainFrame.interior,bd=0,width=0,state='disabled',height=3) self.headerField.tag_configure("center",justify="center") self.boldFont = f = Font(self.headerField,self.headerField.cget('font')) f.configure(weight='bold') self.headerField.configure(font=f) self.headerField.pack(fill=X,expand=0,side=TOP) self.cashFlowsText = TextTable(self.mainFrame.interior, aligns=['left','left','right','right','right','right'], weights=[4,4,1,1,1,1], width=500) self.cashFlowsText.pack(expand=1,fill=BOTH,side=TOP) self.oalText = Text(self.mainFrame.interior,bd=0,width=0,state='disabled',height=0) self.oalText.tag_configure("bold",font=f) self.oalText.pack(fill=X,expand=0,side=TOP) self.noteChunk=NoteChunk(self.mainFrame.interior,self.app) self.noteChunk.pack(fill=BOTH,expand=1,side=TOP) self.noteBlocks = self.noteChunk.noteBlocks def populateTree(self): tStart = secsToDay(self.app.timeFrame[0]).split("-") sYear = tStart[0] sDay = tStart[2] sMonth = MONTHS[int(tStart[1])] tStart = str(sMonth)+" "+str(sDay)+", "+str(sYear) tEnd = secsToDay(self.app.timeFrame[-1]).split("-") month = MONTHS[int(tEnd[1])] year = tEnd[0] day = tEnd[2] self.lines=[] self.headerField['state']='normal' self.headerField.delete('1.0','end') self.headerField.insert('1.0',self.app.councilName+"\nStatement of Cash Flows\nFor the Semester Ended "+month+" "+day+", "+year) self.headerField.tag_add('center','1.0','end') #self.headerField['state']='disabled' self.lines.append([['CASH INFLOWS','Note','','','',''],[],[1,0,0,0,0,0]]) cashFlowList = self.app.listCashflows(showDeleted=False) inflowList = [i for i in cashFlowList if i.source.content.split(":")[0]=="CashReceipt"] totalInflows=0 self.firstInflow=0 self.firstInflowTotal=0 self.lineTypes="Inflow" #replace with db stuff inflowTypeList = ['Council Mandated Funds','General Sponsorship Inflows','Income Generating Projects','Other Inflows'] for inflowType in inflowTypeList: partialList = filterDOT(self.app,[i for i in inflowList if i.getContents().category.content==inflowType]) lines,partialTotal = self.getInflows(partialList) if lines!=[]: self.lines.append([[inflowType,'','','','',''],[],[]]) self.lines=self.lines+lines totalInflows+=partialTotal self.firstInflow=0 self.firstInflowTotal=0 self.lineTypes="Outflow" self.lines.append([[tab(3)+"Total Inflows",'','','','P',floatToStr(totalInflows)],[0,0,0,0,0,1],[]]) self.lines.append([["",'','','','',''],[0,0,0,0,0,0],[0,0,0,0,0,0]]) self.lines.append([['CASH OUTFLOWS','','','','',''],[],[1,0,0,0,0,0]]) outflowList = [i for i in cashFlowList if i.source.content.split(":")[0] in ("OME","COCPNote","LTINote","OONote")] totalOutflows=0 self.firstOutflow=0 self.firstOutflowTotal=0 outflowNames ={"COCPNote":"Council and Other College Projects","LTINote":"Long Term Investment","OME":"Operation and Maintenance Expenses","OONote":"Other Outflows"} for outflowType in ("COCPNote","LTINote","OME","OONote"): partialList = filterDOT(self.app,[i for i in outflowList if i.source.content.split(":")[0]==outflowType]) lines,partialTotal = self.getInflows(partialList) if lines!=[]: self.lines.append([[outflowNames[outflowType],'','','','',''],[],[]]) self.lines=self.lines+lines totalOutflows+=partialTotal self.lines.append([[tab(3)+"Total Outflows",'','','','P',"("+floatToStr(totalOutflows)+")"],[0,0,0,0,0,1],[]]) self.lines = self.setUnderlines(self.lines) totalFlows = totalInflows-totalOutflows strTotalFlows = floatToStrParenNeg(totalFlows) self.lines.append([["Net Cash Flow",'','','','',strTotalFlows],[0,0,0,0,0,0],[1,0,0,0,0,0]]) #beginning balance filler beginningBalance=getStartBalance(self.app,int(self.app.timeFrame[0])) self.lines.append([["Add: Beginning Cash Balance, "+tStart,'','','','',floatToStr(beginningBalance)],[0,0,0,0,0,1],[0,0,0,0,0,0]]) self.lines.append([["Ending Cash Balance, "+month+" "+day+", "+year,'','','','',floatToStrParenNeg(beginningBalance+totalFlows)],[0,0,0,0,0,1],[1,0,0,0,0,0]]) self.lines.append([["",'','','','',''],[0,0,0,0,0,0],[0,0,0,0,0,0]]) self.lines.append([["Cash Breakdown",'','','','',''],[0,0,0,0,0,0],[1,0,0,0,0,0]]) self.lines.append([['Cash on hand','','','','',self.app.cashOnHand],[0,0,0,0,0,0],[0,0,0,0,0,0]]) self.lines.append([['Cash in bank','','','','',self.app.cashInBank],[0,0,0,0,0,0],[0,0,0,0,0,0]]) totalBalance = floatToStr(strToFloat(self.app.cashOnHand)+strToFloat(self.app.cashInBank)) self.lines.append([['Cash Balance, '+month+' '+day+', '+year,'','','','',totalBalance],[0,0,0,0,0,1],[1,0,0,0,0,0]]) self.commitLines(self.lines) self.popOAL() self.noteChunk.update() self.noteBlocks = self.noteChunk.noteBlocks print self.noteBlocks def getInflows(self,flowList): partialTotals={} totalInflows=0 for i in flowList: name = i.getContents().nature.content amount = i.getContents().amount.content notes = i.note.content category = i.source.content.split(":")[0] if category=="COCPNote": name=i.getContents().event.content try: amount = float(amount) except: amount=0 totalInflows+=amount if name in partialTotals: partialTotals[name][0]+=amount else: partialTotals[name]=[amount] partialTotals[name].append(notes) newLines = self.writeLinesPartial(partialTotals) return newLines,totalInflows def writeLinesPartial(self,partialTotalsList): total=0 partialTotalsKeys = partialTotalsList.keys() partialTotalsKeys.sort() tempLines=[] for i in partialTotalsKeys: name = i amount = partialTotalsList[i][0] notes = partialTotalsList[i][1] total+=amount tempLines.append([[tab()+name,notes,'',floatToStr(amount),'',''],[],[]]) if tempLines: if not self.firstInflow: tempLines[0][0][2]="P" self.firstInflow=1 tempLines.append([[tab(2)+"Total",'','','','',floatToStr(total)],[0,0,0,0,0,0],[]]) if self.lineTypes == "Outflow": tempLines[-1][0][-1]="("+tempLines[-1][0][-1]+")" if not self.firstInflowTotal: self.firstInflowTotal=1 tempLines[-1][0][4]="P" return tempLines def commitLines(self,lines): self.cashFlowsText.clear() for i in lines: self.cashFlowsText.addRow(i[0],uls=i[1],bolds=i[2]) def setUnderlines(self,lines): for i in range(0,len(lines)): if lines[i][0][0]==tab(2)+"Total": lines[i-1][1]=[0,0,0,1,0,0] if lines[i][0][0]==tab(3)+"Total Inflows" or lines[i][0][0]==tab(3)+"Total Outflows": lines[i-1][1]=[0,0,0,0,0,1] return lines def popOAL(self): oalInfo = getOAL(self.app) self.oalText['state']='normal' self.oalText.delete('1.0','end') if oalInfo!="": self.oalText.insert(self.oalText.index("end"),"\nOTHER ASSETS AND LIABILITIES\n") self.oalText.tag_add("bold",'1.0','end -1 line lineend') self.oalText.insert(self.oalText.index("end"),oalInfo) self.oalText.configure(height=int(self.oalText.index('end-1c').split('.')[0])+3) self.oalText['state']='disabled' def exportCallback(self): docBuilder = DocBuilder() # Write the 1st line of the header (council name) headerText = self.headerField.get(1.0, "1.end") docBuilder.createParagraph(headerText, "center", bold=True) # Write the 2nd line of the header (statement of cash flows) headerText = self.headerField.get(2.0, "2.end") docBuilder.createParagraph(headerText, "center", bold=True) # Write the 3rd line of the header (semester) headerText = self.headerField.get(3.0, "3.end") docBuilder.createParagraph(headerText, "center", bold=True) # Write the cash flows table self._export_CreateTable(self.lines, docBuilder) # Add some line breaks docBuilder.document.add_paragraph() # Write the OAL oalText = self.oalText.get(1.0, END) oalText = oalText.split("\n") docBuilder.document.add_paragraph().add_run(oalText[1]).bold = True for x in xrange(2, len(oalText)): docBuilder.document.add_paragraph(oalText[x]) # Write the Notes header docBuilder.document.add_paragraph().add_run("NOTES TO FINANCIAL STATEMENT").bold = True # Write the Notes data for noteBlock in self.noteBlocks: if noteBlock.blockType == "text": # Write the heading newParagraph = docBuilder.document.add_paragraph() newParagraph.add_run(noteBlock.payload[0]).bold = True # Write the non-heading text textData = noteBlock.payload[1].split("\n") for line in textData: docBuilder.document.add_paragraph(line) elif noteBlock.blockType == "table": self._export_CreateTable(noteBlock.payload, docBuilder, 5) # Line break docBuilder.document.add_paragraph() # Write the statement of accountability docBuilder.document.add_paragraph().add_run("STATEMENT OF FINANCE COUNCILOR'S ACCOUNTABILITY").bold = True docBuilder.document.add_paragraph(""""I am hereunto affirming that to the best of my intentions, the Statement of Cash Flows and all its pertinent information fairly represent all the financial transactions that have transpired within the council, its constituents, and all relevant stakeholders for the semester ending (date), and in conformity with the standard accounting procedures as set forth and duly upheld by the University Student Council of UP Diliman." """) # Line break docBuilder.document.add_paragraph() docBuilder.document.add_paragraph() docBuilder.document.add_paragraph() # Write the signatures preparedBy = self.app.preparedBy.split("\n") notedBy = self.app.notedBy.split("\n") while len(preparedBy) < 3: preparedBy.append("") while len(notedBy) < 3: notedBy.append("") tableData = [] tableData.append( [CellData("Prepared by:"), CellData("Noted by:")] ) tableData.append( [CellData(""), CellData("")] ) tableData.append( [CellData(""), CellData("")] ) tableData.append( [CellData(preparedBy[0]), CellData(notedBy[0])] ) tableData.append( [CellData(preparedBy[1]), CellData(notedBy[1])] ) tableData.append( [CellData(preparedBy[2]), CellData(notedBy[2])] ) docBuilder.createTable(2, tableData) # # Add signature images # run = docBuilder.table.cell(2, 0).add_paragraph().add_run() # run.add_picture('random.png', width=Inches(1)) # Save the document fileName = 'StatementOfCashFlows_' + datetime.datetime.now().strftime("%I%M%p_%B%d_%Y") + '.docx' docBuilder.save(fileName) def _export_CreateTable(self, lineData, docBuilder, numberOfColumns=6): """Reads self.lines and creates a docx table from it""" lines = list(lineData) # list of lists, where each entry is a list of CellData objects that represents a row tableData = [] # iterate through the rows to construct tableData for line in lines: lineText = line[0] if not line[1]: line[1] = [0] * numberOfColumns if not line[2]: line[2] = [0] * numberOfColumns isUnderlined = line[1] isBold = line[2] rowData = [] # iterate through the cells in a row to construct rowData for i in xrange(numberOfColumns): text = lineText[i] cellData = CellData(text) if (isUnderlined[i] == 1): cellData.tags.append("underline") if (isUnderlined[i] == 2): cellData.tags.append("double_underline") if (isBold[i] == 1): cellData.tags.append("bold") rowData.append(cellData) tableData.append(rowData) docBuilder.createTable(numberOfColumns, tableData) # manually set table column widths if (numberOfColumns == 6): docBuilder.columns[0].width = Inches(2.5) docBuilder.columns[1].width = Inches(1) docBuilder.columns[2].width = Inches(0.25) docBuilder.columns[3].width = Inches(1) docBuilder.columns[4].width = Inches(0.25) docBuilder.columns[5].width = Inches(1) elif (numberOfColumns == 5): docBuilder.columns[0].width = Inches(3.5) docBuilder.columns[1].width = Inches(0.25) docBuilder.columns[2].width = Inches(1) docBuilder.columns[3].width = Inches(0.25) docBuilder.columns[4].width = Inches(1)
def initUI(self): p = Panedwindow(self.parent,orient=HORIZONTAL) leftFrame = LabelFrame(p) rightFrame = LabelFrame(p) p.add(leftFrame,weight=60) p.add(rightFrame,weight=40) p.pack(fill=BOTH,expand=1) p.pack_propagate(0) leftFrame.pack_propagate(0) rightFrame.pack_propagate(0) #leftFrame elements leftFrameUpperest = Frame(leftFrame) leftFrameUpper = Frame(leftFrame) leftFrameLower = Frame(leftFrame) leftFrameLower.pack(expand=0,fill=X,side=BOTTOM) leftFrameUpperest.pack(expand=0,fill=X,side=TOP) leftFrameUpper.pack(expand=1,fill=BOTH,side=BOTTOM) newButton = Button(leftFrameUpperest,text="New",command=self.newEntry,style="NEWButton.TButton") newButton.pack(fill=None,expand=0,side=LEFT) self.tree = tree = Treeview(leftFrameUpper,selectmode="browse") tree.bind("<<TreeviewSelect>>",self.getSelection) yscroll = Scrollbar(leftFrameUpper,orient="vertical",command=tree.yview) xscroll=Scrollbar(leftFrameLower,orient="horizontal",command=tree.xview) colList = ["Timestamp","Date of Transaction","Category","Nature","Amount","Payor's Name","Acknowledgement Receipt #","Notes","Remarks"] tree['columns']= colList for col in colList: tree.heading(col,text=col,command=lambda _col=col: \ treeview_sort_column(tree,_col,False)) tree.column(col,anchor=W,width=60) tree.column('#0',width=3,anchor=W) if "Amount" in colList: tree.column("Amount",anchor=E) tree.configure(yscroll=yscroll.set,xscroll=xscroll.set) yscroll.pack(side=RIGHT,fill=Y) xscroll.pack(side=TOP,fill=X) tree.pack(side=LEFT,fill=BOTH,expand=1) tree.tag_configure("deleted",foreground="red") tree.tag_configure("edited",foreground="orange") #bottombar leftLowestFrame = Frame(leftFrameLower) leftLowestFrame.pack(fill=X,expand=0) self.totalLabel=totalLabel=Label(leftLowestFrame,text="Total Cash Receipts: ",relief=SUNKEN,width=50) totalLabel.pack(fill=None,expand=0,side=RIGHT) #populateTree #testing. Remove later for actual data self.fieldList = ['timestamp','dateOfTransaction','category','nature','amount','payor','receiptNumber','notes','remarks'] self.populateTree() #rightFrame upperRight = VerticalScrolledFrame(rightFrame) lowerRight = Frame(rightFrame) lowerRight.pack(fill=X,expand=0,side=BOTTOM) upperRight.pack(fill=BOTH,expand=1,side=TOP) saveButton = Button(lowerRight,text="Save",command=self.save,style="SAVEButton.TButton") saveButton.pack(side=LEFT,fill=X,expand=1) deleteButton = Button(lowerRight,text="Delete",command=self.delete) deleteButton.pack(side=LEFT,fill=X,expand=1) #fields self.fields={} self.fields['timestamp'] = timestamp = TextFieldBox(upperRight.interior,label="Timestamp",readonly=True,height=1) self.fields['dateOfTransaction']=dot = CalendarBox(upperRight.interior,label="Date of Transaction") dot.pack(side=TOP,fill=X,expand=1) #options for removal, get from DB options = ["Council Mandated Funds","General Sponsorship Inflows","Income Generating Projects","Other Inflows","Excess"] self.fields['category'] = category = AutocompleteBox(upperRight.interior,label="Category",toolTip="[Council Mandated Funds]: All fees, commissions and revenues that the council body is authorized to collect among students and all businesses within the college\n[General Sponsorhip Inflows]: Cash inflows acquired gratuitously from business organizations, studentry/alumni body and other entities\n[Income Generating Projects]: Cash inflows from all council events to raise revenues and generate additional funds supplementary to its operations\n[Other Inflows]: Cash inflows other than council mandated funds, general sponsoships and income generating projects") category.initDropDown(options) self.fields['nature']=nature = AutocompleteBox(upperRight.interior,label="Nature",toolTip=None) nature.initComboBox(self.app.listOptions("Nature")) self.fields['amount'] = TextFieldBox(upperRight.interior,label="Amount",readonly=False,height=1,textType="number") self.fields['payor'] = AutocompleteBox(upperRight.interior,label="Payor's Name",toolTip = "Name of the individual who actually gave the cash.") self.fields['payor'].initComboBox(self.app.listOptions("CR_Payor")) self.fields['receiptNumber'] = TextFieldBox(upperRight.interior,label="Acknowledgement Receipt #",readonly=False) self.fields['notes'] = TextFieldBox(upperRight.interior,label="Notes",toolTip = "Any additional notes about the transaction.") self.fields['remarks'] = TextFieldBox(upperRight.interior,label="Remarks",readonly=True) for i in self.fields: self.fields[i].bind("<Return>",self.save) self.fields[i].pack(side=TOP,fill=X,expand=1)
class CashDisbursmentsWindow(Frame,object): def __init__(self,parent,app,deletedVar): Frame.__init__(self,parent) self.selectedpk="New" self.parent=parent self.app=app self.deletedVar=deletedVar self.deletedVar.trace("w",self.populateTree) s = Style() s.configure("NEWBUTTON.TButton",background="green") s.configure("SAVEButton.TButton",background="blue") self.initUI() self.initTree() self.initTotalTag() self.initSaveDelete() self.initFields() self.populateTree() def initUI(self): #portable p = Panedwindow(self.parent,orient=HORIZONTAL) leftFrame = LabelFrame(p) rightFrame = LabelFrame(p) p.add(leftFrame,weight=60) p.add(rightFrame,weight=40) p.pack(fill=BOTH,expand=1) p.pack_propagate(0) leftFrame.pack_propagate(0) rightFrame.pack_propagate(0) self.saveFrame = saveFrame = Frame(leftFrame) self.treeFrame = treeFrame = Frame(leftFrame) self.xScrollFrame = xScrollFrame = Frame(leftFrame) self.totalFrame = totalFrame = Frame(leftFrame) saveFrame.pack(expand=0,fill=X,side=TOP) totalFrame.pack(expand=0,fill=X,side=BOTTOM) xScrollFrame.pack(expand=0,fill=X,side=BOTTOM) treeFrame.pack(expand=1,fill=BOTH,side=TOP) self.saveDeleteFrame = Frame(rightFrame) self.fieldsFrame = VerticalScrolledFrame(rightFrame) self.saveDeleteFrame.pack(expand=0,fill=X,side=BOTTOM) self.fieldsFrame.pack(expand=1,fill=BOTH,side=TOP) self.generateNewButton() def generateNewButton(self): newButton=Button(self.saveFrame,text="New",style="NEWButton.TButton",command=self.newButtonCallback) newButton.pack(expand=0,fill=None,side=LEFT) def initTree(self): #nonportable self.tree = tree = Treeview(self.treeFrame,selectmode="browse") tree.bind("<<TreeviewSelect>>",self.getSelection) yscroll = Scrollbar(self.treeFrame,orient="vertical",command=tree.yview) xscroll = Scrollbar(self.xScrollFrame,orient="horizontal",command=tree.xview) self.colList = colList = ["Timestamp","Date of Transaction","Category","Event", "Purpose","Nature","Amount","Liquidating Person/Payee","Document #","Notes","Remarks"] tree['columns']=colList for i in colList: tree.heading(i,text=i,command=lambda _i=i:treeview_sort_column(tree,_i,False)) tree.column(i,anchor=W,width=60) tree.column("#0",width=3,anchor=W) if "Amount" in colList: tree.column("Amount",anchor=E) tree.configure(yscroll=yscroll.set,xscroll=xscroll.set) yscroll.pack(side=RIGHT,fill=Y,expand=0) xscroll.pack(side=TOP,fill=X,expand=0) tree.pack(side=LEFT,fill=BOTH,expand=1) tree.tag_configure("deleted",foreground="red") tree.tag_configure("edited",foreground="orange") def initTotalTag(self): #portable,optional self.totalLabel = totalLabel = Label(self.totalFrame,text="Total Cash Disbursements: ",relief=SUNKEN,width=50) totalLabel.pack(fill=None,expand=0,side=RIGHT) def initSaveDelete(self): #portable saveButton=Button(self.saveDeleteFrame,text="Save",command=self.save, style="SAVEButton.TButton") saveButton.pack(side=LEFT,fill=X,expand=1) deleteButton=Button(self.saveDeleteFrame,text="Delete",command=self.delete) deleteButton.pack(side=LEFT,fill=X,expand=1) def initFields(self): #nonportable self.fields={} self.fields['timestamp']=TextFieldBox(self.fieldsFrame.interior, label="Timestamp",readonly=True,height=1) self.fields['dateOfTransaction']=CalendarBox(self.fieldsFrame.interior, label="Date of Transaction") self.fields['dateOfTransaction'].pack(side=TOP,fill=X,expand=1) #patchin get from DB here options=['Council and Other Projects','Operation and Maintenance Expenses','Long Term Investments','Other Outflows'] self.fields['category']=AutocompleteBox(self.fieldsFrame.interior, label="Category",toolTip="[Council and Other Projects]: Cash outflows from all projects undertaken by the council.\n[Operation and Maintenance Expenses]: Cash outflows from recurring expenses of operation and upkeep of the council.\n[Long Term Investments]: Cash outflows for assets intended for use and ownership beyond the current academic year.\n[Other Outflows]: Cash outflows other than those incurred for council projects, operations and maintenance and long term investments") self.fields['category'].initDropDown(options) self.fields['event']=AutocompleteBox(self.fieldsFrame.interior, label="Event",toolTip="Specify event if applicable.") self.fields['event'].initComboBox(self.app.listOptions("CD_Event")) self.fields['purpose']=TextFieldBox(self.fieldsFrame.interior, label="Purpose",toolTip="What the cash was used for.") self.fields['nature']=AutocompleteBox(self.fieldsFrame.interior, label="Nature",toolTip=None) self.fields['nature'].initComboBox(self.app.listOptions("CD_Nature")) self.fields['amount'] = TextFieldBox(self.fieldsFrame.interior, label="Amount",readonly=False,height=1,textType="number", toolTip="Actual amount given to liquidating person/payee regardless if actual expenditure differs") self.fields['liquidatingPerson'] = AutocompleteBox(self.fieldsFrame.interior, label="Liquidating Person/Payee",toolTip="Name of the individual who actually received the cash.") self.fields['liquidatingPerson'].initComboBox(self.app.listOptions("CD_Payee")) self.fields['docNo'] = TextFieldBox(self.fieldsFrame.interior, label="Document Number",toolTip="Put all receipt numbers here, if any. If cash is disbursed before the expenditure, indicate in the notes column that this is so.") self.fields['notes'] = TextFieldBox(self.fieldsFrame.interior, label="Notes",toolTip="Any additional notes.") self.fields['remarks'] = TextFieldBox(self.fieldsFrame.interior, label="Remarks",readonly=True) for i in self.fields: self.fields[i].bind("<Return>",self.save) self.fields[i].pack(side=TOP,fill=X,expand=1) def newButtonCallback(self): #portable dummyEntry=newExistsInTree(self.tree) if not dummyEntry: dummyEntry=self.tree.insert("","end",text="New",values=["" for i in self.colList]) else: dummyEntry=dummyEntry[0] self.tree.selection_set(dummyEntry) self.selectedpk="New" def getSelection(self,event): #semiportable -> must have dateOfTransaction item=self.tree.selection()[0] values=self.tree.item(item,'values') for i in range(0,len(self.fieldList)): self.fields[self.fieldList[i]].text=values[i] if self.fields['dateOfTransaction'].text=="": self.fields['dateOfTransaction'].text=secsToDay(getEpochTime()) self.selectedpk=self.tree.item(item,"text") def _populateTree(self,entryList): #semiportable -> doesn't work if no total total=0 [self.tree.delete(item) for item in self.tree.get_children()] for i in entryList: dataFields=[] pk=i.pk.content try: amt=float(i.amount.content) except: amt=0 if i.status.content!="DELETED": total+=amt for j in self.fieldList: dataFields.append(vars(i)[j].content) dataFields[0]=secsToString(dataFields[0]) dataFields[1]=secsToDay(dataFields[1]) if 'amount' in self.fieldList: dataFields[self.fieldList.index('amount')]=floatToStr(dataFields[self.fieldList.index('amount')]) if i.status.content=="DELETED": self.tree.insert("","end",text=str(pk),values=dataFields,tags=("deleted",)) elif i.status.content=="EDITED": self.tree.insert("","end",text=str(pk),values=dataFields,tags=("edited",)) else: self.tree.insert("","end",text=str(pk),values=dataFields,tags=("none",)) self.totalLabel.config(text="Total Cash Disbursments: "+floatToStr(total)) self.total=total def populateTree(self,*a): #nonportable self.fieldList=['timestamp','dateOfTransaction','category', 'event','purpose','nature','amount','liquidatingPerson', 'docNo','notes','remarks'] showDeleted = self.deletedVar.get() self._populateTree(self.app.listCashDisbursments(showDeleted=showDeleted)) def exportToExcel(self): """Exports the data displayed on the treebox to excel""" excelBuilder = ExcelBuilder() self.addSheet(excelBuilder) excelBuilder.build() def addSheet(self, excelBuilder): rows = [(self.tree.item(i,"values"), self.tree.item(i, "tags")) for i in self.tree.get_children()] columnHeaders = self.colList fileName = 'CashDisbursements_' + datetime.datetime.now().strftime("%I%M%p_%B%d_%Y") + '.xls' excelBuilder.setRows(rows) excelBuilder.setColumnHeaders(columnHeaders) excelBuilder.setStartingPoint(2, 0) excelBuilder.setFileName(fileName) excelBuilder.setTableColumnWidth(5000) excelBuilder.setSheetName("Cash Disbursements") excelBuilder.buildSheet() def save(self,*a): #nonportable if checkFields(self.fields): return 1 if self.selectedpk!="New": self.selectedpk = self.app.editCashDisbursment(self.selectedpk, dateOfTransaction=stringToSecs(self.fields['dateOfTransaction'].text+":0:0:0"), category=self.fields['category'].text, event=self.fields['event'].text, purpose=self.fields['purpose'].text, nature=self.fields['nature'].text, amount=(self.fields['amount'].text), liquidatingPerson=self.fields['liquidatingPerson'].text, docNo=self.fields['docNo'].text, notes=self.fields['notes'].text) else: self.selectedpk=self.app.newCashDisbursment(dateOfTransaction=stringToSecs(self.fields['dateOfTransaction'].text+":0:0:0"), category=self.fields['category'].text, event=self.fields['event'].text, purpose=self.fields['purpose'].text, nature=self.fields['nature'].text, amount=(self.fields['amount'].text), liquidatingPerson=self.fields['liquidatingPerson'].text, docNo=self.fields['docNo'].text, notes=self.fields['notes'].text) self.populateTree() self.app.addOption("CD_Nature",self.fields['nature'].text) self.fields['nature'].comboBox.config(values=self.app.listOptions("CD_Nature")) self.app.addOption("CD_Event",self.fields['event'].text) self.app.addOption("CD_Payee",self.fields['liquidatingPerson'].text) self.fields['event'].comboBox.config(values=self.app.listOptions("CD_Event")) self.fields['liquidatingPerson'].comboBox.config(values=self.app.listOptions("CD_Payee")) self.newButtonCallback() def delete(self): #nonportable if self.selectedpk!="New": self.app.deleteCashDisbursment(self.selectedpk) self.populateTree()
def initUI(self): p = Panedwindow(self.parent, orient=HORIZONTAL) leftFrame = LabelFrame(p) rightFrame = LabelFrame(p) p.add(leftFrame, weight=60) p.add(rightFrame, weight=40) p.pack(fill=BOTH, expand=1) p.pack_propagate(0) leftFrame.pack_propagate(0) rightFrame.pack_propagate(0) #leftFrame elements leftFrameUpperest = Frame(leftFrame) leftFrameUpper = Frame(leftFrame) leftFrameLower = Frame(leftFrame) leftFrameLower.pack(expand=0, fill=X, side=BOTTOM) leftFrameUpperest.pack(expand=0, fill=X, side=TOP) leftFrameUpper.pack(expand=1, fill=BOTH, side=BOTTOM) newButton = Button(leftFrameUpperest, text="New", command=self.newEntry, style="NEWButton.TButton") newButton.pack(fill=None, expand=0, side=LEFT) self.tree = tree = Treeview(leftFrameUpper, selectmode="browse") tree.bind("<<TreeviewSelect>>", self.getSelection) yscroll = Scrollbar(leftFrameUpper, orient="vertical", command=tree.yview) xscroll = Scrollbar(leftFrameLower, orient="horizontal", command=tree.xview) colList = [ "Timestamp", "Date of Transaction", "Category", "Nature", "Amount", "Payor's Name", "Acknowledgement Receipt #", "Notes", "Remarks" ] tree['columns'] = colList for col in colList: tree.heading(col,text=col,command=lambda _col=col: \ treeview_sort_column(tree,_col,False)) tree.column(col, anchor=W, width=60) tree.column('#0', width=3, anchor=W) if "Amount" in colList: tree.column("Amount", anchor=E) tree.configure(yscroll=yscroll.set, xscroll=xscroll.set) yscroll.pack(side=RIGHT, fill=Y) xscroll.pack(side=TOP, fill=X) tree.pack(side=LEFT, fill=BOTH, expand=1) tree.tag_configure("deleted", foreground="red") tree.tag_configure("edited", foreground="orange") #bottombar leftLowestFrame = Frame(leftFrameLower) leftLowestFrame.pack(fill=X, expand=0) self.totalLabel = totalLabel = Label(leftLowestFrame, text="Total Cash Receipts: ", relief=SUNKEN, width=50) totalLabel.pack(fill=None, expand=0, side=RIGHT) #populateTree #testing. Remove later for actual data self.fieldList = [ 'timestamp', 'dateOfTransaction', 'category', 'nature', 'amount', 'payor', 'receiptNumber', 'notes', 'remarks' ] self.populateTree() #rightFrame upperRight = VerticalScrolledFrame(rightFrame) lowerRight = Frame(rightFrame) lowerRight.pack(fill=X, expand=0, side=BOTTOM) upperRight.pack(fill=BOTH, expand=1, side=TOP) saveButton = Button(lowerRight, text="Save", command=self.save, style="SAVEButton.TButton") saveButton.pack(side=LEFT, fill=X, expand=1) deleteButton = Button(lowerRight, text="Delete", command=self.delete) deleteButton.pack(side=LEFT, fill=X, expand=1) #fields self.fields = {} self.fields['timestamp'] = timestamp = TextFieldBox( upperRight.interior, label="Timestamp", readonly=True, height=1) self.fields['dateOfTransaction'] = dot = CalendarBox( upperRight.interior, label="Date of Transaction") dot.pack(side=TOP, fill=X, expand=1) #options for removal, get from DB options = [ "Council Mandated Funds", "General Sponsorship Inflows", "Income Generating Projects", "Other Inflows", "Excess" ] self.fields['category'] = category = AutocompleteBox( upperRight.interior, label="Category", toolTip= "[Council Mandated Funds]: All fees, commissions and revenues that the council body is authorized to collect among students and all businesses within the college\n[General Sponsorhip Inflows]: Cash inflows acquired gratuitously from business organizations, studentry/alumni body and other entities\n[Income Generating Projects]: Cash inflows from all council events to raise revenues and generate additional funds supplementary to its operations\n[Other Inflows]: Cash inflows other than council mandated funds, general sponsoships and income generating projects" ) category.initDropDown(options) self.fields['nature'] = nature = AutocompleteBox(upperRight.interior, label="Nature", toolTip=None) nature.initComboBox(self.app.listOptions("Nature")) self.fields['amount'] = TextFieldBox(upperRight.interior, label="Amount", readonly=False, height=1, textType="number") self.fields['payor'] = AutocompleteBox( upperRight.interior, label="Payor's Name", toolTip="Name of the individual who actually gave the cash.") self.fields['payor'].initComboBox(self.app.listOptions("CR_Payor")) self.fields['receiptNumber'] = TextFieldBox( upperRight.interior, label="Acknowledgement Receipt #", readonly=False) self.fields['notes'] = TextFieldBox( upperRight.interior, label="Notes", toolTip="Any additional notes about the transaction.") self.fields['remarks'] = TextFieldBox(upperRight.interior, label="Remarks", readonly=True) for i in self.fields: self.fields[i].bind("<Return>", self.save) self.fields[i].pack(side=TOP, fill=X, expand=1)
class CashDisbursmentsWindow(Frame, object): def __init__(self, parent, app, deletedVar): Frame.__init__(self, parent) self.selectedpk = "New" self.parent = parent self.app = app self.deletedVar = deletedVar self.deletedVar.trace("w", self.populateTree) s = Style() s.configure("NEWBUTTON.TButton", background="green") s.configure("SAVEButton.TButton", background="blue") self.initUI() self.initTree() self.initTotalTag() self.initSaveDelete() self.initFields() self.populateTree() def initUI(self): #portable p = Panedwindow(self.parent, orient=HORIZONTAL) leftFrame = LabelFrame(p) rightFrame = LabelFrame(p) p.add(leftFrame, weight=60) p.add(rightFrame, weight=40) p.pack(fill=BOTH, expand=1) p.pack_propagate(0) leftFrame.pack_propagate(0) rightFrame.pack_propagate(0) self.saveFrame = saveFrame = Frame(leftFrame) self.treeFrame = treeFrame = Frame(leftFrame) self.xScrollFrame = xScrollFrame = Frame(leftFrame) self.totalFrame = totalFrame = Frame(leftFrame) saveFrame.pack(expand=0, fill=X, side=TOP) totalFrame.pack(expand=0, fill=X, side=BOTTOM) xScrollFrame.pack(expand=0, fill=X, side=BOTTOM) treeFrame.pack(expand=1, fill=BOTH, side=TOP) self.saveDeleteFrame = Frame(rightFrame) self.fieldsFrame = VerticalScrolledFrame(rightFrame) self.saveDeleteFrame.pack(expand=0, fill=X, side=BOTTOM) self.fieldsFrame.pack(expand=1, fill=BOTH, side=TOP) self.generateNewButton() def generateNewButton(self): newButton = Button(self.saveFrame, text="New", style="NEWButton.TButton", command=self.newButtonCallback) newButton.pack(expand=0, fill=None, side=LEFT) def initTree(self): #nonportable self.tree = tree = Treeview(self.treeFrame, selectmode="browse") tree.bind("<<TreeviewSelect>>", self.getSelection) yscroll = Scrollbar(self.treeFrame, orient="vertical", command=tree.yview) xscroll = Scrollbar(self.xScrollFrame, orient="horizontal", command=tree.xview) self.colList = colList = [ "Timestamp", "Date of Transaction", "Category", "Event", "Purpose", "Nature", "Amount", "Liquidating Person/Payee", "Document #", "Notes", "Remarks" ] tree['columns'] = colList for i in colList: tree.heading( i, text=i, command=lambda _i=i: treeview_sort_column(tree, _i, False)) tree.column(i, anchor=W, width=60) tree.column("#0", width=3, anchor=W) if "Amount" in colList: tree.column("Amount", anchor=E) tree.configure(yscroll=yscroll.set, xscroll=xscroll.set) yscroll.pack(side=RIGHT, fill=Y, expand=0) xscroll.pack(side=TOP, fill=X, expand=0) tree.pack(side=LEFT, fill=BOTH, expand=1) tree.tag_configure("deleted", foreground="red") tree.tag_configure("edited", foreground="orange") def initTotalTag(self): #portable,optional self.totalLabel = totalLabel = Label(self.totalFrame, text="Total Cash Disbursements: ", relief=SUNKEN, width=50) totalLabel.pack(fill=None, expand=0, side=RIGHT) def initSaveDelete(self): #portable saveButton = Button(self.saveDeleteFrame, text="Save", command=self.save, style="SAVEButton.TButton") saveButton.pack(side=LEFT, fill=X, expand=1) deleteButton = Button(self.saveDeleteFrame, text="Delete", command=self.delete) deleteButton.pack(side=LEFT, fill=X, expand=1) def initFields(self): #nonportable self.fields = {} self.fields['timestamp'] = TextFieldBox(self.fieldsFrame.interior, label="Timestamp", readonly=True, height=1) self.fields['dateOfTransaction'] = CalendarBox( self.fieldsFrame.interior, label="Date of Transaction") self.fields['dateOfTransaction'].pack(side=TOP, fill=X, expand=1) #patchin get from DB here options = [ 'Council and Other Projects', 'Operation and Maintenance Expenses', 'Long Term Investments', 'Other Outflows' ] self.fields['category'] = AutocompleteBox( self.fieldsFrame.interior, label="Category", toolTip= "[Council and Other Projects]: Cash outflows from all projects undertaken by the council.\n[Operation and Maintenance Expenses]: Cash outflows from recurring expenses of operation and upkeep of the council.\n[Long Term Investments]: Cash outflows for assets intended for use and ownership beyond the current academic year.\n[Other Outflows]: Cash outflows other than those incurred for council projects, operations and maintenance and long term investments" ) self.fields['category'].initDropDown(options) self.fields['event'] = AutocompleteBox( self.fieldsFrame.interior, label="Event", toolTip="Specify event if applicable.") self.fields['event'].initComboBox(self.app.listOptions("CD_Event")) self.fields['purpose'] = TextFieldBox( self.fieldsFrame.interior, label="Purpose", toolTip="What the cash was used for.") self.fields['nature'] = AutocompleteBox(self.fieldsFrame.interior, label="Nature", toolTip=None) self.fields['nature'].initComboBox(self.app.listOptions("CD_Nature")) self.fields['amount'] = TextFieldBox( self.fieldsFrame.interior, label="Amount", readonly=False, height=1, textType="number", toolTip= "Actual amount given to liquidating person/payee regardless if actual expenditure differs" ) self.fields['liquidatingPerson'] = AutocompleteBox( self.fieldsFrame.interior, label="Liquidating Person/Payee", toolTip="Name of the individual who actually received the cash.") self.fields['liquidatingPerson'].initComboBox( self.app.listOptions("CD_Payee")) self.fields['docNo'] = TextFieldBox( self.fieldsFrame.interior, label="Document Number", toolTip= "Put all receipt numbers here, if any. If cash is disbursed before the expenditure, indicate in the notes column that this is so." ) self.fields['notes'] = TextFieldBox(self.fieldsFrame.interior, label="Notes", toolTip="Any additional notes.") self.fields['remarks'] = TextFieldBox(self.fieldsFrame.interior, label="Remarks", readonly=True) for i in self.fields: self.fields[i].bind("<Return>", self.save) self.fields[i].pack(side=TOP, fill=X, expand=1) def newButtonCallback(self): #portable dummyEntry = newExistsInTree(self.tree) if not dummyEntry: dummyEntry = self.tree.insert("", "end", text="New", values=["" for i in self.colList]) else: dummyEntry = dummyEntry[0] self.tree.selection_set(dummyEntry) self.selectedpk = "New" def getSelection(self, event): #semiportable -> must have dateOfTransaction item = self.tree.selection()[0] values = self.tree.item(item, 'values') for i in range(0, len(self.fieldList)): self.fields[self.fieldList[i]].text = values[i] if self.fields['dateOfTransaction'].text == "": self.fields['dateOfTransaction'].text = secsToDay(getEpochTime()) self.selectedpk = self.tree.item(item, "text") def _populateTree(self, entryList): #semiportable -> doesn't work if no total total = 0 [self.tree.delete(item) for item in self.tree.get_children()] for i in entryList: dataFields = [] pk = i.pk.content try: amt = float(i.amount.content) except: amt = 0 if i.status.content != "DELETED": total += amt for j in self.fieldList: dataFields.append(vars(i)[j].content) dataFields[0] = secsToString(dataFields[0]) dataFields[1] = secsToDay(dataFields[1]) if 'amount' in self.fieldList: dataFields[self.fieldList.index('amount')] = floatToStr( dataFields[self.fieldList.index('amount')]) if i.status.content == "DELETED": self.tree.insert("", "end", text=str(pk), values=dataFields, tags=("deleted", )) elif i.status.content == "EDITED": self.tree.insert("", "end", text=str(pk), values=dataFields, tags=("edited", )) else: self.tree.insert("", "end", text=str(pk), values=dataFields, tags=("none", )) self.totalLabel.config(text="Total Cash Disbursments: " + floatToStr(total)) self.total = total def populateTree(self, *a): #nonportable self.fieldList = [ 'timestamp', 'dateOfTransaction', 'category', 'event', 'purpose', 'nature', 'amount', 'liquidatingPerson', 'docNo', 'notes', 'remarks' ] showDeleted = self.deletedVar.get() self._populateTree( self.app.listCashDisbursments(showDeleted=showDeleted)) def exportToExcel(self): """Exports the data displayed on the treebox to excel""" excelBuilder = ExcelBuilder() self.addSheet(excelBuilder) excelBuilder.build() def addSheet(self, excelBuilder): rows = [(self.tree.item(i, "values"), self.tree.item(i, "tags")) for i in self.tree.get_children()] columnHeaders = self.colList fileName = 'CashDisbursements_' + datetime.datetime.now().strftime( "%I%M%p_%B%d_%Y") + '.xls' excelBuilder.setRows(rows) excelBuilder.setColumnHeaders(columnHeaders) excelBuilder.setStartingPoint(2, 0) excelBuilder.setFileName(fileName) excelBuilder.setTableColumnWidth(5000) excelBuilder.setSheetName("Cash Disbursements") excelBuilder.buildSheet() def save(self, *a): #nonportable if checkFields(self.fields): return 1 if self.selectedpk != "New": self.selectedpk = self.app.editCashDisbursment( self.selectedpk, dateOfTransaction=stringToSecs( self.fields['dateOfTransaction'].text + ":0:0:0"), category=self.fields['category'].text, event=self.fields['event'].text, purpose=self.fields['purpose'].text, nature=self.fields['nature'].text, amount=(self.fields['amount'].text), liquidatingPerson=self.fields['liquidatingPerson'].text, docNo=self.fields['docNo'].text, notes=self.fields['notes'].text) else: self.selectedpk = self.app.newCashDisbursment( dateOfTransaction=stringToSecs( self.fields['dateOfTransaction'].text + ":0:0:0"), category=self.fields['category'].text, event=self.fields['event'].text, purpose=self.fields['purpose'].text, nature=self.fields['nature'].text, amount=(self.fields['amount'].text), liquidatingPerson=self.fields['liquidatingPerson'].text, docNo=self.fields['docNo'].text, notes=self.fields['notes'].text) self.populateTree() self.app.addOption("CD_Nature", self.fields['nature'].text) self.fields['nature'].comboBox.config( values=self.app.listOptions("CD_Nature")) self.app.addOption("CD_Event", self.fields['event'].text) self.app.addOption("CD_Payee", self.fields['liquidatingPerson'].text) self.fields['event'].comboBox.config( values=self.app.listOptions("CD_Event")) self.fields['liquidatingPerson'].comboBox.config( values=self.app.listOptions("CD_Payee")) self.newButtonCallback() def delete(self): #nonportable if self.selectedpk != "New": self.app.deleteCashDisbursment(self.selectedpk) self.populateTree()
class StatementWindow(Frame, object): def __init__(self, parent, app, deletedVar, **kwargs): Frame.__init__(self, parent, **kwargs) self.app = app self.parent = parent self.initUI() def initUI(self): self.printFrame = Frame(self) self.printFrame.pack(fill=X, expand=0, side=TOP) self.printButton = Button(self.printFrame, text="Export to docx", command=self.exportCallback) self.printButton.pack(fill=NONE, expand=0, side=LEFT) self.mainFrame = VerticalScrolledFrame(self) self.mainFrame.pack(fill=BOTH, expand=1, side=TOP) self.headerField = Text(self.mainFrame.interior, bd=0, width=0, state='disabled', height=3) self.headerField.tag_configure("center", justify="center") self.boldFont = f = Font(self.headerField, self.headerField.cget('font')) f.configure(weight='bold') self.headerField.configure(font=f) self.headerField.pack(fill=X, expand=0, side=TOP) self.cashFlowsText = TextTable( self.mainFrame.interior, aligns=['left', 'left', 'right', 'right', 'right', 'right'], weights=[4, 4, 1, 1, 1, 1], width=500) self.cashFlowsText.pack(expand=1, fill=BOTH, side=TOP) self.oalText = Text(self.mainFrame.interior, bd=0, width=0, state='disabled', height=0) self.oalText.tag_configure("bold", font=f) self.oalText.pack(fill=X, expand=0, side=TOP) self.noteChunk = NoteChunk(self.mainFrame.interior, self.app) self.noteChunk.pack(fill=BOTH, expand=1, side=TOP) self.noteBlocks = self.noteChunk.noteBlocks def populateTree(self): tStart = secsToDay(self.app.timeFrame[0]).split("-") sYear = tStart[0] sDay = tStart[2] sMonth = MONTHS[int(tStart[1])] tStart = str(sMonth) + " " + str(sDay) + ", " + str(sYear) tEnd = secsToDay(self.app.timeFrame[-1]).split("-") month = MONTHS[int(tEnd[1])] year = tEnd[0] day = tEnd[2] self.lines = [] self.headerField['state'] = 'normal' self.headerField.delete('1.0', 'end') self.headerField.insert( '1.0', self.app.councilName + "\nStatement of Cash Flows\nFor the Semester Ended " + month + " " + day + ", " + year) self.headerField.tag_add('center', '1.0', 'end') #self.headerField['state']='disabled' self.lines.append([['CASH INFLOWS', 'Note', '', '', '', ''], [], [1, 0, 0, 0, 0, 0]]) cashFlowList = self.app.listCashflows(showDeleted=False) inflowList = [ i for i in cashFlowList if i.source.content.split(":")[0] == "CashReceipt" ] totalInflows = 0 self.firstInflow = 0 self.firstInflowTotal = 0 self.lineTypes = "Inflow" #replace with db stuff inflowTypeList = [ 'Council Mandated Funds', 'General Sponsorship Inflows', 'Income Generating Projects', 'Other Inflows' ] for inflowType in inflowTypeList: partialList = filterDOT(self.app, [ i for i in inflowList if i.getContents().category.content == inflowType ]) lines, partialTotal = self.getInflows(partialList) if lines != []: self.lines.append([[inflowType, '', '', '', '', ''], [], []]) self.lines = self.lines + lines totalInflows += partialTotal self.firstInflow = 0 self.firstInflowTotal = 0 self.lineTypes = "Outflow" self.lines.append([[ tab(3) + "Total Inflows", '', '', '', 'P', floatToStr(totalInflows) ], [0, 0, 0, 0, 0, 1], []]) self.lines.append([["", '', '', '', '', ''], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) self.lines.append([['CASH OUTFLOWS', '', '', '', '', ''], [], [1, 0, 0, 0, 0, 0]]) outflowList = [ i for i in cashFlowList if i.source.content.split(":")[0] in ("OME", "COCPNote", "LTINote", "OONote") ] totalOutflows = 0 self.firstOutflow = 0 self.firstOutflowTotal = 0 outflowNames = { "COCPNote": "Council and Other College Projects", "LTINote": "Long Term Investment", "OME": "Operation and Maintenance Expenses", "OONote": "Other Outflows" } for outflowType in ("COCPNote", "LTINote", "OME", "OONote"): partialList = filterDOT(self.app, [ i for i in outflowList if i.source.content.split(":")[0] == outflowType ]) lines, partialTotal = self.getInflows(partialList) if lines != []: self.lines.append( [[outflowNames[outflowType], '', '', '', '', ''], [], []]) self.lines = self.lines + lines totalOutflows += partialTotal self.lines.append([[ tab(3) + "Total Outflows", '', '', '', 'P', "(" + floatToStr(totalOutflows) + ")" ], [0, 0, 0, 0, 0, 1], []]) self.lines = self.setUnderlines(self.lines) totalFlows = totalInflows - totalOutflows strTotalFlows = floatToStrParenNeg(totalFlows) self.lines.append([["Net Cash Flow", '', '', '', '', strTotalFlows], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]]) #beginning balance filler beginningBalance = getStartBalance(self.app, int(self.app.timeFrame[0])) self.lines.append([[ "Add: Beginning Cash Balance, " + tStart, '', '', '', '', floatToStr(beginningBalance) ], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0]]) self.lines.append([[ "Ending Cash Balance, " + month + " " + day + ", " + year, '', '', '', '', floatToStrParenNeg(beginningBalance + totalFlows) ], [0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0]]) self.lines.append([["", '', '', '', '', ''], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) self.lines.append([["Cash Breakdown", '', '', '', '', ''], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]]) self.lines.append( [['Cash on hand', '', '', '', '', self.app.cashOnHand], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) self.lines.append( [['Cash in bank', '', '', '', '', self.app.cashInBank], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) totalBalance = floatToStr( strToFloat(self.app.cashOnHand) + strToFloat(self.app.cashInBank)) self.lines.append([[ 'Cash Balance, ' + month + ' ' + day + ', ' + year, '', '', '', '', totalBalance ], [0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0]]) self.commitLines(self.lines) self.popOAL() self.noteChunk.update() self.noteBlocks = self.noteChunk.noteBlocks print self.noteBlocks def getInflows(self, flowList): partialTotals = {} totalInflows = 0 for i in flowList: name = i.getContents().nature.content amount = i.getContents().amount.content notes = i.note.content category = i.source.content.split(":")[0] if category == "COCPNote": name = i.getContents().event.content try: amount = float(amount) except: amount = 0 totalInflows += amount if name in partialTotals: partialTotals[name][0] += amount else: partialTotals[name] = [amount] partialTotals[name].append(notes) newLines = self.writeLinesPartial(partialTotals) return newLines, totalInflows def writeLinesPartial(self, partialTotalsList): total = 0 partialTotalsKeys = partialTotalsList.keys() partialTotalsKeys.sort() tempLines = [] for i in partialTotalsKeys: name = i amount = partialTotalsList[i][0] notes = partialTotalsList[i][1] total += amount tempLines.append( [[tab() + name, notes, '', floatToStr(amount), '', ''], [], []]) if tempLines: if not self.firstInflow: tempLines[0][0][2] = "P" self.firstInflow = 1 tempLines.append( [[tab(2) + "Total", '', '', '', '', floatToStr(total)], [0, 0, 0, 0, 0, 0], []]) if self.lineTypes == "Outflow": tempLines[-1][0][-1] = "(" + tempLines[-1][0][-1] + ")" if not self.firstInflowTotal: self.firstInflowTotal = 1 tempLines[-1][0][4] = "P" return tempLines def commitLines(self, lines): self.cashFlowsText.clear() for i in lines: self.cashFlowsText.addRow(i[0], uls=i[1], bolds=i[2]) def setUnderlines(self, lines): for i in range(0, len(lines)): if lines[i][0][0] == tab(2) + "Total": lines[i - 1][1] = [0, 0, 0, 1, 0, 0] if lines[i][0][0] == tab(3) + "Total Inflows" or lines[i][0][ 0] == tab(3) + "Total Outflows": lines[i - 1][1] = [0, 0, 0, 0, 0, 1] return lines def popOAL(self): oalInfo = getOAL(self.app) self.oalText['state'] = 'normal' self.oalText.delete('1.0', 'end') if oalInfo != "": self.oalText.insert(self.oalText.index("end"), "\nOTHER ASSETS AND LIABILITIES\n") self.oalText.tag_add("bold", '1.0', 'end -1 line lineend') self.oalText.insert(self.oalText.index("end"), oalInfo) self.oalText.configure( height=int(self.oalText.index('end-1c').split('.')[0]) + 3) self.oalText['state'] = 'disabled' def exportCallback(self): docBuilder = DocBuilder() # Write the 1st line of the header (council name) headerText = self.headerField.get(1.0, "1.end") docBuilder.createParagraph(headerText, "center", bold=True) # Write the 2nd line of the header (statement of cash flows) headerText = self.headerField.get(2.0, "2.end") docBuilder.createParagraph(headerText, "center", bold=True) # Write the 3rd line of the header (semester) headerText = self.headerField.get(3.0, "3.end") docBuilder.createParagraph(headerText, "center", bold=True) # Write the cash flows table self._export_CreateTable(self.lines, docBuilder) # Add some line breaks docBuilder.document.add_paragraph() # Write the OAL oalText = self.oalText.get(1.0, END) oalText = oalText.split("\n") docBuilder.document.add_paragraph().add_run(oalText[1]).bold = True for x in xrange(2, len(oalText)): docBuilder.document.add_paragraph(oalText[x]) # Write the Notes header docBuilder.document.add_paragraph().add_run( "NOTES TO FINANCIAL STATEMENT").bold = True # Write the Notes data for noteBlock in self.noteBlocks: if noteBlock.blockType == "text": # Write the heading newParagraph = docBuilder.document.add_paragraph() newParagraph.add_run(noteBlock.payload[0]).bold = True # Write the non-heading text textData = noteBlock.payload[1].split("\n") for line in textData: docBuilder.document.add_paragraph(line) elif noteBlock.blockType == "table": self._export_CreateTable(noteBlock.payload, docBuilder, 5) # Line break docBuilder.document.add_paragraph() # Write the statement of accountability docBuilder.document.add_paragraph().add_run( "STATEMENT OF FINANCE COUNCILOR'S ACCOUNTABILITY").bold = True docBuilder.document.add_paragraph( """"I am hereunto affirming that to the best of my intentions, the Statement of Cash Flows and all its pertinent information fairly represent all the financial transactions that have transpired within the council, its constituents, and all relevant stakeholders for the semester ending (date), and in conformity with the standard accounting procedures as set forth and duly upheld by the University Student Council of UP Diliman." """ ) # Line break docBuilder.document.add_paragraph() docBuilder.document.add_paragraph() docBuilder.document.add_paragraph() # Write the signatures preparedBy = self.app.preparedBy.split("\n") notedBy = self.app.notedBy.split("\n") while len(preparedBy) < 3: preparedBy.append("") while len(notedBy) < 3: notedBy.append("") tableData = [] tableData.append([CellData("Prepared by:"), CellData("Noted by:")]) tableData.append([CellData(""), CellData("")]) tableData.append([CellData(""), CellData("")]) tableData.append([CellData(preparedBy[0]), CellData(notedBy[0])]) tableData.append([CellData(preparedBy[1]), CellData(notedBy[1])]) tableData.append([CellData(preparedBy[2]), CellData(notedBy[2])]) docBuilder.createTable(2, tableData) # # Add signature images # run = docBuilder.table.cell(2, 0).add_paragraph().add_run() # run.add_picture('random.png', width=Inches(1)) # Save the document fileName = 'StatementOfCashFlows_' + datetime.datetime.now().strftime( "%I%M%p_%B%d_%Y") + '.docx' docBuilder.save(fileName) def _export_CreateTable(self, lineData, docBuilder, numberOfColumns=6): """Reads self.lines and creates a docx table from it""" lines = list(lineData) # list of lists, where each entry is a list of CellData objects that represents a row tableData = [] # iterate through the rows to construct tableData for line in lines: lineText = line[0] if not line[1]: line[1] = [0] * numberOfColumns if not line[2]: line[2] = [0] * numberOfColumns isUnderlined = line[1] isBold = line[2] rowData = [] # iterate through the cells in a row to construct rowData for i in xrange(numberOfColumns): text = lineText[i] cellData = CellData(text) if (isUnderlined[i] == 1): cellData.tags.append("underline") if (isUnderlined[i] == 2): cellData.tags.append("double_underline") if (isBold[i] == 1): cellData.tags.append("bold") rowData.append(cellData) tableData.append(rowData) docBuilder.createTable(numberOfColumns, tableData) # manually set table column widths if (numberOfColumns == 6): docBuilder.columns[0].width = Inches(2.5) docBuilder.columns[1].width = Inches(1) docBuilder.columns[2].width = Inches(0.25) docBuilder.columns[3].width = Inches(1) docBuilder.columns[4].width = Inches(0.25) docBuilder.columns[5].width = Inches(1) elif (numberOfColumns == 5): docBuilder.columns[0].width = Inches(3.5) docBuilder.columns[1].width = Inches(0.25) docBuilder.columns[2].width = Inches(1) docBuilder.columns[3].width = Inches(0.25) docBuilder.columns[4].width = Inches(1)