Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ test.describe("Bookkeeping and Sponsors design prototype", () => {
// The page is the transaction list for the latest month with activity.
await expect(page.locator("[data-period-heading]")).toHaveText("July 2026");
const studioRow = page.locator(".bk-row").filter({ hasText: "Example Studio" });
await expect(studioRow.locator(".bk-flag")).toHaveAttribute("aria-label", "No receipt");
await expect(studioRow.locator(".bk-cell-icon--missing")).toHaveAttribute("aria-label", "No invoice attached");
await expect(studioRow.locator(".bk-col-eur")).toHaveText("−€320.00");
await expectPalette(page, false);
await expectNoPageOverflow(page, 1440);
Expand Down
88 changes: 86 additions & 2 deletions frontend/src/styles/bookkeeping.css
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ tr.bk-month__totals-row > th {
.bk-col-class { padding-left: var(--dk-space-1); padding-right: var(--dk-space-1); overflow: hidden; }
.bookkeeping-surface .bk-col-subtype .bk-inline-select { width: 8.5em; }
.bookkeeping-surface .bk-col-category .bk-inline-select { width: 10.5em; }
.bookkeeping-surface .bk-col-period .bk-inline-select { width: 6.5em; }
.bk-col-flag { width: 4em; padding-right: var(--dk-space-3); text-align: center; }
.bk-flag { display: inline-flex; color: var(--dk-text-faint); }
.bk-flag svg { width: 14px; height: 14px; }
.bk-no-invoice { color: var(--dk-text-muted); font-size: var(--dk-text-xs); white-space: nowrap; }
Expand Down Expand Up @@ -374,3 +372,89 @@ tr.bk-month__totals-row > th {
.bk-inv-note { min-width: 8em; }
.bk-inv-dispose { flex-direction: column; align-items: stretch; }
}

/* ---- Table cells: invoice and account are fixed-width, centred icon columns ---- */
.bk-col-flag,
.bk-col-account { width: 4.5rem; min-width: 4.5rem; max-width: 4.5rem; padding-left: 0; padding-right: 0; text-align: center; vertical-align: middle; }
.bk-table th.bk-col-flag,
.bk-table th.bk-col-account { text-align: center; }
.bookkeeping-surface .bk-table .bk-cell-icon {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
padding: 0;
border: 0;
border-radius: var(--dk-radius-sm);
background: transparent;
color: var(--dk-text-muted);
line-height: 1;
text-decoration: none;
vertical-align: middle;
}
.bk-cell-icon svg { width: 16px; height: 16px; flex: none; }
button.bk-cell-icon,
a.bk-cell-icon { cursor: pointer; }
button.bk-cell-icon:hover,
a.bk-cell-icon:hover { background: var(--dk-bg-hover); color: var(--dk-text-primary); }
button.bk-cell-icon:focus-visible,
a.bk-cell-icon:focus-visible { outline: 2px solid var(--dk-focus-ring); outline-offset: 1px; }
.bk-cell-icon--invoice { color: var(--dk-accent-default); }
.bk-cell-icon--missing { color: var(--dk-warning-text); opacity: 0.75; }
.bk-cell-icon--quiet,
.bk-cell-icon--empty { color: var(--dk-text-faint); }
.bk-cell-icon__count {
position: absolute;
top: -2px;
right: -2px;
min-width: 14px;
height: 14px;
padding: 0 var(--dk-space-1);
border-radius: 7px;
background: var(--dk-accent-default);
color: var(--dk-text-on-accent, var(--dk-bg-surface));
font-size: var(--dk-text-xs);
font-weight: var(--dk-weight-semibold);
line-height: 14px;
text-align: center;
}

/* ---- Transaction detail dialog ---- */
.bk-transaction-dialog { width: min(40rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border: 1px solid var(--dk-border-default); border-radius: var(--dk-radius-lg); background: var(--dk-bg-surface); color: var(--dk-text-body); }
.bk-transaction-dialog::backdrop { background: var(--dk-bg-backdrop); }
.bk-transaction-dialog__header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: var(--dk-space-3); padding: var(--dk-space-3) var(--dk-space-4); border-bottom: 1px solid var(--dk-border-default); background: var(--dk-bg-surface); }
.bk-transaction-dialog__header h2 { margin: 0; overflow: hidden; color: var(--dk-text-heading); font-size: var(--dk-text-base); font-weight: var(--dk-weight-semibold); text-overflow: ellipsis; white-space: nowrap; }
.bk-transaction-dialog__close { flex: none; padding: var(--dk-space-1) var(--dk-space-3); border: 1px solid var(--dk-border-default); border-radius: var(--dk-radius-sm); background: transparent; color: var(--dk-text-body); font: inherit; font-size: var(--dk-text-sm); cursor: pointer; }
.bk-transaction-dialog__close:hover { background: var(--dk-bg-hover); }
.bk-transaction-dialog__content { display: flex; flex-direction: column; gap: var(--dk-space-3); padding: var(--dk-space-4); }
.bk-transaction-dialog__content > section { padding: var(--dk-space-3) var(--dk-space-4); border: 1px solid var(--dk-border-default); border-radius: var(--dk-radius-md); }
.bk-transaction-dialog__content h3 { margin: 0 0 var(--dk-space-2); color: var(--dk-text-muted); font-size: var(--dk-text-xs); font-weight: var(--dk-weight-semibold); letter-spacing: 0.04em; text-transform: uppercase; }
.bk-transaction-invoices__list { display: flex; flex-direction: column; gap: var(--dk-space-2); margin: 0; padding: 0; list-style: none; }
.bk-transaction-invoice { display: flex; align-items: center; justify-content: space-between; gap: var(--dk-space-3); }
.bk-transaction-invoice__name { min-width: 0; overflow: hidden; color: var(--dk-text-heading); font-weight: var(--dk-weight-medium); text-overflow: ellipsis; white-space: nowrap; }
.bk-transaction-invoice__open { flex: none; }
.bk-transaction-invoices--missing { border-style: dashed; background: var(--dk-warning-bg); }
.bk-transaction-invoices__none { margin: 0; color: var(--dk-warning-text); font-weight: var(--dk-weight-semibold); }
.bk-transaction-invoices__hint { margin: var(--dk-space-1) 0 0; color: var(--dk-text-muted); font-size: var(--dk-text-sm); }
.bk-transaction-summary__vendor { margin: 0; color: var(--dk-text-heading); font-size: var(--dk-text-lg); font-weight: var(--dk-weight-semibold); }
.bk-transaction-summary__amount { margin: var(--dk-space-1) 0 0; color: var(--dk-text-heading); font-size: 1.5rem; font-weight: var(--dk-weight-semibold); font-variant-numeric: tabular-nums; }
.bk-transaction-summary__what { margin: var(--dk-space-1) 0 var(--dk-space-3); color: var(--dk-text-muted); }
.bk-transaction-summary__what span { color: var(--dk-text-faint); font-size: var(--dk-text-xs); text-transform: uppercase; letter-spacing: 0.04em; margin-right: var(--dk-space-1); }
.bk-transaction-summary__facts,
.bk-transaction-statement__facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: var(--dk-space-3) var(--dk-space-4); margin: 0; }
.bk-transaction-field { min-width: 0; }
.bk-transaction-field dt,
.bk-transaction-statement__facts dt { color: var(--dk-text-muted); font-size: var(--dk-text-xs); }
.bk-transaction-field dd,
.bk-transaction-statement__facts dd { margin: var(--dk-space-1) 0 0; overflow-wrap: anywhere; color: var(--dk-text-heading); font-variant-numeric: tabular-nums; }
.bk-transaction-statement__record { display: flex; flex-direction: column; gap: var(--dk-space-1); width: 100%; margin-bottom: var(--dk-space-3); padding: var(--dk-space-2) var(--dk-space-3); border: 1px solid var(--dk-border-default); border-radius: var(--dk-radius-sm); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.bk-transaction-statement__record:hover { background: var(--dk-bg-hover); }
.bk-transaction-statement__none { margin: 0 0 var(--dk-space-2); color: var(--dk-text-muted); }
.bk-transaction-statement__candidate-label { display: flex; flex-direction: column; gap: var(--dk-space-1); margin-bottom: var(--dk-space-2); color: var(--dk-text-muted); font-size: var(--dk-text-sm); }
.bk-transaction-statement__candidate-label select { padding: var(--dk-space-2); border: 1px solid var(--dk-border-default); border-radius: var(--dk-radius-sm); color: var(--dk-text-body); font: inherit; }
@media (max-width: 640px) {
.bk-transaction-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; }
.bk-transaction-dialog__content { padding: var(--dk-space-3); }
}
116 changes: 68 additions & 48 deletions frontend/src/surfaces/finance/bookkeeping-ledger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The transaction table: one dense row per transaction, the same columns
// as the bookkeeping spreadsheet it replaces (date, counterparty, what,
// original amount, EUR amount, account, type, category, period). Pure
// original amount, EUR amount, account, type, category). Pure
// functions from records to markup and from URL state to filters; the
// surface (bookkeeping.js) owns fetching, events and saving.
import { sponsorRecordPath } from "../../core/sponsor-routes.js";
Expand All @@ -12,12 +12,12 @@ import { bookkeepingVendorPresentation } from "./bookkeeping-vendors.js";
export const LEDGER_PARAMS = ["month", "q", "account", "dir", "category", "needs", "tx", "view"];
export const SECONDARY_VIEWS = ["files", "package", "invoices", "tuition", "inventory"];

// The spreadsheet's classification columns, in its order and wording:
// "Type" is stored as `subtype`, "Category" as `category`, "Period" as `period`.
// The classification columns: "Type" is stored as `subtype`, "Category" as
// `category`. The spreadsheet's Period column is not shown in the table: it
// was copied in with the sheet layout (efdd13e5), nobody asked for it.
export const CLASSIFICATION_FIELDS = [
{ field: "subtype", label: "Type" },
{ field: "category", label: "Category" },
{ field: "period", label: "Period" },
];

// The account a transaction went through. The sheet's Statement column holds
Expand Down Expand Up @@ -126,11 +126,32 @@ export function linkedEvidenceDocuments(entry, links, documents) {
const ids = new Set((Array.isArray(links) ? links : [])
.filter((link) => link.transactionId === entry.id && link.coverageType === "evidence")
.map((link) => String(link.documentId || "")));
return (Array.isArray(documents) ? documents : []).filter((document) =>
const linked = (Array.isArray(documents) ? documents : []).filter((document) =>
ids.has(String(document.id || ""))
&& document.status === "active"
&& INVOICE_EVIDENCE_TYPES.has(String(document.documentType || "")),
);
return linked.length ? linked : invoiceSourceDocuments(entry);
}

export const INVOICE_SOURCE_PREFIX = "invoice:";

/**
* Rows the invoice intake booked (sourceType "invoice") hold their PDF as the
* confirmed invoice's source artifact, not as a bookkeeping document link, so
* /links never lists it. The month package already resolves it that way; the
* table does the same and opens it through /invoices/:id/document.
*/
export function invoiceSourceDocuments(entry) {
const invoiceId = String(entry?.invoiceId || "").trim();
if (!invoiceId || !String(entry?.documentArtifactId || "").trim()) return [];
const number = String(entry.invoiceNumber || "").trim();
return [{
id: `${INVOICE_SOURCE_PREFIX}${invoiceId}`,
status: "active",
documentType: "invoice",
originalFilename: number ? `Invoice ${number}` : `Invoice from ${entry.counterparty || "vendor"}`,
}];
}

// URL state -> filters. Unknown values fall back to "show everything".
Expand Down Expand Up @@ -296,8 +317,42 @@ const icon = {
bank: '<svg viewBox="0 0 16 16" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4">'
+ '<path d="M2 6 8 2.5 14 6" stroke-linecap="round" stroke-linejoin="round"/>'
+ '<path d="M3.5 6.5V12M6.5 6.5V12M9.5 6.5V12M12.5 6.5V12M2.5 12.5h11" stroke-linecap="round"/></svg>',
missing: '<svg viewBox="0 0 16 16" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4">'
+ '<path d="M4 1.5h5.5L13 5v9.5H4z" stroke-linejoin="round" stroke-dasharray="2 1.6"/>'
+ '<path d="M6.5 9.5h3" stroke-linecap="round"/></svg>',
};

// Invoice cell: always one control on the same axis. Attached -> one PDF icon
// (with a count when several); missing -> one muted dashed icon.
function invoiceCellMarkup(documents, hasAttachedFlag, e, txId) {
const count = documents.length;
if (count === 1) {
const [document] = documents;
const label = document.originalFilename || "invoice or receipt PDF";
return html`<button type="button" class="dk-icon-button dk-icon-button--sm bk-cell-icon bk-cell-icon--invoice bk-evidence-view" data-view-document="${e(document.id)}"
aria-label="View ${e(label)}" title="${e(label)}">${icon.pdf}</button>`;
}
if (count > 1)
return html`<button type="button" class="dk-icon-button dk-icon-button--sm bk-cell-icon bk-cell-icon--invoice bk-evidence-view" data-open-tx="${e(txId)}"
aria-label="${count} invoices attached, open details" title="${count} invoices attached">${icon.pdf}<span class="bk-cell-icon__count">${count}</span></button>`;
if (hasAttachedFlag)
return html`<span class="bk-cell-icon bk-cell-icon--invoice" title="Invoice attached" aria-label="Invoice attached">${icon.receipt}</span>`;
return html`<span class="bk-cell-icon bk-cell-icon--missing" title="No invoice attached" aria-label="No invoice attached">${icon.missing}</span>`;
}

// Account cell: bank icon (opens the statement when matched), a muted bank
// icon with the account name in the tooltip when there is only a label, and
// a dash when there is nothing.
function accountCellMarkup(account, accountDoc, e) {
const title = accountDoc?.statementPeriod ? `${account} — open ${accountDoc.statementPeriod} statement` : account;
if (accountDoc?.statementDocumentId)
return html`<button type="button" class="dk-icon-button dk-icon-button--sm bk-cell-icon bk-account-view" data-view-document="${e(accountDoc.statementDocumentId)}"
aria-label="${e(title)}" title="${e(title)}">${icon.bank}</button>`;
if (account)
return html`<span class="bk-cell-icon bk-cell-icon--quiet" title="${e(account)}" aria-label="${e(account)}">${icon.bank}</span>`;
return html`<span class="bk-cell-icon bk-cell-icon--empty" aria-label="No account" title="No account">—</span>`;
}

export function ledgerRowMarkup(entry, { hasEvidence, hasInvoice = () => false, vocab, selectedId, financeEntry, statementLinks = new Map(), e }) {
const direction = entryDirection(entry);
const net = netValue(entry, financeEntry);
Expand All @@ -313,27 +368,8 @@ export function ledgerRowMarkup(entry, { hasEvidence, hasInvoice = () => false,
const invoiceEvidence = hasInvoice(entry.id);
const invoiceDocuments = Array.isArray(invoiceEvidence) ? invoiceEvidence : [];
const hasInvoiceAttached = invoiceDocuments.length > 0 || invoiceEvidence === true;
// One compact icon per invoice PDF; the filename lives in the tooltip
// instead of a wide "View PDF" button on every row.
const invoiceActions = invoiceDocuments.length
? invoiceDocuments.map((document) => html`<button type="button" class="dk-icon-button dk-icon-button--sm bk-evidence-view"
data-view-document="${e(document.id)}"
aria-label="View ${e(document.originalFilename || "invoice or receipt PDF")}"
title="${e(document.originalFilename || "Invoice or receipt PDF")}">${icon.pdf}</button>`).join("")
: hasInvoiceAttached
? html`<span class="bk-invoice-icon" title="Invoice attached" aria-label="Invoice attached">${icon.receipt}</span>`
: html`<span class="bk-no-invoice">No invoice</span>`;
const account = resolveAccountName(entry, statementLinks);
const accountDoc = statementLinks instanceof Map ? statementLinks.get(String(entry.id || "")) : null;
const accountStatementTitle = accountDoc?.statementPeriod
? `${accountDoc.statementPeriod} statement`
: "statement";
const accountCell = accountDoc?.statementDocumentId
? html`<button type="button" class="dk-icon-button dk-icon-button--sm bk-account-view"
data-view-document="${e(accountDoc.statementDocumentId)}"
aria-label="${e(account)} — open ${e(accountStatementTitle)}"
title="${e(account)} — open ${e(accountStatementTitle)}">${icon.bank}</button>`
: e(account || "—");
return html`<tr class="bk-row${flagged ? " is-uncategorised" : ""}${direction === "income" ? " is-income" : ""}"
data-tx="${e(entry.id)}"${entry.id === selectedId ? ' aria-selected="true"' : ""}>
<td class="bk-col-date">${dateCell(entry, e)}</td>
Expand All @@ -351,11 +387,8 @@ export function ledgerRowMarkup(entry, { hasEvidence, hasInvoice = () => false,
id: entry.id, field, label: `${label} for ${entry.counterparty || "transaction"}`,
value: entry[field], options: vocab[field] || [], e,
})}</td>`).join("")}
<td class="bk-col-flag">
${invoiceActions}
${hasEvidence(entry.id) ? "" : html`<span class="bk-flag" title="No receipt attached" aria-label="No receipt">${icon.receipt}</span>`}
</td>
<td class="bk-col-account">${accountCell}</td>
<td class="bk-col-flag">${invoiceCellMarkup(invoiceDocuments, hasInvoiceAttached, e, entry.id)}</td>
<td class="bk-col-account">${accountCellMarkup(account, accountDoc, e)}</td>
</tr>`;
}

Expand All @@ -380,8 +413,9 @@ function bankOnlyRowMarkup(entry, e) {
: e(signedAmount(eur, "EUR"))}</td>
<td class="bk-col-vat">—</td>
${CLASSIFICATION_FIELDS.map(({ field }) => html`<td class="bk-col-class bk-col-${field}">${e(entry[field] || "")}</td>`).join("")}
<td class="bk-col-flag"><span class="bk-statement-source">Bank statement</span></td>
<td class="bk-col-account">${e(accountOf(entry))}</td>
<td class="bk-col-flag"><span class="bk-cell-icon bk-cell-icon--quiet"
title="Bank statement line, no invoice needed" aria-label="Bank statement line">${icon.bank}</span></td>
<td class="bk-col-account">${accountCellMarkup(accountOf(entry), null, e)}</td>
</tr>`;
}

Expand Down Expand Up @@ -409,21 +443,7 @@ function allocationChildMarkup(entry, allocation, { getAllocationDocument = () =
const document = getAllocationDocument(entry, allocation);
const accountName = resolveAccountName(entry, statementLinks);
const statementLink = statementLinks instanceof Map ? statementLinks.get(String(entry.id || "")) : null;
const accountStatementTitle = statementLink?.statementPeriod
? `${statementLink.statementPeriod} statement`
: "statement";
const accountCell = statementLink?.statementDocumentId
? html`<button type="button" class="dk-icon-button dk-icon-button--sm bk-account-view"
data-view-document="${e(statementLink.statementDocumentId)}"
aria-label="${e(accountName)} — open ${e(accountStatementTitle)}"
title="${e(accountName)} — open ${e(accountStatementTitle)}">${icon.bank}</button>`
: e(accountName || "—");
const pdfAction = document
? html`<button type="button" class="dk-icon-button dk-icon-button--sm bk-evidence-view"
data-view-document="${e(document.id)}"
aria-label="View ${e(document.originalFilename || "invoice or receipt PDF")}"
title="${e(document.originalFilename || "Invoice or receipt PDF")}">${icon.pdf}</button>`
: html`<span class="bk-allocation-no-pdf">No linked PDF</span>`;
const pdfAction = invoiceCellMarkup(document ? [document] : [], false, e, entry.id);
return html`<tr class="bk-row bk-row--allocation-child" data-allocation-parent="${e(entry.id)}" data-allocation-document="${e(allocation.documentId || "")}">
<td class="bk-col-date">${dateCell(child, e)}</td>
<td class="bk-col-who">
Expand All @@ -439,7 +459,7 @@ function allocationChildMarkup(entry, allocation, { getAllocationDocument = () =
<td class="bk-col-vat"${vat ? ` title="${e(vatTitle(child, vat))}"` : ""}>${e(vat || "—")}</td>
${CLASSIFICATION_FIELDS.map(({ field }) => html`<td class="bk-col-class bk-col-${field}">${e(allocation[field] || "")}</td>`).join("")}
<td class="bk-col-flag">${pdfAction}</td>
<td class="bk-col-account">${accountCell}</td>
<td class="bk-col-account">${accountCellMarkup(accountName, statementLink, e)}</td>
</tr>`;
}

Expand All @@ -457,7 +477,7 @@ export function ledgerHeadMarkup() {
</thead>`;
}

const COLUMN_COUNT = 9;
const COLUMN_COUNT = 8;

// One totals row at the bottom of a month: money in and money out, no net.
// The figures are the Finance overview's own (financeTotals from
Expand Down
Loading