2020-02-15 15:50:33 +11:00
|
|
|
{#
|
|
|
|
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/>.
|
|
|
|
#}
|
|
|
|
|
2020-03-20 23:20:39 +11:00
|
|
|
{% extends 'base_report.html' %}
|
|
|
|
|
2020-04-01 11:58:35 +11:00
|
|
|
{% block title %}{% if account %}Account Transactions{% else %}General Ledger{% endif %} for the {{ period }}{% endblock %}
|
2020-03-20 23:20:39 +11:00
|
|
|
|
2020-03-23 17:17:10 +11:00
|
|
|
{% block links %}
|
|
|
|
{{ super() }}
|
2020-04-01 11:58:35 +11:00
|
|
|
{% if account %}<a href="/transactions?{{ {'date_end': date_end.strftime('%Y-%m-%d'), 'date_beg': date_beg.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else '', 'commodity': 'on'}|urlencode }}">Show commodity detail</a>{% endif %}
|
2020-03-23 17:17:10 +11:00
|
|
|
{% endblock %}
|
|
|
|
|
2020-03-20 23:20:39 +11:00
|
|
|
{% block report %}
|
|
|
|
{% if account %}
|
|
|
|
<h1>Account Transactions</h1>
|
|
|
|
<h2 style="margin-bottom: 0;">For {{ account.name }}</h2>
|
|
|
|
{% else %}
|
|
|
|
<h1>General Ledger</h1>
|
|
|
|
{% endif %}
|
|
|
|
<h2>For the {{ period }}</h2>
|
|
|
|
|
|
|
|
<table class="ledger">
|
|
|
|
<tr>
|
2020-03-31 03:01:27 +11:00
|
|
|
<th style="min-width: 5em;">Date</th>
|
|
|
|
<th style="width: 50%;">Description</th>
|
|
|
|
<th style="width: 50%;">{% if account %}Related {% endif %}Account</th>
|
|
|
|
<th style="text-align: right; min-width: 5em;">Dr</th>
|
|
|
|
<th style="text-align: right; min-width: 5em;">Cr</th>
|
|
|
|
{% if account %}<th style="text-align: right; min-width: 6em;">Balance</th>{% endif %}
|
2020-03-20 23:20:39 +11:00
|
|
|
</tr>
|
2020-02-15 15:50:33 +11:00
|
|
|
|
2020-03-20 23:20:39 +11:00
|
|
|
{% set ns = namespace(balance=None) %}
|
|
|
|
{% if account %}
|
2020-04-01 11:58:35 +11:00
|
|
|
{% 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 ''}|urlencode %}
|
2020-05-08 23:20:18 +10:00
|
|
|
<tr class="total trn-first trn-last">
|
2020-04-01 11:58:35 +11:00
|
|
|
<td><a href="{{ prevlink }}">{{ date_beg.strftime('%Y-%m-%d') }}</a></td>
|
2020-03-23 02:01:53 +11:00
|
|
|
<td><a href="{{ prevlink }}">Opening Balance</a></td>
|
2020-03-20 23:20:39 +11:00
|
|
|
<td></td>
|
|
|
|
<td style="text-align: right;"></td>
|
|
|
|
<td style="text-align: right;"></td>
|
|
|
|
<td style="text-align: right;">
|
2020-03-23 02:01:53 +11:00
|
|
|
<a href="{{ prevlink }}">
|
2020-03-20 21:43:05 +11:00
|
|
|
{% if opening_balance >= 0 %}
|
|
|
|
{{ opening_balance|b }} Dr
|
|
|
|
{% else %}
|
|
|
|
{{ -opening_balance|b }} Cr
|
|
|
|
{% endif %}
|
2020-03-20 23:20:39 +11:00
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{% set ns.balance = opening_balance %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% for transaction in transactions %}
|
2020-07-17 11:31:35 +10:00
|
|
|
{% 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 %}
|
2020-05-08 23:35:04 +10:00
|
|
|
|
|
|
|
{% if transaction.has_comment_detail %}
|
|
|
|
<tr class="trn-first">
|
|
|
|
<td>{% if transaction.id %}<a href="{{ trn_url }}">{% endif %}{{ transaction.date.strftime('%Y-%m-%d') }}{% if transaction.id %}</a>{% endif %}</td>
|
|
|
|
<td>{% if transaction.id %}<a href="{{ trn_url }}">{% endif %}{{ transaction.description }}{% if transaction.id %}</a>{% endif %}</td>
|
|
|
|
<td></td>
|
|
|
|
{% if account %}
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
{% else %}
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
{% endif %}
|
|
|
|
</tr>
|
2020-05-17 15:15:19 +10:00
|
|
|
|
|
|
|
{# This account's comment #}
|
|
|
|
{% if account %}
|
|
|
|
{% 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>
|
|
|
|
</tr>
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2020-05-08 23:35:04 +10:00
|
|
|
{% endif %}
|
|
|
|
|
2020-06-07 23:57:26 +10:00
|
|
|
{% for posting in transaction.exchange(report_commodity).postings if posting.account != account %}
|
2020-05-08 23:35:04 +10:00
|
|
|
{% set trn_first = not transaction.has_comment_detail and loop.first %}
|
|
|
|
{% set trn_last = loop.last %}
|
|
|
|
|
|
|
|
<tr{% if trn_first and trn_last %} class="trn-first trn-last"{% elif trn_first %} class="trn-first"{% elif trn_last %} class="trn-last"{% endif %}>
|
|
|
|
<td>{% if trn_first %}{% if transaction.id %}<a href="{{ trn_url }}">{% endif %}{{ transaction.date.strftime('%Y-%m-%d') }}{% if transaction.id %}</a>{% endif %}{% endif %}</td>
|
|
|
|
{% if trn_first %}
|
|
|
|
<td>{% if transaction.id %}<a href="{{ trn_url }}">{% endif %}{{ transaction.description }}{% if transaction.id %}</a>{% endif %}</td>
|
|
|
|
{% elif transaction.has_comment_detail and posting.comment %}
|
|
|
|
<td style="padding-left: 1.5em;">{{ posting.comment }}</td>
|
|
|
|
{% else %}
|
|
|
|
<td></td>
|
|
|
|
{% endif %}
|
2020-04-01 11:58:35 +11:00
|
|
|
<td><a href="/transactions?{{ {'date_end': date_end.strftime('%Y-%m-%d'), 'date_beg': date_beg.strftime('%Y-%m-%d'), 'account': posting.account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ (posting.account.name|e).__str__().replace(':', ':<wbr>')|safe }}</a></td>
|
2020-03-20 23:20:39 +11:00
|
|
|
{% if account %}
|
|
|
|
{# Reverse Dr/Cr so it's from the "perspective" of this account #}
|
2020-06-07 23:57:26 +10:00
|
|
|
{% set ns.balance = ns.balance - posting.amount %}
|
|
|
|
<td style="text-align: right;">{% if posting.amount < 0 %}{{ -posting.amount|b }}{% endif %}</td>
|
|
|
|
<td style="text-align: right;">{% if posting.amount > 0 %}{{ posting.amount|b }}{% endif %}</td>
|
2020-03-20 23:20:39 +11:00
|
|
|
<td style="text-align: right;">
|
|
|
|
{% if loop.last %}
|
|
|
|
{% if ns.balance >= 0 %}
|
|
|
|
{{ ns.balance|b }} Dr
|
|
|
|
{% else %}
|
|
|
|
{{ -ns.balance|b }} Cr
|
2020-03-20 18:54:01 +11:00
|
|
|
{% endif %}
|
2020-03-20 23:20:39 +11:00
|
|
|
{% endif %}
|
|
|
|
</td>
|
|
|
|
{% else %}
|
2020-06-07 23:57:26 +10:00
|
|
|
<td style="text-align: right;">{% if posting.amount > 0 %}{{ posting.amount|b }}{% endif %}</td>
|
|
|
|
<td style="text-align: right;">{% if posting.amount < 0 %}{{ -posting.amount|b }}{% endif %}</td>
|
2020-03-20 23:20:39 +11:00
|
|
|
{% endif %}
|
2020-03-20 21:43:05 +11:00
|
|
|
</tr>
|
2020-03-20 23:20:39 +11:00
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% if account %}
|
2020-07-17 11:32:49 +10:00
|
|
|
{% 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 %}
|
2020-05-08 23:20:18 +10:00
|
|
|
<tr class="total trn-first trn-last">
|
2020-07-17 11:32:49 +10:00
|
|
|
<td><a href="{{ nextlink }}">{{ date_end.strftime('%Y-%m-%d') }}</a></td>
|
|
|
|
<td><a href="{{ nextlink }}">Closing Balance</a></td>
|
2020-03-20 23:20:39 +11:00
|
|
|
<td></td>
|
|
|
|
<td style="text-align: right;"></td>
|
|
|
|
<td style="text-align: right;"></td>
|
|
|
|
<td style="text-align: right;">
|
2020-07-17 11:32:49 +10:00
|
|
|
<a href="{{ nextlink }}">
|
|
|
|
{% if closing_balance >= 0 %}
|
|
|
|
{{ closing_balance|b }} Dr
|
|
|
|
{% else %}
|
|
|
|
{{ -closing_balance|b }} Cr
|
|
|
|
{% endif %}
|
|
|
|
</a>
|
2020-03-20 23:20:39 +11:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{% else %}
|
2020-05-08 23:20:18 +10:00
|
|
|
<tr class="total trn-first trn-last">
|
2020-04-01 11:58:35 +11:00
|
|
|
<td>{{ date_end.strftime('%Y-%m-%d') }}</td>
|
2020-03-20 23:20:39 +11:00
|
|
|
<td>Total</td>
|
|
|
|
<td></td>
|
|
|
|
<td style="text-align: right;">{{ total_dr|b }}</td>
|
|
|
|
<td style="text-align: right;">{{ -total_cr|b }}</td>
|
|
|
|
</tr>
|
|
|
|
{% endif %}
|
|
|
|
</table>
|
|
|
|
{% endblock %}
|