diff --git a/CHANGELOG.md b/CHANGELOG.md index e93323c..b495e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,37 @@ # Changelog +## 0.8.0 + +The window has now been run as a whole: a twenty-line invoice typed, posted and followed through three ledger screens, with nothing on screen moving. + +### New +- Every screen in the sidebar has an icon. +- The payment form picks the customer or supplier with the same search box the document form uses. +- Profit and loss starts on the first day of your fiscal year, not on January 1. + +### Changed +- Tables with a totals row have a fixed height and scroll inside it. The totals stay at the foot and the header stays at the top. +- The line grid on a document shows eight lines and scrolls after that, so the totals and buttons under it stay where they are while you add lines. +- The list of open invoices on a payment shows eight rows and scrolls after that. +- A new account, customer, item or other setup row appears at its place in code order, not at the end. + +### Fixed +- Choosing a party on a payment no longer adds, removes and re-adds an invoice row. +- The totals on a document no longer move sideways when it is posted. +- The search box's list no longer jumps from above the field to below it while you type. +- "Load more" no longer moves when the count beside it changes width. +- Profit and loss, the balance sheet and the ledger screens no longer shift when their rows arrive. + +### Known issues +- The look of the screens is plain. Row heights and spacing are now steady, but the design has not had a pass of its own. +- A line with only a quantity or a price, and no item or description, is dropped without a message when the document is saved. +- Amounts show two decimals for every currency. +- Delivery notes are still outside a sales order's chain, and there are no part receipts, part deliveries or part invoices. +- The desktop app has not been built yet; the window runs in a browser against the server. + +### Under the hood +- The shared table writes its row count to one custom property and a hidden filler row takes the spare height. + ## 0.7.0 The web client gets its first screens. Until now everything was done from the command line or the server's routes. This is a first pass: it has been run in a browser in parts, not yet as a whole. diff --git a/Makefile b/Makefile index 5cb32c7..6873bfb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := v0.7.0 +VERSION := v0.8.0 GO_BUILD := CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" .PHONY: build web server check clean diff --git a/cmd/HASHOUT_LOG.md b/cmd/HASHOUT_LOG.md index 1ecb871..7fc8da9 100644 --- a/cmd/HASHOUT_LOG.md +++ b/cmd/HASHOUT_LOG.md @@ -2,7 +2,7 @@ Living log of all comment content, explainers, rationale, TODOs, & removed (hashed-out) code for the entry point, `embed.go`, `internal/server`, `internal/static` and `internal/startup`. Source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. Read it first, then edit code surgically. -Current build version: v0.7.0 +Current build version: v0.8.0 Last updated: 2026-11-26 (US Eastern) · skeleton port from form.md --- diff --git a/docs/ledger/statements.md b/docs/ledger/statements.md index c02c75a..cf141b4 100644 --- a/docs/ledger/statements.md +++ b/docs/ledger/statements.md @@ -39,4 +39,4 @@ Two views in the Ledger group, "Profit and loss" (a From and To date) and "Balan ## Defaults to confirm - One currency: amounts of accounts in different currencies are added together as they are. Every account in the starter chart is in `USD`. -- The profit and loss starts on the first of January of the end date's year by default, not the start of the fiscal year. +- In the window, the profit and loss starts on the first day of the fiscal year (from `GET /api/fiscal-years`) that contains the end date, and on the first of January of the end date's year when no fiscal year contains it. The route itself, called without `from`, still uses the first of January. diff --git a/docs/window/README.md b/docs/window/README.md index 0c573b1..0309ba2 100644 --- a/docs/window/README.md +++ b/docs/window/README.md @@ -1,18 +1,20 @@ # The window -The web client is the same app as the command line and the server's routes, shown as screens. Everything it does goes through the routes described in `docs/selling/`, `docs/buying/`, `docs/stock/` and `docs/ledger/`; it keeps no numbers of its own. This page says what is on each screen as of v0.7.0 and what is not there yet. +The web client is the same app as the command line and the server's routes, shown as screens. Everything it does goes through the routes described in `docs/selling/`, `docs/buying/`, `docs/stock/` and `docs/ledger/`; it keeps no numbers of its own. This page says what is on each screen and what is not there yet. ## Getting around -The sidebar groups the screens: Selling, Buying, Stock, Ledger and Setup. The address in the browser names the screen, for example `#/quotes?status=posted`, so a reload or a bookmark comes back to the same place. A screen shows only the actions your role allows. +The sidebar groups the screens: Selling, Buying, Stock, Ledger and Setup, with a small icon beside each screen. The address in the browser names the screen, for example `#/quotes?status=posted`, so a reload or a bookmark comes back to the same place. A screen shows only the actions your role allows. ## Lists -There is one list for each kind of document: quotes, sales orders, sales invoices, delivery notes, payments received, purchase orders, goods receipts, purchase invoices and payments made. Each shows the number, date, party, status and total, can be narrowed by status, and loads more rows on request. A draft that has no number yet reads "Draft". Open a row with a click or with Enter. +There is one list for each kind of document: quotes, sales orders, sales invoices, delivery notes, payments received, purchase orders, goods receipts, purchase invoices and payments made. Each shows the number, date, party, status and total, can be narrowed by status, and loads more rows on request, 100 at a time. The count beside the Load more button has a fixed width, so the button does not move when rows arrive. A draft that has no number yet reads "Draft". Open a row with a click or with Enter. A table that has a totals row has a fixed height and scrolls inside it; its rows keep their height and the totals row stays at the foot. ## The document form -Quotes, sales orders, sales invoices, purchase orders and purchase invoices share one form: who it is for, the dates, and a grid of lines. A line is an item, a description, a quantity, a unit price and a tax rate. Pick the party and each item by typing part of its code or name. +Quotes, sales orders, sales invoices, purchase orders and purchase invoices share one form: who it is for, the dates, and a grid of lines. A line is an item, a description, a quantity, a unit price and a tax rate. Pick the party and each item by typing part of its code or name; the list of matches keeps a minimum height of 320 pixels while it filters, so it does not jump between sides of the field. + +The grid of lines has a fixed height of eight lines and scrolls after that; the totals and the buttons stay under it. The server works out every amount. Line totals and the document total appear after a save, in space that was already there for them. @@ -22,7 +24,7 @@ When the server refuses something, for example a locked period, its own sentence ## Payments -A payment names the party, the date, the amount and the account, and lists that party's open invoices. Type an amount against each invoice the payment covers; what is left over is shown as you type and stays on account. +A payment names the party (picked by typing part of its code or name, as on the document form), the date, the amount and the account, and lists that party's open invoices in a box of eight rows that scrolls. Type an amount against each invoice the payment covers; what is left over is shown as you type and stays on account. ## Goods receipts and delivery notes @@ -34,12 +36,11 @@ Customers, suppliers, items, tax rates, warehouses and the chart of accounts eac ## Ledger and position screens -Trial balance (as of a day, and whether it balances), general ledger (one account over a range, with a running balance), profit and loss (over a range), balance sheet (as of a day), receivables and payables ageing, and stock balance with its value and the check against the books. `docs/ledger/statements.md` describes how profit and loss and the balance sheet are built. +Trial balance (as of a day, and whether it balances), general ledger (one account over a range, with a running balance), profit and loss (over a range that starts at the fiscal year's first day), balance sheet (as of a day), receivables and payables ageing, and stock balance with its value and the check against the books. `docs/ledger/statements.md` describes how profit and loss and the balance sheet are built. ## Not there yet - Amounts are shown with two decimal places for every currency. - Receipts and delivery notes cannot be edited before posting. -- There are no icons in the sidebar, no search across documents, and no printing. +- There is no search across documents and no printing. - The setup lists have no delete, because the server has none. -- A list's totals row sits under its rows and moves once when the rows arrive. diff --git a/internal/HASHOUT_LOG.md b/internal/HASHOUT_LOG.md index 7a27d72..c5139dd 100644 --- a/internal/HASHOUT_LOG.md +++ b/internal/HASHOUT_LOG.md @@ -2,7 +2,7 @@ Living log of comment content, rationale and removed code for the core skeleton packages under `internal/`. Source files stay comment-free; what they would have said lives here, indexed. Read it first, then edit code surgically. Covers the packages ported in the core slice only; `internal/server`, `internal/static` and `internal/startup` are logged by their own slice. -Current build version: v0.7.0 +Current build version: v0.8.0 Last updated: 2026-11-27 (US Eastern) · profit and loss and the balance sheet --- diff --git a/internal/app/version.go b/internal/app/version.go index 1c572ca..3ece448 100644 --- a/internal/app/version.go +++ b/internal/app/version.go @@ -1,5 +1,5 @@ package app -var Version = "v0.7.0" +var Version = "v0.8.0" const Product = "FormLedger" diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c0b071e..954b1ba 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1106,7 +1106,7 @@ dependencies = [ [[package]] name = "formledger-desktop" -version = "0.7.0" +version = "0.8.0" dependencies = [ "objc2", "objc2-app-kit", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index cf49af7..c60503d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "formledger-desktop" -version = "0.7.0" +version = "0.8.0" description = "FormLedger desktop app" authors = ["NodeAgentc, Inc."] license = "Apache-2.0" diff --git a/src-tauri/HASHOUT_LOG.md b/src-tauri/HASHOUT_LOG.md index f1c9852..37e44a8 100644 --- a/src-tauri/HASHOUT_LOG.md +++ b/src-tauri/HASHOUT_LOG.md @@ -2,7 +2,7 @@ Living log of all comment content, explainers, rationale, TODOs, & removed (hashed-out) code for the Tauri 2 desktop shell (`src-tauri`). Source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. This file is also the compressed contextual map of the shell: read it first, then edit code surgically. -Current build version: v0.7.0 +Current build version: v0.8.0 Last updated: 2026-11-26 (US Eastern) · the shell ported from form.md's src-tauri and renamed for FormLedger --- diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 8ae8070..00a3fc9 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -2,7 +2,7 @@ "$schema": "https://schema.tauri.app/config/2", "productName": "FormLedger", "mainBinaryName": "formledger-desktop", - "version": "0.7.0", + "version": "0.8.0", "identifier": "ai.nodemode.formledger", "build": { "frontendDist": "splash" }, "app": { diff --git a/web/HASHOUT_LOG.md b/web/HASHOUT_LOG.md index 3a5f10f..9309442 100644 --- a/web/HASHOUT_LOG.md +++ b/web/HASHOUT_LOG.md @@ -2,7 +2,7 @@ Living log of all comment content, explainers, rationale, TODOs, & removed (hashed-out) code for the web client. Source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. This file is also the compressed contextual map of the web side: read it first, then edit code surgically. -Current build version: v0.7.0 +Current build version: v0.8.0 Last updated: 2026-11-26 (US Eastern) · account screens, and the fixes from the throttled browser check --- @@ -577,3 +577,47 @@ One form per family (`sales-doc`, `purchase-doc`) is built on first show from `S - logged: v0.7.0 · 2026-11-27 Six setup views come from one table of specs. Each view builds its table and a fixed-size form once; opening a row rewrites the field values and locks the fields the server refuses to change after create (code, type, currency, linked account codes). Edit sends only the fields that changed. Account, tax rate and item links are typed as codes, not picked, because the picker slice may not land; the server's own sentence shows when a code is unknown. Accounts have no cursor, so the whole chart is read once. + +## masters new row placement + +- refers-to: src/ui/views/masters.ts :: mountMaster +- kind: rationale +- logged: v0.7.0 · 2026-11-27 + +The shared table appends a row it has not seen. After a create, the one new row is moved to its place among the siblings by comparing first-column text with a numeric collation, so a new account lands in code order. Only that row moves; saving an edit rewrites the row in place. + +## statements layout shift and fiscal start + +- refers-to: src/ui/views/statements.ts, src/styles/views/statements.css :: .st .tbl__fill +- kind: rationale +- logged: v0.7.0 · 2026-11-27 + +Under CPU 4x and 400 ms latency, the only node that shifted on a hard reload was the empty filler body inside each totals table (0.061 on profit and loss, 0.060 on the balance sheet); it shrinks as rows arrive and holds nothing, so it is hidden and the tables take their height from the shared block variable. Profit and loss leaves From empty (same size) until the fiscal years answer, then fills it and loads once; an address with a from skips the wait. A stale answer is dropped by a counter. + +### src/styles/views/ledger-screens.css · table height +- refers-to: src/styles/views/ledger-screens.css :: .ls +- kind: rationale +- logged: v0.8.0 · 2026-11-27 + +The five screens set `--tbl-block` to the window height less `--ls-above` (250px: the shell header, title, filter bar and status line plus a bottom margin), never under eight rows, so a long trial balance or ledger scrolls inside a box that ends near the bottom of the window. The shared table now sizes its hidden filler from the row count and sticks the whole totals row, so these screens carry no rules of their own for it. Before that, the filler and the totals row moved when rows arrived and Chrome reported it: 0.18 on the trial balance, 0.30 on the ledger, 0.096 on the other three. Re-measured on the fixed table under CPU 4x and 400 ms latency: 0 on all five screens, with the general ledger's account picked by keyboard, every body row 30px, the header cells at y 218 and the totals cells at y 736 whether the body is short or scrolled. + +### src/styles/views/grid.css · totals column +- refers-to: src/styles/views/grid.css :: .grid__totals; src/ui/views/docform.ts :: fill +- kind: rationale +- logged: v0.8.0 · 2026-11-27 + +The amounts column of the totals list is a fixed 16ch, not `auto`: with `auto` it widened as the total grew and the three amounts moved sideways on post (0.00003, sources the three `dd`). The form passes the loaded document's currency to `grid.setCurrency`, which returns early when it has not changed, so the label is written once per document. + +### src/ui/views/payments.ts · one invoice load per party +- refers-to: src/ui/views/payments.ts :: loadInvoices; src/styles/views/payments.css :: .pay__alloc-box, .pay .tbl__fill +- kind: rationale +- logged: v0.8.0 · 2026-11-27 + +Each invoice load takes its own number and only the latest may write rows, and a pick of the party already loaded does nothing, so `open()` and a party pick no longer race to add, remove and re-add a row. The party is the shared picker; a picked party outside the first 200 is added to the local map so its invoices still load. The allocation box is a fixed eight rows with the unallocated line sticky at its foot: before, rows arriving pushed the error line and buttons (0.008 on the received form, 0.0023 on the made form). The shared filler row is hidden under `.pay`: it moved from y 281 to 633 and shrank from 358 to 6px as rows arrived, 0.082 on a goods receipt and 0.085 on the received list. + +### src/styles/views/doclists.css · count width +- refers-to: src/styles/views/doclists.css :: .dl__count, --dl-count-width; src/ui/views/doclists.ts :: countText +- kind: rationale +- logged: v0.8.0 · 2026-11-27 + +The count beside Load more went from empty to "114 shown, more to load", and the button after it moved sideways on every page (0.00063 then 0.00035 per load, sources the button, 0.0011 to 0.0013 over a list). The count now has a fixed 24ch box, right aligned, so the button stays put: 0.0 on quotes, sales orders and purchase orders afterwards, 0.0001 on the invoice lists from the form's buttons, not from the list. The 0.09 seen on delivery notes and goods receipts is the filler row on their forms, not on the lists. diff --git a/web/package-lock.json b/web/package-lock.json index 235227a..6240d93 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,12 +1,12 @@ { "name": "formledger", - "version": "0.7.0", + "version": "0.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "formledger", - "version": "0.7.0", + "version": "0.8.0", "license": "Apache-2.0", "devDependencies": { "@types/node": "^22.20.5", diff --git a/web/package.json b/web/package.json index 0a3e370..bc572cc 100644 --- a/web/package.json +++ b/web/package.json @@ -1,7 +1,7 @@ { "name": "formledger", "private": true, - "version": "0.7.0", + "version": "0.8.0", "license": "Apache-2.0", "type": "module", "scripts": { diff --git a/web/src/engine/statements.ts b/web/src/engine/statements.ts index a77b8ac..e5af42a 100644 --- a/web/src/engine/statements.ts +++ b/web/src/engine/statements.ts @@ -38,6 +38,21 @@ export function yearStart(day: string): string { return `${day.slice(0, 4)}-01-01`; } +interface FiscalYear { + startDate: string; + endDate: string; +} + +export async function fiscalStart(api: Api, day: string): Promise { + try { + const r = await api.call<{ years: FiscalYear[] }>("GET", "/api/fiscal-years"); + const hit = r.years.find((y) => y.startDate <= day && day <= y.endDate); + return hit ? hit.startDate : yearStart(day); + } catch { + return yearStart(day); + } +} + export function profitAndLoss(api: Api, from: string, to: string): Promise { const q = new URLSearchParams({ from, to }); return api.call("GET", `/api/reports/profit-and-loss?${q}`); diff --git a/web/src/styles/parts.css b/web/src/styles/parts.css index 3b7de7b..44652cc 100644 --- a/web/src/styles/parts.css +++ b/web/src/styles/parts.css @@ -89,6 +89,42 @@ border-block-end: 0; } +.tbl[data-foot] { + --tbl-box: var(--tbl-block, calc(var(--row) * 14)); + block-size: var(--tbl-box); + overflow: auto; +} + +.tbl[data-foot] .tbl__table thead th { + position: sticky; + inset-block-start: 0; +} + +.tbl[data-foot] .tbl__table tfoot { + position: sticky; + inset-block-end: 0; +} + +.tbl[data-foot] .tbl__table tfoot td { + background: var(--surface); +} + +.tbl__fill { + visibility: hidden; +} + +.tbl__fill td { + block-size: max(0px, calc(var(--tbl-box) - var(--row) * (var(--tbl-rows, 0) + 2) - 2px)); + padding: 0; + border: 0; +} + +.tbl[data-open] tbody.tbl__fill tr, +.tbl[data-open] tbody.tbl__fill tr:hover { + cursor: default; + background: none; +} + .tbl[data-open] tbody tr { cursor: pointer; } diff --git a/web/src/styles/views/doclists.css b/web/src/styles/views/doclists.css index 8d0b8e9..d9fd205 100644 --- a/web/src/styles/views/doclists.css +++ b/web/src/styles/views/doclists.css @@ -5,6 +5,7 @@ --dl-col-status: 112px; --dl-col-total: 168px; --dl-filter-width: 160px; + --dl-count-width: 24ch; display: flex; flex-direction: column; gap: var(--space-3); @@ -32,6 +33,9 @@ } .dl__count { + inline-size: var(--dl-count-width); + white-space: nowrap; + text-align: end; font-variant-numeric: tabular-nums; } diff --git a/web/src/styles/views/grid.css b/web/src/styles/views/grid.css index 4e8da2e..8626c0d 100644 --- a/web/src/styles/views/grid.css +++ b/web/src/styles/views/grid.css @@ -82,8 +82,9 @@ } .grid__scroll { - overflow-x: auto; - overflow-y: hidden; + overflow: auto; + block-size: calc(var(--grid-row) + 8 * (var(--grid-row) + var(--grid-err)) + 2px); + overscroll-behavior: contain; } .grid__table { @@ -178,7 +179,7 @@ .grid__totals { display: grid; - grid-template-columns: 1fr auto; + grid-template-columns: minmax(0, 1fr) 16ch; column-gap: var(--space-4); row-gap: var(--space-1); inline-size: var(--grid-totals-w); diff --git a/web/src/styles/views/ledger-screens.css b/web/src/styles/views/ledger-screens.css index 0bd8072..ac26428 100644 --- a/web/src/styles/views/ledger-screens.css +++ b/web/src/styles/views/ledger-screens.css @@ -2,6 +2,8 @@ --ls-field: 36px; --ls-label: 20px; --ls-status: 24px; + --ls-above: 250px; + --tbl-block: max(calc(var(--row) * 8), calc(100dvh - var(--ls-above))); display: flex; flex-direction: column; row-gap: var(--space-3); diff --git a/web/src/styles/views/payments.css b/web/src/styles/views/payments.css index bab05bf..3bbb085 100644 --- a/web/src/styles/views/payments.css +++ b/web/src/styles/views/payments.css @@ -66,6 +66,13 @@ min-inline-size: 0; } +.pay__picker { + position: relative; + inline-size: 100%; + block-size: var(--row); + min-inline-size: 0; +} + .pay__value { display: block; block-size: var(--row); @@ -93,6 +100,20 @@ border-color: var(--danger); } +.pay__alloc-box { + display: flex; + flex-direction: column; + block-size: calc(var(--row) * 8); + overflow-y: auto; +} + +.pay__alloc-box .pay__remain { + position: sticky; + inset-block-end: 0; + margin-block-start: auto; + background: var(--surface); +} + .pay__remain { display: flex; justify-content: flex-end; diff --git a/web/src/styles/views/statements.css b/web/src/styles/views/statements.css index 1bd4ea0..6b35460 100644 --- a/web/src/styles/views/statements.css +++ b/web/src/styles/views/statements.css @@ -72,9 +72,12 @@ } .st .tbl { - block-size: calc(var(--row) * var(--st-rows)); - min-block-size: calc(var(--row) * var(--st-rows)); - overflow: auto; + --tbl-block: calc(var(--row) * var(--st-rows)); + min-block-size: var(--tbl-block); +} + +.st .tbl__fill { + visibility: hidden; } .st__summary { diff --git a/web/src/ui/icons.ts b/web/src/ui/icons.ts index 8042558..6622d2f 100644 --- a/web/src/ui/icons.ts +++ b/web/src/ui/icons.ts @@ -3,6 +3,26 @@ const PATHS = { home: '', lock: '', user: '', + quote: '', + clipboardCheck: '', + document: '', + trayIn: '', + clock: '', + clipboardList: '', + receipt: '', + trayOut: '', + box: '', + truck: '', + layers: '', + scales: '', + table: '', + trend: '', + bars: '', + building: '', + tag: '', + percent: '', + warehouse: '', + tree: '', close: '', info: '', success: '', diff --git a/web/src/ui/parts/picker.ts b/web/src/ui/parts/picker.ts index 52d5dc7..36dc8af 100644 --- a/web/src/ui/parts/picker.ts +++ b/web/src/ui/parts/picker.ts @@ -98,7 +98,8 @@ export function mountPicker(host: HTMLElement, ctx: ViewContext, o: PickerOption if (!list) return; const r = input.getBoundingClientRect(); list.style.left = `${Math.round(r.left)}px`; - const room = list.offsetHeight || 9 * 32; + const room = Math.max(list.offsetHeight, 320); + list.style.minHeight = `${room}px`; const below = r.bottom + room <= window.innerHeight || r.top < room; list.style.top = `${Math.round(below ? r.bottom : r.top - room)}px`; list.style.width = `${Math.max(Math.round(r.width), 240)}px`; diff --git a/web/src/ui/parts/table.ts b/web/src/ui/parts/table.ts index 2d94b8f..ed9632f 100644 --- a/web/src/ui/parts/table.ts +++ b/web/src/ui/parts/table.ts @@ -48,9 +48,10 @@ export function mountTable(host: HTMLElement, o: TableOptions): TableHandl footCells.set(c.key, cell); row.append(cell); } - table.append(h("tfoot", {}, row)); + const fill = h("td", { attrs: { colspan: String(o.columns.length), "aria-hidden": "true" } }); + table.append(h("tbody", { class: "tbl__fill" }, h("tr", {}, fill)), h("tfoot", {}, row)); } - const root = h("div", { class: "tbl", attrs: { "data-empty": "true" } }, table, empty, error); + const root = h("div", { class: "tbl", attrs: o.foot ? { "data-empty": "true", "data-foot": "true" } : { "data-empty": "true" } }, table, empty, error); host.append(root); const rows = new Map(); @@ -84,7 +85,10 @@ export function mountTable(host: HTMLElement, o: TableOptions): TableHandl }); } - const mark = () => setAttr(root, "data-empty", rows.size ? null : "true"); + const mark = () => { + setAttr(root, "data-empty", rows.size ? null : "true"); + if (o.foot) root.style.setProperty("--tbl-rows", String(rows.size)); + }; let endBusy: (() => void) | null = null; return { diff --git a/web/src/ui/view-icons.ts b/web/src/ui/view-icons.ts new file mode 100644 index 0000000..85fb04f --- /dev/null +++ b/web/src/ui/view-icons.ts @@ -0,0 +1,26 @@ +import type { IconName } from "./icons"; + +export const VIEW_ICONS: Record = { + quotes: "quote", + "sales-orders": "clipboardCheck", + "sales-invoices": "document", + "payments-in": "trayIn", + "receivables-ageing": "clock", + "purchase-orders": "clipboardList", + "goods-receipts": "box", + "purchase-invoices": "receipt", + "payments-out": "trayOut", + "payables-ageing": "clock", + "delivery-notes": "truck", + "stock-balance": "layers", + "trial-balance": "scales", + "general-ledger": "table", + "profit-and-loss": "trend", + "balance-sheet": "bars", + customers: "user", + suppliers: "building", + items: "tag", + "tax-rates": "percent", + warehouses: "warehouse", + accounts: "tree", +}; diff --git a/web/src/ui/views.ts b/web/src/ui/views.ts index 2a0d5da..2b49151 100644 --- a/web/src/ui/views.ts +++ b/web/src/ui/views.ts @@ -1,6 +1,7 @@ import type { Api, Engine } from "../engine"; import { h, ref, setAttr, setText } from "./dom"; import { iconNode, type IconName } from "./icons"; +import { VIEW_ICONS } from "./view-icons"; import { ALL_VIEWS } from "./views/index"; export type ViewGroup = "Selling" | "Buying" | "Stock" | "Ledger" | "Setup"; @@ -75,7 +76,8 @@ export function mountViews(engine: Engine): void { let link: HTMLAnchorElement | null = null; if (def.nav) { const mark = h("span", { class: "sb-icon" }); - if (def.icon) mark.append(iconNode(def.icon)); + const icon = def.icon ?? VIEW_ICONS[def.id]; + if (icon) mark.append(iconNode(icon)); link = h("a", { class: "sb-item", attrs: { href: hashFor(def.id) } }, mark, h("span", { class: "sb-label", text: def.title })); nav.append(link); } diff --git a/web/src/ui/views/docform.ts b/web/src/ui/views/docform.ts index 8e2d994..0251bb7 100644 --- a/web/src/ui/views/docform.ts +++ b/web/src/ui/views/docform.ts @@ -172,6 +172,7 @@ function mountForm(spec: FamilySpec, host: HTMLElement, ctx: ViewContext): (para const fill = async (d: Doc) => { doc = d; + grid.setCurrency(d.currency); setValue(kindSelect, d.kind); setValue(dateInput, d.date); setValue(dueInput, d.dueDate); diff --git a/web/src/ui/views/masters.ts b/web/src/ui/views/masters.ts index 3d072c8..0324a03 100644 --- a/web/src/ui/views/masters.ts +++ b/web/src/ui/views/masters.ts @@ -84,6 +84,21 @@ function mountMaster(m: Master, host: HTMLElement, ctx: ViewContext): { show(): if (fresh.disabled === ok) fresh.disabled = !ok; }; + const place = (row: Row) => { + const tr = listHost.querySelector(`tr[data-key="${CSS.escape(String(row.id))}"]`); + const body = tr?.parentElement; + if (!tr || !body) return; + const code = String(row.code ?? ""); + for (const other of body.children) { + if (other === tr) return; + const text = other.firstElementChild?.textContent ?? ""; + if (text.localeCompare(code, undefined, { numeric: true }) > 0) { + body.insertBefore(tr, other); + return; + } + } + }; + let saving = false; const submit = async () => { if (saving || !allowed()) return; @@ -100,8 +115,10 @@ function mountMaster(m: Master, host: HTMLElement, ctx: ViewContext): { show(): save.disabled = true; setText(error, ""); try { + const isNew = !current; const row = current ? await update(ctx.api, m, String(current.id), built.body) : await create(ctx.api, m, built.body); table.patchRow(row); + if (isNew) place(row); fill(row); } catch (e) { setText(error, e instanceof ApiError ? e.message : "The change could not be saved."); diff --git a/web/src/ui/views/payments.ts b/web/src/ui/views/payments.ts index a1e2a5e..c6dc920 100644 --- a/web/src/ui/views/payments.ts +++ b/web/src/ui/views/payments.ts @@ -27,6 +27,7 @@ import { type PaymentDraft, } from "../../engine/payments"; import { delayedIndicator, h, setAttr, setText } from "../dom"; +import { mountPicker } from "../parts/picker"; import { mountTable } from "../parts/table"; import type { ViewContext, ViewDef } from "../views"; @@ -120,8 +121,7 @@ function field(label: string, control: HTMLElement): HTMLElement { function mountForm(dir: PayDir, host: HTMLElement, ctx: ViewContext): (params: URLSearchParams) => void { const f: PayFamily = FAMILIES[dir]; const formId = dir === "in" ? "payment-in" : "payment-out"; - const party = h("select", { class: "input" }); - party.append(h("option", { attrs: { value: "" }, text: "Choose" })); + const partyHost = h("div", { class: "pay__picker" }); const date = h("input", { class: "input", attrs: { type: "date" } }); const amount = h("input", { class: "input pay__num", attrs: { inputmode: "decimal", autocomplete: "off" } }); const account = h("select", { class: "input" }); @@ -133,7 +133,7 @@ function mountForm(dir: PayDir, host: HTMLElement, ctx: ViewContext): (params: U const grid = h( "div", { class: "pay__grid" }, - field(dir === "in" ? "Customer" : "Supplier", party), + h("div", { class: "field pay__field" }, h("span", { class: "field__label", text: dir === "in" ? "Customer" : "Supplier" }), partyHost), field("Date", date), field("Amount", amount), field(dir === "in" ? "Deposit to" : "Paid from", account), @@ -182,6 +182,13 @@ function mountForm(dir: PayDir, host: HTMLElement, ctx: ViewContext): (params: U const error = h("p", { class: "form__error pay__error", attrs: { role: "alert" } }); const root = h("div", { class: "pay pay--form panel", attrs: { "data-status": "new" } }, head, grid, h("h2", { class: "panel__title pay__sub", text: "Allocation" }), allocBox, error, actions); host.append(root); + const party = mountPicker(partyHost, ctx, { + kind: f.partyKey, + label: dir === "in" ? "Customer" : "Supplier", + required: true, + onPick: () => onParty(), + }); + const partyCode = (): string => party.get()?.code ?? ""; const rows = new Map(); const parties = new Map(); @@ -274,23 +281,28 @@ function mountForm(dir: PayDir, host: HTMLElement, ctx: ViewContext): (params: U r.el.remove(); rows.delete(id); } - setText(allocEmpty, list.length ? "" : party.value ? "No open invoices for this party." : "Choose a party to see open invoices."); + setText(allocEmpty, list.length ? "" : partyCode() ? "No open invoices for this party." : "Choose a party to see open invoices."); setAttr(allocBox, "data-empty", list.length ? null : "true"); writeRemainder(); }; + let loadSeq = 0; + let loadedFor: string | null = null; const loadInvoices = async (p: Payment | null) => { - const who = parties.get(party.value); + const mine = ++loadSeq; + const who = parties.get(partyCode()); if (!who) { + loadedFor = ""; setAllocRows([], p); return; } - const mine = seq; try { const inv = await openInvoices(ctx.api, f, who.id); - if (mine === seq) setAllocRows(inv, p); + if (mine !== loadSeq) return; + loadedFor = who.code; + setAllocRows(inv, p); } catch (e) { - if (mine === seq) fail(e); + if (mine === loadSeq) fail(e); } }; @@ -306,14 +318,16 @@ function mountForm(dir: PayDir, host: HTMLElement, ctx: ViewContext): (params: U cancel.disabled = st !== "posted" || !canPost; save.hidden = !canDraft; post.hidden = allocate.hidden = cancel.hidden = !canPost; - for (const c of [party, date, amount, account, memo]) c.disabled = !draft || !canDraft; + party.setDisabled(!draft || !canDraft); + for (const c of [date, amount, account, memo]) c.disabled = !draft || !canDraft; setText(number, current?.number ?? (current ? "Draft" : "New payment")); setText(status, st === "new" ? "" : st); }; const fill = (p: Payment | null) => { current = p; - party.value = p ? (parties.has(p.party) ? p.party : "") : ""; + const pp = p ? parties.get(p.party) : undefined; + if (partyCode() !== (pp?.code ?? "")) party.set(pp ? { id: pp.id, code: pp.code, name: pp.name, record: {} } : null); date.value = p?.date ?? today(); amount.value = p ? money(p.amount) : ""; account.value = p?.account ?? ""; @@ -329,7 +343,7 @@ function mountForm(dir: PayDir, host: HTMLElement, ctx: ViewContext): (params: U setText(error, "Enter an amount greater than zero."); return null; } - return { party: party.value, date: date.value, amount: amt, account: account.value, memo: memo.value.trim() }; + return { party: partyCode(), date: date.value, amount: amt, account: account.value, memo: memo.value.trim() }; }; const allocList = (): AllocationInput[] => [...entered()].map(([invoice, amt]) => ({ invoice, amount: amt })); @@ -389,18 +403,20 @@ function mountForm(dir: PayDir, host: HTMLElement, ctx: ViewContext): (params: U }), ); amount.addEventListener("input", writeRemainder); - party.addEventListener("change", () => { - seq++; + function onParty(): void { + const code = partyCode(); + if (code && !parties.has(code)) { + const g = party.get(); + if (g) parties.set(code, { id: g.id, code, name: g.name, currency: "" }); + } + if (loadedFor === code) return; for (const r of rows.values()) r.input.value = ""; void loadInvoices(current); - }); + } const ready = (async () => { const [ps, accts] = await Promise.all([listParties(ctx.api, f), listAssetAccounts(ctx.api)]); - for (const p of ps) { - parties.set(p.code, p); - party.append(h("option", { attrs: { value: p.code }, text: `${p.code} ${p.name}` })); - } + for (const p of ps) parties.set(p.code, p); for (const a of accts) account.append(h("option", { attrs: { value: a.code }, text: `${a.code} ${a.name}` })); })().catch(fail); diff --git a/web/src/ui/views/statements.ts b/web/src/ui/views/statements.ts index e435fb9..7932a85 100644 --- a/web/src/ui/views/statements.ts +++ b/web/src/ui/views/statements.ts @@ -2,9 +2,9 @@ import { ApiError } from "../../engine"; import { money, today } from "../../engine/format"; import { balanceSheet, + fiscalStart, profitAndLoss, resultLabel, - yearStart, type StatementLine, type StatementSection, } from "../../engine/statements"; @@ -138,6 +138,7 @@ function profitAndLossView(): ViewDef { let refresh: () => void = () => undefined; const from = dateInput("from"); const to = dateInput("to"); + let startSeq = 0; return { id: "profit-and-loss", title: "Profit and loss", @@ -167,8 +168,21 @@ function profitAndLossView(): ViewDef { show(params) { const day = params.get("to") || today(); to.value = day; - from.value = params.get("from") || yearStart(day); - refresh(); + const given = params.get("from"); + if (given) { + from.value = given; + refresh(); + return; + } + const mine = ++startSeq; + from.value = ""; + const api = ctx?.api; + if (!api) return; + void fiscalStart(api, day).then((start) => { + if (mine !== startSeq) return; + from.value = start; + refresh(); + }); }, }; }