修改
This commit is contained in:
@@ -39,7 +39,7 @@ def lock_fiscal_year(req: LockRequest):
|
||||
ON CONFLICT (fiscal_year)
|
||||
DO UPDATE SET
|
||||
is_locked = true,
|
||||
locked_at = CURRENT_TIMESTAMP
|
||||
locked_at = CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Tokyo'
|
||||
""", (req.fiscal_year,))
|
||||
conn.commit()
|
||||
|
||||
|
||||
@@ -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:
|
||||
# このグループにまだ合計行を挿入していない
|
||||
|
||||
@@ -423,7 +423,7 @@ def update_journal_entry(journal_id: int, req: JournalEntryUpdateRequest):
|
||||
UPDATE journal_entries
|
||||
SET description = %s,
|
||||
version = version + 1,
|
||||
updated_at = NOW(),
|
||||
updated_at = CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Tokyo',
|
||||
updated_reason = %s
|
||||
WHERE journal_id = %s
|
||||
""", (
|
||||
@@ -472,7 +472,7 @@ def delete_journal_entry(journal_id: int, req: JournalEntryDeleteRequest):
|
||||
cur.execute("""
|
||||
UPDATE journal_entries
|
||||
SET is_deleted = true,
|
||||
updated_at = NOW()
|
||||
updated_at = CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Tokyo'
|
||||
WHERE journal_entry_id = %s
|
||||
AND is_deleted = false
|
||||
RETURNING journal_entry_id
|
||||
|
||||
@@ -14,7 +14,7 @@ def get_month_locks():
|
||||
fiscal_year,
|
||||
month,
|
||||
is_locked,
|
||||
locked_at,
|
||||
(locked_at AT TIME ZONE 'UTC') AT TIME ZONE 'Asia/Tokyo' as locked_at,
|
||||
locked_by
|
||||
FROM month_locks
|
||||
ORDER BY fiscal_year, month
|
||||
@@ -39,11 +39,11 @@ def lock_month(fiscal_year: int, month: int):
|
||||
locked_at,
|
||||
locked_by
|
||||
)
|
||||
VALUES (%s, %s, true, NOW(), %s)
|
||||
VALUES (%s, %s, true, CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Tokyo', %s)
|
||||
ON CONFLICT (fiscal_year, month)
|
||||
DO UPDATE
|
||||
SET is_locked = true,
|
||||
locked_at = NOW(),
|
||||
locked_at = CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Tokyo',
|
||||
locked_by = EXCLUDED.locked_by
|
||||
""", (
|
||||
fiscal_year,
|
||||
|
||||
@@ -8,7 +8,9 @@ router = APIRouter(prefix="/year-locks", tags=["年度锁定"])
|
||||
def get_year_locks():
|
||||
with get_connection() as conn, conn.cursor() as cur:
|
||||
cur.execute("""
|
||||
SELECT fiscal_year, is_locked, locked_at, locked_by
|
||||
SELECT fiscal_year, is_locked,
|
||||
(locked_at AT TIME ZONE 'UTC') AT TIME ZONE 'Asia/Tokyo' as locked_at,
|
||||
locked_by
|
||||
FROM year_locks
|
||||
ORDER BY fiscal_year
|
||||
""")
|
||||
@@ -20,11 +22,11 @@ def lock_year(fiscal_year: int):
|
||||
with get_connection() as conn, conn.cursor() as cur:
|
||||
cur.execute("""
|
||||
INSERT INTO year_locks (fiscal_year, is_locked, locked_at, locked_by)
|
||||
VALUES (%s, true, NOW(), %s)
|
||||
VALUES (%s, true, CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Tokyo', %s)
|
||||
ON CONFLICT (fiscal_year)
|
||||
DO UPDATE
|
||||
SET is_locked = true,
|
||||
locked_at = NOW(),
|
||||
locked_at = CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Tokyo',
|
||||
locked_by = EXCLUDED.locked_by
|
||||
""", (fiscal_year, "system"))
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user