修正
This commit is contained in:
@@ -60,14 +60,19 @@ 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 より前の仕訳による増減
|
||||
# 修正された仕訳(親となった仕訳)は除外
|
||||
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
|
||||
""", (aid, date_from))
|
||||
opening_from_journals = D(cur.fetchone()["opening"])
|
||||
|
||||
@@ -75,6 +80,7 @@ def fetch_trial_balance(date_from: str, date_to: str):
|
||||
opening = opening_balance_from_table + opening_from_journals
|
||||
|
||||
# 当期増減(date_from ~ date_to)
|
||||
# 修正された仕訳(親となった仕訳)は除外
|
||||
cur.execute("""
|
||||
SELECT
|
||||
COALESCE(SUM(l.debit), 0) AS debit,
|
||||
@@ -82,9 +88,13 @@ 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
|
||||
""", (aid, date_from, date_to))
|
||||
row = cur.fetchone()
|
||||
debit = D(row["debit"])
|
||||
|
||||
@@ -17,9 +17,10 @@ opening AS (
|
||||
SUM(jl.debit) AS opening_debit,
|
||||
SUM(jl.credit) AS opening_credit
|
||||
FROM journal_entries je
|
||||
JOIN journal_lines jl ON jl.journal_id = je.journal_id
|
||||
JOIN journal_lines jl ON jl.journal_entry_id = je.journal_entry_id
|
||||
WHERE je.description = '前期残高'
|
||||
AND je.journal_date = %(start_date)s
|
||||
AND je.entry_date = %(start_date)s
|
||||
AND je.is_deleted = false
|
||||
GROUP BY jl.account_id
|
||||
),
|
||||
|
||||
@@ -29,9 +30,15 @@ period AS (
|
||||
SUM(jl.debit) AS period_debit,
|
||||
SUM(jl.credit) AS period_credit
|
||||
FROM journal_entries je
|
||||
JOIN journal_lines jl ON jl.journal_id = je.journal_id
|
||||
WHERE je.journal_date BETWEEN %(start_date)s AND %(end_date)s
|
||||
JOIN journal_lines jl ON jl.journal_entry_id = je.journal_entry_id
|
||||
LEFT JOIN journal_entries child ON child.parent_entry_id = je.journal_entry_id
|
||||
WHERE je.entry_date BETWEEN %(start_date)s AND %(end_date)s
|
||||
AND je.description <> '前期残高'
|
||||
AND je.is_deleted = false
|
||||
-- 逆仕訳を除外([逆仕訳]プレフィックスを持つ仕訳)
|
||||
AND je.description NOT LIKE '[逆仕訳]%'
|
||||
-- 子仕訳(修正後仕訳)を持つ修正前の仕訳を除外
|
||||
AND child.journal_entry_id IS NULL
|
||||
GROUP BY jl.account_id
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user