Add account transactions view
This commit is contained in:
parent
77d23cb7b4
commit
b34ec8473e
89
drcr/templates/transactions.html
Normal file
89
drcr/templates/transactions.html
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
{# DrCr: Web-based double-entry bookkeeping framework
|
||||||
|
Copyright (C) 2022 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.html' %}
|
||||||
|
{% block title %}Account transactions{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="h2 mt-4 mb-4">Account transactions</h1>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Related Account</th>
|
||||||
|
<th class="text-end">Dr</th>
|
||||||
|
<th class="text-end">Cr</th>
|
||||||
|
<th class="text-end">Balance</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for transaction in transactions %}
|
||||||
|
{% if transaction.postings|length == 2 %}
|
||||||
|
{% for posting in transaction.postings if posting.account == account %}
|
||||||
|
{% set _ = running_total.__setattr__('quantity', running_total.quantity + posting.quantity) %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td>
|
||||||
|
<td>{{ transaction.description }}</td>
|
||||||
|
<td>{% for p in transaction.postings if p.account != account %}{{ p.account }}{% endfor %}</td>
|
||||||
|
<td class="text-end">{{ posting.amount().format() if posting.quantity >= 0 else '' }}</td>
|
||||||
|
<td class="text-end">{{ (posting.amount()|abs).format() if posting.quantity < 0 else '' }}</td>
|
||||||
|
<td class="text-end">{{ (running_total|abs).format() }}</td>
|
||||||
|
<td>{{ 'Dr' if running_total.quantity >= 0 else 'Cr' }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td>
|
||||||
|
<td colspan="2">{{ transaction.description }}</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
{% for posting in transaction.postings if posting.account == account %}
|
||||||
|
{% set _ = running_total.__setattr__('quantity', running_total.quantity + posting.quantity) %}
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td class="text-end"><i>{{ 'Dr' if posting.quantity >= 0 else 'Cr' }}</i></td>
|
||||||
|
<td>{{ account }}</td>
|
||||||
|
<td class="text-end">{{ posting.amount().format() if posting.quantity >= 0 else '' }}</td>
|
||||||
|
<td class="text-end">{{ (posting.amount()|abs).format() if posting.quantity < 0 else '' }}</td>
|
||||||
|
<td class="text-end">{{ (running_total|abs).format() }}</td>
|
||||||
|
<td>{{ 'Dr' if running_total.quantity >= 0 else 'Cr' }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% for posting in transaction.postings if posting.account != account %}
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td class="text-end"><i>{{ 'Dr' if posting.quantity >= 0 else 'Cr' }}</i></td>
|
||||||
|
<td>{{ posting.account }}</td>
|
||||||
|
<td class="text-end">{{ posting.amount().format() if posting.quantity >= 0 else '' }}</td>
|
||||||
|
<td class="text-end">{{ (posting.amount()|abs).format() if posting.quantity < 0 else '' }}</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -33,7 +33,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for name, balance in accounts.items() %}
|
{% for name, balance in accounts.items() %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ name }}</td>
|
<td><a href="/account-transactions?account={{ name }}">{{ name }}</a></td>
|
||||||
<td class="text-end">{{ balance.format() if balance.quantity >= 0 else '' }}</td>
|
<td class="text-end">{{ balance.format() if balance.quantity >= 0 else '' }}</td>
|
||||||
<td class="text-end">{{ (balance|abs).format() if balance.quantity < 0 else '' }}</td>
|
<td class="text-end">{{ (balance|abs).format() if balance.quantity < 0 else '' }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from flask import render_template
|
from flask import render_template, request
|
||||||
|
|
||||||
from .models import Amount, TrialBalancer
|
from .models import Amount, TrialBalancer
|
||||||
from .webapp import all_transactions, app
|
from .webapp import all_transactions, app
|
||||||
@ -36,3 +36,15 @@ def trial_balance():
|
|||||||
total_cr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity < 0), '$')
|
total_cr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity < 0), '$')
|
||||||
|
|
||||||
return render_template('trial_balance.html', accounts=dict(sorted(balancer.accounts.items())), total_dr=total_dr, total_cr=total_cr)
|
return render_template('trial_balance.html', accounts=dict(sorted(balancer.accounts.items())), total_dr=total_dr, total_cr=total_cr)
|
||||||
|
|
||||||
|
@app.route('/account-transactions')
|
||||||
|
def account_transactions():
|
||||||
|
# FIXME: Filter in SQL
|
||||||
|
transactions = [t for t in all_transactions() if any(p.account == request.args['account'] for p in t.postings)]
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'transactions.html',
|
||||||
|
account=request.args['account'],
|
||||||
|
running_total=Amount(0, '$'),
|
||||||
|
transactions=sorted(transactions, key=lambda t: t.dt)
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user