Ejemplo n.º 1
0
 def showRows(self):
     self.debt_sum   = 0
     self.credit_sum = 0
     self.numrows    = 0
     
     self.date.showDateObject(self.cl_document.date)
     rows = self.cl_document.get_notebook_rows()
     for n, s in rows:
         self.numrows += 1
         if n.value < 0:
             value = -(n.value)
             debt = utility.LN(value)
             credit = utility.LN(0)
             self.debt_sum += value
         else:
             credit = utility.LN(n.value)
             debt = utility.LN(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, n.id))
         
     docnum = utility.LN(self.cl_document.number)
     self.builder.get_object("docnumber").set_text (docnum)
     self.builder.get_object("debtsum").set_text (utility.LN(self.debt_sum))
     self.builder.get_object("creditsum").set_text (utility.LN(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.LN(diff))
Ejemplo n.º 2
0
    def viewProductGroups(self):
        self.window = self.builder.get_object("viewProGroupsWindow")

        self.treeview = self.builder.get_object("GroupsTreeView")
        self.treestore = Gtk.TreeStore(str, str, str, str)
        self.treestore.clear()
        self.treeview.set_model(self.treestore)

        column = Gtk.TreeViewColumn(_("Code"), Gtk.CellRendererText(), text=0)
        column.set_spacing(5)
        column.set_resizable(True)
        column.set_sort_column_id(0)
        column.set_sort_indicator(True)
        self.treeview.append_column(column)

        column = Gtk.TreeViewColumn(_("Name"), Gtk.CellRendererText(), text=1)
        column.set_spacing(5)
        column.set_resizable(True)
        column.set_sort_column_id(1)
        column.set_sort_indicator(True)
        self.treeview.append_column(column)

        column = Gtk.TreeViewColumn(_("Buy ID"),
                                    Gtk.CellRendererText(),
                                    text=2)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)

        column = Gtk.TreeViewColumn(_("Sell ID"),
                                    Gtk.CellRendererText(),
                                    text=3)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)

        self.treeview.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
        self.treestore.set_sort_column_id(0, Gtk.SortType.ASCENDING)

        #Fill groups treeview
        query = config.db.session.query(ProductGroups).select_from(
            ProductGroups)
        result = query.all()

        for group in result:
            code = group.code
            buyId = group.buyId
            sellId = group.sellId
            if config.digittype == 1:
                #code = utility.convertToPersian(code)
                buyId = utility.convertToPersian(buyId)
                sellId = utility.convertToPersian(sellId)
            self.treestore.append(
                None, (utility.readNumber(code), str(group.name),
                       utility.readNumber(buyId), utility.readNumber(sellId)))

        self.window.show_all()
        self.window.grab_focus()
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
    def editProductGroup(self, sender):
        dialog = self.builder.get_object("addProductGroupDlg")
        dialog.set_title(_("Edit group"))
        selection = self.treeview.get_selection()
        iter = selection.get_selected()[1]

        if iter != None:
            grpcode = unicode(self.treestore.get(iter, 0)[0])
            #if config.digittype == 1:
            #code = utility.convertToLatin(grpcode)
            #else:
            #code = grpcode

            BuySub = aliased(Subject, name="bs")
            SellSub = aliased(Subject, name="ss")

            query = config.db.session.query(ProductGroups, BuySub.code,
                                            SellSub.code)
            query = query.select_from(
                outerjoin(
                    outerjoin(ProductGroups, BuySub,
                              ProductGroups.buyId == BuySub.id), SellSub,
                    ProductGroups.sellId == SellSub.id))
            (group, buy_code,
             sell_code) = query.filter(ProductGroups.code == grpcode).first()
            name = group.name
            if config.digittype == 1:
                buy_code = utility.convertToPersian(buy_code)
                sell_code = utility.convertToPersian(sell_code)

            self.builder.get_object("groupCodeEntry").set_text(grpcode)
            self.builder.get_object("groupNameEntry").set_text(name)
            self.buyCodeEntry.set_text(buy_code)
            self.sellCodeEntry.set_text(sell_code)

            success = False
            while not success:
                result = dialog.run()
                if result == 1:
                    grpcode = self.builder.get_object(
                        "groupCodeEntry").get_text()
                    grpname = self.builder.get_object(
                        "groupNameEntry").get_text()
                    grpbuycode = self.buyCodeEntry.get_text()
                    grpsellcode = self.sellCodeEntry.get_text()
                    success = self.saveProductGroup(unicode(grpcode),
                                                    unicode(grpname),
                                                    grpbuycode, grpsellcode,
                                                    iter)
                else:
                    break

            dialog.hide()
Ejemplo n.º 5
0
    def editLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Edit Ledger"))
        selection = self.treeview.get_selection()
        iter = selection.get_selected()[1]

        if iter != None:
            if config.digittype == 1:
                code = utility.convertToLatin(self.treestore.get(iter, 0)[0])
                pcode = utility.convertToPersian(code[0:-2])
                ccode = utility.convertToPersian(code[-2:])
            else:
                code = self.treestore.get(iter, 0)[0]
                pcode = code[0:-2]
                ccode = code[-2:]
            self.builder.get_object("parentcode").set_text(pcode)
            self.code.set_text(ccode)

            name = self.treestore.get(iter, 1)[0]
            type = self.treestore.get(iter, 2)[0]
            debtor = False
            creditor = False
            both = False

            if type == self.__class__.subjecttypes[0]:
                self.builder.get_object("debtor").set_active(True)
            else:
                if type == self.__class__.subjecttypes[1]:
                    self.builder.get_object("creditor").set_active(True)
                else:
                    self.builder.get_object("both").set_active(True)
            #label = self.builder.get_object("label3")
            #label.set_text(name)
            entry = self.builder.get_object("ledgername")
            entry.set_text(name)

            hbox = self.builder.get_object("hbox3")
            hbox.hide()
            result = dialog.run()

            if result == 1:
                if self.builder.get_object("debtor").get_active() == True:
                    type = 0
                else:
                    if self.builder.get_object(
                            "creditor").get_active() == True:
                        type = 1
                    else:
                        type = 2
                self.saveLedger(unicode(entry.get_text()), type, iter, True,
                                dialog)
            dialog.hide()
Ejemplo n.º 6
0
    def viewProductGroups(self):
        self.window = self.builder.get_object("viewProGroupsWindow")
        
        self.treeview = self.builder.get_object("GroupsTreeView")
        self.treestore = gtk.TreeStore(str, str, str, str)
        self.treestore.clear()
        self.treeview.set_model(self.treestore)

        column = gtk.TreeViewColumn(_("Code"), gtk.CellRendererText(), text = 0)
        column.set_spacing(5)
        column.set_resizable(True)
        column.set_sort_column_id(0)
        column.set_sort_indicator(True)
        self.treeview.append_column(column)
        
        column = gtk.TreeViewColumn(_("Name"), gtk.CellRendererText(), text = 1)
        column.set_spacing(5)
        column.set_resizable(True)
        column.set_sort_column_id(1)
        column.set_sort_indicator(True)
        self.treeview.append_column(column)
        
        column = gtk.TreeViewColumn(_("Buy ID"), gtk.CellRendererText(), text = 2)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        
        column = gtk.TreeViewColumn(_("Sell ID"), gtk.CellRendererText(), text = 3)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        
        self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE)
        self.treestore.set_sort_column_id(0, gtk.SORT_ASCENDING)
        
        #Fill groups treeview
        query = config.db.session.query(ProductGroups).select_from(ProductGroups)
        result = query.all()
        
        for group in result:
	    code = group.code
	    buyId = group.buyId
	    sellId = group.sellId
            if config.digittype == 1:
                #code = utility.convertToPersian(code)
                buyId = utility.convertToPersian(buyId)
                sellId = utility.convertToPersian(sellId)
            self.treestore.append(None, (code, group.name, buyId, sellId))
            
        self.window.show_all()
        self.window.grab_focus()
Ejemplo n.º 7
0
 def editLedger(self, sender):
     dialog = self.builder.get_object("dialog1")
     dialog.set_title(_("Edit Ledger"))
     selection = self.treeview.get_selection()
     iter = selection.get_selected()[1]
     
     if iter != None :
         if config.digittype == 1:
             code = utility.convertToLatin(self.treestore.get(iter, 0)[0])
             pcode = utility.convertToPersian(code[0:-2])
             ccode = utility.convertToPersian(code[-2:])
         else:
             code = self.treestore.get(iter, 0)[0]
             pcode = code[0:-2]
             ccode = code[-2:]
         self.builder.get_object("parentcode").set_text(pcode)
         self.code.set_text(ccode)
         
         name = self.treestore.get(iter, 1)[0]
         type = self.treestore.get(iter, 2)[0]
         debtor = False
         creditor = False
         both = False
         
         if type == self.__class__.subjecttypes[0]:
             self.builder.get_object("debtor").set_active(True)
         else:
             if type == self.__class__.subjecttypes[1]:
                 self.builder.get_object("creditor").set_active(True)
             else :
                 self.builder.get_object("both").set_active(True) 
         #label = self.builder.get_object("label3")
         #label.set_text(name)
         entry = self.builder.get_object("ledgername")
         entry.set_text(name)
         
         hbox = self.builder.get_object("hbox3")
         hbox.hide()
         result = dialog.run()
         
         if result == 1 :
             if self.builder.get_object("debtor").get_active() == True:
                 type = 0
             else:
                 if  self.builder.get_object("creditor").get_active() == True:
                     type = 1
                 else:
                     type = 2
             self.saveLedger(unicode(entry.get_text()), type, iter, True, dialog)
         dialog.hide()
Ejemplo n.º 8
0
 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))
Ejemplo n.º 9
0
 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()
Ejemplo n.º 10
0
    def createPreviewJob(self):
        report = self.createReport()
        if report == None:
            return
        if len(report["data"]) == 0:
            msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
                                       _("The requested notebook is empty."))
            msgbox.set_title(_("Empty notebook"))
            msgbox.run()
            msgbox.destroy()
            return

        preview = previewreport.PreviewReport(report["data"],
                                              report["heading"])
        if self.type == self.__class__.DAILY:
            todaystr = dateToString(date.today())
            preview.setDrawFunction("drawDailyNotebook")
        else:
            if config.digittype == 1:
                code = utility.convertToPersian(self.subcode)
            else:
                code = self.subcode

            preview.setDrawFunction("drawSubjectNotebook")
        return preview
Ejemplo n.º 11
0
    def addLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Add Ledger"))
        hbox = self.builder.get_object("hbox3")
        hbox.hide()
        entry = self.builder.get_object("ledgername")
        entry.set_text("")

        query = config.db.session.query(
            Subject.code).select_from(Subject).order_by(Subject.id.desc())
        code = query.filter(Subject.parent_id == 0).first()
        if code == None:
            lastcode = "01"
        else:
            lastcode = "%02d" % (int(code[0][-2:]) + 1)

        if config.digittype == 1:
            lastcode = utility.convertToPersian(lastcode)
        self.code.set_text(lastcode)
        self.builder.get_object("parentcode").set_text("")

        #        dialog.show_all()
        result = dialog.run()
        if result == 1:
            if self.builder.get_object("debtor").get_active() == True:
                type = 0
            else:
                if self.builder.get_object("creditor").get_active() == True:
                    type = 1
                else:
                    type = 2

            self.saveLedger(unicode(entry.get_text()), type, None, False,
                            dialog)
        dialog.hide()
Ejemplo n.º 12
0
    def addLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Add Ledger"))
        hbox = self.builder.get_object("hbox3")
        hbox.hide()
        entry = self.builder.get_object("ledgername")
        entry.set_text("")
        
        query = config.db.session.query(Subject.code).select_from(Subject).order_by(Subject.id.desc())
        code = query.filter(Subject.parent_id == 0).first()
        if code == None :
            lastcode = "01"
        else:
            lastcode = "%02d" % (int(code[0][-2:]) + 1)
            
        if config.digittype == 1:
                lastcode = utility.convertToPersian(lastcode)
        self.code.set_text(lastcode)
        self.builder.get_object("parentcode").set_text("")
        
#        dialog.show_all()
        result = dialog.run()
        if result == 1 :
            if self.builder.get_object("debtor").get_active() == True:
                type = 0
            else:
                if self.builder.get_object("creditor").get_active() == True:
                    type = 1
                else:
                    type = 2
             
            self.saveLedger(unicode(entry.get_text()), type, None, False, dialog)
        dialog.hide()
Ejemplo n.º 13
0
 def createPrintJob(self):
     report = self.createReport()
     if report == None:
         return
     if len(report["data"]) == 0:
         msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, 
                                    _("The requested notebook is empty."))
         msgbox.set_title(_("Empty notebook"))
         msgbox.run()
         msgbox.destroy()
         return
     
     printjob = printreport.PrintReport(report["data"], report["col-width"], report["heading"])
     if self.type == self.__class__.DAILY:
         todaystr = dateToString(date.today())
         printjob.setHeader(_("Daily Notebook"), {_("Date"):todaystr})
         printjob.setDrawFunction("drawDailyNotebook")
     else:
         if config.digittype == 1:
             code = utility.convertToPersian(self.subcode)
         else:
             code = self.subcode
             
         if self.type == self.__class__.LEDGER:
             printjob.setHeader(_("Ledgers Notebook"), {_("Subject Name"):self.subname, _("Subject Code"):code})
         else:
             printjob.setHeader(_("Sub-ledgers Notebook"), {_("Subject Name"):self.subname, _("Subject Code"):code})
         printjob.setDrawFunction("drawSubjectNotebook")
     return printjob
Ejemplo n.º 14
0
 def editChildCodes(self, model, path, iter, data):
     basecode = data[0]
     length = data[1]
     chcode = model.get(iter, 0)[0]
     chcode = utility.convertToLatin(chcode)[length:]
     if config.digittype == 1:
         chcode = utility.convertToPersian(chcode)
     self.treestore.set(model.convert_iter_to_child_iter(iter), 0, basecode + chcode )
Ejemplo n.º 15
0
 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}
Ejemplo n.º 16
0
 def editChildCodes(self, model, path, iter, data):
     basecode = data[0]
     length = data[1]
     chcode = model.get(iter, 0)[0]
     chcode = utility.convertToLatin(chcode)[length:]
     if config.digittype == 1:
         chcode = utility.convertToPersian(chcode)
     self.treestore.set(model.convert_iter_to_child_iter(iter), 0,
                        basecode + chcode)
Ejemplo n.º 17
0
    def addSubLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Add Sub-ledger"))
        hbox = self.builder.get_object("hbox3")
        hbox.show()
        selection = self.treeview.get_selection()
        parent = selection.get_selected()[1]

        if parent != None:
            pcode = self.treestore.get(parent, 0)[0]
            self.builder.get_object("parentcode").set_text(pcode)
            pcode = utility.convertToLatin(pcode)

            query = config.db.session.query(Subject).select_from(Subject)
            query = query.filter(Subject.code == pcode)
            psub = query.first()

            #parentname = self.treestore.get(parent, 1)[0]
            label = self.builder.get_object("label3")
            label.set_text(psub.name)
            entry = self.builder.get_object("ledgername")
            entry.set_text("")

            query = config.db.session.query(
                Subject.code).select_from(Subject).order_by(Subject.id.desc())
            code = query.filter(Subject.parent_id == psub.id).first()
            if code == None:
                lastcode = "01"
            else:
                lastcode = "%02d" % (int(code[0][-2:]) + 1)

            if config.digittype == 1:
                lastcode = utility.convertToPersian(lastcode)
            self.code.set_text(lastcode)

            result = dialog.run()
            if result == 1:
                if self.builder.get_object("debtor").get_active() == True:
                    type = 0
                else:
                    if self.builder.get_object(
                            "creditor").get_active() == True:
                        type = 1
                    else:
                        type = 2

                self.saveLedger(unicode(entry.get_text()), type, parent, False,
                                dialog)
            dialog.hide()
        else:
            msgbox = gtk.MessageDialog(
                parent, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
                _("Please select an item from the list, to add subject for it."
                  ))
            msgbox.set_title(_("Select a subject"))
            msgbox.run()
            msgbox.destroy()
Ejemplo n.º 18
0
    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))
Ejemplo n.º 19
0
    def editProductGroup(self, sender):
        dialog = self.builder.get_object("addProductGroupDlg")
        dialog.set_title(_("Edit group"))
        selection = self.treeview.get_selection()
        iter = selection.get_selected()[1]
        
        if iter != None :
	    grpcode = unicode(self.treestore.get(iter, 0)[0])
            #if config.digittype == 1:
                #code = utility.convertToLatin(grpcode)
            #else:
                #code = grpcode
                
            BuySub = aliased(Subject, name="bs")
            SellSub = aliased(Subject, name="ss")
            
            query = config.db.session.query(ProductGroups, BuySub.code, SellSub.code)
            query = query.select_from( outerjoin( outerjoin(ProductGroups, BuySub, ProductGroups.buyId == BuySub.id),
                                                  SellSub, ProductGroups.sellId == SellSub.id ) )
            (group, buy_code, sell_code) = query.filter(ProductGroups.code == grpcode).first()
            name = group.name
            if config.digittype == 1:
		buy_code = utility.convertToPersian(buy_code)
		sell_code = utility.convertToPersian(sell_code)
            
            self.builder.get_object("groupCodeEntry").set_text(grpcode)
            self.builder.get_object("groupNameEntry").set_text(name)
            self.buyCodeEntry.set_text(buy_code)
            self.sellCodeEntry.set_text(sell_code)
            
            success = False
	    while not success :
		result = dialog.run()
		if result == 1:
		    grpcode = self.builder.get_object("groupCodeEntry").get_text()
		    grpname = self.builder.get_object("groupNameEntry").get_text()
		    grpbuycode = self.buyCodeEntry.get_text()
		    grpsellcode = self.sellCodeEntry.get_text()
		    success = self.saveProductGroup(unicode(grpcode), unicode(grpname), grpbuycode, grpsellcode, iter)
		else:
		    break
                
            dialog.hide()
Ejemplo n.º 20
0
    def showRows(self):
        self.debt_sum = 0
        self.credit_sum = 0
        self.numrows = 0

        self.date.showDateObject(self.cl_document.date)
        rows = self.cl_document.get_notebook_rows()
        for n, s in rows:
            self.numrows += 1
            if n.value < 0:
                value = -(n.value)
                debt = utility.LN(value)
                credit = utility.LN(0)
                self.debt_sum += value
            else:
                credit = utility.LN(n.value)
                debt = utility.LN(0)
                self.credit_sum += n.value

            if s:
                code = s.code
            else:
                code = 0
                s = Subject()
            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, str(n.id)))

        docnum = utility.LN(self.cl_document.number)
        self.builder.get_object("docnumber").set_text(docnum)
        self.builder.get_object("debtsum").set_text(utility.LN(self.debt_sum))
        self.builder.get_object("creditsum").set_text(
            utility.LN(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.LN(diff))
Ejemplo n.º 21
0
    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
Ejemplo n.º 22
0
 def addSubLedger(self, sender):
     dialog = self.builder.get_object("dialog1")
     dialog.set_title(_("Add Sub-ledger"))
     hbox = self.builder.get_object("hbox3")
     hbox.show()
     selection = self.treeview.get_selection()
     parent = selection.get_selected()[1]
     
     if parent != None :
         pcode = self.treestore.get(parent, 0)[0]
         self.builder.get_object("parentcode").set_text(pcode)
         pcode = utility.convertToLatin(pcode)
         
         query = config.db.session.query(Subject).select_from(Subject)
         query = query.filter(Subject.code == pcode)
         psub = query.first()
         
         #parentname = self.treestore.get(parent, 1)[0]
         label = self.builder.get_object("label3")
         label.set_text(psub.name)
         entry = self.builder.get_object("ledgername")
         entry.set_text("")
         
         query = config.db.session.query(Subject.code).select_from(Subject).order_by(Subject.id.desc())
         code = query.filter(Subject.parent_id == psub.id).first()
         if code == None :
             lastcode = "01"
         else :
             lastcode = "%02d" % (int(code[0][-2:]) + 1)
             
         if config.digittype == 1:
             lastcode = utility.convertToPersian(lastcode) 
         self.code.set_text(lastcode)
         
         result = dialog.run()
         if result == 1 :
             if self.builder.get_object("debtor").get_active() == True:
                 type = 0
             else:
                 if self.builder.get_object("creditor").get_active() == True:
                     type = 1
                 else:
                     type = 2
                 
             self.saveLedger(unicode(entry.get_text()), type, parent, False, dialog)
         dialog.hide()
     else :
         msgbox =  gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
                                 _("Please select an item from the list, to add subject for it."))
         msgbox.set_title(_("Select a subject"))
         msgbox.run()
         msgbox.destroy()
Ejemplo n.º 23
0
 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))
Ejemplo n.º 24
0
 def createPreviewJob(self):
     report = self.createReport()
     if report == None:
         return
     #if len(report["data"]) == 0:
     datestr = dateToString(self.docdate)
     docnumber = self.docnumber
     if config.digittype == 1:
         docnumber = utility.convertToPersian(docnumber)
         
     preview = previewreport.PreviewReport(report["data"], report["heading"])
     #preview.setHeader(_("Accounting Document"), {_("Document Number"):docnumber, _("Date"):datestr})
     preview.setDrawFunction("drawDocument")
     return preview
Ejemplo n.º 25
0
 def showDate(self, year, month, day):
     datelist = ["", "", ""]
     datelist[config.datefields["year"]] = year
     datelist[config.datefields["month"]] = month
     datelist[config.datefields["day"]] = day
     
     delim = config.datedelims[config.datedelim]
     datestring = str(datelist[0]) + delim + str(datelist[1]) + delim + str(datelist[2])
     if config.digittype == 1:
         datestring = utility.convertToPersian(datestring)
     self.set_text(datestring)
     self.year = year
     self.month = month
     self.day = day
Ejemplo n.º 26
0
    def showDate(self, year, month, day):
        datelist = ["", "", ""]
        datelist[config.datefields["year"]] = year
        datelist[config.datefields["month"]] = month
        datelist[config.datefields["day"]] = day

        delim = config.datedelims[config.datedelim]
        datestring = str(datelist[0]) + delim + str(datelist[1]) + delim + str(
            datelist[2])
        if config.digittype == 1:
            datestring = utility.convertToPersian(datestring)
        self.set_text(datestring)
        self.year = year
        self.month = month
        self.day = day
Ejemplo n.º 27
0
def dateToString(date):
    if config.datetypes[config.datetype] == "jalali":
        jd = DateEntry.cal.gregorian_to_jd(date.year, date.month, date.day)
        (year, month, day) = DateEntry.cal.jd_to_jalali(jd)
    else:
        (year, month, day) = (date.year, date.month, date.day)
        
    datelist = ["", "", ""]
    datelist[config.datefields["year"]] = year
    datelist[config.datefields["month"]] = month
    datelist[config.datefields["day"]] = day
        
    delim = config.datedelims[config.datedelim]
    datestring = str(datelist[0]) + delim + str(datelist[1]) + delim + str(datelist[2])
    if config.digittype == 1:
        datestring = utility.convertToPersian(datestring)
    return datestring
Ejemplo n.º 28
0
    def createPrintJob(self):
        report = self.createReport()
        if report == None:
            return
        if len(report["data"]) == 0:
            msgbox = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL,
                                       Gtk.MessageType.INFO,
                                       Gtk.ButtonsType.OK,
                                       _("The requested notebook is empty."))
            msgbox.set_title(_("Empty notebook"))
            msgbox.run()
            msgbox.destroy()
            return
        report_header = report['heading']
        report_data = report['data']
        col_width = report['col-width']
        if self.type == self.__class__.DAILY:
            todaystr = dateToString(date.today())
            html = '<p ' + self.reportObj.subjectHeaderStyle + '><u>' + _(
                "Daily NoteBook"
            ) + '</u></p><p ' + self.reportObj.detailHeaderStyle + '>' + _(
                "Date") + ': ' + todaystr + '</p>'
        else:
            if config.digittype == 1:
                code = utility.convertToPersian(self.subcode)
            else:
                code = self.subcode

            if self.type == self.__class__.LEDGER:
                html = '<p ' + self.reportObj.subjectHeaderStyle + '><u>' + _(
                    "Ledgers Notebook"
                ) + '</u></p><p style="text-align:center;">' + _(
                    "Subject Name"
                ) + ': ' + self.subname + '</p><p ' + self.reportObj.detailHeaderStyle + '>' + _(
                    "Subject Code") + ': ' + code + '</p>'
            else:
                html = '<p ' + self.reportObj.subjectHeaderStyle + '><u>' + _(
                    "Sub-ledgers Notebook"
                ) + '</u></p><p style="text-align:center;">' + _(
                    "Subject Name"
                ) + ': ' + self.subname + '</p><p ' + self.reportObj.detailHeaderStyle + '>' + _(
                    "Subject Code") + ': ' + code + '</p>'
        html += self.reportObj.createTable(report_header, report_data,
                                           col_width)

        return html
Ejemplo n.º 29
0
def dateToString(date):
    if config.datetypes[config.datetype] == "jalali":
        jd = DateEntry.cal.gregorian_to_jd(date.year, date.month, date.day)
        (year, month, day) = DateEntry.cal.jd_to_jalali(jd)
    else:
        (year, month, day) = (date.year, date.month, date.day)

    datelist = ["", "", ""]
    datelist[config.datefields["year"]] = year
    datelist[config.datefields["month"]] = month
    datelist[config.datefields["day"]] = day

    delim = config.datedelims[config.datedelim]
    datestring = str(datelist[0]) + delim + str(datelist[1]) + delim + str(
        datelist[2])
    if config.digittype == 1:
        datestring = utility.convertToPersian(datestring)
    return datestring
Ejemplo n.º 30
0
    def deleteRow(self, sender):
        selection = self.treeview.get_selection()
        iter = selection.get_selected()[1]
        if iter != None:
            msgbox = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL,
                                       Gtk.MessageType.WARNING,
                                       Gtk.ButtonsType.OK_CANCEL,
                                       _("Are you sure to remove this row?"))
            msgbox.set_title(_("Are you sure?"))
            result = msgbox.run()
            if result == Gtk.ResponseType.OK:
                id = int(unicode(self.liststore.get(iter, 6)[0]))
                code = int(unicode(self.liststore.get(iter, 1)[0]))
                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)
                self.deleted_items.append(id)
                #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.LN(self.debt_sum))
                self.builder.get_object("creditsum").set_text(
                    utility.LN(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.LN(diff))
            msgbox.destroy()
Ejemplo n.º 31
0
    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()
Ejemplo n.º 32
0
 def subjectSelected(self, sender, id, code, name):
     if config.digittype == 1:
         code = utility.convertToPersian(code)
     self.code.set_text(code)
     self.builder.get_object("nameLbl").set_text(name)
     q = config.db.session.query(func.sum(
         Notebook.value)).filter(Notebook.subject_id == id)
     if q.first()[0]:
         val = q.first()[0]
     else:
         val = 0
     self.builder.get_object("remainLbl").set_text(
         utility.readNumber(abs(val)))
     subType = ""
     if val < 0:
         subType = _("Debtor")
     elif val > 0:
         subType = _("Creditor")
     self.builder.get_object("subTypeLbl").set_text(subType)
     sender.window.destroy()
Ejemplo n.º 33
0
 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
Ejemplo n.º 34
0
    def createPrintJob(self):
        report = self.createReport()
        if report == None:
            return
        if len(report["data"]) == 0:
            msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
                                       _("The requested notebook is empty."))
            msgbox.set_title(_("Empty notebook"))
            msgbox.run()
            msgbox.destroy()
            return

        printjob = printreport.PrintReport(report["data"], report["col-width"],
                                           report["heading"])
        if self.type == self.__class__.DAILY:
            todaystr = dateToString(date.today())
            printjob.setHeader(_("Daily Notebook"), {_("Date"): todaystr})
            printjob.setDrawFunction("drawDailyNotebook")
        else:
            if config.digittype == 1:
                code = utility.convertToPersian(self.subcode)
            else:
                code = self.subcode

            if self.type == self.__class__.LEDGER:
                printjob.setHeader(_("Ledgers Notebook"), {
                    _("Subject Name"): self.subname,
                    _("Subject Code"): code
                })
            else:
                printjob.setHeader(_("Sub-ledgers Notebook"), {
                    _("Subject Name"): self.subname,
                    _("Subject Code"): code
                })
            printjob.setDrawFunction("drawSubjectNotebook")
        return printjob
Ejemplo n.º 35
0
 def createPreviewJob(self):
     report = self.createReport()
     if report == None:
         return
     if len(report["data"]) == 0:
         msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, 
                                    _("The requested notebook is empty."))
         msgbox.set_title(_("Empty notebook"))
         msgbox.run()
         msgbox.destroy()
         return
         
     preview = previewreport.PreviewReport(report["data"], report["heading"])
     if self.type == self.__class__.DAILY:
         todaystr = dateToString(date.today())
         preview.setDrawFunction("drawDailyNotebook")
     else:
         if config.digittype == 1:
             code = utility.convertToPersian(self.subcode)
         else:
             code = self.subcode
             
         preview.setDrawFunction("drawSubjectNotebook")
     return preview
Ejemplo n.º 36
0
    def saveProductGroup(self, code, name, buy_code, sell_code, edititer=None):
        msg = ""
        if code == "":
            msg += _("Group code should not be empty.\n")
        if name == "":
            msg = _("Group name should not be empty.\n")
        #TODO set default values for buyid & sellid if empty
            
        if msg != "":
            msgbox =  gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE, msg)
            msgbox.set_title(_("Empty fields"))
            msgbox.run()
            msgbox.destroy()
            return False
        
        if edititer != None:
            pcode = unicode(self.treestore.get_value(edititer, 0))
            #pcode = utility.convertToLatin(pcode)
            query = config.db.session.query(ProductGroups).select_from(ProductGroups)
            group = query.filter(ProductGroups.code == pcode).first()
            gid = group.id
        
        #code = utility.convertToLatin(code)
        buy_code = utility.convertToLatin(buy_code)
        sell_code = utility.convertToLatin(sell_code)
        
        #Checks if the group name or code is repeated.
        query = config.db.session.query(ProductGroups).select_from(ProductGroups)
        query = query.filter(or_(ProductGroups.code == code, ProductGroups.name == name))
        if edititer != None:
            query = query.filter(ProductGroups.id != gid)
        result = query.all()
        msg = ""
        for grp in result:
            if grp.code == code:
                msg += _("A group with this code already exists.\n")
                break
            elif grp.name == name:
                msg += _("A group with this name already exists.\n")
                break
        
        #Check if buy_code & sell_code are valid
        #TODO Check if buying subject is creditor/debtor, and so for selling one.
        query = config.db.session.query(Subject).select_from(Subject)
        buy_sub = query.filter(Subject.code == buy_code).first()
        if buy_sub == None:
	    msg += _("Buying code is not valid.\n")
        
        query = config.db.session.query(Subject).select_from(Subject)
        sell_sub = query.filter(Subject.code == sell_code).first()
        if sell_sub == None:
	    msg += _("Selling code is not valid.\n")
	    
        if msg != "":
            msgbox =  gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg)
            msgbox.set_title(_("Invalid group properties"))
            msgbox.run()
            msgbox.destroy()
            return False
            
        if edititer == None:
            group = ProductGroups(code, name, buy_sub.id, sell_sub.id)
            
            edititer = self.treestore.append(None)
            path = self.treestore.get_path(edititer)
            self.treeview.scroll_to_cell(path, None, False, 0, 0)
            self.treeview.set_cursor(path, None, False)
        else:
            group.code = code
            group.name = name
            group.buyId = buy_sub.id
            group.sellId = sell_sub.id
            
        config.db.session.add(group)
        config.db.session.commit()
        
        if config.digittype == 1:
            #code = utility.convertToPersian(code)
            buy_code = utility.convertToPersian(buy_code)
            sell_code = utility.convertToPersian(sell_code)
        self.saveRow(edititer, (code, name, buy_code, sell_code))
        return True
Ejemplo n.º 37
0
    def __init__(self, number=0):
        self.builder = get_builder("document")
        
        self.window = self.builder.get_object("window1")
        self.window.set_title(_("Register new document"))
        
        self.date = dateentry.DateEntry()
        box = self.builder.get_object("datebox")
        box.add(self.date)
        self.date.show()
        
        self.code = numberentry.NumberEntry()
        box = self.builder.get_object("codebox")
        box.add(self.code)
        self.code.show()
        self.code.connect("activate", self.selectSubject)
        self.code.set_tooltip_text(_("Press Enter to see available subjects."))
        
        self.amount = numberentry.NumberEntry()
        box = self.builder.get_object("amountbox")
        box.add(self.amount)
        self.amount.set_activates_default(True)
        self.amount.show()
        
        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.liststore = gtk.ListStore(str, str, str, str, str, str)
        
        column = gtk.TreeViewColumn(_("Index"), 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 Code"), gtk.CellRendererText(), text=1)
        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=2)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        
        money_cell_renderer = gtk.CellRendererText()
        #money_cell_renderer.set_alignment(1.0, 0.5) #incompatible with pygtk2.16
        
        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Debt"), money_cell_renderer, text=3)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Credit"), money_cell_renderer, text=4)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Description"), gtk.CellRendererText(), text=5)
        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.session = config.db.session
        self.debt_sum = 0
        self.credit_sum = 0
        self.numrows = 0
        self.permanent = False 
        
        if number > 0:
            query = config.db.session.query(Bill).select_from(Bill)
            bill = query.filter(Bill.number == number).first()
            self.docnumber = number
            if bill == None:
                numstring = str(number)
                if config.digittype == 1:
                    numstring = utility.convertToPersian(numstring)
                msg = _("No document found with number %s\nDo you want to register a document with this number?") % numstring
                msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK_CANCEL, msg)
                msgbox.set_title(_("No Documents found"))
                result = msgbox.run()
                msgbox.destroy()
                if result == gtk.RESPONSE_CANCEL:
                    return
                else:
                    self.docid = 0
                    docnum = str(self.docnumber)
                    if config.digittype == 1:
                        docnum = utility.convertToPersian(docnum)
                    self.builder.get_object("docnumber").set_text (docnum)
            else:
                self.showRows(number)
                self.permanent = bill.permanent
                self.window.set_title(_("Edit document"))
        else:
            self.docnumber = 0
            self.docid = 0
    
        self.treeview.set_model(self.liststore)
        self.window.show_all()
        if self.permanent:
            self.builder.get_object("editable").hide()
            self.builder.get_object("non-editable").show()
        else:
            self.builder.get_object("editable").show()
            self.builder.get_object("non-editable").hide()
        
        self.builder.connect_signals(self)
Ejemplo n.º 38
0
    def saveCustGroup(self, code, name, desc, edititer=None):
        msg = ""
        if name == "":
            msg = _("Group name should not be empty")
        elif code == "":
            msg = _("Group code should not be empty")

        if msg != "":
            msgbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE,
                                       msg)
            msgbox.set_title(_("Empty fields"))
            msgbox.run()
            msgbox.destroy()
            return

        if edititer != None:
            pcode = self.treestore.get_value(edititer, 0)
            pcode = utility.convertToLatin(pcode)
            query = config.db.session.query(CustGroups).select_from(CustGroups)
            group = query.filter(CustGroups.custGrpCode == pcode).first()
            gid = group.custGrpId

        code = utility.convertToLatin(code)
        query = config.db.session.query(CustGroups).select_from(CustGroups)
        query = query.filter(
            or_(CustGroups.custGrpCode == code,
                CustGroups.custGrpName == name))
        if edititer != None:
            query = query.filter(CustGroups.custGrpId != gid)
        result = query.all()
        msg = ""
        for grp in result:
            if grp.custGrpCode == code:
                msg = _("A group with this code already exists.")
                break
            elif grp.custGrpName == name:
                msg = _("A group with this name already exists.")
                break
        if msg != "":
            msgbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                                       msg)
            msgbox.set_title(_("Duplicate group"))
            msgbox.run()
            msgbox.destroy()
            return

        if edititer == None:
            group = CustGroups(code, name, desc)

            edititer = self.treestore.append(None)
            path = self.treestore.get_path(edititer)
            self.treeview.scroll_to_cell(path, None, False, 0, 0)
            self.treeview.set_cursor(path, None, False)
        else:
            group.custGrpCode = code
            group.custGrpName = name
            group.custGrpDesc = desc

        config.db.session.add(group)
        config.db.session.commit()

        if config.digittype == 1:
            code = utility.convertToPersian(code)
        self.saveRow(edititer, (code, name, desc))
Ejemplo n.º 39
0
    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)
Ejemplo n.º 40
0
 def saveDocument(self, sender):
     sender.grab_focus()
     if self.numrows == 0:
         msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, 
                                    _("Document should not be empty"))
         msgbox.set_title(_("Can not save document"))
         msgbox.run()
         msgbox.destroy()
         return
     
     iter = self.liststore.get_iter_first()
     debt_sum = 0
     credit_sum = 0
     while iter != None :
         value = unicode(self.liststore.get(iter, 3)[0].replace(",", ""))
         debt_sum += int(value)
         value = unicode(self.liststore.get(iter, 4)[0].replace(",", ""))
         credit_sum += int(value)
         iter = self.liststore.iter_next(iter)
             
     if debt_sum != credit_sum:        
         msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, 
                                    _("Debt sum and Credit sum should be equal"))
         msgbox.set_title(_("Can not save document"))
         msgbox.run()
         msgbox.destroy()
         return
     else:
         #number = 0
         today = date.today()
         if self.docid > 0 :
             query = config.db.session.query(Bill).select_from(Bill)
             bill = query.filter(Bill.id == self.docid).first()
             bill.lastedit_date = today
             bill.date = self.date.getDateObject()
             #number = bill.number
             query = config.db.session.query(Notebook).filter(Notebook.bill_id == bill.id).delete()
         else :
             if self.docnumber == 0:
                 number = 0
                 query = config.db.session.query(Bill.number).select_from(Bill)
                 lastnumbert = query.order_by(Bill.number.desc()).first()
                 if lastnumbert != None:
                     number = lastnumbert[0]
                 self.docnumber = number + 1
             
             #TODO if number is not equal to the maximum BigInteger value, prevent bill registration.
             bill = Bill (self.docnumber, today, today, self.date.getDateObject(), False)
             config.db.session.add(bill)
             config.db.session.commit()
             self.docid = bill.id
             
         iter = self.liststore.get_iter_first()
         
         while iter != None :
             code = utility.convertToLatin(self.liststore.get(iter, 1)[0])
             debt = unicode(self.liststore.get(iter, 3)[0].replace(",", ""))
             value = -(int(debt))
             if value == 0 :
                 credit = unicode(self.liststore.get(iter, 4)[0].replace(",", ""))
                 value = int(credit)
             desctxt = unicode(self.liststore.get(iter, 5)[0])
             
             query = config.db.session.query(Subject).select_from(Subject)
             query = query.filter(Subject.code == code)
             sub = query.first().id
             
             row = Notebook (sub, self.docid, value, desctxt)
             config.db.session.add(row)
             iter = self.liststore.iter_next(iter)
             
         config.db.session.commit()
         docnum = str(self.docnumber)
         if config.digittype == 1:
             docnum = utility.convertToPersian(docnum)
         self.builder.get_object("docnumber").set_text (docnum)
         
         msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, 
                                    _("Document saved with number %s.") % docnum)
         msgbox.set_title(_("Successfully saved"))
         msgbox.run()
         msgbox.destroy()
Ejemplo n.º 41
0
	def editProductsAndGrps(self, sender):
		selection = self.treeview.get_selection()
		iter = selection.get_selected()[1]
		
		if iter != None:
			if self.treestore.iter_parent(iter) == None:
			#iter points to a product group
				self.editProductGroup(sender)
			else:
			#iter points to a product
				dialog = self.builder.get_object("addProductDlg")
				dialog.set_title(_("Edit Product"))
				
				code = self.treestore.get_value(iter, 0)
				query = config.db.session.query(Products, ProductGroups.code)
				query = query.select_from(outerjoin(ProductGroups, Products, ProductGroups.id == Products.accGroup))
				result = query.filter(Products.code == code).first()
				product = result[0]
				groupcode = result[1]
				
				quantity = str(product.quantity)
				quantity_warn = str(product.qntyWarning)
				p_price = str(product.purchacePrice)
				s_price = str(product.sellingPrice)
				if config.digittype == 1:
					quantity = utility.convertToPersian(quantity)
					quantity_warn = utility.convertToPersian(quantity_warn)
					p_price = utility.convertToPersian(p_price)
					s_price = utility.convertToPersian(s_price)
				
				self.builder.get_object("proCodeEntry").set_text(product.code)
				self.builder.get_object("accGrpEntry" ).set_text(groupcode)
				self.builder.get_object("proNameEntry").set_text(product.name)
				self.builder.get_object("proLocEntry" ).set_text(product.location)
				self.builder.get_object("proDescEntry").set_text(product.productDesc)
				self.builder.get_object("discFormulaEntry").set_text(product.discountFormula)
				self.qntyEntry.set_text(quantity)
				self.qntyWrnEntry.set_text(quantity_warn)
				self.purchPriceEntry.set_text(p_price)
				self.sellPriceEntry.set_text(s_price)
				self.builder.get_object("oversell").set_active(product.oversell)
				
				success = False
				while not success :
					result = dialog.run()
					if result == 1:
						code     = unicode(self.builder.get_object("proCodeEntry").get_text())
						accgrp   = unicode(self.builder.get_object("accGrpEntry" ).get_text())
						name     = unicode(self.builder.get_object("proNameEntry").get_text())
						location = unicode(self.builder.get_object("proLocEntry" ).get_text())
						desc     = unicode(self.builder.get_object("proDescEntry").get_text())
						formula  = unicode(self.builder.get_object("discFormulaEntry").get_text())
						quantity = self.qntyEntry.get_float()
						q_warn   = self.qntyWrnEntry.get_float()
						p_price  = self.purchPriceEntry.get_float()
						s_price  = self.sellPriceEntry.get_float()
						oversell = self.builder.get_object("oversell").get_active()
					
						success = self.saveProduct(code, accgrp, name, location, desc, quantity, q_warn, p_price, s_price, oversell, formula, iter)
					else:
						break
				
				dialog.hide()
Ejemplo n.º 42
0
    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)
Ejemplo n.º 43
0
    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)
Ejemplo n.º 44
0
    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)
Ejemplo n.º 45
0
    def createReport(self, printFlag=True):
        number = utility.convertToLatin(unicode(self.number.get_text()))

        if re.match('^\d+$', number) != None:
            self.docnumbers = [int(number)]
        elif re.match('^(\d+)-(\d+)$', number) != None:
            m = re.match('^(\d+)-(\d+)$', number)
            self.docnumbers = range(int(m.group(1)), int(m.group(2)) + 1)
        else:
            self.builder.get_object("message").set_text(
                _("Please enter number in correct format \nTrue Formats: '2-11' or '2'  "
                  ))
            return

        self.builder.get_object("message").set_text("")

        if printFlag:  # preparing data for csv file
            report_header = [
                _("Index"),
                _("Subject Code"),
                _("Subject Name"),
                _("Description"),
                _("Debt"),
                _("Credit")
            ]
        else:
            report_header = [
                _("Doc."),
                _("Index"),
                _("Subject Code"),
                _("Subject Name"),
                _("Description"),
                _("Debt"),
                _("Credit"),
                _("Date")
            ]

        html = ""
        bill_ids = []
        bills = config.db.session.query(Bill).filter(
            Bill.number.in_(self.docnumbers)).order_by(
                Bill.number.asc()).all()
        for bill in bills:
            bill_ids.append(bill.id)

        query = config.db.session.query(Notebook, Subject).select_from(
            outerjoin(
                Notebook, Subject, Notebook.subject_id == Subject.id)).filter(
                    Notebook.bill_id.in_(bill_ids)).order_by(Notebook.id.asc())
        res = query.all()
        if len(res) == 0:
            msgbox = Gtk.MessageDialog(
                self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR,
                Gtk.ButtonsType.OK,
                _("No document found with the requested number."))
            msgbox.set_title(_("Invalid document number"))
            msgbox.run()
            msgbox.destroy()
            return
        if config.locale == 'en_US':
            doDirection = 'left'
            daDirection = 'right'
            text_align = "left"
        else:
            report_header = report_header[::-1]
            doDirection = 'right'
            daDirection = 'left'
            text_align = "right"
        todaystr = dateToString(date.today())
        billCount = 1
        table_h = 8

        for b in bills:
            if printFlag:
                report_data = [("", "", "", "", "", "")] * table_h
            else:
                report_data = [("", "", "", "", "", "", "", "")]
            query = config.db.session.query(Notebook, Subject).select_from(
                outerjoin(Notebook, Subject,
                          Notebook.subject_id == Subject.id)).filter(
                              Notebook.bill_id == b.id).order_by(
                                  Notebook.id.asc())
            res = query.all()

            docdate = b.date
            index = 1
            debt_sum = credit_sum = 0
            datestr = dateToString(docdate)
            docnumber = b.number
            if config.digittype == 1:
                docnumber = utility.convertToPersian(docnumber)

            for n, s in res:
                desc = n.desc
                if n.value < 0:
                    credit = utility.LN(0)
                    debt = utility.LN(-(n.value))
                else:
                    credit = utility.LN(n.value)
                    debt = utility.LN(0)
                    desc = "   " + desc

                code = utility.LN(s.code)
                doc_number = utility.LN(b.number)

                debt_sum += utility.getFloatNumber(debt)
                credit_sum += utility.getFloatNumber(credit)
                if printFlag:
                    if index < table_h:
                        report_data[index - 1] = (utility.LN(index, 0), code,
                                                  s.name, desc, debt, credit)
                    else:
                        report_data.append(
                            (utility.LN(index,
                                        0), code, s.name, desc, debt, credit))
                else:
                    if index < table_h:
                        report_data[index - 1] = (doc_number,
                                                  utility.LN(index,
                                                             0), code, s.name,
                                                  desc, debt, credit, datestr)
                    else:
                        report_data.append(
                            (doc_number, utility.LN(index, 0), code, s.name,
                             desc, debt, credit, datestr))
                index += 1

            if not printFlag:  # preparing data for csv file
                continue

            col_width = [19, 25, 45, 250, 40, 40]
            for i in range(0, len(report_header)):
                col_width[i] = 'style="width:' + str(col_width[i]) + 'pt" '
            i = 0
            html += '<p ' + self.reportObj.subjectHeaderStyle + '><b>' + _(
                "Accounting Document") + '</b></p>\
                <div style="text-align:' + doDirection + '; font-size:12px;float:' + doDirection + '">' + _(
                    "Document Number") + ': ' + str(docnumber) + '</div>\
                <div style="text-align:' + daDirection + '; font-size:12px;float:' + daDirection + '">' + _(
                        "Date") + ': ' + todaystr + '</div> <br/>'
            html += '<table class="notebooks"><thead><tr>'
            if config.locale == 'en_US':
                for header in report_header:
                    html += '<th ' + col_width[i] + '>' + header + '</th>'
                    i += 1
                html += '</tr></thead><tbody>'
                for row in report_data:
                    html += '<tr>'
                    for data in row:
                        html += '<td>' + str(data) + '</td>'
                    html += '</tr>'
            else:
                col_width = col_width[::-1]
                for header in report_header:
                    html += '<th ' + col_width[i] + '>' + header + '</th>'
                    i += 1
                html += '</tr></thead><tbody>'
                for row in report_data:
                    row = row[::-1]
                    html += '<tr>'
                    for data in row:
                        html += '<td>' + str(data) + '</td>'
                    html += '</tr>'
            row = [
                '<td colspan="4" >' + unicode(_("Total") + '</td>'),
                '<td>' + unicode(utility.LN(debt_sum) + '</td>'),
                '<td>' + unicode(utility.LN(credit_sum)) + '</td>'
            ]
            signaturesRow = [
                unicode(_("Accounting")),
                unicode(_("Financial Manager")),
                unicode(_("Managing Director"))
            ]
            if config.locale != 'en_US':
                row = row[::-1]
                signaturesRow = signaturesRow[::-1]
            html += '<tr style="border:1px solid black;">' + row[0] + row[
                1] + row[2] + '</tr>'
            html += '</tbody></table> <br/><br/>'
            html += '<table class="signatures" > \
                    <tr style="border:0px" ><td>' + signaturesRow[
                0] + '</td> <td>' + signaturesRow[
                    1] + '</td> <td>' + signaturesRow[2] + '</td> </tr>\
                    <tr></tr> \
                    </table>'

            billCount += 1
            if billCount <= len(bills):
                html += '<p style="page-break-before: always" ></p>'
            report_data = []

        if not printFlag:
            return {"data": report_data, "heading": report_header}

        html = '<!DOCTYPE html> <html> <head> \
                <style> @font-face {font-family: "Vazir"; src: url(data/font/Vazir.woff); }\
                table {border-collapse: collapse;  text-align:' + text_align + '; width:100%; } \
                th {border:1px solid black; padding: 10px;font-size:10px;}\
                thead {display: table-header-group;} \
                .notebooks td {border-left:1px solid; border-right:1px solid; padding: 10px;font-size:10px;} \
                .signatures {border:0px; font-size:14px; text-align:center}\
                body {font-family: "Vazir"} \
                </style> <meta charset="UTF-8"> </head> <body>' + html + '</body> </html>'
        return html
Ejemplo n.º 46
0
    def saveDocument(self, sender):
        sender.grab_focus()
        if self.numrows == 0:
            msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                                       _("Document should not be empty"))
            msgbox.set_title(_("Can not save document"))
            msgbox.run()
            msgbox.destroy()
            return

        iter = self.liststore.get_iter_first()
        debt_sum = 0
        credit_sum = 0
        while iter != None:
            value = unicode(self.liststore.get(iter, 3)[0].replace(",", ""))
            debt_sum += int(value)
            value = unicode(self.liststore.get(iter, 4)[0].replace(",", ""))
            credit_sum += int(value)
            iter = self.liststore.iter_next(iter)

        if debt_sum != credit_sum:
            msgbox = gtk.MessageDialog(
                self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
                gtk.BUTTONS_OK, _("Debt sum and Credit sum should be equal"))
            msgbox.set_title(_("Can not save document"))
            msgbox.run()
            msgbox.destroy()
            return
        else:
            #number = 0
            today = date.today()
            if self.docid > 0:
                query = config.db.session.query(Bill).select_from(Bill)
                bill = query.filter(Bill.id == self.docid).first()
                bill.lastedit_date = today
                bill.date = self.date.getDateObject()
                #number = bill.number
                query = config.db.session.query(Notebook).filter(
                    Notebook.bill_id == bill.id).delete()
            else:
                if self.docnumber == 0:
                    number = 0
                    query = config.db.session.query(
                        Bill.number).select_from(Bill)
                    lastnumbert = query.order_by(Bill.number.desc()).first()
                    if lastnumbert != None:
                        number = lastnumbert[0]
                    self.docnumber = number + 1

                #TODO if number is not equal to the maximum BigInteger value, prevent bill registration.
                bill = Bill(self.docnumber, today, today,
                            self.date.getDateObject(), False)
                config.db.session.add(bill)
                config.db.session.commit()
                self.docid = bill.id

            iter = self.liststore.get_iter_first()

            while iter != None:
                code = utility.convertToLatin(self.liststore.get(iter, 1)[0])
                debt = unicode(self.liststore.get(iter, 3)[0].replace(",", ""))
                value = -(int(debt))
                if value == 0:
                    credit = unicode(
                        self.liststore.get(iter, 4)[0].replace(",", ""))
                    value = int(credit)
                desctxt = unicode(self.liststore.get(iter, 5)[0])

                query = config.db.session.query(Subject).select_from(Subject)
                query = query.filter(Subject.code == code)
                sub = query.first().id

                row = Notebook(sub, self.docid, value, desctxt)
                config.db.session.add(row)
                iter = self.liststore.iter_next(iter)

            config.db.session.commit()
            docnum = str(self.docnumber)
            if config.digittype == 1:
                docnum = utility.convertToPersian(docnum)
            self.builder.get_object("docnumber").set_text(docnum)

            msgbox = gtk.MessageDialog(
                self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO,
                gtk.BUTTONS_OK,
                _("Document saved with number %s.") % docnum)
            msgbox.set_title(_("Successfully saved"))
            msgbox.run()
            msgbox.destroy()
Ejemplo n.º 47
0
 def subjectSelected(self, sender, id, code, name):
     if config.digittype == 1:
         code = utility.convertToPersian(code)
     self.code.set_text(code)
     sender.window.destroy()
Ejemplo n.º 48
0
    def __init__(self, number=0):
        self.builder = get_builder("document")

        self.window = self.builder.get_object("window1")
        self.window.set_title(_("Register new document"))

        self.date = dateentry.DateEntry()
        box = self.builder.get_object("datebox")
        box.add(self.date)
        self.date.show()

        self.code = numberentry.NumberEntry()
        box = self.builder.get_object("codebox")
        box.add(self.code)
        self.code.show()
        self.code.connect("activate", self.selectSubject)
        self.code.set_tooltip_text(_("Press Enter to see available subjects."))

        self.amount = numberentry.NumberEntry()
        box = self.builder.get_object("amountbox")
        box.add(self.amount)
        self.amount.set_activates_default(True)
        self.amount.show()

        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.liststore = gtk.ListStore(str, str, str, str, str, str)

        column = gtk.TreeViewColumn(_("Index"), 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 Code"),
                                    gtk.CellRendererText(),
                                    text=1)
        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=2)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)

        money_cell_renderer = gtk.CellRendererText()
        #money_cell_renderer.set_alignment(1.0, 0.5) #incompatible with pygtk2.16

        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Debt"), money_cell_renderer, text=3)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Credit"), money_cell_renderer, text=4)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Description"),
                                    gtk.CellRendererText(),
                                    text=5)
        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.session = config.db.session
        self.debt_sum = 0
        self.credit_sum = 0
        self.numrows = 0
        self.permanent = False

        if number > 0:
            query = config.db.session.query(Bill).select_from(Bill)
            bill = query.filter(Bill.number == number).first()
            self.docnumber = number
            if bill == None:
                numstring = str(number)
                if config.digittype == 1:
                    numstring = utility.convertToPersian(numstring)
                msg = _(
                    "No document found with number %s\nDo you want to register a document with this number?"
                ) % numstring
                msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
                                           gtk.MESSAGE_WARNING,
                                           gtk.BUTTONS_OK_CANCEL, msg)
                msgbox.set_title(_("No Documents found"))
                result = msgbox.run()
                msgbox.destroy()
                if result == gtk.RESPONSE_CANCEL:
                    return
                else:
                    self.docid = 0
                    docnum = str(self.docnumber)
                    if config.digittype == 1:
                        docnum = utility.convertToPersian(docnum)
                    self.builder.get_object("docnumber").set_text(docnum)
            else:
                self.showRows(number)
                self.permanent = bill.permanent
                self.window.set_title(_("Edit document"))
        else:
            self.docnumber = 0
            self.docid = 0

        self.treeview.set_model(self.liststore)
        self.window.show_all()
        if self.permanent:
            self.builder.get_object("editable").hide()
            self.builder.get_object("non-editable").show()
        else:
            self.builder.get_object("editable").show()
            self.builder.get_object("non-editable").hide()

        self.builder.connect_signals(self)
Ejemplo n.º 49
0
    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}
Ejemplo n.º 50
0
    def saveProductGroup(self, code, name, buy_code, sell_code, edititer=None):
        msg = ""
        if code == "":
            msg += _("Group code should not be empty.\n")
        if name == "":
            msg = _("Group name should not be empty.\n")
        #TODO set default values for buyid & sellid if empty

        if msg != "":
            msgbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE,
                                       msg)
            msgbox.set_title(_("Empty fields"))
            msgbox.run()
            msgbox.destroy()
            return False

        if edititer != None:
            pcode = unicode(self.treestore.get_value(edititer, 0))
            #pcode = utility.convertToLatin(pcode)
            query = config.db.session.query(ProductGroups).select_from(
                ProductGroups)
            group = query.filter(ProductGroups.code == pcode).first()
            gid = group.id

        #code = utility.convertToLatin(code)
        buy_code = utility.convertToLatin(buy_code)
        sell_code = utility.convertToLatin(sell_code)

        #Checks if the group name or code is repeated.
        query = config.db.session.query(ProductGroups).select_from(
            ProductGroups)
        query = query.filter(
            or_(ProductGroups.code == code, ProductGroups.name == name))
        if edititer != None:
            query = query.filter(ProductGroups.id != gid)
        result = query.all()
        msg = ""
        for grp in result:
            if grp.code == code:
                msg += _("A group with this code already exists.\n")
                break
            elif grp.name == name:
                msg += _("A group with this name already exists.\n")
                break

        #Check if buy_code & sell_code are valid
        #TODO Check if buying subject is creditor/debtor, and so for selling one.
        query = config.db.session.query(Subject).select_from(Subject)
        buy_sub = query.filter(Subject.code == buy_code).first()
        if buy_sub == None:
            msg += _("Buying code is not valid.\n")

        query = config.db.session.query(Subject).select_from(Subject)
        sell_sub = query.filter(Subject.code == sell_code).first()
        if sell_sub == None:
            msg += _("Selling code is not valid.\n")

        if msg != "":
            msgbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                                       msg)
            msgbox.set_title(_("Invalid group properties"))
            msgbox.run()
            msgbox.destroy()
            return False

        if edititer == None:
            group = ProductGroups(code, name, buy_sub.id, sell_sub.id)

            edititer = self.treestore.append(None)
            path = self.treestore.get_path(edititer)
            self.treeview.scroll_to_cell(path, None, False, 0, 0)
            self.treeview.set_cursor(path, None, False)
        else:
            group.code = code
            group.name = name
            group.buyId = buy_sub.id
            group.sellId = sell_sub.id

        config.db.session.add(group)
        config.db.session.commit()

        if config.digittype == 1:
            #code = utility.convertToPersian(code)
            buy_code = utility.convertToPersian(buy_code)
            sell_code = utility.convertToPersian(sell_code)
        self.saveRow(edititer, (code, name, buy_code, sell_code))
        return True
Ejemplo n.º 51
0
	def editProductsAndGrps(self, sender):
		selection = self.treeview.get_selection()
		iter = selection.get_selected()[1]
		
		if iter != None:
			if self.treestore.iter_parent(iter) == None:
			#iter points to a product group
				self.editProductGroup(sender)
			else:
			#iter points to a product
				dialog = self.builder.get_object("addProductDlg")
				dialog.set_title(_("Edit Product"))
				
				code = self.treestore.get_value(iter, 0)
				query = config.db.session.query(Products, ProductGroups.code)
				query = query.select_from(outerjoin(ProductGroups, Products, ProductGroups.id == Products.accGroup))
				result = query.filter(Products.code == code).first()
				product = result[0]
				groupcode = result[1]
				
				quantity = str(product.quantity)
				quantity_warn = str(product.qntyWarning)
				p_price = str(product.purchacePrice)
				s_price = str(product.sellingPrice)
				if config.digittype == 1:
					quantity = utility.convertToPersian(quantity)
					quantity_warn = utility.convertToPersian(quantity_warn)
					p_price = utility.convertToPersian(p_price)
					s_price = utility.convertToPersian(s_price)
				
				self.builder.get_object("proCodeEntry").set_text(product.code)
				self.builder.get_object("accGrpEntry" ).set_text(groupcode)
				self.builder.get_object("proNameEntry").set_text(product.name)
				self.builder.get_object("proLocEntry" ).set_text(product.location)
				self.builder.get_object("proDescEntry").set_text(product.productDesc)
				self.builder.get_object("discFormulaEntry").set_text(product.discountFormula)
				self.qntyEntry.set_text(quantity)
				self.qntyWrnEntry.set_text(quantity_warn)
				self.purchPriceEntry.set_text(p_price)
				self.sellPriceEntry.set_text(s_price)
				self.builder.get_object("oversell").set_active(product.oversell)
				
				success = False
				while not success :
					result = dialog.run()
					if result == 1:
						code     = unicode(self.builder.get_object("proCodeEntry").get_text())
						accgrp   = unicode(self.builder.get_object("accGrpEntry" ).get_text())
						name     = unicode(self.builder.get_object("proNameEntry").get_text())
						location = unicode(self.builder.get_object("proLocEntry" ).get_text())
						desc     = unicode(self.builder.get_object("proDescEntry").get_text())
						formula  = unicode(self.builder.get_object("discFormulaEntry").get_text())
						quantity = self.qntyEntry.get_float()
						q_warn   = self.qntyWrnEntry.get_float()
						p_price  = self.purchPriceEntry.get_float()
						s_price  = self.sellPriceEntry.get_float()
						oversell = self.builder.get_object("oversell").get_active()
					
						success = self.saveProduct(code, accgrp, name, location, desc, quantity, q_warn, p_price, s_price, oversell, formula, iter)
					else:
						break
				
				dialog.hide()
Ejemplo n.º 52
0
 def sellingingSubjectSelected(self, sender, id, code, name):
     if config.digittype == 1:
         code = utility.convertToPersian(code)
     self.sellCodeEntry.set_text(code)
     sender.window.destroy()
Ejemplo n.º 53
0
    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
        }