修正
This commit is contained in:
@@ -39,7 +39,8 @@ def get_journal_entries(
|
||||
from_date: date = None,
|
||||
to_date: date = None,
|
||||
keyword: str = None,
|
||||
account_id: int = None
|
||||
account_id: int = None,
|
||||
include_history: bool = False
|
||||
):
|
||||
"""
|
||||
仕訳一覧を検索して取得
|
||||
@@ -47,20 +48,44 @@ def get_journal_entries(
|
||||
with get_connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
# クエリ構築
|
||||
if include_history:
|
||||
# 修正履歴を含むすべてのバージョンを表示
|
||||
sql = """
|
||||
SELECT
|
||||
je.journal_entry_id,
|
||||
je.entry_date,
|
||||
je.description,
|
||||
je.fiscal_year,
|
||||
je.version,
|
||||
COALESCE(SUM(jl.debit), 0) as debit_total,
|
||||
COALESCE(SUM(jl.credit), 0) as credit_total
|
||||
FROM journal_entries je
|
||||
LEFT JOIN journal_lines jl ON je.journal_entry_id = jl.journal_entry_id
|
||||
WHERE je.is_deleted = false
|
||||
"""
|
||||
|
||||
params = []
|
||||
else:
|
||||
# 最新バージョンのみ表示:parent_entry_idを持つ古い仕訳と逆仕訳を除外
|
||||
sql = """
|
||||
SELECT
|
||||
je.journal_entry_id,
|
||||
je.entry_date,
|
||||
je.description,
|
||||
je.fiscal_year,
|
||||
je.version,
|
||||
COALESCE(SUM(jl.debit), 0) as debit_total,
|
||||
COALESCE(SUM(jl.credit), 0) as credit_total
|
||||
FROM journal_entries je
|
||||
LEFT JOIN journal_lines jl ON je.journal_entry_id = jl.journal_entry_id
|
||||
WHERE je.is_deleted = false
|
||||
AND je.description NOT LIKE %s
|
||||
AND je.journal_entry_id NOT IN (
|
||||
SELECT parent_entry_id
|
||||
FROM journal_entries
|
||||
WHERE parent_entry_id IS NOT NULL
|
||||
)
|
||||
"""
|
||||
params = ['%[逆仕訳]%']
|
||||
|
||||
if from_date:
|
||||
sql += " AND je.entry_date >= %s"
|
||||
@@ -83,8 +108,8 @@ def get_journal_entries(
|
||||
params.append(account_id)
|
||||
|
||||
sql += """
|
||||
GROUP BY je.journal_entry_id, je.entry_date, je.description, je.fiscal_year
|
||||
ORDER BY je.entry_date DESC, je.journal_entry_id DESC
|
||||
GROUP BY je.journal_entry_id, je.entry_date, je.description, je.fiscal_year, je.version
|
||||
ORDER BY je.entry_date DESC, je.journal_entry_id DESC, je.version DESC
|
||||
"""
|
||||
|
||||
cur.execute(sql, params)
|
||||
|
||||
25
backend/sql/update_parent_entry_id.sql
Normal file
25
backend/sql/update_parent_entry_id.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- 修正後の仕訳に対して、元の仕訳IDをparent_entry_idに設定
|
||||
|
||||
-- ステップ1: 【修正後】の仕訳を確認
|
||||
SELECT
|
||||
je_modified.journal_entry_id as modified_id,
|
||||
je_modified.description as modified_desc,
|
||||
je_original.journal_entry_id as original_id,
|
||||
je_original.description as original_desc
|
||||
FROM journal_entries je_modified
|
||||
LEFT JOIN journal_entries je_original
|
||||
ON REPLACE(je_modified.description, '【修正後】', '') = je_original.description
|
||||
AND je_modified.description LIKE '【修正後】%'
|
||||
AND je_original.description NOT LIKE '【修正後】%'
|
||||
AND je_original.description NOT LIKE '[逆仕訳]%'
|
||||
WHERE je_modified.description LIKE '【修正後】%'
|
||||
ORDER BY je_modified.journal_entry_id;
|
||||
|
||||
-- ステップ2: 確認後、以下のUPDATE文を実行
|
||||
UPDATE journal_entries
|
||||
SET parent_entry_id = je_original.journal_entry_id
|
||||
FROM journal_entries je_original
|
||||
WHERE REPLACE(journal_entries.description, '【修正後】', '') = je_original.description
|
||||
AND journal_entries.description LIKE '【修正後】%'
|
||||
AND je_original.description NOT LIKE '【修正後】%'
|
||||
AND je_original.description NOT LIKE '[逆仕訳]%';
|
||||
@@ -184,6 +184,11 @@
|
||||
<option value="">-- すべて --</option>
|
||||
</select>
|
||||
|
||||
<label style="margin-left: 16px">
|
||||
<input type="checkbox" id="searchIncludeHistory" />
|
||||
全検索(修正履歴を含む)
|
||||
</label>
|
||||
|
||||
<button onclick="searchJournals()" style="margin-left: 8px">検索</button>
|
||||
</div>
|
||||
|
||||
@@ -870,6 +875,9 @@
|
||||
const to = document.getElementById("searchToDate").value;
|
||||
const key = document.getElementById("searchKeyword").value;
|
||||
const accountId = document.getElementById("searchAccountId").value;
|
||||
const includeHistory = document.getElementById(
|
||||
"searchIncludeHistory"
|
||||
).checked;
|
||||
|
||||
// 検索条件を保存
|
||||
localStorage.setItem(
|
||||
@@ -879,6 +887,7 @@
|
||||
toDate: to,
|
||||
keyword: key,
|
||||
accountId: accountId,
|
||||
includeHistory: includeHistory,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -887,6 +896,7 @@
|
||||
if (to) qs.append("to_date", to);
|
||||
if (key) qs.append("keyword", key);
|
||||
if (accountId) qs.append("account_id", accountId);
|
||||
if (includeHistory) qs.append("include_history", "true");
|
||||
|
||||
const res = await fetch(`${API}/journal-entries?${qs.toString()}`);
|
||||
const data = await res.json();
|
||||
@@ -896,9 +906,12 @@
|
||||
|
||||
data.forEach((e) => {
|
||||
const tr = document.createElement("tr");
|
||||
// 修正履歴がある場合はバージョン番号を表示
|
||||
const versionInfo =
|
||||
includeHistory && e.version > 1 ? ` (v${e.version})` : "";
|
||||
tr.innerHTML = `
|
||||
<td>${e.entry_date}</td>
|
||||
<td>${e.description}</td>
|
||||
<td>${e.description}${versionInfo}</td>
|
||||
<td style="text-align:right">${e.debit_total.toLocaleString()}</td>
|
||||
<td style="text-align:right">${e.credit_total.toLocaleString()}</td>
|
||||
<td>
|
||||
@@ -1109,6 +1122,9 @@
|
||||
if (conditions.accountId)
|
||||
document.getElementById("searchAccountId").value =
|
||||
conditions.accountId;
|
||||
if (conditions.includeHistory)
|
||||
document.getElementById("searchIncludeHistory").checked =
|
||||
conditions.includeHistory;
|
||||
}
|
||||
|
||||
// ページロード時に自動的に検索を実行して最新データを表示
|
||||
|
||||
Reference in New Issue
Block a user