예제 #1
0
def _select_trans(ts) -> Transaction or None:
    """Returns transaction selected based on iteration
    """
    def _cond(y, m, t):
        return t.get_year() == y and t.get_month() == bc.months_to_int[m]

    print("Unique Years\n" + ("=" * 40))
    y = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if y == -1:
        return

    print("\nUnique Months\n" + ("=" * 40))
    s = (bc.months_abv(m)
         for m in sorted(set(t.get_month() for t in ts if t.get_year() == y)))
    m = bc.trans_timeframe(list(s) + [-1])
    if m == -1:
        return

    ts_tf = sorted((t for t in ts if _cond(y, m, t)),
                   key=lambda x: x.get_day())

    while True:
        try:
            print("\n" + header(True))
            for n0, t in enumerate(ts_tf, 1):
                print(view(t, n0))
            n = int(input("Select transaction number: ").rstrip())
            for n1, v in enumerate(ts_tf, 1):
                if n == n1:
                    return v
        except Exception as e:
            print("    An error has occurred: " + str(e))
예제 #2
0
def _by_custom(ts) -> None:
    """Prints transactions in a series of months and years based on user input
    """
    def cond(y0, y1, m0, m1, t):
        return m0 <= t.get_month() <= m1 and y0 <= t.get_year() <= y1

    print()
    y0 = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if 0 == y0:
        return
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m0 = bc.trans_timeframe(list(s) + [-1])
    if 0 == m0:
        return

    print()
    y1 = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if 0 == y1:
        return
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m1 = bc.trans_timeframe(list(s) + [-1])
    if 0 == m1:
        return

    print("\n" + header())
    for t in (i for i in ts
              if cond(y0, y1, bc.months_to_int[m0], bc.months_to_int[m1], i)):
        print(view(t))
예제 #3
0
def _by_custom(ts) -> None:
    """Prints transactions in a series of months and years based on user input
    """
    def cond(y0,y1,m0,m1,t): return m0 <= t.get_month() <= m1 and y0 <= t.get_year() <= y1
    print()
    y0 = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if 0 == y0: 
        return
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m0 = bc.trans_timeframe(list(s) + [-1])
    if 0 == m0: 
        return
    
    print()
    y1 = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if 0 == y1: 
        return
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m1 = bc.trans_timeframe(list(s) + [-1])
    if 0 == m1: 
        return 
    
    print("\n"+header())
    for t in (i for i in ts if cond(
        y0,y1,bc.months_to_int[m0],bc.months_to_int[m1],i)): 
        print(view(t))    
예제 #4
0
def _select_trans(ts) -> Transaction or None:
    """Returns transaction selected based on iteration
    """
    def _cond(y,m,t): return t.get_year() == y and t.get_month() == bc.months_to_int[m]
    
    print("Unique Years\n"+("=" * 40))
    y = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if y == -1: 
        return 
    
    print("\nUnique Months\n"+("=" * 40))
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts if t.get_year() == y)))
    m = bc.trans_timeframe(list(s) + [-1])
    if m == -1: 
        return 

    ts_tf = sorted((t for t in ts if _cond(y,m,t)), key = lambda x: x.get_day())
    
    while True:     
        try: 
            print("\n"+header(True))
            for n0,t in enumerate(ts_tf, 1):
                print(view(t,n0))        
            n = int(input("Select transaction number: ").rstrip())
            for n1, v in enumerate(ts_tf, 1):
                if n == n1:
                    return v 
        except Exception as e: 
            print("    An error has occurred: " + str(e))
예제 #5
0
def _cts(ats: [Account]) -> None:
    """Executes choice to view transactions of an Account over a custom time period
    """
    def _cond(t): return y0 <= t.get_year() <= y1 and \
        bc.months_to_int[m0] <= t.get_month() <= bc.months_to_int[m1]
    a = bc.select_account(ats)
    
    print("\nSelect Start Timeframe\n"+("="*40))            # Timeframe selection
    y0 = bc.trans_timeframe(_uy(ats))
    if y0 == -1: 
        return
    print()
    m0 = bc.trans_timeframe(_um(a, y0))
    if m0 == -1:
        return

    print("\nSelect End Timeframe\n"+("="*40))
    y1 = bc.trans_timeframe(_uy(ats))
    if y1 == -1: 
        return  
    print()
    m1 = bc.trans_timeframe(_um(a, y1))
    if m1 == -1:
        return

    print(
        "\nDisplaying Transactions for {} from {} {} to {} {}\n".format(
            a.get_name(), m0, y0, m1, y1))
    print(_display_all_trans(a, _cond))
예제 #6
0
def _ocst(ats: [Account]) -> None: 
    """Executes choice to view one account over a custom period
    """
    def _cond(y,m): return (y0,bc.months_to_int[m0]) <= (y,m) <= (y1,bc.months_to_int[m1])
    a = bc.select_account(ats)
    
    print("\nSelect Start Timeframe\n"+("="*40))             # Timeframe selection - copy in account analysis module
    y0 = bc.trans_timeframe(_uy(ats))
    if y0 == -1: 
        return
    print()
    m0 = bc.trans_timeframe(_um(a, y0))
    if m0 == -1:
        return

    print("\nSelect End Timeframe\n"+("="*40))
    y1 = bc.trans_timeframe(_uy(ats))
    if y1 == -1: 
        return  
    print()
    m1 = bc.trans_timeframe(_um(a, y1))
    if m1 == -1:
        return

    it = [(y,m) for y in a.get_budgets() \
          for m in a.get_budgets()[y] if _cond(y,m)]
    print(
        "\nDisplaying {} with Budgets from {} {} to {} {}".format(
            a.get_name(), m0, y0+1, m1, y1+1))
    print(_view_range_budget(
        a, sorted(it, key=lambda x: (x[0], x[1]), reverse=True), max_char))
예제 #7
0
def edit_goal(ats: Account) -> None: 
    """Mutates the goal of the selected Account and timeframe. 
    Provides user interface for mutating this information
    """
    print("\nEditing Goal\n" + ("="*40))
    while True: 
        a = bc.select_account(ats)
        if a == bc.breakout_account: 
            break
        while True: 
            print()
            y = bc.trans_timeframe(a.get_budgets())
            print()
            m = bc.months_to_int[bc.trans_timeframe([bc.months(i) for i in a.get_budgets(y)] + [-1])[:3]]
            while True: 
                print("\nInput New Goal\n" + ("="*40))
                try:
                    choice_str = input("Enter new goal (Current goal: {:.2f}): ".format(a.get_goal(y,m)/100))
                    choice = int(choice_str) * 100
                    valid.amount(choice) 
                    if bc.binary_question("Confirm new goal is {:.2f}".format(choice/100) + " ([y]es [n]o): ", "y", "n"): 
                        a.set_goal(y, m, choice)
                        break
                except Exception as e: 
                    print("    An error has occurred: " + str(e))
            if not bc.binary_question("Enter goals for other months ([y]es or [n]o): ", "y", "n"):
                break
        if not bc.binary_question("Edit a goal for another Account ([y]es or [n]o): ", "y", "n"):
            break
예제 #8
0
def _omy(ats: [Account]) -> None: 
    """Executes choice to view one account for one year and one month
    """
    a = bc.select_account(ats)
    print()
    y0 = bc.trans_timeframe(_uy(ats))
    if y0 == -1: 
        return
    print()  
    m0 = bc.trans_timeframe(_um(a, y0))
    if m0 == -1:
        return
    print(_view_tf_budget(a, (y0, bc.months_to_int[m0] )))
예제 #9
0
def _by_pair(ts) -> None:
    """Prints transactions in a month and year based on user input
    """
    print()
    y = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if y == -1: 
        return 
    
    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m = bc.trans_timeframe(list(s) + [-1])
    if m == -1: 
        return 
    
    print("\n"+header())
    for t in (i for i in ts if i.get_month() == bc.months_to_int[m] and \
               i.get_year() == y): 
        print(view(t))
예제 #10
0
def _by_pair(ts) -> None:
    """Prints transactions in a month and year based on user input
    """
    print()
    y = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if y == -1:
        return

    s = (bc.months_abv(m) for m in sorted(set(t.get_month() for t in ts)))
    print()
    m = bc.trans_timeframe(list(s) + [-1])
    if m == -1:
        return

    print("\n" + header())
    for t in (i for i in ts if i.get_month() == bc.months_to_int[m] and \
               i.get_year() == y):
        print(view(t))
예제 #11
0
def _by_year(ts) -> None:
    """Prints transactions in a year based on user input 
    """
    print()
    y = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if y == -1:  
        return
    print("\n"+header()) 
    for t in (i for i in ts if i.get_year() == y): 
        print(view(t))
예제 #12
0
def _by_year(ts) -> None:
    """Prints transactions in a year based on user input 
    """
    print()
    y = bc.trans_timeframe(sorted(set(t.get_year() for t in ts)) + [-1])
    if y == -1:
        return
    print("\n" + header())
    for t in (i for i in ts if i.get_year() == y):
        print(view(t))
예제 #13
0
def _acst(ats: [Account]) -> None:
    """Executes choice to view all accounts in a specific timeframe
    """
    def _cond1(y,m):
        return (y0,bc.months_to_int[m0]) <= (y,m) <= (y1,bc.months_to_int[m1])
    def _cond2(a):
        for y in range(y0,y1+1):
            for m in range(bc.months_to_int[m0],bc.months_to_int[m1]+1):
                if (y in a.get_budgets() and (m in a.get_budgets()[y])):
                    return True
        return False 
         
    print("\nSelect Start Timeframe\n"+("="*40))             # Timeframe selection
    y0 = bc.trans_timeframe(_uy(ats))
    if y0 == -1: 
        return
    print()
    m0 = bc.trans_timeframe(_um_ats(
        (a for a in ats if y0 in a.get_budgets()), y0))
    if m0 == -1:
        return

    print("\nSelect End Timeframe\n"+("="*40))
    y1 = bc.trans_timeframe(_uy(ats))
    if y1 == -1: 
        return  
    print()
    m1 = bc.trans_timeframe(_um_ats(
        (a for a in ats if y1 in a.get_budgets()), y1))
    if m1 == -1:
        return

    it = sorted(
        set(
        (y,m) for a in ats for y in a.get_budgets() for m in a.get_budgets(y) \
        if _cond1(y,m)), reverse=True)
    print("\nDisplaying All Accounts with Budgets from {} {} to {} {}".format(
        m0, y0+1, m1, y1+1))
    print(_view_range_budgets([a for a in ats if _cond2(a)], it, max_char))
예제 #14
0
def edit_goal(ats: Account) -> None:
    """Mutates the goal of the selected Account and timeframe. 
    Provides user interface for mutating this information
    """
    print("\nEditing Goal\n" + ("=" * 40))
    while True:
        a = bc.select_account(ats)
        if a == bc.breakout_account:
            break
        while True:
            print()
            y = bc.trans_timeframe(a.get_budgets())
            print()
            m = bc.months_to_int[bc.trans_timeframe(
                [bc.months(i) for i in a.get_budgets(y)] + [-1])[:3]]
            while True:
                print("\nInput New Goal\n" + ("=" * 40))
                try:
                    choice_str = input(
                        "Enter new goal (Current goal: {:.2f}): ".format(
                            a.get_goal(y, m) / 100))
                    choice = int(choice_str) * 100
                    valid.amount(choice)
                    if bc.binary_question(
                            "Confirm new goal is {:.2f}".format(choice / 100) +
                            " ([y]es [n]o): ", "y", "n"):
                        a.set_goal(y, m, choice)
                        break
                except Exception as e:
                    print("    An error has occurred: " + str(e))
            if not bc.binary_question(
                    "Enter goals for other months ([y]es or [n]o): ", "y",
                    "n"):
                break
        if not bc.binary_question(
                "Edit a goal for another Account ([y]es or [n]o): ", "y", "n"):
            break
예제 #15
0
def _breakdown(ats: [Account]) -> None:
    """Executes choice to view the breakdown of transactions 
    of Accounts
    """
    def _um(a: Account, y: int) -> [int]:
        """Returns integers representing unique months of an Account and breakout integer
        """
        return sorted(
        set(bc.months_abv(m) for m in a.get_budgets(y)), 
        key=lambda x: bc.months_to_int[x]) + [-1]

        
    def _uy(a: Account or [Account]) -> [int]:
        """Returns integers representing unique years and breakout integer
        """
        if type(a) == Account: 
            return sorted(set(y for y in a.get_budgets())) + [-1]
        return sorted(set(y for act in a for y in act.get_budgets())) + [-1]
    
    def _cond1(y,m): return (y0, bc.months_to_int[m0_str[:3]]) \
        <= (y,m) <= (y1, bc.months_to_int[m1_str[:3]])
    
    def _um_ats(ats: "generator", y: int) -> [int]:
        """Returns integers represnting unique months of an Account collection
        and breakout integer
        """
        months = set() 
        for a in ats:
            if y in a.get_budgets():
                for m in a.get_budgets(y):
                    months.add(bc.months(m))
        return sorted(months, key=lambda x: bc.months_to_int[x[:3]]) + [-1]
                            
    print("\nSelect Start Timeframe\n"+("="*40))
    
    y0 = bc.trans_timeframe(_uy(ats))               # basecui.py selects timeframe based off of one account 
    if y0 == -1: 
        return
    print()
    
    m0_str = bc.trans_timeframe(_um_ats(ats, y0))
    if m0_str == -1:
        return

    print("\nSelect End Timeframe\n"+("="*40))
    y1 = bc.trans_timeframe(_uy(ats))
    if y1 == -1: 
        return  
    print()
    m1_str = bc.trans_timeframe(_um_ats(ats, y1))
    if m1_str == -1:
        return
    
    k = _select_kind(ats)
    
    k_ats = [a for a in ats if a.get_kind() == k]
    total = round(sum(t.get_amount() for a in k_ats for t in a.get_ts())/100, 2)
    line = "{:>3}. {:30} {:>10.2f} ({:>6.2f}%)"
    
    print("\nBreakdown of " + bc.kind_to_str[k] + " by Account")
    print("{:4} {:32} {:>8} {:>5}".format("Num", "Account Name", "Amount", "Percent"))
    print("="*55)
    print(line.format(1, "TOTAL", total, 100))
    
    ats.sort(key=lambda x: x.get_name())
    for n, a in enumerate(k_ats, 2):
        print(_breakdown_str(n, a, 
        [(y,m) for y in a.get_budgets() for m in a.get_budgets(y) if _cond1(y,m)],
        total, line))
예제 #16
0
def _breakdown(ats: [Account]) -> None:
    """Executes choice to view the breakdown of transactions 
    of Accounts
    """
    def _um(a: Account, y: int) -> [int]:
        """Returns integers representing unique months of an Account and breakout integer
        """
        return sorted(set(bc.months_abv(m) for m in a.get_budgets(y)),
                      key=lambda x: bc.months_to_int[x]) + [-1]

    def _uy(a: Account or [Account]) -> [int]:
        """Returns integers representing unique years and breakout integer
        """
        if type(a) == Account:
            return sorted(set(y for y in a.get_budgets())) + [-1]
        return sorted(set(y for act in a for y in act.get_budgets())) + [-1]

    def _cond1(y, m):        return (y0, bc.months_to_int[m0_str[:3]]) \
<= (y,m) <= (y1, bc.months_to_int[m1_str[:3]])

    def _um_ats(ats: "generator", y: int) -> [int]:
        """Returns integers represnting unique months of an Account collection
        and breakout integer
        """
        months = set()
        for a in ats:
            if y in a.get_budgets():
                for m in a.get_budgets(y):
                    months.add(bc.months(m))
        return sorted(months, key=lambda x: bc.months_to_int[x[:3]]) + [-1]

    print("\nSelect Start Timeframe\n" + ("=" * 40))

    y0 = bc.trans_timeframe(
        _uy(ats))  # basecui.py selects timeframe based off of one account
    if y0 == -1:
        return
    print()

    m0_str = bc.trans_timeframe(_um_ats(ats, y0))
    if m0_str == -1:
        return

    print("\nSelect End Timeframe\n" + ("=" * 40))
    y1 = bc.trans_timeframe(_uy(ats))
    if y1 == -1:
        return
    print()
    m1_str = bc.trans_timeframe(_um_ats(ats, y1))
    if m1_str == -1:
        return

    k = _select_kind(ats)

    k_ats = [a for a in ats if a.get_kind() == k]
    total = round(
        sum(t.get_amount() for a in k_ats for t in a.get_ts()) / 100, 2)
    line = "{:>3}. {:30} {:>10.2f} ({:>6.2f}%)"

    print("\nBreakdown of " + bc.kind_to_str[k] + " by Account")
    print("{:4} {:32} {:>8} {:>5}".format("Num", "Account Name", "Amount",
                                          "Percent"))
    print("=" * 55)
    print(line.format(1, "TOTAL", total, 100))

    ats.sort(key=lambda x: x.get_name())
    for n, a in enumerate(k_ats, 2):
        print(
            _breakdown_str(n, a, [(y, m) for y in a.get_budgets()
                                  for m in a.get_budgets(y) if _cond1(y, m)],
                           total, line))