Redefined on-time logic

This commit is contained in:
CIEF ACC1
2024-03-07 02:04:48 +00:00
parent b174496caa
commit 2bee6b91ef
@@ -27,7 +27,7 @@
-- IMPORT -- IMPORT
WITH orders AS ( WITH orders AS (
SELECT * FROM {{ ref('fct_exchange__transaction_orders') }} SELECT * FROM {{ ref('fct_exchange__transaction_orders') }}
), ),
companies AS ( companies AS (
@@ -190,10 +190,16 @@ fct_and_dim_joins AS (
CASE CASE
{% for (service_type, working_day) in service_type_work_day_dict.items() %} {% 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 WHEN
THEN TO_TIMESTAMP(order_created_dates.{{working_day['include_base']}} || ' ' || (orders.order_pending_verification_datetime::TIME)::STRING ) orders.order_created_datetime >= '2023-01-01' AND orders.service_type = '{{service_type}}'
WHEN orders.order_created_datetime >= '2023-01-01' AND orders.service_type = '{{service_type}}' AND DATE_PART(HOUR, orders.order_pending_verification_datetime) >= 16 AND
THEN TO_TIMESTAMP(order_created_dates.{{working_day['exclude_base']}} || ' ' || (orders.order_pending_verification_datetime::TIME)::STRING ) 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 %} {% endfor %}
@@ -203,19 +209,21 @@ fct_and_dim_joins AS (
-- On time delivery boolean (CIEF internal SLA) -- On time delivery boolean (CIEF internal SLA)
CASE CASE
-- On-time boolean is null when order is not complete -- On-time boolean is null when order is not complete
WHEN account_verified_payment_datetime IS NULL THEN NULL WHEN service_type IN ('BA') THEN NULL
WHEN estimated_order_delivery_datetime_website_sla IS NULL 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 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, END AS is_on_time_delivery_website_sla,
-- On time delivery boolean (Customer Expectation) -- On time delivery boolean (Customer Expectation)
CASE CASE
-- On-time boolean is null when order is not complete -- On-time boolean is null when order is not complete
WHEN account_verified_payment_datetime IS NULL THEN NULL WHEN service_type IN ('BA') THEN NULL
WHEN estimated_order_delivery_datetime_customer_expectation IS NULL 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 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, END AS is_on_time_delivery_customer_expectation,
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime '{{ 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
final__rep_exchange__daily_orders AS ( final__rep_exchange__daily_orders AS (