Пример #1
0
 def on_from_clicked(self, button):
     entry  = self.from_entry
     dbconf = dbconfig.dbConfig()
     
     #3:from subj?    5:from key
     if self.type_index is not None and self.type_configs[self.type_index][3]:
         if self.type_configs[self.type_index][5] == None:
             sub = subjects.Subjects()
         else:
             keys = self.type_configs[self.type_index][5]
             parent_id=[]
             for key in keys.split(','):
                 if key == 'cash':
                     val = dbconf.get_value(key)
                     sub = share.config.db.session.query(Subject).filter(Subject.id == val).first()
                     pID = sub.parent_id 
                     if pID !=0:
                         parent_id.append(pID)
                     else:
                         parent_id.append(key)
                 else:
                     parent_id+=dbconf.get_int_list(key)
             sub = subjects.Subjects(parent_id=parent_id)
         sub.connect('subject-selected', self.on_subject_selected, entry, False)
     else:
         cust = customers.Customer()
         cust.connect('customer-selected', self.on_customer_selected, entry, False)
         cust.viewCustomers(True)
Пример #2
0
    def add_account(self,
                    id,
                    name,
                    number="",
                    type=0,
                    owner="",
                    bank=1,
                    branch="",
                    address="",
                    phone="",
                    webpage="",
                    desc=""):
        name = unicode(name)
        number = unicode(number)
        owner = unicode(owner)
        bank = unicode(bank)
        branch = unicode(branch)
        address = unicode(address)
        phone = unicode(phone)
        webpage = unicode(webpage)
        desc = unicode(desc)

        bank_id = bank
        dbconf = dbconfig.dbConfig()
        if id == -1:
            bank_account = BankAccounts(name, number, type, owner, bank_id,
                                        branch, address, phone, webpage, desc)
            config.db.session.add(bank_account)
            config.db.session.commit()
            sub = class_subject.Subjects()
            # accountId = str(bank_account.accId)
            # accSubjectCode = accountId.rjust(3 - len(accountId)+1 , '0')
            sub.add(dbconf.get_int('bank'), name)
        else:
            query = config.db.session.query(BankAccounts).filter(
                BankAccounts.accId == id)
            prevName = query.first().accName
            q = config.db.session.query(Subject).filter(
                Subject.parent_id == (dbconf.get_int('bank'))).filter(
                    Subject.name == prevName)
            if q:
                q.update({Subject.name: name})
            query.update({
                BankAccounts.accName: name,
                BankAccounts.accNumber: number,
                BankAccounts.accType: type,
                BankAccounts.accOwner: owner,
                BankAccounts.accBank: bank_id,
                BankAccounts.accBankBranch: branch,
                BankAccounts.accBankAddress: address,
                BankAccounts.accBankPhone: phone,
                BankAccounts.accBankWebPage: webpage,
                BankAccounts.accDesc: desc
            })

        if id == -1 and bank_account:
            return bank_account.accId
        return id
Пример #3
0
 def delete_account(self, id):
     query = config.db.session.query(BankAccounts).filter(
         BankAccounts.accId == id).first()
     if query:
         accName = query.accName
     query.delete()
     bankSubject = dbconfig.dbConfig().get_int('bank')
     config.db.session.query(Subject).filter(
         Subject.parent_id == bankSubject).filter(
             Subject.name == accName).delete()
     config.db.session.commit()
Пример #4
0
    def on_to_clicked(self, button):
        entry = self.to_entry
        dbconf = dbconfig.dbConfig()

        if self.type_configs[self.type_index][4]:
            if self.type_configs[self.type_index][6] == None:
                sub = subjects.Subjects()
            else:
                keys = self.type_configs[self.type_index][6]
                parent_id=[]
                for key in keys.split(','):
                    parent_id+=dbconf.get_int_list(key)
                sub = subjects.Subjects(parent_id=parent_id)
            sub.connect('subject-selected', self.on_subject_selected, entry, True)
        else:
            cust = customers.Customer()
            cust.connect('customer-selected', self.on_customer_selected, entry, True)
            cust.viewCustomers(True)
Пример #5
0
    def on_conf_key_changed(self, entry):
        add   = self.builder.get_object('add_config')

        entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, None)

        key = entry.get_text()
        if len(key) == 0:
            add.set_sensitive(False)
            return

        conf = dbconfig.dbConfig()
        if conf.exists(key):
            entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, gtk.STOCK_DIALOG_WARNING)
            entry.set_icon_tooltip_text(gtk.ENTRY_ICON_SECONDARY, 'Key already exists')
            add.set_sensitive(False)
            return

        add.set_sensitive(True)
Пример #6
0
    def on_type_change(self, combo):
        iter =  combo.get_active_iter()

        if iter == None:
            return
        
        self.chequeui.new_cheques = []
        self.chequeui.spend_cheques = []
        model = combo.get_model()
        index = model.get(iter, 0)[0]
        self.type_index = int(index)
        
        save_button = self.builder.get_object('save-button')
        
        non_cash, discount, spend_cheque = self.type_configs[self.type_index][:3]

        self.builder.get_object('discount-button').set_sensitive(discount)
        self.discount_entry.set_sensitive(discount)
        
        self.builder.get_object('list-cheque-button').set_sensitive(spend_cheque)
        self.builder.get_object('spend-cheque-label').set_sensitive(spend_cheque)

        self.builder.get_object('non-cash-payment-label').set_sensitive(non_cash)
        self.builder.get_object('non_cash_payment_button').set_sensitive(non_cash)

        self.cash_payment_entry.set_sensitive((non_cash or spend_cheque))

        self.from_entry.set_text("")
        self.to_entry.set_text("")
        self.cash_payment_entry.set_text('0')
        self.total_credit_entry.set_text('0')
        self.discount_entry.set_text('0')

        dbconf = dbconfig.dbConfig()

        if self.type_index == 5:
            self.builder.get_object('to-button').set_sensitive(False)
            query = share.config.db.session.query(Subject).select_from(Subject)
            query = query.filter(Subject.id == dbconf.get_int('bank-wage'))
            query = query.first()
            self.to_id =  query.id
            self.to_entry.set_text(query.name)
        else:
            self.builder.get_object('to-button').set_sensitive(True)
Пример #7
0
    def on_conf_key_changed(self, entry):
        add = self.builder.get_object('add_config')

        entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, None)

        key = entry.get_text()
        if len(key) == 0:
            add.set_sensitive(False)
            return

        conf = dbconfig.dbConfig()
        if conf.exists(key):
            entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY,
                                      Gtk.STOCK_DIALOG_WARNING)
            entry.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY,
                                        'Key already exists')
            add.set_sensitive(False)
            return

        add.set_sensitive(True)
Пример #8
0
    def applyConfigSetting(self):
        conf = dbconfig.dbConfig()
        sub = class_subject.Subjects()

        # self.config_items( 0 => item_id, 1 => get_val function, 2 => exists in subjects)
        for item in self.config_items:
            val = item[1]()

            if val == None or val == '':
                #TODO Can be return on empty row
                val = conf.get_default(item[3])
            elif item[2] == True:
                ids = ''
                val = unicode(val)
                for name in val.split(','):
                    ids += '%d,' % sub.get_id_from_name(name)
                val = ids[:-1]
            conf.set_value(item[0], val, False)

        config.db.session.commit()
Пример #9
0
    def applyConfigSetting(self):
        conf = dbconfig.dbConfig()
        sub  = class_subject.Subjects()
        
        # self.config_items( 0 => item_id, 1 => get_val function, 2 => exists in subjects)
        for item in self.config_items:
            val = item[1]()
            
            if val == None or val == '':
                #TODO Can be return on empty row
                val = conf.get_default(item[3])
            elif item[2] == True:
                ids = ''
                val = unicode(val)
                for name in val.split(','):
                    ids += '%d,' % sub.get_id_from_name(name)
                val = ids[:-1]
            conf.set_value(item[0], val, False)

        config.db.session.commit()
Пример #10
0
    def on_add_config_clicked(self, button):
        key = self.builder.get_object('conf_key').get_text()
        desc = self.builder.get_object('conf_desc').get_text()

        if self.builder.get_object('conf_mode_file').get_active():
            mode = 0
        elif self.builder.get_object('conf_mode_entry').get_active():
            mode = 1
        elif self.builder.get_object('conf_mode_single_subject').get_active():
            mode = 2
        else:
            mode = 3

        self.builder.get_object('conf_key').set_text('')
        self.builder.get_object('conf_desc').set_text('')
        self.builder.get_object('conf_mode_file').set_active(True)

        conf = dbconfig.dbConfig()
        conf.add(key, mode, desc)

        self.setup_config_tab()
Пример #11
0
    def on_add_config_clicked(self, button):
        key  = self.builder.get_object('conf_key').get_text()
        desc = self.builder.get_object('conf_desc').get_text()

        if   self.builder.get_object('conf_mode_file').get_active():
            mode = 0
        elif self.builder.get_object('conf_mode_entry').get_active():
            mode = 1
        elif self.builder.get_object('conf_mode_single_subject').get_active():
            mode = 2
        else:
            mode = 3

        self.builder.get_object('conf_key').set_text('')
        self.builder.get_object('conf_desc').set_text('')
        self.builder.get_object('conf_mode_file').set_active(True)

        conf = dbconfig.dbConfig()
        conf.add(key, mode, desc)

        self.setup_config_tab()
Пример #12
0
    def add_account(self, id, name, number, type, owner, bank, branch, address, phone, webpage, desc):
        name    = unicode(name)
        number  = unicode(number)
        owner   = unicode(owner)
        bank    = unicode(bank)
        branch  = unicode(branch)
        address = unicode(address)
        phone   = unicode(phone)
        webpage = unicode(webpage)
        desc    = unicode(desc)

        bank_id = config.db.session.query(BankNames).select_from(BankNames).filter(BankNames.Name == bank).first().Id

        if id == -1:
            bank_account = BankAccounts(name, number, type, owner, bank_id, branch, address, phone, webpage, desc)
            config.db.session.add(bank_account)
            sub = class_subject.Subjects()
            dbconf = dbconfig.dbConfig()
            sub.add(dbconf.get_int('bank'), name, str(bank_account.accId).rjust(2, '0'))
        else:
            query = config.db.session.query(BankAccounts).select_from(BankAccounts)
            query = query.filter(BankAccounts.accId == id)
            query.update( {BankAccounts.accName        : name,
                           BankAccounts.accNumber      : number,
                           BankAccounts.accType        : type,
                           BankAccounts.accOwner       : owner,
                           BankAccounts.accBank        : bank_id,
                           BankAccounts.accBankBranch  : branch,
                           BankAccounts.accBankAddress : address,
                           BankAccounts.accBankPhone   : phone,
                           BankAccounts.accBankWebPage : webpage,
                           BankAccounts.accDesc        : desc})
        config.db.session.commit()

        if id == -1:
            return bank_account.accId
        return id
Пример #13
0
    def on_save_button_clicked(self, button):
        result = {}
        result['type']                  = self.type_index
        result['total_value']           = self.total_credit_entry.get_float()
        result['cash_payment']          = self.cash_payment_entry.get_float()
        result['non_cash_payment']      = self.builder.get_object('non-cash-payment-label').get_text()
        result['spend_cheque']          = self.builder.get_object('spend-cheque-label').get_text()
        result['discount']              = self.discount_entry.get_float()
        result['non-cash-payment-info'] = None # TODO: = non cash payment infos
        result['spend-cheque-info']     = None # TODO = spent cheque infos
        result['desc']                  = self.builder.get_object('desc').get_text()
        result['from']                  = self.from_id
        result['to']                    = self.to_id

        dbconf = dbconfig.dbConfig()

        #Save data in data base for single use
        if self.liststore == None:
            type(result['from'])
            document = class_document.Document()
            document.add_notebook(result['from'],  result['total_value'], unicode(result['desc']))
            document.add_notebook(result['to']  , -result['cash_payment'], unicode(result['desc']))
            if result['discount'] :
                document.add_notebook(dbconf.get_int('sell-discount'), -result['discount'], result['desc'])
            cl_cheque = class_cheque.ClassCheque()
            for cheque in self.chequeui.new_cheques:
                if self.mode == 'our':
                    document.add_cheque(dbconf.get_int('our_cheque'), -cheque['amount'], cheque['desc'], cheque['serial'])
                else:
                    document.add_cheque(dbconf.get_int('other_cheque'), -cheque['amount'], cheque['desc'], cheque['serial'])
            #spendble cheque
            for sp_cheque in self.chequeui.spend_cheques:
                cl_cheque.update_status(sp_cheque['serial'],5)
                document.add_cheque(dbconf.get_int('other_cheque'), -sp_cheque['amount'] , unicode('kharj shodeh') , sp_cheque['serial'])
                    
            result = document.save()

            if result < 0:
                dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, 'Failed, %s' % document.get_error_message(result))
                dialog.run()
                dialog.destroy()
                return

            if self.type_configs[self.type_index][3] == True: # from is subject
                customer_id = 0
            else: # from is customer
                customer_id = share.config.db.session.query(Customers).select_from(Customers).filter(Customers.custSubj==self.from_id).first().custId

            for cheque in self.chequeui.new_cheques:
                notebook_id =document.cheques_result[cheque['serial']]
                cl_cheque.add_cheque(cheque['amount'], cheque['write_date'], cheque['due_date'],
                                     cheque['serial'], cheque['status'],
                                     customer_id, cheque['bank_account_id'],
                                     result, notebook_id, cheque['desc'])
            cl_cheque.save()
            cl_cheque.save_cheque_history(self.current_time)
            self.on_destroy(self.builder.get_object('general'))
            
            share.mainwin.silent_daialog(_('successfully added. Document number : %d') % document.number)
#            infobar = gtk.InfoBar()
#            label = gtk.Label(_('successfully added. Document number : %d') % document.number)
#            infobar.get_content_area().add(label)
#            width , height = self.main_window_background.window.get_size()
#            infobar.set_size_request(width, -1)
#            self.main_window_background.put(infobar ,0 , 0)
#            infobar.show_all()
#
#            glib.timeout_add_seconds(3, lambda w: w.destroy(), infobar)

        #Store result in list store for showing in addeditdoc
        else:
            mysubject = Subjects()
            numrows = len(self.liststore) + 1
            #document.add_notebook(result['from'],  result['total_value'], result['desc'])
            self.liststore.append ((LN(numrows), LN(self.from_code), self.from_name, LN(0), LN(result['total_value']), result['desc'], None))
            #self.liststore.append ((numrows,                 code,                           sub.name,                          debt, credit,                              desc,           None))
            #document.add_notebook(result['to']  , -result['cash_payment'], result['desc'])
            numrows += 1
            self.liststore.append ((LN(numrows), LN(self.to_code), self.to_name, LN(result['cash_payment']), LN(0), result['desc'], None))
            if result['discount'] :
                numrows += 1
                self.liststore.append ((LN(numrows), LN(mysubject.get_code(dbconf.get_int('sell-discount'))), mysubject.get_name(dbconf.get_int('sell-discount')), LN(result['discount']), LN(0), result['desc'], None))

            #cl_cheque = class_cheque.ClassCheque()
            #or cheque in self.chequeui.new_cheques:
            #    if self.mode == 'our':
            #        document.add_cheque(dbconf.get_int('our_cheque'), -cheque['amount'], cheque['desc'], cheque['serial'])
            #    else:
            #        document.add_cheque(dbconf.get_int('other_cheque'), -cheque['amount'], cheque['desc'], cheque['serial'])
            #spendble cheque
            #for sp_cheque in self.chequeui.spend_cheques:
            #   cl_cheque.update_status(sp_cheque['serial'],5)
            #    document.add_cheque(dbconf.get_int('other_cheque'), -sp_cheque['amount'] , unicode('kharj shodeh') , sp_cheque['serial'])
                    

            #if self.type_configs[self.type_index][3] == True: # from is subject
            #    customer_id = 0
            #else: # from is customer
            #    customer_id = config.db.session.query(Customers).select_from(Customers).filter(Customers.custSubj==self.from_id).first().custId

            #for cheque in self.chequeui.new_cheques:
            #    notebook_id =document.cheques_result[cheque['serial']]
            #    cl_cheque.add_cheque(cheque['amount'], cheque['write_date'], cheque['due_date'],
            #                         cheque['serial'], cheque['status'],
            #                         customer_id, cheque['bank_account_id'],
            #                         result, notebook_id, cheque['desc'])
            #cl_cheque.save()
            #cl_cheque.save_cheque_history(self.current_time)
            self.on_destroy(self.builder.get_object('general'))
Пример #14
0
    def on_save_button_clicked(self, button):
        share.config.db.session.rollback() 
        result = {}
        result['type']                  = self.type_index
        result['total_value']           = self.total_credit_entry.get_float()
        result['cash_payment']          = self.cash_payment_entry.get_float()
        result['non_cash_payment']      = self.builder.get_object('non-cash-payment-label').get_text()
        result['spend_cheque']          = self.builder.get_object('spend-cheque-label').get_text()
        result['discount']              = self.discount_entry.get_float()
        result['non-cash-payment-info'] = None # TODO: = non cash payment infos
        result['spend-cheque-info']     = None # TODO = spent cheque infos
        result['desc']                  = self.builder.get_object('desc').get_text()
        result['from']                  = self.from_id
        result['to']                    = self.to_id

        dbconf = dbconfig.dbConfig()

        #Save data in data base for single use
        if self.liststore == None:
            type(result['from'])
            if self.type_index is not None and self.type_configs[self.type_index][3]:
                mode = 'our'                
            else:
                mode = 'other'            
            desc = result['desc']
            if desc =="":
                desc = self.type_names[self.type_index][1]            
            document = class_document.Document()
            if result['cash_payment']  :
                document.add_notebook(result['from'], result['cash_payment'], unicode(desc))
                document.add_notebook(result['to']  ,  -result['cash_payment'], unicode(desc ))
            if result['discount'] :
                document.add_notebook(dbconf.get_int('sell-discount'), -result['discount'], desc)            

            if self.type_configs[self.type_index][3] == True: # from is subject
                custSubj = self.to_id                
            else: # from is customer
                custSubj = self.from_id
            print custSubj
            customer_id = share.config.db.session.query(Customers).filter(Customers.custSubj==custSubj).first().custId

            for cheque in self.addChequeui.chequesList:
                if mode == 'our':
                    document.add_cheque(dbconf.get_int('our_cheque'),custSubj,(cheque.chqAmount), cheque.chqDesc, cheque.chqId)
                else:
                    document.add_cheque(dbconf.get_int('other_cheque'),custSubj, -cheque.chqAmount, cheque.chqDesc, cheque.chqId)            

            cl_cheque = class_cheque.ClassCheque()

            #spendble cheques
            for sp_cheque in self.spendChequeui.chequesList:
                cl_cheque.update_status(sp_cheque.chqId,5 , customer_id)
                document.add_cheque(custSubj, dbconf.get_int('other_cheque'), -sp_cheque.chqAmount , unicode(_('Cheque No. %s spended') % sp_cheque.chqSerial) , sp_cheque.chqId)
                    
            result = document.save()

            if result < 0:
                dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Failed, %s') % document.get_error_message(result))
                dialog.run()
                dialog.destroy()
                return


            for cheque in self.addChequeui.chequesList:                
                cl_cheque.add_cheque(cheque.chqAmount, cheque.chqWrtDate, cheque.chqDueDate,
                                     cheque.chqSerial, cheque.chqStatus,
                                     customer_id, cheque.chqAccount,
                                     0, 0, cheque.chqDesc, 0, 0)
            cl_cheque.save()
            cl_cheque.save_cheque_history(self.current_time)
            self.on_destroy(self.builder.get_object('general'))
            
            share.mainwin.silent_daialog(_('successfully added. Document number : %d') % document.number)


        #Store result in list store for showing in addeditdoc
        else:
            mysubject = Subjects()
            numrows = len(self.liststore) + 1
            #document.add_notebook(result['from'],  result['total_value'], result['desc'])
            self.liststore.append ((LN(numrows), unicode(self.from_code), unicode(self.from_name), LN(0), LN(result['total_value']), result['desc'], None))
            #self.liststore.append ((numrows,                 code,                           sub.name,                          debt, credit,                              desc,           None))
            #document.add_notebook(result['to']  , -result['cash_payment'], result['desc'])
            numrows += 1
            self.liststore.append ((LN(numrows), unicode(self.to_code), unicode(self.to_name), LN(result['cash_payment']), LN(0), result['desc'], None))
            if result['discount'] :
                numrows += 1
                self.liststore.append ((LN(numrows), unicode(mysubject.get_code(dbconf.get_int('sell-discount'))), mysubject.get_name(dbconf.get_int('sell-discount')), LN(result['discount']), LN(0), result['desc'], None))

            self.on_destroy(self.builder.get_object('general'))
Пример #15
0
from flask_mysqldb import MySQL
from wtforms import Form, StringField, TextAreaField, PasswordField, validators
from passlib.hash import sha256_crypt 
import json
#from data import Articles # do not need to import articles once db is connected.
import requests
from datetime import datetime
from dbconfig import dbConfig
from dbconfig import secretKey
from functools import wraps 



app = Flask(__name__)

creds = dbConfig() #using git ignore to keep db credentials secret
print(secretKey())

#config MySQL
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] =  creds[0] 
app.config['MYSQL_PASSWORD'] = creds[1] 
app.config['MYSQL_DB'] = creds[2] 
app.config['MYSQL_CURSORCLASS'] = 'DictCursor' #sets to dictionary

#init mySQL
mysql = MySQL(app)

#Articles = Articles(); #not needed once db is connected.

app.debug=True
Пример #16
0
 def on_delete_row_clicked(self, button, id):
     conf = dbconfig.dbConfig()
     conf.delete(id)
     self.setup_config_tab()
Пример #17
0
 def on_delete_row_clicked(self, button, id):
     conf = dbconfig.dbConfig()
     conf.delete(id)
     self.setup_config_tab()
Пример #18
0
    def saveProduct(self,
                    code,
                    accgrp,
                    name,
                    location,
                    desc,
                    quantity,
                    quantity_warn,
                    purchase_price,
                    sell_price,
                    oversell,
                    formula,
                    uMeasurement="",
                    editId=0,
                    edititer=None):
        msg = ""
        if code == "":
            msg += _("Product code should not be empty.\n")
        if accgrp == "":
            msg += _("Product group should not be empty.\n")
        if name == "":
            msg += _("Product name should not be empty.\n")

        if msg != "":
            msgbox = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL,
                                       Gtk.MessageType.WARNING,
                                       Gtk.ButtonsType.CLOSE, msg)
            msgbox.set_title(_("Empty fields"))
            msgbox.run()
            msgbox.destroy()
            return False
        result = 0
        #Checks if the product code is repeated.
        query = config.db.session.query(count(Products.id))
        query = query.filter(Products.code == code).filter(
            Products.accGroup == accgrp)
        if edititer != None:
            query = query.filter(Products.id != editId)
        result = query.first()[0]
        if result != 0:
            msg += _("A product with this code already exists.\n")

        query = config.db.session.query(ProductGroups).select_from(
            ProductGroups)
        group = query.filter(ProductGroups.code == accgrp).first()
        if group == None:
            msg += _("Group code is not valid.\n")

        if not quantity:
            quantity = 0
        else:
            if not purchase_price or purchase_price == "":
                msg += _(
                    "Product with initial balance must have purchase price. \n "
                )

        firstnum = 0
        secnum = 0
        try:
            flist = formula.split(u',')
            for elm in flist:
                if elm != '':
                    partlist = elm.split(u':')
                    price = float(partlist[1])
                    numlist = partlist[0].split(u'-')
                    if len(numlist) > 0:
                        firstnum = float(numlist[0])
                        if firstnum < secnum:
                            msg += _("Discount formula is not valid")
                            break
                        if len(numlist) > 1:
                            secnum = float(numlist[1])
                            if firstnum > secnum:
                                msg += _(
                                    "Discount formula should be typed in ascending order."
                                )
                                break
                            if len(numlist) > 2:
                                msg += _("Discount formula is not valid")
                                break
                    else:
                        msg += _("Discount formula is not valid")
                        break
        except ValueError:
            msg += _("Discount formula is not valid")

        if msg != "":
            msgbox = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL,
                                       Gtk.MessageType.WARNING,
                                       Gtk.ButtonsType.CLOSE, msg)
            msgbox.set_title(_("Invalid product properties"))
            msgbox.run()
            msgbox.destroy()
            return False

        if edititer == None:
            product = Products(code, name, quantity_warn, oversell, location,
                               quantity, purchase_price, sell_price, group.id,
                               desc, formula, uMeasurement)
            config.db.session.add(product)
            config.db.session.commit()

            if quantity > 0:
                if config.db.session.query(Bill).filter(Bill.id == 1).first():
                    prevFund = 0
                    query = config.db.session.query(Notebook).filter(
                        Notebook.bill_id == 1)
                    pNote = query.first()
                    if pNote:
                        prevFund = pNote.value
                    query.delete()
                    val = float(quantity) * float(purchase_price) + abs(
                        prevFund)
                    dbconf = dbconfig.dbConfig()
                    config.db.session.add(
                        Notebook(dbconf.get_int('inventories'), 1, -val,
                                 _("Initial balance")))
                    config.db.session.add(
                        Notebook(dbconf.get_int('fund'), 1, val,
                                 _("Initial funding (share capital)")))
                    config.db.session.add(
                        FactorItems(1, product.id, quantity, purchase_price, 0,
                                    0, _("Initial inventory")))

        else:
            product = config.db.session.query(Products).filter(
                Products.id == editId).first()
            product.code = code
            product.name = name
            product.oversell = oversell
            product.location = location
            product.quantity = quantity
            product.accGroup = group.id
            product.productDesc = desc
            product.qntyWarning = quantity_warn
            product.sellingPrice = sell_price
            product.purchacePrice = purchase_price
            product.discountFormula = formula
            product.uMeasurement = uMeasurement

        config.db.session.commit()

        #Show new product in table

        self.fillTreeview()
        try:
            parent_iter = self.treestore.get_iter_first()
        except AttributeError:
            #skip if there is no table to show
            pass
        else:
            if not parent_iter:
                return True
            while self.treestore.iter_is_valid(parent_iter):
                itercode = self.treestore.get_value(parent_iter, 0)
                if itercode == accgrp:
                    break
                parent_iter = self.treestore.iter_next(parent_iter)
                open_iter = parent_iter

            if edititer == None:
                i = 0
                child = 1
                while child:
                    child = self.treestore.iter_nth_child(parent_iter, i)
                    i += 1
                    if code == self.treestore.get_value(child, 0):
                        open_iter = child
                        break

                path = self.treestore.get_path(open_iter)
                self.treeview.expand_to_path(path)
                self.treeview.scroll_to_cell(path, None, False, 0, 0)
                self.treeview.set_cursor(path, None, False)
                self.treeview.grab_focus()

            # self.saveRow(edititer, (code, name, utility.LN(quantity),
            # utility.LN(purchase_price), utility.LN(sell_price) ) )

        return True
Пример #19
0
    def on_type_change(self, combo):
        iter =  combo.get_active_iter()

        if iter == None:
            return
        
        # self.chequeui.new_cheques = []
        # self.chequeui.spend_cheques = []
        model = combo.get_model()
        index = model.get(iter, 0)[0]
        self.type_index = int(index)
        
        save_button = self.builder.get_object('save-button')
        
        non_cash, discount, spend_cheque = self.type_configs[self.type_index][:3]

        self.builder.get_object('discount-button').set_sensitive(discount)
        self.discount_entry.set_sensitive(discount)
        
        self.builder.get_object('list-cheque-button').set_sensitive(spend_cheque)
        self.builder.get_object('spend-cheque-label').set_sensitive(spend_cheque)

        self.builder.get_object('non-cash-payment-label').set_sensitive(non_cash)
        self.builder.get_object('non_cash_payment_button').set_sensitive(non_cash)

        self.cash_payment_entry.set_sensitive((non_cash or spend_cheque))

        self.from_entry.set_text("")
        self.to_entry.set_text("")
        self.cash_payment_entry.set_text(LN(0))
        self.total_credit_entry.set_text(LN(0))
        self.discount_entry.set_text(LN(0))

        dbconf = dbconfig.dbConfig()

        if self.type_index == 5:
            self.builder.get_object('to-button').set_sensitive(False)
            query = share.config.db.session.query(Subject).select_from(Subject)
            query = query.filter(Subject.id == dbconf.get_int('bank-wage'))
            query = query.first()
            self.to_id =  query.id
            self.to_entry.set_text(query.name)
            self.to_code = query.code
            self.to_name = query.name            
        elif self.type_index in [0,4] :
            self.builder.get_object('to-button').set_sensitive(False)
            query = share.config.db.session.query(Subject).select_from(Subject)
            query = query.filter(Subject.id == dbconf.get_int('cash'))
            query = query.first()
            self.to_id =  query.id
            self.to_entry.set_text(query.name)
            self.to_code = query.code
            self.to_name = query.name
        else:
            self.builder.get_object('to-button').set_sensitive(True)

        # resetting non-cash payments UI for adding :
        sellMode = 0
        if self.type_index is not None and self.type_configs[self.type_index][3]:
            #mode = 'our'
            sellMode = 0    # pardakhti
            customerEntry = self.to_entry
        else:
            #mode = 'other'
            sellMode = 1    # daryafti 
            customerEntry = self.from_entry
        self.addChequeui = payments.Payments(0 , sellMode , False)
        self.addChequeui.fillChequeTable()
        self.addChequeui.customerNameLbl.set_text(customerEntry.get_text())
        self.addChequeui.connect("payments-changed",self.update_non_cash_payment_label  )
Пример #20
0
from database import *
from dateentry import *
from share import share
from helpers import get_builder
from gi.repository import Gdk
from converter import *
from datetime import datetime, timedelta
import dateentry
import class_document
import dbconfig
import subjects, customers
import class_bankaccounts
import decimalentry, utility

import logging
dbconf = dbconfig.dbConfig()
config = share.config


class ChequeReport(GObject.GObject):
    chequeStatus = [
        "",
        _("Paid-Not passed"),
        _("Paid-Passed"),
        _("Recieved-Not cashed"),
        _("Recieved-Cashed"),
        _("Spent"),
        _("Returned from customer"),
        _("Returned to customer"),
        _("Paid-Bounced"),
        _("Recieved-Bounced"),