Invoices: business details and logo, saved customers, numbering, GST per line, PDF download (fpdf2), and marking paid, which records the income in the book (split into Incl and Excl GST rows when an invoice has both) or uses an already-imported bank deposit. Statement import treats a split payment as the one bank line it came from. Mileage: vehicles and trips with odometer readings, business or private use, IRD kilometre rates entered per income year, a per-vehicle tier 1/2 claim and a CSV logbook export. Report only: nothing is added to the cashbook or IR10. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
349 lines
21 KiB
JavaScript
349 lines
21 KiB
JavaScript
// ---- invoices: business details, customers, invoices and their payment ----
|
|
// Uses $, state, call, esc, fmt, fmtDate, plural, toast, guard and render from index.html.
|
|
const todayIso = () => { const d = new Date(); return new Date(d - d.getTimezoneOffset() * 6e4).toISOString().slice(0, 10); };
|
|
const addDays = (iso, n) => { const d = new Date(iso + "T00:00:00Z"); d.setUTCDate(d.getUTCDate() + n); return d.toISOString().slice(0, 10); };
|
|
|
|
document.body.insertAdjacentHTML("beforeend", `
|
|
<dialog id="invDialog" class="wide">
|
|
<form method="dialog" id="invForm">
|
|
<h2 style="margin:0 0 4px;font-size:16px" id="invTitle">New invoice</h2>
|
|
<div class="receipt-fields" style="margin-top:10px">
|
|
<label class="wide">Customer<select id="invCustomer" required></select></label>
|
|
<label>Invoice date<input id="invIssue" type="date" required></label>
|
|
<label>Due date<input id="invDue" type="date" required></label>
|
|
</div>
|
|
<div class="scroll" style="margin-top:12px"><table class="inv-lines">
|
|
<thead><tr><th>Description</th><th class="num">Qty</th><th class="num">Unit price (excl GST)</th><th title="GST applies to this line">GST</th><th class="num">Amount</th><th></th></tr></thead>
|
|
<tbody id="invLines"></tbody>
|
|
</table></div>
|
|
<button type="button" id="invAddLine" style="margin-top:6px">Add line</button>
|
|
<div class="inv-totals" id="invTotals"></div>
|
|
<label for="invNotes">Notes on the invoice</label>
|
|
<input id="invNotes" type="text" maxlength="2000" placeholder="e.g. Thanks for your business">
|
|
<div class="actions" style="justify-content:flex-end">
|
|
<button value="cancel" formnovalidate>Cancel</button>
|
|
<button value="ok" class="primary" id="invSave">Save draft</button>
|
|
</div>
|
|
</form>
|
|
</dialog>
|
|
<dialog id="payDialog">
|
|
<form method="dialog">
|
|
<h2 style="margin:0 0 4px;font-size:16px">Record payment</h2>
|
|
<div class="muted small" id="paySub"></div>
|
|
<label for="payDate">Date paid</label>
|
|
<input id="payDate" type="date" required>
|
|
<div id="payOptions" style="margin-top:8px"></div>
|
|
<div class="actions" style="justify-content:flex-end">
|
|
<button value="cancel" formnovalidate>Cancel</button>
|
|
<button value="ok" class="primary">Mark paid</button>
|
|
</div>
|
|
</form>
|
|
</dialog>
|
|
<dialog id="bizDialog" class="wide">
|
|
<form method="dialog" id="bizForm">
|
|
<h2 style="margin:0 0 4px;font-size:16px">Business details</h2>
|
|
<div class="muted small">Shown on every invoice. With a GST number, invoices with GST are titled “Tax invoice”.</div>
|
|
<div class="receipt-fields" style="margin-top:10px">
|
|
<label class="wide">Business name<input data-biz="name" type="text" maxlength="200"></label>
|
|
<label>GST number<input data-biz="gst_number" type="text" maxlength="20" placeholder="123-456-789"></label>
|
|
<label>Phone<input data-biz="phone" type="text" maxlength="50"></label>
|
|
<label class="wide">Address<textarea data-biz="address" rows="2" maxlength="500"></textarea></label>
|
|
<label class="wide">Email<input data-biz="email" type="text" maxlength="200"></label>
|
|
<label class="wide">Bank account for payments<input data-biz="bank_account" type="text" maxlength="50" placeholder="01-0000-0000000-00"></label>
|
|
<label>Number prefix<input data-biz="invoice_prefix" type="text" maxlength="20"></label>
|
|
<label>Next number<input data-biz="next_number" type="number" min="1"></label>
|
|
<label>Payment terms (days)<input data-biz="payment_terms_days" type="number" min="0" max="365"></label>
|
|
<label class="wide">Footer<input data-biz="footer" type="text" maxlength="1000" placeholder="e.g. Company number, terms"></label>
|
|
</div>
|
|
<label>Logo (PNG or JPEG)</label>
|
|
<div style="display:flex;gap:10px;align-items:center;flex-wrap:wrap">
|
|
<img id="bizLogo" alt="Logo" style="max-height:48px;max-width:160px" hidden>
|
|
<button type="button" id="bizLogoAdd">Choose image…</button>
|
|
<button type="button" id="bizLogoRemove" hidden>Remove</button>
|
|
<input id="bizLogoInput" type="file" accept="image/png,image/jpeg" hidden>
|
|
</div>
|
|
<div class="actions" style="justify-content:flex-end">
|
|
<button value="cancel" formnovalidate>Cancel</button>
|
|
<button value="ok" class="primary">Save</button>
|
|
</div>
|
|
</form>
|
|
</dialog>`);
|
|
|
|
document.head.insertAdjacentHTML("beforeend", `<style>
|
|
.inv-lines td { padding: 3px 4px; }
|
|
.inv-lines input[type=text] { width: 100%; min-width: 200px; }
|
|
.inv-lines input[type=number] { width: 90px; text-align: right; }
|
|
.inv-totals { display: grid; grid-template-columns: auto auto; justify-content: end; gap: 2px 18px; margin: 10px 4px; font-variant-numeric: tabular-nums; }
|
|
.inv-totals div:nth-child(even) { text-align: right; }
|
|
.inv-totals .grand { font-weight: 700; font-size: 16px; }
|
|
.chip.draft { background: var(--line); color: var(--muted); }
|
|
.chip.sent { background: var(--accent-soft); color: var(--accent); }
|
|
.chip.paid { background: var(--ok-soft); color: var(--in); }
|
|
.chip.void { background: var(--line); color: var(--muted); text-decoration: line-through; }
|
|
.chip.overdue { background: var(--bad-soft); color: var(--out); }
|
|
.contacts td input, .contacts td textarea { width: 100%; min-width: 120px; }
|
|
.contacts td { vertical-align: top; }
|
|
dialog textarea { width: 100%; font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
|
|
border-radius: 6px; padding: 5px 8px; resize: vertical; }
|
|
#payOptions label { display: flex; gap: 8px; align-items: baseline; margin: 6px 0; font-size: 14px; color: var(--text); }
|
|
#payOptions input { width: auto; }
|
|
</style>`);
|
|
|
|
async function loadInvoices() {
|
|
[state.invoices, state.business, state.customers] = await Promise.all([
|
|
call("/api/invoices"), call("/api/business"), call("/api/customers")]);
|
|
state.view = "invoices"; render();
|
|
}
|
|
|
|
function renderInvoices() {
|
|
const all = state.invoices || [], b = state.business || {};
|
|
const filter = state.invoiceFilter || "all";
|
|
const unpaid = all.filter(i => i.status === "sent" || i.status === "draft");
|
|
const cust = state.invoiceCustomer || "";
|
|
const list = (filter === "unpaid" ? unpaid : filter === "paid" ? all.filter(i => i.status === "paid") : all)
|
|
.filter(i => !cust || String(i.customer_id) === cust);
|
|
const owed = all.filter(i => i.status === "sent").reduce((n, i) => n + i.total, 0);
|
|
const overdue = all.filter(i => i.overdue).reduce((n, i) => n + i.total, 0);
|
|
const chip = i => i.overdue ? `<span class="chip overdue">overdue</span>` : `<span class="chip ${i.status}">${i.status}</span>`;
|
|
const btn = (act, i, label, cls = "") => `<button data-inv="${act}" data-id="${i.id}" class="${cls}">${label}</button>`;
|
|
const actions = i => [
|
|
`<a href="/api/invoices/${i.id}/pdf" download><button tabindex="-1">PDF</button></a>`,
|
|
i.status === "draft" ? btn("edit", i, "Edit") + btn("sent", i, "Mark sent") : "",
|
|
i.status === "sent" ? btn("draft", i, "Back to draft") : "",
|
|
["draft", "sent"].includes(i.status) ? btn("pay", i, "Paid…", "primary") + btn("void", i, "Void") : "",
|
|
i.status === "paid" ? btn("unpay", i, "Undo payment") : "",
|
|
].join("");
|
|
return `
|
|
<div class="row-toolbar">
|
|
<strong style="font-size:16px">Invoices</strong>
|
|
<div class="tabs" style="margin:0">
|
|
${[["all", `All (${all.length})`], ["unpaid", `Unpaid (${unpaid.length})`], ["paid", "Paid"]].map(([k, l]) =>
|
|
`<button data-inv="filter" data-filter="${k}" class="${filter === k ? "on" : ""}">${l}</button>`).join("")}
|
|
</div>
|
|
<select id="invoiceCustomer" title="Show one customer's invoices"><option value="">All customers</option>
|
|
${(state.customers || []).map(c => `<option value="${c.id}" ${String(c.id) === cust ? "selected" : ""}>${esc(c.name)}</option>`).join("")}</select>
|
|
<span style="flex:1"></span>
|
|
<button data-inv="business">Business details</button>
|
|
<button data-inv="new" class="primary">New invoice</button>
|
|
</div>
|
|
${b.name ? "" : `<p class="small" style="color:var(--warn)">Add your <button class="linkish" data-inv="business">business details</button> (name, GST number, bank account) before sending invoices.</p>`}
|
|
<div class="stats">
|
|
<div class="stat"><div class="k">Owed to you</div><div class="v">${fmt(owed)}</div></div>
|
|
<div class="stat"><div class="k">Overdue</div><div class="v ${overdue ? "out" : ""}">${fmt(overdue)}</div></div>
|
|
</div>
|
|
${list.length ? `<div class="scroll"><table>
|
|
<thead><tr><th>Number</th><th>Date</th><th>Customer</th><th>Due</th><th class="num">GST</th><th class="num">Total</th><th>Status</th><th></th></tr></thead>
|
|
<tbody>${list.map(i => `<tr style="${i.status === "void" ? "opacity:.55" : ""}">
|
|
<td><strong>${esc(i.number)}</strong></td><td>${fmtDate(i.issue_date)}</td><td class="ref">${esc(i.customer_name)}</td>
|
|
<td>${fmtDate(i.due_date)}</td><td class="num muted">${fmt(i.gst)}</td><td class="num">${fmt(i.total)}</td>
|
|
<td>${chip(i)}${i.status === "paid" ? `<div class="muted small">${fmtDate(i.paid_date)}${i.payments.length ? ` · ${esc(i.payments[0].book)}` : ""}</div>` : ""}</td>
|
|
<td><div class="icon-btns" style="max-width:none;flex-wrap:nowrap">${actions(i)}</div></td></tr>`).join("")}</tbody>
|
|
</table></div>` : `<div class="empty-state">${all.length ? "No invoices here." : "No invoices yet."}</div>`}
|
|
<p class="muted small">Marking an invoice paid records the money in the cashbook as Sales, in the book for the payment date. If the bank statement is already imported, pick the matching deposit so it isn't counted twice; statements imported later recognise the payment. An invoice with both GST and non-GST items is recorded as two rows (Incl GST and Excl GST).</p>`;
|
|
}
|
|
|
|
// -- invoice editor --
|
|
function lineRow(l = { description: "", qty: 1, unit: "", taxable: true }) {
|
|
return `<tr>
|
|
<td><input type="text" data-l="description" value="${esc(l.description)}" maxlength="500" required></td>
|
|
<td><input type="number" data-l="qty" value="${l.qty}" step="any" min="0.0001" required></td>
|
|
<td><input type="number" data-l="unit" value="${l.unit}" step="0.01" required></td>
|
|
<td style="text-align:center"><input type="checkbox" data-l="taxable" ${l.taxable ? "checked" : ""} style="width:auto"></td>
|
|
<td class="num" data-amount></td>
|
|
<td><button type="button" data-remove title="Remove line">✕</button></td></tr>`;
|
|
}
|
|
function readLines() {
|
|
return [...$("#invLines").rows].map(r => ({
|
|
description: r.querySelector("[data-l=description]").value, qty: Number(r.querySelector("[data-l=qty]").value),
|
|
unit: Number(r.querySelector("[data-l=unit]").value), taxable: r.querySelector("[data-l=taxable]").checked }));
|
|
}
|
|
function updateInvTotals() {
|
|
const cents = l => Math.round(l.qty * Math.round(l.unit * 100));
|
|
const lines = readLines();
|
|
[...$("#invLines").rows].forEach((r, i) => r.querySelector("[data-amount]").textContent = fmt(cents(lines[i]) / 100));
|
|
const taxable = lines.filter(l => l.taxable).reduce((n, l) => n + cents(l), 0);
|
|
const exempt = lines.filter(l => !l.taxable).reduce((n, l) => n + cents(l), 0);
|
|
const gst = Math.floor((taxable * 6 + 20) / 40); // same rounding as the server
|
|
$("#invTotals").innerHTML = `<div>Subtotal (excl GST)</div><div>${fmt((taxable + exempt) / 100)}</div>
|
|
<div>GST 15%${exempt && taxable ? ` on ${fmt(taxable / 100)}` : ""}</div><div>${fmt(gst / 100)}</div>
|
|
<div class="grand">Total</div><div class="grand">${fmt((taxable + exempt + gst) / 100)}</div>`;
|
|
}
|
|
function customerOptions(selected) {
|
|
return `<option value="">Choose a customer…</option>` +
|
|
(state.customers || []).map(c => `<option value="${c.id}" ${c.id === selected ? "selected" : ""}>${esc(c.name)}</option>`).join("") +
|
|
`<option value="new">+ New customer…</option>`;
|
|
}
|
|
function openInvoice(inv) {
|
|
state.editingInvoice = inv || null;
|
|
$("#invTitle").textContent = inv ? `Edit ${inv.number}` : "New invoice";
|
|
$("#invCustomer").innerHTML = customerOptions(inv?.customer_id);
|
|
$("#invIssue").value = inv?.issue_date || todayIso();
|
|
$("#invDue").value = inv?.due_date || addDays($("#invIssue").value, state.business?.payment_terms_days ?? 14);
|
|
$("#invLines").innerHTML = (inv?.lines || [undefined]).map(lineRow).join("");
|
|
$("#invNotes").value = inv?.notes || "";
|
|
updateInvTotals();
|
|
$("#invDialog").returnValue = ""; $("#invDialog").showModal();
|
|
}
|
|
$("#invLines").addEventListener("input", updateInvTotals);
|
|
$("#invLines").addEventListener("click", e => {
|
|
if (!e.target.closest("[data-remove]")) return;
|
|
if ($("#invLines").rows.length > 1) e.target.closest("tr").remove();
|
|
updateInvTotals();
|
|
});
|
|
$("#invAddLine").addEventListener("click", () => {
|
|
$("#invLines").insertAdjacentHTML("beforeend", lineRow());
|
|
$("#invLines").lastElementChild.querySelector("input").focus();
|
|
updateInvTotals();
|
|
});
|
|
$("#invIssue").addEventListener("change", () => {
|
|
if (!state.editingInvoice) $("#invDue").value = addDays($("#invIssue").value, state.business?.payment_terms_days ?? 14);
|
|
});
|
|
$("#invCustomer").addEventListener("change", guard(async e => {
|
|
if (e.target.value !== "new") return;
|
|
const name = prompt("Customer name");
|
|
if (!name?.trim()) { e.target.value = ""; return; }
|
|
const c = await call("/api/customers", { name });
|
|
state.customers = await call("/api/customers");
|
|
e.target.innerHTML = customerOptions(c.id);
|
|
toast(`Added ${c.name}. Add their address under Customers.`);
|
|
}));
|
|
$("#invSave").addEventListener("click", guard(async e => {
|
|
e.preventDefault();
|
|
if (!$("#invForm").reportValidity()) return;
|
|
const body = { customer_id: Number($("#invCustomer").value), issue_date: $("#invIssue").value,
|
|
due_date: $("#invDue").value, lines: readLines(), notes: $("#invNotes").value };
|
|
const inv = state.editingInvoice
|
|
? await call(`/api/invoices/${state.editingInvoice.id}`, body, "PUT")
|
|
: await call("/api/invoices", body);
|
|
$("#invDialog").close();
|
|
toast(state.editingInvoice ? `Saved ${inv.number}` : `Created ${inv.number}. Download the PDF to send it.`);
|
|
await loadInvoices();
|
|
}));
|
|
|
|
// -- payment --
|
|
async function showPayOptions(inv) {
|
|
const matches = await call(`/api/invoices/${inv.id}/matches?date=${$("#payDate").value}`);
|
|
$("#payOptions").innerHTML = (matches.length ? `<div class="small muted">Imported deposits of ${fmt(inv.total)} near that date:</div>` : "") +
|
|
matches.map((m, i) => `<label><input type="radio" name="payRow" value="${m.row}" ${i === 0 ? "checked" : ""}>
|
|
<span>${fmtDate(m.date)} · ${esc(m.reference)} <span class="muted small">${esc(m.book)} · ${m.days_apart ? plural(m.days_apart, "day") + " apart" : "same day"}</span></span></label>`).join("") +
|
|
`<label><input type="radio" name="payRow" value="" ${matches.length ? "" : "checked"}>
|
|
<span>${matches.length ? "None of these: add" : "Add"} it to the cashbook as a new entry <span class="muted small">(the bank statement isn't imported yet)</span></span></label>`;
|
|
}
|
|
function openPay(inv) {
|
|
state.payingInvoice = inv;
|
|
$("#paySub").textContent = `${inv.number} · ${inv.customer_name} · ${fmt(inv.total)}`;
|
|
$("#payDate").value = todayIso();
|
|
$("#payDialog").returnValue = ""; $("#payDialog").showModal();
|
|
return showPayOptions(inv);
|
|
}
|
|
$("#payDate").addEventListener("change", guard(() => showPayOptions(state.payingInvoice)));
|
|
$("#payDialog").addEventListener("close", guard(async () => {
|
|
if ($("#payDialog").returnValue !== "ok") return;
|
|
const row = document.querySelector("input[name=payRow]:checked")?.value;
|
|
const inv = await call(`/api/invoices/${state.payingInvoice.id}/pay`, { date: $("#payDate").value, row: row ? Number(row) : null });
|
|
toast(`${inv.number} paid: recorded in ${inv.payments[0]?.book || "the cashbook"}`);
|
|
if (state.book) state.summary = await call(`/api/summary?book=${encodeURIComponent(state.book)}`);
|
|
await loadInvoices();
|
|
}));
|
|
|
|
// -- customers --
|
|
async function loadCustomers() {
|
|
[state.customers, state.invoices] = await Promise.all([call("/api/customers"), call("/api/invoices")]);
|
|
state.view = "customers"; render();
|
|
}
|
|
function renderCustomers() {
|
|
const list = state.customers || [];
|
|
const owed = id => (state.invoices || []).filter(i => i.customer_id === id && i.status === "sent").reduce((n, i) => n + i.total, 0);
|
|
return `
|
|
<div class="row-toolbar"><strong style="font-size:16px">Customers</strong></div>
|
|
${list.length ? `<div class="scroll"><table class="contacts"><thead><tr><th>Name</th><th>Email</th><th>Address</th><th class="num">Owing</th><th></th></tr></thead><tbody>
|
|
${list.map(c => `<tr>${["name", "email"].map(k =>
|
|
`<td><input type="text" data-cust="${k}" data-id="${c.id}" value="${esc(c[k])}"></td>`).join("")}
|
|
<td><textarea rows="2" data-cust="address" data-id="${c.id}">${esc(c.address)}</textarea></td>
|
|
<td class="num">${c.invoices ? `<button class="linkish" data-cust-show="${c.id}">${fmt(owed(c.id))}</button><div class="muted small">${plural(c.invoices, "invoice")}</div>` : ""}</td>
|
|
<td>${c.invoices ? "" : `<button data-cust-delete="${c.id}">Delete</button>`}</td></tr>`).join("")}
|
|
</tbody></table></div><div class="muted small">Changes are saved as you leave each box. Invoices already made keep the details they were made with.</div>`
|
|
: `<div class="empty-state" style="padding:20px">No customers yet.</div>`}
|
|
<form id="custAdd" class="receipt-fields" style="margin-top:16px;align-items:end">
|
|
<label>Name<input id="custName" type="text" required maxlength="200"></label>
|
|
<label>Email<input id="custEmail" type="text" maxlength="200"></label>
|
|
<label class="wide">Address<textarea id="custAddress" rows="2" maxlength="500"></textarea></label>
|
|
<button class="primary">Add customer</button>
|
|
</form>`;
|
|
}
|
|
$("#main").addEventListener("change", guard(async e => {
|
|
const k = e.target.dataset.cust; if (!k) return;
|
|
const c = state.customers.find(x => x.id === Number(e.target.dataset.id));
|
|
await call(`/api/customers/${c.id}`, { name: c.name, email: c.email, address: c.address, [k]: e.target.value }, "PUT");
|
|
state.customers = await call("/api/customers");
|
|
toast("Saved");
|
|
}));
|
|
$("#main").addEventListener("click", guard(async e => {
|
|
const del = e.target.dataset.custDelete, show = e.target.dataset.custShow;
|
|
if (show) { state.invoiceCustomer = show; state.invoiceFilter = "all"; await loadInvoices(); return; }
|
|
if (del) { await call(`/api/customers/${del}`, undefined, "DELETE"); await loadCustomers(); }
|
|
}));
|
|
$("#main").addEventListener("submit", guard(async e => {
|
|
if (e.target.id !== "custAdd") return;
|
|
e.preventDefault();
|
|
await call("/api/customers", { name: $("#custName").value, email: $("#custEmail").value, address: $("#custAddress").value });
|
|
await loadCustomers();
|
|
}));
|
|
|
|
// -- business details --
|
|
function showLogo() {
|
|
const has = !!state.business.logo_file;
|
|
$("#bizLogo").hidden = !has; $("#bizLogoRemove").hidden = !has;
|
|
if (has) $("#bizLogo").src = `/api/business/logo?t=${Date.now()}`;
|
|
}
|
|
async function openBusiness() {
|
|
state.business = await call("/api/business");
|
|
for (const input of document.querySelectorAll("[data-biz]")) input.value = state.business[input.dataset.biz] ?? "";
|
|
showLogo();
|
|
$("#bizDialog").returnValue = ""; $("#bizDialog").showModal();
|
|
}
|
|
$("#bizDialog").addEventListener("close", guard(async () => {
|
|
if ($("#bizDialog").returnValue !== "ok") return;
|
|
const body = {};
|
|
for (const input of document.querySelectorAll("[data-biz]")) {
|
|
const k = input.dataset.biz, v = input.type === "number" ? Number(input.value) : input.value;
|
|
if (v !== state.business[k]) body[k] = v;
|
|
}
|
|
state.business = await call("/api/business", body, "PUT");
|
|
toast("Business details saved");
|
|
if (state.view === "invoices") render();
|
|
}));
|
|
$("#bizLogoAdd").addEventListener("click", () => $("#bizLogoInput").click());
|
|
$("#bizLogoInput").addEventListener("change", guard(async e => {
|
|
const f = e.target.files[0]; e.target.value = ""; if (!f) return;
|
|
const res = await fetch("/api/business/logo", { method: "POST", body: f });
|
|
const data = await res.json().catch(() => ({}));
|
|
if (!res.ok) throw new Error(errorText(data, res));
|
|
state.business = data; showLogo();
|
|
}));
|
|
$("#bizLogoRemove").addEventListener("click", guard(async () => {
|
|
state.business = await call("/api/business/logo", undefined, "DELETE"); showLogo();
|
|
}));
|
|
|
|
// buttons with data-inv in the Invoices view
|
|
async function invoiceAction(b) {
|
|
const id = Number(b.dataset.id), inv = (state.invoices || []).find(i => i.id === id);
|
|
switch (b.dataset.inv) {
|
|
case "filter": state.invoiceFilter = b.dataset.filter; return render();
|
|
case "new": return openInvoice();
|
|
case "edit": return openInvoice(inv);
|
|
case "business": return openBusiness();
|
|
case "pay": return openPay(inv);
|
|
case "sent": case "draft": await call(`/api/invoices/${id}/status`, { status: b.dataset.inv }); break;
|
|
case "void":
|
|
if (!confirm(`Void ${inv.number}? It keeps its number but can't be used again.`)) return;
|
|
await call(`/api/invoices/${id}/status`, { status: "void" }); break;
|
|
case "unpay":
|
|
if (!confirm(`Undo the payment of ${inv.number}? The cashbook entries it made are removed (an imported bank line is put back as it was).`)) return;
|
|
await call(`/api/invoices/${id}/unpay`, {});
|
|
if (state.book) state.summary = await call(`/api/summary?book=${encodeURIComponent(state.book)}`);
|
|
break;
|
|
}
|
|
await loadInvoices();
|
|
}
|