{# 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 %}Edit statement line charge{% endblock %} {% block content %} <h1 class="h2 my-4">Statement line</h1> <table class="table"> <thead> <tr> <th>Source account</th> <th>Date</th> <th>Description</th> <th>Dr</th> <th>Cr</th> <th>Balance</th> </tr> </thead> <tbody> <tr id="statement-line" data-quantity="{{ statement_line.amount().quantity_string() }}" data-commodity="{{ statement_line.commodity }}"> <td>{{ statement_line.source_account }}</td> <td>{{ statement_line.dt.strftime('%Y-%m-%d') }}</td> <td>{{ statement_line.description }}</td> <td>{{ statement_line.amount().format() if statement_line.quantity >= 0 else '' }}</td> <td>{{ (statement_line.amount()|abs).format() if statement_line.quantity < 0 else '' }}</td> <td>{{ statement_line.balance or '' }}</td> </tr> </tbody> </table> <h1 class="h2 mt-4 mb-4">Transaction</h1> <form method="POST"> <table class="table"> <thead> <tr> <th>Date</th> <th colspan="2">Description</th> <th>Dr</th> <th>Cr</th> </tr> </thead> <tbody> {# FIXME: Customise date, etc. #} <tr> <td>{{ statement_line.dt.strftime('%Y-%m-%d') }}</td> <td colspan="2"><input type="text" name="description" value="{{ statement_line.description }}" class="form-control"></td> <td></td> <td></td> </tr> <tr data-side="source"> {# Source line #} <td></td> <td></td> <td> <div class="input-group"> <div class="input-group-text">{{ 'Dr' if statement_line.quantity >= 0 else 'Cr' }}</div> <input type="text" class="form-control" value="{{ statement_line.source_account }}" disabled> </div> </td> {% if statement_line.quantity >= 0 %}<td class="has-amount">{{ statement_line.amount().format() }}</td>{% else %}<td></td>{% endif %} {% if statement_line.quantity < 0 %}<td class="has-amount">{{ (statement_line.amount()|abs).format() }}</td>{% else %}<td></td>{% endif %} </tr> {# Charge lines #} {% if transaction == None or transaction.postings|length == 2 %} <tr data-side="charge"> <td></td> <td></td> <td> <div class="input-group"> <div class="input-group-text">{{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }}</div> <input type="text" name="charge-account" class="form-control" value="{{ transaction.charge_account(statement_line.source_account) if transaction else '' }}"> <a class="btn btn-outline-primary" href="#" onclick="addPosting(this);return false;"><i class="bi bi-plus-circle-fill"></i></a> </div> </td> {% if statement_line.quantity < 0 %}<td class="has-amount">{{ (statement_line.amount()|abs).format() }}</td>{% else %}<td></td>{% endif %} {% if statement_line.quantity >= 0 %}<td class="has-amount">{{ statement_line.amount().format() }}</td>{% else %}<td></td>{% endif %} </tr> {% else %} {% for posting in transaction.postings if posting.account != statement_line.source_account %} <tr data-side="charge"> <td></td> <td></td> <td> <div class="input-group"> <div class="input-group-text">{{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }}</div> <input type="text" name="charge-account" class="form-control" value="{{ posting.account }}"> <a class="btn btn-outline-primary" href="#" onclick="addPosting(this);return false;"><i class="bi bi-plus-circle-fill"></i></a> </div> </td> {% if statement_line.quantity < 0 %} <td class="has-amount"> <div class="input-group"> <div class="input-group-text">{{ posting.commodity }}</div> <input type="number" name="charge-amount" step="0.01" value="{{ posting.amount().quantity_string() }}" class="form-control"> </div> </td> {% else %}<td></td>{% endif %} {% if statement_line.quantity >= 0 %} <td class="has-amount"> <div class="input-group"> <div class="input-group-text">{{ posting.commodity }}</div> <input type="number" name="charge-amount" step="0.01" value="{{ (posting.amount()|abs).quantity_string() }}" class="form-control"> </div> </td> {% else %}<td></td>{% endif %} </tr> {% endfor %} {% endif %} </tr> </tbody> </table> <div class="d-flex justify-content-end"> <button type="submit" class="btn btn-primary">Save</button> </div> </form> {% endblock %} {% block scripts %} <script> function addPosting(el) { let trPosting = el.parentNode.parentNode.parentNode; let trLine = document.getElementById('statement-line'); let qtyf = parseFloat(trLine.dataset.quantity); if (trPosting.dataset['side'] === 'source') { alert('NYI'); return; } if (trPosting.dataset['side'] === 'charge') { let inputAmount = '<td class="has-amount"><div class="input-group"><div class="input-group-text">' + trLine.dataset.commodity + '</div><input type="number" name="charge-amount" step="0.01" class="form-control"></div></td>'; // Add new posting row let trNew = document.createElement('tr'); trNew.dataset['side'] = 'charge'; trNew.innerHTML = '<td></td><td></td><td><div class="input-group"><div class="input-group-text">' + (qtyf >= 0 ? 'Cr' : 'Dr') + '</div><input type="text" name="charge-account" class="form-control"><a class="btn btn-outline-primary" href="#" onclick="addPosting(this);return false;"><i class="bi bi-plus-circle-fill"></i></a></div></td>' + (qtyf < 0 ? inputAmount : '<td></td>') + (qtyf >= 0 ? inputAmount : '<td></td>'); trPosting.after(trNew); // Put input box in existing row trPosting.querySelector('.has-amount').outerHTML = inputAmount; } } </script> {% endblock %}