# ledger_account_contract

## Description

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

```sql
CREATE TABLE `ledger_account_contract` (
  `ledger_account_contract_id` mediumint unsigned NOT NULL AUTO_INCREMENT,
  `abacus_event_id` mediumint unsigned NOT NULL,
  `account_id` mediumint unsigned NOT NULL,
  `contract_id` mediumint unsigned NOT NULL,
  `currency_code` char(3) COLLATE utf8mb4_general_ci NOT NULL,
  `currency_amount` decimal(20,2) NOT NULL,
  `previous_balance` decimal(20,2) NOT NULL,
  `current_balance` decimal(20,2) NOT NULL,
  `note` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `created_by` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `created_at` datetime NOT NULL,
  `last_modified_by` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `last_modified` datetime NOT NULL,
  PRIMARY KEY (`ledger_account_contract_id`),
  UNIQUE KEY `uidx_ledger_account_contract_event` (`abacus_event_id`,`account_id`,`contract_id`),
  KEY `fk_ledger_account_contract_account` (`account_id`),
  KEY `fk_ledger_account_contract_contract` (`contract_id`),
  KEY `fk_ledger_account_contract_abacus_event` (`abacus_event_id`),
  CONSTRAINT `fk_ledger_account_contract_abacus_event` FOREIGN KEY (`abacus_event_id`) REFERENCES `abacus_event` (`abacus_event_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT `fk_ledger_account_contract_account` FOREIGN KEY (`account_id`) REFERENCES `account` (`account_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT `fk_ledger_account_contract_contract` FOREIGN KEY (`contract_id`) REFERENCES `contract` (`contract_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) 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 |         | false    |                  |                                                                                                                                                                                   | [contract](contract.md)         |         |
| created_at                 | datetime           |         | false    |                  |                                                                                                                                                                                   |                                 |         |
| created_by                 | varchar(255)       |         | false    |                  |                                                                                                                                                                                   |                                 |         |
| currency_amount            | decimal(20,2)      |         | false    |                  |                                                                                                                                                                                   |                                 |         |
| currency_code              | char(3)            |         | false    |                  |                                                                                                                                                                                   |                                 |         |
| current_balance            | decimal(20,2)      |         | false    |                  |                                                                                                                                                                                   |                                 |         |
| last_modified              | datetime           |         | false    |                  |                                                                                                                                                                                   |                                 |         |
| last_modified_by           | varchar(255)       |         | false    |                  |                                                                                                                                                                                   |                                 |         |
| ledger_account_contract_id | mediumint unsigned |         | false    | auto_increment   | [ledger_account_contract_current_balance](ledger_account_contract_current_balance.md) [worksheet_account_contract_closing_balance](worksheet_account_contract_closing_balance.md) |                                 |         |
| note                       | varchar(255)       |         | true     |                  |                                                                                                                                                                                   |                                 |         |
| previous_balance           | decimal(20,2)      |         | false    |                  |                                                                                                                                                                                   |                                 |         |

## Viewpoints

| Name                          | Definition                                 |
| ----------------------------- | ------------------------------------------ |
| [Flowthrough](viewpoint-0.md) | Tables relevant to processing flowthrough. |

## Constraints

| Name                                    | Type        | Definition                                                                               |
| --------------------------------------- | ----------- | ---------------------------------------------------------------------------------------- |
| PRIMARY                                 | PRIMARY KEY | PRIMARY KEY (ledger_account_contract_id)                                                 |
| fk_ledger_account_contract_abacus_event | FOREIGN KEY | FOREIGN KEY (abacus_event_id) REFERENCES abacus_event (abacus_event_id)                  |
| fk_ledger_account_contract_account      | FOREIGN KEY | FOREIGN KEY (account_id) REFERENCES account (account_id)                                 |
| fk_ledger_account_contract_contract     | FOREIGN KEY | FOREIGN KEY (contract_id) REFERENCES contract (contract_id)                              |
| uidx_ledger_account_contract_event      | UNIQUE      | UNIQUE KEY uidx_ledger_account_contract_event (abacus_event_id, account_id, contract_id) |

## Indexes

| Name                                    | Definition                                                                                           |
| --------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| PRIMARY                                 | PRIMARY KEY (ledger_account_contract_id) USING BTREE                                                 |
| fk_ledger_account_contract_abacus_event | KEY fk_ledger_account_contract_abacus_event (abacus_event_id) USING BTREE                            |
| fk_ledger_account_contract_account      | KEY fk_ledger_account_contract_account (account_id) USING BTREE                                      |
| fk_ledger_account_contract_contract     | KEY fk_ledger_account_contract_contract (contract_id) USING BTREE                                    |
| uidx_ledger_account_contract_event      | UNIQUE KEY uidx_ledger_account_contract_event (abacus_event_id, account_id, contract_id) USING BTREE |

## Triggers

| Name                                 | Definition                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| after_ledger_account_contract_insert | CREATE TRIGGER after_ledger_account_contract_insert AFTER INSERT ON ledger_account_contract<br />FOR EACH ROW<br />BEGIN<br />    INSERT INTO `ledger_account_contract_current_balance`<br />        (ledger_account_contract_id, account_id, contract_id, created_by, created_at, last_modified_by, last_modified)<br />    VALUES<br />        (NEW.ledger_account_contract_id, NEW.account_id, NEW.contract_id, NEW.created_by, NOW(), NEW.last_modified_by, NOW())<br />    ON DUPLICATE KEY UPDATE<br />        ledger_account_contract_id = NEW.ledger_account_contract_id,<br />        last_modified_by = NEW.last_modified_by,<br />        last_modified = NOW();<br />END |

## Relations

![er](ledger_account_contract.svg)

---

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