修正
This commit is contained in:
@@ -8,7 +8,13 @@ SELECT
|
||||
FROM journal_lines l
|
||||
JOIN journal_entries j
|
||||
ON j.journal_id = l.journal_id
|
||||
LEFT JOIN journal_entries child
|
||||
ON child.parent_entry_id = j.journal_id
|
||||
WHERE l.account_id = %(account_id)s
|
||||
AND j.journal_date BETWEEN %(date_from)s AND %(date_to)s
|
||||
-- 逆仕訳を除外
|
||||
AND j.description NOT LIKE '[逆仕訳]%'
|
||||
-- 子仕訳(修正後仕訳)を持つ修正前の仕訳を除外
|
||||
AND child.journal_id IS NULL
|
||||
ORDER BY j.journal_date, l.line_id;
|
||||
"""
|
||||
|
||||
@@ -64,8 +64,14 @@ def get_general_ledger(
|
||||
FROM journal_entries j
|
||||
JOIN journal_lines l
|
||||
ON l.journal_id = j.journal_id
|
||||
LEFT JOIN journal_entries child
|
||||
ON child.parent_entry_id = j.journal_id
|
||||
WHERE l.account_id = %s
|
||||
AND j.journal_date BETWEEN %s AND %s
|
||||
-- 逆仕訳を除外
|
||||
AND j.description NOT LIKE '[逆仕訳]%'
|
||||
-- 子仕訳(修正後仕訳)を持つ修正前の仕訳を除外
|
||||
AND child.journal_id IS NULL
|
||||
ORDER BY j.journal_date, l.line_id
|
||||
""", (account_id, date_from, date_to))
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class JournalEntryRequest(BaseModel):
|
||||
tax_paid_account_id: Optional[int] = None # 仮払消費税等 勘定
|
||||
tax_received_account_id: Optional[int] = None # 仮受消費税等 勘定
|
||||
rounding_mode: str = "round" # "round", "floor", or "ceil"
|
||||
parent_entry_id: Optional[int] = None # 修正元の仕訳ID
|
||||
|
||||
class JournalEntryUpdateRequest(BaseModel):
|
||||
description: str
|
||||
@@ -58,7 +59,8 @@ def get_journal_entries(
|
||||
je.fiscal_year,
|
||||
je.version,
|
||||
COALESCE(SUM(jl.debit), 0) as debit_total,
|
||||
COALESCE(SUM(jl.credit), 0) as credit_total
|
||||
COALESCE(SUM(jl.credit), 0) as credit_total,
|
||||
STRING_AGG(DISTINCT CASE WHEN jl.tax_rate IS NOT NULL THEN jl.tax_rate::text END, ', ' ORDER BY CASE WHEN jl.tax_rate IS NOT NULL THEN jl.tax_rate::text END) as tax_rates
|
||||
FROM journal_entries je
|
||||
LEFT JOIN journal_lines jl ON je.journal_entry_id = jl.journal_entry_id
|
||||
WHERE je.is_deleted = false
|
||||
@@ -74,7 +76,8 @@ def get_journal_entries(
|
||||
je.fiscal_year,
|
||||
je.version,
|
||||
COALESCE(SUM(jl.debit), 0) as debit_total,
|
||||
COALESCE(SUM(jl.credit), 0) as credit_total
|
||||
COALESCE(SUM(jl.credit), 0) as credit_total,
|
||||
STRING_AGG(DISTINCT CASE WHEN jl.tax_rate IS NOT NULL THEN jl.tax_rate::text END, ', ' ORDER BY CASE WHEN jl.tax_rate IS NOT NULL THEN jl.tax_rate::text END) as tax_rates
|
||||
FROM journal_entries je
|
||||
LEFT JOIN journal_lines jl ON je.journal_entry_id = jl.journal_entry_id
|
||||
WHERE je.is_deleted = false
|
||||
@@ -202,15 +205,17 @@ def create_reverse_entry(journal_id: int):
|
||||
fiscal_year,
|
||||
version,
|
||||
is_deleted,
|
||||
created_by
|
||||
created_by,
|
||||
parent_entry_id
|
||||
)
|
||||
VALUES (%s, %s, %s, 1, false, %s)
|
||||
VALUES (%s, %s, %s, 1, false, %s, %s)
|
||||
RETURNING journal_entry_id
|
||||
""", (
|
||||
header["entry_date"],
|
||||
f"[逆仕訳] {header['description']}",
|
||||
header["fiscal_year"],
|
||||
"system"
|
||||
"system",
|
||||
journal_id # 逆仕訳の元となる仕訳ID
|
||||
))
|
||||
|
||||
new_entry_id = cur.fetchone()["journal_entry_id"]
|
||||
@@ -322,15 +327,17 @@ def create_journal_entry(req: JournalEntryRequest):
|
||||
fiscal_year,
|
||||
version,
|
||||
is_deleted,
|
||||
created_by
|
||||
created_by,
|
||||
parent_entry_id
|
||||
)
|
||||
VALUES (%s, %s, %s, 1, false, %s)
|
||||
VALUES (%s, %s, %s, 1, false, %s, %s)
|
||||
RETURNING journal_entry_id
|
||||
""", (
|
||||
req.entry_date,
|
||||
req.description,
|
||||
fiscal_year,
|
||||
"system"
|
||||
"system",
|
||||
req.parent_entry_id
|
||||
))
|
||||
|
||||
entry_id = cur.fetchone()["journal_entry_id"]
|
||||
|
||||
Reference in New Issue
Block a user