From 2bee6b91ef14409010e769c63238493c457b25cc Mon Sep 17 00:00:00 2001 From: CIEF ACC1 Date: Thu, 7 Mar 2024 02:04:48 +0000 Subject: [PATCH] Redefined on-time logic --- .../reporting/rep_exchange__daily_orders.sql | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/models/marts/reporting/rep_exchange__daily_orders.sql b/models/marts/reporting/rep_exchange__daily_orders.sql index 7e8ce9d..9ffc8fc 100644 --- a/models/marts/reporting/rep_exchange__daily_orders.sql +++ b/models/marts/reporting/rep_exchange__daily_orders.sql @@ -27,7 +27,7 @@ -- IMPORT WITH orders AS ( - SELECT * FROM {{ ref('fct_exchange__transaction_orders') }} + SELECT * FROM {{ ref('fct_exchange__transaction_orders') }} ), companies AS ( @@ -190,10 +190,16 @@ fct_and_dim_joins AS ( CASE {% for (service_type, working_day) in service_type_work_day_dict.items() %} - WHEN orders.order_created_datetime >= '2023-01-01' AND orders.service_type = '{{service_type}}' AND DATE_PART(HOUR, orders.order_pending_verification_datetime) < 16 - THEN TO_TIMESTAMP(order_created_dates.{{working_day['include_base']}} || ' ' || (orders.order_pending_verification_datetime::TIME)::STRING ) - WHEN orders.order_created_datetime >= '2023-01-01' AND orders.service_type = '{{service_type}}' AND DATE_PART(HOUR, orders.order_pending_verification_datetime) >= 16 - THEN TO_TIMESTAMP(order_created_dates.{{working_day['exclude_base']}} || ' ' || (orders.order_pending_verification_datetime::TIME)::STRING ) + WHEN + orders.order_created_datetime >= '2023-01-01' AND orders.service_type = '{{service_type}}' + AND + DATE_PART(HOUR, orders.order_pending_verification_datetime) < 16 + THEN TO_TIMESTAMP(order_created_dates.{{working_day['include_base']}} || ' ' || (orders.order_pending_verification_datetime::TIME)::STRING ) + WHEN + orders.order_created_datetime >= '2023-01-01' + AND + orders.service_type = '{{service_type}}' AND DATE_PART(HOUR, orders.order_pending_verification_datetime) >= 16 + THEN TO_TIMESTAMP(order_created_dates.{{working_day['exclude_base']}} || ' ' || (orders.order_pending_verification_datetime::TIME)::STRING ) {% endfor %} @@ -203,19 +209,21 @@ fct_and_dim_joins AS ( -- On time delivery boolean (CIEF internal SLA) CASE -- On-time boolean is null when order is not complete - WHEN account_verified_payment_datetime IS NULL THEN NULL - WHEN estimated_order_delivery_datetime_website_sla IS NULL THEN NULL + WHEN service_type IN ('BA') THEN NULL + WHEN transaction_status NOT IN ('UPLOADED_BANK_SLIP') THEN NULL WHEN estimated_order_delivery_datetime_website_sla > orders.operation_uploaded_bank_slip_datetime THEN 1 - ELSE 0 + WHEN estimated_order_delivery_datetime_website_sla < orders.operation_uploaded_bank_slip_datetime THEN 0 + ELSE -999 END AS is_on_time_delivery_website_sla, -- On time delivery boolean (Customer Expectation) CASE -- On-time boolean is null when order is not complete - WHEN account_verified_payment_datetime IS NULL THEN NULL - WHEN estimated_order_delivery_datetime_customer_expectation IS NULL THEN NULL + WHEN service_type IN ('BA') THEN NULL + WHEN transaction_status NOT IN ('UPLOADED_BANK_SLIP') THEN NULL WHEN estimated_order_delivery_datetime_customer_expectation > orders.operation_uploaded_bank_slip_datetime THEN 1 - ELSE 0 + WHEN estimated_order_delivery_datetime_customer_expectation < orders.operation_uploaded_bank_slip_datetime THEN 0 + ELSE -999 END AS is_on_time_delivery_customer_expectation, '{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime @@ -242,6 +250,7 @@ fct_and_dim_joins AS ( ), + --FINAL final__rep_exchange__daily_orders AS (