# View: dt_abacus_tap_closing_bal_taxable_rev_prod

**View Name:** dt_abacus_tap_closing_bal_taxable_rev_prod
**Table Source:** `Derived from: Orchard_App_Reporting_V2, Orchard_App_Reporting_V2.Prod_Royalty_Accounting_Royalty_Accounting, Prod_Royalty_Accounting_Royalty_Accounting.Abacus_State, Prod_Royalty_Accounting_Royalty_Accounting.Account_Tax_Info, Prod_Royalty_Accounting_Royalty_Accounting.Reference_Payment_Entity + 3 more`
**File Path:** `views/dt_abacus_tap_closing_bal_taxable_rev_prod.view.lkml`

## Overview

- **File Size:** 4103 bytes
- **Lines of Code:** 127
- **Dimensions:** 16
- **Measures:** 0
- **Dimension Groups:** 0
- **Filters:** 0

## Dimensions

| Name | Type |
|------|------|
| `paid_by` | string |
| `account_id` | number |
| `contract_id` | number |
| `currency_code` | string |
| `statement_period_id` | number |
| `closing_balance_amount` | string |
| `revenue_transaction_type` | string |
| `is_us_revenue` | string |
| `taxable_revenue_amount` | string |
| `payment_eligibility` | string |
| `tax_eligibility` | string |
| `country_of_tax_residence` | string |
| `tax_rate` | string |
| `is_tax_treaty_claimed` | string |
| `is_resource_provisioned` | string |
| `country_of_withholding` | string |

## Derived Table

```sql
sql:
        SELECT
            rpe.payment_entity_name as paid_by,
            cb.account_id,
            cb.contract_id,
            cb.currency_code,
            cb.statement_period_id,
            cb.amount as closing_balance_amount,
            tr.revenue_transaction_type,
            tr.is_us_revenue,
            tr.amount as taxable_revenue_amount,
            CASE
                WHEN ast1.action_status = 'approved' THEN True
                ELSE False
            END AS payment_eligibility,
            CASE
                WHEN ast2.action_status = 'complete' THEN True
                ELSE False
            END AS tax_eligibility,
            ati.country_of_tax_residence,
            rtw.tax_rate,
            ati.is_tax_treaty_claimed,
            rtw.is_resource_provisioned,
            CASE
                WHEN rpe.payment_entity_name IN ('AWAL-US', 'Orchard-US') then 'USA'
                WHEN rpe.payment_entity_name IN ('AWAL-UK', 'Orchard-UK') then 'GBR'
            END as country_of_withholding
        FROM
            orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.worksheet_account_contract_closing_balance cb
            LEFT JOIN orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.worksheet_account_contract_taxable_revenue tr ON tr.contract_id = cb.contract_id
            AND tr.statement_period_id = cb.statement_period_id
            LEFT JOIN orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.reference_payment_entity rpe ON rpe.reference_payment_entity_id = cb.reference_payment_entity_id
            LEFT JOIN orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.abacus_state ast1 ON ast1.parent_table_id = cb.account_id
            and ast1.action_name = 'payment_eligibility'
            LEFT JOIN orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.abacus_state ast2 ON ast2.parent_table_id = cb.account_id
            and ast2.action_name = 'tax_eligibility'
            LEFT JOIN orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.account_tax_info ati on cb.account_id = ati.account_id
            LEFT JOIN orchard_app_reporting_v2.prod_royalty_accounting_royalty_accounting.reference_tax_withholding rtw on rtw.country_of_withholding = rpe.country_of_tax_reporting
            and ati.country_of_tax_residence = rtw.country_of_tax_residence
        WHERE
            cb.deleted_at is NULL
            and tr.deleted_at is NULL;;
```

