mirror of
https://gitlab.com/cief-data/dbt_cloud.git
synced 2026-08-19 04:14:00 +00:00
Merge branch 'fix-shipping-invoice-value-sum-error' into 'main'
Fix logic for summing invoice value See merge request cief-data/dbt_cloud!43
This commit is contained in:
+13
-4
@@ -3,10 +3,12 @@ WITH stg_shipping__packing_list_invoice_payments AS (
|
||||
SELECT * FROM {{ ref('stg_shipping__packing_list_invoice_payments') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
remove_expired_invoice_payments AS (
|
||||
SELECT
|
||||
*
|
||||
*,
|
||||
ROW_NUMBER() OVER (PARTITION BY packing_list_invoice_id ORDER BY payment_updated_datetime DESC) AS row_num
|
||||
|
||||
FROM stg_shipping__packing_list_invoice_payments
|
||||
|
||||
@@ -14,6 +16,10 @@ remove_expired_invoice_payments AS (
|
||||
invoice_status != 'EXPIRED'
|
||||
AND
|
||||
payment_status NOT IN ('SUSPENDED','REJECTED')
|
||||
|
||||
QUALIFY
|
||||
row_num = 1
|
||||
|
||||
),
|
||||
|
||||
group_by_packing_list_ids AS (
|
||||
@@ -43,13 +49,13 @@ group_by_packing_list_ids AS (
|
||||
SUM(invoice_value_rm) AS invoice_value_rm,
|
||||
SUM(invoice_tax_rm) AS invoice_tax_rm,
|
||||
SUM(invoice_service_charge) AS invoice_service_charge,
|
||||
SUM(payment_value_rm) AS payment_value_rm,
|
||||
SUM(payment_tax_rm) AS payment_tax_rm,
|
||||
SUM(CASE WHEN payment_status = 'APPROVED' THEN payment_value_rm ELSE 0 END) AS payment_value_rm,
|
||||
SUM(CASE WHEN payment_status = 'APPROVED' THEN payment_tax_rm ELSE 0 END) AS payment_tax_rm,
|
||||
SUM(payment_service_charge_rm) AS payment_service_charge_rm,
|
||||
MAX(invoice_created_datetime) AS last_invoice_created_datetime,
|
||||
MAX(payment_created_datetime) AS last_payment_created_datetime,
|
||||
'{{ 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
|
||||
|
||||
FROM remove_expired_invoice_payments
|
||||
|
||||
@@ -60,8 +66,10 @@ group_by_packing_list_ids AS (
|
||||
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__int_shipping__packing_list_invoice_payments_group_by_packing_list_ids AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
old_origin_warehouse_shipping_packing_list_id,
|
||||
@@ -104,6 +112,7 @@ final__int_shipping__packing_list_invoice_payments_group_by_packing_list_ids AS
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM group_by_packing_list_ids
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__int_shipping__packing_list_invoice_payments_group_by_packing_list_ids
|
||||
Reference in New Issue
Block a user