document.getElementById("load").onclick = async () => {
  const from = document.getElementById("from").value;
  const to = document.getElementById("to").value;

  if (!from || !to) {
    alert("期間を指定してください");
    return;
  }

  try {
    const data = await apiGet(`/trial-balance?date_from=${from}&date_to=${to}`);
    const tbody = document.getElementById("tb-body");
    tbody.innerHTML = "";

    data.accounts.forEach((a) => {
      const tr = document.createElement("tr");
      tr.innerHTML = `
        <td>${a.account_name}</td>
        <td style="text-align:right">${a.opening_balance}</td>
        <td style="text-align:right">${a.debit}</td>
        <td style="text-align:right">${a.credit}</td>
        <td style="text-align:right">${a.closing_balance}</td>
      `;
      tbody.appendChild(tr);
    });
  } catch (e) {
    alert(e.message);
  }
};
