# View: KNR_Ownership_Run_Prod_PreApproval

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

## Overview

- **File Size:** 7446 bytes
- **Lines of Code:** 290
- **Dimensions:** 40
- **Measures:** 0
- **Dimension Groups:** 0
- **Filters:** 0

## Dimensions

| Name | Type |
|------|------|
| `Accounting_Period_ID` | string |
| `Run_Controller_ID` | string |
| `Run_Controller_Name` | string |
| `Accounting_Run_ID` | string |
| `Accounting_Run_Name` | string |
| `Account_ID` | string |
| `Account_Name` | string |
| `Contract_ID` | string |
| `Contract_Name` | string |
| `ISRC` | string |
| `UPC` | string |
| `Country_ID` | string |
| `Country_Name` | string |
| `Society_ID` | string |
| `Society_Name` | string |
| `Trans_Type_Abbrev` | string |
| `Transaction_Type` | string |
| `Trans_Sub_Type_ID` | string |
| `Trans_Sub_Type` | string |
| `Recording_Title` | string |
| `Usage_Start_Date` | date |
| `Usage_End_Date` | date |
| `Term_Rate` | number |
| `Quantity` | number |
| `TXN_ID` | string |
| `Unit_Price_USD` | number |
| `Total_USD` | number |
| `Withholding_Tax_USD` | number |
| `Activity_Rate` | number |
| `Sales_Currency` | string |
| `Unit_Price_Sales_Currency` | number |
| `Gross_Revenue_Sales_Currency` | number |
| `Withholding_Tax_Sales_Currency` | number |
| `Gross_Revenue_After_Withholding_Tax_Sales_Currency` | number |
| `Payee_Currency` | string |
| `Gross_Revenue_Payee_Currency` | number |
| `Withholding_Tax_Payee_Currency` | number |
| `Gross_Revenue_After_Withholding_Tax_Payee_Currency` | number |
| `Net_Revenue_Payee_Currency` | number |
| `Distribution_Fee_Payee_Currency` | number |

## SQL Comments

- Slaughter House Data
- Sale Currency
- Payee Currency
- contract
- and rcc.run_controller_id=11 -- filter out any contracts not KNR label

## Derived Table

```sql
sql:

       select
ari.accounting_period_id,
rcc.run_controller_id,
rc.run_controller_name,
    arr.accounting_run_id,
    arr.accounting_run_name,
    cts.account_id,
    a.account_name,
    cts.contract_id,
    c.contract_name,
    txn.isrc,
    txn.upc,
    txn.country_id,
    cn.iso3166a3 country_name,
    txn.store_id,
    cmm.customer_name store,
    txn.transaction_type,
    t.transactiontypedesc,
    txn.TRANSACTION_SUBTYPE_ID,
    st.TRANSACTION_SUBTYPE_DESCRIPTION,
    txn.track_name,
    txn.start_date,
    txn.transaction_date,
    arr.term_rate,
-- Slaughter House Data
    txn.quantity,
    arr.txn_id,
    txn.UNIT_PRICE_USD,
    txn.total_usd,
    txn.withholding_tax_usd,
    txn.activity_rate,
-- Sale Currency
    txn.sale_currency_code,
    arr.unit_price_sale_currency,
    arr.gross_revenue_sale_currency,
    arr.withholding_tax_sale_currency,
    arr.gross_revenue_after_withholding_tax_sale_currency,
-- Payee Currency
    apt.currency_code,
    arr.gross_revenue_payee_currency,
    arr.withholding_tax_payee_currency,
    arr.gross_revenue_after_withholding_tax_payee_currency,
    arr.net_revenue_payee_currency,
    arr.distribution_fee_payee_currency

        -- sales
from royalty_accounting.prod.accounting_run_results_distro_staging 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 orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.run_controller_contract rcc
    on rcc.contract_id=c.contract_id
    join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.run_controller rc on rc.run_controller_id = rcc.run_controller_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
join orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.accounting_run as ari on arr.accounting_run_id = ari.accounting_run_id
left join ROYALTY_ACCOUNTING.PROD.DIM_TRANSACTION_SUBTYPE as st on txn.TRANSACTION_SUBTYPE_ID = st.TRANSACTION_SUBTYPE_ID

        -- predicates
        where true
        order by account_id,contract_id
        ;;
```

