# ledger_correction

## Description

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

```sql
CREATE TABLE `ledger_correction` (
  `ledger_correction_id` mediumint unsigned NOT NULL AUTO_INCREMENT,
  `abacus_event_id` mediumint unsigned NOT NULL,
  `worksheet_correction_id` mediumint unsigned NOT NULL,
  `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(20,2) NOT NULL,
  `distribution_fee` decimal(20,2) NOT NULL,
  `mechanical_deduction_total` decimal(20,2) DEFAULT NULL,
  `mechanical_deduction_admin_fee_total` decimal(20,2) DEFAULT NULL,
  `net_revenue` decimal(20,2) NOT NULL,
  `note` mediumtext COLLATE utf8mb4_general_ci,
  `created_at` datetime NOT NULL,
  `created_by` varchar(180) COLLATE utf8mb4_general_ci NOT NULL,
  `last_modified` datetime NOT NULL,
  `last_modified_by` varchar(180) COLLATE utf8mb4_general_ci NOT NULL,
  PRIMARY KEY (`ledger_correction_id`),
  KEY `fk_ledger_correction_abacus_event` (`abacus_event_id`),
  KEY `fk_ledger_correction_worksheet_correction` (`worksheet_correction_id`),
  KEY `fk_ledger_correction_account` (`account_id`),
  KEY `fk_ledger_correction_contract` (`contract_id`),
  KEY `fk_ledger_correction_statement_period` (`statement_period_id`),
  KEY `fk_ledger_correction_correction_statement_period` (`correction_statement_period_id`),
  CONSTRAINT `fk_ledger_correction_abacus_event` FOREIGN KEY (`abacus_event_id`) REFERENCES `abacus_event` (`abacus_event_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ledger_correction_account` FOREIGN KEY (`account_id`) REFERENCES `account` (`account_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ledger_correction_contract` FOREIGN KEY (`contract_id`) REFERENCES `contract` (`contract_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ledger_correction_correction_statement_period` FOREIGN KEY (`correction_statement_period_id`) REFERENCES `statement_period` (`statement_period_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ledger_correction_statement_period` FOREIGN KEY (`statement_period_id`) REFERENCES `statement_period` (`statement_period_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `fk_ledger_correction_worksheet_correction` FOREIGN KEY (`worksheet_correction_id`) REFERENCES `worksheet_correction` (`worksheet_correction_id`) ON DELETE RESTRICT 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 |
| ------------------------------------ | --------------------------------------------- | ------- | -------- | ---------------- | -------- | ----------------------------------------------- | ------- |
| abacus_event_id                      | mediumint unsigned                            |         | false    |                  |          | [abacus_event](abacus_event.md)                 |         |
| 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(180)                                  |         | false    |                  |          |                                                 |         |
| currency_code                        | char(3)                                       |         | false    |                  |          |                                                 |         |
| distribution_fee                     | decimal(20,2)                                 |         | false    |                  |          |                                                 |         |
| gross_revenue                        | decimal(20,2)                                 |         | false    |                  |          |                                                 |         |
| last_modified                        | datetime                                      |         | false    |                  |          |                                                 |         |
| last_modified_by                     | varchar(180)                                  |         | false    |                  |          |                                                 |         |
| ledger_correction_id                 | mediumint unsigned                            |         | false    | auto_increment   |          |                                                 |         |
| mechanical_deduction_admin_fee_total | decimal(20,2)                                 |         | true     |                  |          |                                                 |         |
| mechanical_deduction_total           | decimal(20,2)                                 |         | true     |                  |          |                                                 |         |
| net_revenue                          | decimal(20,2)                                 |         | false    |                  |          |                                                 |         |
| note                                 | mediumtext                                    |         | true     |                  |          |                                                 |         |
| statement_period_id                  | mediumint unsigned                            |         | false    |                  |          | [statement_period](statement_period.md)         |         |
| worksheet_correction_id              | mediumint unsigned                            |         | false    |                  |          | [worksheet_correction](worksheet_correction.md) |         |

## Constraints

| Name                                             | Type        | Definition                                                                                      |
| ------------------------------------------------ | ----------- | ----------------------------------------------------------------------------------------------- |
| PRIMARY                                          | PRIMARY KEY | PRIMARY KEY (ledger_correction_id)                                                              |
| fk_ledger_correction_abacus_event                | FOREIGN KEY | FOREIGN KEY (abacus_event_id) REFERENCES abacus_event (abacus_event_id)                         |
| fk_ledger_correction_account                     | FOREIGN KEY | FOREIGN KEY (account_id) REFERENCES account (account_id)                                        |
| fk_ledger_correction_contract                    | FOREIGN KEY | FOREIGN KEY (contract_id) REFERENCES contract (contract_id)                                     |
| fk_ledger_correction_correction_statement_period | FOREIGN KEY | FOREIGN KEY (correction_statement_period_id) REFERENCES statement_period (statement_period_id)  |
| fk_ledger_correction_statement_period            | FOREIGN KEY | FOREIGN KEY (statement_period_id) REFERENCES statement_period (statement_period_id)             |
| fk_ledger_correction_worksheet_correction        | FOREIGN KEY | FOREIGN KEY (worksheet_correction_id) REFERENCES worksheet_correction (worksheet_correction_id) |

## Indexes

| Name                                             | Definition                                                                                        |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
| PRIMARY                                          | PRIMARY KEY (ledger_correction_id) USING BTREE                                                    |
| fk_ledger_correction_abacus_event                | KEY fk_ledger_correction_abacus_event (abacus_event_id) USING BTREE                               |
| fk_ledger_correction_account                     | KEY fk_ledger_correction_account (account_id) USING BTREE                                         |
| fk_ledger_correction_contract                    | KEY fk_ledger_correction_contract (contract_id) USING BTREE                                       |
| fk_ledger_correction_correction_statement_period | KEY fk_ledger_correction_correction_statement_period (correction_statement_period_id) USING BTREE |
| fk_ledger_correction_statement_period            | KEY fk_ledger_correction_statement_period (statement_period_id) USING BTREE                       |
| fk_ledger_correction_worksheet_correction        | KEY fk_ledger_correction_worksheet_correction (worksheet_correction_id) USING BTREE               |

## Relations

![er](ledger_correction.svg)

---

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