Dump - ITSA views

This commit is contained in:
AzureAD\SylvainDUVERNAY
2026-06-14 11:05:54 +02:00
parent 3a3e715336
commit af63a53372
27 changed files with 708 additions and 140 deletions

View File

@@ -1,81 +1,70 @@
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_full_pnl AS
WITH trade AS (
SELECT pc."intPurchaseLineId" AS "intTradeId",
(pc."intPurchaseLineId" || '_0'::text) AS strtradeid
(pc."intPurchaseLineId" || '_0'::text) AS "strTradeId",
'Purchase'::text AS "strTradeType",
pc."strBookName"
FROM vw_utility_dim_physical_purchase_contract pc
WHERE ((1 = 1) AND (pc."intPurchaseLineId" > 0))
UNION ALL
SELECT sc."intSaleLineId" AS "intTradeId",
('0_'::text || sc."intSaleLineId") AS strtradeid
('0_'::text || sc."intSaleLineId") AS "strTradeId",
'Sale'::text AS "strTradeType",
sc."strBookName"
FROM vw_utility_dim_physical_sale_contract sc
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0))
)
SELECT 2 AS "intPnlTypeId",
trade.strtradeid AS "strConformedReferenceId",
SELECT
CASE
WHEN ((trade."strBookName")::text ~~ '%Projection%'::text) THEN 1
ELSE 2
END AS "intPnlTypeId",
trade."strTradeId" AS "strConformedReferenceId",
contracts."intPriceGroupId",
contracts."Line Description",
contracts."Open Quantity Signed",
contracts."Price",
contracts."Open Cost Amount" AS amount,
contracts."Estimated BL Date" AS "Delivery Date",
contracts."Line Group"
FROM (vw_bi_itsa_physical_open_costs contracts
CASE
WHEN ((trade."strBookName")::text ~~ '%Projection%'::text) THEN 'Expected'::text
ELSE contracts."Line Group"
END AS "Line Group",
COALESCE(book."intBookId", 0) AS "intBookId",
abs(contracts."Open Quantity Signed") AS "Open Quantity",
'Section 1'::text AS "Code Section"
FROM ((vw_bi_itsa_physical_open_costs_v2 contracts
JOIN trade trade ON ((contracts."intTradeLineId" = trade."intTradeId")))
LEFT JOIN vw_utility_book_dimension book ON (((trade."intTradeId" = book."intTradeLineId") AND (book."strTradeCategory" = 'Physical'::text) AND (book."strTradeType" = trade."strTradeType"))))
UNION ALL
SELECT 3 AS "intPnlTypeId",
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
1 AS "intPriceGroupId",
'Purchase'::character varying AS "Line Description",
CASE
WHEN ((fee_alloc."Fee Type")::text = 'price'::text) THEN 1
ELSE 2
END AS "intPriceGroupId",
fee_alloc."Fee" AS "Line Description",
shipment."Shipped Quantity" AS "Open Quantity Signed",
shipment."Purchase Price" AS "Price",
(shipment."Shipped Quantity" * (shipment."Purchase Price")::double precision) AS amount,
fee_alloc."Price",
(fee_alloc."Amount" * fee_alloc."Sign Multiplier") AS amount,
shipment."BL Date" AS "Delivery Date",
'Purchase'::text AS "Line Group"
FROM vw_bi_itsa_fct_shipments shipment
fee_alloc."Cost Group" AS "Line Group",
shipment."intBookId",
abs(shipment."Shipped Quantity") AS "Open Quantity",
'Section 4'::text AS "Code Section"
FROM (vw_bi_itsa_fct_shipments_v2 shipment
LEFT JOIN vw_bi_fct_fee_allocation fee_alloc ON (((shipment."intShipmentId" = fee_alloc."intShipmentId") AND (shipment."intPurchaseLineId" = fee_alloc."intPurchaseLineId") AND (shipment."intSaleLineId" = fee_alloc."intSaleLineId"))))
UNION ALL
SELECT 3 AS "intPnlTypeId",
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
1 AS "intPriceGroupId",
'Sale'::character varying AS "Line Description",
shipment."Shipped Quantity" AS "Open Quantity Signed",
shipment."Sale Price" AS "Price",
(shipment."Shipped Quantity" * (shipment."Sale Price")::double precision) AS amount,
shipment."BL Date" AS "Delivery Date",
'Sale'::text AS "Line Group"
FROM vw_bi_itsa_fct_shipments shipment
UNION ALL
SELECT 3 AS "intPnlTypeId",
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
'0_0'::text AS "strConformedReferenceId",
2 AS "intPriceGroupId",
fees."Fee" AS "Line Description",
shipment."Shipped Quantity" AS "Open Quantity Signed",
fees."Price",
(shipment."Shipped Quantity" * (fees."Price")::double precision) AS amount,
shipment."BL Date" AS "Delivery Date",
fees."Cost Group" AS "Line Group"
FROM (vw_bi_itsa_fct_shipment_fees fees
JOIN vw_bi_itsa_fct_shipments shipment ON ((fees."intShipmentId" = shipment."intShipmentId")))
UNION ALL
SELECT fees."intPnlTypeId",
fees."strConformedReferenceId",
fees."intPriceGroupId",
fees."Line Description",
fees."Open Quantity Signed",
fees."Price",
fees."Amount" AS amount,
fees."Delivery Date",
fees."Line Group"
FROM vw_bi_itsa_fct_inherited_expenses_on_shipments fees
UNION ALL
SELECT 1 AS "intPnlTypeId",
trade."strTradeId" AS "strConformedReferenceId",
1 AS "intPriceGroupId",
'Expected Price'::character varying AS "Line Description",
ctr."Contract Quantity" AS "Open Quantity Signed",
ctr."Avg Price" AS "Price",
(ctr."Contract Quantity" * ctr."Avg Price") AS amount,
ctr."Delivery Date",
'Expected'::text AS "Line Group"
FROM (vw_bi_itsa_fct_contract ctr
JOIN vw_bi_dim_trade trade ON ((ctr."TradeLineId" = trade."intTradeId")))
WHERE ((trade."Book")::text ~~ '%Projection%'::text);;
ifrs."Comments" AS "Line Description",
0 AS "Open Quantity Signed",
0 AS "Price",
ifrs."Amount" AS amount,
ifrs."Adjustment Date" AS "Delivery Date",
'Monthly Adjustment'::text AS "Line Group",
ifrs."intBookId",
0 AS "Open Quantity",
'Section 5'::text AS "Code Section"
FROM vw_bi_itsa_monthly_trade_ifrs_adjustments ifrs;;