ledger-pyreport/ledger_pyreport/jinja2/transactions_commodity.html

143 lines
6.0 KiB
HTML

{#
ledger-pyreport
Copyright © 2020 Lee Yingtong Li (RunasSudo)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
#}
{% extends 'base_report.html' %}
{% block title %}Account Transactions for the {{ period }}{% endblock %}
{% block report %}
<h1>Account Transactions</h1>
<h2 style="margin-bottom: 0;">For {{ account.name }}</h2>
<h2>For the {{ period }}</h2>
<table class="ledger">
<tr>
<th style="min-width: 5em;">Date</th>
<th style="width: 100%;">Description</th>
<th style="min-width: 1em;"></th> {# Dr/Cr #}
<th style="text-align: right; min-width: 4em;">Amount</th>
<th style="min-width: 2em;"></th> {# Commodity #}
<th style="text-align: right; min-width: 4em;">Balance</th>
<th style="min-width: 2em;"></th> {# Commodity #}
<th style="min-width: 2em;"></th> {# Price #}
<th style="min-width: 1em;"></th>
</tr>
{% set ns = namespace(balance=None) %}
{% set prevlink = '/transactions?' + {'date_end': (date_beg - timedelta(days=1)).strftime('%Y-%m-%d'), 'date_beg': date_beg.replace(year=date_beg.year-1).strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else '', 'commodity': 'on'}|urlencode %}
{% for amount in opening_balance.amounts %}
<tr class="total{% if loop.first %} trn-first{% endif %}{% if loop.last %} trn-last{% endif %}">
<td>{% if loop.first %}<a href="{{ prevlink }}">{{ date_beg.strftime('%Y-%m-%d') }}</a>{% endif %}</td>
<td>{% if loop.first %}<a href="{{ prevlink }}">Opening Balance</a>{% endif %}</td>
<td></td>
<td></td>
<td></td>
{{ amount|abs|bt(True, prevlink) }}
<td>{% if amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
{% else %}
<tr class="total trn-first trn-last">
<td><a href="{{ prevlink }}">{{ date_beg.strftime('%Y-%m-%d') }}</a></td>
<td><a href="{{ prevlink }}">Opening Balance</a></td>
<td></td>
<td></td>
<td></td>
<td style="text-align: right;"><a href="{{ prevlink }}">0.00</a></td>
<td></td>
<td></td>
<td>Dr</td>
</tr>
{% endfor %}
{% set ns.balance = opening_balance %}
{% for transaction in transactions %}
{% set trn_url = '/transaction?' + {'date': date_end.strftime('%Y-%m-%d'), 'pstart': date_beg.strftime('%Y-%m-%d'), 'uuid': transaction.uuid, 'cash': 'on' if cash else ''}|urlencode %}
{% for posting in transaction.postings if posting.account == account %}
{% set ns.balance = ns.balance + posting.amount %}
{% endfor %}
{% for amount in ns.balance.amounts %}
{% set posting = matching_posting(transaction, amount) %}
<tr{% if loop.first and loop.last %} class="trn-first trn-last"{% elif loop.first %} class="trn-first"{% elif loop.last %} class="trn-last"{% endif %}>
<td>{% if loop.first %}{% if transaction.id %}<a href="{{ trn_url }}">{% endif %}{{ transaction.date.strftime('%Y-%m-%d') }}{% if transaction.id %}</a>{% endif %}{% endif %}</td>
<td>{% if loop.first %}{% if transaction.id %}<a href="{{ trn_url }}">{% endif %}{{ transaction.description }}{% if transaction.id %}</a>{% endif %}{% endif %}</td>
{% if posting %}
<td>{% if posting.amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
{{ posting.amount|abs|bt(False) }}
{% else %}
<td colspan="3"></td>
{% endif %}
{{ amount|abs|bt(True) }}
<td>{% if amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
{% endfor %}
{% set ns.balance = ns.balance.clean() %}
{# This account's comment #}
{% for posting in transaction.postings if posting.account == account and posting.comment %}
<tr>
<td></td>
<td style="padding-left: 0.75em;">{{ posting.comment }}</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
{% endfor %}
{% endfor %}
{% set nextlink = '/transactions?' + {'date_beg': (date_end + timedelta(days=1)).strftime('%Y-%m-%d'), 'date_end': date_end.replace(year=date_end.year+1).strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode %}
{% for amount in closing_balance.amounts %}
<tr class="total explicit-rules{% if loop.first %} trn-first{% endif %}{% if loop.last %} trn-last{% endif %}" style="{% if loop.first %}border-top: 1pt solid black;{% endif %}{% if loop.last %}border-bottom: 1pt solid black;{% endif %}">
<td>{% if loop.first %}<a href="{{ nextlink }}">{{ date_end.strftime('%Y-%m-%d') }}</a>{% endif %}</td>
<td>{% if loop.first %}<a href="{{ nextlink }}">Closing Balance</a>{% endif %}</td>
<td></td>
<td></td>
<td></td>
{{ amount|abs|bt(True) }}
<td>{% if amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
{% endfor %}
{% for amount in closing_balance.strip_prices().amounts %}
<tr class="total explicit-rules{% if loop.first %} trn-first{% endif %}{% if loop.last %} trn-last{% endif %}" style="{% if loop.first %}border-top: 1pt solid black;{% endif %}{% if loop.last %}border-bottom: 1pt solid black;{% endif %}">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
{{ amount|abs|bt(True) }}
<td>{% if amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
{% endfor %}
<tr class="total trn-first trn-last">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
{% set closing_balance = closing_balance.exchange(report_commodity, True) %}
{{ closing_balance|abs|bt(True) }}
<td>{% if closing_balance >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
</table>
{% endblock %}