This commit is contained in:
admin
2026-01-12 20:59:52 +09:00
parent 76d8e7622e
commit 59e8e8625d
7 changed files with 840 additions and 314 deletions

View File

@@ -75,8 +75,8 @@
<div style="margin-bottom: 10px">
<label>消費税 端数処理:</label>
<select id="roundingMode">
<option value="round">四捨五入</option>
<option value="floor">切捨て</option>
<option value="round">四捨五入</option>
<option value="ceil">切上げ</option>
</select>
</div>
@@ -104,7 +104,14 @@
<div style="margin-bottom: 8px">
<label>年度:</label>
<input type="number" id="lockYear" value="2025" style="width: 80px" />
<input
type="number"
id="lockYear"
value="2025"
min="1900"
max="2999"
style="width: 80px"
/>
<label>月份:</label>
<input
@@ -353,8 +360,8 @@
const rate = taxType === "8" ? 0.08 : 0.1;
const roundingMode = document.getElementById("roundingMode").value;
// 税込 → 税額逆算
const rawTax = (totalAmount * rate) / (1 + rate);
// 税抜額 × 税率 = 税額
const rawTax = totalAmount * rate;
let taxAmount;
switch (roundingMode) {
case "floor":
@@ -406,7 +413,7 @@
}
// -----------------------------
// 登録(最小可用版)
// 登録(税行自動生成版)
// -----------------------------
async function submitJournal() {
const entryDate = document.getElementById("entryDate").value;
@@ -417,45 +424,55 @@
return;
}
// 明細収集
// 明細収集(税情報も含む)
const rows = document.querySelectorAll("#linesTable tbody tr");
const lines = [];
let totalDebit = 0,
totalCredit = 0;
rows.forEach((row) => {
if (row.classList.contains("tax-row")) return;
if (row.classList.contains("tax-row")) return; // 税行は無視
const accountId = Number(row.querySelector(".account").value);
const debit = Number(row.querySelector(".debit").value || 0);
const credit = Number(row.querySelector(".credit").value || 0);
const taxType = row.querySelector(".taxType").value;
const taxDirection = row.querySelector(".taxDirection").value;
if (debit > 0 && credit > 0) {
alert("同一行不能同时填写借方和贷方");
throw new Error("invalid line");
}
if (debit === 0 && credit === 0) return;
lines.push({ account_id: accountId, debit: debit, credit: credit });
totalDebit += debit;
totalCredit += credit;
const lineData = {
account_id: accountId,
debit: debit,
credit: credit,
};
// 税情報を追加
if (taxType !== "none" && taxDirection !== "none") {
lineData.tax_rate = parseInt(taxType);
lineData.tax_direction = taxDirection;
}
lines.push(lineData);
});
if (lines.length === 0) {
alert("仕訳明細がありません");
return;
}
if (lines.length < 2) {
alert("至少需要借方和贷方各一行");
return;
}
// 借貸一致チェック(最小)
if (totalDebit !== totalCredit) {
alert(
`借方(${totalDebit.toLocaleString()})と貸方(${totalCredit.toLocaleString()})が一致しません`
);
return;
}
const payload = { entry_date: entryDate, description, lines };
const payload = {
entry_date: entryDate,
description,
lines,
tax_paid_account_id:
Number(document.getElementById("taxPaidSelect").value) || null,
tax_received_account_id:
Number(document.getElementById("taxReceivedSelect").value) || null,
rounding_mode: document.getElementById("roundingMode").value,
};
const res = await fetch(`${API}/journal-entries`, {
method: "POST",
@@ -464,7 +481,11 @@
});
if (!res.ok) {
alert("登録に失敗しました");
const errorData = await res.json().catch(() => ({}));
const errorMsg =
errorData.detail || `登録に失敗しました (HTTP ${res.status})`;
console.error("Error:", errorData);
alert(errorMsg);
return;
}