Compare commits
147 Commits
v0.3.1
...
9993f65627
Author | SHA1 | Date | |
---|---|---|---|
9993f65627 | |||
fe01d5418d | |||
2f7b9932a0 | |||
1eed16b732 | |||
ede1160943 | |||
3814f0cb18 | |||
24315b8203 | |||
3c200d0dc6 | |||
9f1e724875 | |||
f838e7f893 | |||
edb893ecd3 | |||
436a4c367f | |||
1813ce0cfa | |||
7683347997 | |||
46ffc7a73d | |||
e0a807d625 | |||
dffcf6d2ce | |||
84d239e4b1 | |||
fcefc64117 | |||
81fbb380b4 | |||
d7ac8a3dcf | |||
bcd3418e2c | |||
ef9e5cb5b3 | |||
e797cfeb8c | |||
22bae7f766 | |||
aa669e9f53 | |||
898a1af7b5 | |||
f762bcf48f | |||
5d4effa360 | |||
dd05478bf3 | |||
9450915404 | |||
8d126e183f | |||
bfb08cf5fc | |||
a7bcf4b5c1 | |||
cd49ca44b1 | |||
734362396f | |||
88147bea66 | |||
cca43c68a6 | |||
480e2d2d8f | |||
be100ce7ec | |||
eca91d32ed | |||
1f95212494 | |||
0173104c84 | |||
6e33fa775d | |||
e244ff70e6 | |||
ace782a26b | |||
90289a0db2 | |||
7e7e1a2844 | |||
ddd028736c | |||
e1d35a64da | |||
39807ef480 | |||
39723b1299 | |||
8cd004bede | |||
4f112dd386 | |||
b806b1ed1f | |||
1d0a79e33c | |||
d4a690ebbc | |||
68687897f3 | |||
a7250fd9bf | |||
eabe80b790 | |||
fe77f87110 | |||
32c27d7c07 | |||
14b871b57a | |||
9d5fce2752 | |||
d333151731 | |||
b2e500a714 | |||
b705795b44 | |||
250f4ff1ae | |||
6bed180790 | |||
10fbc3f638 | |||
f65dc6fc42 | |||
9833bac6e4 | |||
7d412b20d7 | |||
9bfcd3c50c | |||
55c2ce6695 | |||
493677e0aa | |||
710c26d016 | |||
24415018b7 | |||
c50b9a2000 | |||
af9bd14eed | |||
9e1ff16e96 | |||
f7c1fd77f2 | |||
641315537d | |||
a895bd8560 | |||
ca86a08f3e | |||
e118422441 | |||
b3777cffbf | |||
39c9c17007 | |||
3ab4eacf9f | |||
cff3d1b6bd | |||
f41db78831 | |||
73f7d14e7b | |||
f6ed6b10a7 | |||
b5aaee4d15 | |||
c849d6b3d4 | |||
a9908a7df4 | |||
063c769158 | |||
f8e9871300 | |||
78a62a9575 | |||
85fde6219e | |||
4eb9346d8d | |||
11966a52ba | |||
8cf81b5459 | |||
cc958a39b3 | |||
9065686cc5 | |||
9a41cb10a1 | |||
6957e52d0d | |||
9cd9e90be0 | |||
2839dc60b4 | |||
f3548a2327 | |||
79883d6940 | |||
b2bc993416 | |||
453b3f0da5 | |||
63ae3f0746 | |||
da4cc6489f | |||
1102a3a4f3 | |||
1402a12f04 | |||
f049b5d7ee | |||
14ed4ca354 | |||
535ff96ab3 | |||
57482f81fc | |||
a31ce3c400 | |||
319f0aed90 | |||
826dcf0f86 | |||
b2411aee74 | |||
731acdced0 | |||
35b3bca1e6 | |||
3c413497ae | |||
1b5e516413 | |||
20cb5cecc4 | |||
08dc24605d | |||
bb7e9e94ee | |||
2680a1c872 | |||
20a7ce591c | |||
474e844ed9 | |||
b34955f2fb | |||
2bd0f0f14d | |||
8b77d9ff93 | |||
a9c7360020 | |||
d02c87602b | |||
9f966643b5 | |||
5746e2a3d6 | |||
d5c2231794 | |||
fc8e257a10 | |||
2e9bf382fb | |||
de48c848da | |||
9cdcc828a7 |
@ -36,6 +36,14 @@ accounting.transaction.query module
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
accounting.transaction.summary\_helper module
|
||||
---------------------------------------------
|
||||
|
||||
.. automodule:: accounting.transaction.summary_helper
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
accounting.transaction.template module
|
||||
--------------------------------------
|
||||
|
||||
|
@ -13,7 +13,7 @@ sys.path.insert(0, os.path.abspath('../../src/'))
|
||||
project = 'Mia! Accounting Flask'
|
||||
copyright = '2023, imacat'
|
||||
author = 'imacat'
|
||||
release = '0.0.0'
|
||||
release = '0.4.0'
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
@ -28,5 +28,5 @@ exclude_patterns = []
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||
|
||||
html_theme = 'nature'
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
html_static_path = ['_static']
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
[metadata]
|
||||
name = mia-accounting-flask
|
||||
version = 0.3.1
|
||||
version = 0.4.0
|
||||
author = imacat
|
||||
author_email = imacat@mail.imacat.idv.tw
|
||||
description = The Mia! Accounting Flask project.
|
||||
|
@ -58,12 +58,26 @@ def init_app(app: Flask, user_utils: AbstractUserUtils,
|
||||
template_folder="templates",
|
||||
static_folder="static")
|
||||
|
||||
from .template_filters import format_amount, format_date, default
|
||||
bp.add_app_template_filter(format_amount, "accounting_format_amount")
|
||||
bp.add_app_template_filter(format_date, "accounting_format_date")
|
||||
bp.add_app_template_filter(default, "accounting_default")
|
||||
|
||||
from .template_globals import currency_options, default_currency_code
|
||||
bp.add_app_template_global(currency_options,
|
||||
"accounting_currency_options")
|
||||
bp.add_app_template_global(default_currency_code,
|
||||
"accounting_default_currency_code")
|
||||
|
||||
from . import locale
|
||||
locale.init_app(app, bp)
|
||||
|
||||
from .utils import permission
|
||||
permission.init_app(bp, can_view_func, can_edit_func)
|
||||
|
||||
from .utils import next_uri
|
||||
next_uri.init_app(bp)
|
||||
|
||||
from . import base_account
|
||||
base_account.init_app(app, bp)
|
||||
|
||||
@ -76,7 +90,7 @@ def init_app(app: Flask, user_utils: AbstractUserUtils,
|
||||
from . import transaction
|
||||
transaction.init_app(app, bp)
|
||||
|
||||
from .utils import next_uri
|
||||
next_uri.init_app(bp)
|
||||
from . import report
|
||||
report.init_app(app, bp)
|
||||
|
||||
app.register_blueprint(bp)
|
||||
|
@ -14,7 +14,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The account query.
|
||||
"""The queries for the account management.
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
@ -33,7 +33,7 @@ from accounting.utils.pagination import Pagination
|
||||
from accounting.utils.permission import can_view, has_permission, can_edit
|
||||
from accounting.utils.user import get_current_user_pk
|
||||
from .forms import AccountForm, sort_accounts_in, AccountReorderForm
|
||||
from .query import get_account_query
|
||||
from .queries import get_account_query
|
||||
|
||||
bp: Blueprint = Blueprint("account", __name__)
|
||||
"""The view blueprint for the account management."""
|
||||
|
@ -14,7 +14,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The base account query.
|
||||
"""The queries for the base account management.
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
@ -34,7 +34,7 @@ def list_accounts() -> str:
|
||||
|
||||
:return: The account list.
|
||||
"""
|
||||
from .query import get_base_account_query
|
||||
from .queries import get_base_account_query
|
||||
accounts: list[BaseAccount] = get_base_account_query()
|
||||
pagination: Pagination = Pagination[BaseAccount](accounts)
|
||||
return render_template("accounting/base-account/list.html",
|
||||
|
@ -14,7 +14,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The currency query.
|
||||
"""The queries for the currency management.
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
@ -47,7 +47,7 @@ def list_currencies() -> str:
|
||||
|
||||
:return: The currency list.
|
||||
"""
|
||||
from .query import get_currency_query
|
||||
from .queries import get_currency_query
|
||||
currencies: list[Currency] = get_currency_query()
|
||||
pagination: Pagination = Pagination[Currency](currencies)
|
||||
return render_template("accounting/currency/list.html",
|
||||
|
@ -203,25 +203,6 @@ class Account(db.Model):
|
||||
return
|
||||
self.l10n.append(AccountL10n(locale=current_locale, title=value))
|
||||
|
||||
@property
|
||||
def is_in_use(self) -> bool:
|
||||
"""Returns whether the account is in use.
|
||||
|
||||
:return: True if the account is in use, or False otherwise.
|
||||
"""
|
||||
if not hasattr(self, "__is_in_use"):
|
||||
setattr(self, "__is_in_use", len(self.entries) > 0)
|
||||
return getattr(self, "__is_in_use")
|
||||
|
||||
@is_in_use.setter
|
||||
def is_in_use(self, is_in_use: bool) -> None:
|
||||
"""Sets whether the account is in use.
|
||||
|
||||
:param is_in_use: True if the account is in use, or False otherwise.
|
||||
:return: None.
|
||||
"""
|
||||
setattr(self, "__is_in_use", is_in_use)
|
||||
|
||||
@classmethod
|
||||
def find_by_code(cls, code: str) -> t.Self | None:
|
||||
"""Finds an account by its code.
|
||||
@ -674,7 +655,7 @@ class JournalEntry(db.Model):
|
||||
onupdate="CASCADE"),
|
||||
nullable=False)
|
||||
"""The account ID."""
|
||||
account = db.relationship(Account, back_populates="entries", lazy=False)
|
||||
account = db.relationship(Account, back_populates="entries")
|
||||
"""The account."""
|
||||
summary = db.Column(db.String, nullable=True)
|
||||
"""The summary."""
|
||||
|
35
src/accounting/report/__init__.py
Normal file
35
src/accounting/report/__init__.py
Normal file
@ -0,0 +1,35 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/3
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The report management.
|
||||
|
||||
"""
|
||||
from flask import Flask, Blueprint
|
||||
|
||||
|
||||
def init_app(app: Flask, bp: Blueprint) -> None:
|
||||
"""Initialize the application.
|
||||
|
||||
:param app: The Flask application.
|
||||
:param bp: The blueprint of the accounting application.
|
||||
:return: None.
|
||||
"""
|
||||
from .converters import PeriodConverter, IncomeExpensesAccountConverter
|
||||
app.url_map.converters["period"] = PeriodConverter
|
||||
app.url_map.converters["ioAccount"] = IncomeExpensesAccountConverter
|
||||
|
||||
from .views import bp as report_bp
|
||||
bp.register_blueprint(report_bp, url_prefix="/reports")
|
79
src/accounting/report/converters.py
Normal file
79
src/accounting/report/converters.py
Normal file
@ -0,0 +1,79 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/3
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The path converters for the report management.
|
||||
|
||||
"""
|
||||
import re
|
||||
|
||||
from flask import abort
|
||||
from werkzeug.routing import BaseConverter
|
||||
|
||||
from accounting.models import Account
|
||||
from .income_expense_account import IncomeExpensesAccount
|
||||
from .period import Period
|
||||
|
||||
|
||||
class PeriodConverter(BaseConverter):
|
||||
"""The supplier converter to convert the period specification from and to
|
||||
the corresponding period in the routes."""
|
||||
|
||||
def to_python(self, value: str) -> Period:
|
||||
"""Converts a period specification to a period.
|
||||
|
||||
:param value: The period specification.
|
||||
:return: The corresponding period.
|
||||
"""
|
||||
try:
|
||||
return Period.get_instance(value)
|
||||
except ValueError:
|
||||
abort(404)
|
||||
|
||||
def to_url(self, value: Period) -> str:
|
||||
"""Converts a period to its specification.
|
||||
|
||||
:param value: The period.
|
||||
:return: Its specification.
|
||||
"""
|
||||
return value.spec
|
||||
|
||||
|
||||
class IncomeExpensesAccountConverter(BaseConverter):
|
||||
"""The supplier converter to convert the income and expenses pseudo account
|
||||
code from and to the corresponding pseudo account in the routes."""
|
||||
|
||||
def to_python(self, value: str) -> IncomeExpensesAccount:
|
||||
"""Converts an account code to an account.
|
||||
|
||||
:param value: The account code.
|
||||
:return: The corresponding account.
|
||||
"""
|
||||
if value == IncomeExpensesAccount.CURRENT_AL_CODE:
|
||||
return IncomeExpensesAccount.current_assets_and_liabilities()
|
||||
if not re.match("^[12][12]", value):
|
||||
abort(404)
|
||||
account: Account | None = Account.find_by_code(value)
|
||||
if account is None:
|
||||
abort(404)
|
||||
return IncomeExpensesAccount(account)
|
||||
|
||||
def to_url(self, value: IncomeExpensesAccount) -> str:
|
||||
"""Converts an account to account code.
|
||||
|
||||
:param value: The account.
|
||||
:return: Its code.
|
||||
"""
|
||||
return value.code
|
70
src/accounting/report/income_expense_account.py
Normal file
70
src/accounting/report/income_expense_account.py
Normal file
@ -0,0 +1,70 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The pseudo account for the income and expenses log.
|
||||
|
||||
"""
|
||||
import typing as t
|
||||
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Account
|
||||
|
||||
|
||||
class IncomeExpensesAccount:
|
||||
"""The pseudo account for the income and expenses log."""
|
||||
CURRENT_AL_CODE: str = "0000-000"
|
||||
"""The account code for the current assets and liabilities."""
|
||||
|
||||
def __init__(self, account: Account | None = None):
|
||||
"""Constructs the pseudo account for the income and expenses log.
|
||||
|
||||
:param account: The actual account.
|
||||
"""
|
||||
self.account: Account | None = None
|
||||
self.id: int | None = None
|
||||
"""The ID."""
|
||||
self.code: str | None = None
|
||||
"""The code."""
|
||||
self.title: str | None = None
|
||||
"""The title."""
|
||||
self.str: str = ""
|
||||
"""The string representation of the account."""
|
||||
if account is not None:
|
||||
self.account = account
|
||||
self.id = account.id
|
||||
self.code = account.code
|
||||
self.title = account.title
|
||||
self.str = str(account)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Returns the string representation of the account.
|
||||
|
||||
:return: The string representation of the account.
|
||||
"""
|
||||
return self.str
|
||||
|
||||
@classmethod
|
||||
def current_assets_and_liabilities(cls) -> t.Self:
|
||||
"""Returns the pseudo account for current assets and liabilities.
|
||||
|
||||
:return: The pseudo account for current assets and liabilities.
|
||||
"""
|
||||
account: cls = cls()
|
||||
account.id = 0
|
||||
account.code = cls.CURRENT_AL_CODE
|
||||
account.title = gettext("current assets and liabilities")
|
||||
account.str = account.title
|
||||
return account
|
555
src/accounting/report/period.py
Normal file
555
src/accounting/report/period.py
Normal file
@ -0,0 +1,555 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/4
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The date period.
|
||||
|
||||
This file is largely taken from the NanoParma ERP project, first written in
|
||||
2021/9/16 by imacat (imacat@nanoparma.com).
|
||||
|
||||
"""
|
||||
import calendar
|
||||
import datetime
|
||||
import re
|
||||
import typing as t
|
||||
|
||||
from accounting.locale import gettext
|
||||
|
||||
|
||||
class Period:
|
||||
"""A date period."""
|
||||
|
||||
def __init__(self, start: datetime.date | None, end: datetime.date | None):
|
||||
"""Constructs a new date period.
|
||||
|
||||
:param start: The start date, or None from the very beginning.
|
||||
:param end: The end date, or None till no end.
|
||||
"""
|
||||
self.start: datetime.date | None = start
|
||||
"""The start of the period."""
|
||||
self.end: datetime.date | None = end
|
||||
"""The end of the period."""
|
||||
self.is_default: bool = False
|
||||
"""Whether the is the default period."""
|
||||
self.is_this_month: bool = False
|
||||
"""Whether the period is this month."""
|
||||
self.is_last_month: bool = False
|
||||
"""Whether the period is last month."""
|
||||
self.is_since_last_month: bool = False
|
||||
"""Whether the period is since last month."""
|
||||
self.is_this_year: bool = False
|
||||
"""Whether the period is this year."""
|
||||
self.is_last_year: bool = False
|
||||
"""Whether the period is last year."""
|
||||
self.is_today: bool = False
|
||||
"""Whether the period is today."""
|
||||
self.is_yesterday: bool = False
|
||||
"""Whether the period is yesterday."""
|
||||
self.is_all: bool = start is None and end is None
|
||||
"""Whether the period is all time."""
|
||||
self.spec: str = ""
|
||||
"""The period specification."""
|
||||
self.desc: str = ""
|
||||
"""The text description."""
|
||||
self.is_type_month: bool = False
|
||||
"""Whether the period is for the month chooser."""
|
||||
self.is_a_year: bool = False
|
||||
"""Whether the period is a whole year."""
|
||||
self.is_a_day: bool = False
|
||||
"""Whether the period is a single day."""
|
||||
self._set_properties()
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
"""Sets the following properties.
|
||||
|
||||
* self.spec
|
||||
* self.desc
|
||||
* self.is_a_month
|
||||
* self.is_type_month
|
||||
* self.is_a_year
|
||||
* self.is_a_day
|
||||
|
||||
Override this method to set the properties in the subclasses.
|
||||
|
||||
:return: None.
|
||||
"""
|
||||
self.spec = self.__get_spec()
|
||||
self.desc = self.__get_desc()
|
||||
if self.start is None or self.end is None:
|
||||
return
|
||||
self.is_type_month \
|
||||
= self.start.day == 1 and self.end == _month_end(self.start)
|
||||
self.is_a_year = self.start == datetime.date(self.start.year, 1, 1) \
|
||||
and self.end == datetime.date(self.start.year, 12, 31)
|
||||
self.is_a_day = self.start == self.end
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls, spec: str | None = None) -> t.Self:
|
||||
"""Returns a period instance.
|
||||
|
||||
:param spec: The period specification, or omit for the default.
|
||||
:return: The period instance.
|
||||
:raise ValueError: When the period is invalid.
|
||||
"""
|
||||
if spec is None:
|
||||
return ThisMonth()
|
||||
named_periods: dict[str, t.Type[t.Callable[[], Period]]] = {
|
||||
"this-month": lambda: ThisMonth(),
|
||||
"last-month": lambda: LastMonth(),
|
||||
"since-last-month": lambda: SinceLastMonth(),
|
||||
"this-year": lambda: ThisYear(),
|
||||
"last-year": lambda: LastYear(),
|
||||
"today": lambda: Today(),
|
||||
"yesterday": lambda: Yesterday(),
|
||||
}
|
||||
if spec in named_periods:
|
||||
return named_periods[spec]()
|
||||
start: datetime.date
|
||||
end: datetime.date
|
||||
start, end = _parse_period_spec(spec)
|
||||
if start is not None and end is not None and start > end:
|
||||
raise ValueError
|
||||
return cls(start, end)
|
||||
|
||||
def __get_spec(self) -> str:
|
||||
"""Returns the period specification.
|
||||
|
||||
:return: The period specification.
|
||||
"""
|
||||
if self.start is None:
|
||||
if self.end is None:
|
||||
return "-"
|
||||
else:
|
||||
if self.end.day != _month_end(self.end).day:
|
||||
return "-%04d-%02d-%02d" % (
|
||||
self.end.year, self.end.month, self.end.day)
|
||||
if self.end.month != 12:
|
||||
return "-%04d-%02d" % (self.end.year, self.end.month)
|
||||
return "-%04d" % self.end.year
|
||||
else:
|
||||
if self.end is None:
|
||||
if self.start.day != 1:
|
||||
return "%04d-%02d-%02d-" % (
|
||||
self.start.year, self.start.month, self.start.day)
|
||||
if self.start.month != 1:
|
||||
return "%04d-%02d-" % (self.start.year, self.start.month)
|
||||
return "%04d-" % self.start.year
|
||||
else:
|
||||
try:
|
||||
return self.__get_year_spec()
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
return self.__get_month_spec()
|
||||
except ValueError:
|
||||
pass
|
||||
return self.__get_day_spec()
|
||||
|
||||
def __get_year_spec(self) -> str:
|
||||
"""Returns the period specification as a year range.
|
||||
|
||||
:return: The period specification as a year range.
|
||||
:raise ValueError: The period is not a year range.
|
||||
"""
|
||||
if self.start.month != 1 or self.start.day != 1 \
|
||||
or self.end.month != 12 or self.end.day != 31:
|
||||
raise ValueError
|
||||
if self.start.year == self.end.year:
|
||||
return "%04d" % self.start.year
|
||||
return "%04d-%04d" % (self.start.year, self.end.year)
|
||||
|
||||
def __get_month_spec(self) -> str:
|
||||
"""Returns the period specification as a month range.
|
||||
|
||||
:return: The period specification as a month range.
|
||||
:raise ValueError: The period is not a month range.
|
||||
"""
|
||||
if self.start.day != 1 or self.end != _month_end(self.end):
|
||||
raise ValueError
|
||||
if self.start.year == self.end.year \
|
||||
and self.start.month == self.end.month:
|
||||
return "%04d-%02d" % (self.start.year, self.start.month)
|
||||
return "%04d-%02d-%04d-%02d" % (
|
||||
self.start.year, self.start.month,
|
||||
self.end.year, self.end.month)
|
||||
|
||||
def __get_day_spec(self) -> str:
|
||||
"""Returns the period specification as a day range.
|
||||
|
||||
:return: The period specification as a day range.
|
||||
:raise ValueError: The period is a month or year range.
|
||||
"""
|
||||
if self.start == self.end:
|
||||
return "%04d-%02d-%02d" % (
|
||||
self.start.year, self.start.month, self.start.day)
|
||||
return "%04d-%02d-%02d-%04d-%02d-%02d" % (
|
||||
self.start.year, self.start.month, self.start.day,
|
||||
self.end.year, self.end.month, self.end.day)
|
||||
|
||||
def __get_desc(self) -> str:
|
||||
"""Returns the period description.
|
||||
|
||||
:return: The period description.
|
||||
"""
|
||||
cls: t.Type[t.Self] = self.__class__
|
||||
if self.start is None:
|
||||
if self.end is None:
|
||||
return gettext("for all time")
|
||||
else:
|
||||
if self.end != _month_end(self.end):
|
||||
return gettext("until %(end)s",
|
||||
end=cls.__format_date(self.end))
|
||||
if self.end.month != 12:
|
||||
return gettext("until %(end)s",
|
||||
end=cls.__format_month(self.end))
|
||||
return gettext("until %(end)s", end=str(self.end.year))
|
||||
else:
|
||||
if self.end is None:
|
||||
if self.start.day != 1:
|
||||
return gettext("since %(start)s",
|
||||
start=cls.__format_date(self.start))
|
||||
if self.start.month != 1:
|
||||
return gettext("since %(start)s",
|
||||
start=cls.__format_month(self.start))
|
||||
return gettext("since %(start)s", start=str(self.start.year))
|
||||
else:
|
||||
try:
|
||||
return self.__get_year_desc()
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
return self.__get_month_desc()
|
||||
except ValueError:
|
||||
pass
|
||||
return self.__get_day_desc()
|
||||
|
||||
@staticmethod
|
||||
def __format_date(date: datetime.date) -> str:
|
||||
"""Formats a date.
|
||||
|
||||
:param date: The date.
|
||||
:return: The formatted date.
|
||||
"""
|
||||
return F"{date.year}/{date.month}/{date.day}"
|
||||
|
||||
@staticmethod
|
||||
def __format_month(month: datetime.date) -> str:
|
||||
"""Formats a month.
|
||||
|
||||
:param month: The month.
|
||||
:return: The formatted month.
|
||||
"""
|
||||
return F"{month.year}/{month.month}"
|
||||
|
||||
def __get_year_desc(self) -> str:
|
||||
"""Returns the description as a year range.
|
||||
|
||||
:return: The description as a year range.
|
||||
:raise ValueError: The period is not a year range.
|
||||
"""
|
||||
if self.start.month != 1 or self.start.day != 1 \
|
||||
or self.end.month != 12 or self.end.day != 31:
|
||||
raise ValueError
|
||||
start: str = str(self.start.year)
|
||||
if self.start.year == self.end.year:
|
||||
return gettext("in %(period)s", period=start)
|
||||
end: str = str(self.end.year)
|
||||
return gettext("in %(start)s-%(end)s", start=start, end=end)
|
||||
|
||||
def __get_month_desc(self) -> str:
|
||||
"""Returns the description as a month range.
|
||||
|
||||
:return: The description as a month range.
|
||||
:raise ValueError: The period is not a month range.
|
||||
"""
|
||||
if self.start.day != 1 or self.end != _month_end(self.end):
|
||||
raise ValueError
|
||||
start: str = F"{self.start.year}/{self.start.month}"
|
||||
if self.start.year == self.end.year \
|
||||
and self.start.month == self.end.month:
|
||||
return gettext("in %(period)s", period=start)
|
||||
if self.start.year == self.end.year:
|
||||
end_month: str = str(self.end.month)
|
||||
return gettext("in %(start)s-%(end)s", start=start, end=end_month)
|
||||
end: str = F"{self.end.year}/{self.end.month}"
|
||||
return gettext("in %(start)s-%(end)s", start=start, end=end)
|
||||
|
||||
def __get_day_desc(self) -> str:
|
||||
"""Returns the description as a day range.
|
||||
|
||||
:return: The description as a day range.
|
||||
:raise ValueError: The period is a month or year range.
|
||||
"""
|
||||
start: str = F"{self.start.year}/{self.start.month}/{self.start.day}"
|
||||
if self.start == self.end:
|
||||
return gettext("in %(period)s", period=start)
|
||||
if self.start.year == self.end.year \
|
||||
and self.start.month == self.end.month:
|
||||
end_day: str = str(self.end.day)
|
||||
return gettext("in %(start)s-%(end)s", start=start, end=end_day)
|
||||
if self.start.year == self.end.year:
|
||||
end_month_day: str = F"{self.end.month}/{self.end.day}"
|
||||
return gettext("in %(start)s-%(end)s",
|
||||
start=start, end=end_month_day)
|
||||
end: str = F"{self.end.year}/{self.end.month}/{self.end.day}"
|
||||
return gettext("in %(start)s-%(end)s", start=start, end=end)
|
||||
|
||||
def is_year(self, year: int) -> bool:
|
||||
"""Returns whether the period is the specific year period.
|
||||
|
||||
:param year: The year.
|
||||
:return: True if the period is the year period, or False otherwise.
|
||||
"""
|
||||
if not self.is_a_year:
|
||||
return False
|
||||
return self.start.year == year
|
||||
|
||||
@property
|
||||
def is_type_arbitrary(self) -> bool:
|
||||
"""Returns whether this period is an arbitrary period.
|
||||
|
||||
:return: True if this is an arbitrary period, or False otherwise.
|
||||
"""
|
||||
return not self.is_type_month and not self.is_a_year \
|
||||
and not self.is_a_day
|
||||
|
||||
@property
|
||||
def before(self) -> t.Self | None:
|
||||
"""Returns the period before this period.
|
||||
|
||||
:return: The period before this period.
|
||||
"""
|
||||
if self.start is None:
|
||||
return None
|
||||
return Period(None, self.start - datetime.timedelta(days=1))
|
||||
|
||||
|
||||
class ThisMonth(Period):
|
||||
"""The period of this month."""
|
||||
def __init__(self):
|
||||
today: datetime.date = datetime.date.today()
|
||||
this_month_start: datetime.date \
|
||||
= datetime.date(today.year, today.month, 1)
|
||||
super().__init__(this_month_start, _month_end(today))
|
||||
self.is_default = True
|
||||
self.is_this_month = True
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
self.spec = "this-month"
|
||||
self.desc = gettext("This month")
|
||||
self.is_a_month = True
|
||||
self.is_type_month = True
|
||||
|
||||
|
||||
class LastMonth(Period):
|
||||
"""The period of this month."""
|
||||
def __init__(self):
|
||||
today: datetime.date = datetime.date.today()
|
||||
year: int = today.year
|
||||
month: int = today.month - 1
|
||||
if month < 1:
|
||||
year = year - 1
|
||||
month = 12
|
||||
start: datetime.date = datetime.date(year, month, 1)
|
||||
super().__init__(start, _month_end(start))
|
||||
self.is_last_month = True
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
self.spec = "last-month"
|
||||
self.desc = gettext("Last month")
|
||||
self.is_a_month = True
|
||||
self.is_type_month = True
|
||||
|
||||
|
||||
class SinceLastMonth(Period):
|
||||
"""The period of this month."""
|
||||
def __init__(self):
|
||||
today: datetime.date = datetime.date.today()
|
||||
year: int = today.year
|
||||
month: int = today.month - 1
|
||||
if month < 1:
|
||||
year = year - 1
|
||||
month = 12
|
||||
start: datetime.date = datetime.date(year, month, 1)
|
||||
super().__init__(start, None)
|
||||
self.is_since_last_month = True
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
self.spec = "since-last-month"
|
||||
self.desc = gettext("Since last month")
|
||||
self.is_type_month = True
|
||||
|
||||
|
||||
class ThisYear(Period):
|
||||
"""The period of this year."""
|
||||
def __init__(self):
|
||||
year: int = datetime.date.today().year
|
||||
start: datetime.date = datetime.date(year, 1, 1)
|
||||
end: datetime.date = datetime.date(year, 12, 31)
|
||||
super().__init__(start, end)
|
||||
self.is_this_year = True
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
self.spec = "this-year"
|
||||
self.desc = gettext("This year")
|
||||
self.is_a_year = True
|
||||
|
||||
|
||||
class LastYear(Period):
|
||||
"""The period of last year."""
|
||||
def __init__(self):
|
||||
year: int = datetime.date.today().year
|
||||
start: datetime.date = datetime.date(year - 1, 1, 1)
|
||||
end: datetime.date = datetime.date(year - 1, 12, 31)
|
||||
super().__init__(start, end)
|
||||
self.is_last_year = True
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
self.spec = "last-year"
|
||||
self.desc = gettext("Last year")
|
||||
self.is_a_year = True
|
||||
|
||||
|
||||
class Today(Period):
|
||||
"""The period of today."""
|
||||
def __init__(self):
|
||||
today: datetime.date = datetime.date.today()
|
||||
super().__init__(today, today)
|
||||
self.is_this_year = True
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
self.spec = "today"
|
||||
self.desc = gettext("Today")
|
||||
self.is_a_day = True
|
||||
self.is_today = True
|
||||
|
||||
|
||||
class Yesterday(Period):
|
||||
"""The period of yesterday."""
|
||||
def __init__(self):
|
||||
yesterday: datetime.date \
|
||||
= datetime.date.today() - datetime.timedelta(days=1)
|
||||
super().__init__(yesterday, yesterday)
|
||||
self.is_this_year = True
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
self.spec = "yesterday"
|
||||
self.desc = gettext("Yesterday")
|
||||
self.is_a_day = True
|
||||
self.is_yesterday = True
|
||||
|
||||
|
||||
class TemplatePeriod(Period):
|
||||
"""The period template."""
|
||||
def __init__(self):
|
||||
super().__init__(None, None)
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
self.spec = "PERIOD"
|
||||
|
||||
|
||||
class YearPeriod(Period):
|
||||
"""A year period."""
|
||||
def __init__(self, year: int):
|
||||
"""Constructs a year period.
|
||||
|
||||
:param year: The year.
|
||||
"""
|
||||
start: datetime.date = datetime.date(year, 1, 1)
|
||||
end: datetime.date = datetime.date(year, 12, 31)
|
||||
super().__init__(start, end)
|
||||
self.spec = str(year)
|
||||
self.is_a_year = True
|
||||
|
||||
def _set_properties(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def _parse_period_spec(text: str) \
|
||||
-> tuple[datetime.date | None, datetime.date | None]:
|
||||
"""Parses the period specification.
|
||||
|
||||
:param text: The period specification.
|
||||
:return: The start and end day of the period. The start and end day
|
||||
may be None.
|
||||
:raise ValueError: When the date is invalid.
|
||||
"""
|
||||
if text == "this-month":
|
||||
today: datetime.date = datetime.date.today()
|
||||
return datetime.date(today.year, today.month, 1), _month_end(today)
|
||||
if text == "-":
|
||||
return None, None
|
||||
m = re.match(r"^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$", text)
|
||||
if m is not None:
|
||||
return __get_start(m[1], m[2], m[3]), \
|
||||
__get_end(m[1], m[2], m[3])
|
||||
m = re.match(r"^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?-$", text)
|
||||
if m is not None:
|
||||
return __get_start(m[1], m[2], m[3]), None
|
||||
m = re.match(r"-(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$", text)
|
||||
if m is not None:
|
||||
return None, __get_end(m[1], m[2], m[3])
|
||||
m = re.match(r"^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?-(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$", text)
|
||||
if m is not None:
|
||||
return __get_start(m[1], m[2], m[3]), \
|
||||
__get_end(m[4], m[5], m[6])
|
||||
raise ValueError
|
||||
|
||||
|
||||
def __get_start(year: str, month: str | None, day: str | None)\
|
||||
-> datetime.date:
|
||||
"""Returns the start of the period from the date representation.
|
||||
|
||||
:param year: The year.
|
||||
:param month: The month, if any.
|
||||
:param day: The day, if any.
|
||||
:return: The start of the period.
|
||||
:raise ValueError: When the date is invalid.
|
||||
"""
|
||||
if day is not None:
|
||||
return datetime.date(int(year), int(month), int(day))
|
||||
if month is not None:
|
||||
return datetime.date(int(year), int(month), 1)
|
||||
return datetime.date(int(year), 1, 1)
|
||||
|
||||
|
||||
def __get_end(year: str, month: str | None, day: str | None)\
|
||||
-> datetime.date:
|
||||
"""Returns the end of the period from the date representation.
|
||||
|
||||
:param year: The year.
|
||||
:param month: The month, if any.
|
||||
:param day: The day, if any.
|
||||
:return: The end of the period.
|
||||
:raise ValueError: When the date is invalid.
|
||||
"""
|
||||
if day is not None:
|
||||
return datetime.date(int(year), int(month), int(day))
|
||||
if month is not None:
|
||||
year_n: int = int(year)
|
||||
month_n: int = int(month)
|
||||
day_n: int = calendar.monthrange(year_n, month_n)[1]
|
||||
return datetime.date(year_n, month_n, day_n)
|
||||
return datetime.date(int(year), 12, 31)
|
||||
|
||||
|
||||
def _month_end(date: datetime.date) -> datetime.date:
|
||||
"""Returns the end day of month for a date.
|
||||
|
||||
:param date: The date.
|
||||
:return: The end day of the month of that day.
|
||||
"""
|
||||
day: int = calendar.monthrange(date.year, date.month)[1]
|
||||
return datetime.date(date.year, date.month, day)
|
26
src/accounting/report/reports/__init__.py
Normal file
26
src/accounting/report/reports/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The reports.
|
||||
|
||||
"""
|
||||
from .balance_sheet import BalanceSheet
|
||||
from .income_expenses import IncomeExpenses
|
||||
from .income_statement import IncomeStatement
|
||||
from .journal import Journal
|
||||
from .ledger import Ledger
|
||||
from .search import Search
|
||||
from .trial_balance import TrialBalance
|
497
src/accounting/report/reports/balance_sheet.py
Normal file
497
src/accounting/report/reports/balance_sheet.py
Normal file
@ -0,0 +1,497 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The balance sheet.
|
||||
|
||||
"""
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import url_for, render_template, Response
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency, BaseAccount, Account, Transaction, \
|
||||
JournalEntry
|
||||
from accounting.report.period import Period
|
||||
from .utils.base_report import BaseReport
|
||||
from .utils.csv_export import BaseCSVRow, csv_download
|
||||
from .utils.option_link import OptionLink
|
||||
from .utils.page_params import PageParams
|
||||
from .utils.period_choosers import BalanceSheetPeriodChooser
|
||||
from .utils.report_chooser import ReportChooser
|
||||
from .utils.report_type import ReportType
|
||||
|
||||
|
||||
class BalanceSheetAccount:
|
||||
"""An account in the balance sheet."""
|
||||
|
||||
def __init__(self, account: Account, amount: Decimal, url: str):
|
||||
"""Constructs an account in the balance sheet.
|
||||
|
||||
:param account: The account.
|
||||
:param amount: The amount.
|
||||
:param url: The URL to the ledger of the account.
|
||||
"""
|
||||
self.account: Account = account
|
||||
"""The account."""
|
||||
self.amount: Decimal = amount
|
||||
"""The amount of the account."""
|
||||
self.url: str = url
|
||||
"""The URL to the ledger of the account."""
|
||||
|
||||
|
||||
class BalanceSheetSubsection:
|
||||
"""A subsection in the balance sheet."""
|
||||
|
||||
def __init__(self, title: BaseAccount):
|
||||
"""Constructs a subsection in the balance sheet.
|
||||
|
||||
:param title: The title account.
|
||||
"""
|
||||
self.title: BaseAccount = title
|
||||
"""The title account."""
|
||||
self.accounts: list[BalanceSheetAccount] = []
|
||||
"""The accounts in the subsection."""
|
||||
|
||||
@property
|
||||
def total(self) -> Decimal:
|
||||
"""Returns the total of the subsection.
|
||||
|
||||
:return: The total of the subsection.
|
||||
"""
|
||||
return sum([x.amount for x in self.accounts])
|
||||
|
||||
|
||||
class BalanceSheetSection:
|
||||
"""A section in the balance sheet."""
|
||||
|
||||
def __init__(self, title: BaseAccount):
|
||||
"""Constructs a section in the balance sheet.
|
||||
|
||||
:param title: The title account.
|
||||
"""
|
||||
self.title: BaseAccount = title
|
||||
"""The title account."""
|
||||
self.subsections: list[BalanceSheetSubsection] = []
|
||||
"""The subsections in the section."""
|
||||
|
||||
@property
|
||||
def total(self) -> Decimal:
|
||||
"""Returns the total of the section.
|
||||
|
||||
:return: The total of the section.
|
||||
"""
|
||||
return sum([x.total for x in self.subsections])
|
||||
|
||||
|
||||
class AccountCollector:
|
||||
"""The balance sheet account collector."""
|
||||
|
||||
def __init__(self, currency: Currency, period: Period):
|
||||
"""Constructs the balance sheet account collector.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
"""
|
||||
self.__currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.__period: Period = period
|
||||
"""The period."""
|
||||
self.accounts: list[BalanceSheetAccount] = self.__query_balances()
|
||||
"""The balance sheet accounts."""
|
||||
|
||||
def __query_balances(self) -> list[BalanceSheetAccount]:
|
||||
"""Queries and returns the balances.
|
||||
|
||||
:return: The balances.
|
||||
"""
|
||||
sub_conditions: list[sa.BinaryExpression] \
|
||||
= [Account.base_code.startswith(x) for x in {"1", "2", "3"}]
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.currency_code == self.__currency.code,
|
||||
sa.or_(*sub_conditions)]
|
||||
if self.__period.end is not None:
|
||||
conditions.append(Transaction.date <= self.__period.end)
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, JournalEntry.amount),
|
||||
else_=-JournalEntry.amount)).label("balance")
|
||||
select_balance: sa.Select \
|
||||
= sa.select(Account.id, Account.base_code, Account.no,
|
||||
balance_func)\
|
||||
.join(Transaction).join(Account)\
|
||||
.filter(*conditions)\
|
||||
.group_by(Account.id, Account.base_code, Account.no)\
|
||||
.order_by(Account.base_code, Account.no)
|
||||
account_balances: list[sa.Row] \
|
||||
= db.session.execute(select_balance).all()
|
||||
self.__all_accounts: list[Account] = Account.query\
|
||||
.filter(sa.or_(Account.id.in_({x.id for x in account_balances}),
|
||||
Account.base_code == "3351",
|
||||
Account.base_code == "3353")).all()
|
||||
account_by_id: dict[int, Account] \
|
||||
= {x.id: x for x in self.__all_accounts}
|
||||
|
||||
def get_url(account: Account) -> str:
|
||||
"""Returns the ledger URL of an account.
|
||||
|
||||
:param account: The account.
|
||||
:return: The ledger URL of the account.
|
||||
"""
|
||||
if self.__period.is_default:
|
||||
return url_for("accounting.report.ledger-default",
|
||||
currency=self.__currency, account=account)
|
||||
return url_for("accounting.report.ledger",
|
||||
currency=self.__currency, account=account,
|
||||
period=self.__period)
|
||||
|
||||
self.accounts: list[BalanceSheetAccount] \
|
||||
= [BalanceSheetAccount(account=account_by_id[x.id],
|
||||
amount=x.balance,
|
||||
url=get_url(account_by_id[x.id]))
|
||||
for x in account_balances]
|
||||
self.__add_accumulated()
|
||||
self.__add_current_period()
|
||||
self.accounts.sort(key=lambda x: (x.account.base_code, x.account.no))
|
||||
for balance in self.accounts:
|
||||
if not balance.account.base_code.startswith("1"):
|
||||
balance.amount = -balance.amount
|
||||
return self.accounts
|
||||
|
||||
def __add_accumulated(self) -> None:
|
||||
"""Adds the accumulated profit or loss to the balances.
|
||||
|
||||
:return: None.
|
||||
"""
|
||||
code: str = "3351-001"
|
||||
amount: Decimal | None = self.__query_accumulated()
|
||||
url: str = url_for("accounting.report.income-statement",
|
||||
currency=self.__currency,
|
||||
period=self.__period.before)
|
||||
self.__add_owner_s_equity(code, amount, url)
|
||||
|
||||
def __query_accumulated(self) -> Decimal | None:
|
||||
"""Queries and returns the accumulated profit or loss.
|
||||
|
||||
:return: The accumulated profit or loss.
|
||||
"""
|
||||
if self.__period.start is None:
|
||||
return None
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.currency_code == self.__currency.code,
|
||||
Transaction.date < self.__period.start]
|
||||
conditions.extend([sa.not_(Account.base_code.startswith(x))
|
||||
for x in {"1", "2"}])
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, JournalEntry.amount),
|
||||
else_=-JournalEntry.amount)).label("balance")
|
||||
select_balance: sa.Select = sa.select(balance_func)\
|
||||
.join(Transaction).join(Account).filter(*conditions)
|
||||
return db.session.scalar(select_balance)
|
||||
|
||||
def __add_current_period(self) -> None:
|
||||
"""Adds the accumulated profit or loss to the balances.
|
||||
|
||||
:return: None.
|
||||
"""
|
||||
code: str = "3353-001"
|
||||
amount: Decimal | None = self.__query_currency_period()
|
||||
url: str = url_for("accounting.report.income-statement",
|
||||
currency=self.__currency, period=self.__period)
|
||||
self.__add_owner_s_equity(code, amount, url)
|
||||
|
||||
def __query_currency_period(self) -> Decimal | None:
|
||||
"""Queries and returns the net income or loss for current period.
|
||||
|
||||
:return: The net income or loss for current period.
|
||||
"""
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.currency_code == self.__currency.code]
|
||||
if self.__period.start is not None:
|
||||
conditions.append(Transaction.date >= self.__period.start)
|
||||
if self.__period.end is not None:
|
||||
conditions.append(Transaction.date <= self.__period.end)
|
||||
conditions.extend([sa.not_(Account.base_code.startswith(x))
|
||||
for x in {"1", "2"}])
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, JournalEntry.amount),
|
||||
else_=-JournalEntry.amount)).label("balance")
|
||||
select_balance: sa.Select = sa.select(balance_func)\
|
||||
.join(Transaction).join(Account).filter(*conditions)
|
||||
return db.session.scalar(select_balance)
|
||||
|
||||
def __add_owner_s_equity(self, code: str, amount: Decimal | None,
|
||||
url: str) -> None:
|
||||
"""Adds an owner's equity balance.
|
||||
|
||||
:param code: The code of the account to add.
|
||||
:param amount: The amount.
|
||||
:return: None.
|
||||
"""
|
||||
# There is an existing balance.
|
||||
account_balance_by_code: dict[str, BalanceSheetAccount] \
|
||||
= {x.account.code: x for x in self.accounts}
|
||||
if code in account_balance_by_code:
|
||||
balance: BalanceSheetAccount = account_balance_by_code[code]
|
||||
balance.url = url
|
||||
if amount is not None:
|
||||
balance.amount = balance.amount + amount
|
||||
return
|
||||
# Add a new balance
|
||||
if amount is None:
|
||||
return
|
||||
account_by_code: dict[str, Account] \
|
||||
= {x.code: x for x in self.__all_accounts}
|
||||
self.accounts.append(BalanceSheetAccount(account=account_by_code[code],
|
||||
amount=amount,
|
||||
url=url))
|
||||
|
||||
|
||||
class CSVHalfRow:
|
||||
"""A half row in the CSV balance sheet."""
|
||||
|
||||
def __init__(self, title: str | None, amount: Decimal | None):
|
||||
"""The constructs a half row in the CSV balance sheet.
|
||||
|
||||
:param title: The title.
|
||||
:param amount: The amount.
|
||||
"""
|
||||
self.title: str | None = title
|
||||
"""The title."""
|
||||
self.amount: Decimal | None = amount
|
||||
"""The amount."""
|
||||
|
||||
|
||||
class CSVRow(BaseCSVRow):
|
||||
"""A row in the CSV balance sheet."""
|
||||
|
||||
def __init__(self):
|
||||
"""Constructs a row in the CSV balance sheet."""
|
||||
self.asset_title: str | None = None
|
||||
"""The title of the asset."""
|
||||
self.asset_amount: Decimal | None = None
|
||||
"""The amount of the asset."""
|
||||
self.liability_title: str | None = None
|
||||
"""The title of the liability."""
|
||||
self.liability_amount: Decimal | None = None
|
||||
"""The amount of the liability."""
|
||||
|
||||
@property
|
||||
def values(self) -> list[str | Decimal | None]:
|
||||
"""Returns the values of the row.
|
||||
|
||||
:return: The values of the row.
|
||||
"""
|
||||
return [self.asset_title, self.asset_amount,
|
||||
self.liability_title, self.liability_amount]
|
||||
|
||||
|
||||
class BalanceSheetPageParams(PageParams):
|
||||
"""The HTML parameters of the balance sheet."""
|
||||
|
||||
def __init__(self, currency: Currency,
|
||||
period: Period,
|
||||
has_data: bool,
|
||||
assets: BalanceSheetSection,
|
||||
liabilities: BalanceSheetSection,
|
||||
owner_s_equity: BalanceSheetSection):
|
||||
"""Constructs the HTML parameters of the balance sheet.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:param has_data: True if there is any data, or False otherwise.
|
||||
:param assets: The assets.
|
||||
:param liabilities: The liabilities.
|
||||
:param owner_s_equity: The owner's equity.
|
||||
"""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.period: Period = period
|
||||
"""The period."""
|
||||
self.__has_data: bool = has_data
|
||||
"""True if there is any data, or False otherwise."""
|
||||
self.assets: BalanceSheetSection = assets
|
||||
"""The assets."""
|
||||
self.liabilities: BalanceSheetSection = liabilities
|
||||
"""The liabilities."""
|
||||
self.owner_s_equity: BalanceSheetSection = owner_s_equity
|
||||
"""The owner's equity."""
|
||||
self.period_chooser: BalanceSheetPeriodChooser \
|
||||
= BalanceSheetPeriodChooser(currency)
|
||||
"""The period chooser."""
|
||||
|
||||
@property
|
||||
def has_data(self) -> bool:
|
||||
"""Returns whether there is any data on the page.
|
||||
|
||||
:return: True if there is any data, or False otherwise.
|
||||
"""
|
||||
return self.__has_data
|
||||
|
||||
@property
|
||||
def report_chooser(self) -> ReportChooser:
|
||||
"""Returns the report chooser.
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
return ReportChooser(ReportType.BALANCE_SHEET,
|
||||
currency=self.currency,
|
||||
period=self.period)
|
||||
|
||||
@property
|
||||
def currency_options(self) -> list[OptionLink]:
|
||||
"""Returns the currency options.
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
def get_url(currency: Currency):
|
||||
if self.period.is_default:
|
||||
return url_for("accounting.report.balance-sheet-default",
|
||||
currency=currency)
|
||||
return url_for("accounting.report.balance-sheet",
|
||||
currency=currency, period=self.period)
|
||||
|
||||
in_use: set[str] = set(db.session.scalars(
|
||||
sa.select(JournalEntry.currency_code)
|
||||
.group_by(JournalEntry.currency_code)).all())
|
||||
return [OptionLink(str(x), get_url(x), x.code == self.currency.code)
|
||||
for x in Currency.query.filter(Currency.code.in_(in_use))
|
||||
.order_by(Currency.code).all()]
|
||||
|
||||
|
||||
class BalanceSheet(BaseReport):
|
||||
"""The balance sheet."""
|
||||
|
||||
def __init__(self, currency: Currency, period: Period):
|
||||
"""Constructs a balance sheet.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
"""
|
||||
self.__currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.__period: Period = period
|
||||
"""The period."""
|
||||
self.__has_data: bool
|
||||
"""True if there is any data, or False otherwise."""
|
||||
self.__assets: BalanceSheetSection
|
||||
"""The assets."""
|
||||
self.__liabilities: BalanceSheetSection
|
||||
"""The liabilities."""
|
||||
self.__owner_s_equity: BalanceSheetSection
|
||||
"""The owner's equity."""
|
||||
self.__set_data()
|
||||
|
||||
def __set_data(self) -> None:
|
||||
"""Queries and sets assets, the liabilities, and the owner's equity
|
||||
sections in the balance sheet.
|
||||
|
||||
:return: None.
|
||||
"""
|
||||
balances: list[BalanceSheetAccount] = AccountCollector(
|
||||
self.__currency, self.__period).accounts
|
||||
|
||||
titles: list[BaseAccount] = BaseAccount.query\
|
||||
.filter(BaseAccount.code.in_({"1", "2", "3"})).all()
|
||||
subtitles: list[BaseAccount] = BaseAccount.query\
|
||||
.filter(BaseAccount.code.in_({x.account.base_code[:2]
|
||||
for x in balances})).all()
|
||||
|
||||
sections: dict[str, BalanceSheetSection] \
|
||||
= {x.code: BalanceSheetSection(x) for x in titles}
|
||||
subsections: dict[str, BalanceSheetSubsection] \
|
||||
= {x.code: BalanceSheetSubsection(x) for x in subtitles}
|
||||
for subsection in subsections.values():
|
||||
sections[subsection.title.code[0]].subsections.append(subsection)
|
||||
for balance in balances:
|
||||
subsections[balance.account.base_code[:2]].accounts.append(balance)
|
||||
|
||||
self.__has_data = len(balances) > 0
|
||||
self.__assets = sections["1"]
|
||||
self.__liabilities = sections["2"]
|
||||
self.__owner_s_equity = sections["3"]
|
||||
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
filename: str = "balance-sheet-{currency}-{period}.csv"\
|
||||
.format(currency=self.__currency.code, period=self.__period.spec)
|
||||
return csv_download(filename, self.__get_csv_rows())
|
||||
|
||||
def __get_csv_rows(self) -> list[CSVRow]:
|
||||
"""Composes and returns the CSV rows.
|
||||
|
||||
:return: The CSV rows.
|
||||
"""
|
||||
asset_rows: list[CSVHalfRow] = self.__section_csv_rows(self.__assets)
|
||||
liability_rows: list[CSVHalfRow] = []
|
||||
liability_rows.extend(self.__section_csv_rows(self.__liabilities))
|
||||
liability_rows.append(CSVHalfRow(gettext("Total"),
|
||||
self.__liabilities.total))
|
||||
liability_rows.append(CSVHalfRow(None, None))
|
||||
liability_rows.extend(self.__section_csv_rows(self.__owner_s_equity))
|
||||
liability_rows.append(CSVHalfRow(gettext("Total"),
|
||||
self.__owner_s_equity.total))
|
||||
rows: list[CSVRow] = [CSVRow() for _ in
|
||||
range(max(len(asset_rows), len(liability_rows)))]
|
||||
for i in range(len(rows)):
|
||||
if i < len(asset_rows):
|
||||
rows[i].asset_title = asset_rows[i].title
|
||||
rows[i].asset_amount = asset_rows[i].amount
|
||||
if i < len(liability_rows) and liability_rows[i].title is not None:
|
||||
rows[i].liability_title = liability_rows[i].title
|
||||
rows[i].liability_amount = liability_rows[i].amount
|
||||
total: CSVRow = CSVRow()
|
||||
total.asset_title = gettext("Total")
|
||||
total.asset_amount = self.__assets.total
|
||||
total.liability_title = gettext("Total")
|
||||
total.liability_amount \
|
||||
= self.__liabilities.total + self.__owner_s_equity.total
|
||||
rows.append(total)
|
||||
return rows
|
||||
|
||||
@staticmethod
|
||||
def __section_csv_rows(section: BalanceSheetSection) -> list[CSVHalfRow]:
|
||||
"""Gathers the CSV rows for a section.
|
||||
|
||||
:param section: The section.
|
||||
:return: The CSV rows for the section.
|
||||
"""
|
||||
rows: list[CSVHalfRow] \
|
||||
= [CSVHalfRow(section.title.title.title(), None)]
|
||||
for subsection in section.subsections:
|
||||
rows.append(CSVHalfRow(f" {subsection.title.title.title()}", None))
|
||||
for account in subsection.accounts:
|
||||
rows.append(CSVHalfRow(f" {str(account.account).title()}",
|
||||
account.amount))
|
||||
return rows
|
||||
|
||||
def html(self) -> str:
|
||||
"""Composes and returns the report as HTML.
|
||||
|
||||
:return: The report as HTML.
|
||||
"""
|
||||
params: BalanceSheetPageParams = BalanceSheetPageParams(
|
||||
currency=self.__currency,
|
||||
period=self.__period,
|
||||
has_data=self.__has_data,
|
||||
assets=self.__assets,
|
||||
liabilities=self.__liabilities,
|
||||
owner_s_equity=self.__owner_s_equity)
|
||||
return render_template("accounting/report/balance-sheet.html",
|
||||
report=params)
|
487
src/accounting/report/reports/income_expenses.py
Normal file
487
src/accounting/report/reports/income_expenses.py
Normal file
@ -0,0 +1,487 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The income and expenses log.
|
||||
|
||||
"""
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import url_for, render_template, Response
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency, Account, Transaction, JournalEntry
|
||||
from accounting.report.income_expense_account import IncomeExpensesAccount
|
||||
from accounting.report.period import Period
|
||||
from accounting.utils.pagination import Pagination
|
||||
from .utils.base_report import BaseReport
|
||||
from .utils.csv_export import BaseCSVRow, csv_download
|
||||
from .utils.option_link import OptionLink
|
||||
from .utils.page_params import PageParams
|
||||
from .utils.period_choosers import IncomeExpensesPeriodChooser
|
||||
from .utils.report_chooser import ReportChooser
|
||||
from .utils.report_type import ReportType
|
||||
|
||||
|
||||
class Entry:
|
||||
"""An entry in the income and expenses log."""
|
||||
|
||||
def __init__(self, entry: JournalEntry | None = None):
|
||||
"""Constructs the entry in the income and expenses log.
|
||||
|
||||
:param entry: The journal entry.
|
||||
"""
|
||||
self.entry: JournalEntry | None = None
|
||||
"""The journal entry."""
|
||||
self.transaction: Transaction | None = None
|
||||
"""The transaction."""
|
||||
self.is_brought_forward: bool = False
|
||||
"""Whether this is the brought-forward entry."""
|
||||
self.is_total: bool = False
|
||||
"""Whether this is the total entry."""
|
||||
self.date: date | None = None
|
||||
"""The date."""
|
||||
self.account: Account | None = None
|
||||
"""The account."""
|
||||
self.summary: str | None = None
|
||||
"""The summary."""
|
||||
self.income: Decimal | None = None
|
||||
"""The income amount."""
|
||||
self.expense: Decimal | None = None
|
||||
"""The expense amount."""
|
||||
self.balance: Decimal | None = None
|
||||
"""The balance."""
|
||||
self.note: str | None = None
|
||||
"""The note."""
|
||||
if entry is not None:
|
||||
self.entry = entry
|
||||
self.summary = entry.summary
|
||||
self.income = None if entry.is_debit else entry.amount
|
||||
self.expense = entry.amount if entry.is_debit else None
|
||||
|
||||
|
||||
class EntryCollector:
|
||||
"""The income and expenses log entry collector."""
|
||||
|
||||
def __init__(self, currency: Currency, account: IncomeExpensesAccount,
|
||||
period: Period):
|
||||
"""Constructs the income and expenses log entry collector.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
"""
|
||||
self.__currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.__account: IncomeExpensesAccount = account
|
||||
"""The account."""
|
||||
self.__period: Period = period
|
||||
"""The period"""
|
||||
self.brought_forward: Entry | None
|
||||
"""The brought-forward entry."""
|
||||
self.entries: list[Entry]
|
||||
"""The log entries."""
|
||||
self.total: Entry | None
|
||||
"""The total entry."""
|
||||
self.brought_forward = self.__get_brought_forward_entry()
|
||||
self.entries = self.__query_entries()
|
||||
self.total = self.__get_total_entry()
|
||||
self.__populate_balance()
|
||||
|
||||
def __get_brought_forward_entry(self) -> Entry | None:
|
||||
"""Queries, composes and returns the brought-forward entry.
|
||||
|
||||
:return: The brought-forward entry, or None if the period starts from
|
||||
the beginning.
|
||||
"""
|
||||
if self.__period.start is None:
|
||||
return None
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, JournalEntry.amount),
|
||||
else_=-JournalEntry.amount))
|
||||
select: sa.Select = sa.Select(balance_func)\
|
||||
.join(Transaction).join(Account)\
|
||||
.filter(JournalEntry.currency_code == self.__currency.code,
|
||||
self.__account_condition,
|
||||
Transaction.date < self.__period.start)
|
||||
balance: int | None = db.session.scalar(select)
|
||||
if balance is None:
|
||||
return None
|
||||
entry: Entry = Entry()
|
||||
entry.is_brought_forward = True
|
||||
entry.date = self.__period.start
|
||||
entry.account = Account.find_by_code("3351-001")
|
||||
entry.summary = gettext("Brought forward")
|
||||
if balance > 0:
|
||||
entry.income = balance
|
||||
elif balance < 0:
|
||||
entry.expense = -balance
|
||||
entry.balance = balance
|
||||
return entry
|
||||
|
||||
def __query_entries(self) -> list[Entry]:
|
||||
"""Queries and returns the log entries.
|
||||
|
||||
:return: The log entries.
|
||||
"""
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.currency_code == self.__currency.code,
|
||||
self.__account_condition]
|
||||
if self.__period.start is not None:
|
||||
conditions.append(Transaction.date >= self.__period.start)
|
||||
if self.__period.end is not None:
|
||||
conditions.append(Transaction.date <= self.__period.end)
|
||||
txn_with_account: sa.Select = sa.Select(Transaction.id).\
|
||||
join(JournalEntry).join(Account).filter(*conditions)
|
||||
|
||||
return [Entry(x)
|
||||
for x in JournalEntry.query.join(Transaction).join(Account)
|
||||
.filter(JournalEntry.transaction_id.in_(txn_with_account),
|
||||
JournalEntry.currency_code == self.__currency.code,
|
||||
sa.not_(self.__account_condition))
|
||||
.order_by(Transaction.date,
|
||||
JournalEntry.is_debit,
|
||||
JournalEntry.no)]
|
||||
|
||||
@property
|
||||
def __account_condition(self) -> sa.BinaryExpression:
|
||||
if self.__account.code == IncomeExpensesAccount.CURRENT_AL_CODE:
|
||||
return sa.or_(Account.base_code.startswith("11"),
|
||||
Account.base_code.startswith("12"),
|
||||
Account.base_code.startswith("21"),
|
||||
Account.base_code.startswith("22"))
|
||||
return Account.id == self.__account.id
|
||||
|
||||
def __get_total_entry(self) -> Entry | None:
|
||||
"""Composes the total entry.
|
||||
|
||||
:return: The total entry, or None if there is no data.
|
||||
"""
|
||||
if self.brought_forward is None and len(self.entries) == 0:
|
||||
return None
|
||||
entry: Entry = Entry()
|
||||
entry.is_total = True
|
||||
entry.summary = gettext("Total")
|
||||
entry.income = sum([x.income for x in self.entries
|
||||
if x.income is not None])
|
||||
entry.expense = sum([x.expense for x in self.entries
|
||||
if x.expense is not None])
|
||||
entry.balance = entry.income - entry.expense
|
||||
if self.brought_forward is not None:
|
||||
entry.balance = self.brought_forward.balance + entry.balance
|
||||
return entry
|
||||
|
||||
def __populate_balance(self) -> None:
|
||||
"""Populates the balance of the entries.
|
||||
|
||||
:return: None.
|
||||
"""
|
||||
balance: Decimal = 0 if self.brought_forward is None \
|
||||
else self.brought_forward.balance
|
||||
for entry in self.entries:
|
||||
if entry.income is not None:
|
||||
balance = balance + entry.income
|
||||
if entry.expense is not None:
|
||||
balance = balance - entry.expense
|
||||
entry.balance = balance
|
||||
|
||||
|
||||
class CSVRow(BaseCSVRow):
|
||||
"""A row in the CSV income and expenses log."""
|
||||
|
||||
def __init__(self, txn_date: date | str | None,
|
||||
account: str | None,
|
||||
summary: str | None,
|
||||
income: str | Decimal | None,
|
||||
expense: str | Decimal | None,
|
||||
balance: str | Decimal | None,
|
||||
note: str | None):
|
||||
"""Constructs a row in the CSV income and expenses log.
|
||||
|
||||
:param txn_date: The transaction date.
|
||||
:param account: The account.
|
||||
:param summary: The summary.
|
||||
:param income: The income.
|
||||
:param expense: The expense.
|
||||
:param balance: The balance.
|
||||
:param note: The note.
|
||||
"""
|
||||
self.date: date | str | None = txn_date
|
||||
"""The date."""
|
||||
self.account: str | None = account
|
||||
"""The account."""
|
||||
self.summary: str | None = summary
|
||||
"""The summary."""
|
||||
self.income: str | Decimal | None = income
|
||||
"""The income."""
|
||||
self.expense: str | Decimal | None = expense
|
||||
"""The expense."""
|
||||
self.balance: str | Decimal | None = balance
|
||||
"""The balance."""
|
||||
self.note: str | None = note
|
||||
"""The note."""
|
||||
|
||||
@property
|
||||
def values(self) -> list[str | Decimal | None]:
|
||||
"""Returns the values of the row.
|
||||
|
||||
:return: The values of the row.
|
||||
"""
|
||||
return [self.date, self.account, self.summary,
|
||||
self.income, self.expense, self.balance, self.note]
|
||||
|
||||
|
||||
class IncomeExpensesPageParams(PageParams):
|
||||
"""The HTML parameters of the income and expenses log."""
|
||||
|
||||
def __init__(self, currency: Currency,
|
||||
account: IncomeExpensesAccount,
|
||||
period: Period,
|
||||
has_data: bool,
|
||||
pagination: Pagination[Entry],
|
||||
brought_forward: Entry | None,
|
||||
entries: list[Entry],
|
||||
total: Entry | None):
|
||||
"""Constructs the HTML parameters of the income and expenses log.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
:param has_data: True if there is any data, or False otherwise.
|
||||
:param brought_forward: The brought-forward entry.
|
||||
:param entries: The log entries.
|
||||
:param total: The total entry.
|
||||
"""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.account: IncomeExpensesAccount = account
|
||||
"""The account."""
|
||||
self.period: Period = period
|
||||
"""The period."""
|
||||
self.__has_data: bool = has_data
|
||||
"""True if there is any data, or False otherwise."""
|
||||
self.pagination: Pagination[Entry] = pagination
|
||||
"""The pagination."""
|
||||
self.brought_forward: Entry | None = brought_forward
|
||||
"""The brought-forward entry."""
|
||||
self.entries: list[Entry] = entries
|
||||
"""The entries."""
|
||||
self.total: Entry | None = total
|
||||
"""The total entry."""
|
||||
self.period_chooser: IncomeExpensesPeriodChooser \
|
||||
= IncomeExpensesPeriodChooser(currency, account)
|
||||
"""The period chooser."""
|
||||
|
||||
@property
|
||||
def has_data(self) -> bool:
|
||||
"""Returns whether there is any data on the page.
|
||||
|
||||
:return: True if there is any data, or False otherwise.
|
||||
"""
|
||||
return self.__has_data
|
||||
|
||||
@property
|
||||
def report_chooser(self) -> ReportChooser:
|
||||
"""Returns the report chooser.
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
if self.account.account is None:
|
||||
return ReportChooser(ReportType.INCOME_EXPENSES,
|
||||
currency=self.currency,
|
||||
account=Account.cash(),
|
||||
period=self.period)
|
||||
return ReportChooser(ReportType.INCOME_EXPENSES,
|
||||
currency=self.currency,
|
||||
account=self.account.account,
|
||||
period=self.period)
|
||||
|
||||
@property
|
||||
def currency_options(self) -> list[OptionLink]:
|
||||
"""Returns the currency options.
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
def get_url(currency: Currency):
|
||||
if self.period.is_default:
|
||||
return url_for("accounting.report.income-expenses-default",
|
||||
currency=currency, account=self.account)
|
||||
return url_for("accounting.report.income-expenses",
|
||||
currency=currency, account=self.account,
|
||||
period=self.period)
|
||||
|
||||
in_use: set[str] = set(db.session.scalars(
|
||||
sa.select(JournalEntry.currency_code)
|
||||
.group_by(JournalEntry.currency_code)).all())
|
||||
return [OptionLink(str(x), get_url(x), x.code == self.currency.code)
|
||||
for x in Currency.query.filter(Currency.code.in_(in_use))
|
||||
.order_by(Currency.code).all()]
|
||||
|
||||
@property
|
||||
def account_options(self) -> list[OptionLink]:
|
||||
"""Returns the account options.
|
||||
|
||||
:return: The account options.
|
||||
"""
|
||||
def get_url(account: IncomeExpensesAccount):
|
||||
if self.period.is_default:
|
||||
return url_for("accounting.report.income-expenses-default",
|
||||
currency=self.currency, account=account)
|
||||
return url_for("accounting.report.income-expenses",
|
||||
currency=self.currency, account=account,
|
||||
period=self.period)
|
||||
|
||||
current_al: IncomeExpensesAccount \
|
||||
= IncomeExpensesAccount.current_assets_and_liabilities()
|
||||
options: list[OptionLink] \
|
||||
= [OptionLink(str(current_al), get_url(current_al),
|
||||
self.account.id == 0)]
|
||||
in_use: sa.Select = sa.Select(JournalEntry.account_id)\
|
||||
.join(Account)\
|
||||
.filter(JournalEntry.currency_code == self.currency.code,
|
||||
sa.or_(Account.base_code.startswith("11"),
|
||||
Account.base_code.startswith("12"),
|
||||
Account.base_code.startswith("21"),
|
||||
Account.base_code.startswith("22")))\
|
||||
.group_by(JournalEntry.account_id)
|
||||
options.extend([OptionLink(str(x), get_url(IncomeExpensesAccount(x)),
|
||||
x.id == self.account.id)
|
||||
for x in Account.query.filter(Account.id.in_(in_use))
|
||||
.order_by(Account.base_code, Account.no).all()])
|
||||
return options
|
||||
|
||||
|
||||
def _populate_entries(entries: list[Entry]) -> None:
|
||||
"""Populates the income and expenses entries with relative data.
|
||||
|
||||
:param entries: The income and expenses entries.
|
||||
:return: None.
|
||||
"""
|
||||
transactions: dict[int, Transaction] \
|
||||
= {x.id: x for x in Transaction.query.filter(
|
||||
Transaction.id.in_({x.entry.transaction_id for x in entries
|
||||
if x.entry is not None}))}
|
||||
accounts: dict[int, Account] \
|
||||
= {x.id: x for x in Account.query.filter(
|
||||
Account.id.in_({x.entry.account_id for x in entries
|
||||
if x.entry is not None}))}
|
||||
for entry in entries:
|
||||
if entry.entry is not None:
|
||||
entry.transaction = transactions[entry.entry.transaction_id]
|
||||
entry.date = entry.transaction.date
|
||||
entry.note = entry.transaction.note
|
||||
entry.account = accounts[entry.entry.account_id]
|
||||
|
||||
|
||||
class IncomeExpenses(BaseReport):
|
||||
"""The income and expenses log."""
|
||||
|
||||
def __init__(self, currency: Currency, account: IncomeExpensesAccount,
|
||||
period: Period):
|
||||
"""Constructs an income and expenses log.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
"""
|
||||
self.__currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.__account: IncomeExpensesAccount = account
|
||||
"""The account."""
|
||||
self.__period: Period = period
|
||||
"""The period."""
|
||||
collector: EntryCollector = EntryCollector(
|
||||
self.__currency, self.__account, self.__period)
|
||||
self.__brought_forward: Entry | None = collector.brought_forward
|
||||
"""The brought-forward entry."""
|
||||
self.__entries: list[Entry] = collector.entries
|
||||
"""The log entries."""
|
||||
self.__total: Entry | None = collector.total
|
||||
"""The total entry."""
|
||||
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
filename: str = "income-expenses-{currency}-{account}-{period}.csv"\
|
||||
.format(currency=self.__currency.code, account=self.__account.code,
|
||||
period=self.__period.spec)
|
||||
return csv_download(filename, self.__get_csv_rows())
|
||||
|
||||
def __get_csv_rows(self) -> list[CSVRow]:
|
||||
"""Composes and returns the CSV rows.
|
||||
|
||||
:return: The CSV rows.
|
||||
"""
|
||||
_populate_entries(self.__entries)
|
||||
rows: list[CSVRow] = [CSVRow(gettext("Date"), gettext("Account"),
|
||||
gettext("Summary"), gettext("Income"),
|
||||
gettext("Expense"), gettext("Balance"),
|
||||
gettext("Note"))]
|
||||
if self.__brought_forward is not None:
|
||||
rows.append(CSVRow(self.__brought_forward.date,
|
||||
str(self.__brought_forward.account).title(),
|
||||
self.__brought_forward.summary,
|
||||
self.__brought_forward.income,
|
||||
self.__brought_forward.expense,
|
||||
self.__brought_forward.balance,
|
||||
None))
|
||||
rows.extend([CSVRow(x.date, str(x.account).title(), x.summary,
|
||||
x.income, x.expense, x.balance, x.note)
|
||||
for x in self.__entries])
|
||||
if self.__total is not None:
|
||||
rows.append(CSVRow(gettext("Total"), None, None,
|
||||
self.__total.income, self.__total.expense,
|
||||
self.__total.balance, None))
|
||||
return rows
|
||||
|
||||
def html(self) -> str:
|
||||
"""Composes and returns the report as HTML.
|
||||
|
||||
:return: The report as HTML.
|
||||
"""
|
||||
all_entries: list[Entry] = []
|
||||
if self.__brought_forward is not None:
|
||||
all_entries.append(self.__brought_forward)
|
||||
all_entries.extend(self.__entries)
|
||||
if self.__total is not None:
|
||||
all_entries.append(self.__total)
|
||||
pagination: Pagination[Entry] = Pagination[Entry](all_entries)
|
||||
page_entries: list[Entry] = pagination.list
|
||||
has_data: bool = len(page_entries) > 0
|
||||
_populate_entries(page_entries)
|
||||
brought_forward: Entry | None = None
|
||||
if len(page_entries) > 0 and page_entries[0].is_brought_forward:
|
||||
brought_forward = page_entries[0]
|
||||
page_entries = page_entries[1:]
|
||||
total: Entry | None = None
|
||||
if len(page_entries) > 0 and page_entries[-1].is_total:
|
||||
total = page_entries[-1]
|
||||
page_entries = page_entries[:-1]
|
||||
params: IncomeExpensesPageParams = IncomeExpensesPageParams(
|
||||
currency=self.__currency,
|
||||
account=self.__account,
|
||||
period=self.__period,
|
||||
has_data=has_data,
|
||||
pagination=pagination,
|
||||
brought_forward=brought_forward,
|
||||
entries=page_entries,
|
||||
total=total)
|
||||
return render_template("accounting/report/income-expenses.html",
|
||||
report=params)
|
348
src/accounting/report/reports/income_statement.py
Normal file
348
src/accounting/report/reports/income_statement.py
Normal file
@ -0,0 +1,348 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The income statement.
|
||||
|
||||
"""
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import url_for, render_template, Response
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency, BaseAccount, Account, Transaction, \
|
||||
JournalEntry
|
||||
from accounting.report.period import Period
|
||||
from .utils.base_report import BaseReport
|
||||
from .utils.csv_export import BaseCSVRow, csv_download
|
||||
from .utils.option_link import OptionLink
|
||||
from .utils.page_params import PageParams
|
||||
from .utils.period_choosers import IncomeStatementPeriodChooser
|
||||
from .utils.report_chooser import ReportChooser
|
||||
from .utils.report_type import ReportType
|
||||
|
||||
|
||||
class IncomeStatementAccount:
|
||||
"""An account in the income statement."""
|
||||
|
||||
def __init__(self, account: Account, amount: Decimal, url: str):
|
||||
"""Constructs an account in the income statement.
|
||||
|
||||
:param account: The account.
|
||||
:param amount: The amount.
|
||||
:param url: The URL to the ledger of the account.
|
||||
"""
|
||||
self.account: Account = account
|
||||
"""The account."""
|
||||
self.amount: Decimal = amount
|
||||
"""The amount of the account."""
|
||||
self.url: str = url
|
||||
"""The URL to the ledger of the account."""
|
||||
|
||||
|
||||
class IncomeStatementAccumulatedTotal:
|
||||
"""An accumulated total in the income statement."""
|
||||
|
||||
def __init__(self, title: str):
|
||||
"""Constructs an accumulated total in the income statement.
|
||||
|
||||
:param title: The title.
|
||||
"""
|
||||
self.title: str = title
|
||||
"""The account."""
|
||||
self.amount: Decimal = Decimal("0")
|
||||
"""The amount of the account."""
|
||||
|
||||
|
||||
class IncomeStatementSubsection:
|
||||
"""A subsection in the income statement."""
|
||||
|
||||
def __init__(self, title: BaseAccount):
|
||||
"""Constructs a subsection in the income statement.
|
||||
|
||||
:param title: The title account.
|
||||
"""
|
||||
self.title: BaseAccount = title
|
||||
"""The title account."""
|
||||
self.accounts: list[IncomeStatementAccount] = []
|
||||
"""The accounts in the subsection."""
|
||||
|
||||
@property
|
||||
def total(self) -> Decimal:
|
||||
"""Returns the total of the subsection.
|
||||
|
||||
:return: The total of the subsection.
|
||||
"""
|
||||
return sum([x.amount for x in self.accounts])
|
||||
|
||||
|
||||
class IncomeStatementSection:
|
||||
"""A section in the income statement."""
|
||||
|
||||
def __init__(self, title: BaseAccount, accumulated_title: str):
|
||||
"""Constructs a section in the income statement.
|
||||
|
||||
:param title: The title account.
|
||||
:param accumulated_title: The title for the accumulated total.
|
||||
"""
|
||||
self.title: BaseAccount = title
|
||||
"""The title account."""
|
||||
self.subsections: list[IncomeStatementSubsection] = []
|
||||
"""The subsections in the section."""
|
||||
self.accumulated: IncomeStatementAccumulatedTotal \
|
||||
= IncomeStatementAccumulatedTotal(accumulated_title)
|
||||
|
||||
@property
|
||||
def total(self) -> Decimal:
|
||||
"""Returns the total of the section.
|
||||
|
||||
:return: The total of the section.
|
||||
"""
|
||||
return sum([x.total for x in self.subsections])
|
||||
|
||||
|
||||
class CSVRow(BaseCSVRow):
|
||||
"""A row in the CSV income statement."""
|
||||
|
||||
def __init__(self, text: str | None, amount: str | Decimal | None):
|
||||
"""Constructs a row in the CSV income statement.
|
||||
|
||||
:param text: The text.
|
||||
:param amount: The amount.
|
||||
"""
|
||||
self.text: str | None = text
|
||||
"""The text."""
|
||||
self.amount: str | Decimal | None = amount
|
||||
"""The amount."""
|
||||
|
||||
@property
|
||||
def values(self) -> list[str | Decimal | None]:
|
||||
"""Returns the values of the row.
|
||||
|
||||
:return: The values of the row.
|
||||
"""
|
||||
return [self.text, self.amount]
|
||||
|
||||
|
||||
class IncomeStatementPageParams(PageParams):
|
||||
"""The HTML parameters of the income statement."""
|
||||
|
||||
def __init__(self, currency: Currency,
|
||||
period: Period,
|
||||
has_data: bool,
|
||||
sections: list[IncomeStatementSection],):
|
||||
"""Constructs the HTML parameters of the income statement.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:param has_data: True if there is any data, or False otherwise.
|
||||
"""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.period: Period = period
|
||||
"""The period."""
|
||||
self.__has_data: bool = has_data
|
||||
"""True if there is any data, or False otherwise."""
|
||||
self.sections: list[IncomeStatementSection] = sections
|
||||
self.period_chooser: IncomeStatementPeriodChooser \
|
||||
= IncomeStatementPeriodChooser(currency)
|
||||
"""The period chooser."""
|
||||
|
||||
@property
|
||||
def has_data(self) -> bool:
|
||||
"""Returns whether there is any data on the page.
|
||||
|
||||
:return: True if there is any data, or False otherwise.
|
||||
"""
|
||||
return self.__has_data
|
||||
|
||||
@property
|
||||
def report_chooser(self) -> ReportChooser:
|
||||
"""Returns the report chooser.
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
return ReportChooser(ReportType.INCOME_STATEMENT,
|
||||
currency=self.currency,
|
||||
period=self.period)
|
||||
|
||||
@property
|
||||
def currency_options(self) -> list[OptionLink]:
|
||||
"""Returns the currency options.
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
def get_url(currency: Currency):
|
||||
if self.period.is_default:
|
||||
return url_for("accounting.report.income-statement-default",
|
||||
currency=currency)
|
||||
return url_for("accounting.report.income-statement",
|
||||
currency=currency, period=self.period)
|
||||
|
||||
in_use: set[str] = set(db.session.scalars(
|
||||
sa.select(JournalEntry.currency_code)
|
||||
.group_by(JournalEntry.currency_code)).all())
|
||||
return [OptionLink(str(x), get_url(x), x.code == self.currency.code)
|
||||
for x in Currency.query.filter(Currency.code.in_(in_use))
|
||||
.order_by(Currency.code).all()]
|
||||
|
||||
|
||||
class IncomeStatement(BaseReport):
|
||||
"""The income statement."""
|
||||
|
||||
def __init__(self, currency: Currency, period: Period):
|
||||
"""Constructs an income statement.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
"""
|
||||
self.__currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.__period: Period = period
|
||||
"""The period."""
|
||||
self.__has_data: bool
|
||||
"""True if there is any data, or False otherwise."""
|
||||
self.__sections: list[IncomeStatementSection]
|
||||
"""The sections."""
|
||||
self.__set_data()
|
||||
|
||||
def __set_data(self) -> None:
|
||||
"""Queries and sets data sections in the income statement.
|
||||
|
||||
:return: None.
|
||||
"""
|
||||
balances: list[IncomeStatementAccount] = self.__query_balances()
|
||||
|
||||
titles: list[BaseAccount] = BaseAccount.query\
|
||||
.filter(BaseAccount.code.in_({"4", "5", "6", "7", "8", "9"})).all()
|
||||
subtitles: list[BaseAccount] = BaseAccount.query\
|
||||
.filter(BaseAccount.code.in_({x.account.base_code[:2]
|
||||
for x in balances})).all()
|
||||
|
||||
total_titles: dict[str, str] \
|
||||
= {"4": gettext("total revenue"),
|
||||
"5": gettext("gross income"),
|
||||
"6": gettext("operating income"),
|
||||
"7": gettext("before tax income"),
|
||||
"8": gettext("after tax income"),
|
||||
"9": gettext("net income or loss for current period")}
|
||||
|
||||
sections: dict[str, IncomeStatementSection] \
|
||||
= {x.code: IncomeStatementSection(x, total_titles[x.code])
|
||||
for x in titles}
|
||||
subsections: dict[str, IncomeStatementSubsection] \
|
||||
= {x.code: IncomeStatementSubsection(x) for x in subtitles}
|
||||
for subsection in subsections.values():
|
||||
sections[subsection.title.code[0]].subsections.append(subsection)
|
||||
for balance in balances:
|
||||
subsections[balance.account.base_code[:2]].accounts.append(balance)
|
||||
|
||||
self.__has_data = len(balances) > 0
|
||||
self.__sections = sorted(sections.values(), key=lambda x: x.title.code)
|
||||
total: Decimal = Decimal("0")
|
||||
for section in self.__sections:
|
||||
total = total + section.total
|
||||
section.accumulated.amount = total
|
||||
|
||||
def __query_balances(self) -> list[IncomeStatementAccount]:
|
||||
"""Queries and returns the balances.
|
||||
|
||||
:return: The balances.
|
||||
"""
|
||||
sub_conditions: list[sa.BinaryExpression] \
|
||||
= [Account.base_code.startswith(str(x)) for x in range(4, 10)]
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.currency_code == self.__currency.code,
|
||||
sa.or_(*sub_conditions)]
|
||||
if self.__period.start is not None:
|
||||
conditions.append(Transaction.date >= self.__period.start)
|
||||
if self.__period.end is not None:
|
||||
conditions.append(Transaction.date <= self.__period.end)
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, -JournalEntry.amount),
|
||||
else_=JournalEntry.amount)).label("balance")
|
||||
select_balance: sa.Select \
|
||||
= sa.select(JournalEntry.account_id, balance_func)\
|
||||
.join(Transaction).join(Account)\
|
||||
.filter(*conditions)\
|
||||
.group_by(JournalEntry.account_id)\
|
||||
.order_by(Account.base_code, Account.no)
|
||||
balances: list[sa.Row] = db.session.execute(select_balance).all()
|
||||
accounts: dict[int, Account] \
|
||||
= {x.id: x for x in Account.query
|
||||
.filter(Account.id.in_([x.account_id for x in balances])).all()}
|
||||
|
||||
def get_url(account: Account) -> str:
|
||||
"""Returns the ledger URL of an account.
|
||||
|
||||
:param account: The account.
|
||||
:return: The ledger URL of the account.
|
||||
"""
|
||||
if self.__period.is_default:
|
||||
return url_for("accounting.report.ledger-default",
|
||||
currency=self.__currency, account=account)
|
||||
return url_for("accounting.report.ledger",
|
||||
currency=self.__currency, account=account,
|
||||
period=self.__period)
|
||||
|
||||
return [IncomeStatementAccount(account=accounts[x.account_id],
|
||||
amount=x.balance,
|
||||
url=get_url(accounts[x.account_id]))
|
||||
for x in balances]
|
||||
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
filename: str = "income-statement-{currency}-{period}.csv"\
|
||||
.format(currency=self.__currency.code, period=self.__period.spec)
|
||||
return csv_download(filename, self.__get_csv_rows())
|
||||
|
||||
def __get_csv_rows(self) -> list[CSVRow]:
|
||||
"""Composes and returns the CSV rows.
|
||||
|
||||
:return: The CSV rows.
|
||||
"""
|
||||
total_str: str = gettext("Total")
|
||||
rows: list[CSVRow] = [CSVRow(None, gettext("Amount"))]
|
||||
for section in self.__sections:
|
||||
rows.append(CSVRow(str(section.title).title(), None))
|
||||
for subsection in section.subsections:
|
||||
rows.append(CSVRow(f" {str(subsection.title).title()}", None))
|
||||
for account in subsection.accounts:
|
||||
rows.append(CSVRow(f" {str(account.account).title()}",
|
||||
account.amount))
|
||||
rows.append(CSVRow(f" {total_str}", subsection.total))
|
||||
rows.append(CSVRow(section.accumulated.title.title(),
|
||||
section.accumulated.amount))
|
||||
rows.append(CSVRow(None, None))
|
||||
rows = rows[:-1]
|
||||
return rows
|
||||
|
||||
def html(self) -> str:
|
||||
"""Composes and returns the report as HTML.
|
||||
|
||||
:return: The report as HTML.
|
||||
"""
|
||||
params: IncomeStatementPageParams = IncomeStatementPageParams(
|
||||
currency=self.__currency,
|
||||
period=self.__period,
|
||||
has_data=self.__has_data,
|
||||
sections=self.__sections)
|
||||
return render_template("accounting/report/income-statement.html",
|
||||
report=params)
|
243
src/accounting/report/reports/journal.py
Normal file
243
src/accounting/report/reports/journal.py
Normal file
@ -0,0 +1,243 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The journal.
|
||||
|
||||
"""
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import render_template, Response
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency, Account, Transaction, JournalEntry
|
||||
from accounting.report.period import Period
|
||||
from accounting.utils.pagination import Pagination
|
||||
from .utils.base_report import BaseReport
|
||||
from .utils.csv_export import BaseCSVRow, csv_download
|
||||
from .utils.page_params import PageParams
|
||||
from .utils.period_choosers import JournalPeriodChooser
|
||||
from .utils.report_chooser import ReportChooser
|
||||
from .utils.report_type import ReportType
|
||||
|
||||
|
||||
class Entry:
|
||||
"""An entry in the journal."""
|
||||
|
||||
def __init__(self, entry: JournalEntry | None = None):
|
||||
"""Constructs the entry in the journal.
|
||||
|
||||
:param entry: The journal entry.
|
||||
"""
|
||||
self.entry: JournalEntry | None = None
|
||||
"""The journal entry."""
|
||||
self.transaction: Transaction | None = None
|
||||
"""The transaction."""
|
||||
self.is_total: bool = False
|
||||
"""Whether this is the total entry."""
|
||||
self.currency: Currency | None = None
|
||||
"""The account."""
|
||||
self.account: Account | None = None
|
||||
"""The account."""
|
||||
self.summary: str | None = None
|
||||
"""The summary."""
|
||||
self.debit: Decimal | None = None
|
||||
"""The debit amount."""
|
||||
self.credit: Decimal | None = None
|
||||
"""The credit amount."""
|
||||
self.amount: Decimal | None = None
|
||||
"""The amount."""
|
||||
if entry is not None:
|
||||
self.entry = entry
|
||||
self.summary = entry.summary
|
||||
self.debit = entry.amount if entry.is_debit else None
|
||||
self.credit = None if entry.is_debit else entry.amount
|
||||
self.amount = entry.amount
|
||||
|
||||
|
||||
class CSVRow(BaseCSVRow):
|
||||
"""A row in the CSV journal."""
|
||||
|
||||
def __init__(self, txn_date: str | date,
|
||||
currency: str,
|
||||
account: str,
|
||||
summary: str | None,
|
||||
debit: str | Decimal | None,
|
||||
credit: str | Decimal | None,
|
||||
note: str | None):
|
||||
"""Constructs a row in the CSV journal.
|
||||
|
||||
:param txn_date: The transaction date.
|
||||
:param summary: The summary.
|
||||
:param debit: The debit amount.
|
||||
:param credit: The credit amount.
|
||||
:param note: The note.
|
||||
"""
|
||||
self.date: str | date = txn_date
|
||||
"""The date."""
|
||||
self.currency: str = currency
|
||||
"""The currency."""
|
||||
self.account: str = account
|
||||
"""The account."""
|
||||
self.summary: str | None = summary
|
||||
"""The summary."""
|
||||
self.debit: str | Decimal | None = debit
|
||||
"""The debit amount."""
|
||||
self.credit: str | Decimal | None = credit
|
||||
"""The credit amount."""
|
||||
self.note: str | None = note
|
||||
"""The note."""
|
||||
|
||||
@property
|
||||
def values(self) -> list[str | Decimal | None]:
|
||||
"""Returns the values of the row.
|
||||
|
||||
:return: The values of the row.
|
||||
"""
|
||||
return [self.date, self.currency, self.account, self.summary,
|
||||
self.debit, self.credit, self.note]
|
||||
|
||||
|
||||
class JournalPageParams(PageParams):
|
||||
"""The HTML parameters of the journal."""
|
||||
|
||||
def __init__(self, period: Period,
|
||||
pagination: Pagination[Entry],
|
||||
entries: list[Entry]):
|
||||
"""Constructs the HTML parameters of the journal.
|
||||
|
||||
:param period: The period.
|
||||
:param entries: The journal entries.
|
||||
"""
|
||||
self.period: Period = period
|
||||
"""The period."""
|
||||
self.pagination: Pagination[Entry] = pagination
|
||||
"""The pagination."""
|
||||
self.entries: list[Entry] = entries
|
||||
"""The entries."""
|
||||
self.period_chooser: JournalPeriodChooser \
|
||||
= JournalPeriodChooser()
|
||||
"""The period chooser."""
|
||||
|
||||
@property
|
||||
def has_data(self) -> bool:
|
||||
"""Returns whether there is any data on the page.
|
||||
|
||||
:return: True if there is any data, or False otherwise.
|
||||
"""
|
||||
return len(self.entries) > 0
|
||||
|
||||
@property
|
||||
def report_chooser(self) -> ReportChooser:
|
||||
"""Returns the report chooser.
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
return ReportChooser(ReportType.JOURNAL,
|
||||
period=self.period)
|
||||
|
||||
|
||||
def _populate_entries(entries: list[Entry]) -> None:
|
||||
"""Populates the journal entries with relative data.
|
||||
|
||||
:param entries: The journal entries.
|
||||
:return: None.
|
||||
"""
|
||||
transactions: dict[int, Transaction] \
|
||||
= {x.id: x for x in Transaction.query.filter(
|
||||
Transaction.id.in_({x.entry.transaction_id for x in entries}))}
|
||||
accounts: dict[int, Account] \
|
||||
= {x.id: x for x in Account.query.filter(
|
||||
Account.id.in_({x.entry.account_id for x in entries}))}
|
||||
currencies: dict[int, Currency] \
|
||||
= {x.code: x for x in Currency.query.filter(
|
||||
Currency.code.in_({x.entry.currency_code for x in entries}))}
|
||||
for entry in entries:
|
||||
entry.transaction = transactions[entry.entry.transaction_id]
|
||||
entry.account = accounts[entry.entry.account_id]
|
||||
entry.currency = currencies[entry.entry.currency_code]
|
||||
|
||||
|
||||
class Journal(BaseReport):
|
||||
"""The journal."""
|
||||
|
||||
def __init__(self, period: Period):
|
||||
"""Constructs a journal.
|
||||
|
||||
:param period: The period.
|
||||
"""
|
||||
"""The account."""
|
||||
self.__period: Period = period
|
||||
"""The period."""
|
||||
self.__entries: list[Entry] = self.__query_entries()
|
||||
"""The journal entries."""
|
||||
|
||||
def __query_entries(self) -> list[Entry]:
|
||||
"""Queries and returns the journal entries.
|
||||
|
||||
:return: The journal entries.
|
||||
"""
|
||||
conditions: list[sa.BinaryExpression] = []
|
||||
if self.__period.start is not None:
|
||||
conditions.append(Transaction.date >= self.__period.start)
|
||||
if self.__period.end is not None:
|
||||
conditions.append(Transaction.date <= self.__period.end)
|
||||
return [Entry(x) for x in db.session
|
||||
.query(JournalEntry).join(Transaction).filter(*conditions)
|
||||
.order_by(Transaction.date,
|
||||
JournalEntry.is_debit.desc(),
|
||||
JournalEntry.no).all()]
|
||||
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
filename: str = f"journal-{self.__period.spec}.csv"
|
||||
return csv_download(filename, self.__get_csv_rows())
|
||||
|
||||
def __get_csv_rows(self) -> list[CSVRow]:
|
||||
"""Composes and returns the CSV rows.
|
||||
|
||||
:return: The CSV rows.
|
||||
"""
|
||||
_populate_entries(self.__entries)
|
||||
rows: list[CSVRow] = [CSVRow(gettext("Date"), gettext("Currency"),
|
||||
gettext("Account"), gettext("Summary"),
|
||||
gettext("Debit"), gettext("Credit"),
|
||||
gettext("Note"))]
|
||||
rows.extend([CSVRow(x.transaction.date, x.currency.code,
|
||||
str(x.account).title(), x.summary,
|
||||
x.debit, x.credit, x.transaction.note)
|
||||
for x in self.__entries])
|
||||
return rows
|
||||
|
||||
def html(self) -> str:
|
||||
"""Composes and returns the report as HTML.
|
||||
|
||||
:return: The report as HTML.
|
||||
"""
|
||||
pagination: Pagination[Entry] = Pagination[Entry](self.__entries)
|
||||
page_entries: list[Entry] = pagination.list
|
||||
_populate_entries(page_entries)
|
||||
params: JournalPageParams = JournalPageParams(
|
||||
period=self.__period,
|
||||
pagination=pagination,
|
||||
entries=page_entries)
|
||||
return render_template("accounting/report/journal.html",
|
||||
report=params)
|
439
src/accounting/report/reports/ledger.py
Normal file
439
src/accounting/report/reports/ledger.py
Normal file
@ -0,0 +1,439 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The ledger.
|
||||
|
||||
"""
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import url_for, render_template, Response
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency, Account, Transaction, JournalEntry
|
||||
from accounting.report.period import Period
|
||||
from accounting.utils.pagination import Pagination
|
||||
from .utils.base_report import BaseReport
|
||||
from .utils.csv_export import BaseCSVRow, csv_download
|
||||
from .utils.option_link import OptionLink
|
||||
from .utils.page_params import PageParams
|
||||
from .utils.period_choosers import LedgerPeriodChooser
|
||||
from .utils.report_chooser import ReportChooser
|
||||
from .utils.report_type import ReportType
|
||||
|
||||
|
||||
class Entry:
|
||||
"""An entry in the ledger."""
|
||||
|
||||
def __init__(self, entry: JournalEntry | None = None):
|
||||
"""Constructs the entry in the ledger.
|
||||
|
||||
:param entry: The journal entry.
|
||||
"""
|
||||
self.entry: JournalEntry | None = None
|
||||
"""The journal entry."""
|
||||
self.transaction: Transaction | None = None
|
||||
"""The transaction."""
|
||||
self.is_brought_forward: bool = False
|
||||
"""Whether this is the brought-forward entry."""
|
||||
self.is_total: bool = False
|
||||
"""Whether this is the total entry."""
|
||||
self.date: date | None = None
|
||||
"""The date."""
|
||||
self.account: Account | None = None
|
||||
"""The account."""
|
||||
self.summary: str | None = None
|
||||
"""The summary."""
|
||||
self.debit: Decimal | None = None
|
||||
"""The debit amount."""
|
||||
self.credit: Decimal | None = None
|
||||
"""The credit amount."""
|
||||
self.balance: Decimal | None = None
|
||||
"""The balance."""
|
||||
self.note: str | None = None
|
||||
"""The note."""
|
||||
if entry is not None:
|
||||
self.entry = entry
|
||||
self.summary = entry.summary
|
||||
self.debit = entry.amount if entry.is_debit else None
|
||||
self.credit = None if entry.is_debit else entry.amount
|
||||
|
||||
|
||||
class EntryCollector:
|
||||
"""The ledger entry collector."""
|
||||
|
||||
def __init__(self, currency: Currency, account: Account, period: Period):
|
||||
"""Constructs the ledger entry collector.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
"""
|
||||
self.__currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.__account: Account = account
|
||||
"""The account."""
|
||||
self.__period: Period = period
|
||||
"""The period"""
|
||||
self.brought_forward: Entry | None
|
||||
"""The brought-forward entry."""
|
||||
self.entries: list[Entry]
|
||||
"""The ledger entries."""
|
||||
self.total: Entry | None
|
||||
"""The total entry."""
|
||||
self.brought_forward = self.__get_brought_forward_entry()
|
||||
self.entries = self.__query_entries()
|
||||
self.total = self.__get_total_entry()
|
||||
self.__populate_balance()
|
||||
|
||||
def __get_brought_forward_entry(self) -> Entry | None:
|
||||
"""Queries, composes and returns the brought-forward entry.
|
||||
|
||||
:return: The brought-forward entry, or None if the ledger starts from
|
||||
the beginning.
|
||||
"""
|
||||
if self.__period.start is None:
|
||||
return None
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, JournalEntry.amount),
|
||||
else_=-JournalEntry.amount))
|
||||
select: sa.Select = sa.Select(balance_func).join(Transaction)\
|
||||
.filter(JournalEntry.currency_code == self.__currency.code,
|
||||
JournalEntry.account_id == self.__account.id,
|
||||
Transaction.date < self.__period.start)
|
||||
balance: int | None = db.session.scalar(select)
|
||||
if balance is None:
|
||||
return None
|
||||
entry: Entry = Entry()
|
||||
entry.is_brought_forward = True
|
||||
entry.date = self.__period.start
|
||||
entry.summary = gettext("Brought forward")
|
||||
if balance > 0:
|
||||
entry.debit = balance
|
||||
elif balance < 0:
|
||||
entry.credit = -balance
|
||||
entry.balance = balance
|
||||
return entry
|
||||
|
||||
def __query_entries(self) -> list[Entry]:
|
||||
"""Queries and returns the ledger entries.
|
||||
|
||||
:return: The ledger entries.
|
||||
"""
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.currency_code == self.__currency.code,
|
||||
JournalEntry.account_id == self.__account.id]
|
||||
if self.__period.start is not None:
|
||||
conditions.append(Transaction.date >= self.__period.start)
|
||||
if self.__period.end is not None:
|
||||
conditions.append(Transaction.date <= self.__period.end)
|
||||
return [Entry(x) for x in JournalEntry.query.join(Transaction)
|
||||
.filter(*conditions)
|
||||
.order_by(Transaction.date,
|
||||
JournalEntry.is_debit.desc(),
|
||||
JournalEntry.no).all()]
|
||||
|
||||
def __get_total_entry(self) -> Entry | None:
|
||||
"""Composes the total entry.
|
||||
|
||||
:return: The total entry, or None if there is no data.
|
||||
"""
|
||||
if self.brought_forward is None and len(self.entries) == 0:
|
||||
return None
|
||||
entry: Entry = Entry()
|
||||
entry.is_total = True
|
||||
entry.summary = gettext("Total")
|
||||
entry.debit = sum([x.debit for x in self.entries
|
||||
if x.debit is not None])
|
||||
entry.credit = sum([x.credit for x in self.entries
|
||||
if x.credit is not None])
|
||||
entry.balance = entry.debit - entry.credit
|
||||
if self.brought_forward is not None:
|
||||
entry.balance = self.brought_forward.balance + entry.balance
|
||||
return entry
|
||||
|
||||
def __populate_balance(self) -> None:
|
||||
"""Populates the balance of the entries.
|
||||
|
||||
:return: None.
|
||||
"""
|
||||
balance: Decimal = 0 if self.brought_forward is None \
|
||||
else self.brought_forward.balance
|
||||
for entry in self.entries:
|
||||
if entry.debit is not None:
|
||||
balance = balance + entry.debit
|
||||
if entry.credit is not None:
|
||||
balance = balance - entry.credit
|
||||
entry.balance = balance
|
||||
|
||||
|
||||
class CSVRow(BaseCSVRow):
|
||||
"""A row in the CSV ledger."""
|
||||
|
||||
def __init__(self, txn_date: date | str | None,
|
||||
summary: str | None,
|
||||
debit: str | Decimal | None,
|
||||
credit: str | Decimal | None,
|
||||
balance: str | Decimal | None,
|
||||
note: str | None):
|
||||
"""Constructs a row in the CSV ledger.
|
||||
|
||||
:param txn_date: The transaction date.
|
||||
:param summary: The summary.
|
||||
:param debit: The debit amount.
|
||||
:param credit: The credit amount.
|
||||
:param balance: The balance.
|
||||
:param note: The note.
|
||||
"""
|
||||
self.date: date | str | None = txn_date
|
||||
"""The date."""
|
||||
self.summary: str | None = summary
|
||||
"""The summary."""
|
||||
self.debit: str | Decimal | None = debit
|
||||
"""The debit amount."""
|
||||
self.credit: str | Decimal | None = credit
|
||||
"""The credit amount."""
|
||||
self.balance: str | Decimal | None = balance
|
||||
"""The balance."""
|
||||
self.note: str | None = note
|
||||
"""The note."""
|
||||
|
||||
@property
|
||||
def values(self) -> list[str | Decimal | None]:
|
||||
"""Returns the values of the row.
|
||||
|
||||
:return: The values of the row.
|
||||
"""
|
||||
return [self.date, self.summary,
|
||||
self.debit, self.credit, self.balance, self.note]
|
||||
|
||||
|
||||
class LedgerPageParams(PageParams):
|
||||
"""The HTML parameters of the ledger."""
|
||||
|
||||
def __init__(self, currency: Currency,
|
||||
account: Account,
|
||||
period: Period,
|
||||
has_data: bool,
|
||||
pagination: Pagination[Entry],
|
||||
brought_forward: Entry | None,
|
||||
entries: list[Entry],
|
||||
total: Entry | None):
|
||||
"""Constructs the HTML parameters of the ledger.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
:param has_data: True if there is any data, or False otherwise.
|
||||
:param brought_forward: The brought-forward entry.
|
||||
:param entries: The ledger entries.
|
||||
:param total: The total entry.
|
||||
"""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.account: Account = account
|
||||
"""The account."""
|
||||
self.period: Period = period
|
||||
"""The period."""
|
||||
self.__has_data: bool = has_data
|
||||
"""True if there is any data, or False otherwise."""
|
||||
self.pagination: Pagination[Entry] = pagination
|
||||
"""The pagination."""
|
||||
self.brought_forward: Entry | None = brought_forward
|
||||
"""The brought-forward entry."""
|
||||
self.entries: list[Entry] = entries
|
||||
"""The entries."""
|
||||
self.total: Entry | None = total
|
||||
"""The total entry."""
|
||||
self.period_chooser: LedgerPeriodChooser \
|
||||
= LedgerPeriodChooser(currency, account)
|
||||
"""The period chooser."""
|
||||
|
||||
@property
|
||||
def has_data(self) -> bool:
|
||||
"""Returns whether there is any data on the page.
|
||||
|
||||
:return: True if there is any data, or False otherwise.
|
||||
"""
|
||||
return self.__has_data
|
||||
|
||||
@property
|
||||
def report_chooser(self) -> ReportChooser:
|
||||
"""Returns the report chooser.
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
return ReportChooser(ReportType.LEDGER,
|
||||
currency=self.currency,
|
||||
account=self.account,
|
||||
period=self.period)
|
||||
|
||||
@property
|
||||
def currency_options(self) -> list[OptionLink]:
|
||||
"""Returns the currency options.
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
def get_url(currency: Currency):
|
||||
if self.period.is_default:
|
||||
return url_for("accounting.report.ledger-default",
|
||||
currency=currency, account=self.account)
|
||||
return url_for("accounting.report.ledger",
|
||||
currency=currency, account=self.account,
|
||||
period=self.period)
|
||||
|
||||
in_use: set[str] = set(db.session.scalars(
|
||||
sa.select(JournalEntry.currency_code)
|
||||
.group_by(JournalEntry.currency_code)).all())
|
||||
return [OptionLink(str(x), get_url(x), x.code == self.currency.code)
|
||||
for x in Currency.query.filter(Currency.code.in_(in_use))
|
||||
.order_by(Currency.code).all()]
|
||||
|
||||
@property
|
||||
def account_options(self) -> list[OptionLink]:
|
||||
"""Returns the account options.
|
||||
|
||||
:return: The account options.
|
||||
"""
|
||||
def get_url(account: Account):
|
||||
if self.period.is_default:
|
||||
return url_for("accounting.report.ledger-default",
|
||||
currency=self.currency, account=account)
|
||||
return url_for("accounting.report.ledger",
|
||||
currency=self.currency, account=account,
|
||||
period=self.period)
|
||||
|
||||
in_use: sa.Select = sa.Select(JournalEntry.account_id)\
|
||||
.filter(JournalEntry.currency_code == self.currency.code)\
|
||||
.group_by(JournalEntry.account_id)
|
||||
return [OptionLink(str(x), get_url(x), x.id == self.account.id)
|
||||
for x in Account.query.filter(Account.id.in_(in_use))
|
||||
.order_by(Account.base_code, Account.no).all()]
|
||||
|
||||
|
||||
def _populate_entries(entries: list[Entry]) -> None:
|
||||
"""Populates the ledger entries with relative data.
|
||||
|
||||
:param entries: The ledger entries.
|
||||
:return: None.
|
||||
"""
|
||||
transactions: dict[int, Transaction] \
|
||||
= {x.id: x for x in Transaction.query.filter(
|
||||
Transaction.id.in_({x.entry.transaction_id for x in entries
|
||||
if x.entry is not None}))}
|
||||
for entry in entries:
|
||||
if entry.entry is not None:
|
||||
entry.transaction = transactions[entry.entry.transaction_id]
|
||||
entry.date = entry.transaction.date
|
||||
entry.note = entry.transaction.note
|
||||
|
||||
|
||||
class Ledger(BaseReport):
|
||||
"""The ledger."""
|
||||
|
||||
def __init__(self, currency: Currency, account: Account, period: Period):
|
||||
"""Constructs a ledger.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
"""
|
||||
self.__currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.__account: Account = account
|
||||
"""The account."""
|
||||
self.__period: Period = period
|
||||
"""The period."""
|
||||
collector: EntryCollector = EntryCollector(
|
||||
self.__currency, self.__account, self.__period)
|
||||
self.__brought_forward: Entry | None = collector.brought_forward
|
||||
"""The brought-forward entry."""
|
||||
self.__entries: list[Entry] = collector.entries
|
||||
"""The ledger entries."""
|
||||
self.__total: Entry | None = collector.total
|
||||
"""The total entry."""
|
||||
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
filename: str = "ledger-{currency}-{account}-{period}.csv"\
|
||||
.format(currency=self.__currency.code, account=self.__account.code,
|
||||
period=self.__period.spec)
|
||||
return csv_download(filename, self.__get_csv_rows())
|
||||
|
||||
def __get_csv_rows(self) -> list[CSVRow]:
|
||||
"""Composes and returns the CSV rows.
|
||||
|
||||
:return: The CSV rows.
|
||||
"""
|
||||
_populate_entries(self.__entries)
|
||||
rows: list[CSVRow] = [CSVRow(gettext("Date"), gettext("Summary"),
|
||||
gettext("Debit"), gettext("Credit"),
|
||||
gettext("Balance"), gettext("Note"))]
|
||||
if self.__brought_forward is not None:
|
||||
rows.append(CSVRow(self.__brought_forward.date,
|
||||
self.__brought_forward.summary,
|
||||
self.__brought_forward.debit,
|
||||
self.__brought_forward.credit,
|
||||
self.__brought_forward.balance,
|
||||
None))
|
||||
rows.extend([CSVRow(x.date, x.summary,
|
||||
x.debit, x.credit, x.balance, x.note)
|
||||
for x in self.__entries])
|
||||
if self.__total is not None:
|
||||
rows.append(CSVRow(gettext("Total"), None,
|
||||
self.__total.debit, self.__total.credit,
|
||||
self.__total.balance, None))
|
||||
return rows
|
||||
|
||||
def html(self) -> str:
|
||||
"""Composes and returns the report as HTML.
|
||||
|
||||
:return: The report as HTML.
|
||||
"""
|
||||
all_entries: list[Entry] = []
|
||||
if self.__brought_forward is not None:
|
||||
all_entries.append(self.__brought_forward)
|
||||
all_entries.extend(self.__entries)
|
||||
if self.__total is not None:
|
||||
all_entries.append(self.__total)
|
||||
pagination: Pagination[Entry] = Pagination[Entry](all_entries)
|
||||
page_entries: list[Entry] = pagination.list
|
||||
has_data: bool = len(page_entries) > 0
|
||||
_populate_entries(page_entries)
|
||||
brought_forward: Entry | None = None
|
||||
if len(page_entries) > 0 and page_entries[0].is_brought_forward:
|
||||
brought_forward = page_entries[0]
|
||||
page_entries = page_entries[1:]
|
||||
total: Entry | None = None
|
||||
if len(page_entries) > 0 and page_entries[-1].is_total:
|
||||
total = page_entries[-1]
|
||||
page_entries = page_entries[:-1]
|
||||
params: LedgerPageParams = LedgerPageParams(
|
||||
currency=self.__currency,
|
||||
account=self.__account,
|
||||
period=self.__period,
|
||||
has_data=has_data,
|
||||
pagination=pagination,
|
||||
brought_forward=brought_forward,
|
||||
entries=page_entries,
|
||||
total=total)
|
||||
return render_template("accounting/report/ledger.html",
|
||||
report=params)
|
299
src/accounting/report/reports/search.py
Normal file
299
src/accounting/report/reports/search.py
Normal file
@ -0,0 +1,299 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/8
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The search.
|
||||
|
||||
"""
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import Response, render_template, request
|
||||
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency, CurrencyL10n, Account, AccountL10n, \
|
||||
Transaction, JournalEntry
|
||||
from accounting.utils.pagination import Pagination
|
||||
from accounting.utils.query import parse_query_keywords
|
||||
from .utils.base_report import BaseReport
|
||||
from .utils.csv_export import BaseCSVRow, csv_download
|
||||
from .utils.page_params import PageParams
|
||||
from .utils.report_chooser import ReportChooser
|
||||
from .utils.report_type import ReportType
|
||||
|
||||
|
||||
class Entry:
|
||||
"""An entry in the search result."""
|
||||
|
||||
def __init__(self, entry: JournalEntry | None = None):
|
||||
"""Constructs the entry in the search result.
|
||||
|
||||
:param entry: The journal entry.
|
||||
"""
|
||||
self.entry: JournalEntry | None = None
|
||||
"""The journal entry."""
|
||||
self.transaction: Transaction | None = None
|
||||
"""The transaction."""
|
||||
self.is_total: bool = False
|
||||
"""Whether this is the total entry."""
|
||||
self.currency: Currency | None = None
|
||||
"""The account."""
|
||||
self.account: Account | None = None
|
||||
"""The account."""
|
||||
self.summary: str | None = None
|
||||
"""The summary."""
|
||||
self.debit: Decimal | None = None
|
||||
"""The debit amount."""
|
||||
self.credit: Decimal | None = None
|
||||
"""The credit amount."""
|
||||
self.amount: Decimal | None = None
|
||||
"""The amount."""
|
||||
if entry is not None:
|
||||
self.entry = entry
|
||||
self.summary = entry.summary
|
||||
self.debit = entry.amount if entry.is_debit else None
|
||||
self.credit = None if entry.is_debit else entry.amount
|
||||
self.amount = entry.amount
|
||||
|
||||
|
||||
class CSVRow(BaseCSVRow):
|
||||
"""A row in the CSV search result."""
|
||||
|
||||
def __init__(self, txn_date: str | date,
|
||||
currency: str,
|
||||
account: str,
|
||||
summary: str | None,
|
||||
debit: str | Decimal | None,
|
||||
credit: str | Decimal | None,
|
||||
note: str | None):
|
||||
"""Constructs a row in the CSV search result.
|
||||
|
||||
:param txn_date: The transaction date.
|
||||
:param summary: The summary.
|
||||
:param debit: The debit amount.
|
||||
:param credit: The credit amount.
|
||||
:param note: The note.
|
||||
"""
|
||||
self.date: str | date = txn_date
|
||||
"""The date."""
|
||||
self.currency: str = currency
|
||||
"""The currency."""
|
||||
self.account: str = account
|
||||
"""The account."""
|
||||
self.summary: str | None = summary
|
||||
"""The summary."""
|
||||
self.debit: str | Decimal | None = debit
|
||||
"""The debit amount."""
|
||||
self.credit: str | Decimal | None = credit
|
||||
"""The credit amount."""
|
||||
self.note: str | None = note
|
||||
"""The note."""
|
||||
|
||||
@property
|
||||
def values(self) -> list[str | Decimal | None]:
|
||||
"""Returns the values of the row.
|
||||
|
||||
:return: The values of the row.
|
||||
"""
|
||||
return [self.date, self.currency, self.account, self.summary,
|
||||
self.debit, self.credit, self.note]
|
||||
|
||||
|
||||
class SearchPageParams(PageParams):
|
||||
"""The HTML parameters of the search result."""
|
||||
|
||||
def __init__(self, pagination: Pagination[Entry],
|
||||
entries: list[Entry]):
|
||||
"""Constructs the HTML parameters of the search result.
|
||||
|
||||
:param entries: The search result entries.
|
||||
"""
|
||||
self.pagination: Pagination[Entry] = pagination
|
||||
"""The pagination."""
|
||||
self.entries: list[Entry] = entries
|
||||
"""The entries."""
|
||||
|
||||
@property
|
||||
def has_data(self) -> bool:
|
||||
"""Returns whether there is any data on the page.
|
||||
|
||||
:return: True if there is any data, or False otherwise.
|
||||
"""
|
||||
return len(self.entries) > 0
|
||||
|
||||
@property
|
||||
def report_chooser(self) -> ReportChooser:
|
||||
"""Returns the report chooser.
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
return ReportChooser(ReportType.SEARCH)
|
||||
|
||||
|
||||
def _populate_entries(entries: list[Entry]) -> None:
|
||||
"""Populates the search result entries with relative data.
|
||||
|
||||
:param entries: The search result entries.
|
||||
:return: None.
|
||||
"""
|
||||
transactions: dict[int, Transaction] \
|
||||
= {x.id: x for x in Transaction.query.filter(
|
||||
Transaction.id.in_({x.entry.transaction_id for x in entries}))}
|
||||
accounts: dict[int, Account] \
|
||||
= {x.id: x for x in Account.query.filter(
|
||||
Account.id.in_({x.entry.account_id for x in entries}))}
|
||||
currencies: dict[int, Currency] \
|
||||
= {x.code: x for x in Currency.query.filter(
|
||||
Currency.code.in_({x.entry.currency_code for x in entries}))}
|
||||
for entry in entries:
|
||||
entry.transaction = transactions[entry.entry.transaction_id]
|
||||
entry.account = accounts[entry.entry.account_id]
|
||||
entry.currency = currencies[entry.entry.currency_code]
|
||||
|
||||
|
||||
class Search(BaseReport):
|
||||
"""The search."""
|
||||
|
||||
def __init__(self):
|
||||
"""Constructs a search."""
|
||||
"""The account."""
|
||||
self.__entries: list[Entry] = self.__query_entries()
|
||||
"""The journal entries."""
|
||||
|
||||
def __query_entries(self) -> list[Entry]:
|
||||
"""Queries and returns the journal entries.
|
||||
|
||||
:return: The journal entries.
|
||||
"""
|
||||
keywords: list[str] = parse_query_keywords(request.args.get("q"))
|
||||
if len(keywords) == 0:
|
||||
return []
|
||||
conditions: list[sa.BinaryExpression] = []
|
||||
for k in keywords:
|
||||
conditions.append(sa.or_(
|
||||
JournalEntry.summary.contains(k),
|
||||
sa.cast(JournalEntry.amount, sa.String).contains(k),
|
||||
JournalEntry.account_id.in_(self.__get_account_condition(k)),
|
||||
JournalEntry.currency_code.in_(
|
||||
self.__get_currency_condition(k)),
|
||||
JournalEntry.transaction_id.in_(
|
||||
self.__get_transaction_condition(k))))
|
||||
return [Entry(x) for x in JournalEntry.query.filter(*conditions)]
|
||||
|
||||
@staticmethod
|
||||
def __get_account_condition(k: str) -> sa.Select:
|
||||
"""Composes and returns the condition to filter the account.
|
||||
|
||||
:param k: The keyword.
|
||||
:return: The condition to filter the account.
|
||||
"""
|
||||
code: sa.BinaryExpression = Account.base_code + "-" \
|
||||
+ sa.func.substr("000" + sa.cast(Account.no, sa.String),
|
||||
sa.func.char_length(sa.cast(Account.no,
|
||||
sa.String)) + 1)
|
||||
select_l10n: sa.Select = sa.select(AccountL10n.account_id)\
|
||||
.filter(AccountL10n.title.contains(k))
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [Account.base_code.contains(k),
|
||||
Account.title_l10n.contains(k),
|
||||
code.contains(k),
|
||||
Account.id.in_(select_l10n)]
|
||||
if k in gettext("Pay-off needed"):
|
||||
conditions.append(Account.is_pay_off_needed)
|
||||
return sa.select(Account.id).filter(sa.or_(*conditions))
|
||||
|
||||
@staticmethod
|
||||
def __get_currency_condition(k: str) -> sa.Select:
|
||||
"""Composes and returns the condition to filter the currency.
|
||||
|
||||
:param k: The keyword.
|
||||
:return: The condition to filter the currency.
|
||||
"""
|
||||
select_l10n: sa.Select = sa.select(CurrencyL10n.currency_code)\
|
||||
.filter(CurrencyL10n.name.contains(k))
|
||||
return sa.select(Currency.code).filter(
|
||||
sa.or_(Currency.code.contains(k),
|
||||
Currency.name_l10n.contains(k),
|
||||
Currency.code.in_(select_l10n)))
|
||||
|
||||
@staticmethod
|
||||
def __get_transaction_condition(k: str) -> sa.Select:
|
||||
"""Composes and returns the condition to filter the transaction.
|
||||
|
||||
:param k: The keyword.
|
||||
:return: The condition to filter the transaction.
|
||||
"""
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [Transaction.note.contains(k)]
|
||||
txn_date: datetime
|
||||
try:
|
||||
txn_date = datetime.strptime(k, "%Y")
|
||||
conditions.append(
|
||||
sa.extract("year", Transaction.date) == txn_date.year)
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
txn_date = datetime.strptime(k, "%Y/%m")
|
||||
conditions.append(sa.and_(
|
||||
sa.extract("year", Transaction.date) == txn_date.year,
|
||||
sa.extract("month", Transaction.date) == txn_date.month))
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
txn_date = datetime.strptime(f"2000/{k}", "%Y/%m/%d")
|
||||
conditions.append(sa.and_(
|
||||
sa.extract("month", Transaction.date) == txn_date.month,
|
||||
sa.extract("day", Transaction.date) == txn_date.day))
|
||||
except ValueError:
|
||||
pass
|
||||
return sa.select(Transaction.id).filter(sa.or_(*conditions))
|
||||
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
filename: str = "search-{q}.csv".format(q=request.args["q"])
|
||||
return csv_download(filename, self.__get_csv_rows())
|
||||
|
||||
def __get_csv_rows(self) -> list[CSVRow]:
|
||||
"""Composes and returns the CSV rows.
|
||||
|
||||
:return: The CSV rows.
|
||||
"""
|
||||
_populate_entries(self.__entries)
|
||||
rows: list[CSVRow] = [CSVRow(gettext("Date"), gettext("Currency"),
|
||||
gettext("Account"), gettext("Summary"),
|
||||
gettext("Debit"), gettext("Credit"),
|
||||
gettext("Note"))]
|
||||
rows.extend([CSVRow(x.transaction.date, x.currency.code,
|
||||
str(x.account).title(), x.summary,
|
||||
x.debit, x.credit, x.transaction.note)
|
||||
for x in self.__entries])
|
||||
return rows
|
||||
|
||||
def html(self) -> str:
|
||||
"""Composes and returns the report as HTML.
|
||||
|
||||
:return: The report as HTML.
|
||||
"""
|
||||
pagination: Pagination[Entry] = Pagination[Entry](self.__entries)
|
||||
page_entries: list[Entry] = pagination.list
|
||||
_populate_entries(page_entries)
|
||||
params: SearchPageParams = SearchPageParams(pagination=pagination,
|
||||
entries=page_entries)
|
||||
return render_template("accounting/report/search.html",
|
||||
report=params)
|
264
src/accounting/report/reports/trial_balance.py
Normal file
264
src/accounting/report/reports/trial_balance.py
Normal file
@ -0,0 +1,264 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The trial balance.
|
||||
|
||||
"""
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import url_for, Response, render_template
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency, Account, Transaction, JournalEntry
|
||||
from accounting.report.period import Period
|
||||
from .utils.base_report import BaseReport
|
||||
from .utils.csv_export import BaseCSVRow, csv_download
|
||||
from .utils.option_link import OptionLink
|
||||
from .utils.page_params import PageParams
|
||||
from .utils.period_choosers import TrialBalancePeriodChooser
|
||||
from .utils.report_chooser import ReportChooser
|
||||
from .utils.report_type import ReportType
|
||||
|
||||
|
||||
class TrialBalanceAccount:
|
||||
"""An account in the trial balance."""
|
||||
|
||||
def __init__(self, account: Account, amount: Decimal, url: str):
|
||||
"""Constructs an account in the trial balance.
|
||||
|
||||
:param account: The account.
|
||||
:param amount: The amount.
|
||||
:param url: The URL to the ledger of the account.
|
||||
"""
|
||||
self.account: Account = account
|
||||
"""The account."""
|
||||
self.debit: Decimal | None = amount if amount > 0 else None
|
||||
"""The debit amount."""
|
||||
self.credit: Decimal | None = -amount if amount < 0 else None
|
||||
"""The credit amount."""
|
||||
self.url: str = url
|
||||
"""The URL to the ledger of the account."""
|
||||
|
||||
|
||||
class TrialBalanceTotal:
|
||||
"""The total in the trial balance."""
|
||||
|
||||
def __init__(self, debit: Decimal, credit: Decimal):
|
||||
"""Constructs the total in the trial balance.
|
||||
|
||||
:param debit: The debit amount.
|
||||
:param credit: The credit amount.
|
||||
"""
|
||||
self.debit: Decimal | None = debit
|
||||
"""The debit amount."""
|
||||
self.credit: Decimal | None = credit
|
||||
"""The credit amount."""
|
||||
|
||||
|
||||
class CSVRow(BaseCSVRow):
|
||||
"""A row in the CSV trial balance."""
|
||||
|
||||
def __init__(self, text: str | None,
|
||||
debit: str | Decimal | None,
|
||||
credit: str | Decimal | None):
|
||||
"""Constructs a row in the CSV trial balance.
|
||||
|
||||
:param text: The text.
|
||||
:param debit: The debit amount.
|
||||
:param credit: The credit amount.
|
||||
"""
|
||||
self.text: str | None = text
|
||||
"""The text."""
|
||||
self.debit: str | Decimal | None = debit
|
||||
"""The debit amount."""
|
||||
self.credit: str | Decimal | None = credit
|
||||
"""The credit amount."""
|
||||
|
||||
@property
|
||||
def values(self) -> list[str | Decimal | None]:
|
||||
"""Returns the values of the row.
|
||||
|
||||
:return: The values of the row.
|
||||
"""
|
||||
return [self.text, self.debit, self.credit]
|
||||
|
||||
|
||||
class TrialBalancePageParams(PageParams):
|
||||
"""The HTML parameters of the trial balance."""
|
||||
|
||||
def __init__(self, currency: Currency,
|
||||
period: Period,
|
||||
accounts: list[TrialBalanceAccount],
|
||||
total: TrialBalanceTotal):
|
||||
"""Constructs the HTML parameters of the trial balance.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:param accounts: The accounts in the trial balance.
|
||||
:param total: The total of the trial balance.
|
||||
"""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.period: Period = period
|
||||
"""The period."""
|
||||
self.accounts: list[TrialBalanceAccount] = accounts
|
||||
"""The accounts in the trial balance."""
|
||||
self.total: TrialBalanceTotal = total
|
||||
"""The total of the trial balance."""
|
||||
self.period_chooser: TrialBalancePeriodChooser \
|
||||
= TrialBalancePeriodChooser(currency)
|
||||
"""The period chooser."""
|
||||
|
||||
@property
|
||||
def has_data(self) -> bool:
|
||||
"""Returns whether there is any data on the page.
|
||||
|
||||
:return: True if there is any data, or False otherwise.
|
||||
"""
|
||||
return len(self.accounts) > 0
|
||||
|
||||
@property
|
||||
def report_chooser(self) -> ReportChooser:
|
||||
"""Returns the report chooser.
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
return ReportChooser(ReportType.TRIAL_BALANCE,
|
||||
currency=self.currency,
|
||||
period=self.period)
|
||||
|
||||
@property
|
||||
def currency_options(self) -> list[OptionLink]:
|
||||
"""Returns the currency options.
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
def get_url(currency: Currency):
|
||||
if self.period.is_default:
|
||||
return url_for("accounting.report.trial-balance-default",
|
||||
currency=currency)
|
||||
return url_for("accounting.report.trial-balance",
|
||||
currency=currency, period=self.period)
|
||||
|
||||
in_use: set[str] = set(db.session.scalars(
|
||||
sa.select(JournalEntry.currency_code)
|
||||
.group_by(JournalEntry.currency_code)).all())
|
||||
return [OptionLink(str(x), get_url(x), x.code == self.currency.code)
|
||||
for x in Currency.query.filter(Currency.code.in_(in_use))
|
||||
.order_by(Currency.code).all()]
|
||||
|
||||
|
||||
class TrialBalance(BaseReport):
|
||||
"""The trial balance."""
|
||||
|
||||
def __init__(self, currency: Currency, period: Period):
|
||||
"""Constructs a trial balance.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
"""
|
||||
self.__currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.__period: Period = period
|
||||
"""The period."""
|
||||
self.__accounts: list[TrialBalanceAccount]
|
||||
"""The accounts in the trial balance."""
|
||||
self.__total: TrialBalanceTotal
|
||||
"""The total of the trial balance."""
|
||||
self.__set_data()
|
||||
|
||||
def __set_data(self) -> None:
|
||||
"""Queries and sets data sections in the trial balance.
|
||||
|
||||
:return: None.
|
||||
"""
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.currency_code == self.__currency.code]
|
||||
if self.__period.start is not None:
|
||||
conditions.append(Transaction.date >= self.__period.start)
|
||||
if self.__period.end is not None:
|
||||
conditions.append(Transaction.date <= self.__period.end)
|
||||
balance_func: sa.Function = sa.func.sum(sa.case(
|
||||
(JournalEntry.is_debit, JournalEntry.amount),
|
||||
else_=-JournalEntry.amount)).label("balance")
|
||||
select_balances: sa.Select \
|
||||
= sa.select(Account.id, balance_func)\
|
||||
.join(Transaction).join(Account)\
|
||||
.filter(*conditions)\
|
||||
.group_by(JournalEntry.account_id)\
|
||||
.order_by(Account.base_code, Account.no)
|
||||
balances: list[sa.Row] = db.session.execute(select_balances).all()
|
||||
accounts: dict[int, Account] \
|
||||
= {x.id: x for x in Account.query
|
||||
.filter(Account.id.in_([x.id for x in balances])).all()}
|
||||
|
||||
def get_url(account: Account) -> str:
|
||||
"""Returns the ledger URL of an account.
|
||||
|
||||
:param account: The account.
|
||||
:return: The ledger URL of the account.
|
||||
"""
|
||||
if self.__period.is_default:
|
||||
return url_for("accounting.report.ledger-default",
|
||||
currency=self.__currency, account=account)
|
||||
return url_for("accounting.report.ledger",
|
||||
currency=self.__currency, account=account,
|
||||
period=self.__period)
|
||||
|
||||
self.__accounts = [TrialBalanceAccount(account=accounts[x.id],
|
||||
amount=x.balance,
|
||||
url=get_url(accounts[x.id]))
|
||||
for x in balances]
|
||||
self.__total = TrialBalanceTotal(
|
||||
sum([x.debit for x in self.__accounts if x.debit is not None]),
|
||||
sum([x.credit for x in self.__accounts if x.credit is not None]))
|
||||
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
filename: str = "trial-balance-{currency}-{period}.csv"\
|
||||
.format(currency=self.__currency.code, period=self.__period.spec)
|
||||
return csv_download(filename, self.__get_csv_rows())
|
||||
|
||||
def __get_csv_rows(self) -> list[CSVRow]:
|
||||
"""Composes and returns the CSV rows.
|
||||
|
||||
:return: The CSV rows.
|
||||
"""
|
||||
rows: list[CSVRow] = [CSVRow(gettext("Account"), gettext("Debit"),
|
||||
gettext("Credit"))]
|
||||
rows.extend([CSVRow(str(x.account).title(), x.debit, x.credit)
|
||||
for x in self.__accounts])
|
||||
rows.append(CSVRow(gettext("Total"), self.__total.debit,
|
||||
self.__total.credit))
|
||||
return rows
|
||||
|
||||
def html(self) -> str:
|
||||
"""Composes and returns the report as HTML.
|
||||
|
||||
:return: The report as HTML.
|
||||
"""
|
||||
params: TrialBalancePageParams = TrialBalancePageParams(
|
||||
currency=self.__currency,
|
||||
period=self.__period,
|
||||
accounts=self.__accounts,
|
||||
total=self.__total)
|
||||
return render_template("accounting/report/trial-balance.html",
|
||||
report=params)
|
19
src/accounting/report/reports/utils/__init__.py
Normal file
19
src/accounting/report/reports/utils/__init__.py
Normal file
@ -0,0 +1,19 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The utilities to generate reports.
|
||||
|
||||
"""
|
40
src/accounting/report/reports/utils/base_report.py
Normal file
40
src/accounting/report/reports/utils/base_report.py
Normal file
@ -0,0 +1,40 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/8
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The base report.
|
||||
|
||||
"""
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from flask import Response
|
||||
|
||||
|
||||
class BaseReport(ABC):
|
||||
"""The base report class."""
|
||||
|
||||
@abstractmethod
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def html(self) -> str:
|
||||
"""Composes and returns the report as HTML.
|
||||
|
||||
:return: The report as HTML.
|
||||
"""
|
54
src/accounting/report/reports/utils/csv_export.py
Normal file
54
src/accounting/report/reports/utils/csv_export.py
Normal file
@ -0,0 +1,54 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The utility to export the report as CSV for download.
|
||||
|
||||
"""
|
||||
import csv
|
||||
from abc import ABC, abstractmethod
|
||||
from decimal import Decimal
|
||||
from io import StringIO
|
||||
|
||||
from flask import Response
|
||||
|
||||
|
||||
class BaseCSVRow(ABC):
|
||||
"""The base CSV row."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def values(self) -> list[str | Decimal | None]:
|
||||
"""Returns the values of the row.
|
||||
|
||||
:return: The values of the row.
|
||||
"""
|
||||
|
||||
|
||||
def csv_download(filename: str, rows: list[BaseCSVRow]) -> Response:
|
||||
"""Exports the data rows as a CSV file for download.
|
||||
|
||||
:param filename: The download file name.
|
||||
:param rows: The data rows.
|
||||
:return: The response for download the CSV file.
|
||||
"""
|
||||
with StringIO() as fp:
|
||||
writer = csv.writer(fp)
|
||||
writer.writerows([x.values for x in rows])
|
||||
fp.seek(0)
|
||||
response: Response = Response(fp.read(), mimetype="text/csv")
|
||||
response.headers["Content-Disposition"] \
|
||||
= f"attachment; filename={filename}"
|
||||
return response
|
34
src/accounting/report/reports/utils/option_link.py
Normal file
34
src/accounting/report/reports/utils/option_link.py
Normal file
@ -0,0 +1,34 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/5
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The option link.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class OptionLink:
|
||||
"""An option link."""
|
||||
|
||||
def __init__(self, title: str, url: str, is_active: bool):
|
||||
"""Constructs an option link.
|
||||
|
||||
:param title: The title.
|
||||
:param url: The URI.
|
||||
:param is_active: True if active, or False otherwise
|
||||
"""
|
||||
self.title: str = title
|
||||
self.url: str = url
|
||||
self.is_active: bool = is_active
|
68
src/accounting/report/reports/utils/page_params.py
Normal file
68
src/accounting/report/reports/utils/page_params.py
Normal file
@ -0,0 +1,68 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/6
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The page parameters of a report.
|
||||
|
||||
"""
|
||||
import typing as t
|
||||
from abc import ABC, abstractmethod
|
||||
from urllib.parse import urlparse, ParseResult, parse_qsl, urlencode, \
|
||||
urlunparse
|
||||
|
||||
from flask import request
|
||||
|
||||
from accounting.utils.txn_types import TransactionType
|
||||
from .report_chooser import ReportChooser
|
||||
|
||||
|
||||
class PageParams(ABC):
|
||||
"""The page parameters of a report."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def has_data(self) -> bool:
|
||||
"""Returns whether there is any data on the page.
|
||||
|
||||
:return: True if there is any data, or False otherwise.
|
||||
"""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def report_chooser(self) -> ReportChooser:
|
||||
"""Returns the report chooser.
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
|
||||
@property
|
||||
def txn_types(self) -> t.Type[TransactionType]:
|
||||
"""Returns the transaction types.
|
||||
|
||||
:return: The transaction types.
|
||||
"""
|
||||
return TransactionType
|
||||
|
||||
@property
|
||||
def csv_uri(self) -> str:
|
||||
uri: str = request.full_path if request.query_string \
|
||||
else request.path
|
||||
uri_p: ParseResult = urlparse(uri)
|
||||
params: list[tuple[str, str]] = parse_qsl(uri_p.query)
|
||||
params = [x for x in params if x[0] != "as"]
|
||||
params.append(("as", "csv"))
|
||||
parts: list[str] = list(uri_p)
|
||||
parts[4] = urlencode(params)
|
||||
return urlunparse(parts)
|
220
src/accounting/report/reports/utils/period_choosers.py
Normal file
220
src/accounting/report/reports/utils/period_choosers.py
Normal file
@ -0,0 +1,220 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/4
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The period choosers.
|
||||
|
||||
This file is largely taken from the NanoParma ERP project, first written in
|
||||
2021/9/16 by imacat (imacat@nanoparma.com).
|
||||
|
||||
"""
|
||||
import typing as t
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import date
|
||||
|
||||
from flask import url_for
|
||||
|
||||
from accounting.models import Currency, Account, Transaction
|
||||
from accounting.report.income_expense_account import IncomeExpensesAccount
|
||||
from accounting.report.period import YearPeriod, Period, ThisMonth, \
|
||||
LastMonth, SinceLastMonth, ThisYear, LastYear, Today, Yesterday, \
|
||||
TemplatePeriod
|
||||
|
||||
|
||||
class PeriodChooser(ABC):
|
||||
"""The period chooser."""
|
||||
|
||||
def __init__(self, start: date | None):
|
||||
"""Constructs a period chooser.
|
||||
|
||||
:param start: The start of the period.
|
||||
"""
|
||||
|
||||
# Shortcut periods
|
||||
self.this_month_url: str = self._url_for(ThisMonth())
|
||||
"""The URL for this month."""
|
||||
self.last_month_url: str = self._url_for(LastMonth())
|
||||
"""The URL for last month."""
|
||||
self.since_last_month_url: str = self._url_for(SinceLastMonth())
|
||||
"""The URL since last mint."""
|
||||
self.this_year_url: str = self._url_for(ThisYear())
|
||||
"""The URL for this year."""
|
||||
self.last_year_url: str = self._url_for(LastYear())
|
||||
"""The URL for last year."""
|
||||
self.today_url: str = self._url_for(Today())
|
||||
"""The URL for today."""
|
||||
self.yesterday_url: str = self._url_for(Yesterday())
|
||||
"""The URL for yesterday."""
|
||||
self.all_url: str = self._url_for(Period(None, None))
|
||||
"""The URL for all period."""
|
||||
self.url_template: str = self._url_for(TemplatePeriod())
|
||||
"""The URL template."""
|
||||
|
||||
# Attributes
|
||||
self.data_start: date | None = start
|
||||
"""The start of the data."""
|
||||
self.has_data: bool = start is not None
|
||||
"""Whether there is any data."""
|
||||
self.has_last_month: bool = False
|
||||
"""Where there is data in last month."""
|
||||
self.has_last_year: bool = False
|
||||
"""Whether there is data in last year."""
|
||||
self.has_yesterday: bool = False
|
||||
"""Whether there is data in yesterday."""
|
||||
self.available_years: t.Iterator[int] = []
|
||||
"""The available years."""
|
||||
|
||||
if self.has_data is not None:
|
||||
today: date = date.today()
|
||||
self.has_last_month = start < date(today.year, today.month, 1)
|
||||
self.has_last_year = start.year < today.year
|
||||
self.has_yesterday = start < today
|
||||
self.available_years: t.Iterator[int] = []
|
||||
if start.year < today.year - 1:
|
||||
self.available_years \
|
||||
= reversed(range(start.year, today.year - 1))
|
||||
|
||||
@abstractmethod
|
||||
def _url_for(self, period: Period) -> str:
|
||||
"""Returns the URL for a period.
|
||||
|
||||
:param period: The period.
|
||||
:return: The URL for the period.
|
||||
"""
|
||||
pass
|
||||
|
||||
def year_url(self, year: int) -> str:
|
||||
"""Returns the period URL of a year.
|
||||
|
||||
:param year: The year
|
||||
:return: The period URL of the year.
|
||||
"""
|
||||
return self._url_for(YearPeriod(year))
|
||||
|
||||
|
||||
class JournalPeriodChooser(PeriodChooser):
|
||||
"""The journal period chooser."""
|
||||
|
||||
def __init__(self):
|
||||
"""Constructs the journal period chooser."""
|
||||
first: Transaction | None \
|
||||
= Transaction.query.order_by(Transaction.date).first()
|
||||
super().__init__(None if first is None else first.date)
|
||||
|
||||
def _url_for(self, period: Period) -> str:
|
||||
if period.is_default:
|
||||
return url_for("accounting.report.journal-default")
|
||||
return url_for("accounting.report.journal", period=period)
|
||||
|
||||
|
||||
class LedgerPeriodChooser(PeriodChooser):
|
||||
"""The ledger period chooser."""
|
||||
|
||||
def __init__(self, currency: Currency, account: Account):
|
||||
"""Constructs the ledger period chooser."""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.account: Account = account
|
||||
"""The account."""
|
||||
first: Transaction | None \
|
||||
= Transaction.query.order_by(Transaction.date).first()
|
||||
super().__init__(None if first is None else first.date)
|
||||
|
||||
def _url_for(self, period: Period) -> str:
|
||||
if period.is_default:
|
||||
return url_for("accounting.report.ledger-default",
|
||||
currency=self.currency, account=self.account)
|
||||
return url_for("accounting.report.ledger",
|
||||
currency=self.currency, account=self.account,
|
||||
period=period)
|
||||
|
||||
|
||||
class IncomeExpensesPeriodChooser(PeriodChooser):
|
||||
"""The income and expenses period chooser."""
|
||||
|
||||
def __init__(self, currency: Currency, account: IncomeExpensesAccount):
|
||||
"""Constructs the income and expenses period chooser."""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
self.account: IncomeExpensesAccount = account
|
||||
"""The account."""
|
||||
first: Transaction | None \
|
||||
= Transaction.query.order_by(Transaction.date).first()
|
||||
super().__init__(None if first is None else first.date)
|
||||
|
||||
def _url_for(self, period: Period) -> str:
|
||||
if period.is_default:
|
||||
return url_for("accounting.report.income-expenses-default",
|
||||
currency=self.currency, account=self.account)
|
||||
return url_for("accounting.report.income-expenses",
|
||||
currency=self.currency, account=self.account,
|
||||
period=period)
|
||||
|
||||
|
||||
class TrialBalancePeriodChooser(PeriodChooser):
|
||||
"""The trial balance period chooser."""
|
||||
|
||||
def __init__(self, currency: Currency):
|
||||
"""Constructs the trial balance period chooser."""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
first: Transaction | None \
|
||||
= Transaction.query.order_by(Transaction.date).first()
|
||||
super().__init__(None if first is None else first.date)
|
||||
|
||||
def _url_for(self, period: Period) -> str:
|
||||
if period.is_default:
|
||||
return url_for("accounting.report.trial-balance-default",
|
||||
currency=self.currency)
|
||||
return url_for("accounting.report.trial-balance",
|
||||
currency=self.currency, period=period)
|
||||
|
||||
|
||||
class IncomeStatementPeriodChooser(PeriodChooser):
|
||||
"""The income statement period chooser."""
|
||||
|
||||
def __init__(self, currency: Currency):
|
||||
"""Constructs the income statement period chooser."""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
first: Transaction | None \
|
||||
= Transaction.query.order_by(Transaction.date).first()
|
||||
super().__init__(None if first is None else first.date)
|
||||
|
||||
def _url_for(self, period: Period) -> str:
|
||||
if period.is_default:
|
||||
return url_for("accounting.report.income-statement-default",
|
||||
currency=self.currency)
|
||||
return url_for("accounting.report.income-statement",
|
||||
currency=self.currency, period=period)
|
||||
|
||||
|
||||
class BalanceSheetPeriodChooser(PeriodChooser):
|
||||
"""The balance sheet period chooser."""
|
||||
|
||||
def __init__(self, currency: Currency):
|
||||
"""Constructs the balance sheet period chooser."""
|
||||
self.currency: Currency = currency
|
||||
"""The currency."""
|
||||
first: Transaction | None \
|
||||
= Transaction.query.order_by(Transaction.date).first()
|
||||
super().__init__(None if first is None else first.date)
|
||||
|
||||
def _url_for(self, period: Period) -> str:
|
||||
if period.is_default:
|
||||
return url_for("accounting.report.balance-sheet-default",
|
||||
currency=self.currency)
|
||||
return url_for("accounting.report.balance-sheet",
|
||||
currency=self.currency, period=period)
|
170
src/accounting/report/reports/utils/report_chooser.py
Normal file
170
src/accounting/report/reports/utils/report_chooser.py
Normal file
@ -0,0 +1,170 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/4
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The report chooser.
|
||||
|
||||
This file is largely taken from the NanoParma ERP project, first written in
|
||||
2021/9/16 by imacat (imacat@nanoparma.com).
|
||||
|
||||
"""
|
||||
import re
|
||||
import typing as t
|
||||
|
||||
from flask import url_for
|
||||
from flask_babel import LazyString
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency, Account
|
||||
from accounting.report.period import Period
|
||||
from accounting.template_globals import default_currency_code
|
||||
from .option_link import OptionLink
|
||||
from .report_type import ReportType
|
||||
|
||||
|
||||
class ReportChooser:
|
||||
"""The report chooser."""
|
||||
|
||||
def __init__(self, active_report: ReportType,
|
||||
period: Period | None = None,
|
||||
currency: Currency | None = None,
|
||||
account: Account | None = None):
|
||||
"""Constructs the report chooser.
|
||||
|
||||
:param active_report: The active report.
|
||||
:param period: The period.
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
"""
|
||||
self.__active_report: ReportType = active_report
|
||||
"""The currently active report."""
|
||||
self.__period: Period = Period.get_instance() if period is None \
|
||||
else period
|
||||
"""The period."""
|
||||
self.__currency: Currency = db.session.get(
|
||||
Currency, default_currency_code()) \
|
||||
if currency is None else currency
|
||||
"""The currency."""
|
||||
self.__account: Account = Account.find_by_code("1111-001") \
|
||||
if account is None else account
|
||||
"""The currency."""
|
||||
self.__reports: list[OptionLink] = []
|
||||
"""The links to the reports."""
|
||||
self.current_report: str | LazyString = ""
|
||||
"""The title of the current report."""
|
||||
self.__reports.append(self.__journal)
|
||||
self.__reports.append(self.__ledger)
|
||||
self.__reports.append(self.__income_expenses)
|
||||
self.__reports.append(self.__trial_balance)
|
||||
self.__reports.append(self.__income_statement)
|
||||
self.__reports.append(self.__balance_sheet)
|
||||
for report in self.__reports:
|
||||
if report.is_active:
|
||||
self.current_report = report.title
|
||||
|
||||
@property
|
||||
def __journal(self) -> OptionLink:
|
||||
"""Returns the journal.
|
||||
|
||||
:return: The journal.
|
||||
"""
|
||||
url: str = url_for("accounting.report.journal-default") \
|
||||
if self.__period.is_default \
|
||||
else url_for("accounting.report.journal", period=self.__period)
|
||||
return OptionLink(gettext("Journal"), url,
|
||||
self.__active_report == ReportType.JOURNAL)
|
||||
|
||||
@property
|
||||
def __ledger(self) -> OptionLink:
|
||||
"""Returns the ledger.
|
||||
|
||||
:return: The ledger.
|
||||
"""
|
||||
url: str = url_for("accounting.report.ledger-default",
|
||||
currency=self.__currency, account=self.__account) \
|
||||
if self.__period.is_default \
|
||||
else url_for("accounting.report.ledger",
|
||||
currency=self.__currency, account=self.__account,
|
||||
period=self.__period)
|
||||
return OptionLink(gettext("Ledger"), url,
|
||||
self.__active_report == ReportType.LEDGER)
|
||||
|
||||
@property
|
||||
def __income_expenses(self) -> OptionLink:
|
||||
"""Returns the income and expenses.
|
||||
|
||||
:return: The income and expenses.
|
||||
"""
|
||||
account: Account = self.__account
|
||||
if not re.match(r"[12][12]", account.base_code):
|
||||
account: Account = Account.find_by_code("1111-001")
|
||||
url: str = url_for("accounting.report.income-expenses-default",
|
||||
currency=self.__currency, account=account) \
|
||||
if self.__period.is_default \
|
||||
else url_for("accounting.report.income-expenses",
|
||||
currency=self.__currency, account=account,
|
||||
period=self.__period)
|
||||
return OptionLink(gettext("Income and Expenses"), url,
|
||||
self.__active_report == ReportType.INCOME_EXPENSES)
|
||||
|
||||
@property
|
||||
def __trial_balance(self) -> OptionLink:
|
||||
"""Returns the trial balance.
|
||||
|
||||
:return: The trial balance.
|
||||
"""
|
||||
url: str = url_for("accounting.report.trial-balance-default",
|
||||
currency=self.__currency) \
|
||||
if self.__period.is_default \
|
||||
else url_for("accounting.report.trial-balance",
|
||||
currency=self.__currency, period=self.__period)
|
||||
return OptionLink(gettext("Trial Balance"), url,
|
||||
self.__active_report == ReportType.TRIAL_BALANCE)
|
||||
|
||||
@property
|
||||
def __income_statement(self) -> OptionLink:
|
||||
"""Returns the income statement.
|
||||
|
||||
:return: The income statement.
|
||||
"""
|
||||
url: str = url_for("accounting.report.income-statement-default",
|
||||
currency=self.__currency) \
|
||||
if self.__period.is_default \
|
||||
else url_for("accounting.report.income-statement",
|
||||
currency=self.__currency, period=self.__period)
|
||||
return OptionLink(gettext("Income Statement"), url,
|
||||
self.__active_report == ReportType.INCOME_STATEMENT)
|
||||
|
||||
@property
|
||||
def __balance_sheet(self) -> OptionLink:
|
||||
"""Returns the balance sheet.
|
||||
|
||||
:return: The balance sheet.
|
||||
"""
|
||||
url: str = url_for("accounting.report.balance-sheet-default",
|
||||
currency=self.__currency) \
|
||||
if self.__period.is_default \
|
||||
else url_for("accounting.report.balance-sheet",
|
||||
currency=self.__currency, period=self.__period)
|
||||
return OptionLink(gettext("Balance Sheet"), url,
|
||||
self.__active_report == ReportType.BALANCE_SHEET)
|
||||
|
||||
def __iter__(self) -> t.Iterator[OptionLink]:
|
||||
"""Returns the iteration of the reports.
|
||||
|
||||
:return: The iteration of the reports.
|
||||
"""
|
||||
return iter(self.__reports)
|
38
src/accounting/report/reports/utils/report_type.py
Normal file
38
src/accounting/report/reports/utils/report_type.py
Normal file
@ -0,0 +1,38 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/4
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The report types.
|
||||
|
||||
"""
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ReportType(Enum):
|
||||
"""The report types."""
|
||||
JOURNAL: str = "journal"
|
||||
"""The journal."""
|
||||
LEDGER: str = "ledger"
|
||||
"""The ledger."""
|
||||
INCOME_EXPENSES: str = "income-expenses"
|
||||
"""The income and expenses."""
|
||||
TRIAL_BALANCE: str = "trial-balance"
|
||||
"""The trial balance."""
|
||||
INCOME_STATEMENT: str = "income-statement"
|
||||
"""The income statement."""
|
||||
BALANCE_SHEET: str = "balance-sheet"
|
||||
"""The balance sheet."""
|
||||
SEARCH: str = "search"
|
||||
"""The balance sheet."""
|
37
src/accounting/report/template_filters.py
Normal file
37
src/accounting/report/template_filters.py
Normal file
@ -0,0 +1,37 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The template filters for the reports.
|
||||
|
||||
"""
|
||||
from decimal import Decimal
|
||||
|
||||
from accounting.template_filters import format_amount as core_format_amount
|
||||
|
||||
|
||||
def format_amount(value: Decimal | None) -> str | None:
|
||||
"""Formats an amount for the report.
|
||||
|
||||
:param value: The amount.
|
||||
:return: The formatted amount text.
|
||||
"""
|
||||
if value is None:
|
||||
return ""
|
||||
is_negative: bool = value < 0
|
||||
formatted: str = core_format_amount(abs(value))
|
||||
if is_negative:
|
||||
formatted = f"({formatted})"
|
||||
return formatted
|
291
src/accounting/report/views.py
Normal file
291
src/accounting/report/views.py
Normal file
@ -0,0 +1,291 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/3
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The views for the report management.
|
||||
|
||||
"""
|
||||
from flask import Blueprint, request, Response
|
||||
|
||||
from accounting.models import Currency, Account
|
||||
from accounting.utils.permission import has_permission, can_view
|
||||
from .income_expense_account import IncomeExpensesAccount
|
||||
from .period import Period
|
||||
from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \
|
||||
IncomeStatement, BalanceSheet, Search
|
||||
from .template_filters import format_amount
|
||||
|
||||
bp: Blueprint = Blueprint("report", __name__)
|
||||
"""The view blueprint for the reports."""
|
||||
bp.add_app_template_filter(format_amount, "accounting_report_format_amount")
|
||||
|
||||
|
||||
@bp.get("journal", endpoint="journal-default")
|
||||
@has_permission(can_view)
|
||||
def get_default_journal_list() -> str | Response:
|
||||
"""Returns the journal in the default period.
|
||||
|
||||
:return: The journal in the default period.
|
||||
"""
|
||||
return __get_journal_list(Period.get_instance())
|
||||
|
||||
|
||||
@bp.get("journal/<period:period>", endpoint="journal")
|
||||
@has_permission(can_view)
|
||||
def get_journal_list(period: Period) -> str | Response:
|
||||
"""Returns the journal.
|
||||
|
||||
:param period: The period.
|
||||
:return: The journal in the period.
|
||||
"""
|
||||
return __get_journal_list(period)
|
||||
|
||||
|
||||
def __get_journal_list(period: Period) -> str | Response:
|
||||
"""Returns the journal.
|
||||
|
||||
:param period: The period.
|
||||
:return: The journal in the period.
|
||||
"""
|
||||
report: Journal = Journal(period)
|
||||
if "as" in request.args and request.args["as"] == "csv":
|
||||
return report.csv()
|
||||
return report.html()
|
||||
|
||||
|
||||
@bp.get("ledger/<currency:currency>/<account:account>",
|
||||
endpoint="ledger-default")
|
||||
@has_permission(can_view)
|
||||
def get_default_ledger_list(currency: Currency, account: Account) \
|
||||
-> str | Response:
|
||||
"""Returns the ledger in the default period.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:return: The ledger in the default period.
|
||||
"""
|
||||
return __get_ledger_list(currency, account, Period.get_instance())
|
||||
|
||||
|
||||
@bp.get("ledger/<currency:currency>/<account:account>/<period:period>",
|
||||
endpoint="ledger")
|
||||
@has_permission(can_view)
|
||||
def get_ledger_list(currency: Currency, account: Account, period: Period) \
|
||||
-> str | Response:
|
||||
"""Returns the ledger.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
:return: The ledger in the period.
|
||||
"""
|
||||
return __get_ledger_list(currency, account, period)
|
||||
|
||||
|
||||
def __get_ledger_list(currency: Currency, account: Account, period: Period) \
|
||||
-> str | Response:
|
||||
"""Returns the ledger.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
:return: The ledger in the period.
|
||||
"""
|
||||
report: Ledger = Ledger(currency, account, period)
|
||||
if "as" in request.args and request.args["as"] == "csv":
|
||||
return report.csv()
|
||||
return report.html()
|
||||
|
||||
|
||||
@bp.get("income-expenses/<currency:currency>/<ioAccount:account>",
|
||||
endpoint="income-expenses-default")
|
||||
@has_permission(can_view)
|
||||
def get_default_income_expenses_list(currency: Currency,
|
||||
account: IncomeExpensesAccount) \
|
||||
-> str | Response:
|
||||
"""Returns the income and expenses in the default period.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:return: The income and expenses in the default period.
|
||||
"""
|
||||
return __get_income_expenses_list(currency, account, Period.get_instance())
|
||||
|
||||
|
||||
@bp.get(
|
||||
"income-expenses/<currency:currency>/<ioAccount:account>/<period:period>",
|
||||
endpoint="income-expenses")
|
||||
@has_permission(can_view)
|
||||
def get_income_expenses_list(currency: Currency,
|
||||
account: IncomeExpensesAccount,
|
||||
period: Period) -> str | Response:
|
||||
"""Returns the income and expenses.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
:return: The income and expenses in the period.
|
||||
"""
|
||||
return __get_income_expenses_list(currency, account, period)
|
||||
|
||||
|
||||
def __get_income_expenses_list(currency: Currency,
|
||||
account: IncomeExpensesAccount,
|
||||
period: Period) -> str | Response:
|
||||
"""Returns the income and expenses.
|
||||
|
||||
:param currency: The currency.
|
||||
:param account: The account.
|
||||
:param period: The period.
|
||||
:return: The income and expenses in the period.
|
||||
"""
|
||||
report: IncomeExpenses = IncomeExpenses(currency, account, period)
|
||||
if "as" in request.args and request.args["as"] == "csv":
|
||||
return report.csv()
|
||||
return report.html()
|
||||
|
||||
|
||||
@bp.get("trial-balance/<currency:currency>",
|
||||
endpoint="trial-balance-default")
|
||||
@has_permission(can_view)
|
||||
def get_default_trial_balance_list(currency: Currency) -> str | Response:
|
||||
"""Returns the trial balance in the default period.
|
||||
|
||||
:param currency: The currency.
|
||||
:return: The trial balance in the default period.
|
||||
"""
|
||||
return __get_trial_balance_list(currency, Period.get_instance())
|
||||
|
||||
|
||||
@bp.get("trial-balance/<currency:currency>/<period:period>",
|
||||
endpoint="trial-balance")
|
||||
@has_permission(can_view)
|
||||
def get_trial_balance_list(currency: Currency, period: Period) \
|
||||
-> str | Response:
|
||||
"""Returns the trial balance.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:return: The trial balance in the period.
|
||||
"""
|
||||
return __get_trial_balance_list(currency, period)
|
||||
|
||||
|
||||
def __get_trial_balance_list(currency: Currency, period: Period) \
|
||||
-> str | Response:
|
||||
"""Returns the trial balance.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:return: The trial balance in the period.
|
||||
"""
|
||||
report: TrialBalance = TrialBalance(currency, period)
|
||||
if "as" in request.args and request.args["as"] == "csv":
|
||||
return report.csv()
|
||||
return report.html()
|
||||
|
||||
|
||||
@bp.get("income-statement/<currency:currency>",
|
||||
endpoint="income-statement-default")
|
||||
@has_permission(can_view)
|
||||
def get_default_income_statement_list(currency: Currency) -> str | Response:
|
||||
"""Returns the income statement in the default period.
|
||||
|
||||
:param currency: The currency.
|
||||
:return: The income statement in the default period.
|
||||
"""
|
||||
return __get_income_statement_list(currency, Period.get_instance())
|
||||
|
||||
|
||||
@bp.get("income-statement/<currency:currency>/<period:period>",
|
||||
endpoint="income-statement")
|
||||
@has_permission(can_view)
|
||||
def get_income_statement_list(currency: Currency, period: Period) \
|
||||
-> str | Response:
|
||||
"""Returns the income statement.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:return: The income statement in the period.
|
||||
"""
|
||||
return __get_income_statement_list(currency, period)
|
||||
|
||||
|
||||
def __get_income_statement_list(currency: Currency, period: Period) \
|
||||
-> str | Response:
|
||||
"""Returns the income statement.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:return: The income statement in the period.
|
||||
"""
|
||||
report: IncomeStatement = IncomeStatement(currency, period)
|
||||
if "as" in request.args and request.args["as"] == "csv":
|
||||
return report.csv()
|
||||
return report.html()
|
||||
|
||||
|
||||
@bp.get("balance-sheet/<currency:currency>",
|
||||
endpoint="balance-sheet-default")
|
||||
@has_permission(can_view)
|
||||
def get_default_balance_sheet_list(currency: Currency) -> str | Response:
|
||||
"""Returns the balance sheet in the default period.
|
||||
|
||||
:param currency: The currency.
|
||||
:return: The balance sheet in the default period.
|
||||
"""
|
||||
return __get_balance_sheet_list(currency, Period.get_instance())
|
||||
|
||||
|
||||
@bp.get("balance-sheet/<currency:currency>/<period:period>",
|
||||
endpoint="balance-sheet")
|
||||
@has_permission(can_view)
|
||||
def get_balance_sheet_list(currency: Currency, period: Period) \
|
||||
-> str | Response:
|
||||
"""Returns the balance sheet.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:return: The balance sheet in the period.
|
||||
"""
|
||||
return __get_balance_sheet_list(currency, period)
|
||||
|
||||
|
||||
def __get_balance_sheet_list(currency: Currency, period: Period) \
|
||||
-> str | Response:
|
||||
"""Returns the balance sheet.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:return: The balance sheet in the period.
|
||||
"""
|
||||
report: BalanceSheet = BalanceSheet(currency, period)
|
||||
if "as" in request.args and request.args["as"] == "csv":
|
||||
return report.csv()
|
||||
return report.html()
|
||||
|
||||
|
||||
@bp.get("search", endpoint="search")
|
||||
@has_permission(can_view)
|
||||
def search() -> str | Response:
|
||||
"""Returns the search result.
|
||||
|
||||
:return: The search result.
|
||||
"""
|
||||
report: Search = Search()
|
||||
if "as" in request.args and request.args["as"] == "csv":
|
||||
return report.csv()
|
||||
return report.html()
|
||||
|
@ -24,6 +24,9 @@
|
||||
.accounting-clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
.accounting-search-desktop-form {
|
||||
max-width: 16rem;
|
||||
}
|
||||
.btn-group .btn .accounting-search-input {
|
||||
min-height: calc(1em + .5rem + 2px);
|
||||
padding: 0 0.5rem;
|
||||
@ -58,6 +61,15 @@
|
||||
font-size: 1.4rem;
|
||||
color: #373b3e;
|
||||
}
|
||||
.accounting-sheet {
|
||||
padding: 2em 1.5em;
|
||||
margin: 1em;
|
||||
background-color: #F8F9FA;
|
||||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||
}
|
||||
.accounting-sheet h2 {
|
||||
border-bottom: thick double slategray;
|
||||
}
|
||||
|
||||
/** The option selector */
|
||||
.accounting-selector-list {
|
||||
@ -79,15 +91,6 @@
|
||||
.accounting-entry-control {
|
||||
border-color: transparent;
|
||||
}
|
||||
.accounting-transaction-card {
|
||||
padding: 2em 1.5em;
|
||||
margin: 1em;
|
||||
background-color: #F8F9FA;
|
||||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||
}
|
||||
.accounting-transaction-card h2 {
|
||||
border-bottom: thick double slategray;
|
||||
}
|
||||
.accounting-list-group-stripped .list-group-item:nth-child(2n+1) {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
@ -109,6 +112,134 @@
|
||||
border-top: thick double slategray;
|
||||
}
|
||||
|
||||
/* The report table */
|
||||
.accounting-report-table-header, .accounting-report-table-footer {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bolder;
|
||||
}
|
||||
.accounting-report-table-header {
|
||||
border-bottom: thin solid slategray;
|
||||
}
|
||||
.accounting-report-table-footer {
|
||||
font-style: italic;
|
||||
border-top: thin solid slategray;
|
||||
}
|
||||
.accounting-report-table-row {
|
||||
display: grid;
|
||||
}
|
||||
a.accounting-report-table-row {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
.accounting-report-table-row > div {
|
||||
padding: .5rem;
|
||||
}
|
||||
.accounting-report-table .accounting-amount {
|
||||
text-align: right;
|
||||
}
|
||||
.accounting-report-table-body .accounting-amount {
|
||||
font-style: italic;
|
||||
}
|
||||
.accounting-report-table-body .accounting-report-table-row:nth-child(2n+1) {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
.accounting-report-table-body .accounting-report-table-row:hover {
|
||||
background-color: rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
.accounting-journal-table .accounting-report-table-row {
|
||||
grid-template-columns: 1fr 1fr 2fr 4fr 1fr 1fr;
|
||||
}
|
||||
.accounting-ledger-table .accounting-report-table-row {
|
||||
grid-template-columns: 1fr 4fr 1fr 1fr 1fr;
|
||||
}
|
||||
.accounting-ledger-table .accounting-report-table-footer .accounting-report-table-row {
|
||||
grid-template-columns: 5fr 1fr 1fr 1fr;
|
||||
}
|
||||
.accounting-income-expenses-table .accounting-report-table-row {
|
||||
grid-template-columns: 1fr 2fr 4fr 1fr 1fr 1fr;
|
||||
}
|
||||
.accounting-income-expenses-table .accounting-report-table-footer .accounting-report-table-row {
|
||||
grid-template-columns: 7fr 1fr 1fr 1fr;
|
||||
}
|
||||
.accounting-trial-balance-table .accounting-report-table-header {
|
||||
border-bottom: thick double slategray;
|
||||
}
|
||||
.accounting-trial-balance-table .accounting-report-table-footer {
|
||||
border-top: thick double slategray;
|
||||
}
|
||||
.accounting-trial-balance-table .accounting-report-table-row {
|
||||
grid-template-columns: 3fr 1fr 1fr;
|
||||
}
|
||||
.accounting-income-statement-table .accounting-report-table-body {
|
||||
border-top: thick double slategray;
|
||||
border-bottom: thick double slategray;
|
||||
}
|
||||
.accounting-income-statement-table .accounting-report-table-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.accounting-income-statement-table .accounting-report-table-header .accounting-report-table-row {
|
||||
display: block;
|
||||
}
|
||||
.accounting-income-statement-section, .accounting-income-statement-total {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bolder;
|
||||
}
|
||||
.accounting-income-statement-subsection, .accounting-income-statement-subtotal {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.accounting-income-statement-subtotal {
|
||||
border-top: thin solid darkslategray;
|
||||
}
|
||||
/* Indents */
|
||||
.accounting-income-statement-subsection {
|
||||
margin-left: 0.5rem;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
.accounting-income-statement-account, .accounting-income-statement-subtotal {
|
||||
margin-left: 1rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
/* A visual blank line between categories */
|
||||
.accounting-income-statement-section {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
.accounting-income-statement-section:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
.accounting-income-statement-total {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
.accounting-income-statement-total:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.accounting-balance-sheet-section, .accounting-balance-sheet-total {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bolder;
|
||||
}
|
||||
.accounting-balance-sheet-section {
|
||||
border-bottom: thick double darkslategray;
|
||||
}
|
||||
.accounting-balance-sheet-total {
|
||||
border-top: thick double darkslategray;
|
||||
}
|
||||
.accounting-balance-sheet-subtotal {
|
||||
font-size: 1.1rem;
|
||||
font-weight: bolder;
|
||||
border-top: thick double darkslategray;
|
||||
}
|
||||
.accounting-balance-sheet-account {
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
.accounting-balance-sheet-total .accounting-amount, .accounting-balance-sheet-subtotal, .accounting-amount {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* The accounting report */
|
||||
.accounting-mobile-journal-credit {
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
/* The Material Design text field (floating form control in Bootstrap) */
|
||||
.accounting-material-text-field {
|
||||
position: relative;
|
||||
|
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
initializeBaseAccountSelector();
|
||||
document.getElementById("accounting-base-code")
|
||||
.onchange = validateBase;
|
||||
@ -44,23 +44,23 @@ function initializeBaseAccountSelector() {
|
||||
const baseContent = document.getElementById("accounting-base-content");
|
||||
const options = Array.from(document.getElementsByClassName("accounting-base-option"));
|
||||
const btnClear = document.getElementById("accounting-btn-clear-base");
|
||||
selector.addEventListener("show.bs.modal", function () {
|
||||
selector.addEventListener("show.bs.modal", () => {
|
||||
base.classList.add("accounting-not-empty");
|
||||
options.forEach(function (item) {
|
||||
item.classList.remove("active");
|
||||
});
|
||||
for (const option of options) {
|
||||
option.classList.remove("active");
|
||||
}
|
||||
const selected = document.getElementById("accounting-base-option-" + baseCode.value);
|
||||
if (selected !== null) {
|
||||
selected.classList.add("active");
|
||||
}
|
||||
});
|
||||
selector.addEventListener("hidden.bs.modal", function () {
|
||||
selector.addEventListener("hidden.bs.modal", () => {
|
||||
if (baseCode.value === "") {
|
||||
base.classList.remove("accounting-not-empty");
|
||||
}
|
||||
});
|
||||
options.forEach(function (option) {
|
||||
option.onclick = function () {
|
||||
for (const option of options) {
|
||||
option.onclick = () => {
|
||||
baseCode.value = option.dataset.code;
|
||||
baseContent.innerText = option.dataset.content;
|
||||
btnClear.classList.add("btn-danger");
|
||||
@ -69,8 +69,8 @@ function initializeBaseAccountSelector() {
|
||||
validateBase();
|
||||
bootstrap.Modal.getInstance(selector).hide();
|
||||
};
|
||||
});
|
||||
btnClear.onclick = function () {
|
||||
}
|
||||
btnClear.onclick = () => {
|
||||
baseCode.value = "";
|
||||
baseContent.innerText = "";
|
||||
btnClear.classList.add("btn-secondary")
|
||||
@ -92,17 +92,17 @@ function initializeBaseAccountQuery() {
|
||||
const optionList = document.getElementById("accounting-base-option-list");
|
||||
const options = Array.from(document.getElementsByClassName("accounting-base-option"));
|
||||
const queryNoResult = document.getElementById("accounting-base-option-no-result");
|
||||
query.addEventListener("input", function () {
|
||||
query.addEventListener("input", () => {
|
||||
if (query.value === "") {
|
||||
options.forEach(function (option) {
|
||||
for (const option of options) {
|
||||
option.classList.remove("d-none");
|
||||
});
|
||||
}
|
||||
optionList.classList.remove("d-none");
|
||||
queryNoResult.classList.add("d-none");
|
||||
return
|
||||
}
|
||||
let hasAnyMatched = false;
|
||||
options.forEach(function (option) {
|
||||
for (const option of options) {
|
||||
const queryValues = JSON.parse(option.dataset.queryValues);
|
||||
let isMatched = false;
|
||||
for (const queryValue of queryValues) {
|
||||
@ -117,7 +117,7 @@ function initializeBaseAccountQuery() {
|
||||
} else {
|
||||
option.classList.add("d-none");
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!hasAnyMatched) {
|
||||
optionList.classList.add("d-none");
|
||||
queryNoResult.classList.remove("d-none");
|
||||
|
@ -22,10 +22,10 @@
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const list = document.getElementById("accounting-order-list");
|
||||
if (list !== null) {
|
||||
const onReorder = function () {
|
||||
const onReorder = () => {
|
||||
const accounts = Array.from(list.children);
|
||||
for (let i = 0; i < accounts.length; i++) {
|
||||
const no = document.getElementById("accounting-order-" + accounts[i].dataset.id + "-no");
|
||||
|
249
src/accounting/static/js/account-selector.js
Normal file
249
src/accounting/static/js/account-selector.js
Normal file
@ -0,0 +1,249 @@
|
||||
/* The Mia! Accounting Flask Project
|
||||
* transaction-transfer-form.js: The JavaScript for the transfer transaction form
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2023 imacat.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
* First written: 2023/2/28
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
AccountSelector.initialize();
|
||||
});
|
||||
|
||||
/**
|
||||
* The account selector.
|
||||
*
|
||||
*/
|
||||
class AccountSelector {
|
||||
|
||||
/**
|
||||
* The entry type
|
||||
* @type {string}
|
||||
*/
|
||||
#entryType;
|
||||
|
||||
/**
|
||||
* The prefix of the HTML ID and class
|
||||
* @type {string}
|
||||
*/
|
||||
#prefix;
|
||||
|
||||
/**
|
||||
* Constructs an account selector.
|
||||
*
|
||||
* @param modal {HTMLFormElement} the account selector modal
|
||||
*/
|
||||
constructor(modal) {
|
||||
this.#entryType = modal.dataset.entryType;
|
||||
this.#prefix = "accounting-account-selector-" + modal.dataset.entryType;
|
||||
this.#init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the account selector.
|
||||
*
|
||||
*/
|
||||
#init() {
|
||||
const formAccountControl = document.getElementById("accounting-entry-form-account-control");
|
||||
const formAccount = document.getElementById("accounting-entry-form-account");
|
||||
const more = document.getElementById(this.#prefix + "-more");
|
||||
const btnClear = document.getElementById(this.#prefix + "-btn-clear");
|
||||
const options = Array.from(document.getElementsByClassName(this.#prefix + "-option"));
|
||||
more.onclick = () => {
|
||||
more.classList.add("d-none");
|
||||
this.#filterAccountOptions();
|
||||
};
|
||||
this.#initializeAccountQuery();
|
||||
btnClear.onclick = () => {
|
||||
formAccountControl.classList.remove("accounting-not-empty");
|
||||
formAccount.innerText = "";
|
||||
formAccount.dataset.code = "";
|
||||
formAccount.dataset.text = "";
|
||||
validateJournalEntryAccount();
|
||||
};
|
||||
for (const option of options) {
|
||||
option.onclick = () => {
|
||||
formAccountControl.classList.add("accounting-not-empty");
|
||||
formAccount.innerText = option.dataset.content;
|
||||
formAccount.dataset.code = option.dataset.code;
|
||||
formAccount.dataset.text = option.dataset.content;
|
||||
validateJournalEntryAccount();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the query on the account options.
|
||||
*
|
||||
*/
|
||||
#initializeAccountQuery() {
|
||||
const query = document.getElementById(this.#prefix + "-query");
|
||||
query.addEventListener("input", () => {
|
||||
this.#filterAccountOptions();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the account options.
|
||||
*
|
||||
*/
|
||||
#filterAccountOptions() {
|
||||
const query = document.getElementById(this.#prefix + "-query");
|
||||
const optionList = document.getElementById(this.#prefix + "-option-list");
|
||||
if (optionList === null) {
|
||||
console.log(this.#prefix + "-option-list");
|
||||
}
|
||||
const options = Array.from(document.getElementsByClassName(this.#prefix + "-option"));
|
||||
const more = document.getElementById(this.#prefix + "-more");
|
||||
const queryNoResult = document.getElementById(this.#prefix + "-option-no-result");
|
||||
const codesInUse = this.#getAccountCodeUsedInForm();
|
||||
let shouldAnyShow = false;
|
||||
for (const option of options) {
|
||||
const shouldShow = this.#shouldAccountOptionShow(option, more, codesInUse, query);
|
||||
if (shouldShow) {
|
||||
option.classList.remove("d-none");
|
||||
shouldAnyShow = true;
|
||||
} else {
|
||||
option.classList.add("d-none");
|
||||
}
|
||||
}
|
||||
if (!shouldAnyShow && more.classList.contains("d-none")) {
|
||||
optionList.classList.add("d-none");
|
||||
queryNoResult.classList.remove("d-none");
|
||||
} else {
|
||||
optionList.classList.remove("d-none");
|
||||
queryNoResult.classList.add("d-none");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the account codes that are used in the form.
|
||||
*
|
||||
* @return {string[]} the account codes that are used in the form
|
||||
*/
|
||||
#getAccountCodeUsedInForm() {
|
||||
const accountCodes = Array.from(document.getElementsByClassName("accounting-" + this.#prefix + "-account-code"));
|
||||
const formAccount = document.getElementById("accounting-entry-form-account");
|
||||
const inUse = [formAccount.dataset.code];
|
||||
for (const accountCode of accountCodes) {
|
||||
inUse.push(accountCode.value);
|
||||
}
|
||||
return inUse
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an account option should show.
|
||||
*
|
||||
* @param option {HTMLLIElement} the account option
|
||||
* @param more {HTMLLIElement} the more account element
|
||||
* @param inUse {string[]} the account codes that are used in the form
|
||||
* @param query {HTMLInputElement} the query element, if any
|
||||
* @return {boolean} true if the account option should show, or false otherwise
|
||||
*/
|
||||
#shouldAccountOptionShow(option, more, inUse, query) {
|
||||
const isQueryMatched = () => {
|
||||
if (query.value === "") {
|
||||
return true;
|
||||
}
|
||||
const queryValues = JSON.parse(option.dataset.queryValues);
|
||||
for (const queryValue of queryValues) {
|
||||
if (queryValue.includes(query.value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const isMoreMatched = () => {
|
||||
if (more.classList.contains("d-none")) {
|
||||
return true;
|
||||
}
|
||||
return option.classList.contains("accounting-account-in-use") || inUse.includes(option.dataset.code);
|
||||
};
|
||||
return isMoreMatched() && isQueryMatched();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the account selector when it is shown.
|
||||
*
|
||||
*/
|
||||
initShow() {
|
||||
const formAccount = document.getElementById("accounting-entry-form-account");
|
||||
const query = document.getElementById(this.#prefix + "-query")
|
||||
const more = document.getElementById(this.#prefix + "-more");
|
||||
const options = Array.from(document.getElementsByClassName(this.#prefix + "-option"));
|
||||
const btnClear = document.getElementById(this.#prefix + "-btn-clear");
|
||||
query.value = "";
|
||||
more.classList.remove("d-none");
|
||||
this.#filterAccountOptions();
|
||||
for (const option of options) {
|
||||
if (option.dataset.code === formAccount.dataset.code) {
|
||||
option.classList.add("active");
|
||||
} else {
|
||||
option.classList.remove("active");
|
||||
}
|
||||
}
|
||||
if (formAccount.dataset.code === "") {
|
||||
btnClear.classList.add("btn-secondary");
|
||||
btnClear.classList.remove("btn-danger");
|
||||
btnClear.disabled = true;
|
||||
} else {
|
||||
btnClear.classList.add("btn-danger");
|
||||
btnClear.classList.remove("btn-secondary");
|
||||
btnClear.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The account selectors.
|
||||
* @type {{debit: AccountSelector, credit: AccountSelector}}
|
||||
*/
|
||||
static #selectors = {}
|
||||
|
||||
/**
|
||||
* Initializes the account selectors.
|
||||
*
|
||||
*/
|
||||
static initialize() {
|
||||
const modals = Array.from(document.getElementsByClassName("accounting-account-selector-modal"));
|
||||
for (const modal of modals) {
|
||||
const selector = new AccountSelector(modal);
|
||||
this.#selectors[selector.#entryType] = selector;
|
||||
}
|
||||
this.#initializeTransactionForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the transaction form.
|
||||
*
|
||||
*/
|
||||
static #initializeTransactionForm() {
|
||||
const entryForm = document.getElementById("accounting-entry-form");
|
||||
const formAccountControl = document.getElementById("accounting-entry-form-account-control");
|
||||
formAccountControl.onclick = () => this.#selectors[entryForm.dataset.entryType].initShow();
|
||||
}
|
||||
/**
|
||||
* Initializes the account selector for the journal entry form.
|
||||
*x
|
||||
*/
|
||||
static initializeJournalEntryForm() {
|
||||
const entryForm = document.getElementById("accounting-entry-form");
|
||||
const formAccountControl = document.getElementById("accounting-entry-form-account-control");
|
||||
formAccountControl.dataset.bsTarget = "#accounting-account-selector-" + entryForm.dataset.entryType + "-modal";
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
document.getElementById("accounting-code")
|
||||
.onchange = validateCode;
|
||||
document.getElementById("accounting-name")
|
||||
@ -65,9 +65,9 @@ function validateForm() {
|
||||
*/
|
||||
function submitFormIfAllAsyncValid() {
|
||||
let isValid = true;
|
||||
Object.keys(isAsyncValid).forEach(function (key) {
|
||||
for (const key of Object.keys(isAsyncValid)) {
|
||||
isValid = isAsyncValid[key] && isValid;
|
||||
});
|
||||
}
|
||||
if (isValid) {
|
||||
document.getElementById("accounting-form").submit()
|
||||
}
|
||||
|
@ -42,21 +42,21 @@ function initializeDragAndDropReordering(list, onReorder) {
|
||||
function initializeMouseDragAndDropReordering(list, onReorder) {
|
||||
const items = Array.from(list.children);
|
||||
let dragged = null;
|
||||
items.forEach(function (item) {
|
||||
for (const item of items) {
|
||||
item.draggable = true;
|
||||
item.addEventListener("dragstart", function () {
|
||||
item.addEventListener("dragstart", () => {
|
||||
dragged = item;
|
||||
dragged.classList.add("accounting-dragged");
|
||||
});
|
||||
item.addEventListener("dragover", function () {
|
||||
item.addEventListener("dragover", () => {
|
||||
onDragOver(dragged, item);
|
||||
onReorder();
|
||||
});
|
||||
item.addEventListener("dragend", function () {
|
||||
item.addEventListener("dragend", () => {
|
||||
dragged.classList.remove("accounting-dragged");
|
||||
dragged = null;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,20 +68,20 @@ function initializeMouseDragAndDropReordering(list, onReorder) {
|
||||
*/
|
||||
function initializeTouchDragAndDropReordering(list, onReorder) {
|
||||
const items = Array.from(list.children);
|
||||
items.forEach(function (item) {
|
||||
item.addEventListener("touchstart", function () {
|
||||
for (const item of items) {
|
||||
item.addEventListener("touchstart", () => {
|
||||
item.classList.add("accounting-dragged");
|
||||
});
|
||||
item.addEventListener("touchmove", function (event) {
|
||||
item.addEventListener("touchmove", (event) => {
|
||||
const touch = event.targetTouches[0];
|
||||
const target = document.elementFromPoint(touch.pageX, touch.pageY);
|
||||
onDragOver(item, target);
|
||||
onReorder();
|
||||
});
|
||||
item.addEventListener("touchend", function () {
|
||||
item.addEventListener("touchend", () => {
|
||||
item.classList.remove("accounting-dragged");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
initializeMaterialFabSpeedDial();
|
||||
});
|
||||
|
||||
@ -34,7 +34,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
function initializeMaterialFabSpeedDial() {
|
||||
const btnFab = document.getElementById("accounting-btn-material-fab-speed-dial");
|
||||
const fab = document.getElementById(btnFab.dataset.target);
|
||||
btnFab.onclick = function () {
|
||||
btnFab.onclick = () => {
|
||||
if (fab.classList.contains("show")) {
|
||||
fab.classList.remove("show");
|
||||
} else {
|
||||
|
399
src/accounting/static/js/period-chooser.js
Normal file
399
src/accounting/static/js/period-chooser.js
Normal file
@ -0,0 +1,399 @@
|
||||
/* The Mia! Accounting Flask Project
|
||||
* period-chooser.js: The JavaScript for the period chooser
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2023 imacat.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
* First written: 2023/3/4
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
new PeriodChooser();
|
||||
});
|
||||
|
||||
/**
|
||||
* The period chooser.
|
||||
*
|
||||
*/
|
||||
class PeriodChooser {
|
||||
|
||||
/**
|
||||
* The prefix of the HTML ID and class
|
||||
* @type {string}
|
||||
*/
|
||||
prefix;
|
||||
|
||||
/**
|
||||
* The modal of the period chooser
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
modal;
|
||||
|
||||
/**
|
||||
* The tab planes
|
||||
* @type {{month: MonthTab, year: YearTab, day: DayTab, custom: CustomTab}}
|
||||
*/
|
||||
tabPlanes = {};
|
||||
|
||||
/**
|
||||
* Constructs the period chooser.
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
this.prefix = "accounting-period-chooser";
|
||||
this.modal = document.getElementById(this.prefix + "-modal");
|
||||
for (const cls of [MonthTab, YearTab, DayTab, CustomTab]) {
|
||||
const tab = new cls(this);
|
||||
this.tabPlanes[tab.tabId()] = tab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A tab plane.
|
||||
*
|
||||
* @abstract
|
||||
* @private
|
||||
*/
|
||||
class TabPlane {
|
||||
|
||||
/**
|
||||
* The period chooser
|
||||
* @type {PeriodChooser}
|
||||
*/
|
||||
chooser;
|
||||
|
||||
/**
|
||||
* The prefix of the HTML ID and class
|
||||
* @type {string}
|
||||
*/
|
||||
prefix;
|
||||
|
||||
/**
|
||||
* The tab
|
||||
* @type {HTMLSpanElement}
|
||||
*/
|
||||
#tab;
|
||||
|
||||
/**
|
||||
* The page
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#page;
|
||||
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param chooser {PeriodChooser} the period chooser
|
||||
*/
|
||||
constructor(chooser) {
|
||||
this.chooser = chooser;
|
||||
this.prefix = "accounting-period-chooser-" + this.tabId();
|
||||
this.#tab = document.getElementById(this.prefix + "-tab");
|
||||
this.#page = document.getElementById(this.prefix + "-page");
|
||||
this.#tab.onclick = () => this.#switchToMe();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tab ID
|
||||
*
|
||||
* @return {string}
|
||||
* @abstract
|
||||
*/
|
||||
tabId() { throw new Error("Method not implemented.") };
|
||||
|
||||
/**
|
||||
* Switches to the tab plane.
|
||||
*
|
||||
*/
|
||||
#switchToMe() {
|
||||
for (const tabPlane of Object.values(this.chooser.tabPlanes)) {
|
||||
tabPlane.#tab.classList.remove("active")
|
||||
tabPlane.#tab.ariaCurrent = "false";
|
||||
tabPlane.#page.classList.add("d-none");
|
||||
tabPlane.#page.ariaCurrent = "false";
|
||||
}
|
||||
this.#tab.classList.add("active");
|
||||
this.#tab.ariaCurrent = "page";
|
||||
this.#page.classList.remove("d-none");
|
||||
this.#page.ariaCurrent = "page";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The month tab plane.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
class MonthTab extends TabPlane {
|
||||
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param chooser {PeriodChooser} the period chooser
|
||||
*/
|
||||
constructor(chooser) {
|
||||
super(chooser);
|
||||
const monthChooser = document.getElementById(this.prefix + "-chooser");
|
||||
let start = monthChooser.dataset.start;
|
||||
new tempusDominus.TempusDominus(monthChooser, {
|
||||
restrictions: {
|
||||
minDate: start,
|
||||
},
|
||||
display: {
|
||||
inline: true,
|
||||
components: {
|
||||
date: false,
|
||||
clock: false,
|
||||
},
|
||||
},
|
||||
defaultDate: monthChooser.dataset.default,
|
||||
});
|
||||
monthChooser.addEventListener(tempusDominus.Namespace.events.change, (e) => {
|
||||
const date = e.detail.date;
|
||||
const year = date.year;
|
||||
const month = date.month + 1;
|
||||
const period = month < 10? year + "-0" + month: year + "-" + month;
|
||||
window.location = chooser.modal.dataset.urlTemplate
|
||||
.replaceAll("PERIOD", period);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The tab ID
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
tabId() {
|
||||
return "month";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The year tab plane.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
class YearTab extends TabPlane {
|
||||
|
||||
/**
|
||||
* The tab ID
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
tabId() {
|
||||
return "year";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The day tab plane.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
class DayTab extends TabPlane {
|
||||
|
||||
/**
|
||||
* The day input
|
||||
* @type {HTMLInputElement}
|
||||
*/
|
||||
#date;
|
||||
|
||||
/**
|
||||
* The error of the date input
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#dateError;
|
||||
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param chooser {PeriodChooser} the period chooser
|
||||
*/
|
||||
constructor(chooser) {
|
||||
super(chooser);
|
||||
this.#date = document.getElementById(this.prefix + "-date");
|
||||
this.#dateError = document.getElementById(this.prefix + "-date-error");
|
||||
this.#date.onchange = () => {
|
||||
if (this.#validateDate()) {
|
||||
window.location = chooser.modal.dataset.urlTemplate
|
||||
.replaceAll("PERIOD", this.#date.value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the date.
|
||||
*
|
||||
* @return {boolean} true if valid, or false otherwise
|
||||
*/
|
||||
#validateDate() {
|
||||
if (this.#date.value === "") {
|
||||
this.#date.classList.add("is-invalid");
|
||||
this.#dateError.innerText = A_("Please fill in the date.");
|
||||
return false;
|
||||
}
|
||||
if (this.#date.value < this.#date.min) {
|
||||
this.#date.classList.add("is-invalid");
|
||||
this.#dateError.innerText = A_("The date is too early.");
|
||||
return false;
|
||||
}
|
||||
this.#date.classList.remove("is-invalid");
|
||||
this.#dateError.innerText = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The tab ID
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
tabId() {
|
||||
return "day";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The custom tab plane.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
class CustomTab extends TabPlane {
|
||||
|
||||
/**
|
||||
* The start of the period
|
||||
* @type {HTMLInputElement}
|
||||
*/
|
||||
#start;
|
||||
|
||||
/**
|
||||
* The error of the start
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#startError;
|
||||
|
||||
/**
|
||||
* The end of the period
|
||||
* @type {HTMLInputElement}
|
||||
*/
|
||||
#end;
|
||||
|
||||
/**
|
||||
* The error of the end
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
#endError;
|
||||
|
||||
/**
|
||||
* The confirm button
|
||||
* @type {HTMLButtonElement}
|
||||
*/
|
||||
#conform;
|
||||
|
||||
/**
|
||||
* Constructs a tab plane.
|
||||
*
|
||||
* @param chooser {PeriodChooser} the period chooser
|
||||
*/
|
||||
constructor(chooser) {
|
||||
super(chooser);
|
||||
this.#start = document.getElementById(this.prefix + "-start");
|
||||
this.#startError = document.getElementById(this.prefix + "-start-error");
|
||||
this.#end = document.getElementById(this.prefix + "-end");
|
||||
this.#endError = document.getElementById(this.prefix + "-end-error");
|
||||
this.#conform = document.getElementById(this.prefix + "-confirm");
|
||||
this.#start.onchange = () => {
|
||||
if (this.#validateStart()) {
|
||||
this.#end.min = this.#start.value;
|
||||
}
|
||||
};
|
||||
this.#end.onchange = () => {
|
||||
if (this.#validateEnd()) {
|
||||
this.#start.max = this.#end.value;
|
||||
}
|
||||
};
|
||||
this.#conform.onclick = () => {
|
||||
let isValid = true;
|
||||
isValid = this.#validateStart() && isValid;
|
||||
isValid = this.#validateEnd() && isValid;
|
||||
if (isValid) {
|
||||
window.location = chooser.modal.dataset.urlTemplate
|
||||
.replaceAll("PERIOD", this.#start.value + "-" + this.#end.value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the start of the period.
|
||||
*
|
||||
* @returns {boolean} true if valid, or false otherwise
|
||||
* @private
|
||||
*/
|
||||
#validateStart() {
|
||||
if (this.#start.value === "") {
|
||||
this.#start.classList.add("is-invalid");
|
||||
this.#startError.innerText = A_("Please fill in the start date.");
|
||||
return false;
|
||||
}
|
||||
if (this.#start.value < this.#start.min) {
|
||||
this.#start.classList.add("is-invalid");
|
||||
this.#startError.innerText = A_("The start date is too early.");
|
||||
return false;
|
||||
}
|
||||
if (this.#start.value > this.#start.max) {
|
||||
this.#start.classList.add("is-invalid");
|
||||
this.#startError.innerText = A_("The start date cannot be beyond the end date.");
|
||||
return false;
|
||||
}
|
||||
this.#start.classList.remove("is-invalid");
|
||||
this.#startError.innerText = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the end of the period.
|
||||
*
|
||||
* @returns {boolean} true if valid, or false otherwise
|
||||
* @private
|
||||
*/
|
||||
#validateEnd() {
|
||||
this.#end.value = this.#end.value.trim();
|
||||
if (this.#end.value === "") {
|
||||
this.#end.classList.add("is-invalid");
|
||||
this.#endError.innerText = A_("Please fill in the end date.");
|
||||
return false;
|
||||
}
|
||||
if (this.#end.value < this.#end.min) {
|
||||
this.#end.classList.add("is-invalid");
|
||||
this.#endError.innerText = A_("The end date cannot be beyond the start date.");
|
||||
return false;
|
||||
}
|
||||
this.#end.classList.remove("is-invalid");
|
||||
this.#endError.innerText = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The tab ID
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
tabId() {
|
||||
return "custom";
|
||||
}
|
||||
}
|
1198
src/accounting/static/js/summary-editor.js
Normal file
1198
src/accounting/static/js/summary-editor.js
Normal file
File diff suppressed because it is too large
Load Diff
41
src/accounting/static/js/table-row-link.js
Normal file
41
src/accounting/static/js/table-row-link.js
Normal file
@ -0,0 +1,41 @@
|
||||
/* The Mia! Accounting Flask Project
|
||||
* table-row-link.js: The JavaScript for table rows as links.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2023 imacat.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
* First written: 2023/3/4
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
initializeTableRowLinks();
|
||||
});
|
||||
|
||||
/**
|
||||
* Initializes the table rows as links.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function initializeTableRowLinks() {
|
||||
const rows = Array.from(document.getElementsByClassName("accounting-clickable accounting-table-row-link"));
|
||||
for (const row of rows) {
|
||||
row.onclick = () => {
|
||||
window.location = row.dataset.href;
|
||||
};
|
||||
}
|
||||
}
|
@ -22,10 +22,9 @@
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
initializeCurrencyForms();
|
||||
initializeJournalEntries();
|
||||
initializeAccountSelectors();
|
||||
initializeFormValidation();
|
||||
});
|
||||
|
||||
@ -69,22 +68,22 @@ function initializeCurrencyForms() {
|
||||
const btnNew = document.getElementById("accounting-btn-new-currency");
|
||||
const currencyList = document.getElementById("accounting-currency-list");
|
||||
const deleteButtons = Array.from(document.getElementsByClassName("accounting-btn-delete-currency"));
|
||||
const onReorder = function () {
|
||||
const onReorder = () => {
|
||||
const currencies = Array.from(currencyList.children);
|
||||
for (let i = 0; i < currencies.length; i++) {
|
||||
const no = document.getElementById(currencies[i].dataset.prefix + "-no");
|
||||
no.value = String(i + 1);
|
||||
}
|
||||
};
|
||||
btnNew.onclick = function () {
|
||||
btnNew.onclick = () => {
|
||||
const currencies = Array.from(document.getElementsByClassName("accounting-currency"));
|
||||
let maxIndex = 0;
|
||||
currencies.forEach(function (currency) {
|
||||
for (const currency of currencies) {
|
||||
const index = parseInt(currency.dataset.index);
|
||||
if (maxIndex < index) {
|
||||
maxIndex = index;
|
||||
}
|
||||
});
|
||||
}
|
||||
const newIndex = String(maxIndex + 1);
|
||||
const html = form.dataset.currencyTemplate
|
||||
.replaceAll("CURRENCY_INDEX", escapeHtml(newIndex));
|
||||
@ -108,7 +107,7 @@ function initializeCurrencyForms() {
|
||||
*/
|
||||
function initializeBtnDeleteCurrency(button) {
|
||||
const target = document.getElementById(button.dataset.target);
|
||||
button.onclick = function () {
|
||||
button.onclick = () => {
|
||||
target.parentElement.removeChild(target);
|
||||
resetDeleteCurrencyButtons();
|
||||
};
|
||||
@ -122,9 +121,9 @@ function initializeBtnDeleteCurrency(button) {
|
||||
function resetDeleteCurrencyButtons() {
|
||||
const buttons = Array.from(document.getElementsByClassName("accounting-btn-delete-currency"));
|
||||
if (buttons.length > 1) {
|
||||
buttons.forEach(function (button) {
|
||||
for (const button of buttons) {
|
||||
button.classList.remove("d-none");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
buttons[0].classList.add("d-none");
|
||||
}
|
||||
@ -157,27 +156,32 @@ function initializeNewEntryButton(button) {
|
||||
const formAccountControl = document.getElementById("accounting-entry-form-account-control");
|
||||
const formAccount = document.getElementById("accounting-entry-form-account");
|
||||
const formAccountError = document.getElementById("accounting-entry-form-account-error")
|
||||
const formSummaryControl = document.getElementById("accounting-entry-form-summary-control");
|
||||
const formSummary = document.getElementById("accounting-entry-form-summary");
|
||||
const formSummaryError = document.getElementById("accounting-entry-form-summary-error");
|
||||
const formAmount = document.getElementById("accounting-entry-form-amount");
|
||||
const formAmountError = document.getElementById("accounting-entry-form-amount-error");
|
||||
button.onclick = function () {
|
||||
button.onclick = () => {
|
||||
entryForm.dataset.currencyIndex = button.dataset.currencyIndex;
|
||||
entryForm.dataset.entryType = button.dataset.entryType;
|
||||
entryForm.dataset.entryIndex = button.dataset.entryIndex;
|
||||
formAccountControl.classList.remove("accounting-not-empty")
|
||||
formAccountControl.classList.remove("accounting-not-empty");
|
||||
formAccountControl.classList.remove("is-invalid");
|
||||
formAccountControl.dataset.bsTarget = button.dataset.accountModal;
|
||||
formAccount.innerText = "";
|
||||
formAccount.dataset.code = "";
|
||||
formAccount.dataset.text = "";
|
||||
formAccountError.innerText = "";
|
||||
formSummary.value = "";
|
||||
formSummary.classList.remove("is-invalid");
|
||||
formSummaryControl.dataset.bsTarget = "#accounting-summary-editor-" + button.dataset.entryType + "-modal";
|
||||
formSummaryControl.classList.remove("accounting-not-empty");
|
||||
formSummaryControl.classList.remove("is-invalid");
|
||||
formSummary.dataset.value = "";
|
||||
formSummary.innerText = ""
|
||||
formSummaryError.innerText = ""
|
||||
formAmount.value = "";
|
||||
formAmount.classList.remove("is-invalid");
|
||||
formAmountError.innerText = "";
|
||||
AccountSelector.initializeJournalEntryForm();
|
||||
SummaryEditor.initializeNewJournalEntry(button.dataset.entryType);
|
||||
};
|
||||
}
|
||||
|
||||
@ -187,7 +191,7 @@ function initializeNewEntryButton(button) {
|
||||
* @param entryList {HTMLUListElement} the journal entry list.
|
||||
*/
|
||||
function initializeJournalEntryListReorder(entryList) {
|
||||
initializeDragAndDropReordering(entryList, function () {
|
||||
initializeDragAndDropReordering(entryList, () => {
|
||||
const entries = Array.from(entryList.children);
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const no = document.getElementById(entries[i].dataset.prefix + "-no");
|
||||
@ -209,9 +213,10 @@ function initializeJournalEntry(entry) {
|
||||
const control = document.getElementById(entry.dataset.prefix + "-control");
|
||||
const formAccountControl = document.getElementById("accounting-entry-form-account-control");
|
||||
const formAccount = document.getElementById("accounting-entry-form-account");
|
||||
const formSummaryControl = document.getElementById("accounting-entry-form-summary-control");
|
||||
const formSummary = document.getElementById("accounting-entry-form-summary");
|
||||
const formAmount = document.getElementById("accounting-entry-form-amount");
|
||||
control.onclick = function () {
|
||||
control.onclick = () => {
|
||||
entryForm.dataset.currencyIndex = entry.dataset.currencyIndex;
|
||||
entryForm.dataset.entryType = entry.dataset.entryType;
|
||||
entryForm.dataset.entryIndex = entry.dataset.entryIndex;
|
||||
@ -220,12 +225,19 @@ function initializeJournalEntry(entry) {
|
||||
} else {
|
||||
formAccountControl.classList.add("accounting-not-empty");
|
||||
}
|
||||
formAccountControl.dataset.bsTarget = entry.dataset.accountModal;
|
||||
formAccount.innerText = accountCode.dataset.text;
|
||||
formAccount.dataset.code = accountCode.value;
|
||||
formAccount.dataset.text = accountCode.dataset.text;
|
||||
formSummary.value = summary.value;
|
||||
formSummaryControl.dataset.bsTarget = "#accounting-summary-editor-" + entry.dataset.entryType + "-modal";
|
||||
if (summary.value === "") {
|
||||
formSummaryControl.classList.remove("accounting-not-empty");
|
||||
} else {
|
||||
formSummaryControl.classList.add("accounting-not-empty");
|
||||
}
|
||||
formSummary.dataset.value = summary.value;
|
||||
formSummary.innerText = summary.value;
|
||||
formAmount.value = amount.value;
|
||||
AccountSelector.initializeJournalEntryForm();
|
||||
validateJournalEntryForm();
|
||||
};
|
||||
}
|
||||
@ -237,40 +249,10 @@ function initializeJournalEntry(entry) {
|
||||
*/
|
||||
function initializeJournalEntryFormModal() {
|
||||
const entryForm = document.getElementById("accounting-entry-form");
|
||||
const formAccountControl = document.getElementById("accounting-entry-form-account-control");
|
||||
const formAccount = document.getElementById("accounting-entry-form-account");
|
||||
const formSummary = document.getElementById("accounting-entry-form-summary");
|
||||
const formAmount = document.getElementById("accounting-entry-form-amount");
|
||||
const modal = document.getElementById("accounting-entry-form-modal");
|
||||
formAccountControl.onclick = function () {
|
||||
const prefix = "accounting-" + entryForm.dataset.entryType + "-account";
|
||||
const query = document.getElementById(prefix + "-selector-query")
|
||||
const more = document.getElementById(prefix + "-more");
|
||||
const options = Array.from(document.getElementsByClassName(prefix + "-option"));
|
||||
const btnClear = document.getElementById(prefix + "-btn-clear");
|
||||
query.value = "";
|
||||
more.classList.remove("d-none");
|
||||
filterAccountOptions(prefix);
|
||||
options.forEach(function (option) {
|
||||
if (option.dataset.code === formAccount.dataset.code) {
|
||||
option.classList.add("active");
|
||||
} else {
|
||||
option.classList.remove("active");
|
||||
}
|
||||
});
|
||||
if (formAccount.dataset.code === "") {
|
||||
btnClear.classList.add("btn-secondary");
|
||||
btnClear.classList.remove("btn-danger");
|
||||
btnClear.disabled = true;
|
||||
} else {
|
||||
btnClear.classList.add("btn-danger");
|
||||
btnClear.classList.remove("btn-secondary");
|
||||
btnClear.disabled = false;
|
||||
}
|
||||
};
|
||||
formSummary.onchange = validateJournalEntrySummary;
|
||||
formAmount.onchange = validateJournalEntryAmount;
|
||||
entryForm.onsubmit = function () {
|
||||
entryForm.onsubmit = () => {
|
||||
if (validateJournalEntryForm()) {
|
||||
saveJournalEntryForm();
|
||||
bootstrap.Modal.getInstance(modal).hide();
|
||||
@ -297,7 +279,6 @@ function validateJournalEntryForm() {
|
||||
* Validates the account in the journal entry form modal.
|
||||
*
|
||||
* @return {boolean} true if valid, or false otherwise
|
||||
* @private
|
||||
*/
|
||||
function validateJournalEntryAccount() {
|
||||
const field = document.getElementById("accounting-entry-form-account");
|
||||
@ -320,10 +301,9 @@ function validateJournalEntryAccount() {
|
||||
* @private
|
||||
*/
|
||||
function validateJournalEntrySummary() {
|
||||
const field = document.getElementById("accounting-entry-form-summary");
|
||||
const control = document.getElementById("accounting-entry-form-summary-control");
|
||||
const error = document.getElementById("accounting-entry-form-summary-error");
|
||||
field.value = field.value.trim();
|
||||
field.classList.remove("is-invalid");
|
||||
control.classList.remove("is-invalid");
|
||||
error.innerText = "";
|
||||
return true;
|
||||
}
|
||||
@ -366,12 +346,12 @@ function saveJournalEntryForm() {
|
||||
const entries = Array.from(document.getElementsByClassName("accounting-currency-" + currencyIndex + "-" + entryType));
|
||||
const entryList = document.getElementById("accounting-currency-" + currencyIndex + "-" + entryType + "-list")
|
||||
let maxIndex = 0;
|
||||
entries.forEach(function (entry) {
|
||||
for (const entry of entries) {
|
||||
const index = parseInt(entry.dataset.entryIndex);
|
||||
if (maxIndex < index) {
|
||||
maxIndex = index;
|
||||
}
|
||||
});
|
||||
}
|
||||
entryIndex = String(maxIndex + 1);
|
||||
const html = form.dataset.entryTemplate
|
||||
.replaceAll("CURRENCY_INDEX", escapeHtml(currencyIndex))
|
||||
@ -393,8 +373,8 @@ function saveJournalEntryForm() {
|
||||
accountCode.value = formAccount.dataset.code;
|
||||
accountCode.dataset.text = formAccount.dataset.text;
|
||||
accountText.innerText = formAccount.dataset.text;
|
||||
summary.value = formSummary.value;
|
||||
summaryText.innerText = formSummary.value;
|
||||
summary.value = formSummary.dataset.value;
|
||||
summaryText.innerText = formSummary.dataset.value;
|
||||
amount.value = formAmount.value;
|
||||
amountText.innerText = formatDecimal(new Decimal(formAmount.value));
|
||||
if (entryForm.dataset.entryIndex === "new") {
|
||||
@ -418,7 +398,7 @@ function initializeDeleteJournalEntryButton(button) {
|
||||
const currencyIndex = target.dataset.currencyIndex;
|
||||
const entryType = target.dataset.entryType;
|
||||
const currency = document.getElementById("accounting-currency-" + currencyIndex);
|
||||
button.onclick = function () {
|
||||
button.onclick = () => {
|
||||
target.parentElement.removeChild(target);
|
||||
resetDeleteJournalEntryButtons(button.dataset.sameClass);
|
||||
updateBalance(currencyIndex, entryType);
|
||||
@ -436,9 +416,9 @@ function initializeDeleteJournalEntryButton(button) {
|
||||
function resetDeleteJournalEntryButtons(sameClass) {
|
||||
const buttons = Array.from(document.getElementsByClassName(sameClass));
|
||||
if (buttons.length > 1) {
|
||||
buttons.forEach(function (button) {
|
||||
for (const button of buttons) {
|
||||
button.classList.remove("d-none");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
buttons[0].classList.add("d-none");
|
||||
}
|
||||
@ -456,147 +436,14 @@ function updateBalance(currencyIndex, entryType) {
|
||||
const amounts = Array.from(document.getElementsByClassName(prefix + "-amount"));
|
||||
const totalText = document.getElementById(prefix + "-total");
|
||||
let total = new Decimal("0");
|
||||
amounts.forEach(function (amount) {
|
||||
for (const amount of amounts) {
|
||||
if (amount.value !== "") {
|
||||
total = total.plus(new Decimal(amount.value));
|
||||
}
|
||||
});
|
||||
}
|
||||
totalText.innerText = formatDecimal(total);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the account selectors.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function initializeAccountSelectors() {
|
||||
const selectors = Array.from(document.getElementsByClassName("accounting-selector-modal"));
|
||||
const formAccountControl = document.getElementById("accounting-entry-form-account-control");
|
||||
const formAccount = document.getElementById("accounting-entry-form-account");
|
||||
selectors.forEach(function (selector) {
|
||||
const more = document.getElementById(selector.dataset.prefix + "-more");
|
||||
const btnClear = document.getElementById(selector.dataset.prefix + "-btn-clear");
|
||||
const options = Array.from(document.getElementsByClassName(selector.dataset.prefix + "-option"));
|
||||
more.onclick = function () {
|
||||
more.classList.add("d-none");
|
||||
filterAccountOptions(selector.dataset.prefix);
|
||||
};
|
||||
initializeAccountQuery(selector);
|
||||
btnClear.onclick = function () {
|
||||
formAccountControl.classList.remove("accounting-not-empty");
|
||||
formAccount.innerText = "";
|
||||
formAccount.dataset.code = "";
|
||||
formAccount.dataset.text = "";
|
||||
validateJournalEntryAccount();
|
||||
};
|
||||
options.forEach(function (option) {
|
||||
option.onclick = function () {
|
||||
formAccountControl.classList.add("accounting-not-empty");
|
||||
formAccount.innerText = option.dataset.content;
|
||||
formAccount.dataset.code = option.dataset.code;
|
||||
formAccount.dataset.text = option.dataset.content;
|
||||
validateJournalEntryAccount();
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the query on the account options.
|
||||
*
|
||||
* @param selector {HTMLDivElement} the selector modal
|
||||
* @private
|
||||
*/
|
||||
function initializeAccountQuery(selector) {
|
||||
const query = document.getElementById(selector.dataset.prefix + "-selector-query");
|
||||
query.addEventListener("input", function () {
|
||||
filterAccountOptions(selector.dataset.prefix);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the account options.
|
||||
*
|
||||
* @param prefix {string} the HTML ID and class prefix
|
||||
* @private
|
||||
*/
|
||||
function filterAccountOptions(prefix) {
|
||||
const query = document.getElementById(prefix + "-selector-query");
|
||||
const optionList = document.getElementById(prefix + "-option-list");
|
||||
if (optionList === null) {
|
||||
console.log(prefix + "-option-list");
|
||||
}
|
||||
const options = Array.from(document.getElementsByClassName(prefix + "-option"));
|
||||
const more = document.getElementById(prefix + "-more");
|
||||
const queryNoResult = document.getElementById(prefix + "-option-no-result");
|
||||
const codesInUse = getAccountCodeUsedInForm();
|
||||
let shouldAnyShow = false;
|
||||
options.forEach(function (option) {
|
||||
const shouldShow = shouldAccountOptionShow(option, more, codesInUse, query);
|
||||
if (shouldShow) {
|
||||
option.classList.remove("d-none");
|
||||
shouldAnyShow = true;
|
||||
} else {
|
||||
option.classList.add("d-none");
|
||||
}
|
||||
});
|
||||
if (!shouldAnyShow && more.classList.contains("d-none")) {
|
||||
optionList.classList.add("d-none");
|
||||
queryNoResult.classList.remove("d-none");
|
||||
} else {
|
||||
optionList.classList.remove("d-none");
|
||||
queryNoResult.classList.add("d-none");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an account option should show.
|
||||
*
|
||||
* @param option {HTMLLIElement} the account option
|
||||
* @param more {HTMLLIElement} the more account element
|
||||
* @param inUse {string[]} the account codes that are used in the form
|
||||
* @param query {HTMLInputElement} the query element, if any
|
||||
* @return {boolean} true if the account option should show, or false otherwise
|
||||
* @private
|
||||
*/
|
||||
function shouldAccountOptionShow(option, more, inUse, query) {
|
||||
const isQueryMatched = function () {
|
||||
if (query.value === "") {
|
||||
return true;
|
||||
}
|
||||
const queryValues = JSON.parse(option.dataset.queryValues);
|
||||
for (const queryValue of queryValues) {
|
||||
if (queryValue.includes(query.value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const isMoreMatched = function () {
|
||||
if (more.classList.contains("d-none")) {
|
||||
return true;
|
||||
}
|
||||
return option.classList.contains("accounting-account-in-use") || inUse.includes(option.dataset.code);
|
||||
};
|
||||
return isMoreMatched() && isQueryMatched();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the account codes that are used in the form.
|
||||
*
|
||||
* @return {string[]} the account codes that are used in the form
|
||||
* @private
|
||||
*/
|
||||
function getAccountCodeUsedInForm() {
|
||||
const accountCodes = Array.from(document.getElementsByClassName("accounting-account-code"));
|
||||
const formAccount = document.getElementById("accounting-entry-form-account");
|
||||
const inUse = [formAccount.dataset.code];
|
||||
accountCodes.forEach(function (accountCode) {
|
||||
inUse.push(accountCode.value);
|
||||
});
|
||||
return inUse
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the form validation.
|
||||
*
|
||||
@ -655,9 +502,9 @@ function validateCurrencies() {
|
||||
const currencies = Array.from(document.getElementsByClassName("accounting-currency"));
|
||||
let isValid = true;
|
||||
isValid = validateCurrenciesReal() && isValid;
|
||||
currencies.forEach(function (currency) {
|
||||
for (const currency of currencies) {
|
||||
isValid = validateCurrency(currency) && isValid;
|
||||
});
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@ -718,9 +565,9 @@ function validateJournalEntries(currency, entryType) {
|
||||
const entries = Array.from(document.getElementsByClassName("accounting-currency-" + currencyIndex + "-" + entryType));
|
||||
let isValid = true;
|
||||
isValid = validateJournalEntriesReal(currencyIndex, entryType) && isValid;
|
||||
entries.forEach(function (entry) {
|
||||
for (const entry of entries) {
|
||||
isValid = validateJournalEntry(entry) && isValid;
|
||||
})
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@ -791,17 +638,17 @@ function validateBalance(currency) {
|
||||
const creditAmounts = Array.from(document.getElementsByClassName(prefix + "-credit-amount"));
|
||||
if (debit !== null && credit !== null) {
|
||||
let debitTotal = new Decimal("0");
|
||||
debitAmounts.forEach(function (amount) {
|
||||
for (const amount of debitAmounts) {
|
||||
if (amount.value !== "") {
|
||||
debitTotal = debitTotal.plus(new Decimal(amount.value));
|
||||
}
|
||||
});
|
||||
}
|
||||
let creditTotal = new Decimal("0");
|
||||
creditAmounts.forEach(function (amount) {
|
||||
for (const amount of creditAmounts) {
|
||||
if (amount.value !== "") {
|
||||
creditTotal = creditTotal.plus(new Decimal(amount.value));
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!debitTotal.equals(creditTotal)) {
|
||||
control.classList.add("is-invalid");
|
||||
error.innerText = A_("The totals of the debit and credit amounts do not match.");
|
||||
|
@ -22,10 +22,10 @@
|
||||
*/
|
||||
|
||||
// Initializes the page JavaScript.
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const list = document.getElementById("accounting-order-list");
|
||||
if (list !== null) {
|
||||
const onReorder = function () {
|
||||
const onReorder = () => {
|
||||
const accounts = Array.from(list.children);
|
||||
for (let i = 0; i < accounts.length; i++) {
|
||||
const no = document.getElementById("accounting-order-" + accounts[i].dataset.id + "-no");
|
||||
|
81
src/accounting/template_filters.py
Normal file
81
src/accounting/template_filters.py
Normal file
@ -0,0 +1,81 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/25
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The template filters.
|
||||
|
||||
"""
|
||||
import typing as t
|
||||
from datetime import date, timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
from flask_babel import get_locale
|
||||
|
||||
from accounting.locale import gettext
|
||||
|
||||
|
||||
def format_amount(value: Decimal | None) -> str | None:
|
||||
"""Formats an amount for readability.
|
||||
|
||||
:param value: The amount.
|
||||
:return: The formatted amount text.
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
if value == 0:
|
||||
return "-"
|
||||
whole: int = int(value)
|
||||
frac: Decimal = (value - whole).normalize()
|
||||
return "{:,}".format(whole) + str(abs(frac))[1:]
|
||||
|
||||
|
||||
def format_date(value: date) -> str:
|
||||
"""Formats a date to be human-friendly.
|
||||
|
||||
:param value: The date.
|
||||
:return: The human-friendly date text.
|
||||
"""
|
||||
today: date = date.today()
|
||||
if value == today:
|
||||
return gettext("Today")
|
||||
if value == today - timedelta(days=1):
|
||||
return gettext("Yesterday")
|
||||
if value == today + timedelta(days=1):
|
||||
return gettext("Tomorrow")
|
||||
locale = str(get_locale())
|
||||
if locale == "zh" or locale.startswith("zh_"):
|
||||
if value == today - timedelta(days=2):
|
||||
return gettext("The day before yesterday")
|
||||
if value == today + timedelta(days=2):
|
||||
return gettext("The day after tomorrow")
|
||||
if locale == "zh" or locale.startswith("zh_"):
|
||||
weekdays = ["一", "二", "三", "四", "五", "六", "日"]
|
||||
weekday = weekdays[value.weekday()]
|
||||
else:
|
||||
weekday = value.strftime("%a")
|
||||
if value.year != today.year:
|
||||
return "{}/{}/{}({})".format(
|
||||
value.year, value.month, value.day, weekday)
|
||||
return "{}/{}({})".format(value.month, value.day, weekday)
|
||||
|
||||
|
||||
def default(value: t.Any, default_value: t.Any = "") -> t.Any:
|
||||
"""Returns the default value if the given value is None.
|
||||
|
||||
:param value: The value.
|
||||
:param default_value: The default value when the given value is None.
|
||||
:return: The value, or the default value if the given value is None.
|
||||
"""
|
||||
return default_value if value is None else value
|
39
src/accounting/template_globals.py
Normal file
39
src/accounting/template_globals.py
Normal file
@ -0,0 +1,39 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/3
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The template globals for the transaction management.
|
||||
|
||||
"""
|
||||
from flask import current_app
|
||||
|
||||
from accounting.models import Currency
|
||||
|
||||
|
||||
def currency_options() -> str:
|
||||
"""Returns the currency options.
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
return Currency.query.order_by(Currency.code).all()
|
||||
|
||||
|
||||
def default_currency_code() -> str:
|
||||
"""Returns the default currency code.
|
||||
|
||||
:return: The default currency code.
|
||||
"""
|
||||
with current_app.app_context():
|
||||
return current_app.config.get("DEFAULT_CURRENCY", "USD")
|
@ -59,8 +59,8 @@ First written: 2023/1/31
|
||||
{% if accounting_can_edit() %}
|
||||
<form action="{{ url_for("accounting.account.delete", account=obj) }}" method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if "next" in request.args %}
|
||||
<input type="hidden" name="next" value="{{ request.args["next"] }}">
|
||||
{% if request.args.next %}
|
||||
<input type="hidden" name="next" value="{{ request.args.next }}">
|
||||
{% endif %}
|
||||
<div class="modal fade" id="accounting-delete-modal" tabindex="-1" aria-labelledby="accounting-delete-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
|
@ -36,11 +36,11 @@ First written: 2023/2/1
|
||||
|
||||
<form id="accounting-form" action="{% block action_url %}{% endblock %}" method="post">
|
||||
{{ form.csrf_token }}
|
||||
{% if "next" in request.args %}
|
||||
<input type="hidden" name="next" value="{{ request.args["next"] }}">
|
||||
{% if request.args.next %}
|
||||
<input type="hidden" name="next" value="{{ request.args.next }}">
|
||||
{% endif %}
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-base-code" type="hidden" name="base_code" value="{{ "" if form.base_code.data is none else form.base_code.data }}">
|
||||
<input id="accounting-base-code" type="hidden" name="base_code" value="{{ form.base_code.data|accounting_default }}">
|
||||
<div id="accounting-base" class="form-control accounting-clickable accounting-material-text-field {% if form.base_code.data %} accounting-not-empty {% endif %} {% if form.base_code.errors %} is-invalid {% endif %}" data-bs-toggle="modal" data-bs-target="#accounting-base-selector-modal">
|
||||
<label class="form-label" for="accounting-base">{{ A_("Base account") }}</label>
|
||||
<div id="accounting-base-content">
|
||||
@ -57,7 +57,7 @@ First written: 2023/2/1
|
||||
</div>
|
||||
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-title" class="form-control {% if form.title.errors %} is-invalid {% endif %}" type="text" name="title" value="{{ "" if form.title.data is none else form.title.data }}" placeholder=" " required="required">
|
||||
<input id="accounting-title" class="form-control {% if form.title.errors %} is-invalid {% endif %}" type="text" name="title" value="{{ form.title.data|accounting_default }}" placeholder=" " required="required">
|
||||
<label class="form-label" for="accounting-title">{{ A_("Title") }}</label>
|
||||
<div id="accounting-title-error" class="invalid-feedback">{% if form.title.errors %}{{ form.title.errors[0] }}{% endif %}</div>
|
||||
</div>
|
||||
|
@ -21,7 +21,7 @@ First written: 2023/1/30
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block header %}{% block title %}{% if "q" in request.args %}{{ A_("Search Result for \"%(query)s\"", query=request.args["q"]) }}{% else %}{{ A_("Account Management") }}{% endif %}{% endblock %}{% endblock %}
|
||||
{% block header %}{% block title %}{% if request.args.q %}{{ A_("Search Result for \"%(query)s\"", query=request.args.q) }}{% else %}{{ A_("Account Management") }}{% endif %}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@ -32,8 +32,8 @@ First written: 2023/1/30
|
||||
{{ A_("New") }}
|
||||
</a>
|
||||
{% endif %}
|
||||
<form class="btn btn-primary d-flex input-group" action="{{ url_for("accounting.account.list") }}" method="get" role="search" aria-label="{{ A_("Search for Desktop") }}">
|
||||
<input id="accounting-search-desktop" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args["q"] if "q" in request.args else "" }}" placeholder=" " required="required">
|
||||
<form class="btn btn-primary d-flex input-group accounting-search-desktop-form" action="{{ url_for("accounting.account.list") }}" method="get" role="search" aria-label="{{ A_("Search for Desktop") }}">
|
||||
<input id="accounting-search-desktop" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-desktop" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
@ -45,7 +45,7 @@ First written: 2023/1/30
|
||||
|
||||
<div class="btn-group mb-2 d-md-none">
|
||||
<form class="btn btn-primary d-flex input-group" action="{{ url_for("accounting.account.list") }}" method="get" role="search" aria-label="{{ A_("Search for Mobile") }}">
|
||||
<input id="accounting-search-mobile" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args["q"] if "q" in request.args else "" }}" placeholder=" " required="required">
|
||||
<input id="accounting-search-mobile" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-mobile" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
|
@ -40,8 +40,8 @@ First written: 2023/2/2
|
||||
{% if base.accounts|length > 1 and accounting_can_edit() %}
|
||||
<form action="{{ url_for("accounting.account.sort", base=base) }}" method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if "next" in request.args %}
|
||||
<input type="hidden" name="next" value="{{ request.args["next"] }}">
|
||||
{% if request.args.next %}
|
||||
<input type="hidden" name="next" value="{{ request.args.next }}">
|
||||
{% endif %}
|
||||
<ul id="accounting-order-list" class="list-group mb-3" data-base-code="{{ base.code }}">
|
||||
{% for account in base.accounts|sort(attribute="no") %}
|
||||
|
@ -21,13 +21,13 @@ First written: 2023/1/26
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block header %}{% block title %}{% if "q" in request.args %}{{ A_("Search Result for \"%(query)s\"", query=request.args["q"]) }}{% else %}{{ A_("Base Account Managements") }}{% endif %}{% endblock %}{% endblock %}
|
||||
{% block header %}{% block title %}{% if request.args.q %}{{ A_("Search Result for \"%(query)s\"", query=request.args.q) }}{% else %}{{ A_("Base Account Managements") }}{% endif %}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="btn-group mb-2">
|
||||
<form class="btn btn-primary d-flex input-group" action="{{ url_for("accounting.base-account.list") }}" method="get" role="search" aria-label="{{ A_("Search") }}">
|
||||
<input id="accounting-search" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args["q"] if "q" in request.args else "" }}" placeholder=" " required="required">
|
||||
<form class="btn btn-primary d-flex input-group accounting-search-desktop-form" action="{{ url_for("accounting.base-account.list") }}" method="get" role="search" aria-label="{{ A_("Search") }}">
|
||||
<input id="accounting-search" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
|
@ -55,8 +55,8 @@ First written: 2023/2/6
|
||||
{% if accounting_can_edit() %}
|
||||
<form action="{{ url_for("accounting.currency.delete", currency=obj) }}" method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if "next" in request.args %}
|
||||
<input type="hidden" name="next" value="{{ request.args["next"] }}">
|
||||
{% if request.args.next %}
|
||||
<input type="hidden" name="next" value="{{ request.args.next }}">
|
||||
{% endif %}
|
||||
<div class="modal fade" id="accounting-delete-modal" tabindex="-1" aria-labelledby="accounting-delete-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
|
@ -36,17 +36,17 @@ First written: 2023/2/6
|
||||
|
||||
<form id="accounting-form" action="{% block action_url %}{% endblock %}" method="post">
|
||||
{{ form.csrf_token }}
|
||||
{% if "next" in request.args %}
|
||||
<input type="hidden" name="next" value="{{ request.args["next"] }}">
|
||||
{% if request.args.next %}
|
||||
<input type="hidden" name="next" value="{{ request.args.next }}">
|
||||
{% endif %}
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-code" class="form-control {% if form.code.errors %} is-invalid {% endif %}" type="text" name="code" value="{{ "" if form.code.data is none else form.code.data }}" placeholder=" " required="required" data-exists-url="{{ url_for("accounting.currency-api.exists") }}" data-original="{% block original_code %}{% endblock %}" data-blocklist="{{ form.CODE_BLOCKLIST|tojson|forceescape }}">
|
||||
<input id="accounting-code" class="form-control {% if form.code.errors %} is-invalid {% endif %}" type="text" name="code" value="{{ form.code.data|accounting_default }}" placeholder=" " required="required" data-exists-url="{{ url_for("accounting.currency-api.exists") }}" data-original="{% block original_code %}{% endblock %}" data-blocklist="{{ form.CODE_BLOCKLIST|tojson|forceescape }}">
|
||||
<label class="form-label" for="accounting-code">{{ A_("Code") }}</label>
|
||||
<div id="accounting-code-error" class="invalid-feedback">{% if form.code.errors %}{{ form.code.errors[0] }}{% endif %}</div>
|
||||
</div>
|
||||
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-name" class="form-control {% if form.name.errors %} is-invalid {% endif %}" type="text" name="name" value="{{ "" if form.name.data is none else form.name.data }}" placeholder=" " required="required">
|
||||
<input id="accounting-name" class="form-control {% if form.name.errors %} is-invalid {% endif %}" type="text" name="name" value="{{ form.name.data|accounting_default }}" placeholder=" " required="required">
|
||||
<label class="form-label" for="accounting-name">{{ A_("Name") }}</label>
|
||||
<div id="accounting-name-error" class="invalid-feedback">{% if form.name.errors %}{{ form.name.errors[0] }}{% endif %}</div>
|
||||
</div>
|
||||
|
@ -21,7 +21,7 @@ First written: 2023/2/6
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block header %}{% block title %}{% if "q" in request.args %}{{ A_("Search Result for \"%(query)s\"", query=request.args["q"]) }}{% else %}{{ A_("Currency Management") }}{% endif %}{% endblock %}{% endblock %}
|
||||
{% block header %}{% block title %}{% if request.args.q %}{{ A_("Search Result for \"%(query)s\"", query=request.args.q) }}{% else %}{{ A_("Currency Management") }}{% endif %}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@ -32,8 +32,8 @@ First written: 2023/2/6
|
||||
{{ A_("New") }}
|
||||
</a>
|
||||
{% endif %}
|
||||
<form class="btn btn-primary d-flex input-group" action="{{ url_for("accounting.currency.list") }}" method="get" role="search" aria-label="{{ A_("Search for Desktop") }}">
|
||||
<input id="accounting-search-desktop" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args["q"] if "q" in request.args else "" }}" placeholder=" " required="required">
|
||||
<form class="btn btn-primary d-flex input-group accounting-search-desktop-form" action="{{ url_for("accounting.currency.list") }}" method="get" role="search" aria-label="{{ A_("Search for Desktop") }}">
|
||||
<input id="accounting-search-desktop" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-desktop" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
@ -45,7 +45,7 @@ First written: 2023/2/6
|
||||
|
||||
<div class="btn-group mb-2 d-md-none">
|
||||
<form class="btn btn-primary d-flex input-group" action="{{ url_for("accounting.currency.list") }}" method="get" role="search" aria-label="{{ A_("Search for Mobile") }}">
|
||||
<input id="accounting-search-mobile" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args["q"] if "q" in request.args else "" }}" placeholder=" " required="required">
|
||||
<input id="accounting-search-mobile" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-mobile" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
add-new-material-fab.html: The material floating action buttons to add a new transaction
|
||||
add-txn-material-fab.html: The material floating action buttons to add a new transaction
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
@ -22,13 +22,13 @@ First written: 2023/2/25
|
||||
{% if accounting_can_edit() %}
|
||||
<div id="accounting-material-fab-speed-dial" class="d-md-none accounting-material-fab">
|
||||
<div id="accounting-material-fab-speed-dial-actions" class="d-md-none accounting-material-fab-speed-dial-group">
|
||||
<a class="btn rounded-pill" href="{{ url_for("accounting.transaction.create", txn_type=types.expense)|accounting_append_next }}">
|
||||
<a class="btn rounded-pill" href="{{ url_for("accounting.transaction.create", txn_type=txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash expense") }}
|
||||
</a>
|
||||
<a class="btn rounded-pill" href="{{ url_for("accounting.transaction.create", txn_type=types.income)|accounting_append_next }}">
|
||||
<a class="btn rounded-pill" href="{{ url_for("accounting.transaction.create", txn_type=txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash income") }}
|
||||
</a>
|
||||
<a class="btn rounded-pill" href="{{ url_for("accounting.transaction.create", txn_type=types.transfer)|accounting_append_next }}">
|
||||
<a class="btn rounded-pill" href="{{ url_for("accounting.transaction.create", txn_type=txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</div>
|
@ -28,14 +28,14 @@ First written: 2023/1/26
|
||||
</span>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item {% if request.endpoint.startswith("accounting.transaction.") %} active {% endif %}" href="{{ url_for("accounting.transaction.list") }}">
|
||||
<i class="fa-solid fa-receipt"></i>
|
||||
{{ A_("Transactions") }}
|
||||
<a class="dropdown-item {% if request.endpoint.startswith("accounting.report.") %} active {% endif %}" href="{{ url_for("accounting.report.journal-default") }}">
|
||||
<i class="fa-solid fa-book"></i>
|
||||
{{ A_("Reports") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if request.endpoint.startswith("accounting.account.") %} active {% endif %}" href="{{ url_for("accounting.account.list") }}">
|
||||
<i class="fa-solid fa-list"></i>
|
||||
<i class="fa-solid fa-clipboard"></i>
|
||||
{{ A_("Accounts") }}
|
||||
</a>
|
||||
</li>
|
||||
|
245
src/accounting/templates/accounting/report/balance-sheet.html
Normal file
245
src/accounting/templates/accounting/report/balance-sheet.html
Normal file
@ -0,0 +1,245 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
income-statement.html: The income statement
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/7
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block accounting_scripts %}
|
||||
<script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/period-chooser.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}{% block title %}{{ _("Balance Sheet of %(currency)s %(period)s", currency=report.currency.name|title, period=report.period.desc|title) }}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="btn-group mb-2 d-none d-md-inline-flex">
|
||||
{% if accounting_can_edit() %}
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash Expense") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash Income") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
{{ report.currency.name|title }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ report.period.desc|title }}
|
||||
</button>
|
||||
<a class="btn btn-primary" role="button" href="{{ report.csv_uri }}">
|
||||
<i class="fa-solid fa-download"></i>
|
||||
{{ A_("Download") }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% with txn_types = report.txn_types %}
|
||||
{% include "accounting/include/add-txn-material-fab.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="btn-group btn-actions mb-3 d-md-none">
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ A_("Period") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{% with period = report.period, period_chooser = report.period_chooser %}
|
||||
{% include "accounting/report/include/period-chooser.html" %}
|
||||
{% endwith %}
|
||||
|
||||
{% include "accounting/report/include/search-modal.html" %}
|
||||
|
||||
{% if report.has_data %}
|
||||
<div class="accounting-sheet">
|
||||
<div class="d-none d-sm-flex justify-content-center mb-3">
|
||||
<h2 class="text-center">{{ _("Balance Sheet of %(currency)s %(period)s", currency=report.currency.name|title, period=report.period.desc|title) }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="row accounting-report-table accounting-balance-sheet-table">
|
||||
<div class="col-sm-6">
|
||||
{% if report.assets.subsections %}
|
||||
<div class="accounting-report-table-row accounting-balance-sheet-section">
|
||||
<div>{{ report.assets.title.title|title }}</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% for subsection in report.assets.subsections %}
|
||||
<div class="accounting-report-table-row accounting-balance-sheet-subsection">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ subsection.title.code }}</span>
|
||||
{{ subsection.title.title|title }}
|
||||
</div>
|
||||
</div>
|
||||
{% for account in subsection.accounts %}
|
||||
<a class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-account" href="{{ account.url }}">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ account.account.code }}</span>
|
||||
{{ account.account.title|title }}
|
||||
</div>
|
||||
<div class="accounting-amount {% if account.amount < 0 %} text-danger {% endif %}">{{ account.amount|accounting_report_format_amount }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="d-md-none d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-total">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount {% if report.assets.total < 0 %} text-danger {% endif %}">{{ report.assets.total|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6">
|
||||
{% if report.liabilities.subsections %}
|
||||
<div class="accounting-report-table-row accounting-balance-sheet-section">
|
||||
<div>{{ report.liabilities.title.title|title }}</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% for subsection in report.liabilities.subsections %}
|
||||
<div class="accounting-report-table-row accounting-balance-sheet-subsection">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ subsection.title.code }}</span>
|
||||
{{ subsection.title.title|title }}
|
||||
</div>
|
||||
</div>
|
||||
{% for account in subsection.accounts %}
|
||||
<a class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-account" href="{{ account.url }}">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ account.account.code }}</span>
|
||||
{{ account.account.title|title }}
|
||||
</div>
|
||||
<div class="accounting-amount {% if account.amount < 0 %} text-danger {% endif %}">{{ account.amount|accounting_report_format_amount }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-subtotal">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount {% if report.liabilities.total < 0 %} text-danger {% endif %}">{{ report.liabilities.total|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if report.owner_s_equity.subsections %}
|
||||
<div class="accounting-report-table-row accounting-balance-sheet-section">
|
||||
<div>{{ report.owner_s_equity.title.title|title }}</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% for subsection in report.owner_s_equity.subsections %}
|
||||
<div class="accounting-report-table-row accounting-balance-sheet-subsection">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ subsection.title.code }}</span>
|
||||
{{ subsection.title.title|title }}
|
||||
</div>
|
||||
</div>
|
||||
{% for account in subsection.accounts %}
|
||||
<a class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-account" href="{{ account.url }}">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ account.account.code }}</span>
|
||||
{{ account.account.title|title }}
|
||||
</div>
|
||||
<div class="accounting-amount {% if account.amount < 0 %} text-danger {% endif %}">{{ account.amount|accounting_report_format_amount }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-subtotal">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount {% if report.owner_s_equity.total < 0 %} text-danger {% endif %}">{{ report.owner_s_equity.total|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="d-md-none d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-total">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount {% if report.liabilities.total < 0 %} text-danger {% endif %}">{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row d-none d-md-flex">
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex justify-content-between accounting-balance-sheet-total">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount {% if report.assets.total < 0 %} text-danger {% endif %}">{{ report.assets.total|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6">
|
||||
<div class="d-flex justify-content-between accounting-balance-sheet-total">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount {% if report.liabilities.total + report.owner_s_equity.total < 0 %} text-danger {% endif %}">{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ A_("There is no data.") }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
@ -0,0 +1,50 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
income-expenses-mobile-row.html: The row in the income and expenses for the mobile devices
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/5
|
||||
#}
|
||||
<div>
|
||||
{% if entry.date or entry.account %}
|
||||
<div class="text-muted small">
|
||||
{% if entry.date %}
|
||||
{{ entry.date|accounting_format_date }}
|
||||
{% endif %}
|
||||
{% if entry.account %}
|
||||
{{ entry.account.title|title }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if entry.summary %}
|
||||
<div>{{ entry.summary }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="text-nowrap">
|
||||
{% if entry.income %}
|
||||
<span class="badge rounded-pill bg-success">+{{ entry.income|accounting_format_amount }}</span>
|
||||
{% endif %}
|
||||
{% if entry.expense %}
|
||||
<span class="badge rounded-pill bg-warning">-{{ entry.expense|accounting_format_amount }}</span>
|
||||
{% endif %}
|
||||
{% if entry.balance < 0 %}
|
||||
<span class="badge rounded-pill bg-danger">{{ entry.balance|accounting_format_amount }}</span>
|
||||
{% else %}
|
||||
<span class="badge rounded-pill bg-primary">{{ entry.balance|accounting_format_amount }}</span>
|
||||
{% endif %}
|
||||
</div>
|
@ -0,0 +1,41 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
ledger-mobile-row.html: The row in the ledger for the mobile devices
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/5
|
||||
#}
|
||||
<div>
|
||||
{% if entry.date %}
|
||||
<div class="text-muted small">
|
||||
{{ entry.date|accounting_format_date }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if entry.summary %}
|
||||
<div>{{ entry.summary }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{% if entry.debit %}
|
||||
<span class="badge rounded-pill bg-success">+{{ entry.debit|accounting_format_amount }}</span>
|
||||
{% endif %}
|
||||
{% if entry.credit %}
|
||||
<span class="badge rounded-pill bg-warning">-{{ entry.credit|accounting_format_amount }}</span>
|
||||
{% endif %}
|
||||
<span class="badge rounded-pill bg-primary">{{ entry.balance|accounting_format_amount }}</span>
|
||||
</div>
|
@ -0,0 +1,150 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
period-chooser.html: The period chooser
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/4
|
||||
#}
|
||||
<div id="accounting-period-chooser-modal" class="modal fade" tabindex="-1" aria-labelledby="accounting-period-chooser-modal-label" aria-hidden="true" data-url-template="{{ period_chooser.url_template }}">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="accounting-period-chooser-modal-label">{{ A_("Period Chooser") }}</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ A_("Close") }}"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{# Tab navigation #}
|
||||
<ul class="nav nav-tabs mb-2">
|
||||
<li class="nav-item">
|
||||
<span id="accounting-period-chooser-month-tab" class="nav-link {% if period.is_type_month %} active {% endif %} accounting-clickable" aria-current="{% if period.is_type_month %} page {% else %} false {% endif %}" data-tab-id="month">
|
||||
{{ A_("Month") }}
|
||||
</span>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<span id="accounting-period-chooser-year-tab" class="nav-link {% if period.is_a_year %} active {% endif %} accounting-clickable" aria-current="{% if period.is_a_year %} page {% else %} false {% endif %}" data-tab-id="year">
|
||||
{{ A_("Year") }}
|
||||
</span>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<span id="accounting-period-chooser-day-tab" class="nav-link {% if period.is_a_day %} active {% endif %} accounting-clickable" aria-current="{% if period.is_a_day %} page {% else %} false {% endif %}" data-tab-id="day">
|
||||
{{ A_("Day") }}
|
||||
</span>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<span id="accounting-period-chooser-custom-tab" class="nav-link {% if period.is_type_arbitrary %} active {% endif %} accounting-clickable" aria-current="{% if period.is_type_arbitrary %} page {% else %} false {% endif %}" data-tab-id="custom">
|
||||
{{ A_("Custom") }}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{# The month periods #}
|
||||
<div id="accounting-period-chooser-month-page" {% if period.is_type_month %} aria-current="page" {% else %} class="d-none" aria-current="false" {% endif %} aria-labelledby="accounting-period-chooser-month-tab">
|
||||
<div>
|
||||
<a class="btn {% if period.is_this_month %} btn-primary {% else %} btn-outline-primary {% endif %}" role="button" href="{{ period_chooser.this_month_url }}">
|
||||
{{ A_("This month") }}
|
||||
</a>
|
||||
{% if period_chooser.has_last_month %}
|
||||
<a class="btn {% if period.is_last_month %} btn-primary {% else %} btn-outline-primary {% endif %}" role="button" href="{{ period_chooser.last_month_url }}">
|
||||
{{ A_("Last month") }}
|
||||
</a>
|
||||
<a class="btn {% if period.is_since_last_month %} btn-primary {% else %} btn-outline-primary {% endif %}" role="button" href="{{ period_chooser.since_last_month_url }}">
|
||||
{{ A_("Since last month") }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if period_chooser.has_data %}
|
||||
<div id="accounting-period-chooser-month-chooser" class="mt-3" data-start="{{ period_chooser.data_start }}" data-default="{{ period.start }}"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{# The year periods #}
|
||||
<div id="accounting-period-chooser-year-page" {% if period.is_a_year %} aria-current="page" {% else %} class="d-none" aria-current="false" {% endif %} aria-labelledby="accounting-period-chooser-year-tab">
|
||||
<a class="btn {% if period.is_this_year %} btn-primary {% else %} btn-outline-primary {% endif %}" role="button" href="{{ period_chooser.this_year_url }}">
|
||||
{{ A_("This year") }}
|
||||
</a>
|
||||
{% if period_chooser.has_last_year %}
|
||||
<a class="btn {% if period.is_last_year %} btn-primary {% else %} btn-outline-primary {% endif %}" role="button" href="{{ period_chooser.last_year_url }}">
|
||||
{{ A_("Last year") }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if period_chooser.available_years %}
|
||||
<ul class="nav nav-pills mt-3">
|
||||
{% for year in period_chooser.available_years %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if period.is_year(year) %} active {% endif %}" href="{{ period_chooser.year_url(year) }}">{{ year }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{# The day periods #}
|
||||
<div id="accounting-period-chooser-day-page" {% if period.is_a_day %} aria-current="page" {% else %} class="d-none" aria-current="false" {% endif %} aria-labelledby="accounting-period-chooser-day-tab">
|
||||
<div>
|
||||
<a class="btn {% if period.is_today %} btn-primary {% else %} btn-outline-primary {% endif %}" role="button" href="{{ period_chooser.today_url }}">
|
||||
{{ A_("Today") }}
|
||||
</a>
|
||||
{% if period_chooser.has_yesterday %}
|
||||
<a class="btn {% if period.is_yesterday %} btn-primary {% else %} btn-outline-primary {% endif %}" role="button" href="{{ period_chooser.yesterday_url }}">
|
||||
{{ A_("Yesterday") }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if period_chooser.has_data %}
|
||||
<div class="mt-3">
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-period-chooser-day-date" class="form-control" type="date" value="{{ period.start|accounting_default }}" min="{{ period_chooser.data_start }}" required="required">
|
||||
<label for="accounting-period-chooser-day-date" class="form-label">{{ A_("Date") }}</label>
|
||||
<div id="accounting-period-chooser-day-date-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{# The custom periods #}
|
||||
<div id="accounting-period-chooser-custom-page" {% if period.is_type_arbitrary %} aria-current="page" {% else %} class="d-none" aria-current="false" {% endif %} aria-labelledby="accounting-period-chooser-custom-tab">
|
||||
<div>
|
||||
<a class="btn {% if period.is_all %} btn-primary {% else %} btn-outline-primary {% endif %}" role="button" href="{{ period_chooser.all_url }}">
|
||||
{{ A_("All") }}
|
||||
</a>
|
||||
</div>
|
||||
{% if period_chooser.has_data %}
|
||||
<div class="mt-3">
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-period-chooser-custom-start" class="form-control" type="date" value="{{ period.start|accounting_default }}" min="{{ period_chooser.data_start }}" max="{{ period.end }}" required="required">
|
||||
<label for="accounting-period-chooser-custom-start" class="form-label">{{ A_("From") }}</label>
|
||||
<div id="accounting-period-chooser-custom-start-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-period-chooser-custom-end" class="form-control" type="date" value="{{ period.end|accounting_default }}" min="{{ period.start }}" required="required">
|
||||
<label for="accounting-period-chooser-custom-end" class="form-label">{{ A_("To") }}</label>
|
||||
<div id="accounting-period-chooser-custom-end-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button id="accounting-period-chooser-custom-confirm" class="btn btn-primary" type="submit">
|
||||
{{ A_("Confirm") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,38 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
report-chooser.html: The report chooser
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/4
|
||||
#}
|
||||
<div class="btn-group" role="group">
|
||||
<button id="accounting-report-chooser" class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-book"></i>
|
||||
<span class="d-none d-md-inline">{{ report_chooser.current_report }}</span>
|
||||
<span class="d-md-none">{{ A_("Report") }}</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="accounting-report-chooser">
|
||||
{% for report in report_chooser %}
|
||||
<li><a class="dropdown-item {% if report.is_active %} active {% endif %}" href="{{ report.url }}">{{ report.title }}</a></li>
|
||||
{% endfor %}
|
||||
<li>
|
||||
<span class="dropdown-item accounting-clickable" data-bs-toggle="modal" data-bs-target="#accounting-search-modal">
|
||||
{{ A_("Search") }}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
@ -0,0 +1,43 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
search-modal.html: The search modal
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/8
|
||||
#}
|
||||
<form action="{{ url_for("accounting.report.search") }}" method="get" role="search" aria-label="{{ A_("Search the Accounting Data") }}">
|
||||
<div class="modal fade" id="accounting-search-modal" tabindex="-1" aria-labelledby="accounting-search-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="accounting-search-modal-label">{{ A_("Search") }}</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ A_("Close") }}"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-floating">
|
||||
<input id="accounting-search-modal-search" class="form-control" type="text" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-modal-search">{{ A_("Search") }}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ A_("Cancel") }}</button>
|
||||
<button type="submit" class="btn btn-primary">{{ A_("Search") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
230
src/accounting/templates/accounting/report/income-expenses.html
Normal file
230
src/accounting/templates/accounting/report/income-expenses.html
Normal file
@ -0,0 +1,230 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
income-expenses.html: The income and expenses
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/5
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block accounting_scripts %}
|
||||
<script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/period-chooser.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/table-row-link.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}{% block title %}{{ _("Income and Expenses of %(account)s in %(currency)s %(period)s", currency=report.currency.name|title, account=report.account|title, period=report.period.desc|title) }}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="btn-group mb-2 d-none d-md-inline-flex">
|
||||
{% if accounting_can_edit() %}
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash Expense") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash Income") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
{{ report.currency.name|title }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-clipboard"></i>
|
||||
{{ report.account.title|title }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for account in report.account_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if account.is_active %} active {% endif %}" href="{{ account.url }}">
|
||||
{{ account.title|title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ report.period.desc|title }}
|
||||
</button>
|
||||
<a class="btn btn-primary" role="button" href="{{ report.csv_uri }}">
|
||||
<i class="fa-solid fa-download"></i>
|
||||
{{ A_("Download") }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% with txn_types = report.txn_types %}
|
||||
{% include "accounting/include/add-txn-material-fab.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="btn-group btn-actions mb-3 d-md-none">
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-clipboard"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for account in report.account_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if account.is_active %} active {% endif %}" href="{{ account.url }}">
|
||||
{{ account.title|title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ A_("Period") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{% with period = report.period, period_chooser = report.period_chooser %}
|
||||
{% include "accounting/report/include/period-chooser.html" %}
|
||||
{% endwith %}
|
||||
|
||||
{% include "accounting/report/include/search-modal.html" %}
|
||||
|
||||
{% if report.has_data %}
|
||||
{% with pagination = report.pagination %}
|
||||
{% include "accounting/include/pagination.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="d-none d-md-block accounting-report-table accounting-income-expenses-table">
|
||||
<div class="accounting-report-table-header">
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ A_("Date") }}</div>
|
||||
<div>{{ A_("Account") }}</div>
|
||||
<div>{{ A_("Summary") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Income") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Expense") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Balance") }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% if report.brought_forward %}
|
||||
{% with entry = report.brought_forward %}
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ entry.date|accounting_format_date }}</div>
|
||||
<div>{{ entry.account.title|title }}</div>
|
||||
<div>{{ entry.summary|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.income|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.expense|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% for entry in report.entries %}
|
||||
<a class="accounting-report-table-row" href="{{ url_for("accounting.transaction.detail", txn=entry.transaction)|accounting_append_next }}">
|
||||
<div>{{ entry.date|accounting_format_date }}</div>
|
||||
<div>{{ entry.account.title|title }}</div>
|
||||
<div>{{ entry.summary|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.income|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.expense|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if report.total %}
|
||||
{% with entry = report.total %}
|
||||
<div class="accounting-report-table-footer">
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount">{{ entry.income|accounting_format_amount }}</div>
|
||||
<div class="accounting-amount">{{ entry.expense|accounting_format_amount }}</div>
|
||||
<div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="list-group d-md-none">
|
||||
{% if report.brought_forward %}
|
||||
{% with entry = report.brought_forward %}
|
||||
<div class="list-group-item list-group-item-action d-flex justify-content-between">
|
||||
{% include "accounting/report/include/income-expenses-mobile-row.html" %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% for entry in report.entries %}
|
||||
<a class="list-group-item list-group-item-action d-flex justify-content-between" href="{{ url_for("accounting.transaction.detail", txn=entry.transaction)|accounting_append_next }}">
|
||||
{% include "accounting/report/include/income-expenses-mobile-row.html" %}
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% if report.total %}
|
||||
{% with entry = report.total %}
|
||||
<div class="list-group-item list-group-item-action d-flex justify-content-between">
|
||||
{% include "accounting/report/include/income-expenses-mobile-row.html" %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ A_("There is no data.") }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
174
src/accounting/templates/accounting/report/income-statement.html
Normal file
174
src/accounting/templates/accounting/report/income-statement.html
Normal file
@ -0,0 +1,174 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
income-statement.html: The income statement
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/7
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block accounting_scripts %}
|
||||
<script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/period-chooser.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}{% block title %}{{ _("Income Statement of %(currency)s %(period)s", currency=report.currency.name|title, period=report.period.desc|title) }}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="btn-group mb-2 d-none d-md-inline-flex">
|
||||
{% if accounting_can_edit() %}
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash Expense") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash Income") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
{{ report.currency.name|title }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ report.period.desc|title }}
|
||||
</button>
|
||||
<a class="btn btn-primary" role="button" href="{{ report.csv_uri }}">
|
||||
<i class="fa-solid fa-download"></i>
|
||||
{{ A_("Download") }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% with txn_types = report.txn_types %}
|
||||
{% include "accounting/include/add-txn-material-fab.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="btn-group btn-actions mb-3 d-md-none">
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ A_("Period") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{% with period = report.period, period_chooser = report.period_chooser %}
|
||||
{% include "accounting/report/include/period-chooser.html" %}
|
||||
{% endwith %}
|
||||
|
||||
{% include "accounting/report/include/search-modal.html" %}
|
||||
|
||||
{% if report.has_data %}
|
||||
<div class="accounting-sheet">
|
||||
<div class="d-none d-sm-flex justify-content-center mb-3">
|
||||
<h2 class="text-center">{{ _("Income Statement of %(currency)s %(period)s", currency=report.currency.name|title, period=report.period.desc|title) }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="accounting-report-table accounting-income-statement-table">
|
||||
<div class="accounting-report-table-header">
|
||||
<div class="accounting-report-table-row">
|
||||
<div class="accounting-amount">{{ A_("Amount") }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% for section in report.sections %}
|
||||
<div class="accounting-report-table-row accounting-income-statement-section">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ section.title.code }}</span>
|
||||
{{ section.title.title|title }}
|
||||
</div>
|
||||
</div>
|
||||
{% for subsection in section.subsections %}
|
||||
<div class="accounting-report-table-row accounting-income-statement-subsection">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ subsection.title.code }}</span>
|
||||
{{ subsection.title.title|title }}
|
||||
</div>
|
||||
</div>
|
||||
{% for account in subsection.accounts %}
|
||||
<a class="accounting-report-table-row accounting-income-statement-account" href="{{ account.url }}">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ account.account.code }}</span>
|
||||
{{ account.account.title|title }}
|
||||
</div>
|
||||
<div class="accounting-amount {% if account.amount < 0 %} text-danger {% endif %}">{{ account.amount|accounting_report_format_amount }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
<div class="accounting-report-table-row accounting-income-statement-subtotal">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount {% if subsection.total < 0 %} text-danger {% endif %}">{{ subsection.total|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="accounting-report-table-row accounting-income-statement-total">
|
||||
<div>{{ section.accumulated.title|title }}</div>
|
||||
<div class="accounting-amount {% if section.accumulated.amount < 0 %} text-danger {% endif %}">{{ section.accumulated.amount|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ A_("There is no data.") }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
154
src/accounting/templates/accounting/report/journal.html
Normal file
154
src/accounting/templates/accounting/report/journal.html
Normal file
@ -0,0 +1,154 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
journal.html: The journal
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/4
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block accounting_scripts %}
|
||||
<script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/period-chooser.js") }}"></script>
|
||||
{# <script src="{{ url_for("accounting.static", filename="js/table-row-link.js") }}"></script> #}
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}{% block title %}{{ _("Journal %(period)s", period=report.period.desc|title) }}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="btn-group mb-2 d-none d-md-inline-flex">
|
||||
{% if accounting_can_edit() %}
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash Expense") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash Income") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ report.period.desc|title }}
|
||||
</button>
|
||||
<a class="btn btn-primary" role="button" href="{{ report.csv_uri }}">
|
||||
<i class="fa-solid fa-download"></i>
|
||||
{{ A_("Download") }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% with txn_types = report.txn_types %}
|
||||
{% include "accounting/include/add-txn-material-fab.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="btn-group btn-actions mb-3 d-md-none">
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ A_("Period") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{% with period = report.period, period_chooser = report.period_chooser %}
|
||||
{% include "accounting/report/include/period-chooser.html" %}
|
||||
{% endwith %}
|
||||
|
||||
{% include "accounting/report/include/search-modal.html" %}
|
||||
|
||||
{% if report.has_data %}
|
||||
{% with pagination = report.pagination %}
|
||||
{% include "accounting/include/pagination.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="d-none d-md-block accounting-report-table accounting-journal-table">
|
||||
<div class="accounting-report-table-header">
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ A_("Date") }}</div>
|
||||
<div>{{ A_("Currency") }}</div>
|
||||
<div>{{ A_("Account") }}</div>
|
||||
<div>{{ A_("Summary") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Debit") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Credit") }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% for entry in report.entries %}
|
||||
<a class="accounting-report-table-row" href="{{ url_for("accounting.transaction.detail", txn=entry.transaction)|accounting_append_next }}">
|
||||
<div>{{ entry.transaction.date|accounting_format_date }}</div>
|
||||
<div>{{ entry.currency.name }}</div>
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ entry.account.code }}</span>
|
||||
{{ entry.account.title|title }}
|
||||
</div>
|
||||
<div>{{ entry.summary|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list-group d-md-none">
|
||||
{% for entry in report.entries %}
|
||||
<a class="list-group-item list-group-item-action" href="{{ url_for("accounting.transaction.detail", txn=entry.transaction)|accounting_append_next }}">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div {% if not entry.is_debit %} class="accounting-mobile-journal-credit" {% endif %}>
|
||||
<div class="text-muted small">
|
||||
{{ entry.transaction.date|accounting_format_date }}
|
||||
{{ entry.account.title|title }}
|
||||
{% if entry.currency.code != accounting_default_currency_code() %}
|
||||
<span class="badge rounded-pill bg-info">{{ entry.currency.code }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if entry.summary is not none %}
|
||||
<div>{{ entry.summary }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="badge rounded-pill bg-info">{{ entry.amount|accounting_format_amount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ A_("There is no data.") }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
227
src/accounting/templates/accounting/report/ledger.html
Normal file
227
src/accounting/templates/accounting/report/ledger.html
Normal file
@ -0,0 +1,227 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
ledger.html: The ledger
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/5
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block accounting_scripts %}
|
||||
<script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/period-chooser.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/table-row-link.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}{% block title %}{{ _("Ledger of %(account)s in %(currency)s %(period)s", currency=report.currency.name|title, account=report.account|title, period=report.period.desc|title) }}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="btn-group mb-2 d-none d-md-inline-flex">
|
||||
{% if accounting_can_edit() %}
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash Expense") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash Income") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
{{ report.currency.name|title }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-clipboard"></i>
|
||||
{{ report.account.title|title }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for account in report.account_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if account.is_active %} active {% endif %}" href="{{ account.url }}">
|
||||
{{ account.title|title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ report.period.desc|title }}
|
||||
</button>
|
||||
<a class="btn btn-primary" role="button" href="{{ report.csv_uri }}">
|
||||
<i class="fa-solid fa-download"></i>
|
||||
{{ A_("Download") }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% with txn_types = report.txn_types %}
|
||||
{% include "accounting/include/add-txn-material-fab.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="btn-group btn-actions mb-3 d-md-none">
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-clipboard"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for account in report.account_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if account.is_active %} active {% endif %}" href="{{ account.url }}">
|
||||
{{ account.title|title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ A_("Period") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{% with period = report.period, period_chooser = report.period_chooser %}
|
||||
{% include "accounting/report/include/period-chooser.html" %}
|
||||
{% endwith %}
|
||||
|
||||
{% include "accounting/report/include/search-modal.html" %}
|
||||
|
||||
{% if report.has_data %}
|
||||
{% with pagination = report.pagination %}
|
||||
{% include "accounting/include/pagination.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="d-none d-md-block accounting-report-table accounting-ledger-table">
|
||||
<div class="accounting-report-table-header">
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ A_("Date") }}</div>
|
||||
<div>{{ A_("Summary") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Debit") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Credit") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Balance") }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% if report.brought_forward %}
|
||||
{% with entry = report.brought_forward %}
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ entry.date|accounting_format_date }}</div>
|
||||
<div>{{ entry.summary|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% for entry in report.entries %}
|
||||
<a class="accounting-report-table-row" href="{{ url_for("accounting.transaction.detail", txn=entry.transaction)|accounting_append_next }}">
|
||||
<div>{{ entry.date|accounting_format_date }}</div>
|
||||
<div>{{ entry.summary|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if report.total %}
|
||||
{% with entry = report.total %}
|
||||
<div class="accounting-report-table-footer">
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="list-group d-md-none">
|
||||
{% if report.brought_forward %}
|
||||
{% with entry = report.brought_forward %}
|
||||
<div class="list-group-item list-group-item-action d-flex justify-content-between">
|
||||
{% include "accounting/report/include/ledger-mobile-row.html" %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% for entry in report.entries %}
|
||||
<a class="list-group-item list-group-item-action d-flex justify-content-between" href="{{ url_for("accounting.transaction.detail", txn=entry.transaction)|accounting_append_next }}">
|
||||
{% include "accounting/report/include/ledger-mobile-row.html" %}
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% if report.total %}
|
||||
{% with entry = report.total %}
|
||||
<div class="list-group-item list-group-item-action d-flex justify-content-between">
|
||||
{% include "accounting/report/include/ledger-mobile-row.html" %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ A_("There is no data.") }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
159
src/accounting/templates/accounting/report/search.html
Normal file
159
src/accounting/templates/accounting/report/search.html
Normal file
@ -0,0 +1,159 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
search.html: The search result
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/8
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block accounting_scripts %}
|
||||
<script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/period-chooser.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}{% block title %}{{ A_("Search Result for \"%(query)s\"", query=request.args.q) }}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="btn-group mb-2 d-none d-md-inline-flex">
|
||||
{% if accounting_can_edit() %}
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash Expense") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash Income") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<form class="btn btn-primary d-flex input-group accounting-search-desktop-form" action="{{ url_for("accounting.report.search") }}" method="get" role="search" aria-label="{{ A_("Search for Desktop") }}">
|
||||
<input id="accounting-search-desktop" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-desktop" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
{{ A_("Search") }}
|
||||
</button>
|
||||
</label>
|
||||
</form>
|
||||
<a class="btn btn-primary" role="button" href="{{ report.csv_uri }}">
|
||||
<i class="fa-solid fa-download"></i>
|
||||
{{ A_("Download") }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% with txn_types = report.txn_types %}
|
||||
{% include "accounting/include/add-txn-material-fab.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="btn-group btn-actions mb-3 d-md-none">
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<form class="btn btn-primary d-flex input-group" action="{{ url_for("accounting.report.search") }}" method="get" role="search" aria-label="{{ A_("Search for Mobile") }}">
|
||||
<input id="accounting-search-mobile" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-mobile" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
{{ A_("Search") }}
|
||||
</button>
|
||||
</label>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% include "accounting/report/include/search-modal.html" %}
|
||||
|
||||
{% if report.has_data %}
|
||||
{% with pagination = report.pagination %}
|
||||
{% include "accounting/include/pagination.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="d-none d-md-block accounting-report-table accounting-journal-table">
|
||||
<div class="accounting-report-table-header">
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ A_("Date") }}</div>
|
||||
<div>{{ A_("Currency") }}</div>
|
||||
<div>{{ A_("Account") }}</div>
|
||||
<div>{{ A_("Summary") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Debit") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Credit") }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% for entry in report.entries %}
|
||||
<a class="accounting-report-table-row" href="{{ url_for("accounting.transaction.detail", txn=entry.transaction)|accounting_append_next }}">
|
||||
<div>{{ entry.transaction.date|accounting_format_date }}</div>
|
||||
<div>{{ entry.currency.name }}</div>
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ entry.account.code }}</span>
|
||||
{{ entry.account.title|title }}
|
||||
</div>
|
||||
<div>{{ entry.summary|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list-group d-md-none">
|
||||
{% for entry in report.entries %}
|
||||
<a class="list-group-item list-group-item-action" href="{{ url_for("accounting.transaction.detail", txn=entry.transaction)|accounting_append_next }}">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div {% if not entry.is_debit %} class="accounting-mobile-journal-credit" {% endif %}>
|
||||
<div class="text-muted small">
|
||||
{{ entry.transaction.date|accounting_format_date }}
|
||||
{{ entry.account.title|title }}
|
||||
{% if entry.currency.code != accounting_default_currency_code() %}
|
||||
<span class="badge rounded-pill bg-info">{{ entry.currency.code }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if entry.summary is not none %}
|
||||
<div>{{ entry.summary }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="badge rounded-pill bg-info">{{ entry.amount|accounting_format_amount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ A_("There is no data.") }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
159
src/accounting/templates/accounting/report/trial-balance.html
Normal file
159
src/accounting/templates/accounting/report/trial-balance.html
Normal file
@ -0,0 +1,159 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
trial-balance.html: The trial balance
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/3/5
|
||||
#}
|
||||
{% extends "accounting/base.html" %}
|
||||
|
||||
{% block accounting_scripts %}
|
||||
<script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/period-chooser.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}{% block title %}{{ _("Trial Balance of %(currency)s %(period)s", currency=report.currency.name|title, period=report.period.desc|title) }}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="btn-group mb-2 d-none d-md-inline-flex">
|
||||
{% if accounting_can_edit() %}
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash Expense") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash Income") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=report.txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
{{ report.currency.name|title }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ report.period.desc|title }}
|
||||
</button>
|
||||
<a class="btn btn-primary" role="button" href="{{ report.csv_uri }}">
|
||||
<i class="fa-solid fa-download"></i>
|
||||
{{ A_("Download") }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% with txn_types = report.txn_types %}
|
||||
{% include "accounting/include/add-txn-material-fab.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="btn-group btn-actions mb-3 d-md-none">
|
||||
{% with report_chooser = report.report_chooser %}
|
||||
{% include "accounting/report/include/report-chooser.html" %}
|
||||
{% endwith %}
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-money-bill-wave"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% for currency in report.currency_options %}
|
||||
<li>
|
||||
<a class="dropdown-item {% if currency.is_active %} active {% endif %}" href="{{ currency.url }}">
|
||||
{{ currency.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-period-chooser-modal">
|
||||
<i class="fa-solid fa-calendar-day"></i>
|
||||
{{ A_("Period") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{% with period = report.period, period_chooser = report.period_chooser %}
|
||||
{% include "accounting/report/include/period-chooser.html" %}
|
||||
{% endwith %}
|
||||
|
||||
{% include "accounting/report/include/search-modal.html" %}
|
||||
|
||||
{% if report.has_data %}
|
||||
<div class="accounting-sheet">
|
||||
<div class="d-none d-sm-flex justify-content-center mb-3">
|
||||
<h2 class="text-center">{{ _("Trial Balance of %(currency)s %(period)s", currency=report.currency.name|title, period=report.period.desc|title) }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="accounting-report-table accounting-trial-balance-table">
|
||||
<div class="accounting-report-table-header">
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ A_("Account") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Debit") }}</div>
|
||||
<div class="accounting-amount">{{ A_("Credit") }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accounting-report-table-body">
|
||||
{% for account in report.accounts %}
|
||||
<a class="accounting-report-table-row" href="{{ account.url }}">
|
||||
<div>
|
||||
<span class="d-none d-md-inline">{{ account.account.code }}</span>
|
||||
{{ account.account.title|title }}
|
||||
</div>
|
||||
<div class="accounting-amount">{{ account.debit|accounting_format_amount|accounting_default }}</div>
|
||||
<div class="accounting-amount">{{ account.credit|accounting_format_amount|accounting_default }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="accounting-report-table-footer">
|
||||
<div class="accounting-report-table-row">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div class="accounting-amount">{{ report.total.debit|accounting_format_amount }}</div>
|
||||
<div class="accounting-amount">{{ report.total.credit|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ A_("There is no data.") }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
@ -44,14 +44,14 @@ First written: 2023/2/26
|
||||
<div>{{ entry.summary }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>{{ entry.amount|accounting_txn_format_amount }}</div>
|
||||
<div>{{ entry.amount|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li class="list-group-item accounting-transaction-entry accounting-transaction-entry-total">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div>{{ currency.debit_total|accounting_txn_format_amount }}</div>
|
||||
<div>{{ currency.debit_total|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -25,7 +25,7 @@ First written: 2023/2/25
|
||||
<div class="d-flex justify-content-between mt-2 mb-3">
|
||||
<div class="form-floating accounting-currency-content">
|
||||
<select id="accounting-currency-{{ currency_index }}-code" class="form-select" name="currency-{{ currency_index }}-code">
|
||||
{% for currency in accounting_txn_currency_options() %}
|
||||
{% for currency in accounting_currency_options() %}
|
||||
<option value="{{ currency.code }}" {% if currency.code == currency_code_data %} selected="selected" {% endif %}>{{ currency }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
@ -50,14 +50,14 @@ First written: 2023/2/25
|
||||
entry_index = loop.index,
|
||||
entry_id = entry_form.eid.data,
|
||||
only_one_entry_form = debit_forms|length == 1,
|
||||
account_code_data = "" if entry_form.account_code.data is none else entry_form.account_code.data,
|
||||
account_code_data = entry_form.account_code.data|accounting_default,
|
||||
account_code_error = entry_form.account_code.errors,
|
||||
account_text = entry_form.account_text,
|
||||
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
||||
summary_data = entry_form.summary.data|accounting_default,
|
||||
summary_errors = entry_form.summary.errors,
|
||||
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_data = entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_errors = entry_form.amount.errors,
|
||||
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
||||
amount_text = entry_form.amount.data|accounting_format_amount|accounting_default("-"),
|
||||
entry_errors = entry_form.all_errors %}
|
||||
{% include "accounting/transaction/include/form-entry-item.html" %}
|
||||
{% endwith %}
|
||||
@ -70,7 +70,7 @@ First written: 2023/2/25
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button class="btn btn-primary accounting-btn-new-entry accounting-currency-{{ currency_index }}-btn-new-entry" type="button" data-currency-index="{{ currency_index }}" data-entry-type="debit" data-entry-index="new" data-account-modal="#accounting-debit-account-selector-modal" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<button class="btn btn-primary accounting-btn-new-entry accounting-currency-{{ currency_index }}-btn-new-entry" type="button" data-currency-index="{{ currency_index }}" data-entry-type="debit" data-entry-index="new" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<i class="fas fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
|
@ -31,20 +31,26 @@ First written: 2023/2/25
|
||||
currency_code_errors = currency_form.code.errors,
|
||||
debit_forms = currency_form.debit,
|
||||
debit_errors = currency_form.debit_errors,
|
||||
debit_total = currency_form.form.debit_total|accounting_txn_format_amount %}
|
||||
debit_total = currency_form.form.debit_total|accounting_format_amount %}
|
||||
{% include "accounting/transaction/expense/include/form-currency-item.html" %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% with currency_index = 1,
|
||||
only_one_currency_form = True,
|
||||
currency_code_data = accounting_txn_default_currency_code(),
|
||||
currency_code_data = accounting_default_currency_code(),
|
||||
debit_total = "-" %}
|
||||
{% include "accounting/transaction/expense/include/form-currency-item.html" %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block account_selector_modals %}
|
||||
{% include "accounting/transaction/include/debit-account-modal.html" %}
|
||||
{% block form_modals %}
|
||||
{% with summary_editor = form.summary_editor.debit %}
|
||||
{% include "accounting/transaction/include/summary-editor-modal.html" %}
|
||||
{% endwith %}
|
||||
{% with entry_type = "debit",
|
||||
account_options = form.debit_account_options %}
|
||||
{% include "accounting/transaction/include/account-selector-modal.html" %}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
@ -0,0 +1,54 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
account-selector-modal.html: The modal for the account selector
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/2/25
|
||||
#}
|
||||
<div id="accounting-account-selector-{{ entry_type }}-modal" class="modal fade accounting-account-selector-modal" data-entry-type="{{ entry_type }}" tabindex="-1" aria-labelledby="accounting-account-selector-{{ entry_type }}-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="accounting-account-selector-{{ entry_type }}-modal-label">{{ A_("Select Account") }}</h1>
|
||||
<button type="button" class="btn-close" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal" aria-label="{{ A_("Close") }}"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="input-group mb-2">
|
||||
<input id="accounting-account-selector-{{ entry_type }}-query" class="form-control form-control-sm" type="search" placeholder=" " required="required">
|
||||
<label class="input-group-text" for="accounting-account-selector-{{ entry_type }}-query">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
{{ A_("Search") }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<ul id="accounting-account-selector-{{ entry_type }}-option-list" class="list-group accounting-selector-list">
|
||||
{% for account in account_options %}
|
||||
<li id="accounting-account-selector-{{ entry_type }}-option-{{ account.code }}" class="list-group-item accounting-clickable accounting-account-selector-{{ entry_type }}-option {% if account.is_in_use %} accounting-account-in-use {% endif %}" data-code="{{ account.code }}" data-content="{{ account }}" data-query-values="{{ account.query_values|tojson|forceescape }}" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
{{ account }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li id="accounting-account-selector-{{ entry_type }}-more" class="list-group-item accounting-clickable">{{ A_("More…") }}</li>
|
||||
</ul>
|
||||
<p id="accounting-account-selector-{{ entry_type }}-option-no-result" class="d-none">{{ A_("There is no data.") }}</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">{{ A_("Cancel") }}</button>
|
||||
<button id="accounting-account-selector-{{ entry_type }}-btn-clear" type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">{{ A_("Clear") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,54 +0,0 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
credit-modals.html: The modals for the credit journal entry sub-form
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/2/25
|
||||
#}
|
||||
<div id="accounting-credit-account-selector-modal" class="modal fade accounting-selector-modal" data-prefix="accounting-credit-account" tabindex="-1" aria-labelledby="accounting-credit-account-selector-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="accounting-credit-account-selector-modal-label">{{ A_("Select Credit Account") }}</h1>
|
||||
<button type="button" class="btn-close" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal" aria-label="{{ A_("Close") }}"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="input-group mb-2">
|
||||
<input id="accounting-credit-account-selector-query" class="form-control form-control-sm" type="search" placeholder=" " required="required">
|
||||
<label class="input-group-text" for="accounting-credit-account-selector-query">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
{{ A_("Search") }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<ul id="accounting-credit-account-option-list" class="list-group accounting-selector-list">
|
||||
{% for account in form.credit_account_options %}
|
||||
<li id="accounting-credit-account-option-{{ account.code }}" class="list-group-item accounting-clickable accounting-credit-account-option {% if account.is_in_use %} accounting-account-in-use {% endif %}" data-code="{{ account.code }}" data-content="{{ account }}" data-query-values="{{ account.query_values|tojson|forceescape }}" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
{{ account }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li id="accounting-credit-account-more" class="list-group-item accounting-clickable">{{ A_("More…") }}</li>
|
||||
</ul>
|
||||
<p id="accounting-credit-account-option-no-result" class="d-none">{{ A_("There is no data.") }}</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">{{ A_("Cancel") }}</button>
|
||||
<button id="accounting-credit-account-btn-clear" type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">{{ A_("Clear") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,54 +0,0 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
credit-modals.html: The modals for the debit journal entry sub-form
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/2/25
|
||||
#}
|
||||
<div id="accounting-debit-account-selector-modal" class="modal fade accounting-selector-modal" data-prefix="accounting-debit-account" tabindex="-1" aria-labelledby="accounting-debit-account-selector-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="accounting-debit-account-selector-modal-label">{{ A_("Select Debit Account") }}</h1>
|
||||
<button type="button" class="btn-close" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal" aria-label="{{ A_("Close") }}"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="input-group mb-2">
|
||||
<input id="accounting-debit-account-selector-query" class="form-control form-control-sm" type="search" placeholder=" " required="required">
|
||||
<label class="input-group-text" for="accounting-debit-account-selector-query">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
{{ A_("Search") }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<ul id="accounting-debit-account-option-list" class="list-group accounting-selector-list">
|
||||
{% for account in form.debit_account_options %}
|
||||
<li id="accounting-debit-account-option-{{ account.code }}" class="list-group-item accounting-clickable accounting-debit-account-option {% if account.is_in_use %} accounting-account-in-use {% endif %}" data-code="{{ account.code }}" data-content="{{ account }}" data-query-values="{{ account.query_values|tojson|forceescape }}" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
{{ account }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li id="accounting-debit-account-more" class="list-group-item accounting-clickable">{{ A_("More…") }}</li>
|
||||
</ul>
|
||||
<p id="accounting-debit-account-option-no-result" class="d-none">{{ A_("There is no data.") }}</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">{{ A_("Cancel") }}</button>
|
||||
<button id="accounting-debit-account-btn-clear" type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">{{ A_("Clear") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -60,8 +60,8 @@ First written: 2023/2/26
|
||||
{% if accounting_can_edit() %}
|
||||
<form action="{{ url_for("accounting.transaction.delete", txn=obj) }}" method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if "next" in request.args %}
|
||||
<input type="hidden" name="next" value="{{ request.args["next"] }}">
|
||||
{% if request.args.next %}
|
||||
<input type="hidden" name="next" value="{{ request.args.next }}">
|
||||
{% endif %}
|
||||
<div class="modal fade" id="accounting-delete-modal" tabindex="-1" aria-labelledby="accounting-delete-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
@ -83,13 +83,13 @@ First written: 2023/2/26
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<div class="accounting-transaction-card">
|
||||
<div class="accounting-sheet">
|
||||
<div class="d-none d-sm-flex justify-content-center mb-3">
|
||||
<h2 class="text-center">{{ obj }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ obj.date|accounting_txn_format_date }}
|
||||
{{ obj.date|accounting_format_date }}
|
||||
</div>
|
||||
|
||||
{% block transaction_currencies %}{% endblock %}
|
||||
|
@ -36,9 +36,11 @@ First written: 2023/2/25
|
||||
<div id="accounting-entry-form-account-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-entry-form-summary" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label for="accounting-entry-form-summary">{{ A_("Summary") }}</label>
|
||||
<div class="mb-3">
|
||||
<div id="accounting-entry-form-summary-control" class="form-control accounting-clickable accounting-material-text-field" data-bs-toggle="modal" data-bs-target="">
|
||||
<label class="form-label" for="accounting-entry-form-summary">{{ A_("Summary") }}</label>
|
||||
<div id="accounting-entry-form-summary" data-value=""></div>
|
||||
</div>
|
||||
<div id="accounting-entry-form-summary-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
|
||||
|
@ -20,19 +20,19 @@ Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/2/25
|
||||
#}
|
||||
{# <ul> For SonarQube not to complain about incorrect HTML #}
|
||||
<li id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}" class="list-group-item list-group-item-action d-flex justify-content-between accounting-entry accounting-currency-{{ currency_index }}-{{ entry_type }}" data-currency-index="{{ currency_index }}" data-entry-type="{{ entry_type }}" data-entry-index="{{ entry_index }}" data-account-modal="#accounting-{{ entry_type }}-account-selector-modal" data-prefix="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}">
|
||||
<li id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}" class="list-group-item list-group-item-action d-flex justify-content-between accounting-entry accounting-currency-{{ currency_index }}-{{ entry_type }}" data-currency-index="{{ currency_index }}" data-entry-type="{{ entry_type }}" data-entry-index="{{ entry_index }}" data-prefix="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}">
|
||||
{% if entry_id %}
|
||||
<input type="hidden" name="currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-eid" value="{{ entry_id }}">
|
||||
{% endif %}
|
||||
<input id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-no" type="hidden" name="currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-no" value="{{ entry_index }}">
|
||||
<input id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-account-code" class="accounting-account-code" type="hidden" name="currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-account_code" value="{{ account_code_data }}" data-text="{{ account_text }}">
|
||||
<input id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-account-code" class="accounting-{{ entry_type }}-account-code" type="hidden" name="currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-account_code" value="{{ account_code_data }}" data-text="{{ account_text }}">
|
||||
<input id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-summary" type="hidden" name="currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-summary" value="{{ summary_data }}">
|
||||
<input id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-amount" class="accounting-currency-{{ currency_index }}-{{ entry_type }}-amount" type="hidden" name="currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-amount" value="{{ amount_data }}">
|
||||
<div class="accounting-entry-content">
|
||||
<div id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-control" class="form-control clickable d-flex justify-content-between accounting-entry-control {% if entry_errors %} is-invalid {% endif %}" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<div>
|
||||
<div id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-account-text" class="small">{{ account_text }}</div>
|
||||
<div id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-summary-text">{{ "" if summary_data is none else summary_data }}</div>
|
||||
<div id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-summary-text">{{ summary_data }}</div>
|
||||
</div>
|
||||
<div><span id="accounting-currency-{{ currency_index }}-{{ entry_type }}-{{ entry_index }}-amount-text" class="badge rounded-pill bg-primary">{{ amount_text }}</span></div>
|
||||
</div>
|
||||
|
@ -24,6 +24,8 @@ First written: 2023/2/26
|
||||
{% block accounting_scripts %}
|
||||
<script src="{{ url_for("accounting.static", filename="js/drag-and-drop-reorder.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/transaction-form.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/account-selector.js") }}"></script>
|
||||
<script src="{{ url_for("accounting.static", filename="js/summary-editor.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@ -37,12 +39,12 @@ First written: 2023/2/26
|
||||
|
||||
<form id="accounting-form" action="{% block action_url %}{% endblock %}" method="post" data-currency-template="{{ currency_template }}" data-entry-template="{{ entry_template }}">
|
||||
{{ form.csrf_token }}
|
||||
{% if "next" in request.args %}
|
||||
<input type="hidden" name="next" value="{{ request.args["next"] }}">
|
||||
{% if request.args.next %}
|
||||
<input type="hidden" name="next" value="{{ request.args.next }}">
|
||||
{% endif %}
|
||||
|
||||
<div class="form-floating mb-3">
|
||||
<input id="accounting-date" class="form-control {% if form.date.errors %} is-invalid {% endif %}" type="date" name="date" value="{{ "" if form.date.data is none else form.date.data }}" placeholder=" " required="required">
|
||||
<input id="accounting-date" class="form-control {% if form.date.errors %} is-invalid {% endif %}" type="date" name="date" value="{{ form.date.data|accounting_default }}" placeholder=" " required="required">
|
||||
<label class="form-label" for="accounting-date">{{ A_("Date") }}</label>
|
||||
<div id="accounting-date-error" class="invalid-feedback">{% if form.date.errors %}{{ form.date.errors[0] }}{% endif %}</div>
|
||||
</div>
|
||||
@ -65,7 +67,7 @@ First written: 2023/2/26
|
||||
</div>
|
||||
|
||||
<div class="form-floating mb-3">
|
||||
<textarea id="accounting-note" class="form-control form-control-lg {% if form.note.errors %} is-invalid {% endif %}" name="note" rows="5" placeholder=" ">{{ "" if form.note.data is none else form.note.data }}</textarea>
|
||||
<textarea id="accounting-note" class="form-control form-control-lg {% if form.note.errors %} is-invalid {% endif %}" name="note" rows="5" placeholder=" ">{{ form.note.data|accounting_default }}</textarea>
|
||||
<label class="form-label" for="accounting-note">{{ A_("Note") }}</label>
|
||||
<div id="accounting-note-error" class="invalid-feedback">{% if form.note.errors %}{{ form.note.errors[0] }}{% endif %}</div>
|
||||
</div>
|
||||
@ -85,6 +87,6 @@ First written: 2023/2/26
|
||||
</form>
|
||||
|
||||
{% include "accounting/transaction/include/entry-form-modal.html" %}
|
||||
{% block account_selector_modals %}{% endblock %}
|
||||
{% block form_modals %}{% endblock %}
|
||||
|
||||
{% endblock %}
|
||||
|
@ -0,0 +1,190 @@
|
||||
{#
|
||||
The Mia! Accounting Flask Project
|
||||
summary-editor-modal.html: The modal of the summary editor
|
||||
|
||||
Copyright (c) 2023 imacat.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/2/28
|
||||
#}
|
||||
<form id="accounting-summary-editor-{{ summary_editor.type }}" class="accounting-summary-editor" data-entry-type="{{ summary_editor.type }}">
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-modal" class="modal fade" tabindex="-1" aria-labelledby="accounting-summary-editor-{{ summary_editor.type }}-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="accounting-summary-editor-{{ summary_editor.type }}-modal-label">
|
||||
<label for="accounting-summary-editor-{{ summary_editor.type }}-summary">{{ A_("Summary") }}</label>
|
||||
</h1>
|
||||
<button class="btn-close" type="button" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal" aria-label="{{ A_("Close") }}"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-summary" class="form-control" type="text" aria-labelledby="accounting-summary-editor-{{ summary_editor.type }}-modal-label">
|
||||
</div>
|
||||
|
||||
{# Tab navigation #}
|
||||
<ul class="nav nav-tabs mb-2">
|
||||
<li class="nav-item">
|
||||
<span id="accounting-summary-editor-{{ summary_editor.type }}-general-tab" class="nav-link active accounting-clickable" aria-current="page">
|
||||
{{ A_("General") }}
|
||||
</span>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<span id="accounting-summary-editor-{{ summary_editor.type }}-travel-tab" class="nav-link accounting-clickable" aria-current="false">
|
||||
{{ A_("Travel") }}
|
||||
</span>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<span id="accounting-summary-editor-{{ summary_editor.type }}-bus-tab" class="nav-link accounting-clickable" aria-current="false">
|
||||
{{ A_("Bus") }}
|
||||
</span>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<span id="accounting-summary-editor-{{ summary_editor.type }}-regular-tab" class="nav-link accounting-clickable" aria-current="false">
|
||||
{{ A_("Regular") }}
|
||||
</span>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<span id="accounting-summary-editor-{{ summary_editor.type }}-annotation-tab" class="nav-link accounting-clickable" aria-current="false">
|
||||
{{ A_("Annotation") }}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{# A general summary with a tag #}
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-general-page" aria-current="page" aria-labelledby="accounting-summary-editor-{{ summary_editor.type }}-general-tab">
|
||||
<div class="form-floating mb-2">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-general-tag" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-general-tag">{{ A_("Tag") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-general-tag-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{% for tag in summary_editor.general.tags %}
|
||||
<button class="btn btn-outline-primary accounting-summary-editor-{{ summary_editor.type }}-general-btn-tag" type="button" tabindex="-1" data-value="{{ tag.name }}" data-accounts="{{ tag.account_codes|tojson|forceescape }}">
|
||||
{{ tag }}
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# A general trip with the origin and distination #}
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-travel-page" class="d-none" aria-current="false" aria-labelledby="accounting-summary-editor-{{ summary_editor.type }}-travel-tab">
|
||||
<div class="form-floating mb-2">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-travel-tag" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-travel-tag">{{ A_("Tag") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-travel-tag-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{% for tag in summary_editor.travel.tags %}
|
||||
<button class="btn btn-outline-primary accounting-summary-editor-{{ summary_editor.type }}-travel-btn-tag" type="button" tabindex="-1" data-value="{{ tag.name }}" data-accounts="{{ tag.account_codes|tojson|forceescape }}">
|
||||
{{ tag }}
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between mt-2">
|
||||
<div class="form-floating">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-travel-from" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-travel-from">{{ A_("From") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-travel-from-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
<div class="btn-group-vertical ms-1 me-1">
|
||||
<button class="btn btn-primary accounting-summary-editor-{{ summary_editor.type }}-travel-direction accounting-default" type="button" tabindex="-1" data-arrow="→">→</button>
|
||||
<button class="btn btn-outline-primary accounting-summary-editor-{{ summary_editor.type }}-travel-direction" type="button" tabindex="-1" data-arrow="↔">↔</button>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-travel-to" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-travel-to">{{ A_("To") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-travel-to-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# A bus trip with the route name or route number, the origin and distination #}
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-bus-page" class="d-none" aria-current="false" aria-labelledby="accounting-summary-editor-{{ summary_editor.type }}-bus-tab">
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<div class="form-floating me-2">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-bus-tag" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-bus-tag">{{ A_("Tag") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-bus-tag-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-bus-route" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-bus-route">{{ A_("Route") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-bus-route-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{% for tag in summary_editor.bus.tags %}
|
||||
<button class="btn btn-outline-primary accounting-summary-editor-{{ summary_editor.type }}-bus-btn-tag" type="button" tabindex="-1" data-value="{{ tag.name }}" data-accounts="{{ tag.account_codes|tojson|forceescape }}">
|
||||
{{ tag }}
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between mt-2">
|
||||
<div class="form-floating me-2">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-bus-from" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-bus-from">{{ A_("From") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-bus-from-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-bus-to" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-bus-to">{{ A_("To") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-bus-to-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# A regular income or payment #}
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-regular-page" class="d-none" aria-current="false" aria-labelledby="accounting-summary-editor-{{ summary_editor.type }}-regular-tab">
|
||||
{# TODO: To be done #}
|
||||
</div>
|
||||
|
||||
{# The annotation #}
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-annotation-page" class="d-none" aria-current="false" aria-labelledby="accounting-summary-editor-{{ summary_editor.type }}-annotation-tab">
|
||||
<div class="form-floating">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-annotation-number" class="form-control" type="number" min="1" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-annotation-number">{{ A_("The number of items") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-annotation-number-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-floating mt-2">
|
||||
<input id="accounting-summary-editor-{{ summary_editor.type }}-annotation-note" class="form-control" type="text" value="" placeholder=" ">
|
||||
<label class="form-label" for="accounting-summary-editor-{{ summary_editor.type }}-annotation-note">{{ A_("Note") }}</label>
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-annotation-note-error" class="invalid-feedback"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# The suggested accounts #}
|
||||
<div class="mt-3">
|
||||
{% for account in summary_editor.accounts %}
|
||||
<button class="btn btn-outline-primary d-none accounting-summary-editor-{{ summary_editor.type }}-account" type="button" data-code="{{ account.code }}" data-text="{{ account }}">
|
||||
{{ account }}
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">{{ A_("Cancel") }}</button>
|
||||
<button id="accounting-summary-editor-{{ summary_editor.type }}-btn-save" type="submit" class="btn btn-primary">{{ A_("Save") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -44,14 +44,14 @@ First written: 2023/2/26
|
||||
<div>{{ entry.summary }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>{{ entry.amount|accounting_txn_format_amount }}</div>
|
||||
<div>{{ entry.amount|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li class="list-group-item accounting-transaction-entry accounting-transaction-entry-total">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div>{{ currency.debit_total|accounting_txn_format_amount }}</div>
|
||||
<div>{{ currency.debit_total|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -25,7 +25,7 @@ First written: 2023/2/25
|
||||
<div class="d-flex justify-content-between mt-2 mb-3">
|
||||
<div class="form-floating accounting-currency-content">
|
||||
<select id="accounting-currency-{{ currency_index }}-code" class="form-select" name="currency-{{ currency_index }}-code">
|
||||
{% for currency in accounting_txn_currency_options() %}
|
||||
{% for currency in accounting_currency_options() %}
|
||||
<option value="{{ currency.code }}" {% if currency.code == currency_code_data %} selected="selected" {% endif %}>{{ currency }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
@ -50,14 +50,14 @@ First written: 2023/2/25
|
||||
entry_index = loop.index,
|
||||
only_one_entry_form = debit_forms|length == 1,
|
||||
entry_id = entry_form.eid.data,
|
||||
account_code_data = "" if entry_form.account_code.data is none else entry_form.account_code.data,
|
||||
account_code_data = entry_form.account_code.data|accounting_default,
|
||||
account_code_error = entry_form.account_code.errors,
|
||||
account_text = entry_form.account_text,
|
||||
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
||||
summary_data = entry_form.summary.data|accounting_default,
|
||||
summary_errors = entry_form.summary.errors,
|
||||
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_data = entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_errors = entry_form.amount.errors,
|
||||
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
||||
amount_text = entry_form.amount.data|accounting_format_amount|accounting_default("-"),
|
||||
entry_errors = entry_form.all_errors %}
|
||||
{% include "accounting/transaction/include/form-entry-item.html" %}
|
||||
{% endwith %}
|
||||
@ -70,7 +70,7 @@ First written: 2023/2/25
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button class="btn btn-primary accounting-btn-new-entry accounting-currency-{{ currency_index }}-btn-new-entry" type="button" data-currency-index="{{ currency_index }}" data-entry-type="credit" data-entry-index="new" data-account-modal="#accounting-credit-account-selector-modal" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<button class="btn btn-primary accounting-btn-new-entry accounting-currency-{{ currency_index }}-btn-new-entry" type="button" data-currency-index="{{ currency_index }}" data-entry-type="credit" data-entry-index="new" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<i class="fas fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
|
@ -31,20 +31,26 @@ First written: 2023/2/25
|
||||
currency_code_errors = currency_form.code.errors,
|
||||
credit_forms = currency_form.credit,
|
||||
credit_errors = currency_form.credit_errors,
|
||||
credit_total = currency_form.form.credit_total|accounting_txn_format_amount %}
|
||||
credit_total = currency_form.form.credit_total|accounting_format_amount %}
|
||||
{% include "accounting/transaction/income/include/form-currency-item.html" %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% with currency_index = 1,
|
||||
only_one_currency_form = True,
|
||||
currency_code_data = accounting_txn_default_currency_code(),
|
||||
currency_code_data = accounting_default_currency_code(),
|
||||
credit_total = "-" %}
|
||||
{% include "accounting/transaction/income/include/form-currency-item.html" %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block account_selector_modals %}
|
||||
{% include "accounting/transaction/include/credit-account-modal.html" %}
|
||||
{% block form_modals %}
|
||||
{% with summary_editor = form.summary_editor.credit %}
|
||||
{% include "accounting/transaction/include/summary-editor-modal.html" %}
|
||||
{% endwith %}
|
||||
{% with entry_type = "credit",
|
||||
account_options = form.credit_account_options %}
|
||||
{% include "accounting/transaction/include/account-selector-modal.html" %}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
@ -25,7 +25,7 @@ First written: 2023/2/18
|
||||
<script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}{% block title %}{% if "q" in request.args %}{{ A_("Search Result for \"%(query)s\"", query=request.args["q"]) }}{% else %}{{ A_("Transaction Management") }}{% endif %}{% endblock %}{% endblock %}
|
||||
{% block header %}{% block title %}{% if request.args.q %}{{ A_("Search Result for \"%(query)s\"", query=request.args.q) }}{% else %}{{ A_("Transaction Management") }}{% endif %}{% endblock %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@ -38,24 +38,24 @@ First written: 2023/2/18
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=types.expense)|accounting_append_next }}">
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=txn_types.CASH_EXPENSE)|accounting_append_next }}">
|
||||
{{ A_("Cash Expense") }}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=types.income)|accounting_append_next }}">
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=txn_types.CASH_INCOME)|accounting_append_next }}">
|
||||
{{ A_("Cash Income") }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=types.transfer)|accounting_append_next }}">
|
||||
<a class="dropdown-item" href="{{ url_for("accounting.transaction.create", txn_type=txn_types.TRANSFER)|accounting_append_next }}">
|
||||
{{ A_("Transfer") }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
<form class="btn btn-primary d-flex input-group" action="{{ url_for("accounting.transaction.list") }}" method="get" role="search" aria-label="{{ A_("Search for Desktop") }}">
|
||||
<input id="accounting-search-desktop" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args["q"] if "q" in request.args else "" }}" placeholder=" " required="required">
|
||||
<form class="btn btn-primary d-flex input-group accounting-search-desktop-form" action="{{ url_for("accounting.transaction.list") }}" method="get" role="search" aria-label="{{ A_("Search for Desktop") }}">
|
||||
<input id="accounting-search-desktop" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-desktop" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
@ -67,7 +67,7 @@ First written: 2023/2/18
|
||||
|
||||
<div class="btn-group mb-2 d-md-none">
|
||||
<form class="btn btn-primary d-flex input-group" action="{{ url_for("accounting.transaction.list") }}" method="get" role="search" aria-label="{{ A_("Search for Mobile") }}">
|
||||
<input id="accounting-search-mobile" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args["q"] if "q" in request.args else "" }}" placeholder=" " required="required">
|
||||
<input id="accounting-search-mobile" class="form-control form-control-sm accounting-search-input" type="search" name="q" value="{{ request.args.q }}" placeholder=" " required="required">
|
||||
<label for="accounting-search-mobile" class="accounting-search-label">
|
||||
<button type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
@ -77,7 +77,7 @@ First written: 2023/2/18
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% include "accounting/transaction/include/add-new-material-fab.html" %}
|
||||
{% include "accounting/include/add-txn-material-fab.html" %}
|
||||
|
||||
{% if list %}
|
||||
{% include "accounting/include/pagination.html" %}
|
||||
@ -85,7 +85,7 @@ First written: 2023/2/18
|
||||
<div class="list-group">
|
||||
{% for item in list %}
|
||||
<a class="list-group-item list-group-item-action" href="{{ url_for("accounting.transaction.detail", txn=item)|accounting_append_next }}">
|
||||
{{ item.date|accounting_txn_format_date }} {{ item }}
|
||||
{{ item.date|accounting_format_date }} {{ item }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
@ -40,8 +40,8 @@ First written: 2023/2/26
|
||||
{% if list|length > 1 and accounting_can_edit() %}
|
||||
<form action="{{ url_for("accounting.transaction.sort", txn_date=date) }}" method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if "next" in request.args %}
|
||||
<input type="hidden" name="next" value="{{ request.args["next"] }}">
|
||||
{% if request.args.next %}
|
||||
<input type="hidden" name="next" value="{{ request.args.next }}">
|
||||
{% endif %}
|
||||
<ul id="accounting-order-list" class="list-group mb-3">
|
||||
{% for item in list %}
|
||||
|
@ -40,14 +40,14 @@ First written: 2023/2/26
|
||||
<div>{{ entry.summary }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>{{ entry.amount|accounting_txn_format_amount }}</div>
|
||||
<div>{{ entry.amount|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li class="list-group-item accounting-transaction-entry accounting-transaction-entry-total">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div>{{ currency.debit_total|accounting_txn_format_amount }}</div>
|
||||
<div>{{ currency.debit_total|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@ -66,14 +66,14 @@ First written: 2023/2/26
|
||||
<div>{{ entry.summary }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>{{ entry.amount|accounting_txn_format_amount }}</div>
|
||||
<div>{{ entry.amount|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li class="list-group-item accounting-transaction-entry accounting-transaction-entry-total">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>{{ A_("Total") }}</div>
|
||||
<div>{{ currency.debit_total|accounting_txn_format_amount }}</div>
|
||||
<div>{{ currency.debit_total|accounting_format_amount }}</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -25,7 +25,7 @@ First written: 2023/2/25
|
||||
<div class="d-flex justify-content-between mt-2 mb-3">
|
||||
<div class="form-floating accounting-currency-content">
|
||||
<select id="accounting-currency-{{ currency_index }}-code" class="form-select" name="currency-{{ currency_index }}-code">
|
||||
{% for currency in accounting_txn_currency_options() %}
|
||||
{% for currency in accounting_currency_options() %}
|
||||
<option value="{{ currency.code }}" {% if currency.code == currency_code_data %} selected="selected" {% endif %}>{{ currency }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
@ -52,14 +52,14 @@ First written: 2023/2/25
|
||||
entry_index = loop.index,
|
||||
only_one_entry_form = debit_forms|length == 1,
|
||||
entry_id = entry_form.eid.data,
|
||||
account_code_data = "" if entry_form.account_code.data is none else entry_form.account_code.data,
|
||||
account_code_data = entry_form.account_code.data|accounting_default,
|
||||
account_code_error = entry_form.account_code.errors,
|
||||
account_text = entry_form.account_text,
|
||||
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
||||
summary_data = entry_form.summary.data|accounting_default,
|
||||
summary_errors = entry_form.summary.errors,
|
||||
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data,
|
||||
amount_data = entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_errors = entry_form.amount.errors,
|
||||
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
||||
amount_text = entry_form.amount.data|accounting_format_amount|accounting_default("-"),
|
||||
entry_errors = entry_form.all_errors %}
|
||||
{% include "accounting/transaction/include/form-entry-item.html" %}
|
||||
{% endwith %}
|
||||
@ -72,7 +72,7 @@ First written: 2023/2/25
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button class="btn btn-primary accounting-btn-new-entry accounting-currency-{{ currency_index }}-btn-new-entry" type="button" data-currency-index="{{ currency_index }}" data-entry-type="debit" data-entry-index="new" data-account-modal="#accounting-debit-account-selector-modal" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<button class="btn btn-primary accounting-btn-new-entry accounting-currency-{{ currency_index }}-btn-new-entry" type="button" data-currency-index="{{ currency_index }}" data-entry-type="debit" data-entry-index="new" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<i class="fas fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
@ -92,14 +92,14 @@ First written: 2023/2/25
|
||||
entry_type = "credit",
|
||||
entry_index = loop.index,
|
||||
only_one_entry_form = debit_forms|length == 1,
|
||||
account_code_data = "" if entry_form.account_code.data is none else entry_form.account_code.data,
|
||||
account_code_data = entry_form.account_code.data|accounting_default,
|
||||
account_code_error = entry_form.account_code.errors,
|
||||
account_text = entry_form.account_text,
|
||||
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
||||
summary_data = entry_form.summary.data|accounting_default,
|
||||
summary_errors = entry_form.summary.errors,
|
||||
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_data = entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_errors = entry_form.amount.errors,
|
||||
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
||||
amount_text = entry_form.amount.data|accounting_format_amount|accounting_default("-"),
|
||||
entry_errors = entry_form.all_errors %}
|
||||
{% include "accounting/transaction/include/form-entry-item.html" %}
|
||||
{% endwith %}
|
||||
@ -112,7 +112,7 @@ First written: 2023/2/25
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button class="btn btn-primary accounting-btn-new-entry accounting-currency-{{ currency_index }}-btn-new-entry" type="button" data-currency-index="{{ currency_index }}" data-entry-type="credit" data-entry-index="new" data-account-modal="#accounting-credit-account-selector-modal" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<button class="btn btn-primary accounting-btn-new-entry accounting-currency-{{ currency_index }}-btn-new-entry" type="button" data-currency-index="{{ currency_index }}" data-entry-type="credit" data-entry-index="new" data-bs-toggle="modal" data-bs-target="#accounting-entry-form-modal">
|
||||
<i class="fas fa-plus"></i>
|
||||
{{ A_("New") }}
|
||||
</button>
|
||||
|
@ -31,17 +31,17 @@ First written: 2023/2/25
|
||||
currency_code_errors = currency_form.code.errors,
|
||||
debit_forms = currency_form.debit,
|
||||
debit_errors = currency_form.debit_errors,
|
||||
debit_total = currency_form.form.debit_total|accounting_txn_format_amount,
|
||||
debit_total = currency_form.form.debit_total|accounting_format_amount,
|
||||
credit_forms = currency_form.credit,
|
||||
credit_errors = currency_form.credit_errors,
|
||||
credit_total = currency_form.form.credit_total|accounting_txn_format_amount %}
|
||||
credit_total = currency_form.form.credit_total|accounting_format_amount %}
|
||||
{% include "accounting/transaction/transfer/include/form-currency-item.html" %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% with currency_index = 1,
|
||||
only_one_currency_form = True,
|
||||
currency_code_data = accounting_txn_default_currency_code(),
|
||||
currency_code_data = accounting_default_currency_code(),
|
||||
debit_total = "-",
|
||||
credit_total = "-" %}
|
||||
{% include "accounting/transaction/transfer/include/form-currency-item.html" %}
|
||||
@ -49,7 +49,19 @@ First written: 2023/2/25
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block account_selector_modals %}
|
||||
{% include "accounting/transaction/include/debit-account-modal.html" %}
|
||||
{% include "accounting/transaction/include/credit-account-modal.html" %}
|
||||
{% block form_modals %}
|
||||
{% with summary_editor = form.summary_editor.debit %}
|
||||
{% include "accounting/transaction/include/summary-editor-modal.html" %}
|
||||
{% endwith %}
|
||||
{% with summary_editor = form.summary_editor.credit %}
|
||||
{% include "accounting/transaction/include/summary-editor-modal.html" %}
|
||||
{% endwith %}
|
||||
{% with entry_type = "debit",
|
||||
account_options = form.debit_account_options %}
|
||||
{% include "accounting/transaction/include/account-selector-modal.html" %}
|
||||
{% endwith %}
|
||||
{% with entry_type = "credit",
|
||||
account_options = form.credit_account_options %}
|
||||
{% include "accounting/transaction/include/account-selector-modal.html" %}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
@ -24,8 +24,7 @@ from werkzeug.routing import BaseConverter
|
||||
|
||||
from accounting import db
|
||||
from accounting.models import Transaction
|
||||
from accounting.transaction.dispatcher import TransactionType, \
|
||||
TXN_TYPE_DICT
|
||||
from accounting.utils.txn_types import TransactionType
|
||||
|
||||
|
||||
class TransactionConverter(BaseConverter):
|
||||
@ -62,7 +61,9 @@ class TransactionTypeConverter(BaseConverter):
|
||||
:param value: The transaction ID.
|
||||
:return: The corresponding transaction.
|
||||
"""
|
||||
txn_type: TransactionType | None = TXN_TYPE_DICT.get(value)
|
||||
type_dict: dict[str, TransactionType] \
|
||||
= {x.value: x for x in TransactionType}
|
||||
txn_type: TransactionType | None = type_dict.get(value)
|
||||
if txn_type is None:
|
||||
abort(404)
|
||||
return txn_type
|
||||
@ -73,7 +74,7 @@ class TransactionTypeConverter(BaseConverter):
|
||||
:param value: The transaction type.
|
||||
:return: The ID.
|
||||
"""
|
||||
return str(value.ID)
|
||||
return str(value.value)
|
||||
|
||||
|
||||
class DateConverter(BaseConverter):
|
||||
|
@ -37,6 +37,7 @@ from accounting import db
|
||||
from accounting.locale import lazy_gettext
|
||||
from accounting.models import Transaction, Account, JournalEntry, \
|
||||
TransactionCurrency, Currency
|
||||
from accounting.transaction.summary_editor import SummaryEditor
|
||||
from accounting.utils.random_id import new_id
|
||||
from accounting.utils.strip_text import strip_text, strip_multiline_text
|
||||
from accounting.utils.user import get_current_user_pk
|
||||
@ -114,6 +115,35 @@ class IsDebitAccount:
|
||||
"This account is not for debit entries."))
|
||||
|
||||
|
||||
class AccountOption:
|
||||
"""An account option."""
|
||||
|
||||
def __init__(self, account: Account):
|
||||
"""Constructs an account option.
|
||||
|
||||
:param account: The account.
|
||||
"""
|
||||
self.__account: Account = account
|
||||
self.id: str = account.id
|
||||
self.code: str = account.code
|
||||
self.is_in_use: bool = False
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Returns the string representation of the account option.
|
||||
|
||||
:return: The string representation of the account option.
|
||||
"""
|
||||
return str(self.__account)
|
||||
|
||||
@property
|
||||
def query_values(self) -> list[str]:
|
||||
"""Returns the values to be queried.
|
||||
|
||||
:return: The values to be queried.
|
||||
"""
|
||||
return self.__account.query_values
|
||||
|
||||
|
||||
class JournalEntryForm(FlaskForm):
|
||||
"""The base form to create or edit a journal entry."""
|
||||
eid = IntegerField()
|
||||
@ -320,49 +350,54 @@ class TransactionForm(FlaskForm):
|
||||
obj.no = count + 1
|
||||
|
||||
@property
|
||||
def debit_account_options(self) -> list[Account]:
|
||||
def debit_account_options(self) -> list[AccountOption]:
|
||||
"""The selectable debit accounts.
|
||||
|
||||
:return: The selectable debit accounts.
|
||||
"""
|
||||
accounts: list[Account] = Account.debit()
|
||||
in_use: set[int] = self.__get_in_use_account_id()
|
||||
accounts: list[AccountOption] \
|
||||
= [AccountOption(x) for x in Account.debit()]
|
||||
in_use: set[int] = set(db.session.scalars(
|
||||
sa.select(JournalEntry.account_id)
|
||||
.filter(JournalEntry.is_debit)
|
||||
.group_by(JournalEntry.account_id)).all())
|
||||
for account in accounts:
|
||||
account.is_in_use = account.id in in_use
|
||||
return accounts
|
||||
|
||||
@property
|
||||
def credit_account_options(self) -> list[Account]:
|
||||
def credit_account_options(self) -> list[AccountOption]:
|
||||
"""The selectable credit accounts.
|
||||
|
||||
:return: The selectable credit accounts.
|
||||
"""
|
||||
accounts: list[Account] = Account.credit()
|
||||
in_use: set[int] = self.__get_in_use_account_id()
|
||||
accounts: list[AccountOption] \
|
||||
= [AccountOption(x) for x in Account.credit()]
|
||||
in_use: set[int] = set(db.session.scalars(
|
||||
sa.select(JournalEntry.account_id)
|
||||
.filter(sa.not_(JournalEntry.is_debit))
|
||||
.group_by(JournalEntry.account_id)).all())
|
||||
for account in accounts:
|
||||
account.is_in_use = account.id in in_use
|
||||
return accounts
|
||||
|
||||
def __get_in_use_account_id(self) -> set[int]:
|
||||
"""Returns the ID of the accounts that are in use.
|
||||
|
||||
:return: The ID of the accounts that are in use.
|
||||
"""
|
||||
if self.__in_use_account_id is None:
|
||||
self.__in_use_account_id = set(db.session.scalars(
|
||||
sa.select(JournalEntry.account_id)
|
||||
.group_by(JournalEntry.account_id)).all())
|
||||
return self.__in_use_account_id
|
||||
|
||||
@property
|
||||
def currencies_errors(self) -> list[str | LazyString]:
|
||||
"""Returns the currency errors, without the errors in their sub-forms.
|
||||
|
||||
:return:
|
||||
:return: The currency errors, without the errors in their sub-forms.
|
||||
"""
|
||||
return [x for x in self.currencies.errors
|
||||
if isinstance(x, str) or isinstance(x, LazyString)]
|
||||
|
||||
@property
|
||||
def summary_editor(self) -> SummaryEditor:
|
||||
"""Returns the summary editor.
|
||||
|
||||
:return: The summary editor.
|
||||
"""
|
||||
return SummaryEditor()
|
||||
|
||||
|
||||
T = t.TypeVar("T", bound=TransactionForm)
|
||||
"""A transaction form variant."""
|
||||
@ -539,7 +574,8 @@ class IncomeCurrencyForm(CurrencyForm):
|
||||
|
||||
class IncomeTransactionForm(TransactionForm):
|
||||
"""The form to create or edit a cash income transaction."""
|
||||
date = DateField(default=date.today())
|
||||
date = DateField(
|
||||
validators=[DataRequired(lazy_gettext("Please fill in the date."))])
|
||||
"""The date."""
|
||||
currencies = FieldList(FormField(IncomeCurrencyForm), name="currency",
|
||||
validators=[NeedSomeCurrencies()])
|
||||
@ -612,7 +648,8 @@ class ExpenseCurrencyForm(CurrencyForm):
|
||||
|
||||
class ExpenseTransactionForm(TransactionForm):
|
||||
"""The form to create or edit a cash expense transaction."""
|
||||
date = DateField(default=date.today())
|
||||
date = DateField(
|
||||
validators=[DataRequired(lazy_gettext("Please fill in the date."))])
|
||||
"""The date."""
|
||||
currencies = FieldList(FormField(ExpenseCurrencyForm), name="currency",
|
||||
validators=[NeedSomeCurrencies()])
|
||||
@ -721,7 +758,8 @@ class TransferCurrencyForm(CurrencyForm):
|
||||
|
||||
class TransferTransactionForm(TransactionForm):
|
||||
"""The form to create or edit a transfer transaction."""
|
||||
date = DateField(default=date.today())
|
||||
date = DateField(
|
||||
validators=[DataRequired(lazy_gettext("Please fill in the date."))])
|
||||
"""The date."""
|
||||
currencies = FieldList(FormField(TransferCurrencyForm), name="currency",
|
||||
validators=[NeedSomeCurrencies()])
|
||||
|
@ -14,7 +14,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The transaction type dispatcher.
|
||||
"""The operators for different transaction types.
|
||||
|
||||
"""
|
||||
import typing as t
|
||||
@ -24,17 +24,16 @@ from flask import render_template, request, abort
|
||||
from flask_wtf import FlaskForm
|
||||
|
||||
from accounting.models import Transaction
|
||||
from accounting.template_globals import default_currency_code
|
||||
from accounting.utils.txn_types import TransactionType
|
||||
from .forms import TransactionForm, IncomeTransactionForm, \
|
||||
ExpenseTransactionForm, TransferTransactionForm
|
||||
from .template import default_currency_code
|
||||
|
||||
|
||||
class TransactionType(ABC):
|
||||
"""An abstract transaction type."""
|
||||
ID: str = ""
|
||||
"""The transaction type ID."""
|
||||
class TransactionOperator(ABC):
|
||||
"""The base transaction operator."""
|
||||
CHECK_ORDER: int = -1
|
||||
"""The order when checking the transaction type."""
|
||||
"""The order when checking the transaction operator."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
@ -91,12 +90,10 @@ class TransactionType(ABC):
|
||||
entry_index="ENTRY_INDEX")
|
||||
|
||||
|
||||
class IncomeTransaction(TransactionType):
|
||||
class IncomeTransaction(TransactionOperator):
|
||||
"""An income transaction."""
|
||||
ID: str = "income"
|
||||
"""The transaction type ID."""
|
||||
CHECK_ORDER: int = 2
|
||||
"""The order when checking the transaction type."""
|
||||
"""The order when checking the transaction operator."""
|
||||
|
||||
@property
|
||||
def form(self) -> t.Type[TransactionForm]:
|
||||
@ -113,7 +110,8 @@ class IncomeTransaction(TransactionType):
|
||||
:return: the form to create a transaction.
|
||||
"""
|
||||
return render_template("accounting/transaction/income/create.html",
|
||||
form=form, txn_type=self,
|
||||
form=form,
|
||||
txn_type=TransactionType.CASH_INCOME,
|
||||
currency_template=self.__currency_template,
|
||||
entry_template=self._entry_template)
|
||||
|
||||
@ -161,12 +159,10 @@ class IncomeTransaction(TransactionType):
|
||||
credit_total="-")
|
||||
|
||||
|
||||
class ExpenseTransaction(TransactionType):
|
||||
class ExpenseTransaction(TransactionOperator):
|
||||
"""An expense transaction."""
|
||||
ID: str = "expense"
|
||||
"""The transaction type ID."""
|
||||
CHECK_ORDER: int = 1
|
||||
"""The order when checking the transaction type."""
|
||||
"""The order when checking the transaction operator."""
|
||||
|
||||
@property
|
||||
def form(self) -> t.Type[TransactionForm]:
|
||||
@ -183,7 +179,8 @@ class ExpenseTransaction(TransactionType):
|
||||
:return: the form to create a transaction.
|
||||
"""
|
||||
return render_template("accounting/transaction/expense/create.html",
|
||||
form=form, txn_type=self,
|
||||
form=form,
|
||||
txn_type=TransactionType.CASH_EXPENSE,
|
||||
currency_template=self.__currency_template,
|
||||
entry_template=self._entry_template)
|
||||
|
||||
@ -231,12 +228,10 @@ class ExpenseTransaction(TransactionType):
|
||||
debit_total="-")
|
||||
|
||||
|
||||
class TransferTransaction(TransactionType):
|
||||
class TransferTransaction(TransactionOperator):
|
||||
"""A transfer transaction."""
|
||||
ID: str = "transfer"
|
||||
"""The transaction type ID."""
|
||||
CHECK_ORDER: int = 3
|
||||
"""The order when checking the transaction type."""
|
||||
"""The order when checking the transaction operator."""
|
||||
|
||||
@property
|
||||
def form(self) -> t.Type[TransactionForm]:
|
||||
@ -253,7 +248,8 @@ class TransferTransaction(TransactionType):
|
||||
:return: the form to create a transaction.
|
||||
"""
|
||||
return render_template("accounting/transaction/transfer/create.html",
|
||||
form=form, txn_type=self,
|
||||
form=form,
|
||||
txn_type=TransactionType.TRANSFER,
|
||||
currency_template=self.__currency_template,
|
||||
entry_template=self._entry_template)
|
||||
|
||||
@ -301,44 +297,28 @@ class TransferTransaction(TransactionType):
|
||||
debit_total="-", credit_total="-")
|
||||
|
||||
|
||||
class TransactionTypes:
|
||||
"""The transaction types, as object properties."""
|
||||
|
||||
def __init__(self, income: IncomeTransaction, expense: ExpenseTransaction,
|
||||
transfer: TransferTransaction):
|
||||
"""Constructs the transaction types as object properties.
|
||||
|
||||
:param income: The income transaction type.
|
||||
:param expense: The expense transaction type.
|
||||
:param transfer: The transfer transaction type.
|
||||
"""
|
||||
self.income: IncomeTransaction = income
|
||||
self.expense: ExpenseTransaction = expense
|
||||
self.transfer: TransferTransaction = transfer
|
||||
TXN_TYPE_TO_OP: dict[TransactionType, TransactionOperator] \
|
||||
= {TransactionType.CASH_INCOME: IncomeTransaction(),
|
||||
TransactionType.CASH_EXPENSE: ExpenseTransaction(),
|
||||
TransactionType.TRANSFER: TransferTransaction()}
|
||||
"""The map from the transaction types to their operators."""
|
||||
|
||||
|
||||
TXN_TYPE_DICT: dict[str, TransactionType] \
|
||||
= {x.ID: x() for x in {IncomeTransaction,
|
||||
ExpenseTransaction,
|
||||
TransferTransaction}}
|
||||
"""The transaction types, as a dictionary."""
|
||||
TXN_TYPE_OBJ: TransactionTypes = TransactionTypes(**TXN_TYPE_DICT)
|
||||
"""The transaction types, as an object."""
|
||||
|
||||
|
||||
def get_txn_type(txn: Transaction) -> TransactionType:
|
||||
"""Returns the transaction type that may be specified in the "as" query
|
||||
def get_txn_op(txn: Transaction) -> TransactionOperator:
|
||||
"""Returns the transaction operator that may be specified in the "as" query
|
||||
parameter. If it is not specified, check the transaction type from the
|
||||
transaction.
|
||||
transaction.
|
||||
|
||||
:param txn: The transaction.
|
||||
:return: None.
|
||||
"""
|
||||
if "as" in request.args:
|
||||
if request.args["as"] not in TXN_TYPE_DICT:
|
||||
type_dict: dict[str, TransactionType] \
|
||||
= {x.value: x for x in TransactionType}
|
||||
if request.args["as"] not in type_dict:
|
||||
abort(404)
|
||||
return TXN_TYPE_DICT[request.args["as"]]
|
||||
for txn_type in sorted(TXN_TYPE_DICT.values(),
|
||||
return TXN_TYPE_TO_OP[type_dict[request.args["as"]]]
|
||||
for txn_type in sorted(TXN_TYPE_TO_OP.values(),
|
||||
key=lambda x: x.CHECK_ORDER):
|
||||
if txn_type.is_my_type(txn):
|
||||
return txn_type
|
@ -14,7 +14,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The transaction query.
|
||||
"""The queries for the transaction management.
|
||||
|
||||
"""
|
||||
from datetime import datetime
|
255
src/accounting/transaction/summary_editor.py
Normal file
255
src/accounting/transaction/summary_editor.py
Normal file
@ -0,0 +1,255 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/27
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The summary editor.
|
||||
|
||||
"""
|
||||
import typing as t
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from accounting import db
|
||||
from accounting.models import Account, JournalEntry
|
||||
|
||||
|
||||
class SummaryAccount:
|
||||
"""An account for a summary tag."""
|
||||
|
||||
def __init__(self, account: Account, freq: int):
|
||||
"""Constructs an account for a summary tag.
|
||||
|
||||
:param account: The account.
|
||||
:param freq: The frequency of the tag with the account.
|
||||
"""
|
||||
self.account: Account = account
|
||||
"""The account."""
|
||||
self.id: int = account.id
|
||||
"""The account ID."""
|
||||
self.code: str = account.code
|
||||
"""The account code."""
|
||||
self.freq: int = freq
|
||||
"""The frequency of the tag with the account."""
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Returns the string representation of the account.
|
||||
|
||||
:return: The string representation of the account.
|
||||
"""
|
||||
return str(self.account)
|
||||
|
||||
def add_freq(self, freq: int) -> None:
|
||||
"""Adds the frequency of an account.
|
||||
|
||||
:param freq: The frequency of the tag name with the account.
|
||||
:return: None.
|
||||
"""
|
||||
self.freq = self.freq + freq
|
||||
|
||||
|
||||
class SummaryTag:
|
||||
"""A summary tag."""
|
||||
|
||||
def __init__(self, name: str):
|
||||
"""Constructs a summary tag.
|
||||
|
||||
:param name: The tag name.
|
||||
"""
|
||||
self.name: str = name
|
||||
"""The tag name."""
|
||||
self.__account_dict: dict[int, SummaryAccount] = {}
|
||||
"""The accounts that come with the tag, in the order of their
|
||||
frequency."""
|
||||
self.freq: int = 0
|
||||
"""The frequency of the tag."""
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Returns the string representation of the tag.
|
||||
|
||||
:return: The string representation of the tag.
|
||||
"""
|
||||
return self.name
|
||||
|
||||
def add_account(self, account: Account, freq: int):
|
||||
"""Adds an account.
|
||||
|
||||
:param account: The associated account.
|
||||
:param freq: The frequency of the tag name with the account.
|
||||
:return: None.
|
||||
"""
|
||||
self.__account_dict[account.id] = SummaryAccount(account, freq)
|
||||
self.freq = self.freq + freq
|
||||
|
||||
@property
|
||||
def accounts(self) -> list[SummaryAccount]:
|
||||
"""Returns the accounts by the order of their frequencies.
|
||||
|
||||
:return: The accounts by the order of their frequencies.
|
||||
"""
|
||||
return sorted(self.__account_dict.values(), key=lambda x: -x.freq)
|
||||
|
||||
@property
|
||||
def account_codes(self) -> list[str]:
|
||||
"""Returns the account codes by the order of their frequencies.
|
||||
|
||||
:return: The account codes by the order of their frequencies.
|
||||
"""
|
||||
return [x.code for x in self.accounts]
|
||||
|
||||
|
||||
class SummaryType:
|
||||
"""A summary type"""
|
||||
|
||||
def __init__(self, type_id: t.Literal["general", "travel", "bus"]):
|
||||
"""Constructs a summary type.
|
||||
|
||||
:param type_id: The type ID, either "general", "travel", or "bus".
|
||||
"""
|
||||
self.id: t.Literal["general", "travel", "bus"] = type_id
|
||||
"""The type ID."""
|
||||
self.__tag_dict: dict[str, SummaryTag] = {}
|
||||
"""A dictionary from the tag name to their corresponding tag."""
|
||||
|
||||
def add_tag(self, name: str, account: Account, freq: int) -> None:
|
||||
"""Adds a tag.
|
||||
|
||||
:param name: The tag name.
|
||||
:param account: The associated account.
|
||||
:param freq: The frequency of the tag name with the account.
|
||||
:return: None.
|
||||
"""
|
||||
if name not in self.__tag_dict:
|
||||
self.__tag_dict[name] = SummaryTag(name)
|
||||
self.__tag_dict[name].add_account(account, freq)
|
||||
|
||||
@property
|
||||
def tags(self) -> list[SummaryTag]:
|
||||
"""Returns the tags by the order of their frequencies.
|
||||
|
||||
:return: The tags by the order of their frequencies.
|
||||
"""
|
||||
return sorted(self.__tag_dict.values(), key=lambda x: -x.freq)
|
||||
|
||||
|
||||
class SummaryEntryType:
|
||||
"""A summary type"""
|
||||
|
||||
def __init__(self, entry_type_id: t.Literal["debit", "credit"]):
|
||||
"""Constructs a summary entry type.
|
||||
|
||||
:param entry_type_id: The entry type ID, either "debit" or "credit".
|
||||
"""
|
||||
self.type: t.Literal["debit", "credit"] = entry_type_id
|
||||
"""The entry type."""
|
||||
self.general: SummaryType = SummaryType("general")
|
||||
"""The general tags."""
|
||||
self.travel: SummaryType = SummaryType("travel")
|
||||
"""The travel tags."""
|
||||
self.bus: SummaryType = SummaryType("bus")
|
||||
"""The bus tags."""
|
||||
self.__type_dict: dict[t.Literal["general", "travel", "bus"],
|
||||
SummaryType] \
|
||||
= {x.id: x for x in {self.general, self.travel, self.bus}}
|
||||
"""A dictionary from the type ID to the corresponding tags."""
|
||||
|
||||
def add_tag(self, tag_type: t.Literal["general", "travel", "bus"],
|
||||
name: str, account: Account, freq: int) -> None:
|
||||
"""Adds a tag.
|
||||
|
||||
:param tag_type: The tag type, either "general", "travel", or "bus".
|
||||
:param name: The name.
|
||||
:param account: The associated account.
|
||||
:param freq: The frequency of the tag name with the account.
|
||||
:return: None.
|
||||
"""
|
||||
self.__type_dict[tag_type].add_tag(name, account, freq)
|
||||
|
||||
@property
|
||||
def accounts(self) -> list[SummaryAccount]:
|
||||
"""Returns the suggested accounts of all tags in the summary editor in
|
||||
the entry type, in their frequency order.
|
||||
|
||||
:return: The suggested accounts of all tags, in their frequency order.
|
||||
"""
|
||||
accounts: dict[int, SummaryAccount] = {}
|
||||
freq: dict[int, int] = {}
|
||||
for tag_type in self.__type_dict.values():
|
||||
for tag in tag_type.tags:
|
||||
for account in tag.accounts:
|
||||
accounts[account.id] = account
|
||||
if account.id not in freq:
|
||||
freq[account.id] = 0
|
||||
freq[account.id] \
|
||||
= freq[account.id] + account.freq
|
||||
return [accounts[y] for y in sorted(freq.keys(),
|
||||
key=lambda x: -freq[x])]
|
||||
|
||||
|
||||
class SummaryEditor:
|
||||
"""The summary editor."""
|
||||
|
||||
def __init__(self):
|
||||
"""Constructs the summary editor."""
|
||||
self.debit: SummaryEntryType = SummaryEntryType("debit")
|
||||
"""The debit tags."""
|
||||
self.credit: SummaryEntryType = SummaryEntryType("credit")
|
||||
"""The credit tags."""
|
||||
entry_type: sa.Label = sa.case((JournalEntry.is_debit, "debit"),
|
||||
else_="credit").label("entry_type")
|
||||
tag_type: sa.Label = sa.case(
|
||||
(JournalEntry.summary.like("_%—_%—_%→_%"), "bus"),
|
||||
(sa.or_(JournalEntry.summary.like("_%—_%→_%"),
|
||||
JournalEntry.summary.like("_%—_%↔_%")), "travel"),
|
||||
else_="general").label("tag_type")
|
||||
tag: sa.Label = get_prefix(JournalEntry.summary, "—").label("tag")
|
||||
select: sa.Select = sa.Select(entry_type, tag_type, tag,
|
||||
JournalEntry.account_id,
|
||||
sa.func.count().label("freq"))\
|
||||
.filter(JournalEntry.summary.is_not(None),
|
||||
JournalEntry.summary.like("_%—_%"))\
|
||||
.group_by(entry_type, tag_type, tag, JournalEntry.account_id)
|
||||
result: list[sa.Row] = db.session.execute(select).all()
|
||||
accounts: dict[int, Account] \
|
||||
= {x.id: x for x in Account.query
|
||||
.filter(Account.id.in_({x.account_id for x in result})).all()}
|
||||
entry_type_dict: dict[t.Literal["debit", "credit"], SummaryEntryType] \
|
||||
= {x.type: x for x in {self.debit, self.credit}}
|
||||
for row in result:
|
||||
entry_type_dict[row.entry_type].add_tag(
|
||||
row.tag_type, row.tag, accounts[row.account_id], row.freq)
|
||||
|
||||
|
||||
def get_prefix(string: str | sa.Column, separator: str | sa.Column) \
|
||||
-> sa.Function:
|
||||
"""Returns the SQL function to find the prefix of a string.
|
||||
|
||||
:param string: The string.
|
||||
:param separator: The separator.
|
||||
:return: The position of the substring, starting from 1.
|
||||
"""
|
||||
return sa.func.substr(string, 0, get_position(string, separator))
|
||||
|
||||
|
||||
def get_position(string: str | sa.Column, substring: str | sa.Column) \
|
||||
-> sa.Function:
|
||||
"""Returns the SQL function to find the position of a substring.
|
||||
|
||||
:param string: The string.
|
||||
:param substring: The substring.
|
||||
:return: The position of the substring, starting from 1.
|
||||
"""
|
||||
if db.engine.name == "postgresql":
|
||||
return sa.func.strpos(string, substring)
|
||||
return sa.func.instr(string, substring)
|
@ -14,20 +14,15 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The template filters and globals for the transaction management.
|
||||
"""The template filters for the transaction management.
|
||||
|
||||
"""
|
||||
from datetime import date, timedelta
|
||||
from decimal import Decimal
|
||||
from html import escape
|
||||
from urllib.parse import ParseResult, urlparse, parse_qsl, urlencode, \
|
||||
urlunparse
|
||||
|
||||
from flask import request, current_app
|
||||
from flask_babel import get_locale
|
||||
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Currency
|
||||
from flask import request
|
||||
|
||||
|
||||
def with_type(uri: str) -> str:
|
||||
@ -62,60 +57,19 @@ def to_transfer(uri: str) -> str:
|
||||
return urlunparse(parts)
|
||||
|
||||
|
||||
def format_amount(value: Decimal | None) -> str:
|
||||
"""Formats an amount for readability.
|
||||
|
||||
:param value: The amount.
|
||||
:return: The formatted amount text.
|
||||
"""
|
||||
if value is None or value == 0:
|
||||
return "-"
|
||||
whole: int = int(value)
|
||||
frac: Decimal = (value - whole).normalize()
|
||||
return "{:,}".format(whole) + str(frac)[1:]
|
||||
|
||||
|
||||
def format_amount_input(value: Decimal) -> str:
|
||||
def format_amount_input(value: Decimal | None) -> str:
|
||||
"""Format an amount for an input value.
|
||||
|
||||
:param value: The amount.
|
||||
:return: The formatted amount text for an input value.
|
||||
"""
|
||||
if value is None:
|
||||
return ""
|
||||
whole: int = int(value)
|
||||
frac: Decimal = (value - whole).normalize()
|
||||
return str(whole) + str(frac)[1:]
|
||||
|
||||
|
||||
def format_date(value: date) -> str:
|
||||
"""Formats a date to be human-friendly.
|
||||
|
||||
:param value: The date.
|
||||
:return: The human-friendly date text.
|
||||
"""
|
||||
today: date = date.today()
|
||||
if value == today:
|
||||
return gettext("Today")
|
||||
if value == today - timedelta(days=1):
|
||||
return gettext("Yesterday")
|
||||
if value == today + timedelta(days=1):
|
||||
return gettext("Tomorrow")
|
||||
locale = str(get_locale())
|
||||
if locale == "zh" or locale.startswith("zh_"):
|
||||
if value == today - timedelta(days=2):
|
||||
return gettext("The day before yesterday")
|
||||
if value == today + timedelta(days=2):
|
||||
return gettext("The day after tomorrow")
|
||||
if locale == "zh" or locale.startswith("zh_"):
|
||||
weekdays = ["一", "二", "三", "四", "五", "六", "日"]
|
||||
weekday = weekdays[value.weekday()]
|
||||
else:
|
||||
weekday = value.strftime("%a")
|
||||
if value.year != today.year:
|
||||
return "{}/{}/{}({})".format(
|
||||
value.year, value.month, value.day, weekday)
|
||||
return "{}/{}({})".format(value.month, value.day, weekday)
|
||||
|
||||
|
||||
def text2html(value: str) -> str:
|
||||
"""Converts plain text into HTML.
|
||||
|
||||
@ -126,20 +80,3 @@ def text2html(value: str) -> str:
|
||||
s = s.replace("\n", "<br>")
|
||||
s = s.replace(" ", " ")
|
||||
return s
|
||||
|
||||
|
||||
def currency_options() -> str:
|
||||
"""Returns the currency options.
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
return Currency.query.order_by(Currency.code).all()
|
||||
|
||||
|
||||
def default_currency_code() -> str:
|
||||
"""Returns the default currency code.
|
||||
|
||||
:return: The default currency code.
|
||||
"""
|
||||
with current_app.app_context():
|
||||
return current_app.config.get("DEFAULT_CURRENCY", "USD")
|
@ -32,26 +32,21 @@ from accounting.utils.flash_errors import flash_form_errors
|
||||
from accounting.utils.next_uri import inherit_next, or_next
|
||||
from accounting.utils.pagination import Pagination
|
||||
from accounting.utils.permission import has_permission, can_view, can_edit
|
||||
from accounting.utils.txn_types import TransactionType
|
||||
from accounting.utils.user import get_current_user_pk
|
||||
from .dispatcher import TransactionType, get_txn_type, TXN_TYPE_OBJ
|
||||
from .operators import TransactionOperator, TXN_TYPE_TO_OP, get_txn_op
|
||||
from .forms import sort_transactions_in, TransactionReorderForm
|
||||
from .query import get_transaction_query
|
||||
from .template import with_type, to_transfer, format_amount, \
|
||||
format_amount_input, format_date, text2html, currency_options, \
|
||||
default_currency_code
|
||||
from .queries import get_transaction_query
|
||||
from .template_filters import with_type, to_transfer, format_amount_input, \
|
||||
text2html
|
||||
|
||||
bp: Blueprint = Blueprint("transaction", __name__)
|
||||
"""The view blueprint for the transaction management."""
|
||||
bp.add_app_template_filter(with_type, "accounting_txn_with_type")
|
||||
bp.add_app_template_filter(to_transfer, "accounting_txn_to_transfer")
|
||||
bp.add_app_template_filter(format_amount, "accounting_txn_format_amount")
|
||||
bp.add_app_template_filter(format_amount_input,
|
||||
"accounting_txn_format_amount_input")
|
||||
bp.add_app_template_filter(format_date, "accounting_txn_format_date")
|
||||
bp.add_app_template_filter(text2html, "accounting_txn_text2html")
|
||||
bp.add_app_template_global(currency_options, "accounting_txn_currency_options")
|
||||
bp.add_app_template_global(default_currency_code,
|
||||
"accounting_txn_default_currency_code")
|
||||
|
||||
|
||||
@bp.get("", endpoint="list")
|
||||
@ -65,7 +60,7 @@ def list_transactions() -> str:
|
||||
pagination: Pagination = Pagination[Transaction](transactions)
|
||||
return render_template("accounting/transaction/list.html",
|
||||
list=pagination.list, pagination=pagination,
|
||||
types=TXN_TYPE_OBJ)
|
||||
txn_types=TransactionType)
|
||||
|
||||
|
||||
@bp.get("/create/<transactionType:txn_type>", endpoint="create")
|
||||
@ -76,14 +71,16 @@ def show_add_transaction_form(txn_type: TransactionType) -> str:
|
||||
:param txn_type: The transaction type.
|
||||
:return: The form to add a transaction.
|
||||
"""
|
||||
form: txn_type.form
|
||||
txn_op: TransactionOperator = TXN_TYPE_TO_OP[txn_type]
|
||||
form: txn_op.form
|
||||
if "form" in session:
|
||||
form = txn_type.form(ImmutableMultiDict(parse_qsl(session["form"])))
|
||||
form = txn_op.form(ImmutableMultiDict(parse_qsl(session["form"])))
|
||||
del session["form"]
|
||||
form.validate()
|
||||
else:
|
||||
form = txn_type.form()
|
||||
return txn_type.render_create_template(form)
|
||||
form = txn_op.form()
|
||||
form.date.data = date.today()
|
||||
return txn_op.render_create_template(form)
|
||||
|
||||
|
||||
@bp.post("/store/<transactionType:txn_type>", endpoint="store")
|
||||
@ -95,7 +92,8 @@ def add_transaction(txn_type: TransactionType) -> redirect:
|
||||
:return: The redirection to the transaction detail on success, or the
|
||||
transaction creation form on error.
|
||||
"""
|
||||
form: txn_type.form = txn_type.form(request.form)
|
||||
txn_op: TransactionOperator = TXN_TYPE_TO_OP[txn_type]
|
||||
form: txn_op.form = txn_op.form(request.form)
|
||||
if not form.validate():
|
||||
flash_form_errors(form)
|
||||
session["form"] = urlencode(list(request.form.items()))
|
||||
@ -117,8 +115,8 @@ def show_transaction_detail(txn: Transaction) -> str:
|
||||
:param txn: The transaction.
|
||||
:return: The detail.
|
||||
"""
|
||||
txn_type: TransactionType = get_txn_type(txn)
|
||||
return txn_type.render_detail_template(txn)
|
||||
txn_op: TransactionOperator = get_txn_op(txn)
|
||||
return txn_op.render_detail_template(txn)
|
||||
|
||||
|
||||
@bp.get("/<transaction:txn>/edit", endpoint="edit")
|
||||
@ -129,15 +127,15 @@ def show_transaction_edit_form(txn: Transaction) -> str:
|
||||
:param txn: The transaction.
|
||||
:return: The form to edit the transaction.
|
||||
"""
|
||||
txn_type: TransactionType = get_txn_type(txn)
|
||||
form: txn_type.form
|
||||
txn_op: TransactionOperator = get_txn_op(txn)
|
||||
form: txn_op.form
|
||||
if "form" in session:
|
||||
form = txn_type.form(ImmutableMultiDict(parse_qsl(session["form"])))
|
||||
form = txn_op.form(ImmutableMultiDict(parse_qsl(session["form"])))
|
||||
del session["form"]
|
||||
form.validate()
|
||||
else:
|
||||
form = txn_type.form(obj=txn)
|
||||
return txn_type.render_edit_template(txn, form)
|
||||
form = txn_op.form(obj=txn)
|
||||
return txn_op.render_edit_template(txn, form)
|
||||
|
||||
|
||||
@bp.post("/<transaction:txn>/update", endpoint="update")
|
||||
@ -149,8 +147,8 @@ def update_transaction(txn: Transaction) -> redirect:
|
||||
:return: The redirection to the transaction detail on success, or the
|
||||
transaction edit form on error.
|
||||
"""
|
||||
txn_type: TransactionType = get_txn_type(txn)
|
||||
form: txn_type.form = txn_type.form(request.form)
|
||||
txn_op: TransactionOperator = get_txn_op(txn)
|
||||
form: txn_op.form = txn_op.form(request.form)
|
||||
if not form.validate():
|
||||
flash_form_errors(form)
|
||||
session["form"] = urlencode(list(request.form.items()))
|
||||
@ -192,8 +190,8 @@ def show_transaction_order(txn_date: date) -> str:
|
||||
:param txn_date: The date.
|
||||
:return: The order of the transactions in the date.
|
||||
"""
|
||||
transactions: list[Transaction] = Transaction.query\
|
||||
.filter(Transaction.date == txn_date)\
|
||||
transactions: list[Transaction] = Transaction.query \
|
||||
.filter(Transaction.date == txn_date) \
|
||||
.order_by(Transaction.no).all()
|
||||
return render_template("accounting/transaction/order.html",
|
||||
date=txn_date, list=transactions)
|
||||
|
@ -8,8 +8,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Mia! Accounting Flask 0.0.0\n"
|
||||
"Report-Msgid-Bugs-To: imacat@mail.imacat.idv.tw\n"
|
||||
"POT-Creation-Date: 2023-02-27 18:59+0800\n"
|
||||
"PO-Revision-Date: 2023-02-27 18:59+0800\n"
|
||||
"POT-Creation-Date: 2023-03-01 00:51+0800\n"
|
||||
"PO-Revision-Date: 2023-03-01 00:51+0800\n"
|
||||
"Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n"
|
||||
"Language: zh_Hant\n"
|
||||
"Language-Team: zh_Hant <imacat@mail.imacat.idv.tw>\n"
|
||||
@ -126,33 +126,52 @@ msgstr "貨幣刪掉了"
|
||||
msgid "Please fill in the title."
|
||||
msgstr "請填上標題。"
|
||||
|
||||
#: src/accounting/static/js/transaction-form.js:308
|
||||
#: src/accounting/static/js/transaction-form.js:764
|
||||
#: src/accounting/transaction/forms.py:46
|
||||
#: src/accounting/static/js/summary-helper.js:441
|
||||
#: src/accounting/static/js/summary-helper.js:512
|
||||
msgid "Please fill in the tag."
|
||||
msgstr "請填上標籤。"
|
||||
|
||||
#: src/accounting/static/js/summary-helper.js:460
|
||||
#: src/accounting/static/js/summary-helper.js:550
|
||||
msgid "Please fill in the origin."
|
||||
msgstr "請填上起點。"
|
||||
|
||||
#: src/accounting/static/js/summary-helper.js:479
|
||||
#: src/accounting/static/js/summary-helper.js:569
|
||||
msgid "Please fill in the destination."
|
||||
msgstr "請填上終點。"
|
||||
|
||||
#: src/accounting/static/js/summary-helper.js:531
|
||||
msgid "Please fill in the route."
|
||||
msgstr "請填上路線名稱。"
|
||||
|
||||
#: src/accounting/static/js/transaction-form.js:289
|
||||
#: src/accounting/static/js/transaction-form.js:611
|
||||
#: src/accounting/transaction/forms.py:47
|
||||
msgid "Please select the account."
|
||||
msgstr "請選擇科目。"
|
||||
|
||||
#: src/accounting/static/js/transaction-form.js:344
|
||||
#: src/accounting/static/js/transaction-form.js:769
|
||||
#: src/accounting/static/js/transaction-form.js:324
|
||||
#: src/accounting/static/js/transaction-form.js:616
|
||||
msgid "Please fill in the amount."
|
||||
msgstr "請填上金額。"
|
||||
|
||||
#: src/accounting/static/js/transaction-form.js:641
|
||||
#: src/accounting/static/js/transaction-form.js:488
|
||||
msgid "Please fill in the date."
|
||||
msgstr "請填上日期。"
|
||||
|
||||
#: src/accounting/static/js/transaction-form.js:676
|
||||
#: src/accounting/transaction/forms.py:56
|
||||
#: src/accounting/static/js/transaction-form.js:523
|
||||
#: src/accounting/transaction/forms.py:57
|
||||
msgid "Please add some currencies."
|
||||
msgstr "請加上貨幣。"
|
||||
|
||||
#: src/accounting/static/js/transaction-form.js:742
|
||||
#: src/accounting/transaction/forms.py:77
|
||||
#: src/accounting/static/js/transaction-form.js:589
|
||||
#: src/accounting/transaction/forms.py:78
|
||||
msgid "Please add some journal entries."
|
||||
msgstr "請加上分錄。"
|
||||
|
||||
#: src/accounting/static/js/transaction-form.js:807
|
||||
#: src/accounting/transaction/forms.py:670
|
||||
#: src/accounting/static/js/transaction-form.js:654
|
||||
#: src/accounting/transaction/forms.py:672
|
||||
msgid "The totals of the debit and credit amounts do not match."
|
||||
msgstr "借方貸方合計不符。 "
|
||||
|
||||
@ -167,7 +186,7 @@ msgstr "新增科目"
|
||||
#: src/accounting/templates/accounting/currency/detail.html:31
|
||||
#: src/accounting/templates/accounting/currency/include/form.html:33
|
||||
#: src/accounting/templates/accounting/transaction/include/detail.html:31
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:34
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:36
|
||||
#: src/accounting/templates/accounting/transaction/order.html:36
|
||||
msgid "Back"
|
||||
msgstr "回上頁"
|
||||
@ -196,10 +215,10 @@ msgstr "科目刪除確認"
|
||||
#: src/accounting/templates/accounting/account/detail.html:70
|
||||
#: src/accounting/templates/accounting/account/include/form.html:91
|
||||
#: src/accounting/templates/accounting/currency/detail.html:66
|
||||
#: src/accounting/templates/accounting/transaction/include/credit-account-modal.html:27
|
||||
#: src/accounting/templates/accounting/transaction/include/debit-account-modal.html:27
|
||||
#: src/accounting/templates/accounting/transaction/include/account-selector-modal.html:27
|
||||
#: src/accounting/templates/accounting/transaction/include/detail.html:71
|
||||
#: src/accounting/templates/accounting/transaction/include/entry-form-modal.html:28
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:30
|
||||
msgid "Close"
|
||||
msgstr "關閉"
|
||||
|
||||
@ -210,10 +229,10 @@ msgstr "你確定要刪掉這個科目嗎?"
|
||||
#: src/accounting/templates/accounting/account/detail.html:76
|
||||
#: src/accounting/templates/accounting/account/include/form.html:112
|
||||
#: src/accounting/templates/accounting/currency/detail.html:72
|
||||
#: src/accounting/templates/accounting/transaction/include/credit-account-modal.html:49
|
||||
#: src/accounting/templates/accounting/transaction/include/debit-account-modal.html:49
|
||||
#: src/accounting/templates/accounting/transaction/include/account-selector-modal.html:49
|
||||
#: src/accounting/templates/accounting/transaction/include/detail.html:77
|
||||
#: src/accounting/templates/accounting/transaction/include/entry-form-modal.html:52
|
||||
#: src/accounting/templates/accounting/transaction/include/entry-form-modal.html:54
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:175
|
||||
msgid "Cancel"
|
||||
msgstr "取消"
|
||||
|
||||
@ -255,7 +274,7 @@ msgstr "科目管理"
|
||||
#: src/accounting/templates/accounting/account/list.html:32
|
||||
#: src/accounting/templates/accounting/currency/list.html:32
|
||||
#: src/accounting/templates/accounting/transaction/expense/include/form-currency-item.html:75
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:60
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:62
|
||||
#: src/accounting/templates/accounting/transaction/income/include/form-currency-item.html:75
|
||||
#: src/accounting/templates/accounting/transaction/list.html:37
|
||||
#: src/accounting/templates/accounting/transaction/transfer/include/form-currency-item.html:77
|
||||
@ -276,8 +295,7 @@ msgstr "桌機版檢索"
|
||||
#: src/accounting/templates/accounting/base-account/list.html:34
|
||||
#: src/accounting/templates/accounting/currency/list.html:40
|
||||
#: src/accounting/templates/accounting/currency/list.html:52
|
||||
#: src/accounting/templates/accounting/transaction/include/credit-account-modal.html:34
|
||||
#: src/accounting/templates/accounting/transaction/include/debit-account-modal.html:34
|
||||
#: src/accounting/templates/accounting/transaction/include/account-selector-modal.html:34
|
||||
#: src/accounting/templates/accounting/transaction/list.html:62
|
||||
#: src/accounting/templates/accounting/transaction/list.html:74
|
||||
msgid "Search"
|
||||
@ -294,8 +312,7 @@ msgstr "行動版檢索"
|
||||
#: src/accounting/templates/accounting/account/order.html:81
|
||||
#: src/accounting/templates/accounting/base-account/list.html:51
|
||||
#: src/accounting/templates/accounting/currency/list.html:77
|
||||
#: src/accounting/templates/accounting/transaction/include/credit-account-modal.html:46
|
||||
#: src/accounting/templates/accounting/transaction/include/debit-account-modal.html:46
|
||||
#: src/accounting/templates/accounting/transaction/include/account-selector-modal.html:46
|
||||
#: src/accounting/templates/accounting/transaction/list.html:93
|
||||
#: src/accounting/templates/accounting/transaction/order.html:80
|
||||
msgid "There is no data."
|
||||
@ -309,8 +326,9 @@ msgstr "%(base)s下的科目"
|
||||
#: src/accounting/templates/accounting/account/include/form.html:75
|
||||
#: src/accounting/templates/accounting/account/order.html:62
|
||||
#: src/accounting/templates/accounting/currency/include/form.html:57
|
||||
#: src/accounting/templates/accounting/transaction/include/entry-form-modal.html:53
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:76
|
||||
#: src/accounting/templates/accounting/transaction/include/entry-form-modal.html:55
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:78
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:176
|
||||
#: src/accounting/templates/accounting/transaction/order.html:61
|
||||
msgid "Save"
|
||||
msgstr "儲存"
|
||||
@ -337,8 +355,7 @@ msgstr "選擇基本科目"
|
||||
|
||||
#: src/accounting/templates/accounting/account/include/form.html:114
|
||||
#: src/accounting/templates/accounting/account/include/form.html:116
|
||||
#: src/accounting/templates/accounting/transaction/include/credit-account-modal.html:50
|
||||
#: src/accounting/templates/accounting/transaction/include/debit-account-modal.html:50
|
||||
#: src/accounting/templates/accounting/transaction/include/account-selector-modal.html:50
|
||||
msgid "Clear"
|
||||
msgstr "清除"
|
||||
|
||||
@ -432,7 +449,7 @@ msgstr "改轉帳"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/expense/detail.html:37
|
||||
#: src/accounting/templates/accounting/transaction/expense/include/form-currency-item.html:45
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:52
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:54
|
||||
#: src/accounting/templates/accounting/transaction/income/detail.html:37
|
||||
#: src/accounting/templates/accounting/transaction/income/include/form-currency-item.html:45
|
||||
msgid "Content"
|
||||
@ -462,6 +479,14 @@ msgstr "編輯%(txn)s"
|
||||
msgid "Currency"
|
||||
msgstr "貨幣"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/account-selector-modal.html:26
|
||||
msgid "Select Account"
|
||||
msgstr "選擇科目"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/account-selector-modal.html:44
|
||||
msgid "More…"
|
||||
msgstr "更多…"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/add-new-material-fab.html:26
|
||||
msgid "Cash expense"
|
||||
msgstr "現金支出"
|
||||
@ -470,19 +495,6 @@ msgstr "現金支出"
|
||||
msgid "Cash income"
|
||||
msgstr "現金收入"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/credit-account-modal.html:26
|
||||
msgid "Select Credit Account"
|
||||
msgstr "選擇貸方科目科目"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/credit-account-modal.html:44
|
||||
#: src/accounting/templates/accounting/transaction/include/debit-account-modal.html:44
|
||||
msgid "More…"
|
||||
msgstr "更多…"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/debit-account-modal.html:26
|
||||
msgid "Select Debit Account"
|
||||
msgstr "選擇借方科目"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/detail.html:70
|
||||
msgid "Delete Transaction Confirmation"
|
||||
msgstr "傳票刪除確認"
|
||||
@ -500,21 +512,66 @@ msgid "Account"
|
||||
msgstr "科目"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/entry-form-modal.html:41
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:28
|
||||
msgid "Summary"
|
||||
msgstr "摘要"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/entry-form-modal.html:47
|
||||
#: src/accounting/templates/accounting/transaction/include/entry-form-modal.html:49
|
||||
msgid "Amount"
|
||||
msgstr "金額"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:46
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:48
|
||||
msgid "Date"
|
||||
msgstr "日期"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:69
|
||||
#: src/accounting/templates/accounting/transaction/include/form.html:71
|
||||
msgid "Note"
|
||||
msgstr "備註"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:39
|
||||
msgid "General"
|
||||
msgstr "一般"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:44
|
||||
msgid "Travel"
|
||||
msgstr "差旅"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:49
|
||||
msgid "Bus"
|
||||
msgstr "公車"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:54
|
||||
msgid "Regular"
|
||||
msgstr "帳單"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:59
|
||||
msgid "Number"
|
||||
msgstr "數量"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:67
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:84
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:119
|
||||
msgid "Tag"
|
||||
msgstr "標籤"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:99
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:140
|
||||
msgid "From"
|
||||
msgstr "從"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:108
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:145
|
||||
msgid "To"
|
||||
msgstr "至"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:124
|
||||
msgid "Route"
|
||||
msgstr "路線"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/include/summary-helper-modal.html:160
|
||||
msgid "The number of items"
|
||||
msgstr "數量"
|
||||
|
||||
#: src/accounting/templates/accounting/transaction/income/create.html:24
|
||||
msgid "Add a New Cash Income Transaction"
|
||||
msgstr "新增現金收入傳票"
|
||||
@ -533,27 +590,27 @@ msgstr "借方"
|
||||
msgid "Credit"
|
||||
msgstr "貸方"
|
||||
|
||||
#: src/accounting/transaction/forms.py:44
|
||||
#: src/accounting/transaction/forms.py:45
|
||||
msgid "Please select the currency."
|
||||
msgstr "請選擇貨幣。"
|
||||
|
||||
#: src/accounting/transaction/forms.py:67
|
||||
#: src/accounting/transaction/forms.py:68
|
||||
msgid "The currency does not exist."
|
||||
msgstr "沒有這個貨幣。"
|
||||
|
||||
#: src/accounting/transaction/forms.py:88
|
||||
#: src/accounting/transaction/forms.py:89
|
||||
msgid "The account does not exist."
|
||||
msgstr "沒有這個科目。"
|
||||
|
||||
#: src/accounting/transaction/forms.py:99
|
||||
#: src/accounting/transaction/forms.py:100
|
||||
msgid "Please fill in a positive amount."
|
||||
msgstr "金額請填正數。"
|
||||
|
||||
#: src/accounting/transaction/forms.py:113
|
||||
#: src/accounting/transaction/forms.py:114
|
||||
msgid "This account is not for debit entries."
|
||||
msgstr "科目不是借方科目。"
|
||||
|
||||
#: src/accounting/transaction/forms.py:200
|
||||
#: src/accounting/transaction/forms.py:201
|
||||
msgid "This account is not for credit entries."
|
||||
msgstr "科目不是貸方科目。"
|
||||
|
||||
|
30
src/accounting/utils/txn_types.py
Normal file
30
src/accounting/utils/txn_types.py
Normal file
@ -0,0 +1,30 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/4
|
||||
|
||||
# Copyright (c) 2023 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""The transaction types.
|
||||
|
||||
"""
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class TransactionType(Enum):
|
||||
"""The transaction types."""
|
||||
CASH_INCOME: str = "income"
|
||||
"""The cash income transaction."""
|
||||
CASH_EXPENSE: str = "expense"
|
||||
"""The cash expense transaction."""
|
||||
TRANSFER: str = "transfer"
|
||||
"""The transfer transaction."""
|
@ -62,7 +62,7 @@ stock: AccountData = AccountData("1121", 1, "Stock")
|
||||
loan: AccountData = AccountData("2112", 1, "Loan")
|
||||
"""The loan account."""
|
||||
PREFIX: str = "/accounting/accounts"
|
||||
"""The URL prefix of the currency management."""
|
||||
"""The URL prefix for the account management."""
|
||||
|
||||
|
||||
class AccountCommandTestCase(unittest.TestCase):
|
||||
@ -409,9 +409,9 @@ class AccountTestCase(unittest.TestCase):
|
||||
f"{stock.base_code}-002",
|
||||
f"{stock.base_code}-003"})
|
||||
|
||||
stock_account: Account = Account.find_by_code(stock.code)
|
||||
self.assertEqual(stock_account.base_code, stock.base_code)
|
||||
self.assertEqual(stock_account.title_l10n, stock.title)
|
||||
account: Account = Account.find_by_code(stock.code)
|
||||
self.assertEqual(account.base_code, stock.base_code)
|
||||
self.assertEqual(account.title_l10n, stock.title)
|
||||
|
||||
def test_basic_update(self) -> None:
|
||||
"""Tests the basic rules to update a user.
|
||||
@ -434,9 +434,9 @@ class AccountTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account: Account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(cash_account.base_code, cash.base_code)
|
||||
self.assertEqual(cash_account.title_l10n, f"{cash.title}-1")
|
||||
account: Account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(account.base_code, cash.base_code)
|
||||
self.assertEqual(account.title_l10n, f"{cash.title}-1")
|
||||
|
||||
# Empty base account code
|
||||
response = self.client.post(update_uri,
|
||||
@ -492,7 +492,7 @@ class AccountTestCase(unittest.TestCase):
|
||||
from accounting.models import Account
|
||||
detail_uri: str = f"{PREFIX}/{cash.code}"
|
||||
update_uri: str = f"{PREFIX}/{cash.code}/update"
|
||||
cash_account: Account
|
||||
account: Account
|
||||
response: httpx.Response
|
||||
|
||||
response = self.client.post(update_uri,
|
||||
@ -503,11 +503,11 @@ class AccountTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account = Account.find_by_code(cash.code)
|
||||
self.assertIsNotNone(cash_account)
|
||||
cash_account.created_at \
|
||||
= cash_account.created_at - timedelta(seconds=5)
|
||||
cash_account.updated_at = cash_account.created_at
|
||||
account = Account.find_by_code(cash.code)
|
||||
self.assertIsNotNone(account)
|
||||
account.created_at \
|
||||
= account.created_at - timedelta(seconds=5)
|
||||
account.updated_at = account.created_at
|
||||
db.session.commit()
|
||||
|
||||
response = self.client.post(update_uri,
|
||||
@ -518,10 +518,10 @@ class AccountTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account = Account.find_by_code(cash.code)
|
||||
self.assertIsNotNone(cash_account)
|
||||
self.assertLess(cash_account.created_at,
|
||||
cash_account.updated_at)
|
||||
account = Account.find_by_code(cash.code)
|
||||
self.assertIsNotNone(account)
|
||||
self.assertLess(account.created_at,
|
||||
account.updated_at)
|
||||
|
||||
def test_created_updated_by(self) -> None:
|
||||
"""Tests the created-by and updated-by record.
|
||||
@ -533,12 +533,13 @@ class AccountTestCase(unittest.TestCase):
|
||||
client, csrf_token = get_client(self.app, editor2_username)
|
||||
detail_uri: str = f"{PREFIX}/{cash.code}"
|
||||
update_uri: str = f"{PREFIX}/{cash.code}/update"
|
||||
account: Account
|
||||
response: httpx.Response
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account: Account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(cash_account.created_by.username, editor_username)
|
||||
self.assertEqual(cash_account.updated_by.username, editor_username)
|
||||
account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(account.created_by.username, editor_username)
|
||||
self.assertEqual(account.updated_by.username, editor_username)
|
||||
|
||||
response = client.post(update_uri,
|
||||
data={"csrf_token": csrf_token,
|
||||
@ -548,10 +549,10 @@ class AccountTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account: Account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(cash_account.created_by.username,
|
||||
account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(account.created_by.username,
|
||||
editor_username)
|
||||
self.assertEqual(cash_account.updated_by.username,
|
||||
self.assertEqual(account.updated_by.username,
|
||||
editor2_username)
|
||||
|
||||
def test_l10n(self) -> None:
|
||||
@ -562,12 +563,13 @@ class AccountTestCase(unittest.TestCase):
|
||||
from accounting.models import Account
|
||||
detail_uri: str = f"{PREFIX}/{cash.code}"
|
||||
update_uri: str = f"{PREFIX}/{cash.code}/update"
|
||||
account: Account
|
||||
response: httpx.Response
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account: Account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(cash_account.title_l10n, cash.title)
|
||||
self.assertEqual(cash_account.l10n, [])
|
||||
account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(account.title_l10n, cash.title)
|
||||
self.assertEqual(account.l10n, [])
|
||||
|
||||
set_locale(self.client, self.csrf_token, "zh_Hant")
|
||||
|
||||
@ -579,9 +581,9 @@ class AccountTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account: Account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(cash_account.title_l10n, cash.title)
|
||||
self.assertEqual({(x.locale, x.title) for x in cash_account.l10n},
|
||||
account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(account.title_l10n, cash.title)
|
||||
self.assertEqual({(x.locale, x.title) for x in account.l10n},
|
||||
{("zh_Hant", f"{cash.title}-zh_Hant")})
|
||||
|
||||
set_locale(self.client, self.csrf_token, "en")
|
||||
@ -594,9 +596,9 @@ class AccountTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account: Account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(cash_account.title_l10n, f"{cash.title}-2")
|
||||
self.assertEqual({(x.locale, x.title) for x in cash_account.l10n},
|
||||
account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(account.title_l10n, f"{cash.title}-2")
|
||||
self.assertEqual({(x.locale, x.title) for x in account.l10n},
|
||||
{("zh_Hant", f"{cash.title}-zh_Hant")})
|
||||
|
||||
set_locale(self.client, self.csrf_token, "zh_Hant")
|
||||
@ -609,9 +611,9 @@ class AccountTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
cash_account: Account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(cash_account.title_l10n, f"{cash.title}-2")
|
||||
self.assertEqual({(x.locale, x.title) for x in cash_account.l10n},
|
||||
account = Account.find_by_code(cash.code)
|
||||
self.assertEqual(account.title_l10n, f"{cash.title}-2")
|
||||
self.assertEqual({(x.locale, x.title) for x in account.l10n},
|
||||
{("zh_Hant", f"{cash.title}-zh_Hant-2")})
|
||||
|
||||
def test_delete(self) -> None:
|
||||
|
@ -55,7 +55,7 @@ zzc: CurrencyData = CurrencyData("ZZC", "Testing Dollar #C")
|
||||
zzd: CurrencyData = CurrencyData("ZZD", "Testing Dollar #D")
|
||||
"""The fourth test currency."""
|
||||
PREFIX: str = "/accounting/currencies"
|
||||
"""The URL prefix of the currency management."""
|
||||
"""The URL prefix for the currency management."""
|
||||
|
||||
|
||||
class CurrencyCommandTestCase(unittest.TestCase):
|
||||
@ -342,9 +342,9 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
self.assertEqual({x.code for x in Currency.query.all()},
|
||||
{zza.code, zzb.code, zzc.code})
|
||||
|
||||
zzc_currency: Currency = db.session.get(Currency, zzc.code)
|
||||
self.assertEqual(zzc_currency.code, zzc.code)
|
||||
self.assertEqual(zzc_currency.name_l10n, zzc.name)
|
||||
currency: Currency = db.session.get(Currency, zzc.code)
|
||||
self.assertEqual(currency.code, zzc.code)
|
||||
self.assertEqual(currency.name_l10n, zzc.name)
|
||||
|
||||
def test_basic_update(self) -> None:
|
||||
"""Tests the basic rules to update a user.
|
||||
@ -367,9 +367,9 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency: Currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(zza_currency.code, zza.code)
|
||||
self.assertEqual(zza_currency.name_l10n, f"{zza.name}-1")
|
||||
currency: Currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(currency.code, zza.code)
|
||||
self.assertEqual(currency.name_l10n, f"{zza.name}-1")
|
||||
|
||||
# Empty code
|
||||
response = self.client.post(update_uri,
|
||||
@ -433,7 +433,7 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
from accounting.models import Currency
|
||||
detail_uri: str = f"{PREFIX}/{zza.code}"
|
||||
update_uri: str = f"{PREFIX}/{zza.code}/update"
|
||||
zza_currency: Currency
|
||||
currency: Currency | None
|
||||
response: httpx.Response
|
||||
|
||||
response = self.client.post(update_uri,
|
||||
@ -444,11 +444,11 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency = db.session.get(Currency, zza.code)
|
||||
self.assertIsNotNone(zza_currency)
|
||||
zza_currency.created_at \
|
||||
= zza_currency.created_at - timedelta(seconds=5)
|
||||
zza_currency.updated_at = zza_currency.created_at
|
||||
currency = db.session.get(Currency, zza.code)
|
||||
self.assertIsNotNone(currency)
|
||||
currency.created_at \
|
||||
= currency.created_at - timedelta(seconds=5)
|
||||
currency.updated_at = currency.created_at
|
||||
db.session.commit()
|
||||
|
||||
response = self.client.post(update_uri,
|
||||
@ -459,10 +459,10 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency = db.session.get(Currency, zza.code)
|
||||
self.assertIsNotNone(zza_currency)
|
||||
self.assertLess(zza_currency.created_at,
|
||||
zza_currency.updated_at)
|
||||
currency = db.session.get(Currency, zza.code)
|
||||
self.assertIsNotNone(currency)
|
||||
self.assertLess(currency.created_at,
|
||||
currency.updated_at)
|
||||
|
||||
def test_created_updated_by(self) -> None:
|
||||
"""Tests the created-by and updated-by record.
|
||||
@ -474,12 +474,13 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
client, csrf_token = get_client(self.app, editor2_username)
|
||||
detail_uri: str = f"{PREFIX}/{zza.code}"
|
||||
update_uri: str = f"{PREFIX}/{zza.code}/update"
|
||||
currency: Currency
|
||||
response: httpx.Response
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency: Currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(zza_currency.created_by.username, editor_username)
|
||||
self.assertEqual(zza_currency.updated_by.username, editor_username)
|
||||
currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(currency.created_by.username, editor_username)
|
||||
self.assertEqual(currency.updated_by.username, editor_username)
|
||||
|
||||
response = client.post(update_uri,
|
||||
data={"csrf_token": csrf_token,
|
||||
@ -489,9 +490,9 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency: Currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(zza_currency.created_by.username, editor_username)
|
||||
self.assertEqual(zza_currency.updated_by.username, editor2_username)
|
||||
currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(currency.created_by.username, editor_username)
|
||||
self.assertEqual(currency.updated_by.username, editor2_username)
|
||||
|
||||
def test_api_exists(self) -> None:
|
||||
"""Tests the API to check if a code exists.
|
||||
@ -522,12 +523,13 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
from accounting.models import Currency
|
||||
detail_uri: str = f"{PREFIX}/{zza.code}"
|
||||
update_uri: str = f"{PREFIX}/{zza.code}/update"
|
||||
currency: Currency
|
||||
response: httpx.Response
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency: Currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(zza_currency.name_l10n, zza.name)
|
||||
self.assertEqual(zza_currency.l10n, [])
|
||||
currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(currency.name_l10n, zza.name)
|
||||
self.assertEqual(currency.l10n, [])
|
||||
|
||||
set_locale(self.client, self.csrf_token, "zh_Hant")
|
||||
|
||||
@ -539,9 +541,9 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency: Currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(zza_currency.name_l10n, zza.name)
|
||||
self.assertEqual({(x.locale, x.name) for x in zza_currency.l10n},
|
||||
currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(currency.name_l10n, zza.name)
|
||||
self.assertEqual({(x.locale, x.name) for x in currency.l10n},
|
||||
{("zh_Hant", f"{zza.name}-zh_Hant")})
|
||||
|
||||
set_locale(self.client, self.csrf_token, "en")
|
||||
@ -554,9 +556,9 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency: Currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(zza_currency.name_l10n, f"{zza.name}-2")
|
||||
self.assertEqual({(x.locale, x.name) for x in zza_currency.l10n},
|
||||
currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(currency.name_l10n, f"{zza.name}-2")
|
||||
self.assertEqual({(x.locale, x.name) for x in currency.l10n},
|
||||
{("zh_Hant", f"{zza.name}-zh_Hant")})
|
||||
|
||||
set_locale(self.client, self.csrf_token, "zh_Hant")
|
||||
@ -569,9 +571,9 @@ class CurrencyTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Location"], detail_uri)
|
||||
|
||||
with self.app.app_context():
|
||||
zza_currency: Currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(zza_currency.name_l10n, f"{zza.name}-2")
|
||||
self.assertEqual({(x.locale, x.name) for x in zza_currency.l10n},
|
||||
currency = db.session.get(Currency, zza.code)
|
||||
self.assertEqual(currency.name_l10n, f"{zza.name}-2")
|
||||
self.assertEqual({(x.locale, x.name) for x in currency.l10n},
|
||||
{("zh_Hant", f"{zza.name}-zh_Hant-2")})
|
||||
|
||||
def test_delete(self) -> None:
|
||||
|
@ -25,12 +25,14 @@ First written: 2023/1/27
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="author" content="{{ "imacat" }}" />
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.1/css/all.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.1/css/all.min.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.2.10/dist/css/tempus-dominus.min.css" crossorigin="anonymous">
|
||||
{% block styles %}{% endblock %}
|
||||
<script src="{{ url_for("babel_catalog") }}"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/decimal.js-light@2.5.1/decimal.min.js" integrity="sha384-QdsxGEq4Y0erX8WUIsZJDtfoSSyBF6dmNCnzRNYCa2AOM/xzNsyhHu0RbdFBAm+l" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.2.10/dist/js/tempus-dominus.min.js" integrity="sha384-BiIgBzfRUwCKCLJTFUfZPl8n4yeDooQYkgtJBNVI4Gg6OAfIFO6FhEK6KiO1dvhA" crossorigin="anonymous"></script>
|
||||
{% block scripts %}{% endblock %}
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
</head>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user