Cotton code
380 lines · 9.4 KB · JSONRaw
{  "format_version": 1,  "id": "statement_line",  "name": "Statement line",  "plural": "Statement lines",  "builtin": true,  "visibility": "owner",  "date": "posted_on",  "columns": [    {      "key": "statement_id",      "name": "Statement",      "type": "link",      "link_to": "statement",      "required": true,      "readonly": true    },    {      "key": "page",      "type": "number",      "readonly": true    },    {      "key": "line_no",      "type": "number",      "readonly": true    },    {      "key": "posted_on",      "name": "Date",      "type": "date",      "format": "calendar-datetime",      "readonly": true,      "fact": true,      "reading": "{value}"    },    {      "key": "text",      "name": "As the bank wrote it",      "type": "text",      "readonly": true    },    {      "key": "amount_minor",      "name": "Amount",      "type": "amount",      "readonly": true,      "currency": "currency",      "signed": true    },    {      "key": "direction",      "type": "text",      "readonly": true    },    {      "key": "balance_after_minor",      "name": "Balance after",      "type": "amount",      "readonly": true,      "currency": "currency"    },    {      "key": "reference",      "type": "text",      "readonly": true    },    {      "key": "fingerprint",      "type": "text",      "readonly": true    },    {      "key": "ignored_reason",      "name": "Skipped because",      "type": "text",      "readonly": true    },    {      "key": "title",      "name": "With",      "type": "text",      "readonly": true    },    {      "key": "currency",      "type": "text",      "readonly": true    },    {      "key": "state",      "type": "choice",      "choices": [        "recorded",        "unread",        "skipped"      ],      "readonly": true,      "labels": {        "recorded": "Recorded",        "unread": "Not recorded yet",        "skipped": "Skipped"      }    },    {      "key": "transaction_id",      "name": "Recorded as",      "type": "link",      "link_to": "transaction",      "readonly": true    }  ],  "instructions": "Money engine view: one line as a statement printed it. title is the bank's words tidied for reading; text is exactly as the bank wrote them. Engine columns are read-only.",  "tables": [    {      "name": "cotton_money_statement_lines",      "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": "statement_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    statement_id TEXT NOT NULL",          "position": 2        },        {          "name": "page",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    page INTEGER NOT NULL",          "position": 3        },        {          "name": "line_no",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    line_no INTEGER NOT NULL",          "position": 4        },        {          "name": "posted_on",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    posted_on TEXT NOT NULL",          "position": 5        },        {          "name": "text",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    text TEXT NOT NULL",          "position": 6        },        {          "name": "amount_minor",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    amount_minor INTEGER NOT NULL",          "position": 7        },        {          "name": "direction",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    direction TEXT NOT NULL",          "position": 8        },        {          "name": "balance_after_minor",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    balance_after_minor INTEGER",          "position": 9        },        {          "name": "reference",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    reference TEXT",          "position": 10        },        {          "name": "fingerprint",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    fingerprint TEXT NOT NULL",          "position": 11        },        {          "name": "ignored_reason",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    ignored_reason TEXT",          "position": 12        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 13        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 14        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 15        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (statement_id, line_no)",          "position": 16        },        {          "declaration": "\n    CHECK (amount_minor > 0)",          "position": 17        },        {          "declaration": "\n    CHECK (direction IN ('in', 'out'))",          "position": 18        },        {          "declaration": "\n    CHECK (length(trim(text)) > 0)",          "position": 19        },        {          "declaration": "\n    CHECK (line_no >= 1)",          "position": 20        },        {          "declaration": "\n    CHECK (page >= 1)",          "position": 21        },        {          "declaration": "\n    FOREIGN KEY (statement_id) REFERENCES cotton_money_statements(id)",          "position": 22        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 23        }      ],      "prefix": "CREATE TABLE cotton_money_statement_lines (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_money_statement_lines_statement ON cotton_money_statement_lines (statement_id, line_no)",        "CREATE INDEX idx_cotton_money_statement_lines_workspace ON cotton_money_statement_lines (workspace_id)",        "CREATE UNIQUE INDEX uq_cotton_money_statement_lines_fingerprint ON cotton_money_statement_lines (statement_id, fingerprint)",        "CREATE INDEX idx_cotton_money_statement_lines_fingerprint ON cotton_money_statement_lines (fingerprint)",        "CREATE INDEX IF NOT EXISTS idx_cotton_money_statement_lines_author ON cotton_money_statement_lines (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": [        "CREATE TRIGGER cotton_money_statement_lines_no_delete_booked\n       BEFORE DELETE ON cotton_money_statement_lines\n       WHEN EXISTS (SELECT 1 FROM cotton_money_evidence AS e WHERE e.kind = 'statement_line' AND e.ref_id = OLD.id)\n       BEGIN SELECT RAISE(ABORT, 'a booked statement line is never deleted'); END"      ]    }  ],  "picture": null,  "engine": "money",  "title": "title",  "project": null,  "order": null,  "slip": {    "title": "title",    "subtitle": "state",    "trailing": "posted_on",    "photo": null,    "toggle": null,    "title_fallback": "text",    "figure": "amount_minor"  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "title",        "text",        "amount_minor",        "posted_on",        "state",        "transaction_id",        "statement_id",        "balance_after_minor",        "ignored_reason"      ]    }  ],  "search": [    "text"  ],  "delete": false,  "derived": true,  "parts": {    "shape": "sheet",    "head": {      "facts": [        "posted_on"      ],      "state": "state"    },    "links": [],    "lists": [],    "acts": {      "more": []    },    "cards": [      {        "column": "amount_minor"      },      {        "column": "text",        "label": "Bank's words"      },      {        "column": "balance_after_minor"      },      {        "column": "ignored_reason"      }    ],    "strip": []  }}