Cotton code
681 lines · 17.3 KB · JSONRaw
{  "format_version": 1,  "id": "transaction",  "name": "Money row",  "plural": "Money",  "builtin": true,  "visibility": "owner",  "date": "occurred_on",  "title": "description",  "columns": [    {      "key": "occurred_on",      "name": "Date",      "type": "date",      "format": "calendar-datetime"    },    {      "key": "description",      "name": "What",      "type": "text"    },    {      "key": "payee_text",      "name": "Payee",      "type": "text",      "readonly": true    },    {      "key": "account_id",      "type": "link",      "link_to": "money_account",      "name": "Account"    },    {      "key": "counterparty_person_id",      "name": "Person",      "type": "link",      "link_to": "person"    },    {      "key": "amount_minor",      "name": "Amount",      "type": "amount",      "currency": "currency"    },    {      "key": "amount_known",      "type": "bool",      "name": "Amount known"    },    {      "key": "direction",      "type": "choice",      "choices": [        "in",        "out"      ]    },    {      "key": "currency",      "type": "text"    },    {      "key": "for_period",      "type": "text",      "name": "For month"    },    {      "key": "status",      "type": "choice",      "choices": [        "posted",        "proposed",        "actual",        "expected"      ],      "labels": {        "posted": "Posted",        "proposed": "Suggested"      }    },    {      "key": "certainty",      "type": "choice",      "choices": [        "fixed",        "expected",        "estimate"      ]    },    {      "key": "repeat",      "type": "choice",      "choices": [        "none",        "monthly"      ]    },    {      "key": "repeat_day",      "type": "number",      "name": "Repeat day"    },    {      "key": "between_us",      "type": "bool",      "name": "Between us"    },    {      "key": "moves_money",      "type": "bool",      "name": "Moves money"    },    {      "key": "tag",      "type": "text"    },    {      "key": "transfer_of",      "type": "link",      "readonly": true,      "name": "Transfer",      "link_to": "transaction"    },    {      "key": "source",      "type": "text",      "readonly": true    },    {      "key": "external_hash",      "type": "text",      "readonly": true    },    {      "key": "notes",      "type": "longtext"    },    {      "key": "settles_transaction_id",      "name": "Settles",      "type": "link",      "link_to": "transaction",      "readonly": true    },    {      "key": "due_date",      "name": "Due",      "type": "date"    },    {      "key": "source_inbox_id",      "type": "text",      "readonly": true    },    {      "key": "created_by",      "type": "text",      "readonly": true    },    {      "key": "trashed_at",      "type": "date",      "format": "calendar-datetime",      "readonly": true    },    {      "key": "title",      "name": "With",      "type": "text",      "readonly": true    },    {      "key": "can_delete",      "type": "bool",      "readonly": true    },    {      "key": "email_thread_id",      "name": "From mail",      "type": "link",      "link_to": "email_thread",      "readonly": true    },    {      "key": "balance_before_minor",      "name": "Balance before",      "type": "amount",      "currency": "currency",      "readonly": true    },    {      "key": "balance_after_minor",      "name": "Balance after",      "type": "amount",      "currency": "currency",      "readonly": true    },    {      "key": "balance_state",      "name": "Balance state",      "type": "choice",      "choices": [        "ok",        "overdrawn",        "recovers"      ],      "readonly": true    }  ],  "instructions": "One money row is either actual or expected. It has one account, one direction and one amount when known. A statement-booked row stays in the record.",  "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": "account_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    account_id TEXT",          "position": 5        },        {          "name": "counterparty_person_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    counterparty_person_id TEXT",          "position": 6        },        {          "name": "amount_minor",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    amount_minor INTEGER",          "position": 7        },        {          "name": "amount_known",          "type": "INTEGER",          "default": "1",          "nullable": false,          "primary_key": false,          "declaration": "\n    amount_known INTEGER NOT NULL DEFAULT 1 CHECK (amount_known IN (0,1))",          "position": 8        },        {          "name": "direction",          "type": "TEXT",          "default": "'out'",          "nullable": false,          "primary_key": false,          "declaration": "\n    direction TEXT NOT NULL DEFAULT 'out' CHECK (direction IN ('in','out'))",          "position": 9        },        {          "name": "currency",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    currency TEXT",          "position": 10        },        {          "name": "for_period",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    for_period TEXT NOT NULL DEFAULT ''",          "position": 11        },        {          "name": "status",          "type": "TEXT",          "default": "'actual'",          "nullable": false,          "primary_key": false,          "declaration": "\n    status TEXT NOT NULL DEFAULT 'actual' CHECK (status IN ('actual','expected'))",          "position": 12        },        {          "name": "certainty",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    certainty TEXT CHECK (certainty IS NULL OR certainty IN ('fixed','expected','estimate'))",          "position": 13        },        {          "name": "repeat",          "type": "TEXT",          "default": "'none'",          "nullable": false,          "primary_key": false,          "declaration": "\n    repeat TEXT NOT NULL DEFAULT 'none' CHECK (repeat IN ('none','monthly'))",          "position": 14        },        {          "name": "repeat_day",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    repeat_day INTEGER CHECK (repeat_day IS NULL OR repeat_day BETWEEN 1 AND 31)",          "position": 15        },        {          "name": "between_us",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    between_us INTEGER NOT NULL DEFAULT 0 CHECK (between_us IN (0,1))",          "position": 16        },        {          "name": "moves_money",          "type": "INTEGER",          "default": "1",          "nullable": false,          "primary_key": false,          "declaration": "\n    moves_money INTEGER NOT NULL DEFAULT 1 CHECK (moves_money IN (0,1))",          "position": 17        },        {          "name": "tag",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    tag TEXT",          "position": 18        },        {          "name": "transfer_of",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    transfer_of TEXT",          "position": 19        },        {          "name": "source",          "type": "TEXT",          "default": "'manual'",          "nullable": false,          "primary_key": false,          "declaration": "\n    source TEXT NOT NULL DEFAULT 'manual'",          "position": 20        },        {          "name": "external_hash",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    external_hash TEXT",          "position": 21        },        {          "name": "notes",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    notes TEXT",          "position": 22        },        {          "name": "settles_transaction_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    settles_transaction_id TEXT",          "position": 23        },        {          "name": "due_date",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    due_date TEXT",          "position": 24        },        {          "name": "source_inbox_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    source_inbox_id TEXT",          "position": 25        },        {          "name": "created_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    created_by TEXT",          "position": 26        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 27        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 28        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 29        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 30        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    trashed_at TEXT",          "position": 31        }      ],      "constraints": [        {          "declaration": "\n    CHECK ((settles_transaction_id IS NULL) OR (settles_transaction_id <> id))",          "position": 32        },        {          "declaration": "\n    CHECK (source IN ('capture', 'manual', 'import', 'system', 'schedule', 'migration', 'statement', 'external'))",          "position": 33        },        {          "declaration": "\n    FOREIGN KEY (account_id) REFERENCES cotton_money_accounts(id)",          "position": 34        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 35        }      ],      "prefix": "CREATE TABLE \"cotton_money_transactions\" (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_money_transactions_balance ON cotton_money_transactions (workspace_id,account_id,currency,occurred_on,CASE WHEN direction='in' THEN amount_minor ELSE -amount_minor END,direction,amount_minor,status,amount_known,moves_money,trashed_at) WHERE status='actual' AND amount_known=1 AND moves_money=1 AND trashed_at IS NULL",        "CREATE INDEX idx_cotton_money_transactions_glance ON cotton_money_transactions (workspace_id,trashed_at,between_us,status,direction,currency,amount_minor)",        "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_account ON cotton_money_transactions (account_id) WHERE account_id IS NOT NULL",        "CREATE INDEX idx_cotton_money_transactions_expected ON cotton_money_transactions (workspace_id,occurred_on,id,due_date,currency,direction,amount_minor,trashed_at) WHERE status='expected'",        "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": []    }  ],  "picture": {    "photo": "photo:d3020bbe260bf41f313f8116af2a6ee38a7c9ee0ff72794fa86448e88d0b42e6"  },  "engine": "money",  "project": null,  "order": null,  "slip": {    "title": "title",    "subtitle": "tag",    "trailing": "occurred_on",    "photo": null,    "toggle": null,    "title_fallback": "description",    "figure": "amount_minor"  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "description",        "occurred_on",        "account_id",        "status",        "certainty",        "for_period",        "counterparty_person_id",        "tag",        "due_date",        "notes"      ],      "figure": "amount_minor"    },    {      "heading": "Evidence",      "columns": [],      "list": {        "table": "evidence",        "link": "transaction_id"      },      "role": "side"    }  ],  "record_route": "/money/transactions/[id]",  "sort": {    "column": "occurred_on",    "descending": true  },  "search": [    "description",    "tag"  ],  "delete_when": {    "column": "can_delete",    "present": true  },  "deletion": {    "bin": true  },  "links": [    {      "label": "Deleted",      "table": "bin",      "where": {        "table": "transaction"      }    }  ],  "derived": true,  "card": {    "face": "transaction.receipt",    "faces": [      {        "when": {          "column": "direction",          "values": [            "in"          ]        },        "face": "transaction.cheque"      }    ],    "fields": [      {        "slot": "title",        "column": "description"      },      {        "slot": "subtitle",        "column": "tag"      },      {        "slot": "body",        "column": "notes"      },      {        "slot": "date",        "column": "occurred_on",        "form": "weekday_date"      },      {        "slot": "amount",        "column": "amount_minor"      },      {        "slot": "account",        "column": "account_id"      },      {        "slot": "state",        "column": "status",        "only": [          "expected"        ]      },      {        "slot": "facts",        "column": "balance_before_minor",        "also": [          "balance_after_minor"        ]      }    ],    "corner": [      {        "column": "occurred_on",        "form": "relative",        "within": 0,        "ahead": true,        "line": "corner.today"      }    ],    "offers": [      "transaction.receipt",      "transaction"    ]  }}