diff --git a/backend/e2e/bookkeeping-sponsors-design-production-portal.spec.js b/backend/e2e/bookkeeping-sponsors-design-production-portal.spec.js index 6c08b135..eabdc2ab 100644 --- a/backend/e2e/bookkeeping-sponsors-design-production-portal.spec.js +++ b/backend/e2e/bookkeeping-sponsors-design-production-portal.spec.js @@ -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); diff --git a/frontend/src/styles/bookkeeping.css b/frontend/src/styles/bookkeeping.css index 8513c99a..b61c3c01 100644 --- a/frontend/src/styles/bookkeeping.css +++ b/frontend/src/styles/bookkeeping.css @@ -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; } @@ -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); } +} diff --git a/frontend/src/surfaces/finance/bookkeeping-ledger.js b/frontend/src/surfaces/finance/bookkeeping-ledger.js index 2370e874..91b8b0c1 100644 --- a/frontend/src/surfaces/finance/bookkeeping-ledger.js +++ b/frontend/src/surfaces/finance/bookkeeping-ledger.js @@ -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"; @@ -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 @@ -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". @@ -296,8 +317,42 @@ const icon = { bank: '', + missing: '', }; +// 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``; + } + if (count > 1) + return html``; + if (hasAttachedFlag) + return html``; + return html``; +} + +// 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``; + if (account) + return html``; + return html``; +} + export function ledgerRowMarkup(entry, { hasEvidence, hasInvoice = () => false, vocab, selectedId, financeEntry, statementLinks = new Map(), e }) { const direction = entryDirection(entry); const net = netValue(entry, financeEntry); @@ -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``).join("") - : hasInvoiceAttached - ? html`` - : html`No invoice`; 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`` - : e(account || "—"); return html`
No invoice
+Nothing is attached to this transaction yet. Attach one from the suggestions below.
${e(signedAmountMarkup(eurValue, "EUR", amount))}
What for ${e(transaction.description || "Not recorded")}