Cotton code
487 lines · 11.6 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": false    },    {      "key": "kind",      "type": "choice",      "choices": [        "bank",        "credit_card",        "cash",        "wallet",        "loan"      ],      "readonly": true    },    {      "key": "currency",      "type": "text",      "readonly": true    },    {      "key": "institution",      "name": "Held at",      "type": "text",      "readonly": true    },    {      "key": "number_mask",      "name": "Account ending",      "type": "account_number",      "readonly": true,      "fact": true,      "reading": "ending {value}"    },    {      "key": "is_pooled",      "name": "Pooled",      "type": "bool",      "readonly": false    },    {      "key": "balance_minor",      "name": "Balance",      "type": "amount",      "currency": "currency",      "readonly": true    }  ],  "title": "name",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "name",    "subtitle": [      "kind",      "number_mask"    ],    "trailing": null,    "photo": null,    "toggle": null,    "figure": "balance_minor"  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "name",        "kind",        "institution",        "is_pooled"      ],      "figure": "balance_minor"    },    {      "heading": "Statements",      "columns": [],      "list": {        "table": "statement",        "link": "account_id"      },      "role": "side"    }  ],  "instructions": "An account is a bank, card, cash, wallet or loan account. Loan statements are booked like bank statements and the balance is what is still owed.",  "parts": {    "shape": "sheet",    "head": {      "facts": [        "kind",        "institution"      ]    },    "links": [],    "lists": [      {        "table": "statement",        "relation": "account_id",        "heading": "Statements"      }    ],    "acts": {      "more": []    },    "cards": [      {"column": "kind"},      {"column": "institution"},      {"column": "is_pooled"}    ]  },  "tool": {    "views": [      {        "id": "all",        "label": "All",        "is_default": true,        "visibility": "owner",        "read": {          "table": "money_account"        }      },      {        "id": "between_us",        "label": "Between us",        "is_default": false,        "visibility": "owner",        "read": {          "table": "owed"        },        "partition": "counterparty_person_id"      }    ],    "name": "Money",    "tables": [      "money_account",      "transaction",      "statement",      "statement_line",      "evidence"    ],    "key": "accounts",    "card_stock": "tan",    "icon": "wallet",    "route": "/money",    "purpose": "Accounts and money rows.",    "figures": [      {        "read": "in_month",        "many": "In {n} this month",        "summary": {          "table": "transaction",          "op": "sum",          "column": "amount_minor",          "where": {            "status": "actual",            "moves_money": true,            "direction": "in"          },          "period": "this_month"        }      },      {        "read": "out_month",        "many": "Out {n} this month",        "summary": {          "table": "transaction",          "op": "sum",          "column": "amount_minor",          "where": {            "status": "actual",            "moves_money": true,            "direction": "out"          },          "period": "this_month"        }      },      {        "read": "accounts_held",        "many": "{n}",        "summary": {          "table": "money_account",          "op": "sum",          "column": "balance_minor",          "where": {            "kind": [              "bank",              "cash",              "wallet"            ]          }        },        "term": true      },      {        "read": "accounts_owed",        "many": "{n}",        "summary": {          "table": "money_account",          "op": "sum",          "column": "balance_minor",          "where": {            "kind": [              "credit_card",              "loan"            ]          }        },        "term": true      },      {        "read": "owed_to_you",        "many": "{n}",        "summary": {          "table": "transaction",          "op": "sum",          "column": "amount_minor",          "where": {            "status": "actual",            "between_us": true,            "direction": "out"          }        },        "term": true      },      {        "read": "you_owe",        "many": "{n}",        "summary": {          "table": "transaction",          "op": "sum",          "column": "amount_minor",          "where": {            "status": "actual",            "between_us": true,            "direction": "in"          }        },        "term": true      },      {        "read": "worth",        "many": "Worth {n}",        "formula": {          "plus": [            "accounts_held",            "owed_to_you"          ],          "minus": [            "accounts_owed",            "you_owe"          ]        }      }    ]  },  "links": [    {      "label": "So far",      "table": "so_far"    },    {      "label": "Ahead",      "table": "ahead"    },    {      "label": "Owed",      "table": "owed"    },    {      "label": "Months",      "table": "months",      "when": {        "database": "project"      }    }  ],  "tables": [    {      "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": "is_pooled",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    is_pooled INTEGER CHECK (is_pooled IS NULL OR is_pooled IN (0,1))",          "position": 10        },        {          "name": "archived_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    archived_at TEXT",          "position": 11        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 12        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_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        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " trashed_at TEXT",          "position": 16        }      ],      "constraints": [        {          "declaration": "\n    CHECK (kind IN ('asset', 'liability', 'income', 'expense', 'equity', 'loan'))",          "position": 17        },        {          "declaration": "\n    CHECK (subtype IN ('bank', 'cash', 'credit_card', 'wallet', 'receivable', 'payable', 'loan', 'lent_out', 'fixed_asset'))",          "position": 18        },        {          "declaration": "\n    FOREIGN KEY (counterparty_person_id) REFERENCES cotton_people(id)",          "position": 19        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 20        }      ],      "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 INDEX IF NOT EXISTS idx_cotton_money_accounts_author ON cotton_money_accounts (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "add": false,  "delete": false}