796 lines · 20.2 KB · JSONRaw
{ "format_version": 1, "id": "transaction", "name": "Movement", "plural": "Movements", "record_route": "/money/transactions/[id]", "deletion": { "label": "Remove", "confirm": "Remove" }, "picture": {"photo": "photo:8dcc818171791b390006092d0c40c1bed9e261c7ce0b3693defa53ced27823d6", "object": "tool-money"}, "builtin": true, "engine": "money", "columns": [ { "key": "title", "name": "With", "type": "text", "readonly": true }, { "key": "recorded_as", "name": "Recorded as", "type": "text", "readonly": true, "fact": true, "reading": "{value}"}, { "key": "description", "type": "text", "readonly": true, "name": "What" }, { "key": "payee_text", "name": "Payee", "type": "text", "readonly": true }, { "key": "occurred_on", "name": "Date", "type": "date", "readonly": true, "fact": true, "reading": "{value}", "format": "calendar-datetime"}, { "key": "counterparty_person_id", "name": "Person", "type": "link", "link_to": "person", "readonly": true }, { "key": "status", "type": "choice", "choices": [ "posted", "proposed" ], "readonly": true, "labels": { "posted": "Posted", "proposed": "Suggested" }, "shown_when": { "column": "status", "values": [ "proposed" ] } }, { "key": "due_date", "name": "Due", "type": "date", "readonly": true }, { "key": "period_start", "name": "Covers from", "type": "date", "readonly": true }, { "key": "period_end", "name": "Covers to", "type": "date", "readonly": true }, { "key": "gst_amount_minor", "name": "GST", "type": "amount", "currency": "currency", "readonly": true }, { "key": "gst_rate_bps", "name": "GST rate (basis points)", "type": "number", "readonly": true }, { "key": "notes", "type": "longtext", "readonly": true }, { "key": "settles_transaction_id", "name": "Settles", "type": "link", "link_to": "transaction", "readonly": true, "contributes": { "label": "Settled by" } }, { "key": "classified_by", "name": "Classified by", "type": "choice", "choices": [ "import", "assistant", "owner" ], "readonly": true, "labels": { "import": "A statement import", "assistant": "An assistant", "owner": "You" } }, { "key": "confidence_bps", "name": "Confidence (basis points)", "type": "number", "readonly": true }, { "key": "amount_minor", "type": "amount", "currency": "currency", "readonly": true, "name": "Amount" }, { "key": "currency", "type": "text", "readonly": true }, { "key": "cue", "type": "choice", "choices": [ "unaccounted", "unverified" ], "readonly": true, "labels": { "unaccounted": "Not sorted yet", "unverified": "Without proof" } }, { "key": "verb", "type": "choice", "choices": [ "spent", "received", "transfer", "lent", "borrowed", "repaid_by_me", "repaid_to_me" ], "readonly": true }, { "key": "money_account_id", "type": "link", "link_to": "money_account", "readonly": true, "name": "Account", "contributes": false }, { "key": "to_account_id", "type": "link", "link_to": "money_account", "readonly": true, "name": "To", "contributes": false }, { "key": "category_account_id", "type": "link", "link_to": "money_account", "readonly": true, "name": "Category", "contributes": false }, { "key": "statement_id", "name": "Statement", "type": "link", "link_to": "statement", "readonly": true }, { "key": "statement_line_id", "name": "Statement line", "type": "link", "link_to": "statement_line", "readonly": true, "contributes": false }, { "key": "can_delete", "type": "bool", "readonly": true }, { "key": "needs", "name": "Needs", "type": "choice", "choices": [ "sorting" ], "labels": { "sorting": "Not sorted yet" }, "readonly": true, "red_when": [ "sorting" ] }, { "key": "category", "name": "Went on", "type": "text", "readonly": true }, { "key": "can_classify", "type": "bool", "readonly": true }, { "key": "email_thread_id", "name": "From mail", "type": "link", "link_to": "email_thread", "readonly": true } ], "title": "description", "date": "occurred_on", "project": null, "order": null, "slip": { "title": "title", "subtitle": null, "trailing": null, "photo": null, "toggle": null, "figure": "amount_minor", "title_fallback": "description", "caption": { "columns": [ "occurred_on", "category", "cue" ] } }, "views": [{"face": "chart", "name": "Money out by month", "sizes": ["medium", "large"], "chart": {"kind": "bar", "x": "occurred_on", "y": "amount_minor", "by": "month", "where": {"status": "posted"}, "sign": "negative"}}], "tile": { "face": "slip-list" }, "page": [ { "heading": null, "columns": [ "description", "recorded_as", "occurred_on", "category_account_id", "needs", "money_account_id", "to_account_id", "statement_id", "email_thread_id" ], "figure": "amount_minor" }, { "heading": "Details", "columns": [ "counterparty_person_id", "status", "due_date", "period_start", "period_end", "gst_amount_minor", "gst_rate_bps", "settles_transaction_id", "notes" ], "role": "side" }, { "heading": "Classified", "columns": [ "classified_by", "confidence_bps" ], "role": "side" }, { "heading": "Lines", "columns": [], "list": { "table": "transaction_line", "link": "transaction_id" }, "role": "side" }, { "heading": "Evidence", "columns": [], "list": { "table": "evidence", "link": "transaction_id" }, "role": "side" } ], "instructions": "A movement (this table, transaction) is money that moved on one day; the owner calls it a movement. Its amounts live on its lines, one per account, in integer minor units; a filed bank or card statement is the source and every transaction points at the statement line it came from. Proposed transactions are not yet posted. Never make up an amount, a payee or a category the evidence does not show. Generic create takes either a sentence in description alone (\"spent 450 on groceries at Quay Street Grocer\" — the amount, the category it names and the payee are read from it, today, in the account money_account_id names, else the usual account; with several accounts and none usual nothing is written and create answers {ask: {question, column, options}} — create again with that column set to the option picked) or the capture inputs: verb, amount_minor (positive integer minor units), money_account_id, optional to_account_id/category_account_id and occurred_on. These capture inputs build lines once; update changes only the envelope. title is who it was with, else what it was for; amount_minor is one amount from the owner's side (spent and lent below zero, received and borrowed above it, a move between the owner's own accounts unsigned). Engine amounts, classification and relationships are read-only. Only a movement recorded by hand can be deleted — can_delete is true on exactly those; one read from a statement has a statement line behind it and would come back at the next reading.", "derived": true, "delete_when": { "column": "can_delete", "present": true }, "sort": { "column": "occurred_on", "descending": true }, "search": [ "description", "payee_text" ], "commands": [ { "id": "classify", "label": "Classify", "kind": "update", "verb": "classify_transaction", "bindings": { "id": "$id" }, "pick": { "kind": "record", "table": "money_account", "argument": "categoryAccountId", "where": { "subtype": "category", "section": [ "income", "spending" ] } }, "receipt": "Classified as {picked}", "when": { "can_classify": true } }, { "id": "delete", "label": "Delete", "kind": "delete", "verb": "delete_record", "data": { "table": "transaction" }, "bindings": { "id": "$id" }, "when": { "can_delete": true }, "confirm": "Undo on the receipt brings it back.", "receipt": "Deleted", "does": "destroys" }, { "id": "open-category-account-id", "label": "Open category", "kind": "open", "opens": "category_account_id" }, { "id": "open-counterparty-person-id", "label": "Open person", "kind": "open", "opens": "counterparty_person_id" }, { "id": "open-money-account-id", "label": "Open account", "kind": "open", "opens": "money_account_id" }, { "id": "open-settles-transaction-id", "label": "Open settles", "kind": "open", "opens": "settles_transaction_id" }, { "id": "open-statement-id", "label": "Open statement", "kind": "open", "opens": "statement_id" }, { "id": "open-statement-line-id", "label": "Open line", "kind": "open", "opens": "statement_line_id" }, { "id": "open-to-account-id", "label": "Open to", "kind": "open", "opens": "to_account_id" }], "parts": { "shape": "desk", "head": { "facts": [ "recorded_as", "occurred_on" ] }, "links": [], "lists": [ { "table": "transaction_line", "relation": "transaction_id", "heading": "Lines" }, { "table": "evidence", "relation": "transaction_id", "heading": "Evidence" } ], "acts": { "more": [ "classify", "open-category-account-id", "open-counterparty-person-id", "open-money-account-id", "open-settles-transaction-id", "open-statement-id", "open-statement-line-id", "open-to-account-id" ], "away": "delete" }, "cards": [ { "column": "amount_minor" }, { "column": "category" }, { "column": "status" }, { "column": "due_date" }, { "column": "gst_amount_minor" }, { "column": "notes", "row": true } ], "strip": []}, "tables": [ { "name": "cotton_money_transactions", "columns": [ { "name": "id", "type": "TEXT", "default": null, "nullable": true, "primary_key": true, "declaration": "\n id TEXT PRIMARY KEY", "position": 0 }, { "name": "workspace_id", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n workspace_id TEXT NOT NULL", "position": 1 }, { "name": "occurred_on", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n occurred_on TEXT NOT NULL", "position": 2 }, { "name": "description", "type": "TEXT", "default": "''", "nullable": false, "primary_key": false, "declaration": "\n description TEXT NOT NULL DEFAULT ''", "position": 3 }, { "name": "payee_text", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n payee_text TEXT", "position": 4 }, { "name": "counterparty_person_id", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n counterparty_person_id TEXT", "position": 5 }, { "name": "status", "type": "TEXT", "default": "'posted'", "nullable": false, "primary_key": false, "declaration": "\n status TEXT NOT NULL DEFAULT 'posted'", "position": 6 }, { "name": "source", "type": "TEXT", "default": "'manual'", "nullable": false, "primary_key": false, "declaration": "\n source TEXT NOT NULL DEFAULT 'manual'", "position": 7 }, { "name": "external_hash", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n external_hash TEXT", "position": 8 }, { "name": "gst_amount_minor", "type": "INTEGER", "default": null, "nullable": true, "primary_key": false, "declaration": "\n gst_amount_minor INTEGER", "position": 9 }, { "name": "gst_rate_bps", "type": "INTEGER", "default": null, "nullable": true, "primary_key": false, "declaration": "\n gst_rate_bps INTEGER", "position": 10 }, { "name": "notes", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n notes TEXT", "position": 11 }, { "name": "settles_transaction_id", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n settles_transaction_id TEXT", "position": 12 }, { "name": "due_date", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n due_date TEXT", "position": 13 }, { "name": "period_start", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n period_start TEXT", "position": 14 }, { "name": "period_end", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n period_end TEXT", "position": 15 }, { "name": "classified_by", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n classified_by TEXT", "position": 16 }, { "name": "classified_by_label", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n classified_by_label TEXT", "position": 17 }, { "name": "confidence_bps", "type": "INTEGER", "default": null, "nullable": true, "primary_key": false, "declaration": "\n confidence_bps INTEGER", "position": 18 }, { "name": "source_inbox_id", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n source_inbox_id TEXT", "position": 19 }, { "name": "created_by", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n created_by TEXT", "position": 20 }, { "name": "created_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n created_at TEXT NOT NULL", "position": 21 }, { "name": "updated_at", "type": "TEXT", "default": null, "nullable": false, "primary_key": false, "declaration": "\n updated_at TEXT NOT NULL", "position": 22 }, { "name": "_hlc", "type": "TEXT", "default": "''", "nullable": false, "primary_key": false, "declaration": "\n _hlc TEXT NOT NULL DEFAULT ''", "position": 23 }, { "name": "_born", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n _born TEXT", "position": 24 }, { "name": "trashed_at", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n trashed_at TEXT", "position": 25 }, { "name": "classified_at", "type": "TEXT", "default": null, "nullable": true, "primary_key": false, "declaration": "\n classified_at TEXT", "position": 26 } ], "constraints": [ { "declaration": "\n CHECK ((classified_by IS NULL) OR (classified_by IN ('import', 'assistant', 'owner')))", "position": 27 }, { "declaration": "\n CHECK ((confidence_bps IS NULL) OR ((confidence_bps >= 0) AND (confidence_bps <= 10000)))", "position": 28 }, { "declaration": "\n CHECK ((period_start IS NULL) OR (period_end IS NULL) OR (period_end >= period_start))", "position": 29 }, { "declaration": "\n CHECK ((settles_transaction_id IS NULL) OR (settles_transaction_id <> id))", "position": 30 }, { "declaration": "\n CHECK (source IN ('capture', 'manual', 'import', 'system', 'schedule', 'migration', 'statement', 'external'))", "position": 31 }, { "declaration": "\n CHECK (status IN ('posted', 'proposed'))", "position": 32 }, { "declaration": "\n FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n ", "position": 33 } ], "prefix": "CREATE TABLE \"cotton_money_transactions\" (", "suffix": ")", "indexes": [ "CREATE INDEX idx_cotton_money_transactions_unclassified ON cotton_money_transactions (workspace_id, occurred_on DESC) WHERE classified_by IS NULL", "CREATE INDEX idx_cotton_money_transactions_due ON cotton_money_transactions (due_date) WHERE due_date IS NOT NULL", "CREATE INDEX idx_cotton_money_transactions_person ON cotton_money_transactions (counterparty_person_id) WHERE counterparty_person_id IS NOT NULL", "CREATE INDEX idx_cotton_money_transactions_settles ON cotton_money_transactions (settles_transaction_id) WHERE settles_transaction_id IS NOT NULL", "CREATE INDEX idx_cotton_money_transactions_workspace ON cotton_money_transactions (workspace_id)", "CREATE INDEX idx_cotton_money_transactions_workspace_date ON cotton_money_transactions (workspace_id, occurred_on DESC)", "CREATE UNIQUE INDEX uq_cotton_money_transactions_external_hash ON cotton_money_transactions (workspace_id, external_hash) WHERE external_hash IS NOT NULL", "CREATE INDEX IF NOT EXISTS idx_cotton_money_transactions_author ON cotton_money_transactions (substr(_hlc, 20), _hlc)" ], "full_text": [], "triggers": [] } ]}