修改
This commit is contained in:
@@ -24,7 +24,7 @@ ACCOUNT_GROUPS = [
|
||||
("負債合計", ["501", "502", "503", "504", "505", "506", "507", "508", "509"]),
|
||||
# 資本の部
|
||||
("資本金合計", ["601"]),
|
||||
("利益剰余金合計", ["602"]),
|
||||
# 利益剰余金合計は特別処理(602 + 当期純利益の内訳を表示)
|
||||
("純資産合計", ["601", "602"])
|
||||
]
|
||||
|
||||
@@ -145,6 +145,101 @@ def fetch_trial_balance(date_from: str, date_to: str):
|
||||
# 大区分合計用に総計を積算
|
||||
grand_total_closing += data["closing_balance"]
|
||||
|
||||
# 利益剰余金(602)の後に詳細を挿入
|
||||
if code == "602":
|
||||
# 繰越利益剰余金 = 602の期首残高
|
||||
retained_earnings_opening = data["opening_balance"]
|
||||
|
||||
# 当期純損益金額を計算(収益 - 費用)
|
||||
# 収益(7xx)の合計
|
||||
revenue_total = D(0)
|
||||
for acc_code, acc_data in account_data.items():
|
||||
if acc_code.startswith("7"):
|
||||
# 収益は貸方が増加、借方が減少
|
||||
revenue_total += acc_data["credit"] - acc_data["debit"]
|
||||
|
||||
# 費用(8xx)の合計
|
||||
expense_total = D(0)
|
||||
for acc_code, acc_data in account_data.items():
|
||||
if acc_code.startswith("8"):
|
||||
# 費用は借方が増加、貸方が減少
|
||||
expense_total += acc_data["debit"] - acc_data["credit"]
|
||||
|
||||
# 当期純損益金額 = 収益 - 費用
|
||||
net_income = revenue_total - expense_total
|
||||
|
||||
# 繰越利益剰余金合計 = 期首繰越利益 + 当期純損益
|
||||
retained_earnings_total = retained_earnings_opening + net_income
|
||||
|
||||
# 繰越利益の行を追加
|
||||
result_accounts.append({
|
||||
"account_code": "",
|
||||
"account_name": " 繰越利益",
|
||||
"account_type": "equity",
|
||||
"opening_balance": str(retained_earnings_opening),
|
||||
"debit": "0",
|
||||
"credit": "0",
|
||||
"closing_balance": str(retained_earnings_opening),
|
||||
"ratio": None,
|
||||
"is_total": False,
|
||||
"indent": True
|
||||
})
|
||||
|
||||
# 当期純損益金額の行を追加
|
||||
result_accounts.append({
|
||||
"account_code": "",
|
||||
"account_name": " 当期純損益金額",
|
||||
"account_type": "equity",
|
||||
"opening_balance": "0",
|
||||
"debit": str(expense_total) if expense_total > 0 else "0",
|
||||
"credit": str(revenue_total) if revenue_total > 0 else "0",
|
||||
"closing_balance": str(net_income),
|
||||
"ratio": None,
|
||||
"is_total": False,
|
||||
"indent": True
|
||||
})
|
||||
|
||||
# 繰越利益剰余金合計の行を追加
|
||||
result_accounts.append({
|
||||
"account_code": "",
|
||||
"account_name": " 繰越利益剰余金合計",
|
||||
"account_type": "equity",
|
||||
"opening_balance": str(retained_earnings_opening),
|
||||
"debit": str(expense_total) if expense_total > 0 else "0",
|
||||
"credit": str(revenue_total) if revenue_total > 0 else "0",
|
||||
"closing_balance": str(retained_earnings_total),
|
||||
"ratio": None,
|
||||
"is_total": True,
|
||||
"indent": True
|
||||
})
|
||||
|
||||
# その他利益剰余金合計(現在は0)
|
||||
result_accounts.append({
|
||||
"account_code": "",
|
||||
"account_name": " その他利益剰余金合計",
|
||||
"account_type": "equity",
|
||||
"opening_balance": "0",
|
||||
"debit": "0",
|
||||
"credit": "0",
|
||||
"closing_balance": "0",
|
||||
"ratio": None,
|
||||
"is_total": True,
|
||||
"indent": True
|
||||
})
|
||||
|
||||
# 利益剰余金合計の行を追加
|
||||
result_accounts.append({
|
||||
"account_code": "",
|
||||
"account_name": "利益剰余金合計",
|
||||
"account_type": "equity",
|
||||
"opening_balance": str(retained_earnings_opening),
|
||||
"debit": str(expense_total) if expense_total > 0 else "0",
|
||||
"credit": str(revenue_total) if revenue_total > 0 else "0",
|
||||
"closing_balance": str(retained_earnings_total),
|
||||
"ratio": None,
|
||||
"is_total": True
|
||||
})
|
||||
|
||||
# 合計行を挿入(グループ定義の順序で)
|
||||
for group_name, group_codes in ACCOUNT_GROUPS:
|
||||
# このグループにまだ合計行を挿入していない
|
||||
|
||||
Reference in New Issue
Block a user