desktop修正
This commit is contained in:
@@ -2,6 +2,7 @@ from fastapi import APIRouter, HTTPException, Query
|
||||
from decimal import Decimal
|
||||
from typing import Dict, Any, List
|
||||
from app.core.database import get_connection
|
||||
from app.modules.trial_balance.service import fetch_trial_balance
|
||||
|
||||
router = APIRouter(prefix="/trial-balance", tags=["試算表"])
|
||||
|
||||
@@ -10,12 +11,23 @@ def D(x) -> Decimal:
|
||||
|
||||
@router.get("", summary="試算表(全科目)")
|
||||
def get_trial_balance(
|
||||
fiscal_year: int = Query(..., description="会計年度(例: 2025)"),
|
||||
date_from: str = Query(..., description="YYYY-MM-DD"),
|
||||
date_to: str = Query(..., description="YYYY-MM-DD"),
|
||||
):
|
||||
if date_from > date_to:
|
||||
raise HTTPException(status_code=400, detail="期間指定が不正です。")
|
||||
|
||||
result = fetch_trial_balance(date_from, date_to)
|
||||
|
||||
return {
|
||||
"period": {
|
||||
"from": date_from,
|
||||
"to": date_to
|
||||
},
|
||||
**result
|
||||
}
|
||||
|
||||
with get_connection() as conn, conn.cursor() as cur:
|
||||
|
||||
# 全科目取得
|
||||
@@ -37,15 +49,18 @@ def get_trial_balance(
|
||||
for acc in accounts:
|
||||
aid = acc["account_id"]
|
||||
|
||||
# 期首残高
|
||||
# 期首残高(opening_balances)
|
||||
cur.execute("""
|
||||
SELECT COALESCE(SUM(l.debit - l.credit), 0) AS opening
|
||||
FROM journal_lines l
|
||||
JOIN journal_entries j ON j.journal_id = l.journal_id
|
||||
WHERE l.account_id = %s
|
||||
AND j.journal_date < %s
|
||||
""", (aid, date_from))
|
||||
opening = D(cur.fetchone()["opening"])
|
||||
SELECT
|
||||
COALESCE(opening_debit, 0) - COALESCE(opening_credit, 0) AS opening
|
||||
FROM opening_balances
|
||||
WHERE fiscal_year = %s
|
||||
AND account_id = %s
|
||||
""", (fiscal_year, aid))
|
||||
|
||||
row = cur.fetchone()
|
||||
opening = D(row["opening"]) if row else D(0)
|
||||
|
||||
|
||||
# 当期
|
||||
cur.execute("""
|
||||
|
||||
Reference in New Issue
Block a user