# View: label_royalties

**View Name:** label_royalties
**Table Source:** `Derived from: Prod.Accounting_Run_Results_Distro, Prod.Contract_Transaction_Staging, Prod.Stmt_Db_Sales_Distro, Prod.Vw_Dim_Abacus_Contract, Prod_Royalty_Accounting_Royalty_Accounting.Account + 3 more`
**File Path:** `views/label_royalties.view.lkml`

## Overview

- **File Size:** 6034 bytes
- **Lines of Code:** 189
- **Dimensions:** 14
- **Measures:** 10
- **Dimension Groups:** 0
- **Filters:** 0

## Dimensions

| Name | Type |
|------|------|
| `Statement_Period_ID` | string |
| `Statement_Period_Name` | string |
| `Accounting_Run_ID` | string |
| `Accounting_Run_Name` | string |
| `Account_ID` | string |
| `Account_Name` | string |
| `Contract_ID` | string |
| `Contract_Name` | string |
| `Store` | string |
| `Country_Name` | string |
| `Term_Rate` | number |
| `Payee_Currency` | string |
| `company_code` | string |
| `sale_currency` | string |

## Measures

| Name | Type |
|------|------|
| `Total_Gross_Payee_Currency` | sum |
| `Total_WHT_Payee_Currency` | sum |
| `Total_Gross_After_WHT_Payee_Currency` | sum |
| `Net_Revenue_Payee_Currency` | sum |
| `Total_Distribution_Fee_Payee_Currency` | sum |
| `Total_Gross_sale_Currency` | sum |
| `Total_WHT_sale_Currency` | sum |
| `Total_Gross_After_WHT_sale_Currency` | sum |
| `Net_Revenue_sale_Currency` | sum |
| `Total_Distribution_Fee_sale_Currency` | sum |

## SQL Comments

- Payee Currency
- contract
- filter out any contracts not KNR label
- account
- contract conditions

## Derived Table

```sql
sql:
      select
    asp.statement_period_id Statement_Period_ID,
    asp.statement_period_name Statement_Period_Name,
    arr.accounting_run_id Accounting_Run_ID,
    arr.accounting_run_name Accounting_Run_Name,
    cts.account_id Account_ID,
    a.account_name Account_Name,
    cts.contract_id Contract_ID,
    c.contract_name Contract_Name,
    cmm.customer_name Store,
    cn.iso3166a3 Country_Name,
    arr.term_rate Term_Rate,
    ac.company_code,
-- Payee Currency
    apt.currency_code Payee_Currency,
    txn.sale_currency_code as sale_currency,
    round(sum(arr.gross_revenue_sale_currency),5) Total_Gross_Sale_Currency,
    round(sum(arr.withholding_tax_sale_currency),5) Total_WHT_Sale_Currency,
    round(sum(arr.gross_revenue_after_withholding_tax_sale_currency),5) Total_Gross_After_WHT_Sale_Currency,
    round(sum(arr.net_revenue_sale_currency),5) Net_Revenue_Sale_Currency,
    round(sum(arr.distribution_fee_sale_currency),5) Total_Distribution_Fee_Sale_Currency,


    round(sum(arr.gross_revenue_payee_currency),5) Total_Gross_Payee_Currency,
    round(sum(arr.withholding_tax_payee_currency),5) Total_WHT_Payee_Currency,
    round(sum(arr.gross_revenue_after_withholding_tax_payee_currency),5) Total_Gross_After_WHT_Payee_Currency,
    round(sum(arr.net_revenue_payee_currency),5) Net_Revenue_Payee_Currency,
    round(sum(arr.distribution_fee_payee_currency),5) Total_Distribution_Fee_Payee_Currency
-- sales
from royalty_accounting.prod.accounting_run_results_distro as arr
join royalty_accounting.prod.stmt_db_sales_distro as txn on arr.txn_id = txn.stmt_db_sales_distro_txn_id
-- contract
join royalty_accounting.prod.contract_transaction_staging as cts on arr.txn_id = cts.txn_id and cts.accounting_run_id=arr.accounting_run_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.contract as c on cts.contract_id = c.contract_id
join ROYALTY_ACCOUNTING.PROD.VW_DIM_ABACUS_CONTRACT ac on c.contract_id = ac.contract_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.run_controller_contract rcc
    on rcc.contract_id=c.contract_id
    and rcc.run_controller_id=11 -- filter out any contracts not KNR label
-- account
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.account as a on cts.account_id = a.account_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.account_payment_term as apt on a.account_id = apt.account_id
-- contract conditions
join facts.prod.dim_transactiontype as t on txn.transaction_type = t.transactiontypeabbr
left join orchard_app_reporting_v2.art_relations_prod_art_relations.customer_master_master cmm on cmm.customer_master_master_id=txn.store_id
left join orchard_app_reporting_v2.art_relations_prod_art_relations.country cn on cn.id=txn.country_id
--statement period
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.accounting_run as ari on arr.accounting_run_id = ari.accounting_run_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.accounting_period as api on ari.accounting_period_id = api.accounting_period_id
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.statement_period as asp on api.statement_period_id = asp.statement_period_id
-- predicates
where true
--and arr.accounting_run_id=179
group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14
order by account_id,contract_id;;
```

