# royalty_accounting

## Viewpoints

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

## Tables

| Name                                                                                                      | Columns | Comment                                                                                                                    | Type       |
| --------------------------------------------------------------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------- | ---------- |
| [ACC_8715_CONTRACT_OWNER_MAP_SNOWFLAKE](ACC_8715_CONTRACT_OWNER_MAP_SNOWFLAKE.md)                         | 3       |                                                                                                                            | BASE TABLE |
| [ACC_8715_OWNER_SIGNING_ENTITY_MAP_GOOGLE_SHEET](ACC_8715_OWNER_SIGNING_ENTITY_MAP_GOOGLE_SHEET.md)       | 5       |                                                                                                                            | BASE TABLE |
| [ACC_8738_CONTRACT_OWNER_MAP_SNOWFLAKE](ACC_8738_CONTRACT_OWNER_MAP_SNOWFLAKE.md)                         | 3       |                                                                                                                            | BASE TABLE |
| [abacus_event](abacus_event.md)                                                                           | 9       |                                                                                                                            | BASE TABLE |
| [abacus_state](abacus_state.md)                                                                           | 10      |                                                                                                                            | BASE TABLE |
| [abacus_state_history](abacus_state_history.md)                                                           | 11      |                                                                                                                            | BASE TABLE |
| [account](account.md)                                                                                     | 7       |                                                                                                                            | BASE TABLE |
| [account_contract](account_contract.md)                                                                   | 4       |                                                                                                                            | BASE TABLE |
| [account_contract_vat_detail](account_contract_vat_detail.md)                                             | 11      |                                                                                                                            | BASE TABLE |
| [account_payee](account_payee.md)                                                                         | 15      |                                                                                                                            | BASE TABLE |
| [account_payee_history](account_payee_history.md)                                                         | 16      |                                                                                                                            | BASE TABLE |
| [account_payee_kyc_notification](account_payee_kyc_notification.md)                                       | 16      |                                                                                                                            | BASE TABLE |
| [account_payee_kyc_notification_history](account_payee_kyc_notification_history.md)                       | 17      |                                                                                                                            | BASE TABLE |
| [account_payee_tax_form_info](account_payee_tax_form_info.md)                                             | 12      |                                                                                                                            | BASE TABLE |
| [account_payee_tax_form_info_history](account_payee_tax_form_info_history.md)                             | 13      |                                                                                                                            | BASE TABLE |
| [account_payment_term](account_payment_term.md)                                                           | 11      |                                                                                                                            | BASE TABLE |
| [account_payment_term_history](account_payment_term_history.md)                                           | 12      |                                                                                                                            | BASE TABLE |
| [account_payment_term_template](account_payment_term_template.md)                                         | 4       |                                                                                                                            | BASE TABLE |
| [account_tax_info](account_tax_info.md)                                                                   | 15      |                                                                                                                            | BASE TABLE |
| [account_tax_info_history](account_tax_info_history.md)                                                   | 16      |                                                                                                                            | BASE TABLE |
| [accounting_period](accounting_period.md)                                                                 | 12      |                                                                                                                            | BASE TABLE |
| [accounting_period_report](accounting_period_report.md)                                                   | 8       |                                                                                                                            | BASE TABLE |
| [accounting_run](accounting_run.md)                                                                       | 11      |                                                                                                                            | BASE TABLE |
| [contract](contract.md)                                                                                   | 17      |                                                                                                                            | BASE TABLE |
| [contract_advance](contract_advance.md)                                                                   | 22      |                                                                                                                            | BASE TABLE |
| [contract_advance_history](contract_advance_history.md)                                                   | 23      |                                                                                                                            | BASE TABLE |
| [contract_exclusion](contract_exclusion.md)                                                               | 3       |                                                                                                                            | BASE TABLE |
| [contract_flowthrough](contract_flowthrough.md)                                                           | 16      |                                                                                                                            | BASE TABLE |
| [contract_flowthrough_history](contract_flowthrough_history.md)                                           | 17      |                                                                                                                            | BASE TABLE |
| [contract_history](contract_history.md)                                                                   | 17      |                                                                                                                            | BASE TABLE |
| [contract_lifecycle](contract_lifecycle.md)                                                               | 19      |                                                                                                                            | BASE TABLE |
| [contract_lifecycle_bkup_20251015](contract_lifecycle_bkup_20251015.md)                                   | 19      |                                                                                                                            | BASE TABLE |
| [contract_lifecycle_history](contract_lifecycle_history.md)                                               | 19      |                                                                                                                            | BASE TABLE |
| [contract_lifecycle_schedule](contract_lifecycle_schedule.md)                                             | 13      |                                                                                                                            | BASE TABLE |
| [contract_lifecycle_schedule_detail](contract_lifecycle_schedule_detail.md)                               | 3       |                                                                                                                            | BASE TABLE |
| [contract_mechanical_deduction](contract_mechanical_deduction.md)                                         | 12      |                                                                                                                            | BASE TABLE |
| [contract_mechanical_deduction_history](contract_mechanical_deduction_history.md)                         | 13      |                                                                                                                            | BASE TABLE |
| [contract_party](contract_party.md)                                                                       | 10      |                                                                                                                            | BASE TABLE |
| [contract_party_history](contract_party_history.md)                                                       | 11      |                                                                                                                            | BASE TABLE |
| [contract_reserve](contract_reserve.md)                                                                   | 13      |                                                                                                                            | BASE TABLE |
| [contract_template](contract_template.md)                                                                 | 12      |                                                                                                                            | BASE TABLE |
| [contract_term](contract_term.md)                                                                         | 13      |                                                                                                                            | BASE TABLE |
| [contract_term_condition](contract_term_condition.md)                                                     | 13      |                                                                                                                            | BASE TABLE |
| [contract_term_condition_history](contract_term_condition_history.md)                                     | 14      |                                                                                                                            | BASE TABLE |
| [contract_term_history](contract_term_history.md)                                                         | 14      |                                                                                                                            | BASE TABLE |
| [contract_term_schedule](contract_term_schedule.md)                                                       | 9       |                                                                                                                            | BASE TABLE |
| [contract_term_schedule_history](contract_term_schedule_history.md)                                       | 10      |                                                                                                                            | BASE TABLE |
| [deleted_contract](deleted_contract.md)                                                                   | 7       |                                                                                                                            | BASE TABLE |
| [exchange_rate](exchange_rate.md)                                                                         | 9       |                                                                                                                            | BASE TABLE |
| [file_upload](file_upload.md)                                                                             | 23      | Tracks file uploads including S3 location, status, and metadata                                                            | BASE TABLE |
| [file_upload_config](file_upload_config.md)                                                               | 14      | Configurations for different file upload types and their routing rules                                                     | BASE TABLE |
| [historical_contract_advance](historical_contract_advance.md)                                             | 12      | Holds historical advanced payment information.                                                                             | BASE TABLE |
| [json_contract_file_import_status](json_contract_file_import_status.md)                                   | 17      |                                                                                                                            | BASE TABLE |
| [ledger_account](ledger_account.md)                                                                       | 13      |                                                                                                                            | BASE TABLE |
| [ledger_account_contract](ledger_account_contract.md)                                                     | 13      |                                                                                                                            | BASE TABLE |
| [ledger_account_contract_current_balance](ledger_account_contract_current_balance.md)                     | 8       |                                                                                                                            | BASE TABLE |
| [ledger_account_current_balance](ledger_account_current_balance.md)                                       | 7       |                                                                                                                            | BASE TABLE |
| [ledger_accounting_run_balance](ledger_accounting_run_balance.md)                                         | 15      |                                                                                                                            | BASE TABLE |
| [ledger_accounting_run_vat](ledger_accounting_run_vat.md)                                                 | 19      |                                                                                                                            | BASE TABLE |
| [ledger_adjustment](ledger_adjustment.md)                                                                 | 14      |                                                                                                                            | BASE TABLE |
| [ledger_adjustment_adjustment_detail](ledger_adjustment_adjustment_detail.md)                             | 4       |                                                                                                                            | BASE TABLE |
| [ledger_adjustment_adjustment_detail_applied](ledger_adjustment_adjustment_detail_applied.md)             | 3       |                                                                                                                            | BASE TABLE |
| [ledger_adjustment_applied](ledger_adjustment_applied.md)                                                 | 15      |                                                                                                                            | BASE TABLE |
| [ledger_adjustment_detail](ledger_adjustment_detail.md)                                                   | 15      |                                                                                                                            | BASE TABLE |
| [ledger_adjustment_detail_applied](ledger_adjustment_detail_applied.md)                                   | 12      |                                                                                                                            | BASE TABLE |
| [ledger_contract_advance_applied](ledger_contract_advance_applied.md)                                     | 23      |                                                                                                                            | BASE TABLE |
| [ledger_correction](ledger_correction.md)                                                                 | 19      |                                                                                                                            | BASE TABLE |
| [ledger_deposit](ledger_deposit.md)                                                                       | 11      |                                                                                                                            | BASE TABLE |
| [ledger_reserve_release](ledger_reserve_release.md)                                                       | 9       |                                                                                                                            | BASE TABLE |
| [ledger_reserve_release_schedule](ledger_reserve_release_schedule.md)                                     | 14      |                                                                                                                            | BASE TABLE |
| [ledger_reserve_taken](ledger_reserve_taken.md)                                                           | 15      |                                                                                                                            | BASE TABLE |
| [ledger_vat_summary](ledger_vat_summary.md)                                                               | 24      |                                                                                                                            | BASE TABLE |
| [legacy_contract](legacy_contract.md)                                                                     | 3       |                                                                                                                            | BASE TABLE |
| [oa_territory_backfilled_accounts](oa_territory_backfilled_accounts.md)                                   | 5       |                                                                                                                            | BASE TABLE |
| [payee](payee.md)                                                                                         | 11      |                                                                                                                            | BASE TABLE |
| [payee_collaborator](payee_collaborator.md)                                                               | 8       |                                                                                                                            | BASE TABLE |
| [payee_history](payee_history.md)                                                                         | 12      |                                                                                                                            | BASE TABLE |
| [payee_kyc_notification](payee_kyc_notification.md)                                                       | 16      |                                                                                                                            | BASE TABLE |
| [payee_kyc_notification_history](payee_kyc_notification_history.md)                                       | 17      |                                                                                                                            | BASE TABLE |
| [payment_entity_payoneer_program](payment_entity_payoneer_program.md)                                     | 5       |                                                                                                                            | BASE TABLE |
| [payment_group](payment_group.md)                                                                         | 10      |                                                                                                                            | BASE TABLE |
| [payment_group_payment](payment_group_payment.md)                                                         | 10      |                                                                                                                            | BASE TABLE |
| [payment_group_payment_account](payment_group_payment_account.md)                                         | 21      |                                                                                                                            | BASE TABLE |
| [payment_group_payment_account_detail](payment_group_payment_account_detail.md)                           | 16      |                                                                                                                            | BASE TABLE |
| [payment_group_payment_batch](payment_group_payment_batch.md)                                             | 8       |                                                                                                                            | BASE TABLE |
| [payment_group_payment_batch_account](payment_group_payment_batch_account.md)                             | 7       |                                                                                                                            | BASE TABLE |
| [payment_hold](payment_hold.md)                                                                           | 9       |                                                                                                                            | BASE TABLE |
| [payment_hold_history](payment_hold_history.md)                                                           | 11      |                                                                                                                            | BASE TABLE |
| [payment_minimum](payment_minimum.md)                                                                     | 9       |                                                                                                                            | BASE TABLE |
| [reference_adjustment_type](reference_adjustment_type.md)                                                 | 3       |                                                                                                                            | BASE TABLE |
| [reference_advance_payment_method](reference_advance_payment_method.md)                                   | 3       |                                                                                                                            | BASE TABLE |
| [reference_agreement_type](reference_agreement_type.md)                                                   | 2       |                                                                                                                            | BASE TABLE |
| [reference_external_source](reference_external_source.md)                                                 | 9       |                                                                                                                            | BASE TABLE |
| [reference_flowthrough_calculation](reference_flowthrough_calculation.md)                                 | 5       |                                                                                                                            | BASE TABLE |
| [reference_mechanical_rate](reference_mechanical_rate.md)                                                 | 10      |                                                                                                                            | BASE TABLE |
| [reference_payable_detail_type](reference_payable_detail_type.md)                                         | 3       |                                                                                                                            | BASE TABLE |
| [reference_payment_entity](reference_payment_entity.md)                                                   | 7       | AKA "paid_by"; meant to replace signing_entity table                                                                       | BASE TABLE |
| [reference_payment_type](reference_payment_type.md)                                                       | 5       |                                                                                                                            | BASE TABLE |
| [reference_payoneer_program](reference_payoneer_program.md)                                               | 4       |                                                                                                                            | BASE TABLE |
| [reference_sap_profit_center](reference_sap_profit_center.md)                                             | 4       |                                                                                                                            | BASE TABLE |
| [reference_signing_entity](reference_signing_entity.md)                                                   | 9       |                                                                                                                            | BASE TABLE |
| [reference_tax_withholding](reference_tax_withholding.md)                                                 | 9       |                                                                                                                            | BASE TABLE |
| [reference_transaction_type](reference_transaction_type.md)                                               | 3       |                                                                                                                            | BASE TABLE |
| [reference_transaction_type_group](reference_transaction_type_group.md)                                   | 2       |                                                                                                                            | BASE TABLE |
| [reference_transaction_type_group_transaction_type](reference_transaction_type_group_transaction_type.md) | 4       |                                                                                                                            | BASE TABLE |
| [reference_vat_rate](reference_vat_rate.md)                                                               | 14      |                                                                                                                            | BASE TABLE |
| [reference_worksheet_flowthrough_error](reference_worksheet_flowthrough_error.md)                         | 8       | Reference table for worksheet_flowthrough error codes.                                                                     | BASE TABLE |
| [report_custom](report_custom.md)                                                                         | 14      |                                                                                                                            | BASE TABLE |
| [report_payment](report_payment.md)                                                                       | 9       |                                                                                                                            | BASE TABLE |
| [report_payment_group_payment](report_payment_group_payment.md)                                           | 8       |                                                                                                                            | BASE TABLE |
| [run_controller](run_controller.md)                                                                       | 9       |                                                                                                                            | BASE TABLE |
| [run_controller_contract](run_controller_contract.md)                                                     | 8       |                                                                                                                            | BASE TABLE |
| [run_controller_contract_history](run_controller_contract_history.md)                                     | 9       |                                                                                                                            | BASE TABLE |
| [sales_file](sales_file.md)                                                                               | 10      |                                                                                                                            | BASE TABLE |
| [schedule](schedule.md)                                                                                   | 9       |                                                                                                                            | BASE TABLE |
| [schedule_attachment](schedule_attachment.md)                                                             | 10      |                                                                                                                            | BASE TABLE |
| [schedule_attachment_history](schedule_attachment_history.md)                                             | 11      |                                                                                                                            | BASE TABLE |
| [schedule_history](schedule_history.md)                                                                   | 10      |                                                                                                                            | BASE TABLE |
| [statement_attachment](statement_attachment.md)                                                           | 15      |                                                                                                                            | BASE TABLE |
| [statement_attachment_archive_WAR-1131](statement_attachment_archive_WAR-1131.md)                         | 12      |                                                                                                                            | BASE TABLE |
| [statement_period](statement_period.md)                                                                   | 7       |                                                                                                                            | BASE TABLE |
| [statement_period_adjustment_file](statement_period_adjustment_file.md)                                   | 17      |                                                                                                                            | BASE TABLE |
| [statement_period_payment_entity](statement_period_payment_entity.md)                                     | 4       |                                                                                                                            | BASE TABLE |
| [tax_withholding_override](tax_withholding_override.md)                                                   | 9       |                                                                                                                            | BASE TABLE |
| [tax_withholding_override_history](tax_withholding_override_history.md)                                   | 10      |                                                                                                                            | BASE TABLE |
| [vat_summary_file](vat_summary_file.md)                                                                   | 5       |                                                                                                                            | BASE TABLE |
| [worksheet_account_contract_closing_balance](worksheet_account_contract_closing_balance.md)               | 16      |                                                                                                                            | BASE TABLE |
| [worksheet_account_contract_payable_after_tax](worksheet_account_contract_payable_after_tax.md)           | 19      |                                                                                                                            | BASE TABLE |
| [worksheet_account_contract_payable_details](worksheet_account_contract_payable_details.md)               | 19      |                                                                                                                            | BASE TABLE |
| [worksheet_account_contract_taxable_revenue](worksheet_account_contract_taxable_revenue.md)               | 17      |                                                                                                                            | BASE TABLE |
| [worksheet_adjustment](worksheet_adjustment.md)                                                           | 18      |                                                                                                                            | BASE TABLE |
| [worksheet_adjustment_detail](worksheet_adjustment_detail.md)                                             | 20      |                                                                                                                            | BASE TABLE |
| [worksheet_correction](worksheet_correction.md)                                                           | 19      |                                                                                                                            | BASE TABLE |
| [worksheet_flowthrough](worksheet_flowthrough.md)                                                         | 20      | Entries for worksheet flowthrough records, tracking individual flowthrough amounts                                         | BASE TABLE |
| [worksheet_flowthrough_batch](worksheet_flowthrough_batch.md)                                             | 17      | Batches of flowthrough data from file uploads, UI entry, or automatic generation. Tracks processing and approval statuses. | BASE TABLE |
| [worksheet_flowthrough_file](worksheet_flowthrough_file.md)                                               | 13      | Generated download files representing flowthrough batch data in various formats for user consumption.                      | BASE TABLE |
| [worksheet_payment_contract_advance](worksheet_payment_contract_advance.md)                               | 25      |                                                                                                                            | BASE TABLE |
| [worksheet_payment_custom](worksheet_payment_custom.md)                                                   | 17      |                                                                                                                            | BASE TABLE |
| [worksheet_tax_correction](worksheet_tax_correction.md)                                                   | 14      |                                                                                                                            | BASE TABLE |
| [worksheet_tax_correction_vat](worksheet_tax_correction_vat.md)                                           | 23      |                                                                                                                            | BASE TABLE |

## Relations

![er](schema.svg)

---

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