This commit is contained in:
admin
2026-02-20 15:47:27 +09:00
parent c60cbf2d9a
commit 584530937b
108 changed files with 12112 additions and 416 deletions

View File

@@ -61,19 +61,16 @@ def fetch_trial_balance(date_from: str, date_to: str):
opening_balance_from_table = D(ob_row["ob"]) if ob_row else D(0)
# date_from より前の仕訳による増減
# 修正された仕訳(親となった仕訳)は除外
# 修正された仕訳(is_latest = false)は除外
cur.execute("""
SELECT COALESCE(SUM(l.debit - l.credit), 0) AS opening
FROM journal_lines l
JOIN journal_entries j
ON j.journal_entry_id = l.journal_entry_id
LEFT JOIN journal_entries child
ON child.parent_entry_id = j.journal_entry_id
WHERE l.account_id = %s
AND j.entry_date < %s
AND j.is_deleted = false
AND j.description NOT LIKE '[逆仕訳]%%'
AND child.journal_entry_id IS NULL
AND j.is_latest = true
""", (aid, date_from))
opening_from_journals = D(cur.fetchone()["opening"])
@@ -81,7 +78,7 @@ def fetch_trial_balance(date_from: str, date_to: str):
opening = opening_balance_from_table + opening_from_journals
# 当期増減date_from date_to
# 修正された仕訳(親となった仕訳)は除外
# 修正された仕訳(is_latest = false)は除外
cur.execute("""
SELECT
COALESCE(SUM(l.debit), 0) AS debit,
@@ -89,13 +86,10 @@ def fetch_trial_balance(date_from: str, date_to: str):
FROM journal_lines l
JOIN journal_entries j
ON j.journal_entry_id = l.journal_entry_id
LEFT JOIN journal_entries child
ON child.parent_entry_id = j.journal_entry_id
WHERE l.account_id = %s
AND j.entry_date BETWEEN %s AND %s
AND j.is_deleted = false
AND j.description NOT LIKE '[逆仕訳]%%'
AND child.journal_entry_id IS NULL
AND j.is_latest = true
""", (aid, date_from, date_to))
row = cur.fetchone()
debit = D(row["debit"])