mirror of
https://gitlab.com/cief-data/dbt_cloud.git
synced 2026-08-19 04:14:00 +00:00
Merge branch 'main' of gitlab.com:cief-data/dbt_cloud into build-wallet-cash-flow-analysis
This commit is contained in:
@@ -209,8 +209,9 @@ fct_and_dim_joins AS (
|
||||
-- On time delivery boolean (CIEF internal SLA)
|
||||
CASE
|
||||
-- On-time boolean is null when order is not complete
|
||||
WHEN service_type IN ('BA') THEN NULL
|
||||
WHEN service_type IN ('BA', 'RECEIVED-ON-BEHALF') THEN NULL
|
||||
WHEN transaction_status NOT IN ('UPLOADED_BANK_SLIP') THEN NULL
|
||||
WHEN order_created_datetime < '2023-01-01' THEN NULL
|
||||
WHEN estimated_order_delivery_datetime_website_sla > orders.operation_uploaded_bank_slip_datetime THEN 1
|
||||
WHEN estimated_order_delivery_datetime_website_sla < orders.operation_uploaded_bank_slip_datetime THEN 0
|
||||
ELSE -999
|
||||
@@ -219,8 +220,9 @@ fct_and_dim_joins AS (
|
||||
-- On time delivery boolean (Customer Expectation)
|
||||
CASE
|
||||
-- On-time boolean is null when order is not complete
|
||||
WHEN service_type IN ('BA') THEN NULL
|
||||
WHEN service_type IN ('BA', 'RECEIVED-ON-BEHALF') THEN NULL
|
||||
WHEN transaction_status NOT IN ('UPLOADED_BANK_SLIP') THEN NULL
|
||||
WHEN order_created_datetime < '2023-01-01' THEN NULL
|
||||
WHEN estimated_order_delivery_datetime_customer_expectation > orders.operation_uploaded_bank_slip_datetime THEN 1
|
||||
WHEN estimated_order_delivery_datetime_customer_expectation < orders.operation_uploaded_bank_slip_datetime THEN 0
|
||||
ELSE -999
|
||||
|
||||
@@ -59,7 +59,7 @@ restructure_and_expand_table_cief_vs_world_rate AS (
|
||||
|
||||
),
|
||||
|
||||
restructure_and_expand_table_cief_1688_vs_c2m_altr AS (
|
||||
restructure_and_expand_table_cief_1688_vs_c2m_tbdf AS (
|
||||
|
||||
SELECT
|
||||
t1.provider,
|
||||
@@ -83,7 +83,7 @@ restructure_and_expand_table_cief_1688_vs_c2m_altr AS (
|
||||
LEFT JOIN currency_exchange_rate_compilation t2
|
||||
ON ( t1.exchange_rate_date = t2.exchange_rate_date )
|
||||
AND t2.provider = 'C2M'
|
||||
AND t2.service_type = 'ALTR'
|
||||
AND t2.service_type = 'TBDF'
|
||||
|
||||
WHERE
|
||||
t1.provider = 'CIEF'
|
||||
@@ -94,7 +94,7 @@ restructure_and_expand_table_cief_1688_vs_c2m_altr AS (
|
||||
|
||||
),
|
||||
|
||||
restructure_and_expand_table_cief_1_day_transfer_vs_c2m_tbdf AS (
|
||||
restructure_and_expand_table_cief_1_day_transfer_vs_c2m_altr AS (
|
||||
|
||||
SELECT
|
||||
t1.provider,
|
||||
@@ -118,7 +118,7 @@ restructure_and_expand_table_cief_1_day_transfer_vs_c2m_tbdf AS (
|
||||
LEFT JOIN currency_exchange_rate_compilation t2
|
||||
ON ( t1.exchange_rate_date = t2.exchange_rate_date )
|
||||
AND t2.provider = 'C2M'
|
||||
AND t2.service_type = 'TBDF'
|
||||
AND t2.service_type = 'ALTR'
|
||||
|
||||
CROSS JOIN get_base_myr_value_for_comparison
|
||||
|
||||
@@ -171,21 +171,23 @@ union_expanded_tables AS (
|
||||
|
||||
SELECT * FROM restructure_and_expand_table_cief_vs_world_rate
|
||||
UNION ALL
|
||||
SELECT * FROM restructure_and_expand_table_cief_1688_vs_c2m_altr
|
||||
SELECT * FROM restructure_and_expand_table_cief_1688_vs_c2m_tbdf
|
||||
UNION ALL
|
||||
SELECT * FROM restructure_and_expand_table_cief_1_day_transfer_vs_c2m_tbdf
|
||||
SELECT * FROM restructure_and_expand_table_cief_1_day_transfer_vs_c2m_altr
|
||||
UNION ALL
|
||||
SELECT * FROM restructure_and_expand_table_cief_3_days_vs_sd
|
||||
|
||||
),
|
||||
|
||||
rate_comparison AS (
|
||||
exchange_amount_compute AS (
|
||||
|
||||
SELECT
|
||||
*,
|
||||
|
||||
-- CIEF exchanged CNY after deducting service charge
|
||||
( (comparison_base_value_myr / 1.02) * myr_to_cny_currency_exchange_rate ) AS cief_amount_cny,
|
||||
|
||||
-- Competitor exchanged CNY after deducting service charge
|
||||
CASE
|
||||
WHEN competitor_name = 'WORLD RATE'
|
||||
THEN comparison_base_value_myr * competitor_myr_to_cny_currency_exchange_rate
|
||||
@@ -197,6 +199,25 @@ rate_comparison AS (
|
||||
THEN ( comparison_base_value_myr * competitor_myr_to_cny_currency_exchange_rate ) - handling_fee_cny
|
||||
END AS competitor_amount_cny,
|
||||
|
||||
-- Median and Average difference in CNY amount exchanged comparing CIEF to competitor
|
||||
MEDIAN(1 - DIV0(competitor_amount_cny, cief_amount_cny)) OVER (
|
||||
PARTITION BY service_type, exchange_rate_date, competitor_name, competitor_service_type, competitor_payment_method
|
||||
) AS median_amount_percent_difference,
|
||||
|
||||
median_amount_percent_difference - 0.5 * median_amount_percent_difference AS upper_bound_median_amount_percent_difference,
|
||||
median_amount_percent_difference + 0.5 * median_amount_percent_difference AS lower_bound_median_amount_percent_difference,
|
||||
|
||||
AVG(1 - DIV0(competitor_amount_cny, cief_amount_cny)) OVER (
|
||||
PARTITION BY service_type, exchange_rate_date, competitor_name, competitor_service_type, competitor_payment_method
|
||||
) AS average_amount_percent_difference,
|
||||
|
||||
average_amount_percent_difference - 0.5 * average_amount_percent_difference AS upper_bound_average_amount_percent_difference,
|
||||
average_amount_percent_difference + 0.5 * average_amount_percent_difference AS lower_bound_average_amount_percent_difference,
|
||||
|
||||
AVG(1 - DIV0(COMPETITOR_AMOUNT_CNY, CIEF_AMOUNT_CNY)) OVER (
|
||||
PARTITION BY service_type, exchange_rate_date, payment_method, competitor_name, competitor_service_type, competitor_payment_method
|
||||
) AS comparison_average_percent_difference,
|
||||
|
||||
MAX(exchange_rate_date) OVER ( PARTITION BY competitor_name, payment_method, competitor_payment_method) AS latest_exchange_rate_date
|
||||
|
||||
FROM union_expanded_tables
|
||||
@@ -227,23 +248,31 @@ order_metrics AS (
|
||||
exchange_rate_join_order_metrics AS (
|
||||
|
||||
SELECT
|
||||
rate_comparison.provider,
|
||||
rate_comparison.payment_method,
|
||||
rate_comparison.service_type,
|
||||
rate_comparison.myr_to_cny_currency_exchange_rate,
|
||||
rate_comparison.exchange_rate_date,
|
||||
rate_comparison.competitor_name,
|
||||
rate_comparison.start_range_myr,
|
||||
rate_comparison.end_range_myr,
|
||||
rate_comparison.competitor_payment_method,
|
||||
rate_comparison.competitor_service_type,
|
||||
rate_comparison.handling_fee_myr,
|
||||
rate_comparison.handling_fee_cny,
|
||||
rate_comparison.competitor_myr_to_cny_currency_exchange_rate,
|
||||
rate_comparison.comparison_base_value_myr,
|
||||
rate_comparison.cief_amount_cny,
|
||||
rate_comparison.competitor_amount_cny,
|
||||
rate_comparison.latest_exchange_rate_date,
|
||||
exchange_amount_compute.provider,
|
||||
exchange_amount_compute.payment_method,
|
||||
exchange_amount_compute.service_type,
|
||||
exchange_amount_compute.myr_to_cny_currency_exchange_rate,
|
||||
exchange_amount_compute.exchange_rate_date,
|
||||
exchange_amount_compute.competitor_name,
|
||||
exchange_amount_compute.start_range_myr,
|
||||
exchange_amount_compute.end_range_myr,
|
||||
exchange_amount_compute.competitor_payment_method,
|
||||
exchange_amount_compute.competitor_service_type,
|
||||
exchange_amount_compute.handling_fee_myr,
|
||||
exchange_amount_compute.handling_fee_cny,
|
||||
exchange_amount_compute.competitor_myr_to_cny_currency_exchange_rate,
|
||||
exchange_amount_compute.comparison_base_value_myr,
|
||||
exchange_amount_compute.cief_amount_cny,
|
||||
exchange_amount_compute.competitor_amount_cny,
|
||||
exchange_amount_compute.latest_exchange_rate_date,
|
||||
exchange_amount_compute.median_amount_percent_difference,
|
||||
exchange_amount_compute.upper_bound_median_amount_percent_difference,
|
||||
exchange_amount_compute.lower_bound_median_amount_percent_difference,
|
||||
exchange_amount_compute.average_amount_percent_difference,
|
||||
exchange_amount_compute.upper_bound_average_amount_percent_difference,
|
||||
exchange_amount_compute.lower_bound_average_amount_percent_difference,
|
||||
exchange_amount_compute.comparison_average_percent_difference,
|
||||
|
||||
order_metrics.daily_sales_cny,
|
||||
order_metrics.total_daily_sales_cny,
|
||||
order_metrics.daily_sales_myr,
|
||||
@@ -253,14 +282,14 @@ exchange_rate_join_order_metrics AS (
|
||||
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM rate_comparison
|
||||
FROM exchange_amount_compute
|
||||
|
||||
LEFT JOIN order_metrics
|
||||
ON
|
||||
(
|
||||
rate_comparison.exchange_rate_date = order_metrics.order_date
|
||||
AND rate_comparison.service_type = order_metrics.service_type
|
||||
AND rate_comparison.payment_method = order_metrics.order_payment_method
|
||||
exchange_amount_compute.exchange_rate_date = order_metrics.order_date
|
||||
AND exchange_amount_compute.service_type = order_metrics.service_type
|
||||
AND exchange_amount_compute.payment_method = order_metrics.order_payment_method
|
||||
)
|
||||
|
||||
),
|
||||
@@ -296,6 +325,13 @@ final__rep_exchange__exchange_rate_analysis AS (
|
||||
total_daily_sales_cny,
|
||||
daily_sales_myr,
|
||||
total_daily_sales_myr,
|
||||
median_amount_percent_difference,
|
||||
upper_bound_median_amount_percent_difference,
|
||||
lower_bound_median_amount_percent_difference,
|
||||
average_amount_percent_difference,
|
||||
upper_bound_average_amount_percent_difference,
|
||||
lower_bound_average_amount_percent_difference,
|
||||
comparison_average_percent_difference,
|
||||
|
||||
-- date/times
|
||||
exchange_rate_date,
|
||||
|
||||
@@ -536,6 +536,8 @@ purchase_order_invoice_status_redefined AS (
|
||||
CASE
|
||||
WHEN order_status IN ('REFUNDED')
|
||||
THEN 'ORDER_REFUNDED'
|
||||
WHEN order_status IN ('EXPIRED')
|
||||
THEN 'ORDER_EXPIRED'
|
||||
WHEN order_status IN ('COMPLETED', 'APPROVED') AND cost_status IS NULL
|
||||
THEN 'PENDING_GENERATE_WHITE_FORM'
|
||||
WHEN order_status IN ('COMPLETED', 'APPROVED') AND cost_status IN ('PENDING_VERIFICATION')
|
||||
|
||||
Reference in New Issue
Block a user