Exemple #1
0
def input_recap(cycle):
    overview = dict()
    data_this_cycle = filter_df_on_cycle(read_data(), cycle)
    provisions_this_cycle = filter_df_on_cycle(read_deposit_input(), cycle)
    recap_by_category = recap_by_cat(cycle, False)
    if cycle_is_finished(cycle):
        overview['Input goal'] = - round(sum(recap_by_category['amount']), 2)
        overview['(actual) Over'] = overview['Input goal'] - sum(get_budgets(cycle)[amount_euro_col])
    else:
        overview['Budgets'] = round(sum(recap_by_category['budget']), 2)
        overview['Over (so far)'] = round(sum(recap_by_category['over']), 2)
        overview['Input goal'] = overview['Budgets'] + overview['Over (so far)']

    data_this_cycle_input = filter_df_one_value(data_this_cycle, 'category', 'Input')
    provisions_this_cycle_input = filter_df_one_value(provisions_this_cycle, 'category', 'Input')
    overview['Done'] = total_euro_amount(data_this_cycle_input) - total_euro_amount(provisions_this_cycle_input)
    remaining = round(overview['Input goal'] - overview['Done'], 2)
    if remaining > 0:
        overview['Remaining TO DO'] = remaining
    elif remaining < 0:
        overview['Margin'] = - remaining

    overview = pd.Series(overview).rename('amount', inplace=True).to_frame()
    add_column_with_value(overview, currency_col, default_currency)
    return overview
Exemple #2
0
def get_state_deposit(filter_null):
    selected_columns = [deposit_name_col, amount_euro_col]
    deposit = select_columns(get_deposit_input_and_output(), selected_columns)
    add_column_with_value(deposit, currency_col, default_currency)
    deposit_state = group_by_field(deposit, deposit_name_col).round(decimals=2)
    if filter_null:
        deposit_state = deposit_state[deposit_state != 0]
    return deposit_state
Exemple #3
0
def convert_non_euro_amounts(data):
    if value_is_nan(total_amount(data)):
        info('#Recap converting currencies with current rate')
        exchange_rate_col = 'exchange_rate'
        process_currency_data(data)
        apply_function_to_field_overrule(data,
                                         currency_col,
                                         latest_rate_from_euro,
                                         destination=exchange_rate_col)
        assign_new_column(
            data, 'amount',
            get_one_field(data, amount_euro_col) /
            get_one_field(data, exchange_rate_col))
        drop_columns(data, [exchange_rate_col])
    add_column_with_value(data, currency_col, default_currency)
Exemple #4
0
def identify_new_and_gone(data, latest_data, account):
    if df_is_not_empty(latest_data):
        add_link_ids(latest_data, '+', '-')
        condition1 = data['account'] == account
        condition2 = data['type'] != 'FIC'
        previous_data = data[both_series_are_true(condition1, condition2)]
        new_data = latest_data[latest_data['id'].isin(previous_data['id']) ==
                               False]
        previous_in_range = previous_data[
            previous_data['date'] >= min(latest_data['date'])]
        gone_data = previous_in_range[previous_in_range['id'].isin(
            latest_data['id']) == False]
        if df_is_not_empty(gone_data):
            add_link_ids(gone_data, '+', '-')
            add_column_with_value(new_data, 'replaces_a_pending', False)
            return new_data, gone_data
        return new_data, empty_data_dataframe()
    return empty_data_dataframe(), empty_data_dataframe()
Exemple #5
0
def recap_by_account(cycle):
    field_name = account_col
    selected_columns = [amount_euro_col, field_name, currency_col]

    cycle = decode_cycle(cycle)
    data = get_data_from_cycle(cycle)
    process_currency_data(data)

    if cycle != 'all':
        is_deposit = column_is_null(data, deposit_name_col) == False
        deposit_transactions = filter_df_on_bools(data, is_deposit)

        add_column_with_value(deposit_transactions, account_col, deposit_account)
        reverse_amount(deposit_transactions)

        data = select_columns(concat_lines([data, deposit_transactions]), selected_columns)

        deposit = get_deposit_debits_from_cycle(cycle)
        data = concat_lines([deposit, data])

    all_outputs = select_columns(data, selected_columns)
    recap = group_by_field(all_outputs, field_name).round(decimals=2)
    return recap
Exemple #6
0
def recap_by_cat(cycle, round_it=True):
    output_columns = ['category', 'currency', 'spent', 'remaining', 'spent_from_budget', 'amount', 'budget', 'over']
    data = get_data_from_cycle(cycle)
    deposit = get_deposit_debits_from_cycle(cycle)

    convert_non_euro_amounts(data)
    add_column_with_value(deposit, currency_col, default_currency)

    field_name = category_col
    selected_columns = [amount_euro_col, field_name, currency_col]
    data = filter_df_on_bools(data, column_is_null(data, deposit_name_col))
    data = select_columns(data, selected_columns)
    deposit = select_columns(deposit, selected_columns)

    all_output = concat_lines([data, deposit])
    if df_is_empty(all_output):
        return empty_df(columns=output_columns)

    spent = group_by_field(all_output, category_col).set_index(currency_col, append=True)
    if df_is_empty(spent):
        return empty_df(columns=output_columns)

    budgets = get_budgets(cycle).set_index(currency_col, append=True)
    rename_columns(budgets, {amount_euro_col: budgets_col})

    recap = concat_columns([spent, budgets], keep_index_name=True).round(2).fillna(0).reset_index()
    recap = filter_df_not_these_values(recap, category_col, no_recap_categories)

    over = positive_part(- recap[amount_euro_col] - recap[budgets_col])
    remaining = positive_part(recap[budgets_col] + recap[amount_euro_col])
    spent = positive_part(- recap[amount_euro_col] - over)

    assign_new_column(recap, 'over', ceil_series(over) if round_it else over)
    assign_new_column(recap, 'remaining', floor_series(remaining) if round_it else remaining)
    assign_new_column(recap, 'spent_from_budget', ceil_series(spent) if round_it else spent)

    return recap
Exemple #7
0
def read_deposit_input():
    deposit_input = read_data_from_file(provisions_file)
    add_column_with_value(deposit_input, type_trans_col, deposit_type)
    return deposit_input
Exemple #8
0
def edit_budgets(budgets, cycle):
    budgets_df = json_to_df(budgets, orient='records')
    add_column_with_value(budgets_df, cycle_col, cycle)
    return edit_budgets_cycle(budgets_df)
Exemple #9
0
def get_deposit_debits_from_cycle(cycle):
    deposit = filter_df_on_cycle(read_deposit_input(), cycle)
    deposit['amount'] = -deposit['amount']
    add_column_with_value(deposit, currency_col, default_currency)
    return deposit