{# Lot ladder. Consumes `lot_rows` from _pane_lot_info() (Task 2). Layout: sorted by date desc by default; client-side Alpine sort on column headers lets the user flip by date / qty / basis / unrealized / status. Collapses to "N lots" toggle when N > 5. Each row: date · qty · adj basis · unrealized · status pill. Click on a lot opens the ticker lots view in a new tab. Status values: "ST" (short-term), "LT" (long-term), "TACKED" (IRC §1223(4)), "WS" (lot cost basis inflated by §1091(d) disallowed-loss roll-in). Status precedence: TACKED > WS > LT > ST. When a lot is both TACKED and WS-implicated, TACKED wins (holding-period concern is more material). Cross-account mode (cross_account=True): lot rows are grouped by account with a small section header per account. The per-row HTML is factored into the `lot_row` macro to avoid duplication between the flat-list and grouped branches. #} {% macro lot_row(row, sym) %} {{ row.date.isoformat() }} {{ fmt_quantity(row.qty) }} sh {{ fmt_currency(row.adj_basis) }} {% if row.unrealized is not none %} {{ fmt_currency(row.unrealized) }} {% else %} {% endif %} {{ row.status }} {% endmacro %} {% if lot_rows %} {% set _sorted = lot_rows | sort(attribute='date', reverse=True) %} {% set _collapsed = _sorted | length > 5 %}
container.appendChild(row)); }); } }"> {% if _collapsed %} {% else %}
{{ _sorted | length }} lot{{ 's' if _sorted | length != 1 else '' }}
{% endif %}
{# Column header row with click-to-sort #}
{% set _columns = [ ('date', 'Date'), ('qty', 'Qty'), ('basis', 'Basis'), ('unrealized', 'Unrealized'), ('status', 'Status'), ] %} {% for key, label in _columns %} {% endfor %}
{% if cross_account %} {# Group by account: render a small section header per account, then the rows for that account, preserving the date-desc sort within each group. distinct_account_displays is pre-sorted by the route so iteration order is deterministic. #} {% for account_display in distinct_account_displays %} {% set account_rows = _sorted | selectattr('account', 'equalto', account_display) | list %} {% if account_rows %}
{{ account_display }}
{% for row in account_rows %} {{ lot_row(row, sym) }} {% endfor %}
{% endif %} {% endfor %} {% else %}
{% for row in _sorted %} {{ lot_row(row, sym) }} {% endfor %}
{% endif %}
{% endif %}