Commit all views
This commit is contained in:
39
Database Backups/SQL Views/vw_bi_dim_conformed_reference.sql
Normal file
39
Database Backups/SQL Views/vw_bi_dim_conformed_reference.sql
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
CREATE OR REPLACE VIEW public.vw_bi_dim_conformed_reference AS
|
||||||
|
SELECT pc."strTradeId" AS "strConformedReferenceId",
|
||||||
|
pc."Contract Ref" AS "Conformed Trade Ref",
|
||||||
|
'Purchase'::text AS "Trade Type",
|
||||||
|
pc."Price Fixing Status",
|
||||||
|
pc."Bassin",
|
||||||
|
pc."Book",
|
||||||
|
pc."Supplier Country" AS "Counterparty Country"
|
||||||
|
FROM vw_bi_dim_purchase_physical_contract pc
|
||||||
|
WHERE ((1 = 1) AND (pc."intPurchaseLineId" > 0))
|
||||||
|
UNION ALL
|
||||||
|
SELECT sc."strTradeLineId" AS "strConformedReferenceId",
|
||||||
|
sc."Contract Ref" AS "Conformed Trade Ref",
|
||||||
|
'Sale'::text AS "Trade Type",
|
||||||
|
sc."Price Fixing Status",
|
||||||
|
sc."Bassin",
|
||||||
|
sc."Book",
|
||||||
|
sc."Customer Country" AS "Counterparty Country"
|
||||||
|
FROM vw_bi_dim_sale_physical_contract sc
|
||||||
|
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0))
|
||||||
|
UNION ALL
|
||||||
|
SELECT DISTINCT ((s."intPurchaseLineId" || '_'::text) || s."intSaleLineId") AS "strConformedReferenceId",
|
||||||
|
CASE
|
||||||
|
WHEN ((pc."Contract Ref")::text <> (sc."Contract Ref")::text) THEN ((((pc."Contract Ref")::text || ' / '::text) || (sc."Contract Ref")::text))::character varying
|
||||||
|
ELSE pc."Contract Ref"
|
||||||
|
END AS "Conformed Trade Ref",
|
||||||
|
'Shipped'::text AS "Trade Type",
|
||||||
|
CASE
|
||||||
|
WHEN ((pc."Price Fixing Status" = sc."Price Fixing Status") AND (pc."Price Fixing Status" = 'Fixed'::text)) THEN 'Fixed'::text
|
||||||
|
WHEN ((pc."Price Fixing Status" = sc."Price Fixing Status") AND (pc."Price Fixing Status" = 'Unfixed'::text)) THEN 'Unfixed'::text
|
||||||
|
ELSE 'Partially Fixed'::text
|
||||||
|
END AS "Price Fixing Status",
|
||||||
|
pc."Bassin",
|
||||||
|
pc."Book",
|
||||||
|
sc."Customer Country" AS "Counterparty Country"
|
||||||
|
FROM ((vw_bi_itsa_fct_shipments s
|
||||||
|
JOIN vw_bi_dim_purchase_physical_contract pc ON ((s."intPurchaseLineId" = pc."intPurchaseLineId")))
|
||||||
|
JOIN vw_bi_dim_sale_physical_contract sc ON ((s."intSaleLineId" = sc."intSaleLineId")))
|
||||||
|
WHERE (1 = 1);;
|
||||||
@@ -1,46 +1,61 @@
|
|||||||
CREATE OR REPLACE VIEW public.vw_bi_dim_purchase_physical_contract AS
|
CREATE OR REPLACE VIEW public.vw_bi_dim_purchase_physical_contract AS
|
||||||
SELECT "intPurchaseLineId",
|
WITH pricingstatus AS (
|
||||||
"strContractNb" AS "Contract Nb",
|
SELECT pvl_1."intContractLineId",
|
||||||
"strCounterparty" AS "Supplier",
|
pvl_1."strState"
|
||||||
"strReference" AS "Contract Ref",
|
FROM vw_utility_physical_valuation_line pvl_1
|
||||||
"dtmContractDate" AS "Contract Date",
|
GROUP BY pvl_1."intContractLineId", pvl_1."strState"
|
||||||
|
)
|
||||||
|
SELECT dpc."intPurchaseLineId",
|
||||||
|
dpc."strContractNb" AS "Contract Nb",
|
||||||
|
dpc."strCounterparty" AS "Supplier",
|
||||||
|
dpc."strReference" AS "Contract Ref",
|
||||||
|
dpc."dtmContractDate" AS "Contract Date",
|
||||||
CASE
|
CASE
|
||||||
WHEN (("strContractStatus")::text = 'Draft'::text) THEN ((("strContractStatus")::text || ' 🧾'::text))::character varying
|
WHEN ((dpc."strContractStatus")::text = 'Draft'::text) THEN (((dpc."strContractStatus")::text || ' 🧾'::text))::character varying
|
||||||
WHEN (("strContractStatus")::text = 'Confirmed'::text) THEN ((("strContractStatus")::text || ' ✅'::text))::character varying
|
WHEN ((dpc."strContractStatus")::text = 'Confirmed'::text) THEN (((dpc."strContractStatus")::text || ' ✅'::text))::character varying
|
||||||
WHEN (("strContractStatus")::text = 'Validated'::text) THEN ((("strContractStatus")::text || ' ✔️'::text))::character varying
|
WHEN ((dpc."strContractStatus")::text = 'Validated'::text) THEN (((dpc."strContractStatus")::text || ' ✔️'::text))::character varying
|
||||||
WHEN (("strContractStatus")::text = 'Processing'::text) THEN ((("strContractStatus")::text || ' ⏳'::text))::character varying
|
WHEN ((dpc."strContractStatus")::text = 'Processing'::text) THEN (((dpc."strContractStatus")::text || ' ⏳'::text))::character varying
|
||||||
ELSE "strContractStatus"
|
ELSE dpc."strContractStatus"
|
||||||
END AS "Contract Status",
|
END AS "Contract Status",
|
||||||
"strPaymentTerm" AS "Payment Terms",
|
dpc."strPaymentTerm" AS "Payment Terms",
|
||||||
"strCurrency" AS "Currency",
|
dpc."strCurrency" AS "Currency",
|
||||||
"strWeightBasis" AS "Weight Basis",
|
dpc."strWeightBasis" AS "Weight Basis",
|
||||||
"strBroker" AS "Broker",
|
dpc."strBroker" AS "Broker",
|
||||||
"strCertif" AS "Certification",
|
dpc."strCertif" AS "Certification",
|
||||||
"strAssociation" AS "Association",
|
dpc."strAssociation" AS "Association",
|
||||||
"strCrop" AS "Crop",
|
dpc."strCrop" AS "Crop",
|
||||||
"dblTolMinPct" AS "Tolerance Min %",
|
dpc."dblTolMinPct" AS "Tolerance Min %",
|
||||||
"dblTolMaxPct" AS "Tolerance Max %",
|
dpc."dblTolMaxPct" AS "Tolerance Max %",
|
||||||
"strIncoterm" AS "Inco Terms",
|
dpc."strIncoterm" AS "Inco Terms",
|
||||||
"strLoadingPlace" AS "Loading Place",
|
dpc."strLoadingPlace" AS "Loading Place",
|
||||||
"strDestinationPlace" AS "Destination Place",
|
dpc."strDestinationPlace" AS "Destination Place",
|
||||||
"strProduct" AS "Product",
|
dpc."strProduct" AS "Product",
|
||||||
"strDeliveryPeriod" AS "Delivery Period",
|
dpc."strDeliveryPeriod" AS "Delivery Period",
|
||||||
"strRegion" AS "Bassin",
|
dpc."strRegion" AS "Bassin",
|
||||||
"strBookName" AS "Book",
|
dpc."strBookName" AS "Book",
|
||||||
"strStrategyName" AS "Strategy",
|
dpc."strStrategyName" AS "Strategy",
|
||||||
"strQuantityUom" AS "Quantity UOM",
|
dpc."strQuantityUom" AS "Quantity UOM",
|
||||||
"dtmDeliveryDateFrom" AS "Delivery Date From",
|
dpc."dtmDeliveryDateFrom" AS "Delivery Date From",
|
||||||
"dtmDeliveryDateTo" AS "Delivery Date To",
|
dpc."dtmDeliveryDateTo" AS "Delivery Date To",
|
||||||
CASE
|
CASE
|
||||||
WHEN ("dtmDeliveryDateTo" < CURRENT_DATE) THEN 'Overdue'::text
|
WHEN (dpc."dtmDeliveryDateTo" < CURRENT_DATE) THEN 'Overdue'::text
|
||||||
WHEN (("dtmDeliveryDateFrom" <= CURRENT_DATE) AND ("dtmDeliveryDateTo" >= CURRENT_DATE)) THEN 'Current'::text
|
WHEN ((dpc."dtmDeliveryDateFrom" <= CURRENT_DATE) AND (dpc."dtmDeliveryDateTo" >= CURRENT_DATE)) THEN 'Current'::text
|
||||||
WHEN ("dtmDeliveryDateFrom" > CURRENT_DATE) THEN 'Future'::text
|
WHEN (dpc."dtmDeliveryDateFrom" > CURRENT_DATE) THEN 'Future'::text
|
||||||
ELSE 'Unknown'::text
|
ELSE 'Unknown'::text
|
||||||
END AS "Delivery Status",
|
END AS "Delivery Status",
|
||||||
CASE
|
CASE
|
||||||
WHEN (("strBookName")::text ~~ '%Projection%'::text) THEN 'Yes'::text
|
WHEN ((dpc."strBookName")::text ~~ '%Projection%'::text) THEN 'Yes'::text
|
||||||
ELSE 'No'::text
|
ELSE 'No'::text
|
||||||
END AS "Is Projection",
|
END AS "Is Projection",
|
||||||
"strIncotermCode" AS "Incoterm Code",
|
dpc."strIncotermCode" AS "Incoterm Code",
|
||||||
"dtmEstimatedBLDate" AS "Estimated BL Date"
|
dpc."dtmEstimatedBLDate" AS "Estimated BL Date",
|
||||||
FROM vw_utility_dim_physical_purchase_contract dpc;;
|
dpc."strPricingType" AS "Pricing Type",
|
||||||
|
COALESCE(mtm."strStrategy", 'Undefined'::character varying) AS "MtM Strategy",
|
||||||
|
COALESCE(mtm."strScenario", 'Undefined'::character varying) AS "MtM Scenario",
|
||||||
|
COALESCE(mtm."strComponentCurve", 'Undefined'::character varying) AS "MtM Component Curve",
|
||||||
|
dpc."strCounterpartyCountry" AS "Supplier Country",
|
||||||
|
COALESCE(pvl."strState", ('Undefined'::character varying)::text) AS "Price Fixing Status",
|
||||||
|
(dpc."intPurchaseLineId" || '_0'::text) AS "strTradeId"
|
||||||
|
FROM ((vw_utility_dim_physical_purchase_contract dpc
|
||||||
|
LEFT JOIN vw_utility_physical_mtm_definition mtm ON (((dpc."intPurchaseLineId" = mtm."intContractLineId") AND (mtm."strContractType" = 'Purchase'::text) AND ((mtm."strComponentFixType")::text = 'Market price'::text))))
|
||||||
|
LEFT JOIN pricingstatus pvl ON ((dpc."intPurchaseLineId" = pvl."intContractLineId")));;
|
||||||
|
|||||||
@@ -1,46 +1,61 @@
|
|||||||
CREATE OR REPLACE VIEW public.vw_bi_dim_sale_physical_contract AS
|
CREATE OR REPLACE VIEW public.vw_bi_dim_sale_physical_contract AS
|
||||||
SELECT "intSaleLineId",
|
WITH pricingstatus AS (
|
||||||
"strContractNb" AS "Contract Nb",
|
SELECT pvl_1."intContractLineId",
|
||||||
"strCounterparty" AS "Customer",
|
pvl_1."strState"
|
||||||
"strReference" AS "Contract Ref",
|
FROM vw_utility_physical_valuation_line pvl_1
|
||||||
"dtmContractDate" AS "Contract Date",
|
GROUP BY pvl_1."intContractLineId", pvl_1."strState"
|
||||||
|
)
|
||||||
|
SELECT dpc."intSaleLineId",
|
||||||
|
dpc."strContractNb" AS "Contract Nb",
|
||||||
|
dpc."strCounterparty" AS "Customer",
|
||||||
|
dpc."strReference" AS "Contract Ref",
|
||||||
|
dpc."dtmContractDate" AS "Contract Date",
|
||||||
CASE
|
CASE
|
||||||
WHEN (("strContractStatus")::text = 'Draft'::text) THEN ((("strContractStatus")::text || ' 🧾'::text))::character varying
|
WHEN ((dpc."strContractStatus")::text = 'Draft'::text) THEN (((dpc."strContractStatus")::text || ' 🧾'::text))::character varying
|
||||||
WHEN (("strContractStatus")::text = 'Confirmed'::text) THEN ((("strContractStatus")::text || ' ✅'::text))::character varying
|
WHEN ((dpc."strContractStatus")::text = 'Confirmed'::text) THEN (((dpc."strContractStatus")::text || ' ✅'::text))::character varying
|
||||||
WHEN (("strContractStatus")::text = 'Validated'::text) THEN ((("strContractStatus")::text || ' ✔️'::text))::character varying
|
WHEN ((dpc."strContractStatus")::text = 'Validated'::text) THEN (((dpc."strContractStatus")::text || ' ✔️'::text))::character varying
|
||||||
WHEN (("strContractStatus")::text = 'Processing'::text) THEN ((("strContractStatus")::text || ' ⏳'::text))::character varying
|
WHEN ((dpc."strContractStatus")::text = 'Processing'::text) THEN (((dpc."strContractStatus")::text || ' ⏳'::text))::character varying
|
||||||
ELSE "strContractStatus"
|
ELSE dpc."strContractStatus"
|
||||||
END AS "Contract Status",
|
END AS "Contract Status",
|
||||||
"strPaymentTerm" AS "Payment Terms",
|
dpc."strPaymentTerm" AS "Payment Terms",
|
||||||
"strCurrency" AS "Currency",
|
dpc."strCurrency" AS "Currency",
|
||||||
"strWeightBasis" AS "Weight Basis",
|
dpc."strWeightBasis" AS "Weight Basis",
|
||||||
"strBroker" AS "Broker",
|
dpc."strBroker" AS "Broker",
|
||||||
"strCertif" AS "Certification",
|
dpc."strCertif" AS "Certification",
|
||||||
"strAssociation" AS "Association",
|
dpc."strAssociation" AS "Association",
|
||||||
"strCrop" AS "Crop",
|
dpc."strCrop" AS "Crop",
|
||||||
"dblTolMinPct" AS "Tolerance Min %",
|
dpc."dblTolMinPct" AS "Tolerance Min %",
|
||||||
"dblTolMaxPct" AS "Tolerance Max %",
|
dpc."dblTolMaxPct" AS "Tolerance Max %",
|
||||||
"strIncoterm" AS "Inco Terms",
|
dpc."strIncoterm" AS "Inco Terms",
|
||||||
"strLoadingPlace" AS "Loading Place",
|
dpc."strLoadingPlace" AS "Loading Place",
|
||||||
"strDestinationPlace" AS "Destination Place",
|
dpc."strDestinationPlace" AS "Destination Place",
|
||||||
"strProduct" AS "Product",
|
dpc."strProduct" AS "Product",
|
||||||
"strDeliveryPeriod" AS "Delivery Period",
|
dpc."strDeliveryPeriod" AS "Delivery Period",
|
||||||
"strQuantityUom" AS "Quantity UOM",
|
dpc."strQuantityUom" AS "Quantity UOM",
|
||||||
"dtmDeliveryDateFrom" AS "Delivery Date From",
|
dpc."dtmDeliveryDateFrom" AS "Delivery Date From",
|
||||||
"dtmDeliveryDateTo" AS "Delivery Date To",
|
dpc."dtmDeliveryDateTo" AS "Delivery Date To",
|
||||||
CASE
|
CASE
|
||||||
WHEN ("dtmDeliveryDateTo" < CURRENT_DATE) THEN 'Overdue'::text
|
WHEN (dpc."dtmDeliveryDateTo" < CURRENT_DATE) THEN 'Overdue'::text
|
||||||
WHEN (("dtmDeliveryDateFrom" <= CURRENT_DATE) AND ("dtmDeliveryDateTo" >= CURRENT_DATE)) THEN 'Current'::text
|
WHEN ((dpc."dtmDeliveryDateFrom" <= CURRENT_DATE) AND (dpc."dtmDeliveryDateTo" >= CURRENT_DATE)) THEN 'Current'::text
|
||||||
WHEN ("dtmDeliveryDateFrom" > CURRENT_DATE) THEN 'Future'::text
|
WHEN (dpc."dtmDeliveryDateFrom" > CURRENT_DATE) THEN 'Future'::text
|
||||||
ELSE 'Unknown'::text
|
ELSE 'Unknown'::text
|
||||||
END AS "Delivery Status",
|
END AS "Delivery Status",
|
||||||
"strRegion" AS "Bassin",
|
dpc."strRegion" AS "Bassin",
|
||||||
"strBookName" AS "Book",
|
dpc."strBookName" AS "Book",
|
||||||
"strStrategyName" AS "Strategy",
|
dpc."strStrategyName" AS "Strategy",
|
||||||
CASE
|
CASE
|
||||||
WHEN (("strBookName")::text ~~ '%Projection%'::text) THEN 'Yes'::text
|
WHEN ((dpc."strBookName")::text ~~ '%Projection%'::text) THEN 'Yes'::text
|
||||||
ELSE 'No'::text
|
ELSE 'No'::text
|
||||||
END AS "Is Projection",
|
END AS "Is Projection",
|
||||||
"strIncotermCode" AS "Incoterm Code",
|
dpc."strIncotermCode" AS "Incoterm Code",
|
||||||
"dtmEstimatedBLDate" AS "Estimated BL Date"
|
dpc."dtmEstimatedBLDate" AS "Estimated BL Date",
|
||||||
FROM vw_utility_dim_physical_sale_contract dpc;;
|
dpc."strPricingType" AS "Pricing Type",
|
||||||
|
COALESCE(mtm."strStrategy", 'Undefined'::character varying) AS "MtM Strategy",
|
||||||
|
COALESCE(mtm."strScenario", 'Undefined'::character varying) AS "MtM Scenario",
|
||||||
|
COALESCE(mtm."strComponentCurve", 'Undefined'::character varying) AS "MtM Component Curve",
|
||||||
|
dpc."strCounterpartyCountry" AS "Customer Country",
|
||||||
|
COALESCE(pvl."strState", ('Undefined'::character varying)::text) AS "Price Fixing Status",
|
||||||
|
('0_'::text || dpc."intSaleLineId") AS "strTradeLineId"
|
||||||
|
FROM ((vw_utility_dim_physical_sale_contract dpc
|
||||||
|
LEFT JOIN vw_utility_physical_mtm_definition mtm ON (((dpc."intSaleLineId" = mtm."intContractLineId") AND (mtm."strContractType" = 'Sale'::text) AND ((mtm."strComponentFixType")::text = 'Market price'::text))))
|
||||||
|
LEFT JOIN pricingstatus pvl ON ((dpc."intSaleLineId" = pvl."intContractLineId")));;
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
CREATE OR REPLACE VIEW public.vw_bi_dim_trade AS
|
CREATE OR REPLACE VIEW public.vw_bi_dim_trade AS
|
||||||
SELECT pc."intPurchaseLineId" AS "intTradeId",
|
SELECT pc."intPurchaseLineId" AS "intTradeId",
|
||||||
|
(pc."intPurchaseLineId" || '_0'::text) AS "strTradeId",
|
||||||
'Physical'::text AS "Trade Category",
|
'Physical'::text AS "Trade Category",
|
||||||
'Purchase'::text AS "Trade Type",
|
'Purchase'::text AS "Trade Type",
|
||||||
pc."strReference" AS "Trade Ref",
|
pc."strReference" AS "Trade Ref",
|
||||||
|
pc."strContractNb" AS "Trade Number",
|
||||||
pc."dtmContractDate" AS "Trade Date",
|
pc."dtmContractDate" AS "Trade Date",
|
||||||
pc."strCounterparty" AS "Counterparty",
|
pc."strCounterparty" AS "Counterparty",
|
||||||
pc."strRegion" AS "Bassin",
|
pc."strRegion" AS "Bassin",
|
||||||
@@ -12,9 +14,11 @@ CREATE OR REPLACE VIEW public.vw_bi_dim_trade AS
|
|||||||
WHERE ((1 = 1) AND (pc."intPurchaseLineId" > 0))
|
WHERE ((1 = 1) AND (pc."intPurchaseLineId" > 0))
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT sc."intSaleLineId" AS "intTradeId",
|
SELECT sc."intSaleLineId" AS "intTradeId",
|
||||||
|
('0_'::text || sc."intSaleLineId") AS "strTradeId",
|
||||||
'Physical'::text AS "Trade Category",
|
'Physical'::text AS "Trade Category",
|
||||||
'Sale'::text AS "Trade Type",
|
'Sale'::text AS "Trade Type",
|
||||||
sc."strReference" AS "Trade Ref",
|
sc."strReference" AS "Trade Ref",
|
||||||
|
sc."strContractNb" AS "Trade Number",
|
||||||
sc."dtmContractDate" AS "Trade Date",
|
sc."dtmContractDate" AS "Trade Date",
|
||||||
sc."strCounterparty" AS "Counterparty",
|
sc."strCounterparty" AS "Counterparty",
|
||||||
sc."strRegion" AS "Bassin",
|
sc."strRegion" AS "Bassin",
|
||||||
|
|||||||
9
Database Backups/SQL Views/vw_bi_itsa_dim_pnl_type.sql
Normal file
9
Database Backups/SQL Views/vw_bi_itsa_dim_pnl_type.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE OR REPLACE VIEW public.vw_bi_itsa_dim_pnl_type AS
|
||||||
|
SELECT 1 AS "intPnlTypeId",
|
||||||
|
'Expected'::text AS "PNL Type"
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3 AS "intPnlTypeId",
|
||||||
|
'Realized'::text AS "PNL Type"
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2 AS "intPnlTypeId",
|
||||||
|
'Forward'::text AS "PNL Type";;
|
||||||
12
Database Backups/SQL Views/vw_bi_itsa_dim_price_group.sql
Normal file
12
Database Backups/SQL Views/vw_bi_itsa_dim_price_group.sql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
CREATE OR REPLACE VIEW public.vw_bi_itsa_dim_price_group AS
|
||||||
|
SELECT 1 AS "intPriceGroupId",
|
||||||
|
'Price'::text AS "Price Group",
|
||||||
|
1 AS "Group Order"
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2 AS "intPriceGroupId",
|
||||||
|
'Fees'::text AS "Price Group",
|
||||||
|
2 AS "Group Order"
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3 AS "intPriceGroupId",
|
||||||
|
'MTM'::text AS "Price Group",
|
||||||
|
2 AS "Group Order";;
|
||||||
@@ -1,30 +1,49 @@
|
|||||||
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_contract AS
|
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_contract AS
|
||||||
|
WITH valuation_info AS (
|
||||||
|
SELECT pvl."intContractId",
|
||||||
|
pvl."intContractLineId",
|
||||||
|
pvl."strState",
|
||||||
|
avg(pvl."dblPrice") AS "avgPrice",
|
||||||
|
avg(pvl."dblMtmPrice") AS "avgMtmPrice"
|
||||||
|
FROM vw_utility_physical_valuation_line pvl
|
||||||
|
GROUP BY pvl."intContractId", pvl."intContractLineId", pvl."strState"
|
||||||
|
)
|
||||||
SELECT 'Purchase'::text AS "TradeType",
|
SELECT 'Purchase'::text AS "TradeType",
|
||||||
pc."intPurchaseLineId" AS "TradeLineId",
|
pc."intPurchaseLineId" AS "TradeLineId",
|
||||||
pc."dblQuantity" AS "Quantity",
|
pc."dblQuantity" AS "Quantity",
|
||||||
pc."dblTheoriticalQuantity" AS "TheoriticalQuantity",
|
pc."dblTheoriticalQuantity" AS "Contract Quantity",
|
||||||
pc."dblInInstructedQuantity" AS "InstructedQuantity",
|
pc."dblInInstructedQuantity" AS "InstructedQuantity",
|
||||||
CASE
|
CASE
|
||||||
WHEN (pc."ysnFinished" = true) THEN (0)::numeric(18,3)
|
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)
|
WHEN ((pc."dblTheoriticalQuantity")::double precision > pc."dblInInstructedQuantity") THEN (((pc."dblTheoriticalQuantity")::double precision - pc."dblInInstructedQuantity"))::numeric(18,3)
|
||||||
ELSE (0)::numeric(18,3)
|
ELSE (0)::numeric(18,3)
|
||||||
END AS "Open Quantity",
|
END AS "Open Quantity",
|
||||||
pc."dblUnitPrice" AS "Price",
|
COALESCE(pc."dtmEstimatedBLDate", pc."dtmDeliveryDateFrom") AS "Delivery Date",
|
||||||
COALESCE(pc."dtmEstimatedBLDate", pc."dtmDeliveryDateFrom") AS "DeliveryDate"
|
COALESCE(vi."strState", 'Unknown'::text) AS "Price Fixing Status",
|
||||||
FROM vw_utility_purchase_physical_contract pc
|
COALESCE(vi."avgPrice", (0)::numeric) AS "Avg Price",
|
||||||
|
COALESCE(vi."avgMtmPrice", (0)::numeric) AS "Avg Mtm Price",
|
||||||
|
pc."dblTheoriticalQuantity" AS "Contract Quantity Signed",
|
||||||
|
pc."dblInInstructedQuantity" AS "Instructed Quantity Signed"
|
||||||
|
FROM (vw_utility_purchase_physical_contract pc
|
||||||
|
LEFT JOIN valuation_info vi ON ((pc."intPurchaseLineId" = vi."intContractLineId")))
|
||||||
WHERE (1 = 1)
|
WHERE (1 = 1)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT 'Sale'::text AS "TradeType",
|
SELECT 'Sale'::text AS "TradeType",
|
||||||
pc."intSaleLineId" AS "TradeLineId",
|
pc."intSaleLineId" AS "TradeLineId",
|
||||||
pc."dblQuantity" AS "Quantity",
|
pc."dblQuantity" AS "Quantity",
|
||||||
pc."dblTheoreticalQuantity" AS "TheoriticalQuantity",
|
pc."dblTheoreticalQuantity" AS "Contract Quantity",
|
||||||
pc."dblInstructedQuantity" AS "InstructedQuantity",
|
pc."dblInstructedQuantity" AS "InstructedQuantity",
|
||||||
CASE
|
CASE
|
||||||
WHEN (pc."ysnFinished" = true) THEN (0)::numeric(18,3)
|
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)
|
WHEN ((pc."dblTheoreticalQuantity")::double precision > pc."dblInstructedQuantity") THEN (((pc."dblTheoreticalQuantity")::double precision - pc."dblInstructedQuantity"))::numeric(18,3)
|
||||||
ELSE (0)::numeric(18,3)
|
ELSE (0)::numeric(18,3)
|
||||||
END AS "Open Quantity",
|
END AS "Open Quantity",
|
||||||
pc."dblUnitPrice" AS "Price",
|
COALESCE(pc."dtmEstimatedBLDate", pc."dtmDeliveryDateFrom") AS "Delivery Date",
|
||||||
COALESCE(pc."dtmEstimatedBLDate", pc."dtmDeliveryDateFrom") AS "DeliveryDate"
|
COALESCE(vi."strState", 'Unknown'::text) AS "Price Fixing Status",
|
||||||
FROM vw_utility_sale_physical_contract pc
|
COALESCE(vi."avgPrice", (0)::numeric) AS "Avg Price",
|
||||||
|
COALESCE(vi."avgMtmPrice", (0)::numeric) AS "Avg Mtm Price",
|
||||||
|
(pc."dblTheoreticalQuantity" * ('-1'::integer)::numeric) AS "Contract Quantity Signed",
|
||||||
|
(pc."dblInstructedQuantity" * (('-1'::integer)::numeric)::double precision) AS "Instructed Quantity Signed"
|
||||||
|
FROM (vw_utility_sale_physical_contract pc
|
||||||
|
LEFT JOIN valuation_info vi ON ((pc."intSaleLineId" = vi."intContractLineId")))
|
||||||
WHERE (1 = 1);;
|
WHERE (1 = 1);;
|
||||||
|
|||||||
65
Database Backups/SQL Views/vw_bi_itsa_fct_full_pnl.sql
Normal file
65
Database Backups/SQL Views/vw_bi_itsa_fct_full_pnl.sql
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
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
|
||||||
|
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
|
||||||
|
FROM vw_utility_dim_physical_sale_contract sc
|
||||||
|
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0))
|
||||||
|
)
|
||||||
|
SELECT 2 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"
|
||||||
|
FROM (vw_bi_itsa_physical_open_costs contracts
|
||||||
|
JOIN trade trade ON ((contracts."intTradeLineId" = trade."intTradeId")))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3 AS "intPnlTypeId",
|
||||||
|
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
|
||||||
|
1 AS "intPriceGroupId",
|
||||||
|
'Purchase'::character varying 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,
|
||||||
|
shipment."BL Date" AS "Delivery Date"
|
||||||
|
FROM vw_bi_itsa_fct_shipments shipment
|
||||||
|
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"
|
||||||
|
FROM vw_bi_itsa_fct_shipments shipment
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3 AS "intPnlTypeId",
|
||||||
|
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") 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"
|
||||||
|
FROM (vw_bi_itsa_fct_shipment_fees fees
|
||||||
|
JOIN vw_bi_itsa_fct_shipments shipment ON ((fees."intShipmentId" = shipment."intShipmentId")))
|
||||||
|
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"
|
||||||
|
FROM (vw_bi_itsa_fct_contract ctr
|
||||||
|
JOIN vw_bi_dim_trade trade ON ((ctr."TradeLineId" = trade."intTradeId")))
|
||||||
|
WHERE ((trade."Book")::text ~~ '%Projection%'::text);;
|
||||||
@@ -10,7 +10,9 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_shipments AS
|
|||||||
sm."dblQuantity" AS "Shipped Quantity",
|
sm."dblQuantity" AS "Shipped Quantity",
|
||||||
sm."strUnit" AS "Quantity Unit",
|
sm."strUnit" AS "Quantity Unit",
|
||||||
COALESCE(p."dblUnitPrice", (0)::numeric) AS "Purchase Price",
|
COALESCE(p."dblUnitPrice", (0)::numeric) AS "Purchase Price",
|
||||||
COALESCE(s."dblUnitPrice", (0)::numeric) AS "Sale Price"
|
COALESCE(s."dblUnitPrice", (0)::numeric) AS "Sale Price",
|
||||||
FROM ((vw_utility_stock_movements sm
|
shipment."dtmBillOfLadingDate" AS "BL Date"
|
||||||
|
FROM (((vw_utility_stock_movements sm
|
||||||
|
JOIN vw_utility_shipment_in shipment ON ((sm."intShipmentId" = shipment."intShipmentId")))
|
||||||
LEFT JOIN vw_utility_purchase_physical_contract p ON ((sm."intPurchaseLineId" = p."intPurchaseLineId")))
|
LEFT JOIN vw_utility_purchase_physical_contract p ON ((sm."intPurchaseLineId" = p."intPurchaseLineId")))
|
||||||
LEFT JOIN vw_utility_sale_physical_contract s ON ((sm."intSaleLineId" = s."intSaleLineId")));;
|
LEFT JOIN vw_utility_sale_physical_contract s ON ((sm."intSaleLineId" = s."intSaleLineId")));;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE OR REPLACE VIEW public.vw_bi_itsa_monthly_trade_ifrs_adjustments AS
|
||||||
|
SELECT "intAdjustmentId",
|
||||||
|
"dtmAdjustmentDate" AS "Adjustment Date",
|
||||||
|
"dblAmount" AS "Amount",
|
||||||
|
"strCurrency" AS "Currency",
|
||||||
|
"strComments" AS "Comments"
|
||||||
|
FROM vw_utility_monthly_trade_ifrs_adjustments;;
|
||||||
148
Database Backups/SQL Views/vw_bi_itsa_physical_open_costs.sql
Normal file
148
Database Backups/SQL Views/vw_bi_itsa_physical_open_costs.sql
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
CREATE OR REPLACE VIEW public.vw_bi_itsa_physical_open_costs AS
|
||||||
|
WITH valuation_info AS (
|
||||||
|
SELECT pvl."intContractId",
|
||||||
|
pvl."intContractLineId",
|
||||||
|
pvl."strState",
|
||||||
|
avg(pvl."dblPrice") AS "avgPrice",
|
||||||
|
(avg(pvl."dblMtmPrice"))::numeric(18,2) AS "avgMtmPrice"
|
||||||
|
FROM vw_utility_physical_valuation_line pvl
|
||||||
|
GROUP BY pvl."intContractId", pvl."intContractLineId", pvl."strState"
|
||||||
|
), contract_open_quantity AS (
|
||||||
|
SELECT 'Purchase'::text AS "TradeType",
|
||||||
|
pc."intPurchaseLineId" AS "TradeLineId",
|
||||||
|
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",
|
||||||
|
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 "OpenQuantitySigned",
|
||||||
|
COALESCE(vi."avgMtmPrice", (0)::numeric(18,2)) AS "AvgMtmPrice",
|
||||||
|
pc."dblTheoriticalQuantity" AS "TheoriticalQuantitySigned"
|
||||||
|
FROM (vw_utility_purchase_physical_contract pc
|
||||||
|
LEFT JOIN valuation_info vi ON ((pc."intPurchaseLineId" = vi."intContractLineId")))
|
||||||
|
WHERE (1 = 1)
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'Sale'::text AS "TradeType",
|
||||||
|
pc."intSaleLineId" AS "TradeLineId",
|
||||||
|
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",
|
||||||
|
(
|
||||||
|
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 * ('-1'::integer)::numeric) AS "OpenQuantitySigned",
|
||||||
|
COALESCE(vi."avgMtmPrice", (0)::numeric(18,2)) AS "AvgMtmPrice",
|
||||||
|
(pc."dblTheoreticalQuantity" * ('-1'::integer)::numeric) AS "TheoriticalQuantitySigned"
|
||||||
|
FROM (vw_utility_sale_physical_contract pc
|
||||||
|
LEFT JOIN valuation_info vi ON ((pc."intSaleLineId" = vi."intContractLineId")))
|
||||||
|
WHERE (1 = 1)
|
||||||
|
)
|
||||||
|
SELECT 1 AS "Group Order",
|
||||||
|
'Price'::text AS "Group Type",
|
||||||
|
ctr."intPurchaseLineId" AS "intTradeLineId",
|
||||||
|
'Fixed Price'::character varying AS "Line Description",
|
||||||
|
pur."dblUnitPrice" AS "Price",
|
||||||
|
opq."OpenQuantitySigned" AS "Open Quantity Signed",
|
||||||
|
((opq."OpenQuantitySigned" * pur."dblUnitPrice") * ('-1'::integer)::numeric) AS "Open Cost Amount",
|
||||||
|
1 AS "intPriceGroupId",
|
||||||
|
ctr."dtmEstimatedBLDate" AS "Estimated BL Date",
|
||||||
|
opq."TheoriticalQuantitySigned" AS "Contract Quantity Signed"
|
||||||
|
FROM ((vw_utility_dim_physical_purchase_contract ctr
|
||||||
|
JOIN vw_utility_purchase_physical_contract pur ON ((ctr."intPurchaseLineId" = pur."intPurchaseLineId")))
|
||||||
|
JOIN contract_open_quantity opq ON (((ctr."intPurchaseLineId" = opq."TradeLineId") AND (opq."TradeType" = 'Purchase'::text))))
|
||||||
|
WHERE (((ctr."strPricingType")::text = 'priced'::text) AND (opq."OpenQuantity" <> (0)::numeric))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2 AS "Group Order",
|
||||||
|
'MTM'::text AS "Group Type",
|
||||||
|
ctr."intPurchaseLineId" AS "intTradeLineId",
|
||||||
|
mtm."strComponentCurve" AS "Line Description",
|
||||||
|
opq."AvgMtmPrice" AS "Price",
|
||||||
|
opq."OpenQuantitySigned" AS "Open Quantity Signed",
|
||||||
|
(opq."OpenQuantitySigned" * opq."AvgMtmPrice") AS "Open Cost Amount",
|
||||||
|
3 AS "intPriceGroupId",
|
||||||
|
ctr."dtmEstimatedBLDate" AS "Estimated BL Date",
|
||||||
|
opq."TheoriticalQuantitySigned" AS "Contract Quantity Signed"
|
||||||
|
FROM ((vw_utility_physical_mtm_definition mtm
|
||||||
|
JOIN vw_utility_dim_physical_purchase_contract ctr ON ((mtm."intContractLineId" = ctr."intPurchaseLineId")))
|
||||||
|
JOIN contract_open_quantity opq ON (((ctr."intPurchaseLineId" = opq."TradeLineId") AND (opq."TradeType" = 'Purchase'::text))))
|
||||||
|
WHERE ((mtm."strContractType" = 'Purchase'::text) AND (opq."OpenQuantity" <> (0)::numeric))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3 AS "Group Order",
|
||||||
|
'Fee'::text AS "Group Type",
|
||||||
|
fees."intContractLineId" AS "intTradeLineId",
|
||||||
|
fees."strProduct" AS "Line Description",
|
||||||
|
fees."dblPrice" AS "Price",
|
||||||
|
opq."OpenQuantitySigned" AS "Open Quantity Signed",
|
||||||
|
((((
|
||||||
|
CASE
|
||||||
|
WHEN ((fees."strPayOrRec")::text = 'pay'::text) THEN 1
|
||||||
|
ELSE '-1'::integer
|
||||||
|
END)::numeric * opq."OpenQuantity") * fees."dblPrice") * ('-1'::integer)::numeric) AS "Open Cost Amount",
|
||||||
|
2 AS "intPriceGroupId",
|
||||||
|
ctr."dtmEstimatedBLDate" AS "Estimated BL Date",
|
||||||
|
opq."TheoriticalQuantitySigned" AS "Contract Quantity Signed"
|
||||||
|
FROM ((vw_utility_contract_fees fees
|
||||||
|
JOIN vw_utility_dim_physical_purchase_contract ctr ON ((fees."intContractLineId" = ctr."intPurchaseLineId")))
|
||||||
|
JOIN contract_open_quantity opq ON (((ctr."intPurchaseLineId" = opq."TradeLineId") AND (opq."TradeType" = 'Purchase'::text))))
|
||||||
|
WHERE ((fees."strContractType" = 'Purchase'::text) AND (opq."OpenQuantity" <> (0)::numeric))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 1 AS "Group Order",
|
||||||
|
'Price'::text AS "Group Type",
|
||||||
|
ctr."intSaleLineId" AS "intTradeLineId",
|
||||||
|
'Fixed Price'::character varying AS "Line Description",
|
||||||
|
sale."dblUnitPrice" AS "Price",
|
||||||
|
opq."OpenQuantitySigned" AS "Open Quantity Signed",
|
||||||
|
((opq."OpenQuantitySigned" * sale."dblUnitPrice") * ('-1'::integer)::numeric) AS "Open Cost Amount",
|
||||||
|
1 AS "intPriceGroupId",
|
||||||
|
ctr."dtmEstimatedBLDate" AS "Estimated BL Date",
|
||||||
|
opq."TheoriticalQuantitySigned" AS "Contract Quantity Signed"
|
||||||
|
FROM ((vw_utility_dim_physical_sale_contract ctr
|
||||||
|
JOIN vw_utility_sale_physical_contract sale ON ((ctr."intSaleLineId" = sale."intSaleLineId")))
|
||||||
|
JOIN contract_open_quantity opq ON (((ctr."intSaleLineId" = opq."TradeLineId") AND (opq."TradeType" = 'Sale'::text))))
|
||||||
|
WHERE (((ctr."strPricingType")::text = 'priced'::text) AND (opq."OpenQuantity" <> (0)::numeric))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 2 AS "Group Order",
|
||||||
|
'MTM'::text AS "Group Type",
|
||||||
|
ctr."intSaleLineId" AS "intTradeLineId",
|
||||||
|
mtm."strComponentCurve" AS "Line Description",
|
||||||
|
opq."AvgMtmPrice" AS "Price",
|
||||||
|
opq."OpenQuantitySigned" AS "Open Quantity Signed",
|
||||||
|
(opq."OpenQuantitySigned" * opq."AvgMtmPrice") AS "Open Cost Amount",
|
||||||
|
3 AS "intPriceGroupId",
|
||||||
|
ctr."dtmEstimatedBLDate" AS "Estimated BL Date",
|
||||||
|
opq."TheoriticalQuantitySigned" AS "Contract Quantity Signed"
|
||||||
|
FROM ((vw_utility_physical_mtm_definition mtm
|
||||||
|
JOIN vw_utility_dim_physical_sale_contract ctr ON ((mtm."intContractLineId" = ctr."intSaleLineId")))
|
||||||
|
JOIN contract_open_quantity opq ON (((ctr."intSaleLineId" = opq."TradeLineId") AND (opq."TradeType" = 'Sale'::text))))
|
||||||
|
WHERE ((mtm."strContractType" = 'Sale'::text) AND (opq."OpenQuantity" <> (0)::numeric))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 3 AS "Group Order",
|
||||||
|
'Fee'::text AS "Group Type",
|
||||||
|
fees."intContractLineId" AS "intTradeLineId",
|
||||||
|
fees."strProduct" AS "Line Description",
|
||||||
|
fees."dblPrice" AS "Price",
|
||||||
|
opq."OpenQuantitySigned" AS "Open Quantity Signed",
|
||||||
|
((((
|
||||||
|
CASE
|
||||||
|
WHEN ((fees."strPayOrRec")::text = 'pay'::text) THEN 1
|
||||||
|
ELSE '-1'::integer
|
||||||
|
END)::numeric * opq."OpenQuantity") * fees."dblPrice") * ('-1'::integer)::numeric) AS "Open Cost Amount",
|
||||||
|
2 AS "intPriceGroupId",
|
||||||
|
ctr."dtmEstimatedBLDate" AS "Estimated BL Date",
|
||||||
|
opq."TheoriticalQuantitySigned" AS "Contract Quantity Signed"
|
||||||
|
FROM ((vw_utility_contract_fees fees
|
||||||
|
JOIN vw_utility_dim_physical_sale_contract ctr ON ((fees."intContractLineId" = ctr."intSaleLineId")))
|
||||||
|
JOIN contract_open_quantity opq ON (((ctr."intSaleLineId" = opq."TradeLineId") AND (opq."TradeType" = 'Sale'::text))))
|
||||||
|
WHERE ((fees."strContractType" = 'Sale'::text) AND (opq."OpenQuantity" <> (0)::numeric));;
|
||||||
@@ -27,7 +27,9 @@ CREATE OR REPLACE VIEW public.vw_utility_dim_physical_purchase_contract AS
|
|||||||
''::character varying AS "strBookName",
|
''::character varying AS "strBookName",
|
||||||
''::character varying AS "strQuantityUom",
|
''::character varying AS "strQuantityUom",
|
||||||
''::character varying AS "strIncotermCode",
|
''::character varying AS "strIncotermCode",
|
||||||
NULL::date AS "dtmEstimatedBLDate"
|
NULL::date AS "dtmEstimatedBLDate",
|
||||||
|
''::character varying AS "strPricingType",
|
||||||
|
''::character varying AS "strCounterpartyCountry"
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT pl.id AS "intPurchaseLineId",
|
SELECT pl.id AS "intPurchaseLineId",
|
||||||
pc.number AS "strContractNb",
|
pc.number AS "strContractNb",
|
||||||
@@ -62,7 +64,9 @@ UNION ALL
|
|||||||
book."strValueName" AS "strBookName",
|
book."strValueName" AS "strBookName",
|
||||||
pu1.name AS "strQuantityUom",
|
pu1.name AS "strQuantityUom",
|
||||||
COALESCE(inc.code, ''::character varying) AS "strIncotermCode",
|
COALESCE(inc.code, ''::character varying) AS "strIncotermCode",
|
||||||
COALESCE(bl.estimated_date, pl.to_del) AS "dtmEstimatedBLDate"
|
COALESCE(bl.estimated_date, pl.to_del) AS "dtmEstimatedBLDate",
|
||||||
|
pl.price_type AS "strPricingType",
|
||||||
|
COALESCE(ad."strCountry", 'Undefined'::character varying) AS "strCounterpartyCountry"
|
||||||
FROM (((((((((((((((((((purchase_line pl
|
FROM (((((((((((((((((((purchase_line pl
|
||||||
JOIN purchase_purchase pc ON ((pl.purchase = pc.id)))
|
JOIN purchase_purchase pc ON ((pl.purchase = pc.id)))
|
||||||
JOIN party_party pty ON ((pc.party = pty.id)))
|
JOIN party_party pty ON ((pc.party = pty.id)))
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ CREATE OR REPLACE VIEW public.vw_utility_dim_physical_sale_contract AS
|
|||||||
''::character varying AS "strStrategyName",
|
''::character varying AS "strStrategyName",
|
||||||
''::character varying AS "strBookName",
|
''::character varying AS "strBookName",
|
||||||
''::character varying AS "strIncotermCode",
|
''::character varying AS "strIncotermCode",
|
||||||
NULL::date AS "dtmEstimatedBLDate"
|
NULL::date AS "dtmEstimatedBLDate",
|
||||||
|
''::character varying AS "strPricingType",
|
||||||
|
''::character varying AS "strCounterpartyCountry"
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT sl.id AS "intSaleLineId",
|
SELECT sl.id AS "intSaleLineId",
|
||||||
sc.number AS "strContractNb",
|
sc.number AS "strContractNb",
|
||||||
@@ -57,7 +59,9 @@ UNION ALL
|
|||||||
strategy."strValueName" AS "strStrategyName",
|
strategy."strValueName" AS "strStrategyName",
|
||||||
book."strValueName" AS "strBookName",
|
book."strValueName" AS "strBookName",
|
||||||
COALESCE(inc.code, ''::character varying) AS "strIncotermCode",
|
COALESCE(inc.code, ''::character varying) AS "strIncotermCode",
|
||||||
COALESCE(bl.estimated_date, sl.to_del) AS "dtmEstimatedBLDate"
|
COALESCE(bl.estimated_date, sl.to_del) AS "dtmEstimatedBLDate",
|
||||||
|
sl.price_type AS "strPricingType",
|
||||||
|
COALESCE(ad."strCountry", 'Undefined'::character varying) AS "strCounterpartyCountry"
|
||||||
FROM (((((((((((((((((((sale_line sl
|
FROM (((((((((((((((((((sale_line sl
|
||||||
JOIN sale_sale sc ON ((sl.sale = sc.id)))
|
JOIN sale_sale sc ON ((sl.sale = sc.id)))
|
||||||
JOIN party_party pty ON ((sc.party = pty.id)))
|
JOIN party_party pty ON ((sc.party = pty.id)))
|
||||||
@@ -77,5 +81,5 @@ UNION ALL
|
|||||||
LEFT JOIN vw_utility_last_counterparty_address ad ON ((pty.id = ad."intPartyId")))
|
LEFT JOIN vw_utility_last_counterparty_address ad ON ((pty.id = ad."intPartyId")))
|
||||||
LEFT JOIN vw_utility_strategy_dimension strategy ON (((sl.id = strategy."intTradeLineId") AND (strategy."strTradeCategory" = 'Physical'::text) AND (strategy."strTradeType" = 'Sale'::text))))
|
LEFT JOIN vw_utility_strategy_dimension strategy ON (((sl.id = strategy."intTradeLineId") AND (strategy."strTradeCategory" = 'Physical'::text) AND (strategy."strTradeType" = 'Sale'::text))))
|
||||||
LEFT JOIN vw_utility_book_dimension book ON (((sl.id = book."intTradeLineId") AND (book."strTradeCategory" = 'Physical'::text) AND (book."strTradeType" = 'Sale'::text))))
|
LEFT JOIN vw_utility_book_dimension book ON (((sl.id = book."intTradeLineId") AND (book."strTradeCategory" = 'Physical'::text) AND (book."strTradeType" = 'Sale'::text))))
|
||||||
LEFT JOIN pricing_estimated bl ON (((sl.id = bl.line) AND ((bl.trigger)::text = 'bldate'::text))))
|
LEFT JOIN pricing_estimated bl ON (((sl.id = bl.sale_line) AND ((bl.trigger)::text = 'bldate'::text))))
|
||||||
WHERE ((1 = 1) AND ((sl.type)::text = 'line'::text));;
|
WHERE ((1 = 1) AND ((sl.type)::text = 'line'::text));;
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
CREATE OR REPLACE VIEW public.vw_utility_monthly_trade_ifrs_adjustments AS
|
||||||
|
SELECT apti.id AS "intAdjustmentId",
|
||||||
|
apti.date AS "dtmAdjustmentDate",
|
||||||
|
apti.amount AS "dblAmount",
|
||||||
|
cur.name AS "strCurrency",
|
||||||
|
apti.comment AS "strComments"
|
||||||
|
FROM (account_physical_trade_ifrs apti
|
||||||
|
JOIN currency_currency cur ON ((cur.id = apti.currency)));;
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
CREATE OR REPLACE VIEW public.vw_utility_physical_mtm_definition AS
|
||||||
|
SELECT 'Purchase'::text AS "strContractType",
|
||||||
|
pp.id AS "intContractId",
|
||||||
|
pl.id AS "intContractLineId",
|
||||||
|
pl.quantity AS "dblLineQuantity",
|
||||||
|
ms.name AS "strStrategy",
|
||||||
|
msc.name AS "strScenario",
|
||||||
|
cur.symbol AS "strStrategyCurrency",
|
||||||
|
pc_mtm.price_source_type AS "strComponentPriceSource",
|
||||||
|
pc_mtm.ratio AS "strComponentRatioPct",
|
||||||
|
ft.name AS "strComponentFixType",
|
||||||
|
pi.price_desc AS "strComponentCurve",
|
||||||
|
pc_cal.name AS "strComponentCalendar"
|
||||||
|
FROM (((((((((purchase_strategy ps
|
||||||
|
JOIN purchase_line pl ON ((pl.id = ps.line)))
|
||||||
|
JOIN purchase_purchase pp ON ((pp.id = pl.purchase)))
|
||||||
|
JOIN mtm_strategy ms ON ((ms.id = ps.strategy)))
|
||||||
|
JOIN mtm_scenario msc ON ((msc.id = ms.scenario)))
|
||||||
|
JOIN currency_currency cur ON ((cur.id = ms.currency)))
|
||||||
|
LEFT JOIN pricing_component pc_mtm ON ((pc_mtm.strategy = ms.id)))
|
||||||
|
LEFT JOIN price_fixtype ft ON ((ft.id = pc_mtm.fix_type)))
|
||||||
|
LEFT JOIN price_price pi ON ((pi.id = pc_mtm.price_index)))
|
||||||
|
LEFT JOIN price_calendar pc_cal ON ((pc_cal.id = pc_mtm.calendar)))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'Sale'::text AS "strContractType",
|
||||||
|
ss.id AS "intContractId",
|
||||||
|
sl.id AS "intContractLineId",
|
||||||
|
sl.quantity AS "dblLineQuantity",
|
||||||
|
ms.name AS "strStrategy",
|
||||||
|
msc.name AS "strScenario",
|
||||||
|
cur.symbol AS "strStrategyCurrency",
|
||||||
|
pc_mtm.price_source_type AS "strComponentPriceSource",
|
||||||
|
pc_mtm.ratio AS "strComponentRatioPct",
|
||||||
|
ft.name AS "strComponentFixType",
|
||||||
|
pi.price_desc AS "strComponentCurve",
|
||||||
|
pc_cal.name AS "strComponentCalendar"
|
||||||
|
FROM (((((((((sale_strategy sa
|
||||||
|
JOIN sale_line sl ON ((sl.id = sa.sale_line)))
|
||||||
|
JOIN sale_sale ss ON ((ss.id = sl.sale)))
|
||||||
|
JOIN mtm_strategy ms ON ((ms.id = sa.strategy)))
|
||||||
|
JOIN mtm_scenario msc ON ((msc.id = ms.scenario)))
|
||||||
|
JOIN currency_currency cur ON ((cur.id = ms.currency)))
|
||||||
|
LEFT JOIN pricing_component pc_mtm ON ((pc_mtm.strategy = ms.id)))
|
||||||
|
LEFT JOIN price_fixtype ft ON ((ft.id = pc_mtm.fix_type)))
|
||||||
|
LEFT JOIN price_price pi ON ((pi.id = pc_mtm.price_index)))
|
||||||
|
LEFT JOIN price_calendar pc_cal ON ((pc_cal.id = pc_mtm.calendar)));;
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
CREATE OR REPLACE VIEW public.vw_utility_physical_valuation_line AS
|
||||||
|
SELECT 'Purchase'::text AS "strContractType",
|
||||||
|
vvl.date AS "dtmValuationDate",
|
||||||
|
vvl.reference AS "strReference",
|
||||||
|
vvl.purchase AS "intContractId",
|
||||||
|
vvl.line AS "intContractLineId",
|
||||||
|
vvl.lot AS "intLotId",
|
||||||
|
vvl.quantity AS "dblQuantity",
|
||||||
|
initcap((vvl.state)::text) AS "strState",
|
||||||
|
vvl.price AS "dblPrice",
|
||||||
|
COALESCE(vvl.mtm_price, (0)::numeric) AS "dblMtmPrice",
|
||||||
|
vvl.amount AS "dblAmount",
|
||||||
|
vvl.base_amount AS "dblBaseAmount"
|
||||||
|
FROM valuation_valuation_line vvl
|
||||||
|
WHERE ((1 = 1) AND ((vvl.type)::text = 'pur. priced'::text) AND (COALESCE(vvl.lot, 0) > 0) AND (COALESCE(vvl.purchase, 0) > 0) AND (COALESCE(vvl.line, 0) > 0))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'Sale'::text AS "strContractType",
|
||||||
|
vvl.date AS "dtmValuationDate",
|
||||||
|
vvl.reference AS "strReference",
|
||||||
|
vvl.sale AS "intContractId",
|
||||||
|
vvl.sale_line AS "intContractLineId",
|
||||||
|
vvl.lot AS "intLotId",
|
||||||
|
vvl.quantity AS "dblQuantity",
|
||||||
|
initcap((vvl.state)::text) AS "strState",
|
||||||
|
vvl.price AS "dblPrice",
|
||||||
|
COALESCE(vvl.mtm_price, (0)::numeric) AS "dblMtmPrice",
|
||||||
|
vvl.amount AS "dblAmount",
|
||||||
|
vvl.base_amount AS "dblBaseAmount"
|
||||||
|
FROM valuation_valuation_line vvl
|
||||||
|
WHERE ((1 = 1) AND ((vvl.type)::text = 'sale priced'::text) AND (COALESCE(vvl.lot, 0) > 0) AND (COALESCE(vvl.sale, 0) > 0) AND (COALESCE(vvl.sale_line, 0) > 0));;
|
||||||
Reference in New Issue
Block a user