Esempio n. 1
0
def view_incomes():
    system("clear")
    transactions = get_all_incomes()
    if transactions:
        table = prettytable.PrettyTable()
        table.field_names = ["ID", "Amount", "Date-Time", "Note"]
        for transaction in transactions:
            table.add_row([
                transaction[0], transaction[1], transaction[2], transaction[3]
            ])
        print(table)

        print("\n01. Delete an Income")
        print("02. Modify an Income")
        print("00. Back to previous menu")
        choice = input("\n> ")
        try:
            choice = int(choice)
        except:
            pass

        if (choice == 1):
            id = input("Enter ID : ")
            try:
                id = int(id)
            except:
                print("Invalid input")
                input()
                return
            delete_income(id)

        elif (choice == 2):
            id = input("Enter ID : ")
            try:
                id = int(id)
            except:
                print("Invalid input")
                input()
                return
            transaction = get_all_transactions(tablename,
                                               "WHERE rowid={}".format(id))[0]
            print('\nIf no input is provided previous values will be taken.')
            amount = input("\nAmount : ")
            if (not amount):
                amount = transaction[1]
            note = input("\nNote : ")
            if (not note):
                note = transaction[3]
            with conn:
                curr.execute(
                    "UPDATE {} SET amount=:amount, note=:note WHERE rowid={}".
                    format(tablename, id), {
                        'amount': amount,
                        'note': note
                    })
    else:
        print("No transactions found.")
        input()
Esempio n. 2
0
def view_loans():
    is_empty = True
    system("clear")
    transactions = get_all_unsettled_loans()
    print("\nUnsettled loans :")
    if transactions:
        is_empty = False
        table = prettytable.PrettyTable()
        table.field_names = ["ID", "Amount", "Lent to", "Date-Time", "Note"]
        for transaction in transactions:
            table.add_row([
                transaction[0], transaction[1], transaction[4], transaction[2],
                transaction[3]
            ])
        print(table)
    else:
        print("No transactions found.")

    transactions = get_all_settled_loans()
    print("\n\nSettled loans :")
    if transactions:
        is_empty = False
        table = prettytable.PrettyTable()
        table.field_names = ["ID", "Amount", "Lent to", "Date-Time", "Note"]
        for transaction in transactions:
            table.add_row([
                transaction[0], transaction[1], transaction[4], transaction[2],
                transaction[3]
            ])
        print(table)
    else:
        print("No transactions found.")

    if (not is_empty):
        print("\n01. Delete a Loan")
        print("02. Modify a Loan")
        print("03. Mark as settled / unsettled")
        print("00. Back to previous menu")
        choice = input("\n> ")
        try:
            choice = int(choice)
        except:
            pass

        if (choice == 1):
            id = input("Enter ID : ")
            try:
                id = int(id)
            except:
                print("Invalid input")
                input()
                return
            delete_loan(id)

        elif (choice == 2):
            id = input("Enter ID : ")
            try:
                id = int(id)
            except:
                print("Invalid input")
                input()
                return
            transaction = get_all_transactions(tablename,
                                               "WHERE rowid={}".format(id))[0]
            print('\nIf no input is provided previous values will be taken.')
            amount = input("\nAmount : ")
            if (not amount):
                amount = transaction[1]
            to_ = input("\nLent to : ")
            if (not to_):
                to_ = transaction[4]
            note = input("\nNote : ")
            if (not note):
                note = transaction[3]
            with conn:
                curr.execute(
                    "UPDATE {} SET amount=:amount, note=:note, to_=:to_ WHERE rowid={}"
                    .format(tablename, id), {
                        'amount': amount,
                        'note': note,
                        'to_': to_
                    })

        elif (choice == 3):
            id = input("Enter ID : ")
            try:
                id = int(id)
            except:
                print("Invalid input")
                input()
                return
            transaction = get_all_transactions(tablename,
                                               "WHERE rowid={}".format(id))[0]
            if (transaction[5] == 0):
                settled = 1
            else:
                settled = 0
            with conn:
                curr.execute(
                    "UPDATE {} SET settled=:settled WHERE rowid={}".format(
                        tablename, id), {'settled': settled})

    else:
        input()
Esempio n. 3
0
def get_all_unsettled_loans():
    return get_all_transactions(tablename, "WHERE settled={}".format(0))
Esempio n. 4
0
def get_all_incomes():
    return get_all_transactions(tablename)
Esempio n. 5
0
def view_expenses():
    while (True):
        system("clear")
        expenditure = total_expenditure()

        if expenditure:
            table = prettytable.PrettyTable()
            table.field_names = ["Category", "Percentage", "Amount"]
            for category in categories.values():
                category_total = total_expenditure_by_category(category)
                percentage = category_total * 100 / expenditure
                table.add_row([category, '%.2f' % percentage, category_total])
            print(table)
        else:
            print("No transactions found.")
            input()
            break

        print("\n01. View all expenses\
            \n02. View by category\
            \n00. Back to previous menu")

        choice = input("\n> ")
        try:
            choice = int(choice)
        except:
            pass
        system("clear")

        if (choice == 1):
            transactions = get_all_expenses()
            if transactions:
                table = prettytable.PrettyTable()
                table.field_names = [
                    "ID", "Amount", "Category", "Date-Time", "Note"
                ]
                for transaction in transactions:
                    table.add_row([
                        transaction[0], transaction[1], transaction[4],
                        transaction[2], transaction[3]
                    ])
                print(table)
            else:
                print("No transactions found.")
                input()
                continue

        elif (choice == 2):
            category_no = get_category()
            system("clear")
            transactions = get_all_expenses_by_category(
                categories[category_no])
            if transactions:
                table = prettytable.PrettyTable()
                table.field_names = ["ID", "Amount", "Date-Time", "Note"]
                for transaction in transactions:
                    table.add_row([
                        transaction[0], transaction[1], transaction[2],
                        transaction[3]
                    ])
                print(table)
            else:
                print("No transactions found.")
                input()
                continue

        else:
            break

        print("\n01. Delete an Expense")
        print("02. Modify an Expense")
        print("00. Back to previous menu")
        choice = input("\n> ")
        try:
            choice = int(choice)
        except:
            pass

        if (choice == 1):
            id = input("Enter ID : ")
            try:
                id = int(id)
            except:
                print("Invalid input")
                break
            delete_expense(id)

        elif (choice == 2):
            id = input("Enter ID : ")
            try:
                id = int(id)
            except:
                print("Invalid input")
                break
            transaction = get_all_transactions(tablename,
                                               "WHERE rowid={}".format(id))[0]
            print('\nIf no input is provided previous values will be taken.')
            amount = input("\nAmount : ")
            if (not amount):
                amount = transaction[1]
            category_no = get_category()
            if (not category_no):
                category = transaction[4]
            else:
                category = categories[category_no]
            note = input("\nNote : ")
            if (not note):
                note = transaction[3]
            with conn:
                curr.execute(
                    "UPDATE {} SET amount=:amount, note=:note, category=:category WHERE rowid={}"
                    .format(tablename, id), {
                        'amount': amount,
                        'note': note,
                        'category': category
                    })
Esempio n. 6
0
def get_all_expenses_by_category(category):
    return get_all_transactions(tablename,
                                'WHERE category="{}"'.format(category))
Esempio n. 7
0
def get_all_expenses():
    return get_all_transactions(tablename)
Esempio n. 8
0
def get_all_settled_debts():
    return get_all_transactions(tablename, "WHERE settled={}".format(1))