# worksheet_flowthrough

## Description

Entries for worksheet flowthrough records, tracking individual flowthrough amounts

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `worksheet_flowthrough` (
  `worksheet_flowthrough_id` mediumint unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key.',
  `worksheet_flowthrough_batch_id` mediumint unsigned NOT NULL COMMENT 'Foreign key to worksheet_flowthrough_batch table.',
  `batch_row_index` mediumint unsigned NOT NULL COMMENT 'Zero-based index of this entry within the batch.',
  `source_data` json NOT NULL COMMENT 'Original source data, before validation. Example: {"account_id": "ABC123", "amount": "Not a number", ...}.',
  `account_id` mediumint unsigned DEFAULT NULL COMMENT 'Foreign key to account table. NULL if invalid. Original account ID in source_data.',
  `contract_id` mediumint unsigned DEFAULT NULL COMMENT 'Foreign key to contract table. NULL if invalid. Original contract ID in source_data.',
  `amount` decimal(20,2) DEFAULT NULL COMMENT 'Amount after rounding. NULL if invalid. Original amount in source_data.',
  `amount_raw` decimal(30,12) DEFAULT NULL COMMENT 'Raw amount. NULL if invalid. Original amount in source_data.',
  `activity_month` tinyint unsigned DEFAULT NULL COMMENT 'Activity month (1-12). NULL if invalid. Original month in source_data.',
  `activity_year` smallint unsigned DEFAULT NULL COMMENT 'Activity year (e.g., 2025). NULL if invalid. Original year in source_data.',
  `activity_statement_period_id` mediumint unsigned DEFAULT NULL COMMENT 'Foreign key to statement_period table. Derived from activity_month and activity_year. NULL if statement period could not be determined.',
  `note` mediumtext COMMENT 'User-visible note about this entry. NULL if invalid. Original note in source_data.',
  `internal_note` mediumtext COMMENT 'Internal note for operational purposes. NULL if invalid or not given. Original internal note in source_data.',
  `errors` json DEFAULT NULL COMMENT 'Array of error codes. Example: ["ACCOUNT_ID_NOT_FOUND"]. NULL if no errors. See table reference_worksheet_flowthrough_error for codes.',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_by` varchar(180) NOT NULL,
  `last_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_modified_by` varchar(180) NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` varchar(180) DEFAULT NULL,
  PRIMARY KEY (`worksheet_flowthrough_id`),
  UNIQUE KEY `uidx_batch_row` (`worksheet_flowthrough_batch_id`,`batch_row_index`) COMMENT 'Ensures unique batch row indexes per batch.',
  KEY `fk_worksheet_flowthrough_worksheet_flowthrough_batch` (`worksheet_flowthrough_batch_id`),
  KEY `fk_worksheet_flowthrough_account` (`account_id`),
  KEY `fk_worksheet_flowthrough_contract` (`contract_id`),
  KEY `fk_worksheet_flowthrough_statement_period` (`activity_statement_period_id`),
  CONSTRAINT `fk_worksheet_flowthrough_account` FOREIGN KEY (`account_id`) REFERENCES `account` (`account_id`) ON DELETE CASCADE,
  CONSTRAINT `fk_worksheet_flowthrough_contract` FOREIGN KEY (`contract_id`) REFERENCES `contract` (`contract_id`) ON DELETE CASCADE,
  CONSTRAINT `fk_worksheet_flowthrough_statement_period` FOREIGN KEY (`activity_statement_period_id`) REFERENCES `statement_period` (`statement_period_id`) ON DELETE RESTRICT,
  CONSTRAINT `fk_worksheet_flowthrough_worksheet_flowthrough_batch` FOREIGN KEY (`worksheet_flowthrough_batch_id`) REFERENCES `worksheet_flowthrough_batch` (`worksheet_flowthrough_batch_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='Entries for worksheet flowthrough records, tracking individual flowthrough amounts'
```

</details>

## Columns

| Name                           | Type               | Default           | Nullable | Extra Definition                              | Children | Parents                                                       | Comment                                                                                                                                 |
| ------------------------------ | ------------------ | ----------------- | -------- | --------------------------------------------- | -------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| account_id                     | mediumint unsigned |                   | true     |                                               |          | [account](account.md)                                         | Foreign key to account table. NULL if invalid. Original account ID in source_data.                                                      |
| activity_month                 | tinyint unsigned   |                   | true     |                                               |          |                                                               | Activity month (1-12). NULL if invalid. Original month in source_data.                                                                  |
| activity_statement_period_id   | mediumint unsigned |                   | true     |                                               |          | [statement_period](statement_period.md)                       | Foreign key to statement_period table. Derived from activity_month and activity_year. NULL if statement period could not be determined. |
| activity_year                  | smallint unsigned  |                   | true     |                                               |          |                                                               | Activity year (e.g., 2025). NULL if invalid. Original year in source_data.                                                              |
| amount                         | decimal(20,2)      |                   | true     |                                               |          |                                                               | Amount after rounding. NULL if invalid. Original amount in source_data.                                                                 |
| amount_raw                     | decimal(30,12)     |                   | true     |                                               |          |                                                               | Raw amount. NULL if invalid. Original amount in source_data.                                                                            |
| batch_row_index                | mediumint unsigned |                   | false    |                                               |          |                                                               | Zero-based index of this entry within the batch.                                                                                        |
| contract_id                    | mediumint unsigned |                   | true     |                                               |          | [contract](contract.md)                                       | Foreign key to contract table. NULL if invalid. Original contract ID in source_data.                                                    |
| created_at                     | datetime           | CURRENT_TIMESTAMP | false    | DEFAULT_GENERATED                             |          |                                                               |                                                                                                                                         |
| created_by                     | varchar(180)       |                   | false    |                                               |          |                                                               |                                                                                                                                         |
| deleted_at                     | datetime           |                   | true     |                                               |          |                                                               |                                                                                                                                         |
| deleted_by                     | varchar(180)       |                   | true     |                                               |          |                                                               |                                                                                                                                         |
| errors                         | json               |                   | true     |                                               |          |                                                               | Array of error codes. Example: ["ACCOUNT_ID_NOT_FOUND"]. NULL if no errors. See table reference_worksheet_flowthrough_error for codes.  |
| internal_note                  | mediumtext         |                   | true     |                                               |          |                                                               | Internal note for operational purposes. NULL if invalid or not given. Original internal note in source_data.                            |
| last_modified                  | datetime           | CURRENT_TIMESTAMP | false    | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |          |                                                               |                                                                                                                                         |
| last_modified_by               | varchar(180)       |                   | false    |                                               |          |                                                               |                                                                                                                                         |
| note                           | mediumtext         |                   | true     |                                               |          |                                                               | User-visible note about this entry. NULL if invalid. Original note in source_data.                                                      |
| source_data                    | json               |                   | false    |                                               |          |                                                               | Original source data, before validation. Example: {"account_id": "ABC123", "amount": "Not a number", ...}.                              |
| worksheet_flowthrough_batch_id | mediumint unsigned |                   | false    |                                               |          | [worksheet_flowthrough_batch](worksheet_flowthrough_batch.md) | Foreign key to worksheet_flowthrough_batch table.                                                                                       |
| worksheet_flowthrough_id       | mediumint unsigned |                   | false    | auto_increment                                |          |                                                               | Primary key.                                                                                                                            |

## Constraints

| Name                                                 | Type        | Definition                                                                                                           |
| ---------------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------- |
| PRIMARY                                              | PRIMARY KEY | PRIMARY KEY (worksheet_flowthrough_id)                                                                               |
| fk_worksheet_flowthrough_account                     | FOREIGN KEY | FOREIGN KEY (account_id) REFERENCES account (account_id)                                                             |
| fk_worksheet_flowthrough_contract                    | FOREIGN KEY | FOREIGN KEY (contract_id) REFERENCES contract (contract_id)                                                          |
| fk_worksheet_flowthrough_statement_period            | FOREIGN KEY | FOREIGN KEY (activity_statement_period_id) REFERENCES statement_period (statement_period_id)                         |
| fk_worksheet_flowthrough_worksheet_flowthrough_batch | FOREIGN KEY | FOREIGN KEY (worksheet_flowthrough_batch_id) REFERENCES worksheet_flowthrough_batch (worksheet_flowthrough_batch_id) |
| uidx_batch_row                                       | UNIQUE      | UNIQUE KEY uidx_batch_row (worksheet_flowthrough_batch_id, batch_row_index)                                          |

## Indexes

| Name                                                 | Definition                                                                                            |
| ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| PRIMARY                                              | PRIMARY KEY (worksheet_flowthrough_id) USING BTREE                                                    |
| fk_worksheet_flowthrough_account                     | KEY fk_worksheet_flowthrough_account (account_id) USING BTREE                                         |
| fk_worksheet_flowthrough_contract                    | KEY fk_worksheet_flowthrough_contract (contract_id) USING BTREE                                       |
| fk_worksheet_flowthrough_statement_period            | KEY fk_worksheet_flowthrough_statement_period (activity_statement_period_id) USING BTREE              |
| fk_worksheet_flowthrough_worksheet_flowthrough_batch | KEY fk_worksheet_flowthrough_worksheet_flowthrough_batch (worksheet_flowthrough_batch_id) USING BTREE |
| uidx_batch_row                                       | UNIQUE KEY uidx_batch_row (worksheet_flowthrough_batch_id, batch_row_index) USING BTREE               |

## Relations

![er](worksheet_flowthrough.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
