修正
This commit is contained in:
@@ -1,108 +1,199 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ja">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<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>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<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>
|
||||
|
||||
<h2>仕訳一覧</h2>
|
||||
<label>期間</label>
|
||||
<input type="date" id="fromDate" min="1900-01-01" max="2999-12-31" /> ~
|
||||
<input type="date" id="toDate" min="1900-01-01" max="2999-12-31" />
|
||||
|
||||
<label>期間</label>
|
||||
<input type="date" id="fromDate"> ~ <input type="date" id="toDate">
|
||||
<label>摘要</label>
|
||||
<input type="text" id="keyword" />
|
||||
|
||||
<label>摘要</label>
|
||||
<input type="text" id="keyword">
|
||||
<button onclick="search()">検索</button>
|
||||
|
||||
<button onclick="search()">検索</button>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>日付</th>
|
||||
<th>摘要</th>
|
||||
<th>借方合計</th>
|
||||
<th>貸方合計</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="list"></tbody>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>日付</th>
|
||||
<th>摘要</th>
|
||||
<th>借方合計</th>
|
||||
<th>貸方合計</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="list"></tbody>
|
||||
</table>
|
||||
<script>
|
||||
const API = "http://127.0.0.1:18080";
|
||||
|
||||
<script>
|
||||
const API = "http://127.0.0.1:18080";
|
||||
async function search() {
|
||||
const from = document.getElementById("fromDate").value;
|
||||
const to = document.getElementById("toDate").value;
|
||||
const key = document.getElementById("keyword").value;
|
||||
|
||||
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 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 res = await fetch(`${API}/journal-entries?${qs.toString()}`);
|
||||
const data = await res.json();
|
||||
|
||||
const tbody = document.getElementById("list");
|
||||
tbody.innerHTML = "";
|
||||
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>
|
||||
</td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
}
|
||||
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");
|
||||
}
|
||||
function view(id) {
|
||||
window.open(`journal-view.html?id=${id}`, "_blank");
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// 修正仕訳:逆仕訳を作って修正画面へ遷移
|
||||
// --------------------------------------------------
|
||||
async function reverseAndEdit(id) {
|
||||
if (!confirm("この仕訳の逆仕訳を作成し、修正仕訳入力画面を開きます。よろしいですか?")) return;
|
||||
// --------------------------------------------------
|
||||
// 修正仕訳:逆仕訳を作って修正画面へ遷移
|
||||
// --------------------------------------------------
|
||||
async function reverseAndEdit(id) {
|
||||
if (
|
||||
!confirm(
|
||||
"この仕訳の逆仕訳を作成し、修正仕訳入力画面を開きます。よろしいですか?"
|
||||
)
|
||||
)
|
||||
return;
|
||||
|
||||
// ① 逆仕訳を作成
|
||||
const res = await fetch(`${API}/journal-entries/${id}/reverse`, {
|
||||
method: "POST"
|
||||
});
|
||||
try {
|
||||
// ① 逆仕訳を作成
|
||||
const res = await fetch(`${API}/journal-entries/${id}/reverse`, {
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
alert(data.detail || "逆仕訳の作成に失敗しました");
|
||||
return;
|
||||
}
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
alert(
|
||||
data.detail || `逆仕訳の作成に失敗しました (HTTP ${res.status})`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
alert(`逆仕訳を作成しました(ID: ${data.reversed_journal_entry_id})`);
|
||||
const data = await res.json();
|
||||
alert(
|
||||
`逆仕訳を作成しました(ID: ${data.reversed_journal_entry_id})`
|
||||
);
|
||||
|
||||
// ② 元仕訳内容を取得して修正画面へ遷移
|
||||
const src = await fetch(`${API}/journal-entries/${id}`);
|
||||
const srcData = await src.json();
|
||||
// ② 元仕訳内容を取得して修正画面へ遷移
|
||||
const srcRes = await fetch(`${API}/journal-entries/${id}`);
|
||||
if (!srcRes.ok) {
|
||||
alert("元仕訳の取得に失敗しました");
|
||||
return;
|
||||
}
|
||||
|
||||
localStorage.setItem("editSource", JSON.stringify(srcData));
|
||||
const srcData = await srcRes.json();
|
||||
localStorage.setItem("editSource", JSON.stringify(srcData));
|
||||
|
||||
window.open("journal-edit.html", "_blank");
|
||||
}
|
||||
// 修正画面を開く
|
||||
window.open("journal-edit.html", "_blank");
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
alert(`エラーが発生しました: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
// --------------------------------------------------
|
||||
// 仕訳削除
|
||||
// --------------------------------------------------
|
||||
async function deleteEntry(id) {
|
||||
const reason = prompt("削除理由を入力してください:");
|
||||
if (!reason || reason.trim() === "") {
|
||||
alert("削除理由の入力が必要です");
|
||||
return;
|
||||
}
|
||||
|
||||
</body>
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user