Beispiel #1
0
def set_balance(acc_number, new_acc_balance):
    acc = AccountHelper()
    if acc.set_balance(acc_number, new_acc_balance):
        print('Set balance of account `{}` to `{}`.'.format(
            acc_number, new_acc_balance))
    else:
        print('Account `{}` is not in the Database! Aborting!'.format(
            acc_number))
Beispiel #2
0
def load_bootstrap_csvs():
    if os.path.exists(
            '/mnt/c/Users/fabio_dittrich/Documents/Budget/db/budget.db'):
        os.remove('/mnt/c/Users/fabio_dittrich/Documents/Budget/db/budget.db')
    acc = AccountHelper()
    bud = BudgetHelper()
    rul = RuleHelper()

    acc.load_csv("CSVs/accounts.csv")
    bud.load_csv("CSVs/budgets.csv")
    rul.load_csv("CSVs/rules.csv")
Beispiel #3
0
 def change_budget_account(self, budget_name, new_budget_acc):
     self.c.execute("SELECT * FROM budget WHERE budget_name=:budget_name", {'budget_name': budget_name})
     if (self.c.fetchone() != None):
         acc = AccountHelper()
         acc_id = acc.get_id(new_budget_acc)
         self.c.execute("UPDATE budget SET account_id=:acc_id WHERE budget_name=:budget_name", {'acc_id': acc_id, 'budget_name': budget_name})
         #logging.info('Set budget `{}` to account `{}`.'.format(budget_name, new_budget_acc))
     else:
         logging.error('Budget `{}` is not in the Database! Aborting!'.format(budget_name))
         sys.exit(1)
     self.conn.commit()
Beispiel #4
0
    def update_budget(self, budget_name, new_budget_value, new_acc_name, new_budget_balance):
        acc = AccountHelper()
        new_acc_id = acc.get_id(new_acc_name)

        new_budget_value = float(new_budget_value)
        new_budget_balance = float(new_budget_balance)
        
        self.c.execute("SELECT * FROM budget WHERE budget_name=:budget_name", {'budget_name': budget_name})
        i, _, budget_value, acc_id, budget_balance = self.c.fetchone()

        if new_budget_value != budget_value:
            self.change_budget_value(budget_name, new_budget_value)
        if new_budget_balance != budget_balance:
            self.change_budget_balance(budget_name, new_budget_balance)
        if new_acc_id != acc_id:
            self.change_budget_account(budget_name, new_acc_name)
Beispiel #5
0
    def create(self, budget_name, budget_value, acc_name, budget_balance):
        """Checks if budget already exists. If it doesn't, creates it."""
        self.c.execute("SELECT * FROM budget WHERE budget_name=:budget_name", {'budget_name': budget_name})
        if (self.c.fetchone() != None):
            logging.error('There\'s already a budget called `{}` in the Database! Aborting!'.format(budget_name))
            sys.exit(1)

        acc = AccountHelper()
        acc_id = acc.get_id(acc_name)

        if acc_id:
            self.c.execute("INSERT INTO budget VALUES (NULL, :budget_name, :budget_value, :acc_id, :budget_balance)", {'budget_value': budget_value, 'budget_name': budget_name, 'acc_id': acc_id, 'budget_balance': budget_balance})
            #logging.info('Created budget `{}` for {} associated to account `{}` with a balance of `{}`.'.format(budget_name, budget_value, acc_name, budget_balance))
            self.conn.commit()
        else:
            logging.error('Account `{}` doesn\'t exist!'.format(acc_name))
            sys.exit(1)
Beispiel #6
0
 def apply_budget(self):
     acc = AccountHelper()
     bud = BudgetHelper()
     budgets = bud.itemize()
     for bname, bvalue, bacc in budgets:
         acc.increase_balance_by(bacc, bvalue)
Beispiel #7
0
    def load_csv(self, csv_file):
        with open(csv_file, 'r') as csvfile:
            reader = csv.reader(csvfile)
            data = list(reader)
        filtered_data = [[line[i] for i in CSV_FILTER] for line in data]

        #remove header
        filtered_data.pop(0)

        r = RuleHelper()
        rules = r.itemize()
        for rul in rules:
            print(rul)

        resolved_list = []
        unresolved_list = []

        for line in filtered_data:
            #positive transactions, i.e. incoming money
            if float(line[3]) > 0:
                continue
                #TODO:we might want to change this in the future
            found_match = False
            for rule in rules:
                #print('rule', rule)
                if rule[1] and not rule[2]:
                    #print('r1')
                    match_desc1 = re.search(rule[1], line[1])
                    if match_desc1:
                        found_match = True
                        #print('r1 match')
                        break
                elif rule[2] and not rule[1]:
                    #print('r2')
                    match_desc2 = re.search(rule[2], line[2])
                    if match_desc2:
                        found_match = True
                        #print('r2 match')
                        break
                else:
                    #print('r1&2')
                    match_desc1 = re.search(rule[1], line[1])
                    match_desc2 = re.search(rule[2], line[2])
                    if match_desc1 and match_desc2:
                        found_match = True
                        #print('r1&2 match')
                        break
            #print('\n\n')
            if found_match:
                #print("Line {0} matches rule {1}".format(line, rule))
                resolved_list.append([line, rule[3]])
            else:
                #print("Line {0} does not match any rules".format(line))
                unresolved_list.append(line)

        print(
            'The lines presented below have been already associated to a budget based on the rules:'
        )
        for i in resolved_list:
            print(i)
        print('\n\n')

        print(len(resolved_list))
        print(resolved_list, '\n\n')
        print(len(unresolved_list))
        print(unresolved_list, '\n\n\n\n\n\n')
        expenses_by_budget, resolved = self.get_manual_input(unresolved_list)
        resolved_list.extend(resolved)

        print('\n\n', expenses_by_budget, '\n\n')
        print('\n\n', resolved_list, '\n\n')

        #print('\n\n')
        #for i in resolved_list:
        #print(i)
        #print('\n\n')
        #go over list of things to resolve and allow user to input resolution
        #add resolutions to list of resolved
        #go over resolved list, compute values and show as output
        #expenses_by_budget = {}
        for i in resolved_list:
            expenses_by_budget[i[1]] += float(i[0][3])

        print('\nSum of expenses for each budget:')
        for i in sorted(expenses_by_budget):
            print(i, expenses_by_budget[i])

        bud = BudgetHelper()
        budgets = bud.itemize()
        budget_values = {}
        budget_accounts = {}
        for bname, bvalue, bacc, _ in budgets:
            budget_values[bname] = bvalue
            budget_accounts[bname] = bacc

        print('\n\nBudget values for each budget:')
        for i in sorted(budget_values):
            print(i, budget_values[i])

        budget_balance = {}
        for i in expenses_by_budget:
            budget_balance[i] = round(expenses_by_budget[i] + budget_values[i],
                                      2)

        print('\n\nBudget balances for each budget:')
        for i in sorted(budget_balance):
            print(i, f"\t\t{budget_balance[i]}")

        acc = AccountHelper()
        accounts_names = [a[1] for a in acc.itemize()]

        print('\n\n\n')
        #account['Acc'] = [spendings, sum of all budgets for account, balance]
        accounts = {}
        for i in accounts_names:
            accounts[i] = [0.0, 0.0, 0.0]

        for i in budget_balance:
            print("Budget ", i)
            associated_acc = budget_accounts[i]
            print('\taccount ', associated_acc)
            #if associated_acc not in account_balances:
            #    account_balances[associated_acc] = budget_balance[i]
            #else:
            accounts[associated_acc][0] += expenses_by_budget[i]
            accounts[associated_acc][1] += budget_values[i]
            accounts[associated_acc][2] += budget_balance[i]

        print('\nAccount balances:')
        for i in sorted(accounts):
            print(i.replace(' ', '_'), '\t', accounts[i][0], '\t',
                  accounts[i][1], '\t', accounts[i][2])
Beispiel #8
0
def list_accounts():
    acc = AccountHelper()
    acc.itemize()
Beispiel #9
0
def load_account_csv(account_csv_file):
    acc = AccountHelper()
    acc.load_csv(account_csv_file)
Beispiel #10
0
def save_account_csv(account_csv_file):
    acc = AccountHelper()
    acc.save_csv(account_csv_file)
Beispiel #11
0
def create_account(acc_number, acc_name, acc_balance):
    acc = AccountHelper()
    acc.create(acc_number, acc_name, acc_balance)
Beispiel #12
0
def get_account_id(acc_name):
    acc = AccountHelper()
    print(acc.get_id(acc_name))
Beispiel #13
0
def delete_account(acc_number):
    acc = AccountHelper()
    acc.delete(acc_number)
Beispiel #14
0
def rename_account(acc_number, new_acc_name):
    acc = AccountHelper()
    acc.rename(acc_number, new_acc_name)