Files
Implementation_ITSA/Database Backups/SQL Views/vw_bi_itsa_fct_contract.sql
AzureAD\SylvainDUVERNAY 832a142e87 Commit all views for ITSA
2026-03-24 14:40:53 +01:00

31 lines
1.5 KiB
SQL

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);;