This commit is contained in:
admin
2026-05-14 22:02:06 +09:00
parent 78022b3b15
commit b9f994b1e1
22 changed files with 1225 additions and 126 deletions

View File

@@ -861,6 +861,7 @@
<div class="search-buttons">
<button onclick="searchJournals()">🔍 検索</button>
<button onclick="printSearchResults()">🖨️ 印刷</button>
<button onclick="clearSearchConditions()" style="background: #6c757d; color: white; border: none; padding: 6px 14px; border-radius: 4px; cursor: pointer;">🔄 条件クリア</button>
</div>
</div>
@@ -2394,6 +2395,8 @@
});
const printArea = document.getElementById("printArea");
// 印刷後に元の検索結果を復元できるよう保存
const savedSearchHtml = printArea.innerHTML;
printArea.innerHTML = "";
// 月ごとにデータをグループ化
@@ -2525,6 +2528,13 @@
printArea.appendChild(section);
});
// 印刷後に元の検索結果を復元する
const restoreAfterPrint = () => {
printArea.innerHTML = savedSearchHtml;
window.removeEventListener("afterprint", restoreAfterPrint);
};
window.addEventListener("afterprint", restoreAfterPrint);
// 少し待ってから印刷(データの表示を待つ)
setTimeout(() => {
window.print();
@@ -2552,6 +2562,25 @@
searchJournals();
}
// 検索条件クリア(期間以外)
function clearSearchConditions() {
// 科目
const accountInput = document.getElementById("searchAccountInput");
if (accountInput) {
accountInput.value = "";
accountInput.dataset.accountId = "";
}
// 摘要
const keyword = document.getElementById("searchKeyword");
if (keyword) keyword.value = "";
// 方向
const side = document.getElementById("searchAccountSide");
if (side) side.value = "";
// 修正履歴を含む
const includeHistory = document.getElementById("searchIncludeHistory");
if (includeHistory) includeHistory.checked = false;
}
// 检索结果を表に表示
async function searchJournals() {
try {
@@ -2784,14 +2813,70 @@
const data = await res.json();
// 日付をコピー
document.getElementById("entryDate").value = data.entry_date;
// 行数で振り分け: 3行以上 → 複数行詳細フォーム、2行以下 → 簡易フォーム
if (data.lines && data.lines.length > 2) {
copyJournalToDetailForm(data);
} else {
copyJournalToSimpleForm(data);
}
} catch (error) {
console.error("Error:", error);
showAlert(`エラーが発生しました: ${error.message}`, "error");
}
}
// 摘要をコピー
document.getElementById("description").value = data.description || "";
// 複数行フォームへのコピー
function copyJournalToDetailForm(data) {
document.getElementById("detailEntryDate").value = data.entry_date;
document.getElementById("detailDescription").value = data.description || "";
// 新UIでは簡易的にフォームに反映最初の借方行の科目 + 最初の貸方行を取引手段に設定)
if (data.lines && data.lines.length > 0) {
// 既存行をクリア
document.getElementById("detailLinesTbody").innerHTML = "";
detailRowSeq = 0;
// 各明細行をコピー
data.lines.forEach((line) => {
const tr = detailAddLine();
const accountInput = tr.querySelector(".detail-account-input");
const acc = accounts.find((a) => a.account_id === line.account_id);
if (acc) {
accountInput.value = `${acc.account_code} ${acc.account_name}`;
accountInput.dataset.accountId = acc.account_id;
}
if (Number(line.debit) > 0) {
tr.querySelector(".detail-debit").value = Number(line.debit).toLocaleString();
}
if (Number(line.credit) > 0) {
tr.querySelector(".detail-credit").value = Number(line.credit).toLocaleString();
}
if (line.line_description) {
tr.querySelector(".detail-line-memo").value = line.line_description;
}
});
detailUpdateTotals();
// 詳細セクションを開いてスクロール
const detailSection = document.getElementById("detailSection");
detailSection.open = true;
detailSection.scrollIntoView({ behavior: "smooth", block: "start" });
showAlert(
`仕訳を複製しました(複数行モード)。\n\n※ このコピーは新規仕訳として独立した記録になります。\n※ 日付と摘要を必要に応じて修正してから登録してください。`,
"success",
);
}
// 簡易フォームへのコピー(従来ロジック)
function copyJournalToSimpleForm(data) {
// 日付をコピー
document.getElementById("entryDate").value = data.entry_date;
// 摘要をコピー
document.getElementById("description").value = data.description || "";
// 新UIでは簡易的にフォームに反映最初の借方行の科目 + 最初の貸方行を取引手段に設定)
if (data.lines && data.lines.length > 0) {
// 借方と貸方を分類
const debitLines = data.lines.filter((l) => Number(l.debit) > 0);
const creditLines = data.lines.filter((l) => Number(l.credit) > 0);
@@ -2961,10 +3046,6 @@
`仕訳を複製しました。\n\n※ このコピーは新規仕訳として独立した記録になります。\n※ 日付と摘要を必要に応じて修正してから登録してください。`,
"success",
);
} catch (error) {
console.error("Error:", error);
showAlert(`エラーが発生しました: ${error.message}`, "error");
}
}
// --------------------------------------------------