# worksheet_flowthrough_batch

## Description

Batches of flowthrough data from file uploads, UI entry, or automatic generation. Tracks processing and approval statuses.

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

```sql
CREATE TABLE `worksheet_flowthrough_batch` (
  `worksheet_flowthrough_batch_id` mediumint unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key.',
  `statement_period_id` mediumint unsigned NOT NULL COMMENT 'Foreign key to statement_period table.',
  `source_file_upload_id` mediumint unsigned DEFAULT NULL COMMENT 'The uploaded source file that created this batch. NULL for manual/auto batch types.',
  `batch_type` enum('auto','manual','upload') NOT NULL COMMENT 'Batch creation type: auto (generated), manual (UI entry), upload (file upload).',
  `batch_status` enum('pending','scanning','validating','importing','pending_approval','approved','rejected','error') NOT NULL DEFAULT 'pending' COMMENT 'Processing and approval status: pending (queued), scanning (AV check), validating (rules check), importing (writing to DB), pending_approval (awaiting human review), approved (accepted), rejected (declined), error (failed processing).',
  `errors` json DEFAULT NULL COMMENT 'Array of error codes. Example: ["HEADER_MISSING"]. NULL if no errors. See table reference_worksheet_flowthrough_batch_error for codes.',
  `error_row_count` mediumint unsigned DEFAULT NULL COMMENT 'Number of batch rows with errors.',
  `row_level_error_count` mediumint unsigned DEFAULT NULL COMMENT 'Number of errors in batch rows (a single row can have multiple errors). Does not include batch-level errors.',
  `total_row_count` mediumint unsigned DEFAULT NULL COMMENT 'Total number of batch rows. See worksheet_flowthrough for row data.',
  `total_amount` decimal(30,2) DEFAULT NULL COMMENT 'Sum of imported amounts after rounding (mixed currencies, not normalized).',
  `total_amount_raw` decimal(40,12) DEFAULT NULL COMMENT 'Sum of raw amounts from source (mixed currencies, not normalized). Used as checksum to verify import integrity.',
  `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_batch_id`),
  KEY `fk_worksheet_flowthrough_batch_statement_period` (`statement_period_id`),
  KEY `fk_worksheet_flowthrough_batch_source_file` (`source_file_upload_id`),
  KEY `idx_batch_status` (`batch_status`) COMMENT 'For filtering by status.',
  KEY `idx_created_at` (`created_at`) COMMENT 'For sorting by creation date.',
  CONSTRAINT `fk_worksheet_flowthrough_batch_source_file` FOREIGN KEY (`source_file_upload_id`) REFERENCES `file_upload` (`file_upload_id`) ON DELETE SET NULL,
  CONSTRAINT `fk_worksheet_flowthrough_batch_statement_period` FOREIGN KEY (`statement_period_id`) REFERENCES `statement_period` (`statement_period_id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='Batches of flowthrough data from file uploads, UI entry, or automatic generation. Tracks processing and approval statuses.'
```

</details>

## Columns

| Name                           | Type                                                                                                 | Default           | Nullable | Extra Definition                              | Children                                                                                                      | Parents                                 | Comment                                                                                                                                                                                                                                    |
| ------------------------------ | ---------------------------------------------------------------------------------------------------- | ----------------- | -------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| batch_status                   | enum('pending','scanning','validating','importing','pending_approval','approved','rejected','error') | pending           | false    |                                               |                                                                                                               |                                         | Processing and approval status: pending (queued), scanning (AV check), validating (rules check), importing (writing to DB), pending_approval (awaiting human review), approved (accepted), rejected (declined), error (failed processing). |
| batch_type                     | enum('auto','manual','upload')                                                                       |                   | false    |                                               |                                                                                                               |                                         | Batch creation type: auto (generated), manual (UI entry), upload (file upload).                                                                                                                                                            |
| created_at                     | datetime                                                                                             | CURRENT_TIMESTAMP | false    | DEFAULT_GENERATED                             |                                                                                                               |                                         |                                                                                                                                                                                                                                            |
| created_by                     | varchar(180)                                                                                         |                   | false    |                                               |                                                                                                               |                                         |                                                                                                                                                                                                                                            |
| deleted_at                     | datetime                                                                                             |                   | true     |                                               |                                                                                                               |                                         |                                                                                                                                                                                                                                            |
| deleted_by                     | varchar(180)                                                                                         |                   | true     |                                               |                                                                                                               |                                         |                                                                                                                                                                                                                                            |
| error_row_count                | mediumint unsigned                                                                                   |                   | true     |                                               |                                                                                                               |                                         | Number of batch rows with errors.                                                                                                                                                                                                          |
| errors                         | json                                                                                                 |                   | true     |                                               |                                                                                                               |                                         | Array of error codes. Example: ["HEADER_MISSING"]. NULL if no errors. See table reference_worksheet_flowthrough_batch_error for codes.                                                                                                     |
| last_modified                  | datetime                                                                                             | CURRENT_TIMESTAMP | false    | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |                                                                                                               |                                         |                                                                                                                                                                                                                                            |
| last_modified_by               | varchar(180)                                                                                         |                   | false    |                                               |                                                                                                               |                                         |                                                                                                                                                                                                                                            |
| row_level_error_count          | mediumint unsigned                                                                                   |                   | true     |                                               |                                                                                                               |                                         | Number of errors in batch rows (a single row can have multiple errors). Does not include batch-level errors.                                                                                                                               |
| source_file_upload_id          | mediumint unsigned                                                                                   |                   | true     |                                               |                                                                                                               | [file_upload](file_upload.md)           | The uploaded source file that created this batch. NULL for manual/auto batch types.                                                                                                                                                        |
| statement_period_id            | mediumint unsigned                                                                                   |                   | false    |                                               |                                                                                                               | [statement_period](statement_period.md) | Foreign key to statement_period table.                                                                                                                                                                                                     |
| total_amount                   | decimal(30,2)                                                                                        |                   | true     |                                               |                                                                                                               |                                         | Sum of imported amounts after rounding (mixed currencies, not normalized).                                                                                                                                                                 |
| total_amount_raw               | decimal(40,12)                                                                                       |                   | true     |                                               |                                                                                                               |                                         | Sum of raw amounts from source (mixed currencies, not normalized). Used as checksum to verify import integrity.                                                                                                                            |
| total_row_count                | mediumint unsigned                                                                                   |                   | true     |                                               |                                                                                                               |                                         | Total number of batch rows. See worksheet_flowthrough for row data.                                                                                                                                                                        |
| worksheet_flowthrough_batch_id | mediumint unsigned                                                                                   |                   | false    | auto_increment                                | [worksheet_flowthrough](worksheet_flowthrough.md) [worksheet_flowthrough_file](worksheet_flowthrough_file.md) |                                         | Primary key.                                                                                                                                                                                                                               |

## Constraints

| Name                                            | Type        | Definition                                                                          |
| ----------------------------------------------- | ----------- | ----------------------------------------------------------------------------------- |
| PRIMARY                                         | PRIMARY KEY | PRIMARY KEY (worksheet_flowthrough_batch_id)                                        |
| fk_worksheet_flowthrough_batch_source_file      | FOREIGN KEY | FOREIGN KEY (source_file_upload_id) REFERENCES file_upload (file_upload_id)         |
| fk_worksheet_flowthrough_batch_statement_period | FOREIGN KEY | FOREIGN KEY (statement_period_id) REFERENCES statement_period (statement_period_id) |

## Indexes

| Name                                            | Definition                                                                            |
| ----------------------------------------------- | ------------------------------------------------------------------------------------- |
| PRIMARY                                         | PRIMARY KEY (worksheet_flowthrough_batch_id) USING BTREE                              |
| fk_worksheet_flowthrough_batch_source_file      | KEY fk_worksheet_flowthrough_batch_source_file (source_file_upload_id) USING BTREE    |
| fk_worksheet_flowthrough_batch_statement_period | KEY fk_worksheet_flowthrough_batch_statement_period (statement_period_id) USING BTREE |
| idx_batch_status                                | KEY idx_batch_status (batch_status) USING BTREE                                       |
| idx_created_at                                  | KEY idx_created_at (created_at) USING BTREE                                           |

## Relations

![er](worksheet_flowthrough_batch.svg)

---

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