Files
njts-accounting-core/frontend/journal-list.html
2026-02-07 20:04:42 +09:00

203 lines
6.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<script src="js/auth.js"></script>
<title>仕訳一覧</title>
<style>
body {
font-family: sans-serif;
margin: 24px;
}
table {
border-collapse: collapse;
width: 100%;
margin-top: 12px;
}
th,
td {
border: 1px solid #ccc;
padding: 6px;
}
th {
background: #f5f5f5;
}
</style>
</head>
<body>
<h2>仕訳一覧</h2>
<label>期間</label>
<input type="date" id="fromDate" min="1900-01-01" max="2099-12-31" />
<input type="date" id="toDate" min="1900-01-01" max="2099-12-31" />
<label>摘要</label>
<input type="text" id="keyword" />
<button onclick="search()">検索</button>
<table>
<thead>
<tr>
<th>日付</th>
<th>摘要</th>
<th>借方合計</th>
<th>貸方合計</th>
<th>操作</th>
</tr>
</thead>
<tbody id="list"></tbody>
</table>
<script>
const API = "";
async function search() {
const from = document.getElementById("fromDate").value;
const to = document.getElementById("toDate").value;
const key = document.getElementById("keyword").value;
// 検索条件を保存
localStorage.setItem(
"journalSearchConditions",
JSON.stringify({
fromDate: from,
toDate: to,
keyword: key,
}),
);
const qs = new URLSearchParams();
if (from) qs.append("from_date", from);
if (to) qs.append("to_date", to);
if (key) qs.append("keyword", key);
const res = await fetch(`${API}/journal-entries?${qs.toString()}`);
const data = await res.json();
const tbody = document.getElementById("list");
tbody.innerHTML = "";
data.forEach((e) => {
const tr = document.createElement("tr");
tr.innerHTML = `
<td>${e.entry_date}</td>
<td>${e.description}</td>
<td style="text-align:right">${e.debit_total.toLocaleString()}</td>
<td style="text-align:right">${e.credit_total.toLocaleString()}</td>
<td>
<button onclick="view(${e.journal_entry_id})">表示</button>
<button onclick="reverseAndEdit(${e.journal_entry_id})">修正</button>
<button onclick="deleteEntry(${
e.journal_entry_id
})" style="color: red;">削除</button>
</td>
`;
tbody.appendChild(tr);
});
}
function view(id) {
window.open(`journal-view.html?id=${id}`, "_blank");
}
// --------------------------------------------------
// 修正仕訳:逆仕訳を作って修正画面へ遷移
// --------------------------------------------------
async function reverseAndEdit(id) {
if (
!confirm(
"この仕訳の逆仕訳を作成し、修正仕訳入力画面を開きます。よろしいですか?",
)
)
return;
try {
// ① 逆仕訳を作成
const res = await fetch(`${API}/journal-entries/${id}/reverse`, {
method: "POST",
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
alert(
data.detail || `逆仕訳の作成に失敗しました (HTTP ${res.status})`,
);
return;
}
const data = await res.json();
alert(
`逆仕訳を作成しましたID: ${data.reversed_journal_entry_id}`,
);
// ② 元仕訳内容を取得して修正画面へ遷移
const srcRes = await fetch(`${API}/journal-entries/${id}`);
if (!srcRes.ok) {
alert("元仕訳の取得に失敗しました");
return;
}
const srcData = await srcRes.json();
// 逆仕訳IDを追加して保存【修正後】仕訳のparent_entry_idとして使用
srcData.reversed_journal_entry_id = data.reversed_journal_entry_id;
localStorage.setItem("editSource", JSON.stringify(srcData));
// 修正画面を開く
window.open("journal-edit.html", "_blank");
} catch (error) {
console.error("Error:", error);
alert(`エラーが発生しました: ${error.message}`);
}
}
// --------------------------------------------------
// 仕訳削除
// --------------------------------------------------
async function deleteEntry(id) {
const reason = prompt("削除理由を入力してください:");
if (!reason || reason.trim() === "") {
alert("削除理由の入力が必要です");
return;
}
if (!confirm("この仕訳を削除してもよろしいですか?")) {
return;
}
const res = await fetch(`${API}/journal-entries/${id}`, {
method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ deleted_reason: reason }),
});
const data = await res.json();
if (!res.ok) {
alert(data.detail || "削除に失敗しました");
return;
}
alert("削除しました");
search(); // リストを再読み込み
}
// ページロード時に前回の検索条件を復元
window.addEventListener("DOMContentLoaded", () => {
const savedConditions = localStorage.getItem("journalSearchConditions");
if (savedConditions) {
const conditions = JSON.parse(savedConditions);
if (conditions.fromDate)
document.getElementById("fromDate").value = conditions.fromDate;
if (conditions.toDate)
document.getElementById("toDate").value = conditions.toDate;
if (conditions.keyword)
document.getElementById("keyword").value = conditions.keyword;
// 自動的に検索を実行
search();
}
});
</script>
</body>
</html>