109 lines
2.8 KiB
HTML
109 lines
2.8 KiB
HTML
<!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>
|
||
|
||
<h2>仕訳一覧</h2>
|
||
|
||
<label>期間</label>
|
||
<input type="date" id="fromDate"> ~ <input type="date" id="toDate">
|
||
|
||
<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 = "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;
|
||
|
||
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>
|
||
</td>
|
||
`;
|
||
tbody.appendChild(tr);
|
||
});
|
||
}
|
||
|
||
function view(id) {
|
||
window.open(`journal-view.html?id=${id}`, "_blank");
|
||
}
|
||
|
||
// --------------------------------------------------
|
||
// 修正仕訳:逆仕訳を作って修正画面へ遷移
|
||
// --------------------------------------------------
|
||
async function reverseAndEdit(id) {
|
||
if (!confirm("この仕訳の逆仕訳を作成し、修正仕訳入力画面を開きます。よろしいですか?")) return;
|
||
|
||
// ① 逆仕訳を作成
|
||
const res = await fetch(`${API}/journal-entries/${id}/reverse`, {
|
||
method: "POST"
|
||
});
|
||
|
||
const data = await res.json();
|
||
if (!res.ok) {
|
||
alert(data.detail || "逆仕訳の作成に失敗しました");
|
||
return;
|
||
}
|
||
|
||
alert(`逆仕訳を作成しました(ID: ${data.reversed_journal_entry_id})`);
|
||
|
||
// ② 元仕訳内容を取得して修正画面へ遷移
|
||
const src = await fetch(`${API}/journal-entries/${id}`);
|
||
const srcData = await src.json();
|
||
|
||
localStorage.setItem("editSource", JSON.stringify(srcData));
|
||
|
||
window.open("journal-edit.html", "_blank");
|
||
}
|
||
|
||
</script>
|
||
|
||
</body>
|
||
</html>
|