mirror of
https://gitlab.com/cief-data/dbt_cloud.git
synced 2026-08-19 12:24:04 +00:00
Exclude Internal Purchase
This commit is contained in:
@@ -5,34 +5,65 @@ WITH transactions AS (
|
||||
|
||||
|
||||
-- LOGIC
|
||||
-- Filter transaction id for 'internal purchase'
|
||||
internal_purchase_transaction_id AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
|
||||
FROM transactions
|
||||
|
||||
WHERE owner_id IN (
|
||||
SELECT id FROM {{ source('src_exchange_mysql', 'bookings') }}
|
||||
WHERE service_id IN (7) -- INTERNAL PURCHASE
|
||||
)
|
||||
AND owner_type = 'App\\Models\\Booking'
|
||||
|
||||
),
|
||||
|
||||
exclude_internal_purchase_bookings AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
|
||||
FROM transactions
|
||||
|
||||
WHERE id NOT IN (
|
||||
SELECT id FROM internal_purchase_transaction_id
|
||||
)
|
||||
|
||||
),
|
||||
|
||||
transactions_rename AS (
|
||||
|
||||
SELECT
|
||||
transactions.id AS transaction_id,
|
||||
transactions.owner_type,
|
||||
transactions.owner_id,
|
||||
transactions.type AS transaction_type,
|
||||
transactions.issuer AS issuer_user_id,
|
||||
transactions.receiver AS receiver_user_id,
|
||||
transactions.recipient_bank_account_id AS recipient_bank_id,
|
||||
transactions.payment_method,
|
||||
transactions.payment_reference,
|
||||
transactions.bill_no AS bill_number,
|
||||
transactions.amount AS base_value,
|
||||
transactions.original_amount AS quote_value,
|
||||
transactions.currency_id AS base_currency_id,
|
||||
transactions.original_currency_id AS quote_currency_id,
|
||||
transactions.currency_rate AS base_to_quote_currency_exchange_rate,
|
||||
transactions.tax AS base_tax,
|
||||
transactions.service_charge AS base_service_charge,
|
||||
transactions.expires_on AS expired_datetime,
|
||||
transactions.status,
|
||||
transactions.deleted_at AS deleted_datetime,
|
||||
transactions.created_at AS created_datetime,
|
||||
transactions.updated_at AS updated_datetime,
|
||||
exclude_internal_purchase_bookings.id AS transaction_id,
|
||||
exclude_internal_purchase_bookings.owner_type,
|
||||
exclude_internal_purchase_bookings.owner_id,
|
||||
exclude_internal_purchase_bookings.type AS transaction_type,
|
||||
exclude_internal_purchase_bookings.issuer AS issuer_user_id,
|
||||
exclude_internal_purchase_bookings.receiver AS receiver_user_id,
|
||||
exclude_internal_purchase_bookings.recipient_bank_account_id AS recipient_bank_id,
|
||||
exclude_internal_purchase_bookings.payment_method,
|
||||
exclude_internal_purchase_bookings.payment_reference,
|
||||
exclude_internal_purchase_bookings.bill_no AS bill_number,
|
||||
exclude_internal_purchase_bookings.amount AS base_value,
|
||||
exclude_internal_purchase_bookings.original_amount AS quote_value,
|
||||
exclude_internal_purchase_bookings.currency_id AS base_currency_id,
|
||||
exclude_internal_purchase_bookings.original_currency_id AS quote_currency_id,
|
||||
exclude_internal_purchase_bookings.currency_rate AS base_to_quote_currency_exchange_rate,
|
||||
exclude_internal_purchase_bookings.tax AS base_tax,
|
||||
exclude_internal_purchase_bookings.service_charge AS base_service_charge,
|
||||
exclude_internal_purchase_bookings.expires_on AS expired_datetime,
|
||||
exclude_internal_purchase_bookings.status,
|
||||
exclude_internal_purchase_bookings.deleted_at AS deleted_datetime,
|
||||
exclude_internal_purchase_bookings.created_at AS created_datetime,
|
||||
exclude_internal_purchase_bookings.updated_at AS updated_datetime,
|
||||
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transactions
|
||||
FROM exclude_internal_purchase_bookings
|
||||
|
||||
),
|
||||
|
||||
|
||||
@@ -74,6 +105,7 @@ final__base_exchange__transactions AS (
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM transactions_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__transactions
|
||||
Reference in New Issue
Block a user