Complete implementation of balance sheet

This commit is contained in:
RunasSudo 2022-12-25 00:21:03 +11:00
parent 7bbbce7a65
commit f97e7e10e0
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 157 additions and 8 deletions

View File

@ -16,7 +16,7 @@
from flask import render_template from flask import render_template
from ..config import COA_MAPPING from ..config import BALANCE_SHEET_MAPPING, COA_MAPPING
from ..models import Amount, TrialBalancer from ..models import Amount, TrialBalancer
from ..webapp import all_transactions, app from ..webapp import all_transactions, app
@ -30,10 +30,7 @@ def balance_sheet():
for source_account, destination_account in COA_MAPPING.items(): for source_account, destination_account in COA_MAPPING.items():
balancer.transfer_balance(source_account, destination_account) balancer.transfer_balance(source_account, destination_account)
balancer.transfer_balance('Income', 'Equity') balancer.transfer_balance('Income', 'Current year surplus (deficit)')
balancer.transfer_balance('Expenses', 'Equity') balancer.transfer_balance('Expenses', 'Current year surplus (deficit)')
total_dr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity > 0), '$') return render_template('reports/balance_sheet.html', accounts=balancer.accounts, running_total=Amount(0, '$'), BALANCE_SHEET_MAPPING=BALANCE_SHEET_MAPPING)
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)

View File

@ -26,9 +26,16 @@
</head> </head>
<body> <body>
{% block body %} {% block body %}
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-sm navbar-light bg-light">
<div class="container"> <div class="container">
<a class="navbar-brand" href="/">DrCr</a> <a class="navbar-brand" href="/">DrCr</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="/general-journal">General journal</a></li>
<li class="nav-item"><a class="nav-link" href="/statement-lines">Statement lines</a></li>
<li class="nav-item"><a class="nav-link" href="/trial-balance">Trial balance</a></li>
</ul>
</div>
</div> </div>
</nav> </nav>
<div class="container"> <div class="container">

View File

@ -0,0 +1,145 @@
{# 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 %}Balance sheet{% endblock %}
{% macro fmtbal(amount, mul=1) %}
{# FIXME: Honour AMOUNT_DPS #}
{% if amount.quantity * mul >= 0 %}
{{ '{:,.2f}'.format(amount.quantity|abs / 100) }}&nbsp;
{% else %}
({{ '{:,.2f}'.format(amount.quantity|abs / 100) }})
{% endif %}
{% endmacro %}
{% macro acctrow(name, mul=1) %}
<tr>
<td>{{ name }}</td>
<td class="text-end">{{ fmtbal(accounts[name], mul) }}</td>
</tr>
{% set _ = running_total.__setattr__('quantity', running_total.quantity + accounts[name].quantity) %}
{% endmacro %}
{% block content %}
<h1 class="h2 mt-4">Balance sheet</h1>
<table class="table table-borderless table-sm">
<thead>
<tr style="border-width:0 0 1px 0">
<th></th>
<th class="text-end">$</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="2">Current assets</th>
</tr>
{% set _ = running_total.__setattr__('quantity', 0) %}
{% for account in BALANCE_SHEET_MAPPING['Current assets'] %}
{{ acctrow(account) }}
{% endfor %}
<tr>
<th>Total current assets</th>
<th class="text-end">{{ fmtbal(running_total) }}</th>
</tr>
{% set assets = running_total.quantity %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th colspan="2">Non-current assets</th>
</tr>
{% set _ = running_total.__setattr__('quantity', 0) %}
{% for account in BALANCE_SHEET_MAPPING['Non-current assets'] %}
{{ acctrow(account) }}
{% endfor %}
<tr>
<th>Total non-current assets</th>
<th class="text-end">{{ fmtbal(running_total) }}</th>
</tr>
{% set assets = assets + running_total.quantity %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr style="border-width:1px 0">
<th>Total assets</th>
{% set _ = running_total.__setattr__('quantity', assets) %}
<th class="text-end">{{ fmtbal(running_total) }}</th>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th colspan="2">Current liabilities</th>
</tr>
{% set _ = running_total.__setattr__('quantity', 0) %}
{% for account in BALANCE_SHEET_MAPPING['Current liabilities'] %}
{{ acctrow(account, -1) }}
{% endfor %}
<tr>
<th>Total current liabilities</th>
<th class="text-end">{{ fmtbal(running_total, -1) }}</th>
</tr>
{% set liabilities = running_total.quantity %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th colspan="2">Non-current liabilities</th>
</tr>
{% set _ = running_total.__setattr__('quantity', 0) %}
{% for account in BALANCE_SHEET_MAPPING['Non-current liabilities'] %}
{{ acctrow(account, -1) }}
{% endfor %}
<tr>
<th>Total non-current liabilities</th>
<th class="text-end">{{ fmtbal(running_total, -1) }}</th>
</tr>
{% set liabilities = liabilities + running_total.quantity %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr style="border-width:1px 0">
<th>Total liabilities</th>
{% set _ = running_total.__setattr__('quantity', liabilities) %}
<th class="text-end">{{ fmtbal(running_total, -1) }}</th>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr style="border-width:1px 0">
<th>Net assets</th>
{% set _ = running_total.__setattr__('quantity', assets + liabilities) %}
<th class="text-end">{{ fmtbal(running_total) }}</th>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th colspan="2">Equity</th>
</tr>
{% set _ = running_total.__setattr__('quantity', 0) %}
{{ acctrow('Accumulated surplus (deficit)', -1) }}
{{ acctrow('Current year surplus (deficit)', -1) }}
<tr style="border-width:1px 0">
<th>Total equity</th>
<th class="text-end">{{ fmtbal(running_total, -1) }}</th>
</tr>
</tbody>
</table>
{% endblock %}