diff --git a/CHANGELOG.md b/CHANGELOG.md index e76b302..65d8bd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 0.13.9 + +Every printable document has a FormTxt template, document lines are tighter and add up as you type, and the window tells the owner to back up the key. + +### New +- **FormTxt templates for every printable document:** quote, sales order, invoice, purchase order, purchase invoice, goods receipt and statement, each in Letter and A4. `formledger formtxt-template KIND` writes one, `--a4` picks A4, and `formledger formtxt-template --all --out DIR` writes all 14. Open them once in FormTxt and FormLedger finds each by its name. +- **Key backup notice:** when FormLedger made the key itself, as the desktop app does, the owner sees a notice saying the books are encrypted, where the key file is and that losing it loses the books, until they press "I have backed up the key". Setup always shows whether the books are encrypted, where the key is and whether it is backed up. + +### Improved +- **Document lines are 30 pixels tall,** down from 47, with no empty band under each line. A line's error shows as a small tag on the line and moves nothing. +- **Removing a line** no longer moves the lines below it. + +### Changed +- **FormTxt pages follow the plain page's size:** Letter for USD, A4 for other currencies. + +### Fixed +- A document started from a template showed no amounts and totals of 0.00 until it was saved. Amounts, subtotal, tax and total now show as soon as the lines appear and as you type. +- The goods receipt template was looked up under a name that did not match `FORMLEDGER_FORMTXT_TEMPLATE_GOODS_RECEIPT`. + +### Known issues +- You still open the template files in FormTxt yourself; FormTxt gives an outside program no way to add a document. +- The plain renderer has no delivery note or payment receipt, so neither has a template. +- Reading the snapshot from FormCel's window was not checked for this version. + +### Under the hood +- The desktop app was compiled on Linux for the first time and opened on a virtual display: it started the server, made its key once, kept using it on the second start, and the ledger file was not readable as a plain database. Dashboards were checked with a currency that has no minor unit. Not run: the packaged app on macOS or Windows. + ## 0.13.0 FormLedger ships its own FormTxt templates, and a document started from a template shows where each line posts. diff --git a/Makefile b/Makefile index d0d25cb..abf72f1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := v0.13.0 +VERSION := v0.13.9 GO_BUILD := CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" .PHONY: build web server check clean diff --git a/README.md b/README.md index b624d1d..3badee2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@

- version v0.13.0 + version v0.13.9 Go 1.26+ TypeScript and Vite License: Apache-2.0 diff --git a/cmd/HASHOUT_LOG.md b/cmd/HASHOUT_LOG.md index 76d6020..26cf313 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.13.0 +Current build version: v0.13.9 Last updated: 2026-11-26 (US Eastern) · skeleton port from form.md --- diff --git a/cmd/formledger/main.go b/cmd/formledger/main.go index e568413..104ba43 100644 --- a/cmd/formledger/main.go +++ b/cmd/formledger/main.go @@ -212,7 +212,7 @@ func usage(w io.Writer) { fmt.Fprintln(w, " serve run the server (default)") fmt.Fprintln(w, " cli ledger commands against the running server (formledger cli --help)") fmt.Fprintln(w, " report snapshot write a plain read-only SQLite snapshot (--out FILE, --force; server stopped)") - fmt.Fprintln(w, " formtxt-template write FormLedger's invoice (or statement) template for FormTxt (--out FILE, default formledger-KIND.ftxt)") + fmt.Fprintln(w, " formtxt-template write FormLedger's FormTxt template for KIND (quote, order, invoice, purchase-order, purchase-invoice, goods-receipt, statement; --a4 for non-USD pages; --out FILE), or --all --out DIR for every kind in both sizes") fmt.Fprintln(w, " keygen print a new at-rest encryption key") fmt.Fprintln(w, " encrypt encrypt an existing plain ledger with FORMLEDGER_KEY_FILE (server stopped)") fmt.Fprintln(w, " version print the version") diff --git a/docs/ENCRYPTION.md b/docs/ENCRYPTION.md index 25a0f1a..b318f25 100644 --- a/docs/ENCRYPTION.md +++ b/docs/ENCRYPTION.md @@ -75,6 +75,8 @@ The key is one line of 64 hex characters, so it can be kept as text: Back the key up again only if you replace it; it never changes on its own. Every backup of the books (`~/FormLedger`) needs that key to open. +**The window tells the owner.** When the server made the key itself (`FORMLEDGER_KEY_HOME`, the desktop app) and the owner has not yet confirmed a backup, the owner sees a notice at the bottom of the window: the books are encrypted, the key file's path, that losing it loses the books, and how to back it up. It stays until the owner presses "I have backed up the key", which calls `POST /api/me/key-backed-up`; the server then writes `formledger.key.backed-up` (the time of the confirmation) beside the key, and the notice never shows again. Delete that file to see the notice again. The Setup hub always lists the same facts under Encryption: encrypted or not, the key file and whether a backup was confirmed. Only the owner sees either, and only the key's path is sent to the window, never the key. With your own `FORMLEDGER_KEY_FILE` there is no notice: you made the key, so its backup is yours. (In this build the route line in `internal/auth/module.go` and the notice's mount in `web/src/ui/app.ts` are with their owners; both were run and checked in a private copy.) + ## Turning it on for an existing ledger A key given to a plain ledger is refused, so a plain ledger is never opened as if it were encrypted: diff --git a/docs/PRINT.md b/docs/PRINT.md index 2527748..c0c56a2 100644 --- a/docs/PRINT.md +++ b/docs/PRINT.md @@ -25,7 +25,7 @@ The same document gives the same bytes every time: the PDF's creation and change ## The page -Letter for documents in USD, A4 for every other currency; there is no page size setting yet. The page carries the company name (the instance name), the document kind, number, date, due date, currency and status, the customer or supplier, a line table (item, description, quantity, unit price, tax rate, amount before tax) whose header repeats on every page and whose rows wrap, the subtotal, tax and total from the document itself, the notes, and "Page N of M". Drafts carry "DRAFT" and cancelled documents "CANCELLED" across every page. Amounts use the app's own money formatting with thousands separators. +Letter for documents in USD, A4 for every other currency; there is no page size setting yet. A page FormTxt draws follows the same rule (see Page size under FormTxt). The page carries the company name (the instance name), the document kind, number, date, due date, currency and status, the customer or supplier, a line table (item, description, quantity, unit price, tax rate, amount before tax) whose header repeats on every page and whose rows wrap, the subtotal, tax and total from the document itself, the notes, and "Page N of M". Drafts carry "DRAFT" and cancelled documents "CANCELLED" across every page. Amounts use the app's own money formatting with thousands separators. ## Fonts and characters @@ -39,20 +39,42 @@ Rendering goes through a list of renderers, each of which draws a document and a - It finds FormTxt the way FormTxt's own tools do (`setup/report.py`, `setup/catalogue.py`): the engine at `http://127.0.0.1:$FORMTXT_ENGINE_PORT`, port `8210` when unset. There is no discovery file. - It posts to `/api/reports/run` with the data as `records` (one record per line, the document's header fields repeated on each: `company`, `title`, `number`, `date`, `dueDate`, `customer`, `customerName`, `supplier`, `supplierName`, `currency`, `status`, `memo`, `subtotal`, `taxTotal`, `total`, then `item`, `description`, `quantity`, `unitPrice`, `taxRate`, `lineSubtotal`; a statement's are `customer`, `customerName`, `currency`, `from`, `to`, `opening`, `closing`, then `lineDate`, `event`, `reference`, `debit`, `credit`, `balance`), `mode` `list`, `format` `pdf`, and `out` a file in a fresh temporary folder that it reads back and removes. Amounts arrive formatted, as on the plain page. -- The template is a FormTxt document. FormLedger ships one for invoices (below). When `FORMLEDGER_FORMTXT_TEMPLATE_INVOICE` is unset, FormLedger reads FormTxt's document list (`GET /api/documents`, a read FormTxt answers any local caller) and uses the newest document titled `FormLedger invoice template`. A set id always wins, per kind: `FORMLEDGER_FORMTXT_TEMPLATE_INVOICE`, `_QUOTE`, `_ORDER`, `_PURCHASE_ORDER`, `_PURCHASE_INVOICE`, `_GOODS_RECEIPT`, `_STATEMENT`. Any other kind with no id set goes to the plain renderer. +- The template is a FormTxt document. FormLedger ships one for every printable kind (below). When the kind's `FORMLEDGER_FORMTXT_TEMPLATE_*` is unset, FormLedger reads FormTxt's document list (`GET /api/documents`, a read FormTxt answers any local caller) and uses the newest document with the kind's exact title for the document's page size, for example `FormLedger invoice template` for a USD invoice and `FormLedger invoice template (A4)` for a EUR one. A set id always wins, per kind: `FORMLEDGER_FORMTXT_TEMPLATE_INVOICE`, `_QUOTE`, `_ORDER`, `_PURCHASE_ORDER`, `_PURCHASE_INVOICE`, `_GOODS_RECEIPT`, `_STATEMENT`; FormLedger then uses that document whatever its page size. - Any failure (no engine, a refusal, a timeout of 13 seconds, a file that is not a PDF) goes to the plain renderer. When FormTxt answered but did not draw, the response carries the reason in `X-FormLedger-Renderer-Note` (path-escaped) and `cli print` writes it on standard error under the renderer line. A 403 reads: `FormTxt refused to draw the page, so FormLedger drew the plain page. FormTxt said: No FormTxt window is open. Start it with ./formtxt and open the app, then retry. Open FormTxt, allow outside agents when it asks, or turn on Allow outside agents in its Preferences under Privacy, then print again.` A template id FormTxt does not hold (404) names the environment variable to set. The wait is 13 seconds, the owner's choice: a person who has not answered FormTxt's question by then gets the plain page and prints again after answering. FormTxt itself waits up to 180 seconds for the answer and withdraws the question when FormLedger hangs up. -### The shipped invoice template +### The shipped templates + +| Kind | Title (Letter, for USD) | Data file | What it adds to the invoice layout | +| --- | --- | --- | --- | +| `quote` | `FormLedger quote template` | `formtxt_quote.json` | "Quote for" the customer; the due date reads "Valid until" | +| `order` | `FormLedger order template` | `formtxt_order.json` | sales order, "Bill to" the customer | +| `invoice` | `FormLedger invoice template` | `formtxt_invoice.json` | | +| `purchase-order` | `FormLedger purchase order template` | `formtxt_purchase_order.json` | "Supplier" name and code | +| `purchase-invoice` | `FormLedger purchase invoice template` | `formtxt_purchase_invoice.json` | "Supplier", and "Supplier ref" (`supplierRef`) | +| `goods-receipt` | `FormLedger goods receipt template` | `formtxt_goods_receipt.json` | "Received from" the supplier, "Supplier ref", no due date, lines with item, description and quantity only, no amounts | +| `statement` | `FormLedger statement template` | `formtxt_statement.json` | | + +Each data file is FormLedger's own, in FormTxt's `.ftxt` document format, embedded in the binary under `internal/printout/`. The records FormLedger sends now also carry `supplierRef`. A delivery note and a payment receipt are not printable kinds (the plain renderer draws only the kinds in the table at the top), so no template ships for them. + +`./formledger formtxt-template KIND [--a4] [--out FILE]` writes one kind (default `invoice`, file `formledger-KIND.ftxt`, or `formledger-KIND-a4.ftxt` with `--a4`). `./formledger formtxt-template --all --out DIR` writes all 14 files, every kind in both sizes. + +### Page size + +FormTxt's `/api/reports/run` takes no page size (its fields are `template`, `data`, `mode`, `groupBy`, `format`, `out`, `overwrite`, `title`); the size is the template's own section page. So each kind ships in two sizes made from one data file: the file holds the Letter page (612 by 792 points), and `--a4` writes the same document with an A4 page (595.28 by 841.89 points), side margins of 51.64 points so the tables keep their 492 point width, and ` (A4)` added to the title. FormLedger asks FormTxt for the title that matches the plain page's rule: Letter for USD, A4 for every other currency, for documents and statements alike. A person who prints only in USD opens only the Letter files and never sees the A4 ones, and the reverse; only someone who prints in both opens both. When the matching size is not in FormTxt, the plain page is drawn (in the right size) with the note `FormTxt holds no document named FormLedger invoice template (A4), so FormLedger drew the plain page. Run ./formledger formtxt-template invoice --a4, ...`. FormLedger never uses a template of the other size, so a FormTxt page is never a different size than the plain page would be. + +**Run on 2026-11-27 against FormTxt 0.38.0** (a copy on port 8901 with its own data folder, window in headless Chrome; FormLedger 0.13.9 work on 8801, seeded with `fl_exit.py --seed`, no `FORMLEDGER_FORMTXT_TEMPLATE_*` set). One draft of each kind was made through the API (quote, sales order, invoice for ACME; purchase order, purchase invoice and goods receipt for a supplier NORD with supplier ref NP-4471; an invoice in EUR for a EUR customer) and printed by id with `cli print`. Before the templates were in FormTxt each printed plain with the missing-template note (the EUR invoice's note named the `(A4)` title). After the 14 files from `--all` were opened through File > Open or import file and Always allow was clicked once, all eight prints (the seven kinds plus the EUR invoice) were drawn by FormTxt in 0.28 to 0.88 seconds. Page sizes: every USD document and the statement 612 by 792 points (Letter), the EUR invoice 595.28 by 841.89 points (A4), the same as the plain renderer gave for each. The statement had no rows because nothing was posted. + +### How the template is used FormLedger carries an invoice template as its own data, written in FormTxt's `.ftxt` document format (`internal/printout/formtxt_invoice.json`, embedded in the binary). It is titled `FormLedger invoice template` and holds the company name, the document title and number, date, due date, currency and status, the bill-to customer name and code, a line table whose header row repeats on every page and whose second row is marked to repeat once per line (`item`, `description`, `quantity`, `unitPrice` as Rate, `taxRate`, `lineSubtotal` as Amount), then subtotal, tax, total with the currency, the notes, and "Page N of M" in the footer. A statement template ships the same way (`internal/printout/formtxt_statement.json`, titled `FormLedger statement template`, written by `./formledger formtxt-template statement`): company, period, customer name and code, currency, opening balance, one repeating row per event (`lineDate`, `event`, `reference`, `debit`, `credit`, `balance`) and the closing balance. With no `from` the heading reads "Statement to" and the end date. The two lookups are separate, so each kind uses its template once it is in FormTxt. FormLedger does not put the template into FormTxt by itself. FormTxt gives an outside program no way to create a document: every write but `/mcp` and `/api/reports/run` needs the key only FormTxt's own window holds for that launch, `/mcp` runs the window's editing commands (none of which types text or opens a file from a path), and `/api/reports/run` merges into a document that must already be in FormTxt's library. Taking the window's key from its session storage, or writing into FormTxt's data folder, would get past FormTxt's consent, so FormLedger does neither. The person adds it once: -1. Run `./formledger formtxt-template` (or `--out FILE`). It writes `formledger-invoice.ftxt` and names the full path. +1. Run `./formledger formtxt-template KIND` (add `--a4` for documents not in USD), or `--all --out DIR` for every kind in both sizes. It writes `formledger-KIND.ftxt` and names the full path and the title. 2. In the FormTxt window, choose File > Open or import file and pick that file. FormTxt adds it to its library as `FormLedger invoice template`. Set `FORMTXT_ENGINE_PORT` in FormLedger's server environment when FormTxt is not on 8210; no template id is needed. 3. Print once with the window open. FormTxt asks **Allow an outside agent to make changes in FormTxt?**, naming the temporary file it will write, with Deny, Allow once and Always allow all outside agents. Answer within 13 seconds, or print again after answering. Always allow saves `agentsAllowed` in FormTxt's own `settings.json` in its data folder (not the system password store), so later prints draw with no window open. Allow once lets that one print through without saving the answer (read from FormTxt's `consent`, not tried here). -Until step 2 is done, printing goes to the plain renderer with the note: `FormTxt holds no document named FormLedger invoice template, so FormLedger drew the plain page. Run ./formledger formtxt-template, open the file it writes in FormTxt with File > Open or import file, then print again.` +Until step 2 is done, printing goes to the plain renderer with the note: `FormTxt holds no document named FormLedger invoice template, so FormLedger drew the plain page. Run ./formledger formtxt-template invoice, open the file it writes in FormTxt with File > Open or import file, then print again.` **Run on 2026-11-27 against FormTxt 0.38.0** (a copy with its own engine on port 8701 and data folder, its window built from its own frontend and opened in headless Chrome; FormLedger's server had no `FORMLEDGER_FORMTXT_TEMPLATE_*` variable set). On the fresh FormTxt library, `cli print invoice SI-2026-000001` printed plain in 0.32 seconds with the note above. The file from `formledger formtxt-template` was then opened through File > Open or import file; the next print raised FormTxt's question, Always allow was clicked 2.15 seconds in, and the page was drawn by FormTxt from the shipped template in 2.87 seconds (`printed by the formtxt renderer`): every field, the three lines, subtotal 68.13, tax 5.45 and total USD 73.58 were filled. With the window open but the question left unanswered, FormLedger gave up after 13.13 seconds and printed plain with the 13 second note. With FormTxt's engine stopped it printed plain in 0.35 seconds, since nothing answered on the port. Then `cli print statement ACME` printed plain with the statement note, the statement file was opened the same way, and the next statement print was drawn by FormTxt in 0.20 seconds with outside agents already allowed. FormTxt's report route also keeps each merged result in its own library (here `Invoice SI-2026-000001`); that is FormTxt's behavior and FormLedger does not remove it. diff --git a/internal/HASHOUT_LOG.md b/internal/HASHOUT_LOG.md index 474308f..668e73a 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.13.0 +Current build version: v0.13.9 Last updated: 2026-11-27 (US Eastern) · profit and loss and the balance sheet --- @@ -1882,3 +1882,17 @@ Run against a copy of FormTxt 0.38.0 (engine on 8504, its window built from its - logged: v0.13.0 · 2026-11-27 The owner chose a 13 second wait (down from 100) and a shipped template. The template is FormLedger's own data in FormTxt's `.ftxt` format (docs/FORMAT.md in FormTxt): `document.json` is embedded and packed on demand with `mimetype` stored first, as the format requires, with zip times fixed at 1970 so the file is the same bytes every run. FormTxt gives outside programs no create route: every write but `/mcp` and `/api/reports/run` needs the window's per-launch key, and none of the window commands `/mcp` runs types text or opens a path. So FormLedger never creates the document; the person opens the file once with File > Open or import file, and `findShipped` matches the exact title on FormTxt's open `GET /api/documents` (newest `modified` wins, so a re-import replaces an older copy without clearing it). A set `FORMLEDGER_FORMTXT_TEMPLATE_*` id still wins, and only `invoice` has a shipped title; the list read shares the 13 second limit. Ids in the JSON are FormTxt-style prefixes with 4 or more letters because the format says so, though the merge re-ids every block. Proven on 2026-11-27 against FormTxt 0.38.0 on port 8701: plain with the missing-template note before import, FormTxt-drawn after import and Always allow (2.87 s), plain after 13.13 s with the question unanswered, plain in 0.35 s with the engine stopped. + +### internal/printout/template.go · a FormTxt template per kind, sized by currency +- refers-to: internal/printout/template.go :: shipped, shippedOrder, templateTitle, sized, Template, TemplateCommand, writeTemplate, findShipped; internal/printout/formtxt.go :: Render, Statement, run; internal/printout/formtxt_quote.json, formtxt_order.json, formtxt_purchase_order.json, formtxt_purchase_invoice.json, formtxt_goods_receipt.json +- kind: rationale +- logged: v0.13.9 · 2026-11-27 + +FormTxt 0.38.0's `/api/reports/run` has no page size field, so the size lives in the template's section. One data file per kind holds the Letter page; `sized` makes the A4 twin at write time (page 595.28 by 841.89, side margins 51.64 so the 492 point tables still fit, title plus ` (A4)`, id plus `a4`), which keeps seven data files instead of fourteen. `run` takes `PageSize(currency)` from plain.go and `findShipped` asks only for the title of that size, never the other, so FormTxt cannot draw a page of a different size than the plain renderer; a missing size falls to plain with a note naming `--a4`. The purchase receipt used to look up `purchase-receipt`, which matched neither the print kind nor the documented `FORMLEDGER_FORMTXT_TEMPLATE_GOODS_RECEIPT`; it is now `goods-receipt`. Records carry `supplierRef` for the purchase invoice and goods receipt. Proven on 2026-11-27 against FormTxt 0.38.0 on 8901 with all eight prints drawn by FormTxt: USD pages 612 by 792, the EUR invoice 595.28 by 841.89. + +### internal/crypt/home.go, internal/auth/keynotice.go, internal/auth/users.go · the owner learns where the made key is +- refers-to: internal/crypt/home.go :: HomeState, HomeStatus, ConfirmHomeBackup, HomeBackedUpName; internal/auth/keynotice.go :: keyState, handleKeyBackedUp; internal/auth/users.go :: meBody.Key, me +- kind: rationale +- logged: v0.13.9 · 2026-11-27 + +The lost-key warning was only in the log. `/api/me` now carries `key` for the owner role only: encrypted, `madeHere` (the key is the one `EnsureHome` made in `FORMLEDGER_KEY_HOME` and no `FORMLEDGER_KEY_FILE` or credential overrides it), the path, and `backedUp`. The key itself never leaves the server. The confirmation is a file beside the key, `formledger.key.backed-up`, not a row in the database: it belongs to that key on that computer, survives a fresh data folder that reuses the key, and is gone if the key folder is replaced. `keyState` reads `config.Load` rather than threading the config through `Service`, because `server.go` builds the service and is not this slice's file; in desktop mode that also mints an unused window key per call, which is harmless. The route `POST /api/me/key-backed-up` (Session, owner checked in the handler) needs one line in `internal/auth/module.go`, with its owner. Run in a private copy with that line, started as the desktop shell does (`FORMLEDGER_DESKTOP=1 FORMLEDGER_KEY_HOME=/tmp/P3/appdata`, signed in through `/desktop/enter`): `key` read encrypted, madeHere, the path, not backed up; the confirm answered 200 and wrote the marker; a reload read backed up. With no key home, `key` read not encrypted and no path. diff --git a/internal/app/version.go b/internal/app/version.go index c346089..eca3e1c 100644 --- a/internal/app/version.go +++ b/internal/app/version.go @@ -1,5 +1,5 @@ package app -var Version = "v0.13.0" +var Version = "v0.13.9" const Product = "FormLedger" diff --git a/internal/auth/keynotice.go b/internal/auth/keynotice.go new file mode 100644 index 0000000..607b993 --- /dev/null +++ b/internal/auth/keynotice.go @@ -0,0 +1,37 @@ +package auth + +import ( + "net/http" + + "github.com/nodemode-ai/formledger/internal/config" + "github.com/nodemode-ai/formledger/internal/crypt" + "github.com/nodemode-ai/formledger/internal/httpx" + "github.com/nodemode-ai/formledger/internal/policy" +) + +func keyState() *crypt.HomeState { + cfg, err := config.Load() + if err != nil { + return nil + } + st := crypt.HomeStatus(cfg.DataDir, cfg.KeyFile, cfg.KeyHome) + return &st +} + +func (s *Service) handleKeyBackedUp(w http.ResponseWriter, r *http.Request, p *policy.Principal) error { + if p.Role != policy.Owner { + return httpx.Fail(http.StatusForbidden, "owner_only", "only the owner can confirm the key backup") + } + cfg, err := config.Load() + if err != nil { + return err + } + if crypt.KeyPath(cfg.KeyFile) != "" { + return httpx.Fail(http.StatusConflict, "own_key", "this ledger uses a key file you gave it") + } + if err := crypt.ConfirmHomeBackup(cfg.KeyHome); err != nil { + return httpx.Fail(http.StatusConflict, "no_home_key", "this ledger has no key made by FormLedger") + } + s.log.Info("the owner confirmed the key is backed up", "user", p.UserID) + return s.handleMe(w, r, p) +} diff --git a/internal/auth/module.go b/internal/auth/module.go index 8aee02f..f53cac1 100644 --- a/internal/auth/module.go +++ b/internal/auth/module.go @@ -22,6 +22,7 @@ func (m module) Mount(r *httpx.Router, _ *app.Deps) error { r.HandleFunc("POST /api/auth/logout", s.Public(s.handleLogout)) r.HandleFunc("GET /api/me", s.Signed(s.handleMe)) + r.HandleFunc("POST /api/me/key-backed-up", s.Session(s.handleKeyBackedUp)) r.HandleFunc("POST /api/account/claim", s.Session(s.handleClaim)) r.HandleFunc("POST /api/account/lock", s.Require(policy.SettingsManage, s.handleLock)) r.HandleFunc("GET /api/me/tokens", s.Session(s.handleListTokens)) diff --git a/internal/auth/users.go b/internal/auth/users.go index b9be29e..08c2da0 100644 --- a/internal/auth/users.go +++ b/internal/auth/users.go @@ -10,6 +10,7 @@ import ( "unicode/utf8" "github.com/nodemode-ai/formledger/internal/audit" + "github.com/nodemode-ai/formledger/internal/crypt" "github.com/nodemode-ai/formledger/internal/httpx" "github.com/nodemode-ai/formledger/internal/ids" "github.com/nodemode-ai/formledger/internal/policy" @@ -103,6 +104,7 @@ type meBody struct { Desktop bool `json:"desktop"` ClaimRequired bool `json:"claimRequired"` AppLock bool `json:"appLock"` + Key *crypt.HomeState `json:"key,omitempty"` } func (s *Service) me(ctx context.Context, p *policy.Principal) (*meBody, error) { @@ -115,6 +117,9 @@ func (s *Service) me(ctx context.Context, p *policy.Principal) (*meBody, error) return nil, err } body := &meBody{User: p, Can: []policy.Action{}, Desktop: s.Desktop(), ClaimRequired: claim, AppLock: locked} + if p.Role == policy.Owner { + body.Key = keyState() + } for _, a := range policy.AllActions { if policy.Can(p, a) { body.Can = append(body.Can, a) diff --git a/internal/crypt/home.go b/internal/crypt/home.go index 03823f6..02b9b9a 100644 --- a/internal/crypt/home.go +++ b/internal/crypt/home.go @@ -4,6 +4,7 @@ import ( "errors" "os" "path/filepath" + "time" ) const HomeKeyName = "formledger.key" @@ -35,4 +36,43 @@ func EnsureHome(dir string) (string, bool, error) { return path, true, nil } +const HomeBackedUpName = "formledger.key.backed-up" + +type HomeState struct { + Encrypted bool `json:"encrypted"` + MadeHere bool `json:"madeHere"` + Path string `json:"path,omitempty"` + BackedUp bool `json:"backedUp"` +} + +func HomeStatus(dataDir, keyFile, keyHome string) HomeState { + st := HomeState{Encrypted: Encrypted(dataDir)} + if configured := KeyPath(keyFile); configured != "" { + st.Path = configured + st.BackedUp = true + return st + } + if keyHome == "" { + return st + } + path := filepath.Join(keyHome, HomeKeyName) + if _, err := os.Stat(path); err != nil { + return st + } + st.MadeHere, st.Path = true, path + _, err := os.Stat(filepath.Join(keyHome, HomeBackedUpName)) + st.BackedUp = err == nil + return st +} + +func ConfirmHomeBackup(keyHome string) error { + if keyHome == "" { + return errors.New("this ledger has no key made by FormLedger") + } + if _, err := os.Stat(filepath.Join(keyHome, HomeKeyName)); err != nil { + return err + } + return os.WriteFile(filepath.Join(keyHome, HomeBackedUpName), []byte(time.Now().UTC().Format(time.RFC3339)+"\n"), 0o600) +} + const LossWarning = "Losing the key loses the books: without it nobody can read this ledger, not even you. Back the key file up now to a password manager or an offline drive." diff --git a/internal/printout/formtxt.go b/internal/printout/formtxt.go index b5f4ca4..2e84c09 100644 --- a/internal/printout/formtxt.go +++ b/internal/printout/formtxt.go @@ -35,10 +35,13 @@ func (f formtxt) Render(d *Document) ([]byte, error) { kind := d.Kind if d.Side == "purchase" { kind = "purchase-" + d.Kind + if d.Kind == "receipt" { + kind = "goods-receipt" + } } head := map[string]any{ "company": d.Company, "title": d.Title(), "number": d.Number, "date": d.Date, "dueDate": d.DueDate, - "customer": d.Customer, "customerName": d.CustomerName, "supplier": d.Supplier, "supplierName": d.SupplierName, + "customer": d.Customer, "customerName": d.CustomerName, "supplier": d.Supplier, "supplierName": d.SupplierName, "supplierRef": d.SupplierRef, "currency": d.Currency, "status": d.Status, "memo": d.Memo, "subtotal": amount(d.Subtotal, d.Currency), "taxTotal": amount(d.TaxTotal, d.Currency), "total": amount(d.Total, d.Currency), } @@ -54,7 +57,7 @@ func (f formtxt) Render(d *Document) ([]byte, error) { if len(rows) == 0 { rows = append(rows, head) } - return f.run(kind, d.Title()+" "+d.Number, rows) + return f.run(kind, PageSize(d.Currency), d.Title()+" "+d.Number, rows) } func (f formtxt) Statement(s *Statement) ([]byte, error) { @@ -74,16 +77,16 @@ func (f formtxt) Statement(s *Statement) ([]byte, error) { if len(rows) == 0 { rows = append(rows, head) } - return f.run("statement", "Statement "+s.Customer.Code, rows) + return f.run("statement", PageSize(s.Currency), "Statement "+s.Customer.Code, rows) } -func (formtxt) run(kind, title string, rows []map[string]any) ([]byte, error) { +func (formtxt) run(kind, size, title string, rows []map[string]any) ([]byte, error) { base, template := formtxtBase(), formtxtTemplate(kind) if base == "" { return nil, ErrUnavailable } if template == "" { - found, err := findShipped(base, kind) + found, err := findShipped(base, kind, size) if err != nil { return nil, err } diff --git a/internal/printout/formtxt_goods_receipt.json b/internal/printout/formtxt_goods_receipt.json new file mode 100644 index 0000000..d9a6e58 --- /dev/null +++ b/internal/printout/formtxt_goods_receipt.json @@ -0,0 +1,487 @@ +{ + "format": "ftxt", + "formatVersion": 1, + "id": "d_formledgergoodsreceipt", + "title": "FormLedger goods receipt template", + "meta": { + "author": "FormLedger", + "created": 0, + "modified": 0, + "subject": "FormLedger goods receipt", + "keywords": [ + "formledger" + ], + "language": "en-US" + }, + "settings": { + "pageless": false, + "defaultTab": 36.0, + "trackChanges": false, + "mailMerge": { + "source": "FormLedger", + "columns": [ + "company", + "title", + "number", + "date", + "dueDate", + "currency", + "status", + "memo", + "supplier", + "supplierName", + "supplierRef", + "item", + "description", + "quantity" + ], + "rows": [] + } + }, + "styles": { + "Normal": { + "type": "paragraph", + "name": "Normal", + "basedOn": null, + "next": "Normal", + "run": { + "font": "Inter", + "size": 10.0, + "color": "#1f2328" + }, + "para": { + "spaceBefore": 0.0, + "spaceAfter": 4.0, + "lineSpacing": 1.15, + "align": "left" + } + }, + "Title": { + "type": "paragraph", + "name": "Title", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 22.0, + "bold": true + }, + "para": { + "spaceAfter": 2.0 + } + }, + "Subtitle": { + "type": "paragraph", + "name": "Subtitle", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 14.0, + "color": "#57606a" + }, + "para": { + "spaceAfter": 14.0 + } + }, + "Heading3": { + "type": "paragraph", + "name": "Heading 3", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 9.0, + "bold": true, + "color": "#57606a", + "allCaps": true + }, + "para": { + "spaceBefore": 10.0, + "spaceAfter": 2.0, + "keepWithNext": true, + "outlineLevel": 3 + } + } + }, + "numbering": {}, + "sections": [ + { + "id": "sec_formledger", + "page": { + "size": "letter", + "width": 612.0, + "height": 792.0, + "orientation": "portrait" + }, + "margins": { + "top": 60.0, + "right": 60.0, + "bottom": 60.0, + "left": 60.0, + "header": 30.0, + "footer": 30.0, + "gutter": 0.0 + }, + "columns": { + "count": 1, + "gap": 36.0 + }, + "headers": {}, + "footers": { + "default": { + "text": "Page {PAGE} of {NUMPAGES}", + "align": "center" + } + }, + "titlePage": false, + "start": "nextPage" + } + ], + "tabs": [ + { + "id": "tab_formledger", + "title": "Goods receipt", + "parent": null, + "body": [ + { + "type": "paragraph", + "id": "p_company", + "style": "Title", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "company" + } + ] + }, + { + "type": "paragraph", + "id": "p_heading", + "style": "Subtitle", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "title" + }, + { + "type": "text", + "text": " " + }, + { + "type": "mergefield", + "name": "number" + } + ] + }, + { + "type": "table", + "id": "t_head", + "look": "plain", + "columns": [ + 246.0, + 246.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_billto", + "style": "Heading3", + "content": [ + { + "type": "text", + "text": "Received from" + } + ] + }, + { + "type": "paragraph", + "id": "p_custname", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "supplierName", + "marks": { + "bold": true + } + } + ] + }, + { + "type": "paragraph", + "id": "p_custcode", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Supplier " + }, + { + "type": "mergefield", + "name": "supplier" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_date", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Date ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "date" + } + ] + }, + { + "type": "paragraph", + "id": "p_supref", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Supplier ref ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "supplierRef" + } + ] + }, + { + "type": "paragraph", + "id": "p_currency", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Currency ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "currency" + } + ] + }, + { + "type": "paragraph", + "id": "p_status", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Status ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "status" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_space", + "style": "Normal", + "section": "sec_formledger", + "content": [] + }, + { + "type": "table", + "id": "t_lines", + "look": "rows", + "repeatHeader": true, + "columns": [ + 90.0, + 312.0, + 90.0 + ], + "rows": [ + { + "cells": [ + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hitem", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Item", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hdesc", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Description", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hqty", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Quantity", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + }, + { + "repeat": true, + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_item", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "item" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_desc", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "description" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_quantity", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "quantity" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_memo", + "style": "Normal", + "section": "sec_formledger", + "props": { + "spaceBefore": 14.0 + }, + "content": [ + { + "type": "mergefield", + "name": "memo" + } + ] + } + ] + } + ], + "notes": { + "footnotes": {}, + "endnotes": {} + }, + "comments": {}, + "media": {} +} \ No newline at end of file diff --git a/internal/printout/formtxt_order.json b/internal/printout/formtxt_order.json new file mode 100644 index 0000000..18c6d4c --- /dev/null +++ b/internal/printout/formtxt_order.json @@ -0,0 +1,794 @@ +{ + "format": "ftxt", + "formatVersion": 1, + "id": "d_formledgerorder", + "title": "FormLedger order template", + "meta": { + "author": "FormLedger", + "created": 0, + "modified": 0, + "subject": "FormLedger sales order", + "keywords": [ + "formledger" + ], + "language": "en-US" + }, + "settings": { + "pageless": false, + "defaultTab": 36.0, + "trackChanges": false, + "mailMerge": { + "source": "FormLedger", + "columns": [ + "company", + "title", + "number", + "date", + "dueDate", + "currency", + "status", + "memo", + "customer", + "customerName", + "subtotal", + "taxTotal", + "total", + "item", + "description", + "quantity", + "unitPrice", + "taxRate", + "lineSubtotal" + ], + "rows": [] + } + }, + "styles": { + "Normal": { + "type": "paragraph", + "name": "Normal", + "basedOn": null, + "next": "Normal", + "run": { + "font": "Inter", + "size": 10.0, + "color": "#1f2328" + }, + "para": { + "spaceBefore": 0.0, + "spaceAfter": 4.0, + "lineSpacing": 1.15, + "align": "left" + } + }, + "Title": { + "type": "paragraph", + "name": "Title", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 22.0, + "bold": true + }, + "para": { + "spaceAfter": 2.0 + } + }, + "Subtitle": { + "type": "paragraph", + "name": "Subtitle", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 14.0, + "color": "#57606a" + }, + "para": { + "spaceAfter": 14.0 + } + }, + "Heading3": { + "type": "paragraph", + "name": "Heading 3", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 9.0, + "bold": true, + "color": "#57606a", + "allCaps": true + }, + "para": { + "spaceBefore": 10.0, + "spaceAfter": 2.0, + "keepWithNext": true, + "outlineLevel": 3 + } + } + }, + "numbering": {}, + "sections": [ + { + "id": "sec_formledger", + "page": { + "size": "letter", + "width": 612.0, + "height": 792.0, + "orientation": "portrait" + }, + "margins": { + "top": 60.0, + "right": 60.0, + "bottom": 60.0, + "left": 60.0, + "header": 30.0, + "footer": 30.0, + "gutter": 0.0 + }, + "columns": { + "count": 1, + "gap": 36.0 + }, + "headers": {}, + "footers": { + "default": { + "text": "Page {PAGE} of {NUMPAGES}", + "align": "center" + } + }, + "titlePage": false, + "start": "nextPage" + } + ], + "tabs": [ + { + "id": "tab_formledger", + "title": "Sales order", + "parent": null, + "body": [ + { + "type": "paragraph", + "id": "p_company", + "style": "Title", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "company" + } + ] + }, + { + "type": "paragraph", + "id": "p_heading", + "style": "Subtitle", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "title" + }, + { + "type": "text", + "text": " " + }, + { + "type": "mergefield", + "name": "number" + } + ] + }, + { + "type": "table", + "id": "t_head", + "look": "plain", + "columns": [ + 246.0, + 246.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_billto", + "style": "Heading3", + "content": [ + { + "type": "text", + "text": "Bill to" + } + ] + }, + { + "type": "paragraph", + "id": "p_custname", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "customerName", + "marks": { + "bold": true + } + } + ] + }, + { + "type": "paragraph", + "id": "p_custcode", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Customer " + }, + { + "type": "mergefield", + "name": "customer" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_date", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Date ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "date" + } + ] + }, + { + "type": "paragraph", + "id": "p_duedate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Due ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "dueDate" + } + ] + }, + { + "type": "paragraph", + "id": "p_currency", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Currency ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "currency" + } + ] + }, + { + "type": "paragraph", + "id": "p_status", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Status ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "status" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_space", + "style": "Normal", + "section": "sec_formledger", + "content": [] + }, + { + "type": "table", + "id": "t_lines", + "look": "rows", + "repeatHeader": true, + "columns": [ + 62.0, + 170.0, + 60.0, + 70.0, + 50.0, + 80.0 + ], + "rows": [ + { + "cells": [ + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hitem", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Item", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hdesc", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Description", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hqty", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Quantity", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hrate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Rate", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_htax", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Tax", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hamt", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Amount", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + }, + { + "repeat": true, + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_item", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "item" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_desc", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "description" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_quantity", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "quantity" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_rate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "unitPrice" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxrate", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "taxRate" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_amount", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "lineSubtotal" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "table", + "id": "t_totals", + "look": "plain", + "columns": [ + 312.0, + 100.0, + 80.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_subblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_sublabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Subtotal" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_subvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "subtotal" + } + ] + } + ] + } + ] + }, + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_taxblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxlabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Tax" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "taxTotal" + } + ] + } + ] + } + ] + }, + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_totblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_totlabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Total", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_totvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "currency", + "marks": { + "bold": true + } + }, + { + "type": "text", + "text": " ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "total", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_memo", + "style": "Normal", + "section": "sec_formledger", + "props": { + "spaceBefore": 14.0 + }, + "content": [ + { + "type": "mergefield", + "name": "memo" + } + ] + } + ] + } + ], + "notes": { + "footnotes": {}, + "endnotes": {} + }, + "comments": {}, + "media": {} +} \ No newline at end of file diff --git a/internal/printout/formtxt_purchase_invoice.json b/internal/printout/formtxt_purchase_invoice.json new file mode 100644 index 0000000..4d6e48c --- /dev/null +++ b/internal/printout/formtxt_purchase_invoice.json @@ -0,0 +1,816 @@ +{ + "format": "ftxt", + "formatVersion": 1, + "id": "d_formledgerpurchaseinvoice", + "title": "FormLedger purchase invoice template", + "meta": { + "author": "FormLedger", + "created": 0, + "modified": 0, + "subject": "FormLedger purchase invoice", + "keywords": [ + "formledger" + ], + "language": "en-US" + }, + "settings": { + "pageless": false, + "defaultTab": 36.0, + "trackChanges": false, + "mailMerge": { + "source": "FormLedger", + "columns": [ + "company", + "title", + "number", + "date", + "dueDate", + "currency", + "status", + "memo", + "supplier", + "supplierName", + "supplierRef", + "subtotal", + "taxTotal", + "total", + "item", + "description", + "quantity", + "unitPrice", + "taxRate", + "lineSubtotal" + ], + "rows": [] + } + }, + "styles": { + "Normal": { + "type": "paragraph", + "name": "Normal", + "basedOn": null, + "next": "Normal", + "run": { + "font": "Inter", + "size": 10.0, + "color": "#1f2328" + }, + "para": { + "spaceBefore": 0.0, + "spaceAfter": 4.0, + "lineSpacing": 1.15, + "align": "left" + } + }, + "Title": { + "type": "paragraph", + "name": "Title", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 22.0, + "bold": true + }, + "para": { + "spaceAfter": 2.0 + } + }, + "Subtitle": { + "type": "paragraph", + "name": "Subtitle", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 14.0, + "color": "#57606a" + }, + "para": { + "spaceAfter": 14.0 + } + }, + "Heading3": { + "type": "paragraph", + "name": "Heading 3", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 9.0, + "bold": true, + "color": "#57606a", + "allCaps": true + }, + "para": { + "spaceBefore": 10.0, + "spaceAfter": 2.0, + "keepWithNext": true, + "outlineLevel": 3 + } + } + }, + "numbering": {}, + "sections": [ + { + "id": "sec_formledger", + "page": { + "size": "letter", + "width": 612.0, + "height": 792.0, + "orientation": "portrait" + }, + "margins": { + "top": 60.0, + "right": 60.0, + "bottom": 60.0, + "left": 60.0, + "header": 30.0, + "footer": 30.0, + "gutter": 0.0 + }, + "columns": { + "count": 1, + "gap": 36.0 + }, + "headers": {}, + "footers": { + "default": { + "text": "Page {PAGE} of {NUMPAGES}", + "align": "center" + } + }, + "titlePage": false, + "start": "nextPage" + } + ], + "tabs": [ + { + "id": "tab_formledger", + "title": "Purchase invoice", + "parent": null, + "body": [ + { + "type": "paragraph", + "id": "p_company", + "style": "Title", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "company" + } + ] + }, + { + "type": "paragraph", + "id": "p_heading", + "style": "Subtitle", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "title" + }, + { + "type": "text", + "text": " " + }, + { + "type": "mergefield", + "name": "number" + } + ] + }, + { + "type": "table", + "id": "t_head", + "look": "plain", + "columns": [ + 246.0, + 246.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_billto", + "style": "Heading3", + "content": [ + { + "type": "text", + "text": "Supplier" + } + ] + }, + { + "type": "paragraph", + "id": "p_custname", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "supplierName", + "marks": { + "bold": true + } + } + ] + }, + { + "type": "paragraph", + "id": "p_custcode", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Supplier " + }, + { + "type": "mergefield", + "name": "supplier" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_date", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Date ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "date" + } + ] + }, + { + "type": "paragraph", + "id": "p_duedate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Due ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "dueDate" + } + ] + }, + { + "type": "paragraph", + "id": "p_supref", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Supplier ref ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "supplierRef" + } + ] + }, + { + "type": "paragraph", + "id": "p_currency", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Currency ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "currency" + } + ] + }, + { + "type": "paragraph", + "id": "p_status", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Status ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "status" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_space", + "style": "Normal", + "section": "sec_formledger", + "content": [] + }, + { + "type": "table", + "id": "t_lines", + "look": "rows", + "repeatHeader": true, + "columns": [ + 62.0, + 170.0, + 60.0, + 70.0, + 50.0, + 80.0 + ], + "rows": [ + { + "cells": [ + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hitem", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Item", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hdesc", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Description", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hqty", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Quantity", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hrate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Rate", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_htax", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Tax", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hamt", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Amount", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + }, + { + "repeat": true, + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_item", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "item" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_desc", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "description" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_quantity", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "quantity" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_rate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "unitPrice" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxrate", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "taxRate" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_amount", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "lineSubtotal" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "table", + "id": "t_totals", + "look": "plain", + "columns": [ + 312.0, + 100.0, + 80.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_subblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_sublabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Subtotal" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_subvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "subtotal" + } + ] + } + ] + } + ] + }, + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_taxblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxlabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Tax" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "taxTotal" + } + ] + } + ] + } + ] + }, + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_totblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_totlabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Total", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_totvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "currency", + "marks": { + "bold": true + } + }, + { + "type": "text", + "text": " ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "total", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_memo", + "style": "Normal", + "section": "sec_formledger", + "props": { + "spaceBefore": 14.0 + }, + "content": [ + { + "type": "mergefield", + "name": "memo" + } + ] + } + ] + } + ], + "notes": { + "footnotes": {}, + "endnotes": {} + }, + "comments": {}, + "media": {} +} \ No newline at end of file diff --git a/internal/printout/formtxt_purchase_order.json b/internal/printout/formtxt_purchase_order.json new file mode 100644 index 0000000..b873082 --- /dev/null +++ b/internal/printout/formtxt_purchase_order.json @@ -0,0 +1,795 @@ +{ + "format": "ftxt", + "formatVersion": 1, + "id": "d_formledgerpurchaseorder", + "title": "FormLedger purchase order template", + "meta": { + "author": "FormLedger", + "created": 0, + "modified": 0, + "subject": "FormLedger purchase order", + "keywords": [ + "formledger" + ], + "language": "en-US" + }, + "settings": { + "pageless": false, + "defaultTab": 36.0, + "trackChanges": false, + "mailMerge": { + "source": "FormLedger", + "columns": [ + "company", + "title", + "number", + "date", + "dueDate", + "currency", + "status", + "memo", + "supplier", + "supplierName", + "supplierRef", + "subtotal", + "taxTotal", + "total", + "item", + "description", + "quantity", + "unitPrice", + "taxRate", + "lineSubtotal" + ], + "rows": [] + } + }, + "styles": { + "Normal": { + "type": "paragraph", + "name": "Normal", + "basedOn": null, + "next": "Normal", + "run": { + "font": "Inter", + "size": 10.0, + "color": "#1f2328" + }, + "para": { + "spaceBefore": 0.0, + "spaceAfter": 4.0, + "lineSpacing": 1.15, + "align": "left" + } + }, + "Title": { + "type": "paragraph", + "name": "Title", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 22.0, + "bold": true + }, + "para": { + "spaceAfter": 2.0 + } + }, + "Subtitle": { + "type": "paragraph", + "name": "Subtitle", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 14.0, + "color": "#57606a" + }, + "para": { + "spaceAfter": 14.0 + } + }, + "Heading3": { + "type": "paragraph", + "name": "Heading 3", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 9.0, + "bold": true, + "color": "#57606a", + "allCaps": true + }, + "para": { + "spaceBefore": 10.0, + "spaceAfter": 2.0, + "keepWithNext": true, + "outlineLevel": 3 + } + } + }, + "numbering": {}, + "sections": [ + { + "id": "sec_formledger", + "page": { + "size": "letter", + "width": 612.0, + "height": 792.0, + "orientation": "portrait" + }, + "margins": { + "top": 60.0, + "right": 60.0, + "bottom": 60.0, + "left": 60.0, + "header": 30.0, + "footer": 30.0, + "gutter": 0.0 + }, + "columns": { + "count": 1, + "gap": 36.0 + }, + "headers": {}, + "footers": { + "default": { + "text": "Page {PAGE} of {NUMPAGES}", + "align": "center" + } + }, + "titlePage": false, + "start": "nextPage" + } + ], + "tabs": [ + { + "id": "tab_formledger", + "title": "Purchase order", + "parent": null, + "body": [ + { + "type": "paragraph", + "id": "p_company", + "style": "Title", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "company" + } + ] + }, + { + "type": "paragraph", + "id": "p_heading", + "style": "Subtitle", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "title" + }, + { + "type": "text", + "text": " " + }, + { + "type": "mergefield", + "name": "number" + } + ] + }, + { + "type": "table", + "id": "t_head", + "look": "plain", + "columns": [ + 246.0, + 246.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_billto", + "style": "Heading3", + "content": [ + { + "type": "text", + "text": "Supplier" + } + ] + }, + { + "type": "paragraph", + "id": "p_custname", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "supplierName", + "marks": { + "bold": true + } + } + ] + }, + { + "type": "paragraph", + "id": "p_custcode", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Supplier " + }, + { + "type": "mergefield", + "name": "supplier" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_date", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Date ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "date" + } + ] + }, + { + "type": "paragraph", + "id": "p_duedate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Due ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "dueDate" + } + ] + }, + { + "type": "paragraph", + "id": "p_currency", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Currency ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "currency" + } + ] + }, + { + "type": "paragraph", + "id": "p_status", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Status ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "status" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_space", + "style": "Normal", + "section": "sec_formledger", + "content": [] + }, + { + "type": "table", + "id": "t_lines", + "look": "rows", + "repeatHeader": true, + "columns": [ + 62.0, + 170.0, + 60.0, + 70.0, + 50.0, + 80.0 + ], + "rows": [ + { + "cells": [ + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hitem", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Item", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hdesc", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Description", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hqty", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Quantity", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hrate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Rate", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_htax", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Tax", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hamt", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Amount", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + }, + { + "repeat": true, + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_item", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "item" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_desc", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "description" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_quantity", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "quantity" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_rate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "unitPrice" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxrate", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "taxRate" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_amount", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "lineSubtotal" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "table", + "id": "t_totals", + "look": "plain", + "columns": [ + 312.0, + 100.0, + 80.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_subblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_sublabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Subtotal" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_subvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "subtotal" + } + ] + } + ] + } + ] + }, + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_taxblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxlabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Tax" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "taxTotal" + } + ] + } + ] + } + ] + }, + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_totblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_totlabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Total", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_totvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "currency", + "marks": { + "bold": true + } + }, + { + "type": "text", + "text": " ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "total", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_memo", + "style": "Normal", + "section": "sec_formledger", + "props": { + "spaceBefore": 14.0 + }, + "content": [ + { + "type": "mergefield", + "name": "memo" + } + ] + } + ] + } + ], + "notes": { + "footnotes": {}, + "endnotes": {} + }, + "comments": {}, + "media": {} +} \ No newline at end of file diff --git a/internal/printout/formtxt_quote.json b/internal/printout/formtxt_quote.json new file mode 100644 index 0000000..0fc5c53 --- /dev/null +++ b/internal/printout/formtxt_quote.json @@ -0,0 +1,794 @@ +{ + "format": "ftxt", + "formatVersion": 1, + "id": "d_formledgerquote", + "title": "FormLedger quote template", + "meta": { + "author": "FormLedger", + "created": 0, + "modified": 0, + "subject": "FormLedger quote", + "keywords": [ + "formledger" + ], + "language": "en-US" + }, + "settings": { + "pageless": false, + "defaultTab": 36.0, + "trackChanges": false, + "mailMerge": { + "source": "FormLedger", + "columns": [ + "company", + "title", + "number", + "date", + "dueDate", + "currency", + "status", + "memo", + "customer", + "customerName", + "subtotal", + "taxTotal", + "total", + "item", + "description", + "quantity", + "unitPrice", + "taxRate", + "lineSubtotal" + ], + "rows": [] + } + }, + "styles": { + "Normal": { + "type": "paragraph", + "name": "Normal", + "basedOn": null, + "next": "Normal", + "run": { + "font": "Inter", + "size": 10.0, + "color": "#1f2328" + }, + "para": { + "spaceBefore": 0.0, + "spaceAfter": 4.0, + "lineSpacing": 1.15, + "align": "left" + } + }, + "Title": { + "type": "paragraph", + "name": "Title", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 22.0, + "bold": true + }, + "para": { + "spaceAfter": 2.0 + } + }, + "Subtitle": { + "type": "paragraph", + "name": "Subtitle", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 14.0, + "color": "#57606a" + }, + "para": { + "spaceAfter": 14.0 + } + }, + "Heading3": { + "type": "paragraph", + "name": "Heading 3", + "basedOn": "Normal", + "next": "Normal", + "run": { + "size": 9.0, + "bold": true, + "color": "#57606a", + "allCaps": true + }, + "para": { + "spaceBefore": 10.0, + "spaceAfter": 2.0, + "keepWithNext": true, + "outlineLevel": 3 + } + } + }, + "numbering": {}, + "sections": [ + { + "id": "sec_formledger", + "page": { + "size": "letter", + "width": 612.0, + "height": 792.0, + "orientation": "portrait" + }, + "margins": { + "top": 60.0, + "right": 60.0, + "bottom": 60.0, + "left": 60.0, + "header": 30.0, + "footer": 30.0, + "gutter": 0.0 + }, + "columns": { + "count": 1, + "gap": 36.0 + }, + "headers": {}, + "footers": { + "default": { + "text": "Page {PAGE} of {NUMPAGES}", + "align": "center" + } + }, + "titlePage": false, + "start": "nextPage" + } + ], + "tabs": [ + { + "id": "tab_formledger", + "title": "Quote", + "parent": null, + "body": [ + { + "type": "paragraph", + "id": "p_company", + "style": "Title", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "company" + } + ] + }, + { + "type": "paragraph", + "id": "p_heading", + "style": "Subtitle", + "section": "sec_formledger", + "content": [ + { + "type": "mergefield", + "name": "title" + }, + { + "type": "text", + "text": " " + }, + { + "type": "mergefield", + "name": "number" + } + ] + }, + { + "type": "table", + "id": "t_head", + "look": "plain", + "columns": [ + 246.0, + 246.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_billto", + "style": "Heading3", + "content": [ + { + "type": "text", + "text": "Quote for" + } + ] + }, + { + "type": "paragraph", + "id": "p_custname", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "customerName", + "marks": { + "bold": true + } + } + ] + }, + { + "type": "paragraph", + "id": "p_custcode", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Customer " + }, + { + "type": "mergefield", + "name": "customer" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_date", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Date ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "date" + } + ] + }, + { + "type": "paragraph", + "id": "p_duedate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Valid until ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "dueDate" + } + ] + }, + { + "type": "paragraph", + "id": "p_currency", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Currency ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "currency" + } + ] + }, + { + "type": "paragraph", + "id": "p_status", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Status ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "status" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_space", + "style": "Normal", + "section": "sec_formledger", + "content": [] + }, + { + "type": "table", + "id": "t_lines", + "look": "rows", + "repeatHeader": true, + "columns": [ + 62.0, + 170.0, + 60.0, + 70.0, + 50.0, + 80.0 + ], + "rows": [ + { + "cells": [ + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hitem", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Item", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hdesc", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Description", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hqty", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Quantity", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hrate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Rate", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_htax", + "style": "Normal", + "content": [ + { + "type": "text", + "text": "Tax", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "header": true, + "shading": "#eef1f4", + "body": [ + { + "type": "paragraph", + "id": "p_hamt", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Amount", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + }, + { + "repeat": true, + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_item", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "item" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_desc", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "description" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_quantity", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "quantity" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_rate", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "unitPrice" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxrate", + "style": "Normal", + "content": [ + { + "type": "mergefield", + "name": "taxRate" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_amount", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "lineSubtotal" + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "table", + "id": "t_totals", + "look": "plain", + "columns": [ + 312.0, + 100.0, + 80.0 + ], + "rows": [ + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_subblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_sublabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Subtotal" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_subvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "subtotal" + } + ] + } + ] + } + ] + }, + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_taxblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxlabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Tax" + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_taxvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "taxTotal" + } + ] + } + ] + } + ] + }, + { + "cells": [ + { + "body": [ + { + "type": "paragraph", + "id": "p_totblank", + "style": "Normal", + "content": [] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_totlabel", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "text", + "text": "Total", + "marks": { + "bold": true + } + } + ] + } + ] + }, + { + "body": [ + { + "type": "paragraph", + "id": "p_totvalue", + "style": "Normal", + "props": { + "align": "right" + }, + "content": [ + { + "type": "mergefield", + "name": "currency", + "marks": { + "bold": true + } + }, + { + "type": "text", + "text": " ", + "marks": { + "bold": true + } + }, + { + "type": "mergefield", + "name": "total", + "marks": { + "bold": true + } + } + ] + } + ] + } + ] + } + ] + }, + { + "type": "paragraph", + "id": "p_memo", + "style": "Normal", + "section": "sec_formledger", + "props": { + "spaceBefore": 14.0 + }, + "content": [ + { + "type": "mergefield", + "name": "memo" + } + ] + } + ] + } + ], + "notes": { + "footnotes": {}, + "endnotes": {} + }, + "comments": {}, + "media": {} +} \ No newline at end of file diff --git a/internal/printout/template.go b/internal/printout/template.go index 5318161..d288bb1 100644 --- a/internal/printout/template.go +++ b/internal/printout/template.go @@ -20,7 +20,24 @@ var invoiceTemplate []byte //go:embed formtxt_statement.json var statementTemplate []byte -const TemplateUsage = "formtxt-template [invoice|statement] [--out FILE]" +//go:embed formtxt_quote.json +var quoteTemplate []byte + +//go:embed formtxt_order.json +var orderTemplate []byte + +//go:embed formtxt_purchase_order.json +var purchaseOrderTemplate []byte + +//go:embed formtxt_purchase_invoice.json +var purchaseInvoiceTemplate []byte + +//go:embed formtxt_goods_receipt.json +var goodsReceiptTemplate []byte + +const TemplateUsage = "formtxt-template [KIND] [--a4] [--out FILE], or formtxt-template --all [--out DIR]; KIND is " + templateKinds + +const templateKinds = "quote, order, invoice, purchase-order, purchase-invoice, goods-receipt or statement" type shippedTemplate struct { title string @@ -28,14 +45,56 @@ type shippedTemplate struct { } var shipped = map[string]shippedTemplate{ - "invoice": {"FormLedger invoice template", invoiceTemplate}, - "statement": {"FormLedger statement template", statementTemplate}, + "quote": {"FormLedger quote template", quoteTemplate}, + "order": {"FormLedger order template", orderTemplate}, + "invoice": {"FormLedger invoice template", invoiceTemplate}, + "purchase-order": {"FormLedger purchase order template", purchaseOrderTemplate}, + "purchase-invoice": {"FormLedger purchase invoice template", purchaseInvoiceTemplate}, + "goods-receipt": {"FormLedger goods receipt template", goodsReceiptTemplate}, + "statement": {"FormLedger statement template", statementTemplate}, } -func Template(kind string) ([]byte, error) { +var shippedOrder = []string{"quote", "order", "invoice", "purchase-order", "purchase-invoice", "goods-receipt", "statement"} + +func templateTitle(kind, size string) string { + if size == "A4" { + return shipped[kind].title + " (A4)" + } + return shipped[kind].title +} + +func sized(raw []byte, kind, size string) ([]byte, error) { + if size != "A4" { + return raw, nil + } + var d map[string]any + if err := json.Unmarshal(raw, &d); err != nil { + return nil, err + } + d["title"] = templateTitle(kind, size) + d["id"] = fmt.Sprint(d["id"], "a4") + secs, _ := d["sections"].([]any) + for _, s := range secs { + sec, _ := s.(map[string]any) + if sec == nil { + continue + } + sec["page"] = map[string]any{"size": "a4", "width": 595.28, "height": 841.89, "orientation": "portrait"} + if m, ok := sec["margins"].(map[string]any); ok { + m["left"], m["right"] = 51.64, 51.64 + } + } + return json.Marshal(d) +} + +func Template(kind, size string) ([]byte, error) { t, ok := shipped[kind] if !ok { - return nil, errors.New("FormLedger ships a FormTxt template for invoice and statement only") + return nil, errors.New("FormLedger ships a FormTxt template for " + templateKinds + " only") + } + body, err := sized(t.doc, kind, size) + if err != nil { + return nil, err } var buf bytes.Buffer z := zip.NewWriter(&buf) @@ -50,7 +109,7 @@ func Template(kind string) ([]byte, error) { if err != nil { return nil, err } - if _, err = doc.Write(t.doc); err != nil { + if _, err = doc.Write(body); err != nil { return nil, err } if err = z.Close(); err != nil { @@ -60,45 +119,94 @@ func Template(kind string) ([]byte, error) { } func TemplateCommand(args []string, stdout io.Writer) error { - kind, file := "invoice", "" + kind, file, size, all := "invoice", "", "Letter", false for i := 0; i < len(args); i++ { - switch a := args[i]; { + a := args[i] + _, known := shipped[a] + switch { case a == "--out" && i+1 < len(args): i++ file = args[i] case len(a) > 6 && a[:6] == "--out=": file = a[6:] - case a == "invoice" || a == "statement": + case a == "--a4": + size = "A4" + case a == "--all": + all = true + case known: kind = a default: return errors.New("usage: " + TemplateUsage) } } + if all { + dir := file + if dir == "" { + dir = "." + } + if err := os.MkdirAll(dir, 0o755); err != nil { + return err + } + for _, k := range shippedOrder { + for _, s := range []string{"Letter", "A4"} { + name := "formledger-" + k + ".ftxt" + if s == "A4" { + name = "formledger-" + k + "-a4.ftxt" + } + if err := writeTemplate(filepath.Join(dir, name), k, s, stdout); err != nil { + return err + } + } + } + _, err := fmt.Fprintln(stdout, "Open the files for the kinds and page sizes you print in FormTxt with File > Open or import file. Letter is used for USD documents, A4 for every other currency.") + return err + } if file == "" { file = "formledger-" + kind + ".ftxt" - } - data, err := Template(kind) - if err != nil { - return err + if size == "A4" { + file = "formledger-" + kind + "-a4.ftxt" + } } if file == "-" { + data, err := Template(kind, size) + if err != nil { + return err + } _, err = stdout.Write(data) return err } + if err := writeTemplate(file, kind, size, stdout); err != nil { + return err + } + _, err := fmt.Fprintf(stdout, "Open it in FormTxt with File > Open or import file. FormLedger then finds the document named %q by itself for %s documents.\n", templateTitle(kind, size), sizeWords(size)) + return err +} + +func sizeWords(size string) string { + if size == "A4" { + return "non-USD" + } + return "USD" +} + +func writeTemplate(file, kind, size string, stdout io.Writer) error { + data, err := Template(kind, size) + if err != nil { + return err + } if err = os.WriteFile(file, data, 0o644); err != nil { return err } abs, _ := filepath.Abs(file) - _, err = fmt.Fprintf(stdout, "wrote %s\nOpen it in FormTxt with File > Open or import file. FormLedger then finds the document named %q by itself.\n", abs, shipped[kind].title) + _, err = fmt.Fprintf(stdout, "wrote %s (%s, %s)\n", abs, templateTitle(kind, size), size) return err } -func findShipped(base, kind string) (string, error) { - t, ok := shipped[kind] - if !ok { +func findShipped(base, kind, size string) (string, error) { + if _, ok := shipped[kind]; !ok { return "", ErrUnavailable } - title := t.title + title := templateTitle(kind, size) resp, err := (&http.Client{Timeout: 13 * time.Second}).Get(base + "/api/documents") if err != nil { return "", ErrUnavailable @@ -124,7 +232,11 @@ func findShipped(base, kind string) (string, error) { } } if id == "" { - return "", refused{"FormTxt holds no document named " + title + ", so FormLedger drew the plain page. Run ./formledger formtxt-template " + kind + ", open the file it writes in FormTxt with File > Open or import file, then print again."} + flag := "" + if size == "A4" { + flag = " --a4" + } + return "", refused{"FormTxt holds no document named " + title + ", so FormLedger drew the plain page. Run ./formledger formtxt-template " + kind + flag + ", open the file it writes in FormTxt with File > Open or import file, then print again."} } return id, nil } diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index e648049..6bf7f54 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1106,7 +1106,7 @@ dependencies = [ [[package]] name = "formledger-desktop" -version = "0.13.0" +version = "0.13.9" dependencies = [ "objc2", "objc2-app-kit", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 25e7ec3..ddd09c3 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "formledger-desktop" -version = "0.13.0" +version = "0.13.9" 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 486ca32..cdad10f 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.13.0 +Current build version: v0.13.9 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 225141b..6740eeb 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.13.0", + "version": "0.13.9", "identifier": "ai.nodemode.formledger", "build": { "frontendDist": "splash" }, "app": { diff --git a/web/HASHOUT_LOG.md b/web/HASHOUT_LOG.md index 0985c8a..9475e18 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.13.0 +Current build version: v0.13.9 Last updated: 2026-11-26 (US Eastern) · account screens, and the fixes from the throttled browser check --- @@ -740,3 +740,17 @@ Measured side by side at 1400 by 900, dark, against a form.md build run from a c - logged: v0.13.0 · 2026-11-27 Every description cell carries an empty `.grid__hint` from first paint, absolutely placed at the cell's end, so a form with no template is unchanged and a row stays at its height. When a template's lines arrive, `writeHint` writes the hint text ("4100 Sales") and the tooltip "Posts to 4100 Sales" once per free line. The hint follows the description, because the account still goes out keyed by that text: edit the description and the hint clears, which is the truth about what will be posted. An item line never shows one. The Post and Confirm label swap moved the action row by 0.00016 when a template set the kind to invoice; the primary label now keeps a minimum width of 8ch. `minorUnits` in engine/format is now the one list of zero-decimal currencies; the line grid reads it, and so does the chart's compact axis through `setChartCurrency`, which stays at two places until dashboards.ts calls it with the company currency. Checked under 4x CPU and the slowed network at 1400 by 900: sales and purchase templates opened by a hard reload read 0 shift; typing in two descriptions read 0 with input and 0 without. + +### src/ui/key-notice.ts, src/ui/hubs.ts · key backup notice and Setup's encryption facts; zero-decimal dashboards seen +- refers-to: src/ui/key-notice.ts :: mountKeyNotice, keyFacts, keyOf, KeyState; src/ui/hubs.ts :: hub (setup mount) +- kind: rationale +- logged: v0.13.9 · 2026-11-27 + +Pre-write statement. 1: most sessions never see the notice, so no space is reserved for it in the layout. 2: it is one `aside` built once at final size in `#overlay-root`, fixed at the bottom end of the window at `--z-popover`, so showing or hiding it moves no content. 3: only its `hidden` flag and the path text are ever written, from the `me` and `screen` state. The notice is for the owner only, while the screen is the app, the ledger is encrypted with a key the server made, and no backup is confirmed; "I have backed up the key" posts `/api/me/key-backed-up` and puts the answer into `me`, which hides it. It is not a toast (it must not vanish) and not a dialog (it must not block). It first sat at the bottom start and covered the sidebar's account row; it now sits at the bottom end over the content. The Setup hub appends an Encryption list under its cards with the same three facts; it is built once and only its three values are written. `Me` gains no field in `engine/session.ts` (not this slice's file); `keyOf` reads `key` through a local type. The notice needs `mountKeyNotice(engine)` after `mountAccount(engine)` in `app.ts`, with its owner. Run in a private copy with that line, desktop mode with a key home, 4x CPU, 400 ms and 50000 B/s, hard reload at 1400 by 900: load with the notice 0 shift without input and 0 with; the confirm click 0 and 0; the reload after it 0 and 0, notice gone; desktop mode with no key home, load 0 and 0, no notice. Dashboards with a JPY company (accounts made in JPY so the base currency reads JPY, four posted invoices of 125,000, 196,000, 125,000 and 192,000): cards read 638,000 JPY, the September readout 125,000, the axis top 317K for November's 317,000; the same amounts in USD read 6,380.00 USD and 3.2K. The v0.13.0 reasoning held and nothing in dashboards.ts or chart.ts was changed. + +### src/ui/parts/linegrid.ts, src/styles/views/grid.css · thirty pixel line rows, totals from the first paint, removal that moves nothing +- refers-to: src/ui/parts/linegrid.ts :: recompute, rateOf, put, dropRow, setLines; src/styles/views/grid.css :: .grid__line, .grid__err, .grid__scroll; src/styles/views/docform.css :: .grid__hint +- kind: rationale +- logged: v0.13.9 · 2026-11-27 + +Each `.grid__line` was 47 px: a second grid track of `--grid-err` (16 px) held the per-line error text ("Needs an item", server line errors) under every row, plus a 1 px border. The line is now one track at `block-size: var(--row)` (30 px, border inside), and `.grid__err` is an absolutely placed tag over the row's lower edge at `--z-raised`, hidden while empty, so an error appears without moving anything. The scroll box's minimum is five rows plus one error tag. Totals: the form's `onChange` is a no-op and the document totals came only from the server's answer after a save, while `setLines` never totaled at all, so a template's lines showed no Amount and 0.00 totals. `recompute` now works out each line the way `sales.LineAmounts` does (subtotal half-up from milli quantity, tax half-up from the rate's basis points read from the tax picker's record) and writes only changed text into the existing cells and sums; it runs on every edit, at the end of `setLines`, and again when a line's tax rate resolves. The server's figures still overwrite them after save, and they agree. Removing a line used to pull every row below it up; `dropRow` now copies the following lines' values up one row and drops the last node. The account hint box is a fixed 45 percent wide so its text changing never resizes it. Checked under 4x CPU and the slowed network at 1400 by 900: the twenty-line exit run read 0 at every step; the service-hours template read 1,200.00, 180.00, 0.00 and 1,380.00 at load, 0 shift dark and light; a hand-typed free line 3 at 25.50 read 76.50; removing line 2 and the last line read 0 with and without input; a posted template invoice read subtotal 120000 and total 120000 from the API, as the form showed. diff --git a/web/package-lock.json b/web/package-lock.json index a3ea4d8..632e74d 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,12 +1,12 @@ { "name": "formledger", - "version": "0.13.0", + "version": "0.13.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "formledger", - "version": "0.13.0", + "version": "0.13.9", "license": "Apache-2.0", "devDependencies": { "@types/node": "^22.20.5", diff --git a/web/package.json b/web/package.json index e884635..2e5c9e8 100644 --- a/web/package.json +++ b/web/package.json @@ -1,7 +1,7 @@ { "name": "formledger", "private": true, - "version": "0.13.0", + "version": "0.13.9", "license": "Apache-2.0", "type": "module", "scripts": { diff --git a/web/src/styles/key-notice.css b/web/src/styles/key-notice.css new file mode 100644 index 0000000..aa2ab1d --- /dev/null +++ b/web/src/styles/key-notice.css @@ -0,0 +1,37 @@ +.keynote { + position: fixed; + inset-block-end: var(--space-6); + inset-inline-end: var(--space-6); + z-index: var(--z-popover); + inline-size: min(28rem, calc(100vw - 2 * var(--space-6))); + padding: var(--space-4); + background: var(--surface); + border: 1px solid var(--border-strong); + border-inline-start: 3px solid var(--warning); + border-radius: var(--radius); + display: grid; + gap: var(--space-2); + font-size: var(--text-sm); + color: var(--text); +} +.keynote[hidden] { display: none; } +.keynote__path { overflow-wrap: anywhere; font-size: var(--text-xs); } +.keynote__how { color: var(--text-muted); } +.keynote__ok { justify-self: start; } + +.keyfacts { + margin-block-start: var(--space-6); + display: grid; + gap: var(--space-2); + font-size: var(--text-sm); +} +.keyfacts[hidden] { display: none; } +.keyfacts__list { + display: grid; + grid-template-columns: max-content 1fr; + gap: var(--space-1) var(--space-4); + margin: 0; +} +.keyfacts__row { display: contents; } +.keyfacts__label { color: var(--text-muted); } +.keyfacts__value { margin: 0; overflow-wrap: anywhere; } diff --git a/web/src/styles/views/docform.css b/web/src/styles/views/docform.css index ffe8969..de7bec8 100644 --- a/web/src/styles/views/docform.css +++ b/web/src/styles/views/docform.css @@ -267,9 +267,10 @@ inset-block-start: 50%; inset-inline-end: var(--space-2); transform: translateY(-50%); - max-inline-size: 45%; + inline-size: 45%; overflow: hidden; color: var(--text-muted); + text-align: end; font-size: var(--text-xs); white-space: nowrap; text-overflow: ellipsis; diff --git a/web/src/styles/views/grid.css b/web/src/styles/views/grid.css index 6104b45..4ef2652 100644 --- a/web/src/styles/views/grid.css +++ b/web/src/styles/views/grid.css @@ -83,7 +83,7 @@ .grid__scroll { flex: 1 1 0; - min-block-size: calc(var(--grid-row) + 4 * (var(--grid-row) + var(--grid-err))); + min-block-size: calc(var(--grid-row) * 5 + var(--grid-err)); overflow: auto; overscroll-behavior: contain; border: 1px solid var(--border); @@ -137,7 +137,9 @@ } .grid__line { - grid-template-rows: var(--grid-row) var(--grid-err); + position: relative; + grid-template-rows: minmax(0, 1fr); + block-size: var(--grid-row); border-block-end: 1px solid var(--border-subtle, transparent); } @@ -219,15 +221,27 @@ } .grid__err { - grid-column: 1 / -1; + position: absolute; + inset-block-start: calc(100% - var(--space-1)); + inset-inline-start: calc(var(--space-1) + var(--space-2)); + z-index: var(--z-raised); + max-inline-size: calc(100% - var(--space-4)); block-size: var(--grid-err); padding: 0 var(--space-2); overflow: hidden; color: var(--danger, red); - font-size: 0.8em; - line-height: var(--grid-err); + background: var(--surface); + border: 1px solid var(--danger, red); + border-radius: var(--radius-sm, 4px); + font-size: var(--text-xs); + line-height: calc(var(--grid-err) - 2px); white-space: nowrap; text-overflow: ellipsis; + pointer-events: none; +} + +.grid__err:empty { + visibility: hidden; } .grid__foot { diff --git a/web/src/ui/app.ts b/web/src/ui/app.ts index 2842a49..2f21a49 100644 --- a/web/src/ui/app.ts +++ b/web/src/ui/app.ts @@ -5,6 +5,7 @@ import { openPalette } from "./command-palette"; import { writeSnapshot } from "./snapshot-action"; import { dismissToast, toast } from "./toast"; import { mountAccount } from "./account"; +import { mountKeyNotice } from "./key-notice"; import { hashFor, mountViews } from "./views"; const SERVER_TOAST = "server-health"; @@ -346,5 +347,6 @@ export function mountApp(engine: Engine): void { bindStatus(engine); mountHome(engine); mountAccount(engine); + mountKeyNotice(engine); mountViews(engine); } diff --git a/web/src/ui/hubs.ts b/web/src/ui/hubs.ts index 41d01dc..0844322 100644 --- a/web/src/ui/hubs.ts +++ b/web/src/ui/hubs.ts @@ -1,5 +1,6 @@ import { h } from "./dom"; import { iconNode } from "./icons"; +import { keyFacts } from "./key-notice"; import { VIEW_ABOUT } from "./view-about"; import { VIEW_ICONS } from "./view-icons"; import type { ViewDef, ViewGroup } from "./views"; @@ -41,7 +42,7 @@ function hub(id: string, title: string, group: ViewGroup, screens: readonly HubS title, group, nav: false, - mount(host) { + mount(host, ctx) { const grid = h("div", { class: "hub" }); for (const s of screens) { const mark = h("span", { class: "hub__icon" }); @@ -58,6 +59,7 @@ function hub(id: string, title: string, group: ViewGroup, screens: readonly HubS ); } host.append(grid); + if (id === "setup") host.append(keyFacts(ctx.engine)); }, }; } diff --git a/web/src/ui/key-notice.ts b/web/src/ui/key-notice.ts new file mode 100644 index 0000000..52043cf --- /dev/null +++ b/web/src/ui/key-notice.ts @@ -0,0 +1,80 @@ +import type { Engine } from "../engine"; +import type { Me } from "../engine/session"; +import { byId, h, setText } from "./dom"; +import "../styles/key-notice.css"; + +export interface KeyState { + encrypted: boolean; + madeHere: boolean; + path?: string; + backedUp: boolean; +} + +type KeyMe = Me & { key?: KeyState }; + +export function keyOf(me: Me | null | undefined): KeyState | null { + if (!me || me.user.role !== "owner") return null; + return (me as KeyMe).key ?? null; +} + +export function mountKeyNotice(engine: Engine): void { + const path = h("code", { class: "keynote__path" }); + const confirm = h("button", { class: "btn btn--primary keynote__ok", attrs: { type: "button" }, text: "I have backed up the key" }); + const panel = h( + "aside", + { class: "keynote", attrs: { role: "region", "aria-label": "Back up your encryption key", "data-ref": "key-notice", hidden: "" } }, + h("strong", { text: "Your books are encrypted. Back up the key." }), + h("span", { text: "FormLedger made this key and keeps it in:" }), + path, + h("span", { text: "Losing the key loses the books: without it nobody can read this ledger, not even you." }), + h("span", { + class: "keynote__how", + text: "Copy that file to a password manager (open it in a text editor and save the one line as a secure note) or to an offline drive kept apart from this computer.", + }), + confirm, + ); + byId("overlay-root").append(panel); + const show = (me: Me | null) => { + const k = keyOf(me); + const on = engine.state.get("screen") === "app" && !!k && k.encrypted && k.madeHere && !k.backedUp; + if (k?.path) setText(path, k.path); + panel.hidden = !on; + }; + confirm.addEventListener("click", async () => { + confirm.disabled = true; + try { + const me = await engine.api.call("POST", "/api/me/key-backed-up"); + engine.state.set("me", me); + } catch { + confirm.disabled = false; + } + }); + engine.state.watch("me", show, { immediate: true }); + engine.state.watch("screen", () => show(engine.state.get("me"))); +} + +export function keyFacts(engine: Engine): HTMLElement { + const row = (label: string, value: HTMLElement) => h("div", { class: "keyfacts__row" }, h("dt", { class: "keyfacts__label", text: label }), value); + const enc = h("dd", { class: "keyfacts__value" }); + const where = h("dd", { class: "keyfacts__value" }); + const backed = h("dd", { class: "keyfacts__value" }); + const box = h( + "section", + { class: "keyfacts", attrs: { "aria-label": "Encryption", "data-ref": "key-facts" } }, + h("strong", { text: "Encryption" }), + h("dl", { class: "keyfacts__list" }, row("Books", enc), row("Key file", where), row("Backed up", backed)), + ); + engine.state.watch( + "me", + (me) => { + const k = keyOf(me); + box.hidden = !k; + if (!k) return; + setText(enc, k.encrypted ? "Encrypted at rest" : "Not encrypted"); + setText(where, k.path ?? "No key"); + setText(backed, !k.path ? "Not applicable" : k.madeHere ? (k.backedUp ? "Yes, confirmed by the owner" : "Not yet confirmed") : "Your own key file; keep your own backup"); + }, + { immediate: true }, + ); + return box; +} diff --git a/web/src/ui/parts/linegrid.ts b/web/src/ui/parts/linegrid.ts index 34911d4..5a88db2 100644 --- a/web/src/ui/parts/linegrid.ts +++ b/web/src/ui/parts/linegrid.ts @@ -140,11 +140,42 @@ export function mountLineGrid(host: HTMLElement, ctx: ViewContext, o: LineGridOp ); host.append(root); - function emit(): void { + function rateOf(r: Row): number { + if (!r.line.taxRateId) return 0; + const picked = r.tax.get(); + const bp = picked && picked.id === r.line.taxRateId ? Number(picked.record.rateBp) : 0; + return Number.isFinite(bp) ? bp : 0; + } + + function put(el: HTMLElement, text: string): void { + if (el.textContent !== text) setText(el, text); + } + + function recompute(): void { + let s = 0; + let x = 0; for (const r of rows) { - const net = isBlank(r.line) ? "" : fmt(Math.round((r.line.qtyMilli * r.line.unitPrice) / 1000)); - if (r.total.textContent !== net) setText(r.total, net); + if (isBlank(r.line)) { + put(r.sub, ""); + put(r.taxAmt, ""); + put(r.total, ""); + continue; + } + const net = Math.round((r.line.qtyMilli * r.line.unitPrice) / 1000); + const tax = Math.round((net * rateOf(r)) / 10000); + s += net; + x += tax; + put(r.sub, fmt(net)); + put(r.taxAmt, fmt(tax)); + put(r.total, fmt(net)); } + put(sumSub, fmt(s)); + put(sumTax, fmt(x)); + put(sumTotal, fmt(s + x)); + } + + function emit(): void { + recompute(); o.onChange(collect()); } @@ -191,7 +222,9 @@ export function mountLineGrid(host: HTMLElement, ctx: ViewContext, o: LineGridOp r.qty.classList.remove("is-invalid"); r.price.classList.remove("is-invalid"); void r.item.setById(l.itemId); - void r.tax.setById(l.taxRateId); + void r.tax.setById(l.taxRateId).then(() => { + if (rows.includes(r) && r.line.taxRateId === l.taxRateId) recompute(); + }); } function clearTotals(r: Row): void { @@ -347,10 +380,9 @@ export function mountLineGrid(host: HTMLElement, ctx: ViewContext, o: LineGridOp focusCell(rows[i - 1], col); } else if (ev.key === "Delete" && ev.ctrlKey) { ev.preventDefault(); - const target = rows[i + 1] ?? rows[i - 1]; dropRow(r); emit(); - focusCell(target, col); + focusCell(rows[i] ?? rows[i - 1], col); } }); @@ -370,8 +402,20 @@ export function mountLineGrid(host: HTMLElement, ctx: ViewContext, o: LineGridOp setText(r.error, ""); return; } - rows.splice(i, 1); - r.el.remove(); + for (let j = i; j < rows.length - 1; j++) { + const a = rows[j] as Row; + const b = rows[j + 1] as Row; + writeLine(a, b.line); + a.touched = b.touched; + a.el.classList.toggle("needs-item", b.el.classList.contains("needs-item")); + put(a.error, b.error.textContent ?? ""); + a.qty.value = b.qty.value; + a.price.value = b.price.value; + a.qty.classList.toggle("is-invalid", b.qty.classList.contains("is-invalid")); + a.price.classList.toggle("is-invalid", b.price.classList.contains("is-invalid")); + } + const last = rows.pop(); + last?.el.remove(); } addBtn.addEventListener("click", () => { @@ -397,6 +441,7 @@ export function mountLineGrid(host: HTMLElement, ctx: ViewContext, o: LineGridOp setText(r.error, ""); }); for (let i = rows.length; i < want; i++) addRow(next[i] ?? blank()); + recompute(); collect(); }, setTotals: (t) => {