-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
broke out intermediate tables to focus on billing and deposits exclus…
…ively, and deduplicate
- Loading branch information
1 parent
6df3ce0
commit 25719fe
Showing
2 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
warehouse/models/staging/payments/elavon/int_elavon__billing_transactions_deduped.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{{ config(materialized='table') }} | ||
|
||
WITH | ||
|
||
stg_elavon__transactions AS ( | ||
|
||
SELECT * FROM {{ ref('stg_elavon__transactions') }} | ||
|
||
), | ||
|
||
billing_transactions AS ( | ||
|
||
SELECT * FROM stg_elavon__transactions | ||
WHERE batch_type = 'B' | ||
|
||
), | ||
|
||
dedup_billing_transactions AS ( | ||
|
||
SELECT * | ||
FROM billing_transactions | ||
WHERE execution_ts = (SELECT MAX(execution_ts) FROM billing_transactions) | ||
|
||
), | ||
|
||
int_elavon__billing_transactions_deduped AS ( | ||
|
||
SELECT | ||
|
||
payment_reference, | ||
payment_date, | ||
account_number, | ||
routing_number, | ||
fund_amt, | ||
batch_reference, | ||
batch_type, | ||
customer_batch_reference, | ||
customer_name, | ||
merchant_number, | ||
external_mid, | ||
store_number, | ||
chain, | ||
batch_amt, | ||
amount, | ||
surchg_amount, | ||
convnce_amt, | ||
card_type, | ||
charge_type, | ||
charge_type_description, | ||
card_plan, | ||
card_no, | ||
chk_num, | ||
transaction_date, | ||
settlement_date, | ||
authorization_code, | ||
chargeback_control_no, | ||
roc_text, | ||
trn_aci, | ||
card_scheme_ref, | ||
trn_ref_num, | ||
settlement_method, | ||
currency_code, | ||
cb_acq_ref_id, | ||
chgbk_rsn_code, | ||
chgbk_rsn_desc, | ||
mer_ref, | ||
purch_id, | ||
cust_cod, | ||
trn_arn, | ||
term_id, | ||
ent_num, | ||
dt, | ||
execution_ts | ||
|
||
FROM dedup_billing_transactions | ||
|
||
) | ||
|
||
SELECT * FROM int_elavon__billing_transactions_deduped |
85 changes: 85 additions & 0 deletions
85
warehouse/models/staging/payments/elavon/int_elavon__deposit_transactions_deduped.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{{ config(materialized='table') }} | ||
|
||
WITH | ||
|
||
stg_elavon__transactions AS ( | ||
|
||
SELECT * FROM {{ ref('stg_elavon__transactions') }} | ||
|
||
), | ||
|
||
deposit_transactions AS ( | ||
|
||
SELECT * FROM stg_elavon__transactions | ||
WHERE batch_type = 'D' | ||
|
||
), | ||
|
||
dedup_deposit_transactions AS ( | ||
|
||
SELECT | ||
|
||
transactions.* | ||
|
||
FROM deposit_transactions AS transactions | ||
|
||
INNER JOIN | ||
|
||
(SELECT trn_ref_num, MAX(execution_ts) AS max_ts FROM deposit_transactions GROUP BY trn_ref_num) AS grouped_tbl | ||
ON transactions.trn_ref_num = grouped_tbl.trn_ref_num | ||
AND transactions.execution_ts = max_ts | ||
), | ||
|
||
int_elavon__deposit_transactions_deduped AS ( | ||
|
||
SELECT | ||
payment_reference, | ||
payment_date, | ||
account_number, | ||
routing_number, | ||
fund_amt, | ||
batch_reference, | ||
batch_type, | ||
customer_batch_reference, | ||
customer_name, | ||
merchant_number, | ||
external_mid, | ||
store_number, | ||
chain, | ||
batch_amt, | ||
amount, | ||
surchg_amount, | ||
convnce_amt, | ||
card_type, | ||
charge_type, | ||
charge_type_description, | ||
card_plan, | ||
card_no, | ||
chk_num, | ||
transaction_date, | ||
settlement_date, | ||
authorization_code, | ||
chargeback_control_no, | ||
roc_text, | ||
trn_aci, | ||
card_scheme_ref, | ||
trn_ref_num, | ||
settlement_method, | ||
currency_code, | ||
cb_acq_ref_id, | ||
chgbk_rsn_code, | ||
chgbk_rsn_desc, | ||
mer_ref, | ||
purch_id, | ||
cust_cod, | ||
trn_arn, | ||
term_id, | ||
ent_num, | ||
dt, | ||
execution_ts | ||
|
||
FROM dedup_deposit_transactions | ||
|
||
) | ||
|
||
SELECT * FROM int_elavon__deposit_transactions_deduped |