修正
This commit is contained in:
@@ -1,40 +1,32 @@
|
||||
async function loadTrialBalance() {
|
||||
const from = document.getElementById("from").value;
|
||||
const to = document.getElementById("to").value;
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
console.log("trial-balance.js 已执行");
|
||||
const API_URL = "http://127.0.0.1:18080/trial-balance";
|
||||
|
||||
if (!from || !to) {
|
||||
alert("期間を指定してください");
|
||||
return;
|
||||
}
|
||||
fetch(API_URL)
|
||||
.then(r => { if (!r.ok) throw new Error("API 返回错误: " + r.status); return r.json(); })
|
||||
.then(data => {
|
||||
|
||||
try {
|
||||
const data = await apiGet("/trial-balance", {
|
||||
date_from: from,
|
||||
date_to: to,
|
||||
});
|
||||
console.log("试算表 API 数据:", data);
|
||||
const tbody = document.querySelector("#trialBalanceTable tbody");
|
||||
if (!tbody) { console.error("未找到 #trialBalanceTable tbody"); return; }
|
||||
|
||||
const tbody = document.querySelector("#trial-table tbody");
|
||||
tbody.innerHTML = "";
|
||||
let totalDebit = 0, totalCredit = 0;
|
||||
data.accounts.forEach(row => {
|
||||
const debit = Number(row.debit ?? 0);
|
||||
const credit = Number(row.credit ?? 0);
|
||||
totalDebit += debit; totalCredit += credit;
|
||||
|
||||
data.accounts.forEach((acc) => {
|
||||
const tr = document.createElement("tr");
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `
|
||||
<td class="left">${row.account_code}</td>
|
||||
<td class="left">${row.account_name}</td>
|
||||
<td>${debit.toLocaleString()}</td>
|
||||
<td>${credit.toLocaleString()}</td>`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
|
||||
tr.innerHTML = `
|
||||
<td>${acc.account_code}</td>
|
||||
<td>
|
||||
<a href="ledger.html?account_id=${acc.account_id}&from=${from}&to=${to}">
|
||||
${acc.account_name}
|
||||
</a>
|
||||
</td>
|
||||
<td>${acc.opening_balance}</td>
|
||||
<td>${acc.debit}</td>
|
||||
<td>${acc.credit}</td>
|
||||
<td>${acc.closing_balance}</td>
|
||||
`;
|
||||
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
} catch (e) {
|
||||
alert(e.message);
|
||||
}
|
||||
}
|
||||
document.getElementById("totalDebit").textContent = totalDebit.toLocaleString();
|
||||
document.getElementById("totalCredit").textContent = totalCredit.toLocaleString();
|
||||
})
|
||||
.catch(err => { console.error("試算表读取失败:", err); alert("試算表读取失败,请查看控制台日志"); });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user