DrCr/drcr/templates/statement_lines.html

79 lines
3.1 KiB
HTML

{# 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 %}Statement lines{% endblock %}
{% block body %}
<div class="container">
<h1 class="h2 mt-4 mb-4">Statement lines</h1>
<table class="table">
<thead>
<tr>
<th>Source account</th>
<th>Date</th>
<th>Description</th>
<th>Charged to</th>
<th>Dr</th>
<th>Cr</th>
<th>Balance</th>
</tr>
</thead>
<tbody>
{% for line in statement_lines %}
<tr data-line-id="{{ line.id }}">
<td>{{ line.source_account }}</td>
<td>{{ line.dt.strftime('%Y-%m-%d') }}</td>
<td>{{ line.description }}</td>
{% if line.postings|length > 1 %}
<td class="charge-account"><i class="bi bi-info-circle-fill" title="Complex transaction"></i></td>
{% elif line.postings|length == 0 %}
<td class="charge-account"><a href="#" class="text-danger" onclick="classifyLine({{ line.id }});return false;">Unclassified</a> <a href="/statement-lines/edit-transaction?line-id={{ line.id }}" class="text-muted"><i class="bi bi-pencil"></i></a></td>
{% else %}
<td class="charge-account"><a href="#" class="text-body" onclick="classifyLine({{ line.id }});return false;">{{ line.postings[0].transaction.charge_account(line.source_account) }}</a> <a href="/statement-lines/edit-transaction?line-id={{ line.id }}" class="text-muted"><i class="bi bi-pencil"></i></a></td>
{% endif %}
<td>{{ line.amount().format() if line.quantity >= 0 else '' }}</td>
<td>{{ (line.amount()|abs).format() if line.quantity < 0 else '' }}</td>
<td>{{ line.balance or '' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script>
function classifyLine(lineId) {
let chargeAccount = prompt('Charge to:');
if (!chargeAccount) {
return;
}
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', function() {
if (xhr.status === 200) {
document.querySelector('[data-line-id="' + lineId + '"] .charge-account a').innerText = chargeAccount;
document.querySelector('[data-line-id="' + lineId + '"] .charge-account a').className = 'text-body';
}
});
xhr.open('POST', '/statement-lines/charge');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('line-id=' + lineId + '&charge-account=' + chargeAccount);
}
</script>
{% endblock %}