def deleteRow(self, sender): selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None : msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK_CANCEL, _("Are you sure to remove this row?")) msgbox.set_title(_("Are you sure?")) result = msgbox.run(); if result == gtk.RESPONSE_OK : debt = int(unicode(self.liststore.get(iter, 3)[0].replace(",", ""))) credit = int(unicode(self.liststore.get(iter, 4)[0].replace(",", ""))) index = int(unicode(self.liststore.get(iter, 0)[0])) res = self.liststore.remove(iter) #Update index of next rows if res: while iter != None: strindex = str(index) if config.digittype == 1: strindex = utility.convertToPersian(strindex) self.liststore.set_value (iter, 0, strindex) index += 1 iter = self.liststore.iter_next(iter) self.numrows -= 1; self.debt_sum -= debt self.credit_sum -= credit self.builder.get_object("debtsum").set_text (utility.showNumber(self.debt_sum)) self.builder.get_object("creditsum").set_text (utility.showNumber(self.credit_sum)) if self.debt_sum > self.credit_sum: diff = self.debt_sum - self.credit_sum else: diff = self.credit_sum - self.debt_sum self.builder.get_object("difference").set_text (utility.showNumber(diff)) msgbox.destroy()
def drawSubjectNotebook(self): self.pages = ((len(self.content) - 1) / (self.lines_per_page - 2) ) + 1 debtsum = 0 creditsum = 0 diagnose = "" remaining = int(self.content[0][3].replace(",", "")) - int(self.content[0][4].replace(",", "")) if self.content[0][5] == _("deb"): remaining -= int(self.content[0][6].replace(",", "")) else: remaining += int(self.content[0][6].replace(",", "")) if remaining < 0: diagnose = _("deb") sr = utility.showNumber(-(remaining)) else: if remaining == 0: diagnose = _("equ") else: diagnose = _("cre") sr = utility.showNumber(remaining) for page_nr in range(1, self.pages + 1) : temp = self.lines_per_page * page_nr self.content.insert(self.lines_per_page * (page_nr - 1), ("", "" ,_("Sum of previous page"), debtsum, creditsum, diagnose, sr)) for data in self.content[(self.lines_per_page * (page_nr - 1) + 1) : temp - 1]: debtsum += int(data[3].replace(",", "")) creditsum += int(data[4].replace(",", "")) diagnose = data[5] sr = data[6] self.content.insert(temp - 1, ("", "" ,_("Sum"), debtsum, creditsum, diagnose, sr))
def saveRow(self, code, amount, type, desc, iter=None): query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == code) sub = query.first() if sub == None: if config.digittype == 1: code = utility.convertToPersian(code) errorstr = _("No subject is registered with the code: %s") % code msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, errorstr) msgbox.set_title(_("No subjects found")) msgbox.run() msgbox.destroy() return if sub.type != 2: type = sub.type debt = "0" credit = "0" if config.digittype == 1: debt = utility.convertToPersian(debt) credit = utility.convertToPersian(credit) code = utility.convertToPersian(code) if type == 0: debt = utility.showNumber(amount) self.debt_sum += amount else: if type == 1: credit = utility.showNumber(amount) self.credit_sum += amount if iter != None: self.liststore.set(iter, 1, code, 2, sub.name, 3, debt, 4, credit, 5, desc) else: self.numrows += 1 numrows = str(self.numrows) if config.digittype == 1: numrows = utility.convertToPersian(numrows) self.liststore.append( (numrows, code, sub.name, debt, credit, desc)) self.builder.get_object("debtsum").set_text( utility.showNumber(self.debt_sum)) self.builder.get_object("creditsum").set_text( utility.showNumber(self.credit_sum)) if self.debt_sum > self.credit_sum: diff = self.debt_sum - self.credit_sum else: diff = self.credit_sum - self.debt_sum self.builder.get_object("difference").set_text( utility.showNumber(diff))
def createReport(self): report_data = [] remaining = 0 report_header = [_("Ledger name"), _("Debt"), _("Credit"), _("Remaining")] col_width = [31, 23, 23, 23] query = config.db.session.query(Subject).select_from(Subject) result = query.filter(Subject.parent_id == 0).all() query1 = config.db.session.query(sum(Notebook.value)) # Check the report parameters if self.builder.get_object("allcontent1").get_active() == True: query1 = query1.select_from(outerjoin(Subject, Notebook, Subject.id == Notebook.subject_id)) else: query1 = query1.select_from(outerjoin(outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) if self.builder.get_object("atdate1").get_active() == True: date = self.date.getDateObject() query1 = query1.filter(Bill.date == date) else: if self.builder.get_object("betweendates1").get_active() == True: fdate = self.fdate.getDateObject() tdate = self.tdate.getDateObject() if tdate < fdate: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Second date value shouldn't precede the first one.")) msgbox.set_title(_("Invalid date order")) msgbox.run() msgbox.destroy() return query1 = query1.filter(Bill.date.between(fdate, tdate)) for s in result: res = query1.filter(and_(Subject.lft >= s.lft, Subject.lft <= s.rgt, Notebook.value < 0)).first() if res[0] == None: debt_sum = 0 else: debt_sum = res[0] res = query1.filter(and_(Subject.lft >= s.lft, Subject.lft <= s.rgt, Notebook.value > 0)).first() if res[0] == None: credit_sum = 0 else: credit_sum = res[0] remain = credit_sum + debt_sum if remain < 0: remain = "( " + utility.showNumber(-remain) + " )" else: remain = utility.showNumber(remain) report_data.append((s.name, utility.showNumber(-debt_sum), utility.showNumber(credit_sum), remain)) return {"data":report_data, "col-width":col_width ,"heading":report_header}
def populateChildren(self, treeview, iter, path): chiter = self.treestore.iter_children(iter) if chiter != None: #Checks name field(second) because code field(first) may have changed during parent code edition. value = utility.convertToLatin(self.treestore.get(chiter, 1)[0]) if value == "": value = utility.convertToLatin(self.treestore.get(iter, 0)[0]) #remove empty subledger to add real children instead self.treestore.remove(chiter) Sub = aliased(Subject, name="s") Child = aliased(Subject, name="c") Parent = aliased(Subject, name="p") query = config.db.session.query(Sub.code, Sub.name, Sub.type, count(Child.id), Sub.lft, Sub.rgt) query = query.select_from( outerjoin( outerjoin(Parent, Sub, Sub.parent_id == Parent.id), Child, Sub.id == Child.parent_id)) result = query.filter(Parent.code == value).group_by( Sub.id).all() for row in result: code = row[0] if config.digittype == 1: code = utility.convertToPersian(code) type = _(self.__class__.subjecttypes[row[2]]) #-------- subject_sum = config.db.session.query(sum( Notebook.value)).select_from( outerjoin(Subject, Notebook, Subject.id == Notebook.subject_id)) subject_sum = subject_sum.filter( and_(Subject.lft >= row[4], Subject.lft <= row.rgt)).first() subject_sum = subject_sum[0] if (subject_sum == None): subject_sum = utility.showNumber("0") else: if (subject_sum < 0): subject_sum = "(-" + utility.showNumber( -subject_sum) + ")" else: subject_sum = utility.showNumber(subject_sum) chiter = self.treestore.append( iter, (code, row[1], type, subject_sum)) if row[3] != 0: #add empty subledger for those children which have subledgers in turn. (to show expander) self.treestore.append(chiter, ("", "", "", "")) return False
def saveRow(self, code, amount, type, desc, iter=None): query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == code) sub = query.first() if sub == None: if config.digittype == 1: code = utility.convertToPersian(code) errorstr = _("No subject is registered with the code: %s") % code msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, errorstr) msgbox.set_title(_("No subjects found")) msgbox.run() msgbox.destroy() return if sub.type != 2: type = sub.type debt = "0" credit = "0" if config.digittype == 1: debt = utility.convertToPersian(debt) credit = utility.convertToPersian(credit) code = utility.convertToPersian(code) if type == 0: debt = utility.showNumber(amount) self.debt_sum += amount else: if type == 1: credit = utility.showNumber(amount) self.credit_sum += amount if iter != None: self.liststore.set (iter, 1, code, 2, sub.name, 3, debt, 4, credit, 5, desc) else : self.numrows += 1 numrows = str(self.numrows) if config.digittype == 1: numrows = utility.convertToPersian(numrows) self.liststore.append ((numrows, code, sub.name, debt, credit, desc)) self.builder.get_object("debtsum").set_text (utility.showNumber(self.debt_sum)) self.builder.get_object("creditsum").set_text (utility.showNumber(self.credit_sum)) if self.debt_sum > self.credit_sum: diff = self.debt_sum - self.credit_sum else: diff = self.credit_sum - self.debt_sum self.builder.get_object("difference").set_text (utility.showNumber(diff))
def createReport(self): self.docnumber = self.number.get_text() if self.docnumber == "": return report_header = [] report_data = [] col_width = [] query1 = config.db.session.query(Bill, Notebook, Subject) query1 = query1.select_from(outerjoin(outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) query1 = query1.filter(Bill.number == int(unicode(self.docnumber))).order_by(Notebook.id.asc()) res = query1.all() if len(res) == 0: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("No document found with the requested number.")) msgbox.set_title(_("Invalid document number")) msgbox.run() msgbox.destroy() return self.docdate = res[0][0].date report_header = [_("Index"), _("Subject Code"), _("Subject Name"), _("Description"), _("Debt"), _("Credit")] #define the percentage of table width that each column needs col_width = [5, 11, 15, 43, 13, 13 ] index = 1 for b, n, s in res: desc = n.desc if n.value < 0: credit = utility.showNumber(0) debt = utility.showNumber(-(n.value)) else: credit = utility.showNumber(n.value) debt = utility.showNumber(0) desc = " " + desc code = s.code strindex = str(index) if config.digittype == 1: code = utility.convertToPersian(code) strindex = utility.convertToPersian(strindex) report_data.append((strindex, code, s.name, desc, debt, credit)) index += 1 return {"data":report_data, "col-width":col_width ,"heading":report_header}
def deleteRow(self, sender): selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK_CANCEL, _("Are you sure to remove this row?")) msgbox.set_title(_("Are you sure?")) result = msgbox.run() if result == gtk.RESPONSE_OK: debt = int( unicode(self.liststore.get(iter, 3)[0].replace(",", ""))) credit = int( unicode(self.liststore.get(iter, 4)[0].replace(",", ""))) index = int(unicode(self.liststore.get(iter, 0)[0])) res = self.liststore.remove(iter) #Update index of next rows if res: while iter != None: strindex = str(index) if config.digittype == 1: strindex = utility.convertToPersian(strindex) self.liststore.set_value(iter, 0, strindex) index += 1 iter = self.liststore.iter_next(iter) self.numrows -= 1 self.debt_sum -= debt self.credit_sum -= credit self.builder.get_object("debtsum").set_text( utility.showNumber(self.debt_sum)) self.builder.get_object("creditsum").set_text( utility.showNumber(self.credit_sum)) if self.debt_sum > self.credit_sum: diff = self.debt_sum - self.credit_sum else: diff = self.credit_sum - self.debt_sum self.builder.get_object("difference").set_text( utility.showNumber(diff)) msgbox.destroy()
def populateChildren(self, treeview, iter, path): chiter = self.treestore.iter_children(iter) if chiter != None : #Checks name field(second) because code field(first) may have changed during parent code edition. value = utility.convertToLatin(self.treestore.get(chiter, 1)[0]) if value == "" : value = utility.convertToLatin(self.treestore.get(iter, 0)[0]) #remove empty subledger to add real children instead self.treestore.remove(chiter) Sub = aliased(Subject, name="s") Child = aliased(Subject, name="c") Parent = aliased(Subject, name="p") query = config.db.session.query(Sub.code, Sub.name, Sub.type, count(Child.id), Sub.lft, Sub.rgt) query = query.select_from(outerjoin(outerjoin(Parent, Sub, Sub.parent_id == Parent.id), Child, Sub.id == Child.parent_id)) result = query.filter(Parent.code == value).group_by(Sub.id).all() for row in result : code = row[0] if config.digittype == 1: code = utility.convertToPersian(code) type = _(self.__class__.subjecttypes[row[2]]) #-------- subject_sum = config.db.session.query(sum(Notebook.value)).select_from(outerjoin(Subject, Notebook, Subject.id == Notebook.subject_id)) subject_sum = subject_sum.filter(and_(Subject.lft >= row[4], Subject.lft <= row.rgt)).first() subject_sum = subject_sum[0] if(subject_sum == None): subject_sum = utility.showNumber("0") else : if(subject_sum < 0): subject_sum = "(-" + utility.showNumber(-subject_sum) + ")" else : subject_sum = utility.showNumber(subject_sum) chiter = self.treestore.append(iter, (code, row[1], type, subject_sum)) if row[3] != 0 : #add empty subledger for those children which have subledgers in turn. (to show expander) self.treestore.append(chiter, ("", "", "", "")) return False
def showRows(self, docnumber): query = config.db.session.query(Bill).select_from(Bill) bill = query.filter(Bill.number == docnumber).first() self.date.showDateObject(bill.date) self.docid = bill.id query = config.db.session.query(Notebook, Subject) query = query.select_from( outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id)) rows = query.filter(Notebook.bill_id == bill.id).all() for n, s in rows: self.numrows += 1 if n.value < 0: value = -(n.value) debt = utility.showNumber(value) credit = utility.showNumber(0) self.debt_sum += value else: credit = utility.showNumber(n.value) debt = utility.showNumber(0) self.credit_sum += n.value code = s.code numrows = str(self.numrows) if config.digittype == 1: code = utility.convertToPersian(code) numrows = utility.convertToPersian(numrows) self.liststore.append( (numrows, code, s.name, debt, credit, n.desc)) docnum = str(docnumber) if config.digittype == 1: docnum = utility.convertToPersian(docnum) self.builder.get_object("docnumber").set_text(docnum) self.builder.get_object("debtsum").set_text( utility.showNumber(self.debt_sum)) self.builder.get_object("creditsum").set_text( utility.showNumber(self.credit_sum)) if self.debt_sum > self.credit_sum: diff = self.debt_sum - self.credit_sum else: diff = self.credit_sum - self.debt_sum self.builder.get_object("difference").set_text( utility.showNumber(diff))
def showRows(self, docnumber): query = config.db.session.query(Bill).select_from(Bill) bill = query.filter(Bill.number == docnumber).first() self.date.showDateObject(bill.date) self.docid = bill.id query = config.db.session.query(Notebook, Subject) query = query.select_from(outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id)) rows = query.filter(Notebook.bill_id == bill.id).all() for n, s in rows: self.numrows += 1 if n.value < 0: value = -(n.value) debt = utility.showNumber(value) credit = utility.showNumber(0) self.debt_sum += value else: credit = utility.showNumber(n.value) debt = utility.showNumber(0) self.credit_sum += n.value code = s.code numrows = str(self.numrows) if config.digittype == 1: code = utility.convertToPersian(code) numrows = utility.convertToPersian(numrows) self.liststore.append((numrows, code, s.name, debt, credit, n.desc)) docnum = str(docnumber) if config.digittype == 1: docnum = utility.convertToPersian(docnum) self.builder.get_object("docnumber").set_text (docnum) self.builder.get_object("debtsum").set_text (utility.showNumber(self.debt_sum)) self.builder.get_object("creditsum").set_text (utility.showNumber(self.credit_sum)) if self.debt_sum > self.credit_sum: diff = self.debt_sum - self.credit_sum else: diff = self.credit_sum - self.debt_sum self.builder.get_object("difference").set_text (utility.showNumber(diff))
def drawDocument(self, page_nr): # RIGHT_EDGE = 570 #(table width + PAGE_MARGIN) RIGHT_EDGE = self.page_setup.get_page_width(gtk.UNIT_POINTS) - config.rightmargin HEADER_HEIGHT = self.header_height HEADING_HEIGHT = self.heading_height # PAGE_MARGIN = self.page_margin MARGIN = self.cell_margin TABLE_TOP = HEADER_HEIGHT + HEADING_HEIGHT + self.cell_margin ROW_HEIGHT = self.row_height LINE = self.line cr = self.cairo_context fontsize = config.contentfont fdesc = pango.FontDescription("Sans") fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) # #Table top line # cr.move_to(PAGE_MARGIN, TABLE_TOP) # cr.line_to(RIGHT_EDGE, TABLE_TOP) self.drawTableHeading() #Draw table data rindex = page_nr * self.lines_per_page offset = 0 self.debt_sum = 0 self.credit_sum = 0 addh= TABLE_TOP try: while (offset < self.lines_per_page): row = self.content[rindex + offset] cr.move_to(RIGHT_EDGE, addh) cr.line_to(RIGHT_EDGE, addh+ROW_HEIGHT) right_txt = RIGHT_EDGE dindex = 0 for data in row: right_txt -= MARGIN+LINE if dindex == 2 or dindex == 3: fontsize -= 1 fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(data) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) fontsize = config.contentfont fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) else: self.pangolayout.set_text(data) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[dindex] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) dindex += 1 self.debt_sum += int(row[4].replace(",", "")) self.credit_sum += int(row[5].replace(",", "")) addh += ROW_HEIGHT offset += 1 except IndexError: pass right_txt = RIGHT_EDGE cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= 4*(MARGIN + LINE) + self.cols_width[0] + self.cols_width[1] + self.cols_width[2] self.pangolayout.set_text(_("Sum")) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[3] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) cr.move_to(RIGHT_EDGE, addh) cr.line_to(right_txt, addh) right_txt -= MARGIN + LINE self.pangolayout.set_text(utility.showNumber(self.debt_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[4] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(utility.showNumber(self.credit_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[5] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) #Table top line cr.move_to(right_txt, TABLE_TOP) cr.line_to(RIGHT_EDGE, TABLE_TOP) #Table bottom line cr.move_to(right_txt, addh + ROW_HEIGHT) cr.line_to(RIGHT_EDGE, addh + ROW_HEIGHT) cr.stroke()
def drawSubjectNotebook(self, page_nr): # RIGHT_EDGE = 570 #(table width + PAGE_MARGIN) RIGHT_EDGE = self.page_setup.get_page_width(gtk.UNIT_POINTS) - config.rightmargin HEADER_HEIGHT = self.header_height HEADING_HEIGHT = self.heading_height # PAGE_MARGIN = self.page_margin MARGIN = self.cell_margin TABLE_TOP = HEADER_HEIGHT + HEADING_HEIGHT + self.cell_margin ROW_HEIGHT = self.row_height LINE = self.line cr = self.cairo_context fontsize = config.contentfont fdesc = pango.FontDescription("Sans") fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) # #Table top line # cr.move_to(PAGE_MARGIN, TABLE_TOP) # cr.line_to(RIGHT_EDGE, TABLE_TOP) self.drawTableHeading() #Draw table data rindex = page_nr * self.lines_per_page offset = 0 right_txt = RIGHT_EDGE cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) self.pangolayout.set_text("----") (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) for i in range(0, 2): right_txt -= MARGIN + LINE cr.move_to (right_txt -(width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[i] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) right_txt -= MARGIN + LINE fontsize -= 1 fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(_("Sum of previous page")) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[2] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) right_txt -= MARGIN + LINE fontsize = config.contentfont fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) if page_nr == 0: self.pangolayout.set_text(utility.showNumber(0)) self.debt_sum = 0 else: self.pangolayout.set_text(utility.showNumber(self.debt_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[3] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) right_txt -= MARGIN + LINE if page_nr == 0: self.pangolayout.set_text(utility.showNumber(0)) self.credit_sum = 0 else: self.pangolayout.set_text(utility.showNumber(self.credit_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[4] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) if page_nr == 0: remaining = int(self.content[0][3].replace(",", "")) - int(self.content[0][4].replace(",", "")) if self.content[0][5] == _("deb"): remaining -= int(self.content[0][6].replace(",", "")) else: remaining += int(self.content[0][6].replace(",", "")) if remaining < 0: self.diagnose = _("deb") self.remaining = utility.showNumber(-(remaining)) else: if remaining == 0: self.diagnose = _("equ") else: self.diagnose = _("cre") self.remaining = utility.showNumber(remaining) right_txt -= MARGIN + LINE self.pangolayout.set_text(self.diagnose) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[5] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(self.remaining) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[6] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) addh= ROW_HEIGHT + TABLE_TOP try: while (offset < self.lines_per_page): row = self.content[rindex + offset] cr.move_to(RIGHT_EDGE, addh) cr.line_to(RIGHT_EDGE, addh+ROW_HEIGHT) right_txt = RIGHT_EDGE dindex = 0 for data in row: right_txt -= MARGIN+LINE if dindex == 2: fontsize -= 1 fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(data) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) fontsize = config.contentfont fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) else: self.pangolayout.set_text(data) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[dindex] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) dindex += 1 self.debt_sum += int(row[3].replace(",", "")) self.credit_sum += int(row[4].replace(",", "")) addh += ROW_HEIGHT offset += 1 except IndexError: pass self.diagnose = self.content[rindex + offset - 1][5] self.remaining = self.content[rindex + offset - 1][6] right_txt = RIGHT_EDGE cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) self.pangolayout.set_text("----") (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) for i in range(0, 2): right_txt -= MARGIN + LINE cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[i] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE fontsize -= 1 fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(_("Sum")) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[2] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE fontsize = config.contentfont fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(utility.showNumber(self.debt_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[3] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(utility.showNumber(self.credit_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[4] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(self.diagnose) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[5] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(self.remaining) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to (right_txt -(width / pango.SCALE), addh + (ROW_HEIGHT-(height / pango.SCALE))/2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[6] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) #Table top line cr.move_to(right_txt, TABLE_TOP) cr.line_to(RIGHT_EDGE, TABLE_TOP) #Table bottom line # cr.move_to(self.page_margin, addh + ROW_HEIGHT) cr.move_to(right_txt, addh + ROW_HEIGHT) cr.line_to(RIGHT_EDGE, addh + ROW_HEIGHT) cr.stroke()
def saveLedger(self, name, type, iter, edit, widget): if name == "" : msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Subject name should not be empty.")) msgbox.set_title(_("Empty subject name")) msgbox.run() msgbox.destroy() else : #Check to see if a subject with the given name exists already. if iter == None : iter_code = "" parent_id = 0 parent_right = 0 parent_left = 0 else : iter_code = utility.convertToLatin(self.treestore.get(iter, 0)[0]) query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == iter_code) sub = query.first() if edit == True: iter_id = sub.id parent_id = sub.parent_id temp_code = iter_code iter_code = iter_code[0:-2] parent_right = sub.rgt parent_left = sub.lft else : parent_id = sub.id parent_right = sub.rgt parent_left = sub.lft query = config.db.session.query(count(Subject.id)).select_from(Subject) query = query.filter(and_(Subject.name == name, Subject.parent_id == parent_id)) if edit== True: query = query.filter(Subject.id != iter_id) result = query.first() if result[0] != 0 : msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("A subject with this name already exists in the current level.")) msgbox.set_title(_("Duplicate subject name")) msgbox.run() msgbox.destroy() return lastcode = utility.convertToLatin(self.code.get_text())[0:2] if lastcode == '': msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Ledger Code field is empty")) msgbox.set_title(_("Invalid subject code")) msgbox.run() msgbox.destroy() return lastcode = iter_code + lastcode[0:2] query = config.db.session.query(count(Subject.id)).select_from(Subject) query = query.filter(and_(Subject.parent_id == parent_id, Subject.code == lastcode)) if edit== True: query = query.filter(Subject.id != iter_id) result = query.first() if result[0] != 0 : msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("A subject with this code already exists.")) msgbox.set_title(_("Duplicate subject code")) msgbox.run() msgbox.destroy() return if edit == True: query = config.db.session.query(count(Notebook.id)).select_from(Notebook) query = query.filter(Notebook.subject_id == iter_id) rowcount = 0 msg = "" if type == 1: rowcounts = query.filter(Notebook.value < 0).first() rowcount = rowcounts[0] msg = _("The type of this subject can not be changed to 'creditor', Because there are \ %d documents that use it as debtor.") % rowcount elif type == 0: rowcounts = query.filter(Notebook.value > 0).first() rowcount = rowcounts[0] msg = _("The type of this subject can not be changed to 'debtor', Because there are \ %d documents that use it as creditor.") % rowcount if (rowcount > 0): msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg) msgbox.set_title(_("Can not change subject type")) msgbox.run() msgbox.destroy() return sub.code = lastcode sub.name = name sub.type = type #update subledger codes if parent ledger code has changed length = len(lastcode) if temp_code != lastcode: query = config.db.session.query(Subject).select_from(Subject) query = query.filter(and_(Subject.lft > parent_left, Subject.rgt < parent_right)) result = query.all() for child in result: child.code = lastcode + child.code[length:] config.db.session.add(child) config.db.session.commit() #TODO show updated children on screen if config.digittype == 1: basecode = utility.convertToPersian(lastcode) else: basecode = lastcode if temp_code != lastcode: # chiter = self.treestore.iter_children(iter) tempstore = self.treestore.filter_new(self.treestore.get_path(iter)) tempstore.foreach(self.editChildCodes, (basecode, length)) # while chiter: # chcode = self.treestore.get(chiter, 0)[0] # chcode = utility.convertToLatin(chcode)[-2:] # if config.digittype == 1: # chcode = utility.convertToPersian(chcode) # self.treestore.set(chiter, 0, basecode + chcode ) # chiter = self.treestore.iter_next(chiter) self.treestore.set(iter, 0, basecode, 1, name, 2, _(self.__class__.subjecttypes[type])) else: # query = self.session.query(Subject.code).select_from(Subject).order_by(Subject.id.desc()) # code = query.filter(Subject.parent_id == parent_id).first() # if code == None : # lastcode = "01" # else : # lastcode = "%02d" % (int(code[0][-2:]) + 1) # If row have not been expanded yet, function 'populateChidren' will be executed and adds children # to the row, then we insert new child in the database and call treeview.append to add it to the # end of the tree. if iter != None: self.treeview.expand_row(self.treestore.get_path(iter), False) sub_right = config.db.session.query(max(Subject.rgt)).select_from(Subject).filter(Subject.parent_id == parent_id).first() sub_right = sub_right[0] if sub_right == None : sub_right = parent_left else : #sub_right = self.session.query(Subject.rgt).select_from(Subject).order_by(Subject.rgt.desc()).first(); sub_right = config.db.session.query(max(Subject.rgt)).select_from(Subject).first() sub_right = sub_right[0] if sub_right == None : sub_right = 0 #Update subjects which we want to place new subject before them: rlist = config.db.session.query(Subject).filter(Subject.rgt > sub_right).all() for r in rlist: r.rgt += 2 config.db.session.add(r) llist = config.db.session.query(Subject).filter(Subject.lft > sub_right).all() for l in llist: l.lft += 2 config.db.session.add(l) sub_left = sub_right + 1 sub_right = sub_left + 1 #Now create new subject: ledger = Subject(lastcode, name, parent_id, sub_left, sub_right, type) config.db.session.add(ledger) config.db.session.commit() if config.digittype == 1: lastcode = utility.convertToPersian(lastcode) child = self.treestore.append(iter, (lastcode, name, _(self.__class__.subjecttypes[type]), utility.showNumber("0"))) self.temppath = self.treestore.get_path(child) self.treeview.scroll_to_cell(self.temppath, None, False, 0, 0) self.treeview.set_cursor(self.temppath, None, False)
def __init__ (self, ledgers_only=False): gobject.GObject.__init__(self) self.builder = get_builder("notebook") self.window = self.builder.get_object("subjectswindow") self.window.set_modal(True) self.treeview = self.builder.get_object("treeview") self.treeview.set_direction(gtk.TEXT_DIR_LTR) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL : halign = 1 else: halign = 0 self.treestore = gtk.TreeStore(str, str, str, str) column = gtk.TreeViewColumn(_("Subject Code"), gtk.CellRendererText(), text=0) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Name"), gtk.CellRendererText(), text=1) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Debtor or Creditor"), gtk.CellRendererText(), text=2) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Sum"), gtk.CellRendererText(), text=3) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) self.code = numberentry.NumberEntry() box = self.builder.get_object("codebox") box.add(self.code) self.code.show() config.db.session = config.db.session Subject1 = aliased(Subject, name="s1") Subject2 = aliased(Subject, name="s2") #Find top level ledgers (with parent_id equal to 0) query = config.db.session.query(Subject1.code, Subject1.name, Subject1.type, Subject1.lft, Subject1.rgt, count(Subject2.id)) query = query.select_from(outerjoin(Subject1, Subject2, Subject1.id == Subject2.parent_id)) result = query.filter(Subject1.parent_id == 0).group_by(Subject1.id).all() for a in result : type = _(self.__class__.subjecttypes[a[2]]) code = a[0] if config.digittype == 1: code = utility.convertToPersian(code) #-------- subject_sum = config.db.session.query(sum(Notebook.value)).select_from(outerjoin(Subject, Notebook, Subject.id == Notebook.subject_id)) subject_sum = subject_sum.filter(and_(Subject.lft >= a.lft, Subject.lft <= a.rgt)).first() subject_sum = subject_sum[0] if(subject_sum == None): subject_sum = utility.showNumber("0") else : if(subject_sum < 0): subject_sum = "( -" + utility.showNumber(-subject_sum) + " )" else : subject_sum = utility.showNumber(subject_sum) iter = self.treestore.append(None, (code, a[1], type, subject_sum)) if (a[5] != 0 and ledgers_only == False) : #Add empty subledger to show expander for ledgers which have chidren self.treestore.append(iter, ("", "", "", "")) if ledgers_only == True: btn = self.builder.get_object("addsubtoolbutton") btn.hide() self.treeview.set_model(self.treestore) self.treestore.set_sort_column_id(0, gtk.SORT_ASCENDING) self.window.show_all() self.builder.connect_signals(self)
def saveLedger(self, name, type, iter, edit, widget): if name == "": msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Subject name should not be empty.")) msgbox.set_title(_("Empty subject name")) msgbox.run() msgbox.destroy() else: #Check to see if a subject with the given name exists already. if iter == None: iter_code = "" parent_id = 0 parent_right = 0 parent_left = 0 else: iter_code = utility.convertToLatin( self.treestore.get(iter, 0)[0]) query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == iter_code) sub = query.first() if edit == True: iter_id = sub.id parent_id = sub.parent_id temp_code = iter_code iter_code = iter_code[0:-2] parent_right = sub.rgt parent_left = sub.lft else: parent_id = sub.id parent_right = sub.rgt parent_left = sub.lft query = config.db.session.query(count( Subject.id)).select_from(Subject) query = query.filter( and_(Subject.name == name, Subject.parent_id == parent_id)) if edit == True: query = query.filter(Subject.id != iter_id) result = query.first() if result[0] != 0: msgbox = gtk.MessageDialog( widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("A subject with this name already exists in the current level." )) msgbox.set_title(_("Duplicate subject name")) msgbox.run() msgbox.destroy() return lastcode = utility.convertToLatin(self.code.get_text())[0:2] if lastcode == '': msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Ledger Code field is empty")) msgbox.set_title(_("Invalid subject code")) msgbox.run() msgbox.destroy() return lastcode = iter_code + lastcode[0:2] query = config.db.session.query(count( Subject.id)).select_from(Subject) query = query.filter( and_(Subject.parent_id == parent_id, Subject.code == lastcode)) if edit == True: query = query.filter(Subject.id != iter_id) result = query.first() if result[0] != 0: msgbox = gtk.MessageDialog( widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("A subject with this code already exists.")) msgbox.set_title(_("Duplicate subject code")) msgbox.run() msgbox.destroy() return if edit == True: query = config.db.session.query(count( Notebook.id)).select_from(Notebook) query = query.filter(Notebook.subject_id == iter_id) rowcount = 0 msg = "" if type == 1: rowcounts = query.filter(Notebook.value < 0).first() rowcount = rowcounts[0] msg = _( "The type of this subject can not be changed to 'creditor', Because there are \ %d documents that use it as debtor.") % rowcount elif type == 0: rowcounts = query.filter(Notebook.value > 0).first() rowcount = rowcounts[0] msg = _( "The type of this subject can not be changed to 'debtor', Because there are \ %d documents that use it as creditor.") % rowcount if (rowcount > 0): msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg) msgbox.set_title(_("Can not change subject type")) msgbox.run() msgbox.destroy() return sub.code = lastcode sub.name = name sub.type = type #update subledger codes if parent ledger code has changed length = len(lastcode) if temp_code != lastcode: query = config.db.session.query(Subject).select_from( Subject) query = query.filter( and_(Subject.lft > parent_left, Subject.rgt < parent_right)) result = query.all() for child in result: child.code = lastcode + child.code[length:] config.db.session.add(child) config.db.session.commit() #TODO show updated children on screen if config.digittype == 1: basecode = utility.convertToPersian(lastcode) else: basecode = lastcode if temp_code != lastcode: # chiter = self.treestore.iter_children(iter) tempstore = self.treestore.filter_new( self.treestore.get_path(iter)) tempstore.foreach(self.editChildCodes, (basecode, length)) # while chiter: # chcode = self.treestore.get(chiter, 0)[0] # chcode = utility.convertToLatin(chcode)[-2:] # if config.digittype == 1: # chcode = utility.convertToPersian(chcode) # self.treestore.set(chiter, 0, basecode + chcode ) # chiter = self.treestore.iter_next(chiter) self.treestore.set(iter, 0, basecode, 1, name, 2, _(self.__class__.subjecttypes[type])) else: # query = self.session.query(Subject.code).select_from(Subject).order_by(Subject.id.desc()) # code = query.filter(Subject.parent_id == parent_id).first() # if code == None : # lastcode = "01" # else : # lastcode = "%02d" % (int(code[0][-2:]) + 1) # If row have not been expanded yet, function 'populateChidren' will be executed and adds children # to the row, then we insert new child in the database and call treeview.append to add it to the # end of the tree. if iter != None: self.treeview.expand_row(self.treestore.get_path(iter), False) sub_right = config.db.session.query(max( Subject.rgt)).select_from(Subject).filter( Subject.parent_id == parent_id).first() sub_right = sub_right[0] if sub_right == None: sub_right = parent_left else: #sub_right = self.session.query(Subject.rgt).select_from(Subject).order_by(Subject.rgt.desc()).first(); sub_right = config.db.session.query(max( Subject.rgt)).select_from(Subject).first() sub_right = sub_right[0] if sub_right == None: sub_right = 0 #Update subjects which we want to place new subject before them: rlist = config.db.session.query(Subject).filter( Subject.rgt > sub_right).all() for r in rlist: r.rgt += 2 config.db.session.add(r) llist = config.db.session.query(Subject).filter( Subject.lft > sub_right).all() for l in llist: l.lft += 2 config.db.session.add(l) sub_left = sub_right + 1 sub_right = sub_left + 1 #Now create new subject: ledger = Subject(lastcode, name, parent_id, sub_left, sub_right, type) config.db.session.add(ledger) config.db.session.commit() if config.digittype == 1: lastcode = utility.convertToPersian(lastcode) child = self.treestore.append( iter, (lastcode, name, _(self.__class__.subjecttypes[type]), utility.showNumber("0"))) self.temppath = self.treestore.get_path(child) self.treeview.scroll_to_cell(self.temppath, None, False, 0, 0) self.treeview.set_cursor(self.temppath, None, False)
def drawDocument(self, page_nr): # RIGHT_EDGE = 570 #(table width + PAGE_MARGIN) RIGHT_EDGE = self.page_setup.get_page_width( gtk.UNIT_POINTS) - config.rightmargin HEADER_HEIGHT = self.header_height HEADING_HEIGHT = self.heading_height # PAGE_MARGIN = self.page_margin MARGIN = self.cell_margin TABLE_TOP = HEADER_HEIGHT + HEADING_HEIGHT + self.cell_margin ROW_HEIGHT = self.row_height LINE = self.line cr = self.cairo_context fontsize = config.contentfont fdesc = pango.FontDescription("Sans") fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) # #Table top line # cr.move_to(PAGE_MARGIN, TABLE_TOP) # cr.line_to(RIGHT_EDGE, TABLE_TOP) self.drawTableHeading() #Draw table data rindex = page_nr * self.lines_per_page offset = 0 self.debt_sum = 0 self.credit_sum = 0 addh = TABLE_TOP try: while (offset < self.lines_per_page): row = self.content[rindex + offset] cr.move_to(RIGHT_EDGE, addh) cr.line_to(RIGHT_EDGE, addh + ROW_HEIGHT) right_txt = RIGHT_EDGE dindex = 0 for data in row: right_txt -= MARGIN + LINE if dindex == 2 or dindex == 3: fontsize -= 1 fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(data) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to( right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) fontsize = config.contentfont fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) else: self.pangolayout.set_text(data) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to( right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[dindex] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) dindex += 1 self.debt_sum += int(row[4].replace(",", "")) self.credit_sum += int(row[5].replace(",", "")) addh += ROW_HEIGHT offset += 1 except IndexError: pass right_txt = RIGHT_EDGE cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= 4 * (MARGIN + LINE) + self.cols_width[ 0] + self.cols_width[1] + self.cols_width[2] self.pangolayout.set_text(_("Sum")) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[3] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) cr.move_to(RIGHT_EDGE, addh) cr.line_to(right_txt, addh) right_txt -= MARGIN + LINE self.pangolayout.set_text(utility.showNumber(self.debt_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[4] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(utility.showNumber(self.credit_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[5] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) #Table top line cr.move_to(right_txt, TABLE_TOP) cr.line_to(RIGHT_EDGE, TABLE_TOP) #Table bottom line cr.move_to(right_txt, addh + ROW_HEIGHT) cr.line_to(RIGHT_EDGE, addh + ROW_HEIGHT) cr.stroke()
def drawSubjectNotebook(self, page_nr): # RIGHT_EDGE = 570 #(table width + PAGE_MARGIN) RIGHT_EDGE = self.page_setup.get_page_width( gtk.UNIT_POINTS) - config.rightmargin HEADER_HEIGHT = self.header_height HEADING_HEIGHT = self.heading_height # PAGE_MARGIN = self.page_margin MARGIN = self.cell_margin TABLE_TOP = HEADER_HEIGHT + HEADING_HEIGHT + self.cell_margin ROW_HEIGHT = self.row_height LINE = self.line cr = self.cairo_context fontsize = config.contentfont fdesc = pango.FontDescription("Sans") fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) # #Table top line # cr.move_to(PAGE_MARGIN, TABLE_TOP) # cr.line_to(RIGHT_EDGE, TABLE_TOP) self.drawTableHeading() #Draw table data rindex = page_nr * self.lines_per_page offset = 0 right_txt = RIGHT_EDGE cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) self.pangolayout.set_text("----") (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) for i in range(0, 2): right_txt -= MARGIN + LINE cr.move_to(right_txt - (width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[i] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) right_txt -= MARGIN + LINE fontsize -= 1 fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(_("Sum of previous page")) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[2] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) right_txt -= MARGIN + LINE fontsize = config.contentfont fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) if page_nr == 0: self.pangolayout.set_text(utility.showNumber(0)) self.debt_sum = 0 else: self.pangolayout.set_text(utility.showNumber(self.debt_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[3] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) right_txt -= MARGIN + LINE if page_nr == 0: self.pangolayout.set_text(utility.showNumber(0)) self.credit_sum = 0 else: self.pangolayout.set_text(utility.showNumber(self.credit_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[4] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) if page_nr == 0: remaining = int(self.content[0][3].replace(",", "")) - int( self.content[0][4].replace(",", "")) if self.content[0][5] == _("deb"): remaining -= int(self.content[0][6].replace(",", "")) else: remaining += int(self.content[0][6].replace(",", "")) if remaining < 0: self.diagnose = _("deb") self.remaining = utility.showNumber(-(remaining)) else: if remaining == 0: self.diagnose = _("equ") else: self.diagnose = _("cre") self.remaining = utility.showNumber(remaining) right_txt -= MARGIN + LINE self.pangolayout.set_text(self.diagnose) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[5] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(self.remaining) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), TABLE_TOP + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[6] cr.move_to(right_txt, TABLE_TOP) cr.line_to(right_txt, TABLE_TOP + ROW_HEIGHT) addh = ROW_HEIGHT + TABLE_TOP try: while (offset < self.lines_per_page): row = self.content[rindex + offset] cr.move_to(RIGHT_EDGE, addh) cr.line_to(RIGHT_EDGE, addh + ROW_HEIGHT) right_txt = RIGHT_EDGE dindex = 0 for data in row: right_txt -= MARGIN + LINE if dindex == 2: fontsize -= 1 fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(data) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to( right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) fontsize = config.contentfont fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) else: self.pangolayout.set_text(data) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to( right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[dindex] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) dindex += 1 self.debt_sum += int(row[3].replace(",", "")) self.credit_sum += int(row[4].replace(",", "")) addh += ROW_HEIGHT offset += 1 except IndexError: pass self.diagnose = self.content[rindex + offset - 1][5] self.remaining = self.content[rindex + offset - 1][6] right_txt = RIGHT_EDGE cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) self.pangolayout.set_text("----") (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) for i in range(0, 2): right_txt -= MARGIN + LINE cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[i] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE fontsize -= 1 fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(_("Sum")) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[2] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE fontsize = config.contentfont fdesc.set_size(fontsize * pango.SCALE) self.pangolayout.set_font_description(fdesc) self.pangolayout.set_text(utility.showNumber(self.debt_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[3] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(utility.showNumber(self.credit_sum)) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[4] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(self.diagnose) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[5] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) right_txt -= MARGIN + LINE self.pangolayout.set_text(self.remaining) (width, height) = self.pangolayout.get_size() self.pangolayout.set_alignment(pango.ALIGN_RIGHT) cr.move_to(right_txt - (width / pango.SCALE), addh + (ROW_HEIGHT - (height / pango.SCALE)) / 2) self.pangocairo.show_layout(self.pangolayout) right_txt -= self.cols_width[6] cr.move_to(right_txt, addh) cr.line_to(right_txt, addh + ROW_HEIGHT) #Table top line cr.move_to(right_txt, TABLE_TOP) cr.line_to(RIGHT_EDGE, TABLE_TOP) #Table bottom line # cr.move_to(self.page_margin, addh + ROW_HEIGHT) cr.move_to(right_txt, addh + ROW_HEIGHT) cr.line_to(RIGHT_EDGE, addh + ROW_HEIGHT) cr.stroke()
def createReport(self): report_header = [] report_data = [] col_width = [] remaining = 1 query1 = config.db.session.query(Notebook, Subject.code, Bill) query1 = query1.select_from(outerjoin(outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) query2 = config.db.session.query(sum(Notebook.value)) query2 = query2.select_from(outerjoin(outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) # Check if the subject code is valid in ledger and subledger reports if self.type != self.__class__.DAILY: code = utility.convertToLatin(self.code.get_text()) query3 = config.db.session.query(Subject.name) query3 = query3.select_from(Subject).filter(Subject.code == code) names = query3.first() if names == None: errorstr = _("No subject is registered with the code: %s") % self.code.get_text() msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, errorstr) msgbox.set_title(_("No subjects found")) msgbox.run() msgbox.destroy() return else: self.subname = names[0] self.subcode = code query1 = query1.filter(Subject.code.startswith(code)) query2 = query2.filter(Subject.code.startswith(code)) searchkey = unicode(self.builder.get_object("searchentry").get_text()) if searchkey != "": try: value = int(utility.convertToLatin(searchkey)) except (UnicodeEncodeError, ValueError): #search key is not a number query1 = query1.filter(Notebook.desc.like("%"+searchkey+"%")) else: query1 = query1.filter(or_(Notebook.desc.like("%"+searchkey+"%"), Notebook.value == value, Notebook.value == -value)) # Check the report parameters if self.builder.get_object("allcontent").get_active() == True: query1 = query1.order_by(Bill.date.asc(), Bill.number.asc()) remaining = 0 else: if self.builder.get_object("atdate").get_active() == True: date = self.date.getDateObject() query1 = query1.filter(Bill.date == date).order_by(Bill.number.asc()) query2 = query2.filter(Bill.date < date) else: if self.builder.get_object("betweendates").get_active() == True: fdate = self.fdate.getDateObject() tdate = self.tdate.getDateObject() if tdate < fdate: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Second date value shouldn't precede the first one.")) msgbox.set_title(_("Invalid date order")) msgbox.run() msgbox.destroy() return query1 = query1.filter(Bill.date.between(fdate, tdate)).order_by(Bill.date.asc(), Bill.number.asc()) query2 = query2.filter(Bill.date < fdate) else: if unicode(self.fnum.get_text()) == '' or unicode(self.tnum.get_text()) == '': msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("One of document numbers are empty.")) msgbox.set_title(_("Invalid document order")) msgbox.run() msgbox.destroy() return fnumber = int(unicode(self.fnum.get_text())) tnumber = int(unicode(self.tnum.get_text())) if tnumber < fnumber: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Second document number shouldn't be greater than the first one.")) msgbox.set_title(_("Invalid document order")) msgbox.run() msgbox.destroy() return query1 = query1.filter(Bill.number.between(fnumber, tnumber)).order_by(Bill.date.asc(), Bill.number.asc()) query2 = query2.filter(Bill.number < fnumber) #Prepare report data for PrintReport class res = query1.all() if self.type == self.__class__.DAILY: report_header = [_("Doc. Number"), _("Date"), _("Subject Code"), _("Description"), _("Debt"), _("Credit")] #define the percentage of table width that each column needs col_width = [10, 10, 11, 43, 13, 13 ] for n, code, b in res: desc = n.desc if n.value < 0: credit = utility.showNumber("0") debt = utility.showNumber(-(n.value)) else: credit = utility.showNumber(n.value) debt = utility.showNumber("0") desc = " " + desc billnumber = str(b.number) if config.digittype == 1: code = utility.convertToPersian(code) billnumber = utility.convertToPersian(billnumber) report_data.append((billnumber, dateToString(b.date), code, desc, debt, credit)) else: diagnose = "" if remaining != 0: remaining = query2.first()[0] #if self.type == self.__class__.LEDGER: report_header = [_("Doc. Number"), _("Date"), _("Description"), _("Debt"), _("Credit"), _("Diagnosis"), _("Remaining")] #define the percentage of table width that each column needs col_width = [10, 10, 37, 13, 13, 4, 13] for n, code, b in res: if n.value < 0: credit = utility.showNumber("0") debt = utility.showNumber(-(n.value)) else: credit = utility.showNumber(n.value) debt = utility.showNumber("0") remaining += n.value billnumber = str(b.number) if config.digittype == 1: billnumber = utility.convertToPersian(billnumber) if remaining < 0: diagnose = _("deb") report_data.append((billnumber, dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(-(remaining)))) else: if remaining == 0: diagnose = _("equ") else: diagnose = _("cre") report_data.append((billnumber, dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(remaining))) # else: # if self.type == self.__class__.SUBLEDGER: # report_header = [_("Doc. Number"), _("Date"), _("Description"), _("Debt"), _("Credit"), _("Diagnosis"), _("Remaining")] # col_width = [55, 64, 174, 70, 70, 20, 70] # for n, code, b in res: # if n.value < 0: # credit = "0" # debt = utility.showNumber(-(n.value)) # else: # credit = utility.showNumber(n.value) # debt = "0" # # remaining += n.value # if remaining < 0: # diagnose = _("deb") # report_data.append((str(b.number), dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(-(remaining)))) # else: # if remaining == 0: # diagnose = _("equ") # else: # diagnose = _("cre") # report_data.append((str(b.number), dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(remaining))) return {"data":report_data, "col-width":col_width ,"heading":report_header}
def createReport(self): report_data = [] remaining = 0 report_header = [ _("Ledger name"), _("Debt"), _("Credit"), _("Remaining") ] col_width = [31, 23, 23, 23] query = config.db.session.query(Subject).select_from(Subject) result = query.filter(Subject.parent_id == 0).all() query1 = config.db.session.query(sum(Notebook.value)) # Check the report parameters if self.builder.get_object("allcontent1").get_active() == True: query1 = query1.select_from( outerjoin(Subject, Notebook, Subject.id == Notebook.subject_id)) else: query1 = query1.select_from( outerjoin( outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) if self.builder.get_object("atdate1").get_active() == True: date = self.date.getDateObject() query1 = query1.filter(Bill.date == date) else: if self.builder.get_object( "betweendates1").get_active() == True: fdate = self.fdate.getDateObject() tdate = self.tdate.getDateObject() if tdate < fdate: msgbox = gtk.MessageDialog( self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Second date value shouldn't precede the first one." )) msgbox.set_title(_("Invalid date order")) msgbox.run() msgbox.destroy() return query1 = query1.filter(Bill.date.between(fdate, tdate)) for s in result: res = query1.filter( and_(Subject.lft >= s.lft, Subject.lft <= s.rgt, Notebook.value < 0)).first() if res[0] == None: debt_sum = 0 else: debt_sum = res[0] res = query1.filter( and_(Subject.lft >= s.lft, Subject.lft <= s.rgt, Notebook.value > 0)).first() if res[0] == None: credit_sum = 0 else: credit_sum = res[0] remain = credit_sum + debt_sum if remain < 0: remain = "( " + utility.showNumber(-remain) + " )" else: remain = utility.showNumber(remain) report_data.append((s.name, utility.showNumber(-debt_sum), utility.showNumber(credit_sum), remain)) return { "data": report_data, "col-width": col_width, "heading": report_header }
def createReport(self): report_header = [] report_data = [] col_width = [] remaining = 1 query1 = config.db.session.query(Notebook, Subject.code, Bill) query1 = query1.select_from( outerjoin( outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) query2 = config.db.session.query(sum(Notebook.value)) query2 = query2.select_from( outerjoin( outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) # Check if the subject code is valid in ledger and subledger reports if self.type != self.__class__.DAILY: code = utility.convertToLatin(self.code.get_text()) query3 = config.db.session.query(Subject.name) query3 = query3.select_from(Subject).filter(Subject.code == code) names = query3.first() if names == None: errorstr = _("No subject is registered with the code: %s" ) % self.code.get_text() msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, errorstr) msgbox.set_title(_("No subjects found")) msgbox.run() msgbox.destroy() return else: self.subname = names[0] self.subcode = code query1 = query1.filter(Subject.code.startswith(code)) query2 = query2.filter(Subject.code.startswith(code)) searchkey = unicode(self.builder.get_object("searchentry").get_text()) if searchkey != "": try: value = int(utility.convertToLatin(searchkey)) except (UnicodeEncodeError, ValueError): #search key is not a number query1 = query1.filter( Notebook.desc.like("%" + searchkey + "%")) else: query1 = query1.filter( or_(Notebook.desc.like("%" + searchkey + "%"), Notebook.value == value, Notebook.value == -value)) # Check the report parameters if self.builder.get_object("allcontent").get_active() == True: query1 = query1.order_by(Bill.date.asc(), Bill.number.asc()) remaining = 0 else: if self.builder.get_object("atdate").get_active() == True: date = self.date.getDateObject() query1 = query1.filter(Bill.date == date).order_by( Bill.number.asc()) query2 = query2.filter(Bill.date < date) else: if self.builder.get_object( "betweendates").get_active() == True: fdate = self.fdate.getDateObject() tdate = self.tdate.getDateObject() if tdate < fdate: msgbox = gtk.MessageDialog( self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Second date value shouldn't precede the first one." )) msgbox.set_title(_("Invalid date order")) msgbox.run() msgbox.destroy() return query1 = query1.filter(Bill.date.between( fdate, tdate)).order_by(Bill.date.asc(), Bill.number.asc()) query2 = query2.filter(Bill.date < fdate) else: if unicode(self.fnum.get_text()) == '' or unicode( self.tnum.get_text()) == '': msgbox = gtk.MessageDialog( self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("One of document numbers are empty.")) msgbox.set_title(_("Invalid document order")) msgbox.run() msgbox.destroy() return fnumber = int(unicode(self.fnum.get_text())) tnumber = int(unicode(self.tnum.get_text())) if tnumber < fnumber: msgbox = gtk.MessageDialog( self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Second document number shouldn't be greater than the first one." )) msgbox.set_title(_("Invalid document order")) msgbox.run() msgbox.destroy() return query1 = query1.filter( Bill.number.between(fnumber, tnumber)).order_by( Bill.date.asc(), Bill.number.asc()) query2 = query2.filter(Bill.number < fnumber) #Prepare report data for PrintReport class res = query1.all() if self.type == self.__class__.DAILY: report_header = [ _("Doc. Number"), _("Date"), _("Subject Code"), _("Description"), _("Debt"), _("Credit") ] #define the percentage of table width that each column needs col_width = [10, 10, 11, 43, 13, 13] for n, code, b in res: desc = n.desc if n.value < 0: credit = utility.showNumber("0") debt = utility.showNumber(-(n.value)) else: credit = utility.showNumber(n.value) debt = utility.showNumber("0") desc = " " + desc billnumber = str(b.number) if config.digittype == 1: code = utility.convertToPersian(code) billnumber = utility.convertToPersian(billnumber) report_data.append((billnumber, dateToString(b.date), code, desc, debt, credit)) else: diagnose = "" if remaining != 0: remaining = query2.first()[0] #if self.type == self.__class__.LEDGER: report_header = [ _("Doc. Number"), _("Date"), _("Description"), _("Debt"), _("Credit"), _("Diagnosis"), _("Remaining") ] #define the percentage of table width that each column needs col_width = [10, 10, 37, 13, 13, 4, 13] for n, code, b in res: if n.value < 0: credit = utility.showNumber("0") debt = utility.showNumber(-(n.value)) else: credit = utility.showNumber(n.value) debt = utility.showNumber("0") remaining += n.value billnumber = str(b.number) if config.digittype == 1: billnumber = utility.convertToPersian(billnumber) if remaining < 0: diagnose = _("deb") report_data.append( (billnumber, dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(-(remaining)))) else: if remaining == 0: diagnose = _("equ") else: diagnose = _("cre") report_data.append( (billnumber, dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(remaining))) # else: # if self.type == self.__class__.SUBLEDGER: # report_header = [_("Doc. Number"), _("Date"), _("Description"), _("Debt"), _("Credit"), _("Diagnosis"), _("Remaining")] # col_width = [55, 64, 174, 70, 70, 20, 70] # for n, code, b in res: # if n.value < 0: # credit = "0" # debt = utility.showNumber(-(n.value)) # else: # credit = utility.showNumber(n.value) # debt = "0" # # remaining += n.value # if remaining < 0: # diagnose = _("deb") # report_data.append((str(b.number), dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(-(remaining)))) # else: # if remaining == 0: # diagnose = _("equ") # else: # diagnose = _("cre") # report_data.append((str(b.number), dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(remaining))) return { "data": report_data, "col-width": col_width, "heading": report_header }
def __init__(self, ledgers_only=False): gobject.GObject.__init__(self) self.builder = get_builder("notebook") self.window = self.builder.get_object("subjectswindow") self.window.set_modal(True) self.treeview = self.builder.get_object("treeview") self.treeview.set_direction(gtk.TEXT_DIR_LTR) if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: halign = 1 else: halign = 0 self.treestore = gtk.TreeStore(str, str, str, str) column = gtk.TreeViewColumn(_("Subject Code"), gtk.CellRendererText(), text=0) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Subject Name"), gtk.CellRendererText(), text=1) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Debtor or Creditor"), gtk.CellRendererText(), text=2) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) column = gtk.TreeViewColumn(_("Sum"), gtk.CellRendererText(), text=3) column.set_alignment(halign) column.set_spacing(5) column.set_resizable(True) self.treeview.append_column(column) self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE) self.code = numberentry.NumberEntry() box = self.builder.get_object("codebox") box.add(self.code) self.code.show() config.db.session = config.db.session Subject1 = aliased(Subject, name="s1") Subject2 = aliased(Subject, name="s2") #Find top level ledgers (with parent_id equal to 0) query = config.db.session.query(Subject1.code, Subject1.name, Subject1.type, Subject1.lft, Subject1.rgt, count(Subject2.id)) query = query.select_from( outerjoin(Subject1, Subject2, Subject1.id == Subject2.parent_id)) result = query.filter(Subject1.parent_id == 0).group_by( Subject1.id).all() for a in result: type = _(self.__class__.subjecttypes[a[2]]) code = a[0] if config.digittype == 1: code = utility.convertToPersian(code) #-------- subject_sum = config.db.session.query(sum( Notebook.value)).select_from( outerjoin(Subject, Notebook, Subject.id == Notebook.subject_id)) subject_sum = subject_sum.filter( and_(Subject.lft >= a.lft, Subject.lft <= a.rgt)).first() subject_sum = subject_sum[0] if (subject_sum == None): subject_sum = utility.showNumber("0") else: if (subject_sum < 0): subject_sum = "( -" + utility.showNumber( -subject_sum) + " )" else: subject_sum = utility.showNumber(subject_sum) iter = self.treestore.append(None, (code, a[1], type, subject_sum)) if (a[5] != 0 and ledgers_only == False): #Add empty subledger to show expander for ledgers which have chidren self.treestore.append(iter, ("", "", "", "")) if ledgers_only == True: btn = self.builder.get_object("addsubtoolbutton") btn.hide() self.treeview.set_model(self.treestore) self.treestore.set_sort_column_id(0, gtk.SORT_ASCENDING) self.window.show_all() self.builder.connect_signals(self)