CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_contract AS SELECT 'Purchase'::text AS "TradeType", pc."intPurchaseLineId" AS "TradeLineId", pc."dblQuantity" AS "Quantity", pc."dblTheoriticalQuantity" AS "TheoriticalQuantity", pc."dblInInstructedQuantity" AS "InstructedQuantity", CASE WHEN (pc."ysnFinished" = true) THEN (0)::numeric(18,3) WHEN ((pc."dblTheoriticalQuantity")::double precision > pc."dblInInstructedQuantity") THEN (((pc."dblTheoriticalQuantity")::double precision - pc."dblInInstructedQuantity"))::numeric(18,3) ELSE (0)::numeric(18,3) END AS "OpenQuantity", pc."dblUnitPrice" AS "Price", COALESCE(pc."dtmEstimatedBLDate", pc."dtmDeliveryDateFrom") AS "DeliveryDate" FROM vw_utility_purchase_physical_contract pc WHERE (1 = 1) UNION ALL SELECT 'Sale'::text AS "TradeType", pc."intSaleLineId" AS "TradeLineId", pc."dblQuantity" AS "Quantity", pc."dblTheoreticalQuantity" AS "TheoriticalQuantity", pc."dblInstructedQuantity" AS "InstructedQuantity", CASE WHEN (pc."ysnFinished" = true) THEN (0)::numeric(18,3) WHEN ((pc."dblTheoreticalQuantity")::double precision > pc."dblInstructedQuantity") THEN (((pc."dblTheoreticalQuantity")::double precision - pc."dblInstructedQuantity"))::numeric(18,3) ELSE (0)::numeric(18,3) END AS "OpenQuantity", pc."dblUnitPrice" AS "Price", COALESCE(pc."dtmEstimatedBLDate", pc."dtmDeliveryDateFrom") AS "DeliveryDate" FROM vw_utility_sale_physical_contract pc WHERE (1 = 1);;