-
-
Save biozz/0de1f7af557a9360a096fd9a2f0bf110 to your computer and use it in GitHub Desktop.
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
SELECT | |
"meta_order"."id", | |
"meta_order"."partner_id", | |
"meta_order"."partner_data_id", | |
"meta_order"."ordergroup_id", | |
"meta_order"."content_type_id", | |
"meta_order"."object_id", | |
"meta_order"."has_tickets", | |
"meta_order"."package_id", | |
"meta_order"."paid_at", | |
"meta_order"."payment_type", | |
"meta_order"."payment_by", | |
"meta_order"."modified_at", | |
"meta_order"."created_at", | |
CASE WHEN "car"."sell" = ("car"."refund") THEN True ELSE False END AS "car__payable_isnull", | |
CASE WHEN "upsell"."sell" = ("upsell"."refund") THEN True ELSE False END AS "upsell__payable_isnull", | |
( | |
"hotel"."sell" * "hotel"."sell_currency_rate" | |
) AS "hotel__sell_base", | |
( | |
"hotel"."refund" * "hotel"."refund_currency_rate" | |
) AS "hotel__refund_base", | |
CASE WHEN ( | |
"hotel"."sell" * "hotel"."sell_currency_rate" | |
) = ( | |
( | |
"hotel"."refund" * "hotel"."refund_currency_rate" | |
) | |
) THEN True ELSE False END AS "hotel__payable_isnull", | |
COALESCE( | |
"hotel"."payment_pending", | |
"car"."payment_pending" | |
) AS "_payment_pending", | |
COALESCE( | |
"hotel"."payment_due", | |
"car"."payment_due" | |
) AS "_payment_due", | |
COALESCE( | |
"hotel"."free_cancellation_before", | |
'2018-11-3019:07:12.337162' | |
) AS "_free_cancellation_before", | |
COALESCE("hotel"."refund", 0) AS "refund", | |
COALESCE("hotel"."refund_currency_rate", 1) AS "refund_currency_rate", | |
COALESCE("hotel"."sell", 0) AS "sell", | |
COALESCE("hotel"."sell_currency_rate", 1) AS "sell_currency_rate", | |
( | |
COALESCE("hotel"."sell", 0) * COALESCE("hotel"."sell_currency_rate", 1) | |
) AS "sell_base", | |
( | |
COALESCE("hotel"."refund", 0) * COALESCE("hotel"."refund_currency_rate", 1) | |
) AS "refund_base", | |
( | |
( | |
COALESCE("hotel"."sell", 0) * COALESCE("hotel"."sell_currency_rate", 1) | |
) - ( | |
COALESCE("hotel"."refund", 0) * COALESCE("hotel"."refund_currency_rate", 1) | |
) | |
) AS "payable_base", | |
CASE WHEN "meta_order"."content_type_id" = 161 THEN ( | |
(hotel.currency_data_raw->>'EUR')::numeric | |
) ELSE 1 END AS "_reporting_currency_rate", | |
( | |
( | |
( | |
COALESCE("hotel"."sell", 0) * COALESCE("hotel"."sell_currency_rate", 1) | |
) - ( | |
COALESCE("hotel"."refund", 0) * COALESCE("hotel"."refund_currency_rate", 1) | |
) | |
) / CASE WHEN "meta_order"."content_type_id" = 161 THEN ( | |
(hotel.currency_data_raw->>'EUR')::numeric | |
) ELSE 1 END | |
) AS "payable_in_cur" | |
FROM | |
"meta_order" | |
LEFT OUTER JOIN "car" ON ( | |
"meta_order"."object_id" = "car"."id" | |
AND ("meta_order"."content_type_id" = 163) | |
) | |
LEFT OUTER JOIN "upsell" ON ( | |
"meta_order"."object_id" = "upsell"."id" | |
AND ("meta_order"."content_type_id" = 165) | |
) | |
LEFT OUTER JOIN "hotel" ON ( | |
"meta_order"."object_id" = "hotel"."id" | |
AND ("meta_order"."content_type_id" = 161) | |
) | |
INNER JOIN "hotel" T7 ON ( | |
"meta_order"."object_id" = T7."id" | |
AND ("meta_order"."content_type_id" = 161) | |
) | |
WHERE | |
( | |
"meta_order"."partner_id" = 5782 | |
AND "meta_order"."paid_at" IS NULL | |
AND CASE WHEN ( | |
"car"."sell" = ("car"."refund") | |
) THEN True ELSE False END = False | |
AND CASE WHEN ( | |
( | |
"hotel"."sell" * "hotel"."sell_currency_rate" | |
) = ( | |
( | |
"hotel"."refund" * "hotel"."refund_currency_rate" | |
) | |
) | |
) THEN True ELSE False END = False | |
AND CASE WHEN ( | |
"upsell"."sell" = ("upsell"."refund") | |
) THEN True ELSE False END = False | |
AND "meta_order"."content_type_id" IN (161) | |
AND T7."source" IN ('b2b-site', 'b2b-card', 'b2b-api', 'b2b-handmade') | |
AND T7."status" IN ('completed', 'cancelled', 'noshow') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment