# worksheet_correction

## Description

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

```sql
CREATE TABLE `worksheet_correction` (
  `worksheet_correction_id` mediumint unsigned NOT NULL AUTO_INCREMENT,
  `account_id` mediumint unsigned NOT NULL,
  `contract_id` mediumint unsigned DEFAULT NULL,
  `statement_period_id` mediumint unsigned NOT NULL,
  `correction_statement_period_id` mediumint unsigned NOT NULL,
  `correction_type` enum('royalty_reversal','royalty_correction') COLLATE utf8mb4_general_ci NOT NULL,
  `currency_code` char(3) COLLATE utf8mb4_general_ci NOT NULL,
  `gross_revenue` decimal(38,18) NOT NULL,
  `distribution_fee` decimal(38,18) NOT NULL,
  `mechanical_deduction_total` decimal(38,18) DEFAULT NULL,
  `mechanical_deduction_admin_fee_total` decimal(38,18) DEFAULT NULL,
  `net_revenue` decimal(38,18) NOT NULL,
  `note` mediumtext COLLATE utf8mb4_general_ci,
  `created_at` datetime NOT NULL,
  `created_by` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `last_modified` datetime NOT NULL,
  `last_modified_by` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`worksheet_correction_id`),
  KEY `fk_account_worksheet_correction` (`account_id`),
  KEY `fk_contract_worksheet_correction` (`contract_id`),
  KEY `fk_statement_period_worksheet_correction` (`statement_period_id`),
  KEY `fk_correction_statement_period_worksheet_correction` (`correction_statement_period_id`),
  CONSTRAINT `fk_account_worksheet_correction` FOREIGN KEY (`account_id`) REFERENCES `account` (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_contract_worksheet_correction` FOREIGN KEY (`contract_id`) REFERENCES `contract` (`contract_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_correction_statement_period_worksheet_correction` FOREIGN KEY (`correction_statement_period_id`) REFERENCES `statement_period` (`statement_period_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_statement_period_worksheet_correction` FOREIGN KEY (`statement_period_id`) REFERENCES `statement_period` (`statement_period_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
```

</details>

## Columns

| Name                                 | Type                                          | Default | Nullable | Extra Definition | Children                                  | Parents                                 | Comment |
| ------------------------------------ | --------------------------------------------- | ------- | -------- | ---------------- | ----------------------------------------- | --------------------------------------- | ------- |
| account_id                           | mediumint unsigned                            |         | false    |                  |                                           | [account](account.md)                   |         |
| contract_id                          | mediumint unsigned                            |         | true     |                  |                                           | [contract](contract.md)                 |         |
| correction_statement_period_id       | mediumint unsigned                            |         | false    |                  |                                           | [statement_period](statement_period.md) |         |
| correction_type                      | enum('royalty_reversal','royalty_correction') |         | false    |                  |                                           |                                         |         |
| created_at                           | datetime                                      |         | false    |                  |                                           |                                         |         |
| created_by                           | varchar(255)                                  |         | false    |                  |                                           |                                         |         |
| currency_code                        | char(3)                                       |         | false    |                  |                                           |                                         |         |
| deleted_at                           | datetime                                      |         | true     |                  |                                           |                                         |         |
| deleted_by                           | varchar(255)                                  |         | true     |                  |                                           |                                         |         |
| distribution_fee                     | decimal(38,18)                                |         | false    |                  |                                           |                                         |         |
| gross_revenue                        | decimal(38,18)                                |         | false    |                  |                                           |                                         |         |
| last_modified                        | datetime                                      |         | false    |                  |                                           |                                         |         |
| last_modified_by                     | varchar(255)                                  |         | false    |                  |                                           |                                         |         |
| mechanical_deduction_admin_fee_total | decimal(38,18)                                |         | true     |                  |                                           |                                         |         |
| mechanical_deduction_total           | decimal(38,18)                                |         | true     |                  |                                           |                                         |         |
| net_revenue                          | decimal(38,18)                                |         | false    |                  |                                           |                                         |         |
| note                                 | mediumtext                                    |         | true     |                  |                                           |                                         |         |
| statement_period_id                  | mediumint unsigned                            |         | false    |                  |                                           | [statement_period](statement_period.md) |         |
| worksheet_correction_id              | mediumint unsigned                            |         | false    | auto_increment   | [ledger_correction](ledger_correction.md) |                                         |         |

## Constraints

| Name                                                | Type        | Definition                                                                                     |
| --------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------- |
| PRIMARY                                             | PRIMARY KEY | PRIMARY KEY (worksheet_correction_id)                                                          |
| fk_account_worksheet_correction                     | FOREIGN KEY | FOREIGN KEY (account_id) REFERENCES account (account_id)                                       |
| fk_contract_worksheet_correction                    | FOREIGN KEY | FOREIGN KEY (contract_id) REFERENCES contract (contract_id)                                    |
| fk_correction_statement_period_worksheet_correction | FOREIGN KEY | FOREIGN KEY (correction_statement_period_id) REFERENCES statement_period (statement_period_id) |
| fk_statement_period_worksheet_correction            | FOREIGN KEY | FOREIGN KEY (statement_period_id) REFERENCES statement_period (statement_period_id)            |

## Indexes

| Name                                                | Definition                                                                                           |
| --------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| PRIMARY                                             | PRIMARY KEY (worksheet_correction_id) USING BTREE                                                    |
| fk_account_worksheet_correction                     | KEY fk_account_worksheet_correction (account_id) USING BTREE                                         |
| fk_contract_worksheet_correction                    | KEY fk_contract_worksheet_correction (contract_id) USING BTREE                                       |
| fk_correction_statement_period_worksheet_correction | KEY fk_correction_statement_period_worksheet_correction (correction_statement_period_id) USING BTREE |
| fk_statement_period_worksheet_correction            | KEY fk_statement_period_worksheet_correction (statement_period_id) USING BTREE                       |

## Relations

![er](worksheet_correction.svg)

---

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