async function loadLedger() {
  const params = new URLSearchParams(location.search);
  const accountId = params.get("account_id");
  const from = params.get("from");
  const to = params.get("to");

  try {
    const data = await apiGet("/general-ledger", {
      account_id: accountId,
      date_from: from,
      date_to: to,
    });

    document.getElementById(
      "account-title"
    ).innerText = `${data.account.account_code} ${data.account.account_name}`;

    const tbody = document.getElementById("ledger-body");
    tbody.innerHTML = "";

    data.lines.forEach((line) => {
      const tr = document.createElement("tr");
      tr.innerHTML = `
        <td>${line.journal_date}</td>
        <td>${line.description}</td>
        <td>${line.debit}</td>
        <td>${line.credit}</td>
        <td>${line.balance}</td>
      `;
      tbody.appendChild(tr);
    });
  } catch (e) {
    alert(e.message);
  }
}

loadLedger();
