# account_payment_term

## Description

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

```sql
CREATE TABLE `account_payment_term` (
  `account_payment_term_id` mediumint unsigned NOT NULL AUTO_INCREMENT,
  `account_id` mediumint unsigned NOT NULL,
  `currency_code` char(3) COLLATE utf8mb4_general_ci NOT NULL,
  `payment_minimum` decimal(10,2) DEFAULT NULL,
  `payment_entity_id` mediumint unsigned DEFAULT NULL,
  `agreement_type_id` tinyint unsigned DEFAULT NULL,
  `payment_schedule` enum('30_days_after_month_end','45_days_after_month_end','60_days_after_month_end','90_days_after_month_end','30_days_after_quarter_end','45_days_after_quarter_end','60_days_after_quarter_end','90_days_after_quarter_end','30_days_after_half_year_end','45_days_after_half_year_end','60_days_after_half_year_end','90_days_after_half_year_end','TEMPORARY') 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 (`account_payment_term_id`),
  UNIQUE KEY `uidx_account_id` (`account_id`),
  KEY `fk_account_payment_term_agreement_type` (`agreement_type_id`),
  KEY `fk_account_payment_term_payment_entity` (`payment_entity_id`),
  CONSTRAINT `fk_account_payment_term_account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_account_payment_term_agreement_type` FOREIGN KEY (`agreement_type_id`) REFERENCES `reference_agreement_type` (`reference_agreement_type_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_account_payment_term_payment_entity` FOREIGN KEY (`payment_entity_id`) REFERENCES `reference_payment_entity` (`reference_payment_entity_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)                                   |         |
| account_payment_term_id | mediumint unsigned                                                                                                                                                                                                                                                                                                                                                |         | false    | auto_increment   | [account_payment_term_history](account_payment_term_history.md) |                                                         |         |
| agreement_type_id       | tinyint unsigned                                                                                                                                                                                                                                                                                                                                                  |         | true     |                  |                                                                 | [reference_agreement_type](reference_agreement_type.md) |         |
| created_at              | datetime                                                                                                                                                                                                                                                                                                                                                          |         | false    |                  |                                                                 |                                                         |         |
| created_by              | varchar(255)                                                                                                                                                                                                                                                                                                                                                      |         | false    |                  |                                                                 |                                                         |         |
| currency_code           | char(3)                                                                                                                                                                                                                                                                                                                                                           |         | false    |                  |                                                                 |                                                         |         |
| last_modified           | datetime                                                                                                                                                                                                                                                                                                                                                          |         | false    |                  |                                                                 |                                                         |         |
| last_modified_by        | varchar(255)                                                                                                                                                                                                                                                                                                                                                      |         | false    |                  |                                                                 |                                                         |         |
| payment_entity_id       | mediumint unsigned                                                                                                                                                                                                                                                                                                                                                |         | true     |                  |                                                                 | [reference_payment_entity](reference_payment_entity.md) |         |
| payment_minimum         | decimal(10,2)                                                                                                                                                                                                                                                                                                                                                     |         | true     |                  |                                                                 |                                                         |         |
| payment_schedule        | enum('30_days_after_month_end','45_days_after_month_end','60_days_after_month_end','90_days_after_month_end','30_days_after_quarter_end','45_days_after_quarter_end','60_days_after_quarter_end','90_days_after_quarter_end','30_days_after_half_year_end','45_days_after_half_year_end','60_days_after_half_year_end','90_days_after_half_year_end','TEMPORARY') |         | true     |                  |                                                                 |                                                         |         |

## Constraints

| Name                                   | Type        | Definition                                                                                        |
| -------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------- |
| PRIMARY                                | PRIMARY KEY | PRIMARY KEY (account_payment_term_id)                                                             |
| fk_account_payment_term_account_id     | FOREIGN KEY | FOREIGN KEY (account_id) REFERENCES account (account_id)                                          |
| fk_account_payment_term_agreement_type | FOREIGN KEY | FOREIGN KEY (agreement_type_id) REFERENCES reference_agreement_type (reference_agreement_type_id) |
| fk_account_payment_term_payment_entity | FOREIGN KEY | FOREIGN KEY (payment_entity_id) REFERENCES reference_payment_entity (reference_payment_entity_id) |
| uidx_account_id                        | UNIQUE      | UNIQUE KEY uidx_account_id (account_id)                                                           |

## Indexes

| Name                                   | Definition                                                                 |
| -------------------------------------- | -------------------------------------------------------------------------- |
| PRIMARY                                | PRIMARY KEY (account_payment_term_id) USING BTREE                          |
| fk_account_payment_term_agreement_type | KEY fk_account_payment_term_agreement_type (agreement_type_id) USING BTREE |
| fk_account_payment_term_payment_entity | KEY fk_account_payment_term_payment_entity (payment_entity_id) USING BTREE |
| uidx_account_id                        | UNIQUE KEY uidx_account_id (account_id) USING BTREE                        |

## Triggers

| Name                              | Definition                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| after_update_account_payment_term | CREATE TRIGGER after_update_account_payment_term AFTER UPDATE ON account_payment_term<br />FOR EACH ROW<br />BEGIN<br />INSERT INTO `account_payment_term_history`(<br />        `account_payment_term_id`,<br />        `account_id`,<br />        `currency_code`,<br />        `payment_minimum`,<br />        `payment_entity_id`,<br />        `agreement_type_id`,<br />        `payment_schedule`,<br />        `created_by`,<br />        `created_at`,<br />        `last_modified_by`,<br />        `last_modified`<br />    ) VALUES (<br />        old.account_payment_term_id,<br />        old.account_id,<br />        old.currency_code,<br />        old.payment_minimum,<br />        old.payment_entity_id,<br />        old.agreement_type_id,<br />        old.payment_schedule,<br />        old.created_by,<br />        old.created_at,<br />        old.last_modified_by,<br />        old.last_modified<br />    );<br />END |

## Relations

![er](account_payment_term.svg)

---

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