Cotton code
794 lines · 19.8 KB · JSONRaw
{  "format_version": 1,  "id": "money_account",  "name": "Account",  "plural": "Accounts",  "picture": {"photo":"photo:8dcc818171791b390006092d0c40c1bed9e261c7ce0b3693defa53ced27823d6","object":"tool-money"},  "builtin": true,  "engine": "money",  "record_route": "/money/accounts/[id]",  "derived": true,  "columns": [    {      "key": "name",      "type": "text",      "readonly": true    },    {      "key": "kind",      "type": "text",      "readonly": true    },    {      "key": "subtype",      "type": "text",      "readonly": true    },    {      "key": "currency",      "type": "text",      "readonly": true    },    {      "key": "institution",      "type": "text",      "readonly": true,      "name": "Bank"    },    {      "key": "number_mask",      "type": "text",      "readonly": true,      "name": "Account ending"    },    {      "key": "is_default",      "type": "bool",      "name": "Usual account"    },    {      "key": "balance_minor",      "type": "amount",      "currency": "currency",      "readonly": true,      "name": "Ledger balance"    },    {      "key": "posted_balance_minor",      "type": "amount",      "currency": "currency",      "readonly": true,      "name": "Posted balance"    },    {  "key": "coverage",  "type": "text",  "readonly": true,  "name": "Covers",  "fact": true,  "reading": "{value}"},    {  "key": "gaps",  "type": "text",  "readonly": true,  "name": "Missing statements",  "fact": false,  "reading": "{value}",  "fact_join": "; "},    {      "key": "statement_to",      "type": "date",      "readonly": true,      "name": "Statements up to"    },    {      "key": "is_place",      "type": "bool",      "readonly": true    },    {      "key": "unaccounted",      "type": "number",      "readonly": true,      "name": "To explain",      "units": {        "one": "transaction",        "other": "transactions",        "zero": ""      }    },    {      "key": "unverified",      "type": "number",      "readonly": true,      "name": "To check",      "units": {        "one": "transaction",        "other": "transactions",        "zero": ""      }    },    {      "key": "section",      "type": "choice",      "choices": [        "accounts",        "people",        "income",        "spending",        "other",        "unsorted",        "settled"      ],      "labels": {        "accounts": "Accounts",        "people": "People",        "income": "Money in",        "spending": "Spending",        "other": "Other",        "unsorted": "Not sorted yet",        "settled": "Settled"      },      "readonly": true    },    {  "key": "standing",  "name": "What it is",  "type": "text",  "readonly": true,  "fact": true,  "reading": "{value}"},    {      "key": "balances",      "name": "In each currency",      "type": "text",      "readonly": true    },    {      "key": "shown_minor",      "name": "Balance",      "type": "amount",      "currency": "currency",      "readonly": true    },    {      "key": "holds",      "type": "bool",      "readonly": true    },    {      "key": "asks",      "name": "Needs",      "type": "choice",      "choices": [        "unaccounted"      ],      "labels": {        "unaccounted": "Money to explain"      },      "readonly": true    },    {      "key": "can_be_usual",      "type": "bool",      "readonly": true    },    {      "key": "takes_movements",      "type": "bool",      "readonly": true    },    {      "key": "balance_fact",      "name": "Running balance",      "type": "text",      "readonly": true    },    {      "key": "month_minor",      "name": "Monthly net movement",      "type": "amount",      "currency": "currency",      "readonly": true    },    {      "key": "month_totals",      "name": "This month",      "type": "text",      "readonly": true    }  ],  "title": "name",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "name",    "subtitle": "standing",    "trailing": null,    "photo": null,    "toggle": null,    "figure": "shown_minor",    "byline": {      "column": "asks",      "words": {        "unaccounted": "Money to explain"      },      "ink": "red"    }  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "name"      ],      "hand": [        "standing",        "balances"      ],      "figure": "shown_minor"    },    {      "heading": null,      "columns": [        "coverage"      ],      "when": {        "column": "coverage",        "present": true      }    },    {      "heading": null,      "columns": [        "is_default"      ],      "when": {        "column": "can_be_usual",        "present": true      }    },    {      "heading": null,      "columns": [        "unverified"      ],      "when": {        "column": "asks",        "present": true      },      "note": "Some money here has not been explained yet.",      "ink": "red"    },    {      "heading": "Movements",      "columns": [],      "list": {        "table": "transaction_line",        "link": "account_id",        "limit": 10,        "empty": "No movements in {title} yet"      }    },    {      "heading": "To explain",      "columns": [],      "list": {        "table": "transaction",        "link": "money_account_id",        "where": {          "needs": "sorting"        }      },      "when": {        "column": "asks",        "present": true      },      "role": "side"    },    {      "heading": "Statements",      "columns": [],      "list": {        "table": "statement",        "link": "account_id"      },      "when": {        "column": "statement_to",        "present": true      },      "role": "side"    }  ],  "instructions": "Money engine view: the places money sits, the people it is owed to or by, and the categories it came in under or went on. A read of the list answers the places money sits (shows: section accounts); name section in where for the others — people (a person's ledger with something owed either way, largest first), settled (a person's ledger with nothing owed), income, spending, other, or unsorted (the bucket money nobody has explained waits in). Engine columns are read-only. holds is true for somewhere the owner keeps money (a bank, cash, a wallet, a card); asks says money moved through it that is still to be explained. shown_minor and standing say its balance in the owner's sense (income as what came in, a person's ledger as an unsigned amount that \"Owes you\" or \"You owe\"), while balance_minor is the ledger's figure (an income total turned to read as money in). is_default is the usual account, the one a movement said with no account leaves from: at most one open bank, cash or wallet account is usual (can_be_usual says which may be). update_record with is_default true makes an account the usual one, and the other stops being usual; false turns it off, and with none usual a movement said without an account asks which. To record a movement, create a transaction. balance_fact is the running balance in each currency with its ledger direction. month_minor is the current calendar month’s net movement in the account currency; month_totals says the month and each currency separately. Both include proposals, like the drawn running balance. Monthly account movement includes transfers; it is not household income or spending.",  "delete": false,  "lists": [    {      "heading": "Recent",      "columns": [],      "list": {        "table": "transaction",        "limit": 10,        "whole": "All movements"      }    }  ],  "capture": {    "table": "transaction",    "placeholder": "Spent 450 on groceries…",    "link": "money_account_id",    "when": {      "column": "takes_movements",      "present": true    }  },  "empty": {"title": "No accounts yet"},  "shows": {    "section": "accounts"  },  "group": {    "column": "section",    "sections": [      {        "heading": "Accounts",        "values": [          "accounts"        ]      },      {        "heading": null,        "values": [          "people",          "income",          "spending",          "other",          "unsorted",          "settled"        ]      }    ]  },  "links": [    {      "label": "To explain",      "table": "transaction",      "where": {        "needs": "sorting"      },      "lead": true    },    {      "label": "People",      "table": "money_account",      "where": {        "section": "people"      }    },    {      "label": "Categories",      "table": "money_account",      "where": {        "section": [          "income",          "spending",          "other"        ]      }    },    {      "label": "Statements",      "table": "statement"    },    {      "label": "Settled accounts",      "table": "money_account",      "where": {        "section": "settled"      }    }  ],  "tool": {    "name": "Money",    "tables": [      "money_account",      "transaction",      "transaction_line",      "statement",      "statement_line",      "evidence"    ],    "key": "accounts",    "card_stock": "tan",    "icon": "wallet",    "route": "/money",    "figures": [      {        "read": "overdueClaims",        "many": "{n} overdue"      }    ]  ,"purpose":"Your accounts, spending and money movements."},  "commands": [    {      "id": "record",      "label": "Record transaction",      "kind": "create",      "verb": "create_record",      "data": {        "table": "transaction"      },      "bindings": {        "data.money_account_id": "$id"      },      "pick": {        "kind": "text",        "argument": "data.description"      },      "when": {        "takes_movements": true      },      "receipt": "Transaction recorded",      "does": "moves"    }  ],  "parts": {  "shape": "sheet",  "head": {    "facts": [  "coverage",  "standing"]  },  "links": [],  "lists": [    {      "table": "transaction_line",      "relation": "account_id",      "heading": "Movements"    },    {      "table": "transaction",      "relation": "money_account_id",      "heading": "To explain"    },    {      "table": "statement",      "relation": "account_id",      "heading": "Statements"    }  ],  "acts": {    "main": "record",    "more": []  },  "cards": [  {    "column": "shown_minor"  },  {    "column": "month_minor",    "label": "this month"  },  {    "column": "unaccounted"  },  {    "column": "unverified"  },  {    "column": "is_default"  }],  "strip": []},  "tables": [    {      "name": "cotton_money_aliases",      "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": "alias",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    alias TEXT NOT NULL",          "position": 2        },        {          "name": "category_account_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    category_account_id TEXT",          "position": 3        },        {          "name": "person_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    person_id TEXT",          "position": 4        },        {          "name": "source",          "type": "TEXT",          "default": "'import'",          "nullable": false,          "primary_key": false,          "declaration": "\n    source TEXT NOT NULL DEFAULT 'import'",          "position": 5        },        {          "name": "project_ids",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    project_ids TEXT",          "position": 6        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 7        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 8        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 9        }      ],      "constraints": [        {          "declaration": "\n    CHECK (source IN ('import', 'capture', 'manual'))",          "position": 10        },        {          "declaration": "\n    FOREIGN KEY (category_account_id) REFERENCES cotton_money_accounts(id)",          "position": 11        },        {          "declaration": "\n    FOREIGN KEY (person_id) REFERENCES cotton_people(id)",          "position": 12        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 13        }      ],      "prefix": "CREATE TABLE cotton_money_aliases (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_money_aliases_workspace ON cotton_money_aliases (workspace_id)",        "CREATE UNIQUE INDEX uq_cotton_money_aliases_alias ON cotton_money_aliases (workspace_id, lower(alias))",        "CREATE INDEX IF NOT EXISTS idx_cotton_money_aliases_author ON cotton_money_aliases (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    },    {      "name": "cotton_money_accounts",      "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": "kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    kind TEXT NOT NULL",          "position": 2        },        {          "name": "subtype",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    subtype TEXT NOT NULL",          "position": 3        },        {          "name": "name",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    name TEXT NOT NULL",          "position": 4        },        {          "name": "counterparty_person_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    counterparty_person_id TEXT",          "position": 5        },        {          "name": "currency",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    currency TEXT NOT NULL",          "position": 6        },        {          "name": "institution",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    institution TEXT",          "position": 7        },        {          "name": "number_mask",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    number_mask TEXT",          "position": 8        },        {          "name": "is_default",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    is_default INTEGER NOT NULL DEFAULT 0",          "position": 9        },        {          "name": "archived_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    archived_at TEXT",          "position": 10        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 11        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 12        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 13        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 14        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " trashed_at TEXT",          "position": 15        }      ],      "constraints": [        {          "declaration": "\n    CHECK (kind IN ('asset', 'liability', 'income', 'expense', 'equity'))",          "position": 16        },        {          "declaration": "\n    CHECK (subtype IN ('bank', 'cash', 'credit_card', 'wallet', 'receivable', 'payable', 'loan', 'lent_out', 'fixed_asset', 'suspense', 'category'))",          "position": 17        },        {          "declaration": "\n    FOREIGN KEY (counterparty_person_id) REFERENCES cotton_people(id)",          "position": 18        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 19        }      ],      "prefix": "CREATE TABLE \"cotton_money_accounts\" (",      "suffix": ")",      "indexes": [        "CREATE UNIQUE INDEX uq_cotton_money_accounts_identity ON cotton_money_accounts (workspace_id, institution, number_mask) WHERE (institution IS NOT NULL) AND (number_mask IS NOT NULL)",        "CREATE INDEX idx_cotton_money_accounts_person ON cotton_money_accounts (counterparty_person_id) WHERE counterparty_person_id IS NOT NULL",        "CREATE INDEX idx_cotton_money_accounts_workspace ON cotton_money_accounts (workspace_id)",        "CREATE UNIQUE INDEX uq_cotton_money_accounts_default ON cotton_money_accounts (workspace_id) WHERE is_default = 1",        "CREATE UNIQUE INDEX uq_cotton_money_accounts_person_claim ON cotton_money_accounts (workspace_id, counterparty_person_id, subtype, currency) WHERE (counterparty_person_id IS NOT NULL) AND (subtype IN ('receivable', 'payable', 'lent_out', 'loan'))",        "CREATE INDEX IF NOT EXISTS idx_cotton_money_accounts_author ON cotton_money_accounts (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ]}