{% extends "_layout.html" %} {% set active_page = 'holdings' %} {% import 'macros/_account_macros.html' as account_macros with context %} {% import '_query_table.html' as querytable with context %} {% macro num_cell(value, currency) -%} {{ value|format_currency(currency) }} {%- endmacro %} {% set holdings_by = { 'none': 'SELECT account, units(sum(position)) as units, cost_number as cost, first(getprice(currency, cost_currency)) as price, cost(sum(position)) as book_value, value(sum(position)) as market_value, cost_date as acquision_date WHERE account_sortkey(account) ~ "^[01]" GROUP BY account, cost_date, currency, cost_currency, cost_number, account_sortkey(account) ORDER BY account_sortkey(account)', 'account': 'SELECT account, units(sum(position)) as units, sum(cost_number)/count(cost_number) as average_cost, sum(getprice(currency, cost_currency))/count(cost_currency) as average_price, cost(sum(position)) as book_value, value(sum(position)) as market_value WHERE account_sortkey(account) ~ "^[01]" GROUP BY account, cost_currency, account_sortkey(account) ORDER BY account_sortkey(account)', 'currency': 'SELECT units(sum(position)) as units, sum(cost_number)/count(cost_number) as average_cost, sum(getprice(currency, cost_currency))/count(cost_currency) as average_price, cost(sum(position)) as book_value, value(sum(position)) as market_value WHERE account_sortkey(account) ~ "^[01]" GROUP BY currency, cost_currency ORDER BY currency, cost_currency', 'cost_currency': 'SELECT units(sum(position)) as units, sum(cost_number)/count(cost_number) as average_cost, sum(getprice(currency, cost_currency))/count(cost_currency) as average_price, cost(sum(position)) as book_value, value(sum(position)) as market_value WHERE account_sortkey(account) ~ "^[01]" GROUP BY cost_currency ORDER BY cost_currency', } %} {% set units_column = { 'none': 1, 'account': 1, 'currency': 0, 'cost_currency': 0, } %} {% block content %}

{% if aggregation_key %}{{ _('Holdings') }}{% else %}{{ _('Holdings') }}{% endif %}

{% for key, label in [('account', _('Account')), ('currency', _('Currency')), ('cost_currency', _('Cost currency'))] %}

{% if not (aggregation_key == key) %}{{ _('Holdings by') }} {{ label }}{% else %}{{ _('Holdings by') }} {{ label }}{% endif %}

{% endfor %}
{% if not aggregation_key %}{% set aggregation_key = 'none' %}{% endif %} {% set query = holdings_by[aggregation_key] %}

Query {{ querytable.download_links(query) }}

{% set contents, result_types, result_rows = ledger.query_shell.execute_query(holdings_by[aggregation_key]) %} {{ querytable.querytable(result_types, result_rows, filter_empty=units_column[aggregation_key]) }} {% endblock %}