# contract_advance

## Description

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

```sql
CREATE TABLE `contract_advance` (
  `contract_advance_id` mediumint unsigned NOT NULL AUTO_INCREMENT,
  `contract_id` mediumint unsigned NOT NULL,
  `reference_payment_type_id` smallint unsigned DEFAULT NULL,
  `reference_advance_payment_method_id` smallint unsigned DEFAULT NULL,
  `advance_description` varchar(180) NOT NULL,
  `amount` decimal(20,2) NOT NULL,
  `vat_amount` decimal(20,2) DEFAULT NULL,
  `withholding_tax_amount` decimal(20,2) DEFAULT NULL,
  `amount_after_withholding_and_vat` decimal(20,2) DEFAULT NULL,
  `us_source_income_rate` decimal(9,6) unsigned DEFAULT NULL,
  `currency_code` char(3) NOT NULL,
  `milestone` enum('contract_execution','delivery','recoupment','scheduled_installment','sales_milestone','other') NOT NULL,
  `milestone_description` text NOT NULL,
  `milestone_date` date DEFAULT NULL,
  `advance_status` enum('not_qualified','qualified','approved','paid','deleted','in_review','pending_payment') NOT NULL DEFAULT 'not_qualified',
  `note` varchar(255) DEFAULT NULL,
  `created_by` varchar(255) NOT NULL,
  `created_at` datetime NOT NULL,
  `last_modified_by` varchar(255) NOT NULL,
  `last_modified` datetime NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` varchar(180) DEFAULT NULL,
  PRIMARY KEY (`contract_advance_id`),
  KEY `fk_contract_contract_advance` (`contract_id`),
  KEY `fk_contract_advance_reference_advance_payment_method` (`reference_advance_payment_method_id`),
  KEY `fk_contract_advance_reference_payment_type` (`reference_payment_type_id`),
  CONSTRAINT `fk_contract_advance_reference_advance_payment_method` FOREIGN KEY (`reference_advance_payment_method_id`) REFERENCES `reference_advance_payment_method` (`reference_advance_payment_method_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_contract_advance_reference_payment_type` FOREIGN KEY (`reference_payment_type_id`) REFERENCES `reference_payment_type` (`reference_payment_type_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_contract_contract_advance` FOREIGN KEY (`contract_id`) REFERENCES `contract` (`contract_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb3
```

</details>

## Columns

| Name                                | Type                                                                                                 | Default       | Nullable | Extra Definition | Children                                                                                                                                                                                                  | Parents                                                                 | Comment |
| ----------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------- | -------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------- |
| advance_description                 | varchar(180)                                                                                         |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| advance_status                      | enum('not_qualified','qualified','approved','paid','deleted','in_review','pending_payment')          | not_qualified | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| amount                              | decimal(20,2)                                                                                        |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| amount_after_withholding_and_vat    | decimal(20,2)                                                                                        |               | true     |                  |                                                                                                                                                                                                           |                                                                         |         |
| contract_advance_id                 | mediumint unsigned                                                                                   |               | false    | auto_increment   | [contract_advance_history](contract_advance_history.md) [ledger_contract_advance_applied](ledger_contract_advance_applied.md) [worksheet_payment_contract_advance](worksheet_payment_contract_advance.md) |                                                                         |         |
| contract_id                         | mediumint unsigned                                                                                   |               | false    |                  |                                                                                                                                                                                                           | [contract](contract.md)                                                 |         |
| created_at                          | datetime                                                                                             |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| created_by                          | varchar(255)                                                                                         |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| currency_code                       | char(3)                                                                                              |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| deleted_at                          | datetime                                                                                             |               | true     |                  |                                                                                                                                                                                                           |                                                                         |         |
| deleted_by                          | varchar(180)                                                                                         |               | true     |                  |                                                                                                                                                                                                           |                                                                         |         |
| last_modified                       | datetime                                                                                             |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| last_modified_by                    | varchar(255)                                                                                         |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| milestone                           | enum('contract_execution','delivery','recoupment','scheduled_installment','sales_milestone','other') |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| milestone_date                      | date                                                                                                 |               | true     |                  |                                                                                                                                                                                                           |                                                                         |         |
| milestone_description               | text                                                                                                 |               | false    |                  |                                                                                                                                                                                                           |                                                                         |         |
| note                                | varchar(255)                                                                                         |               | true     |                  |                                                                                                                                                                                                           |                                                                         |         |
| reference_advance_payment_method_id | smallint unsigned                                                                                    |               | true     |                  |                                                                                                                                                                                                           | [reference_advance_payment_method](reference_advance_payment_method.md) |         |
| reference_payment_type_id           | smallint unsigned                                                                                    |               | true     |                  |                                                                                                                                                                                                           | [reference_payment_type](reference_payment_type.md)                     |         |
| us_source_income_rate               | decimal(9,6) unsigned                                                                                |               | true     |                  |                                                                                                                                                                                                           |                                                                         |         |
| vat_amount                          | decimal(20,2)                                                                                        |               | true     |                  |                                                                                                                                                                                                           |                                                                         |         |
| withholding_tax_amount              | decimal(20,2)                                                                                        |               | true     |                  |                                                                                                                                                                                                           |                                                                         |         |

## Constraints

| Name                                                 | Type        | Definition                                                                                                                          |
| ---------------------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| PRIMARY                                              | PRIMARY KEY | PRIMARY KEY (contract_advance_id)                                                                                                   |
| fk_contract_advance_reference_advance_payment_method | FOREIGN KEY | FOREIGN KEY (reference_advance_payment_method_id) REFERENCES reference_advance_payment_method (reference_advance_payment_method_id) |
| fk_contract_advance_reference_payment_type           | FOREIGN KEY | FOREIGN KEY (reference_payment_type_id) REFERENCES reference_payment_type (reference_payment_type_id)                               |
| fk_contract_contract_advance                         | FOREIGN KEY | FOREIGN KEY (contract_id) REFERENCES contract (contract_id)                                                                         |

## Indexes

| Name                                                 | Definition                                                                                                 |
| ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| PRIMARY                                              | PRIMARY KEY (contract_advance_id) USING BTREE                                                              |
| fk_contract_advance_reference_advance_payment_method | KEY fk_contract_advance_reference_advance_payment_method (reference_advance_payment_method_id) USING BTREE |
| fk_contract_advance_reference_payment_type           | KEY fk_contract_advance_reference_payment_type (reference_payment_type_id) USING BTREE                     |
| fk_contract_contract_advance                         | KEY fk_contract_contract_advance (contract_id) USING BTREE                                                 |

## Triggers

| Name                          | Definition                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| after_contract_advance_update | CREATE TRIGGER after_contract_advance_update AFTER UPDATE ON contract_advance<br />FOR EACH ROW<br />BEGIN<br />	INSERT INTO `contract_advance_history`(<br />		`contract_advance_id`,<br />		`contract_id`,<br />		`reference_payment_type_id`,<br />		`reference_advance_payment_method_id`,<br />	    `advance_description`,<br />		`amount`,<br />	    `vat_amount`,<br />	    `withholding_tax_amount`,<br />	    `amount_after_withholding_and_vat`,<br />	    `us_source_income_rate`,<br />		`currency_code`,<br />		`milestone`,<br />		`milestone_description`,<br />		`milestone_date`,<br />		`advance_status`,<br />		`note`,<br />		`created_by`,<br />		`created_at`,<br />		`last_modified_by`,<br />		`last_modified`,<br />		`deleted_at`,<br />		`deleted_by`<br />	) VALUES (<br />		old.contract_advance_id,<br />		old.contract_id,<br />		old.reference_payment_type_id,<br />		old.reference_advance_payment_method_id,<br />	    old.advance_description,<br />		old.amount,<br />	    old.vat_amount,<br />	    old.withholding_tax_amount,<br />	    old.amount_after_withholding_and_vat,<br />	    old.us_source_income_rate,<br />		old.currency_code,<br />		old.milestone,<br />		old.milestone_description,<br />		old.milestone_date,<br />		old.advance_status,<br />		old.note,<br />		old.created_by,<br />		old.created_at,<br />		old.last_modified_by,<br />		old.last_modified,<br />		old.deleted_at,<br />		old.deleted_by<br />	);<br />END |

## Relations

![er](contract_advance.svg)

---

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