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

@@ -0,0 +1,13 @@
CREATE OR REPLACE VIEW public.vw_bi_dim_book AS
SELECT 0 AS "intBookId",
''::character varying AS "Book Code",
'Undefined Book'::character varying AS "Book Name",
'-'::character varying AS "Book Year"
UNION ALL
SELECT adv.id AS "intBookId",
adv.code AS "Book Code",
adv.name AS "Book Name",
"right"((adv.name)::text, 4) AS "Book Year"
FROM (analytic_dimension ad
JOIN analytic_dimension_value adv ON ((ad.id = adv.dimension)))
WHERE ((ad.code)::text = 'book'::text);;

View File

@@ -5,7 +5,9 @@ CREATE OR REPLACE VIEW public.vw_bi_dim_conformed_reference AS
pc."Price Fixing Status",
pc."Bassin",
pc."Book",
pc."Supplier Country" AS "Counterparty Country"
pc."Supplier Country" AS "Counterparty Country",
pc."MtM Strategy",
pc."MtM Strategy Aternative Name"
FROM vw_bi_dim_purchase_physical_contract pc
WHERE ((1 = 1) AND (pc."intPurchaseLineId" > 0))
UNION ALL
@@ -15,7 +17,9 @@ UNION ALL
sc."Price Fixing Status",
sc."Bassin",
sc."Book",
sc."Customer Country" AS "Counterparty Country"
sc."Customer Country" AS "Counterparty Country",
sc."MtM Strategy",
sc."MtM Strategy Aternative Name"
FROM vw_bi_dim_sale_physical_contract sc
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0))
UNION ALL
@@ -32,8 +36,20 @@ UNION ALL
END AS "Price Fixing Status",
pc."Bassin",
pc."Book",
sc."Customer Country" AS "Counterparty Country"
sc."Customer Country" AS "Counterparty Country",
sc."MtM Strategy",
sc."MtM Strategy Aternative Name"
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);;
WHERE (1 = 1)
UNION ALL
SELECT '0_0'::text AS "strConformedReferenceId",
'N/A'::text AS "Conformed Trade Ref",
'Monthly Adjustment'::text AS "Trade Type",
'Fixed'::text AS "Price Fixing Status",
'N/A'::text AS "Bassin",
'N/A'::text AS "Book",
'N/A'::text AS "Counterparty Country",
'N/A'::text AS "MtM Strategy",
'N/A'::text AS "MtM Strategy Aternative Name";;

View File

@@ -55,7 +55,8 @@ CREATE OR REPLACE VIEW public.vw_bi_dim_purchase_physical_contract AS
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"
(dpc."intPurchaseLineId" || '_0'::text) AS "strTradeId",
COALESCE(mtm."strStrategyAltName", ('Undefined'::character varying)::text) AS "MtM Strategy Aternative Name"
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")));;

View File

@@ -55,7 +55,8 @@ CREATE OR REPLACE VIEW public.vw_bi_dim_sale_physical_contract AS
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"
('0_'::text || dpc."intSaleLineId") AS "strTradeLineId",
COALESCE(mtm."strStrategyAltName", ('Undefined'::character varying)::text) AS "MtM Strategy Aternative Name"
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")));;

View File

@@ -0,0 +1,23 @@
CREATE OR REPLACE VIEW public.vw_bi_fct_fee_allocation AS
SELECT "intShipmentId",
"intLotId",
"intFeeId",
"strFeeSource" AS "Fee Source",
"strFeeType" AS "Fee Type",
"intPurchaseLineId",
"intSaleLineId",
"intProductId",
"strFee" AS "Fee",
"intSupplierId",
"strSupplier" AS "Supplier",
"strPackaging" AS "Packaging",
"strPayOrRec" AS "Pay or Receive",
"strState" AS "State",
"dblQuantity" AS "Quantity",
"dblPrice" AS "Price",
"strCurrency" AS "Currency",
"strUnit" AS "Unit",
"dblAmount" AS "Amount",
"strCostGroup" AS "Cost Group",
"intSignMultiplier" AS "Sign Multiplier"
FROM vw_utility_shipment_fee_allocation fee;;

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

View File

@@ -4,25 +4,27 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_inherited_expenses_on_shipments AS
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
2 AS "intPriceGroupId",
ctr_fees."Fee" AS "Line Description",
shipment."Shipped Quantity" AS "Open Quantity Signed",
(shipment."Shipped Quantity")::double precision AS "Open Quantity Signed",
ctr_fees."Price",
(shipment."Shipped Quantity" * (ctr_fees."Price")::double precision) AS "Amount",
((shipment."Shipped Quantity")::double precision * (ctr_fees."Price")::double precision) AS "Amount",
shipment."BL Date" AS "Delivery Date",
ctr_fees."Cost Group" AS "Line Group"
FROM (vw_bi_itsa_fct_shipments shipment
ctr_fees."Cost Group" AS "Line Group",
shipment."intBookId"
FROM (vw_bi_itsa_fct_shipments_v2 shipment
JOIN vw_bi_itsa_fct_contract_fees ctr_fees ON ((ctr_fees."intContractLineId" = shipment."intPurchaseLineId")))
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",
(shipment."Shipped Quantity")::double precision AS "Open Quantity Signed",
fees."Price",
(shipment."Shipped Quantity" * (fees."Price")::double precision) AS "Amount",
((shipment."Shipped Quantity")::double precision * (fees."Price")::double precision) AS "Amount",
shipment."BL Date" AS "Delivery Date",
fees."Cost Group" AS "Line Group"
fees."Cost Group" AS "Line Group",
shipment."intBookId"
FROM (vw_bi_itsa_fct_shipment_fees fees
JOIN vw_bi_itsa_fct_shipments shipment ON ((fees."intShipmentId" = shipment."intShipmentId")))
JOIN vw_bi_itsa_fct_shipments_v2 shipment ON ((fees."intShipmentId" = shipment."intShipmentId")))
)
SELECT all_fees."intPnlTypeId",
all_fees."strConformedReferenceId",
@@ -32,7 +34,8 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_inherited_expenses_on_shipments AS
all_fees."Price",
all_fees."Amount",
all_fees."Delivery Date",
all_fees."Line Group"
all_fees."Line Group",
all_fees."intBookId"
FROM all_fees
WHERE ((all_fees."Line Description")::text <> 'Profit sharing'::text)
UNION ALL
@@ -44,7 +47,8 @@ UNION ALL
ranked."Price",
ranked."Amount",
ranked."Delivery Date",
ranked."Line Group"
ranked."Line Group",
ranked."intBookId"
FROM ( SELECT all_fees."intPnlTypeId",
all_fees."strConformedReferenceId",
all_fees."intPriceGroupId",
@@ -54,6 +58,7 @@ UNION ALL
all_fees."Amount",
all_fees."Delivery Date",
all_fees."Line Group",
all_fees."intBookId",
row_number() OVER (PARTITION BY all_fees."strConformedReferenceId" ORDER BY all_fees."Price" DESC) AS rn
FROM all_fees
WHERE ((all_fees."Line Description")::text = 'Profit sharing'::text)) ranked

View File

@@ -13,8 +13,10 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_shipments_v2 AS
q.bl_date AS "BL Date",
q.delivery_date_from AS "Delivery Date From",
q.delivery_date_to AS "Delivery Date To",
q.valued_lot_type AS "Lot Type"
FROM ((vw_utility_trade_pnl_quantities q
q.valued_lot_type AS "Lot Type",
COALESCE(book."intBookId", 0) AS "intBookId"
FROM (((vw_utility_trade_pnl_quantities q
LEFT JOIN vw_utility_purchase_physical_contract p ON ((q.purchase_line_id = p."intPurchaseLineId")))
LEFT JOIN vw_utility_sale_physical_contract s ON ((q.sale_line_id = s."intSaleLineId")))
LEFT JOIN vw_utility_book_dimension book ON (((s."intSaleLineId" = book."intTradeLineId") AND (book."strTradeCategory" = 'Physical'::text) AND (book."strTradeType" = 'Sale'::text))))
WHERE ((q.ignored_by_finished_rule = false) AND (q.shipment_id IS NOT NULL));;

View File

@@ -3,5 +3,6 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_monthly_trade_ifrs_adjustments AS
"dtmAdjustmentDate" AS "Adjustment Date",
"dblAmount" AS "Amount",
"strCurrency" AS "Currency",
"strComments" AS "Comments"
"strComments" AS "Comments",
"intBookId"
FROM vw_utility_monthly_trade_ifrs_adjustments;;

View File

@@ -10,8 +10,6 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_physical_open_costs AS
), 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)
@@ -30,8 +28,6 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_physical_open_costs AS
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)

View File

@@ -0,0 +1,217 @@
CREATE OR REPLACE VIEW public.vw_bi_itsa_physical_open_costs_v2 AS
WITH valuation_info AS (
SELECT pvl."intContractId",
pvl."intContractLineId",
pvl."strState",
(sum(pvl."dblMtmPrice"))::numeric(18,2) AS "avgMtmPrice"
FROM vw_utility_physical_valuation_line pvl
GROUP BY pvl."intContractId", pvl."intContractLineId", pvl."strState"
), utility_open_quantity AS (
SELECT
CASE
WHEN (uop."strContractSide" = 'purchase'::text) THEN 'Purchase'::text
WHEN (uop."strContractSide" = 'sale'::text) THEN 'Sale'::text
ELSE NULL::text
END AS "TradeType",
uop."intContractLineId" AS "TradeLineId",
(sum(uop."dblOpenQuantity"))::numeric(18,3) AS "OpenQuantitySigned",
(sum(uop."dblOpenTargetedQuantity"))::numeric(18,3) AS "OpenExpectedQuantitySigned"
FROM vw_utility_open_position uop
GROUP BY
CASE
WHEN (uop."strContractSide" = 'purchase'::text) THEN 'Purchase'::text
WHEN (uop."strContractSide" = 'sale'::text) THEN 'Sale'::text
ELSE NULL::text
END, uop."intContractLineId"
), contract_open_quantity AS (
SELECT 'Purchase'::text AS "TradeType",
pc."intPurchaseLineId" AS "TradeLineId",
(abs(COALESCE(uop."OpenQuantitySigned", (0)::numeric)))::numeric(18,3) AS "OpenQuantity",
(COALESCE(uop."OpenQuantitySigned", (0)::numeric))::numeric(18,3) AS "OpenQuantitySigned",
(COALESCE(uop."OpenExpectedQuantitySigned", (0)::numeric))::numeric(18,3) AS "OpenExpectedQuantitySigned",
COALESCE(vi."avgMtmPrice", (0)::numeric(18,2)) AS "AvgMtmPrice",
pc."dblTheoriticalQuantity" AS "TheoriticalQuantitySigned"
FROM ((vw_utility_purchase_physical_contract pc
LEFT JOIN utility_open_quantity uop ON (((uop."TradeType" = 'Purchase'::text) AND (uop."TradeLineId" = pc."intPurchaseLineId"))))
LEFT JOIN valuation_info vi ON ((pc."intPurchaseLineId" = vi."intContractLineId")))
UNION ALL
SELECT 'Sale'::text AS "TradeType",
pc."intSaleLineId" AS "TradeLineId",
(abs(COALESCE(uop."OpenQuantitySigned", (0)::numeric)))::numeric(18,3) AS "OpenQuantity",
(COALESCE(uop."OpenQuantitySigned", (0)::numeric))::numeric(18,3) AS "OpenQuantitySigned",
(COALESCE(uop."OpenExpectedQuantitySigned", (0)::numeric))::numeric(18,3) AS "OpenExpectedQuantitySigned",
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 utility_open_quantity uop ON (((uop."TradeType" = 'Sale'::text) AND (uop."TradeLineId" = pc."intSaleLineId"))))
LEFT JOIN valuation_info vi ON ((pc."intSaleLineId" = vi."intContractLineId")))
)
SELECT 1 AS "Group Order",
'Price'::text AS "Group Type",
ctr."intPurchaseLineId" AS "intTradeLineId",
CASE
WHEN ((ctr."strPricingType")::text = 'basis'::text) THEN COALESCE(prc."strPriceDescription", 'Basis Price Curve Missing'::character varying)
ELSE 'Fixed Price'::character varying
END 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",
'Price'::text AS "Line Group",
opq."OpenExpectedQuantitySigned" AS "Open Expected Quantity Signed",
((opq."OpenExpectedQuantitySigned" * pur."dblUnitPrice") * ('-1'::integer)::numeric) AS "Open ExpectedCost Amount"
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))))
LEFT JOIN vw_utility_physical_pricing_definition prc ON (((prc."strContractType" = 'Purchase'::text) AND (prc."intContractLineId" = ctr."intPurchaseLineId"))))
WHERE (((ctr."strPricingType")::text = ANY (ARRAY['priced'::text, 'basis'::text])) AND (opq."OpenQuantity" <> (0)::numeric))
UNION ALL
SELECT 1 AS "Group Order",
'Price'::text AS "Group Type",
ctr."intPurchaseLineId" AS "intTradeLineId",
prc."strPremiumType" AS "Line Description",
prc."dblPremiumAmount" AS "Price",
opq."OpenQuantitySigned" AS "Open Quantity Signed",
((opq."OpenQuantitySigned" * prc."dblPremiumAmount") * ('-1'::integer)::numeric) AS "Open Cost Amount",
1 AS "intPriceGroupId",
ctr."dtmEstimatedBLDate" AS "Estimated BL Date",
opq."TheoriticalQuantitySigned" AS "Contract Quantity Signed",
'Price'::text AS "Line Group",
opq."OpenExpectedQuantitySigned" AS "Open Expected Quantity Signed",
((opq."OpenExpectedQuantitySigned" * prc."dblPremiumAmount") * ('-1'::integer)::numeric) AS "Open ExpectedCost Amount"
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))))
JOIN vw_utility_premium_composition prc ON (((prc."strContractType" = 'Purchase'::text) AND (prc."intContractLineId" = ctr."intPurchaseLineId"))))
WHERE (((ctr."strPricingType")::text = ANY (ARRAY['priced'::text, 'basis'::text])) AND (opq."OpenQuantity" <> (0)::numeric))
UNION ALL
SELECT DISTINCT 2 AS "Group Order",
'MTM'::text AS "Group Type",
ctr."intPurchaseLineId" AS "intTradeLineId",
mtm."strStrategy" 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",
'MTM'::text AS "Line Group",
opq."OpenExpectedQuantitySigned" AS "Open Expected Quantity Signed",
(opq."OpenExpectedQuantitySigned" * opq."AvgMtmPrice") AS "Open ExpectedCost Amount"
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",
fees."strProductGroup" AS "Line Group",
opq."OpenExpectedQuantitySigned" AS "Open Expected Quantity Signed",
((((
CASE
WHEN ((fees."strPayOrRec")::text = 'pay'::text) THEN 1
ELSE '-1'::integer
END)::numeric * opq."OpenExpectedQuantitySigned") * fees."dblPrice") * ('-1'::integer)::numeric) AS "Open ExpectedCost Amount"
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",
CASE
WHEN ((ctr."strPricingType")::text = 'basis'::text) THEN COALESCE(prc."strPriceDescription", 'Basis Price Curve Missing'::character varying)
ELSE 'Fixed Price'::character varying
END 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",
'Price'::text AS "Line Group",
opq."OpenExpectedQuantitySigned" AS "Open Expected Quantity Signed",
((opq."OpenExpectedQuantitySigned" * sale."dblUnitPrice") * ('-1'::integer)::numeric) AS "Open ExpectedCost Amount"
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))))
LEFT JOIN vw_utility_physical_pricing_definition prc ON (((prc."strContractType" = 'Sale'::text) AND (prc."intContractLineId" = ctr."intSaleLineId"))))
WHERE (((ctr."strPricingType")::text = ANY (ARRAY['priced'::text, 'basis'::text])) AND (opq."OpenQuantity" <> (0)::numeric))
UNION ALL
SELECT 1 AS "Group Order",
'Price'::text AS "Group Type",
ctr."intSaleLineId" AS "intTradeLineId",
prc."strPremiumType" AS "Line Description",
(prc."dblPremiumAmount" / abs(opq."OpenExpectedQuantitySigned")) AS "Price",
opq."OpenQuantitySigned" AS "Open Quantity Signed",
((opq."OpenQuantitySigned" * prc."dblPremiumAmount") * ('-1'::integer)::numeric) AS "Open Cost Amount",
1 AS "intPriceGroupId",
ctr."dtmEstimatedBLDate" AS "Estimated BL Date",
opq."TheoriticalQuantitySigned" AS "Contract Quantity Signed",
'Price'::text AS "Line Group",
opq."OpenExpectedQuantitySigned" AS "Open Expected Quantity Signed",
((opq."OpenExpectedQuantitySigned" * prc."dblPremiumAmount") * ('-1'::integer)::numeric) AS "Open ExpectedCost Amount"
FROM (((vw_utility_dim_physical_sale_contract ctr
JOIN vw_utility_sale_physical_contract pur ON ((ctr."intSaleLineId" = pur."intSaleLineId")))
JOIN contract_open_quantity opq ON (((ctr."intSaleLineId" = opq."TradeLineId") AND (opq."TradeType" = 'Sale'::text))))
JOIN vw_utility_premium_composition prc ON (((prc."strContractType" = 'Sale'::text) AND (prc."intContractLineId" = ctr."intSaleLineId"))))
WHERE (((ctr."strPricingType")::text = ANY (ARRAY['priced'::text, 'basis'::text])) AND (opq."OpenQuantity" <> (0)::numeric))
UNION ALL
SELECT DISTINCT 2 AS "Group Order",
'MTM'::text AS "Group Type",
ctr."intSaleLineId" AS "intTradeLineId",
mtm."strStrategy" 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",
'MTM'::text AS "Line Group",
opq."OpenExpectedQuantitySigned" AS "Open Expected Quantity Signed",
(opq."OpenExpectedQuantitySigned" * opq."AvgMtmPrice") AS "Open ExpectedCost Amount"
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",
fees."strProductGroup" AS "Line Group",
opq."OpenExpectedQuantitySigned" AS "Open Expected Quantity Signed",
(((
CASE
WHEN ((fees."strPayOrRec")::text = 'pay'::text) THEN 1
ELSE '-1'::integer
END)::numeric * opq."OpenExpectedQuantitySigned") * fees."dblPrice") AS "Open ExpectedCost Amount"
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));;

View File

@@ -14,7 +14,8 @@ CREATE OR REPLACE VIEW public.vw_utility_book_dimension AS
'Physical'::text AS "strTradeCategory",
'Purchase'::text AS "strTradeType",
bv."valueCode" AS "strValueCode",
bv."valueName" AS "strValueName"
bv."valueName" AS "strValueName",
bv."valueId" AS "intBookId"
FROM ((analytic_dimension_assignment aa
JOIN bookvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
JOIN purchase_line pl ON ((aa.purchase = pl.purchase)))
@@ -25,7 +26,8 @@ UNION ALL
'Physical'::text AS "strTradeCategory",
'Sale'::text AS "strTradeType",
bv."valueCode" AS "strValueCode",
bv."valueName" AS "strValueName"
bv."valueName" AS "strValueName",
bv."valueId" AS "intBookId"
FROM ((analytic_dimension_assignment aa
JOIN bookvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
JOIN sale_line sl ON ((sl.sale = aa.sale)))

View File

@@ -18,4 +18,4 @@ CREATE OR REPLACE VIEW public.vw_utility_lot_not_invoiced_on_purchase AS
JOIN purchase_purchase pur ON ((pur.id = pl.purchase)))
JOIN party_party pp ON ((pp.id = pur.party)))
JOIN currency_currency cur ON ((cur.id = pur.currency)))
WHERE ((1 = 1) AND ((l.lot_type)::text = 'physic'::text) AND ((si.state)::text = ANY ((ARRAY['received'::character varying, 'done'::character varying])::text[])) AND (l.invoice_line IS NULL));;
WHERE ((1 = 1) AND ((l.lot_type)::text = 'physic'::text) AND ((si.state)::text = ANY (ARRAY[('received'::character varying)::text, ('done'::character varying)::text])) AND (l.invoice_line IS NULL));;

View File

@@ -1,8 +1,23 @@
CREATE OR REPLACE VIEW public.vw_utility_monthly_trade_ifrs_adjustments AS
WITH books AS (
SELECT adv.id AS "intBookId",
adv.code AS "BookCode",
adv.name AS "BookName",
"right"((adv.name)::text, 4) AS "BookYear"
FROM (analytic_dimension ad
JOIN analytic_dimension_value adv ON ((ad.id = adv.dimension)))
WHERE (((ad.code)::text = 'book'::text) AND ((adv.name)::text !~~ '%Projection%'::text))
)
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)));;
apti.comment AS "strComments",
books."intBookId"
FROM ((account_physical_trade_ifrs apti
JOIN currency_currency cur ON ((cur.id = apti.currency)))
LEFT JOIN books ON ((books."BookYear" = (((EXTRACT(year FROM apti.date))::integer -
CASE
WHEN ((EXTRACT(month FROM apti.date))::integer < 4) THEN 1
ELSE 0
END))::text)));;

View File

@@ -0,0 +1,89 @@
CREATE OR REPLACE VIEW public.vw_utility_open_position AS
WITH physical_lot_quantity AS (
SELECT 'purchase'::text AS side,
l.line AS contract_line_id,
sum(COALESCE(qh.quantity, (0)::numeric)) AS physical_quantity
FROM (lot_lot l
LEFT JOIN lot_qt_hist qh ON (((qh.lot = l.id) AND (qh.quantity_type = l.lot_state))))
WHERE (((l.lot_type)::text = 'physic'::text) AND (l.line IS NOT NULL))
GROUP BY l.line
UNION ALL
SELECT 'sale'::text AS side,
l.sale_line AS contract_line_id,
sum(COALESCE(qh.quantity, (0)::numeric)) AS physical_quantity
FROM (lot_lot l
LEFT JOIN lot_qt_hist qh ON (((qh.lot = l.id) AND (qh.quantity_type = l.lot_state))))
WHERE (((l.lot_type)::text = 'physic'::text) AND (l.sale_line IS NOT NULL))
GROUP BY l.sale_line
), matched_virtual_quantity AS (
SELECT 'purchase'::text AS side,
lp.line AS contract_line_id,
sum(lqt.lot_quantity) AS matched_quantity
FROM (lot_qt lqt
JOIN lot_lot lp ON ((lp.id = lqt.lot_p)))
WHERE (((lp.lot_type)::text = 'virtual'::text) AND (lp.line IS NOT NULL) AND (lqt.lot_s IS NOT NULL) AND (lqt.lot_quantity > (0)::numeric))
GROUP BY lp.line
UNION ALL
SELECT 'sale'::text AS side,
ls.sale_line AS contract_line_id,
sum(lqt.lot_quantity) AS matched_quantity
FROM (lot_qt lqt
JOIN lot_lot ls ON ((ls.id = lqt.lot_s)))
WHERE (((ls.lot_type)::text = 'virtual'::text) AND (ls.sale_line IS NOT NULL) AND (lqt.lot_p IS NOT NULL) AND (lqt.lot_quantity > (0)::numeric))
GROUP BY ls.sale_line
), open_virtual_lots AS (
SELECT 'purchase'::text AS side,
lqt.id AS int_lot_qt_id,
lp.id AS int_lot_id,
pl.id AS int_contract_line_id,
pp.party AS int_counterparty_id,
pl.product AS int_product_id,
uom.name AS uom,
lqt.lot_quantity AS open_quantity,
pl.from_del AS period_start,
pl.to_del AS period_end,
COALESCE(plq.physical_quantity, (0)::numeric) AS physical_lot_quantity,
((pl.targeted_qt - COALESCE(plq.physical_quantity, (0)::numeric)) - COALESCE(mvq.matched_quantity, (0)::numeric)) AS open_targeted_quantity
FROM ((((((lot_qt lqt
JOIN lot_lot lp ON ((lp.id = lqt.lot_p)))
JOIN purchase_line pl ON ((pl.id = lp.line)))
JOIN purchase_purchase pp ON ((pp.id = pl.purchase)))
LEFT JOIN product_uom uom ON ((uom.id = lqt.lot_unit)))
LEFT JOIN physical_lot_quantity plq ON (((plq.side = 'purchase'::text) AND (plq.contract_line_id = pl.id))))
LEFT JOIN matched_virtual_quantity mvq ON (((mvq.side = 'purchase'::text) AND (mvq.contract_line_id = pl.id))))
WHERE (((lp.lot_type)::text = 'virtual'::text) AND (lqt.lot_s IS NULL) AND (COALESCE(pl.finished, false) = false) AND (lqt.lot_quantity > (0)::numeric))
UNION ALL
SELECT 'sale'::text AS side,
lqt.id AS int_lot_qt_id,
ls.id AS int_lot_id,
sl.id AS int_contract_line_id,
ss.party AS int_counterparty_id,
sl.product AS int_product_id,
uom.name AS uom,
(- lqt.lot_quantity) AS open_quantity,
sl.from_del AS period_start,
sl.to_del AS period_end,
COALESCE(plq.physical_quantity, (0)::numeric) AS physical_lot_quantity,
(- ((sl.targeted_qt - COALESCE(plq.physical_quantity, (0)::numeric)) - COALESCE(mvq.matched_quantity, (0)::numeric))) AS open_targeted_quantity
FROM ((((((lot_qt lqt
JOIN lot_lot ls ON ((ls.id = lqt.lot_s)))
JOIN sale_line sl ON ((sl.id = ls.sale_line)))
JOIN sale_sale ss ON ((ss.id = sl.sale)))
LEFT JOIN product_uom uom ON ((uom.id = lqt.lot_unit)))
LEFT JOIN physical_lot_quantity plq ON (((plq.side = 'sale'::text) AND (plq.contract_line_id = sl.id))))
LEFT JOIN matched_virtual_quantity mvq ON (((mvq.side = 'sale'::text) AND (mvq.contract_line_id = sl.id))))
WHERE (((ls.lot_type)::text = 'virtual'::text) AND (lqt.lot_p IS NULL) AND (COALESCE(sl.finished, false) = false) AND (lqt.lot_quantity > (0)::numeric))
)
SELECT side AS "strContractSide",
int_lot_qt_id AS "intLotQtId",
int_lot_id AS "intLotId",
int_contract_line_id AS "intContractLineId",
int_counterparty_id AS "intCounterpartyId",
int_product_id AS "intProductId",
uom AS "strUom",
open_quantity AS "dblOpenQuantity",
period_start AS "dtmPeriodStart",
period_end AS "dtmPeriodEnd",
physical_lot_quantity AS "dblPhysicalLotQuantity",
open_targeted_quantity AS "dblOpenTargetedQuantity"
FROM open_virtual_lots;;

View File

@@ -10,7 +10,9 @@ CREATE OR REPLACE VIEW public.vw_utility_physical_mtm_definition AS
pc_mtm.ratio AS "strComponentRatioPct",
ft.name AS "strComponentFixType",
pi.price_desc AS "strComponentCurve",
pc_cal.name AS "strComponentCalendar"
pc_cal.name AS "strComponentCalendar",
pi.id AS "intPriceIndexId",
TRIM(BOTH FROM regexp_replace((ms.name)::text, '\m[0-9]{4}-[0-9]{2}\M'::text, ''::text, 'g'::text)) AS "strStrategyAltName"
FROM (((((((((purchase_strategy ps
JOIN purchase_line pl ON ((pl.id = ps.line)))
JOIN purchase_purchase pp ON ((pp.id = pl.purchase)))
@@ -33,7 +35,9 @@ UNION ALL
pc_mtm.ratio AS "strComponentRatioPct",
ft.name AS "strComponentFixType",
pi.price_desc AS "strComponentCurve",
pc_cal.name AS "strComponentCalendar"
pc_cal.name AS "strComponentCalendar",
pi.id AS "intPriceIndexId",
TRIM(BOTH FROM regexp_replace((ms.name)::text, '\m[0-9]{4}-[0-9]{2}\M'::text, ''::text, 'g'::text)) AS "strStrategyAltName"
FROM (((((((((sale_strategy sa
JOIN sale_line sl ON ((sl.id = sa.sale_line)))
JOIN sale_sale ss ON ((ss.id = sl.sale)))

View File

@@ -0,0 +1,38 @@
CREATE OR REPLACE VIEW public.vw_utility_physical_pricing_definition AS
SELECT 'Purchase'::text AS "strContractType",
pc.line AS "intContractLineId",
pc.id AS "intPricingComponentId",
pc.price_index AS "intPriceCurveId",
vpc."strPriceDescription",
vpc."strPriceIndex",
vpc."strCurrency",
vpc."strUnit",
vpc."strPriceCurveType",
vpc."strPriceArea",
vpc."strPriceCalendar",
vpc."strPricingType",
vpc."dtmPricingStartDate",
vpc."dtmPricingEndDate",
vpc."strPricingMonth"
FROM (pricing_component pc
LEFT JOIN vw_utility_price_curve vpc ON ((vpc."intPriceCurveId" = pc.price_index)))
WHERE (pc.line IS NOT NULL)
UNION ALL
SELECT 'Sale'::text AS "strContractType",
pc.sale_line AS "intContractLineId",
pc.id AS "intPricingComponentId",
pc.price_index AS "intPriceCurveId",
vpc."strPriceDescription",
vpc."strPriceIndex",
vpc."strCurrency",
vpc."strUnit",
vpc."strPriceCurveType",
vpc."strPriceArea",
vpc."strPriceCalendar",
vpc."strPricingType",
vpc."dtmPricingStartDate",
vpc."dtmPricingEndDate",
vpc."strPricingMonth"
FROM (pricing_component pc
LEFT JOIN vw_utility_price_curve vpc ON ((vpc."intPriceCurveId" = pc.price_index)))
WHERE (pc.sale_line IS NOT NULL);;

View File

@@ -0,0 +1,18 @@
CREATE OR REPLACE VIEW public.vw_utility_premium_composition AS
SELECT pc.line AS "intContractLineId",
'Purchase'::text AS "strContractType",
pf.name AS "strPremiumType",
pc.premium AS "dblPremiumAmount",
pc.reference AS "strReference"
FROM (premium_composition pc
JOIN price_fixtype pf ON ((pc.type = pf.id)))
WHERE (pc.line IS NOT NULL)
UNION ALL
SELECT pc.sale_line AS "intContractLineId",
'Sale'::text AS "strContractType",
pf.name AS "strPremiumType",
pc.premium AS "dblPremiumAmount",
pc.reference AS "strReference"
FROM (premium_composition pc
JOIN price_fixtype pf ON ((pc.type = pf.id)))
WHERE (pc.sale_line IS NOT NULL);;

View File

@@ -31,7 +31,8 @@ CREATE OR REPLACE VIEW public.vw_utility_purchase_physical_contract AS
(COALESCE((pl.quantity_theorical)::double precision, (0)::double precision) - COALESCE(phys.dblphysicalqty, (0)::double precision)) AS "dblOpenQuantity",
COALESCE(inst.dblinstructedqty, (0)::double precision) AS "dblInInstructedQuantity",
COALESCE(bl.estimated_date, pl.to_del) AS "dtmEstimatedBLDate",
pl.finished AS "ysnFinished"
pl.finished AS "ysnFinished",
pl.targeted_qt AS "dblTargetedQuantity"
FROM (((((((((((purchase_line pl
JOIN purchase_purchase pc ON ((pl.purchase = pc.id)))
JOIN product_uom pu1 ON ((pl.unit = pu1.id)))
@@ -60,4 +61,4 @@ CREATE OR REPLACE VIEW public.vw_utility_purchase_physical_contract AS
FROM vw_utility_instructed_lots t1
GROUP BY t1."intPurchaseLineId") inst ON ((pl.id = inst."intPurchaseLineId")))
LEFT JOIN pricing_estimated bl ON (((pl.id = bl.line) AND ((bl.trigger)::text = 'bldate'::text))))
WHERE (1 = 1);;
WHERE ((1 = 1) AND ((pc.line_type)::text = 'goods'::text));;

View File

@@ -30,7 +30,8 @@ CREATE OR REPLACE VIEW public.vw_utility_sale_physical_contract AS
((convert_weight(sl.quantity_theorical, (pu1.name)::text, 'Kilogram'::text))::double precision - COALESCE((shipped."dblNetWeightKg")::double precision, (0)::double precision)) AS "dblOpenWeightKg",
COALESCE(bl.estimated_date, sl.from_del) AS "dtmEstimatedBLDate",
COALESCE(instructed.dblinstructedqty, ((0)::numeric)::double precision) AS "dblInstructedQuantity",
sl.finished AS "ysnFinished"
sl.finished AS "ysnFinished",
sl.targeted_qt AS "dblTargetedQuantity"
FROM ((((((sale_line sl
JOIN sale_sale sc ON ((sl.sale = sc.id)))
JOIN product_uom pu1 ON ((sl.unit = pu1.id)))

View File

@@ -44,13 +44,14 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
FROM virtual_shipment_lots
), shipment_context AS (
SELECT shipment_lots.shipment_id,
shipment_lots.lot_id,
shipment_lots.purchase_line_id,
shipment_lots.sale_line_id,
shipment_lots.shipment_unit_id,
sum(COALESCE(shipment_lots.shipment_quantity, (0)::numeric)) AS shipment_quantity
FROM shipment_lots
WHERE (shipment_lots.shipment_id IS NOT NULL)
GROUP BY shipment_lots.shipment_id, shipment_lots.purchase_line_id, shipment_lots.sale_line_id, shipment_lots.shipment_unit_id
GROUP BY shipment_lots.shipment_id, shipment_lots.lot_id, shipment_lots.purchase_line_id, shipment_lots.sale_line_id, shipment_lots.shipment_unit_id
), shipment_base AS (
SELECT shipment_context.shipment_id,
sum(shipment_context.shipment_quantity) AS shipment_quantity
@@ -66,8 +67,6 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
ELSE NULL::integer
END AS priority,
sb.shipment_id,
NULL::integer AS purchase_line_id,
NULL::integer AS sale_line_id,
f_1.product AS product_id,
f_1.supplier AS supplier_id,
f_1.mode AS packaging,
@@ -82,18 +81,17 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
CASE
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN 1
ELSE '-1'::integer
END AS sign_multiplier
END AS sign_multiplier,
NULL::text AS forced_cost_group
FROM (shipment_base sb
JOIN fee_fee f_1 ON ((f_1.shipment_in = sb.shipment_id)))
WHERE ((f_1.type)::text = ANY ((ARRAY['ordered'::character varying, 'scheduled'::character varying])::text[]))
), shipment_fee_allocated AS (
WHERE ((f_1.type)::text = ANY (ARRAY[('ordered'::character varying)::text, ('scheduled'::character varying)::text]))
), shipment_fee_limits AS (
SELECT c.fee_id,
c.fee_source,
c.fee_type,
c.priority,
c.shipment_id,
c.purchase_line_id,
c.sale_line_id,
c.product_id,
c.supplier_id,
c.packaging,
@@ -106,8 +104,34 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
c.currency_id,
c.unit_id,
c.sign_multiplier,
LEAST(c.requested_quantity, GREATEST((c.shipment_quantity - COALESCE(sum(c.requested_quantity) OVER (PARTITION BY c.shipment_id, c.product_id, c.supplier_id ORDER BY c.priority, c.fee_id ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), (0)::numeric)), (0)::numeric)) AS allocated_quantity
c.forced_cost_group,
LEAST(GREATEST(c.requested_quantity, (0)::numeric), GREATEST((c.shipment_quantity - COALESCE(sum(c.requested_quantity) OVER (PARTITION BY c.shipment_id, c.product_id, c.supplier_id ORDER BY c.priority, c.fee_id ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), (0)::numeric)), (0)::numeric)) AS fee_allocatable_quantity
FROM shipment_fee_candidates c
), shipment_fee_allocated AS (
SELECT fl.fee_id,
fl.fee_source,
fl.fee_type,
fl.priority,
fl.shipment_id,
sc.lot_id,
sc.purchase_line_id,
sc.sale_line_id,
fl.product_id,
fl.supplier_id,
fl.packaging,
fl.pay_or_rec,
fl.state,
fl.weight_type,
fl.requested_quantity,
fl.shipment_quantity,
fl.fee_price,
fl.currency_id,
COALESCE(fl.unit_id, sc.shipment_unit_id) AS unit_id,
fl.sign_multiplier,
fl.forced_cost_group,
LEAST(sc.shipment_quantity, GREATEST((fl.fee_allocatable_quantity - COALESCE(sum(sc.shipment_quantity) OVER (PARTITION BY fl.fee_id ORDER BY sc.lot_id, sc.purchase_line_id, sc.sale_line_id ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), (0)::numeric)), (0)::numeric)) AS allocated_quantity
FROM (shipment_fee_limits fl
JOIN shipment_context sc ON ((sc.shipment_id = fl.shipment_id)))
), shipment_fee_coverage AS (
SELECT shipment_fee_allocated.shipment_id,
shipment_fee_allocated.product_id,
@@ -122,8 +146,9 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
f_1.type AS fee_type,
3 AS priority,
sc.shipment_id,
sc.lot_id,
sc.purchase_line_id,
NULL::integer AS sale_line_id,
sc.sale_line_id,
f_1.product AS product_id,
f_1.supplier AS supplier_id,
f_1.mode AS packaging,
@@ -137,7 +162,8 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
CASE
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN '-1'::integer
ELSE 1
END AS sign_multiplier
END AS sign_multiplier,
NULL::text AS forced_cost_group
FROM (shipment_context sc
JOIN fee_fee f_1 ON ((f_1.line = sc.purchase_line_id)))
WHERE (((f_1.type)::text = 'budgeted'::text) AND (sc.purchase_line_id IS NOT NULL))
@@ -147,7 +173,8 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
f_1.type AS fee_type,
3 AS priority,
sc.shipment_id,
NULL::integer AS purchase_line_id,
sc.lot_id,
sc.purchase_line_id,
sc.sale_line_id,
f_1.product AS product_id,
f_1.supplier AS supplier_id,
@@ -162,7 +189,8 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
CASE
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN 1
ELSE '-1'::integer
END AS sign_multiplier
END AS sign_multiplier,
NULL::text AS forced_cost_group
FROM (shipment_context sc
JOIN fee_fee f_1 ON ((f_1.sale_line = sc.sale_line_id)))
WHERE (((f_1.type)::text = 'budgeted'::text) AND (sc.sale_line_id IS NOT NULL))
@@ -172,6 +200,7 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
c.fee_type,
c.priority,
c.shipment_id,
c.lot_id,
c.purchase_line_id,
c.sale_line_id,
c.product_id,
@@ -185,15 +214,66 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
c.currency_id,
c.unit_id,
c.sign_multiplier,
GREATEST((c.shipment_quantity - COALESCE(fc.allocated_quantity, (0)::numeric)), (0)::numeric) AS allocated_quantity
c.forced_cost_group,
LEAST(c.shipment_quantity, GREATEST(((sum(c.shipment_quantity) OVER (PARTITION BY c.shipment_id, c.product_id, c.supplier_id, c.fee_id) - COALESCE(fc.allocated_quantity, (0)::numeric)) - COALESCE(sum(c.shipment_quantity) OVER (PARTITION BY c.shipment_id, c.product_id, c.supplier_id, c.fee_id ORDER BY c.lot_id ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), (0)::numeric)), (0)::numeric)) AS allocated_quantity
FROM (contract_budgeted_fee_candidates c
LEFT JOIN shipment_fee_coverage fc ON (((fc.shipment_id = c.shipment_id) AND (fc.product_id = c.product_id) AND (fc.supplier_id = c.supplier_id))))
), price_rows AS (
SELECT NULL::integer AS fee_id,
'Purchase Price'::text AS fee_source,
'price'::text AS fee_type,
4 AS priority,
sc.shipment_id,
sc.lot_id,
sc.purchase_line_id,
sc.sale_line_id,
pl.product AS product_id,
NULL::integer AS supplier_id,
NULL::character varying AS packaging,
NULL::character varying AS pay_or_rec,
NULL::character varying AS state,
NULL::character varying AS weight_type,
sc.shipment_quantity AS allocated_quantity,
pl.unit_price AS fee_price,
pl.currency_ AS currency_id,
COALESCE(pl.unit, sc.shipment_unit_id) AS unit_id,
1 AS sign_multiplier,
'PurchasePrice'::text AS forced_cost_group
FROM (shipment_context sc
JOIN purchase_line pl ON ((pl.id = sc.purchase_line_id)))
WHERE (sc.purchase_line_id IS NOT NULL)
UNION ALL
SELECT NULL::integer AS fee_id,
'Sale Price'::text AS fee_source,
'price'::text AS fee_type,
5 AS priority,
sc.shipment_id,
sc.lot_id,
sc.purchase_line_id,
sc.sale_line_id,
sl.product AS product_id,
NULL::integer AS supplier_id,
NULL::character varying AS packaging,
NULL::character varying AS pay_or_rec,
NULL::character varying AS state,
NULL::character varying AS weight_type,
sc.shipment_quantity AS allocated_quantity,
sl.unit_price AS fee_price,
ss.currency AS currency_id,
COALESCE(sl.unit, sc.shipment_unit_id) AS unit_id,
'-1'::integer AS sign_multiplier,
'SalePrice'::text AS forced_cost_group
FROM ((shipment_context sc
JOIN sale_line sl ON ((sl.id = sc.sale_line_id)))
JOIN sale_sale ss ON ((ss.id = sl.sale)))
WHERE (sc.sale_line_id IS NOT NULL)
), final_fees AS (
SELECT shipment_fee_allocated.fee_id,
shipment_fee_allocated.fee_source,
shipment_fee_allocated.fee_type,
shipment_fee_allocated.priority,
shipment_fee_allocated.shipment_id,
shipment_fee_allocated.lot_id,
shipment_fee_allocated.purchase_line_id,
shipment_fee_allocated.sale_line_id,
shipment_fee_allocated.product_id,
@@ -206,7 +286,8 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
shipment_fee_allocated.fee_price,
shipment_fee_allocated.currency_id,
shipment_fee_allocated.unit_id,
shipment_fee_allocated.sign_multiplier
shipment_fee_allocated.sign_multiplier,
shipment_fee_allocated.forced_cost_group
FROM shipment_fee_allocated
WHERE (shipment_fee_allocated.allocated_quantity > (0)::numeric)
UNION ALL
@@ -215,6 +296,7 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
contract_budgeted_allocated.fee_type,
contract_budgeted_allocated.priority,
contract_budgeted_allocated.shipment_id,
contract_budgeted_allocated.lot_id,
contract_budgeted_allocated.purchase_line_id,
contract_budgeted_allocated.sale_line_id,
contract_budgeted_allocated.product_id,
@@ -227,41 +309,73 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
contract_budgeted_allocated.fee_price,
contract_budgeted_allocated.currency_id,
contract_budgeted_allocated.unit_id,
contract_budgeted_allocated.sign_multiplier
contract_budgeted_allocated.sign_multiplier,
contract_budgeted_allocated.forced_cost_group
FROM contract_budgeted_allocated
WHERE (contract_budgeted_allocated.allocated_quantity > (0)::numeric)
UNION ALL
SELECT price_rows.fee_id,
price_rows.fee_source,
price_rows.fee_type,
price_rows.priority,
price_rows.shipment_id,
price_rows.lot_id,
price_rows.purchase_line_id,
price_rows.sale_line_id,
price_rows.product_id,
price_rows.supplier_id,
price_rows.packaging,
price_rows.pay_or_rec,
price_rows.state,
price_rows.weight_type,
price_rows.allocated_quantity AS fee_quantity,
price_rows.fee_price,
price_rows.currency_id,
price_rows.unit_id,
price_rows.sign_multiplier,
price_rows.forced_cost_group
FROM price_rows
WHERE (price_rows.allocated_quantity > (0)::numeric)
)
SELECT f.shipment_id AS "intShipmentId",
f.fee_id AS "intFeeId",
f.lot_id AS "intLotId",
COALESCE(f.fee_id, 0) AS "intFeeId",
f.fee_source AS "strFeeSource",
f.fee_type AS "strFeeType",
f.priority AS "intPriority",
f.purchase_line_id AS "intPurchaseLineId",
f.sale_line_id AS "intSaleLineId",
f.product_id AS "intProductId",
p.code AS "strFee",
f.supplier_id AS "intSupplierId",
sup.name AS "strSupplier",
f.packaging AS "strPackaging",
f.pay_or_rec AS "strPayOrRec",
f.state AS "strState",
COALESCE(f.purchase_line_id, 0) AS "intPurchaseLineId",
COALESCE(f.sale_line_id, 0) AS "intSaleLineId",
COALESCE(f.product_id, 0) AS "intProductId",
COALESCE(p.code, ''::character varying) AS "strFee",
COALESCE(f.supplier_id, 0) AS "intSupplierId",
COALESCE(sup.name, ''::character varying) AS "strSupplier",
COALESCE(f.packaging, ''::character varying) AS "strPackaging",
COALESCE(f.pay_or_rec, ''::character varying) AS "strPayOrRec",
COALESCE(f.state, ''::character varying) AS "strState",
CASE
WHEN (upper((f.weight_type)::text) = 'BRUT'::text) THEN 'Gross'::text
ELSE 'Net'::text
END AS "strWeighingType",
f.fee_quantity AS "dblQuantity",
(f.fee_price * (f.sign_multiplier)::numeric) AS "dblPrice",
cur.name AS "strCurrency",
f.fee_price AS "dblPrice",
COALESCE(cur.name, ''::character varying) AS "strCurrency",
COALESCE(uom.name, 'Mt'::character varying) AS "strUnit",
((f.fee_quantity * f.fee_price) * (f.sign_multiplier)::numeric) AS "dblAmount",
(f.fee_quantity * f.fee_price) AS "dblAmount",
COALESCE(f.forced_cost_group,
CASE
WHEN (upper((p.code)::text) ~~ '%FREIGHT%'::text) THEN 'Freight'::text
WHEN (upper((p.code)::text) ~~ '%PROFIT SHARING%'::text) THEN 'ProfitSharing'::text
ELSE 'OtherCosts'::text
END AS "strCostGroup"
WHEN (upper((p.code)::text) ~~ '%PROFIT SHARING%'::text) THEN 'Profit Sharing'::text
ELSE 'Other Costs'::text
END) AS "strCostGroup",
CASE
WHEN ((f.pay_or_rec)::text = 'pay'::text) THEN (- (1)::numeric)
WHEN ((f.pay_or_rec)::text = 'rec'::text) THEN (1)::numeric
WHEN ((f.fee_source = 'Purchase Price'::text) AND ((f.fee_type)::text = 'price'::text)) THEN (- (1)::numeric)
WHEN ((f.fee_source = 'Sale Price'::text) AND ((f.fee_type)::text = 'price'::text)) THEN (1)::numeric
ELSE (- (1)::numeric)
END AS "intSignMultiplier"
FROM ((((final_fees f
JOIN product_product p ON ((p.id = f.product_id)))
JOIN party_party sup ON ((sup.id = f.supplier_id)))
LEFT JOIN party_party sup ON ((sup.id = f.supplier_id)))
LEFT JOIN currency_currency cur ON ((cur.id = f.currency_id)))
LEFT JOIN product_uom uom ON ((uom.id = f.unit_id)))
ORDER BY f.shipment_id, f.product_id, f.supplier_id, f.priority, f.fee_id;;
LEFT JOIN product_uom uom ON ((uom.id = f.unit_id)));;

View File

@@ -16,11 +16,11 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
p.reference AS purchase_reference,
pl.id AS purchase_line_id,
pl.finished AS purchase_line_finished,
NULL::integer AS sale_id,
NULL::character varying AS sale_number,
NULL::character varying AS sale_reference,
NULL::integer AS sale_line_id,
NULL::boolean AS sale_line_finished,
s.id AS sale_id,
s.number AS sale_number,
s.reference AS sale_reference,
sl.id AS sale_line_id,
sl.finished AS sale_line_finished,
l.id AS valued_lot_id,
l.lot_type AS valued_lot_type,
NULL::integer AS lot_qt_id,
@@ -33,10 +33,12 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
shi.bl_date,
pl.from_del AS delivery_date_from,
pl.to_del AS delivery_date_to
FROM ((((((purchase_line pl
FROM ((((((((purchase_line pl
JOIN purchase_purchase p ON ((p.id = pl.purchase)))
JOIN lot_lot l ON ((l.line = pl.id)))
JOIN lot_current_qty lcq ON ((lcq.lot_id = l.id)))
LEFT JOIN sale_line sl ON ((sl.id = l.sale_line)))
LEFT JOIN sale_sale s ON ((s.id = sl.sale)))
LEFT JOIN stock_shipment_in shi ON ((shi.id = l.lot_shipment_in)))
LEFT JOIN stock_shipment_internal sint ON ((sint.id = l.lot_shipment_internal)))
LEFT JOIN stock_shipment_out sho ON ((sho.id = l.lot_shipment_out)))
@@ -74,7 +76,9 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
LEFT JOIN stock_shipment_in shi ON ((shi.id = l.lot_shipment_in)))
LEFT JOIN stock_shipment_internal sint ON ((sint.id = l.lot_shipment_internal)))
LEFT JOIN stock_shipment_out sho ON ((sho.id = l.lot_shipment_out)))
WHERE (((pl.type)::text = 'line'::text) AND ((l.lot_type)::text = 'physic'::text))
WHERE (((pl.type)::text = 'line'::text) AND ((l.lot_type)::text = 'physic'::text) AND (NOT (EXISTS ( SELECT 1
FROM purchase_pnl_lots ppl
WHERE ((ppl.valued_lot_id = l.id) AND (ppl.sale_line_id = sl.id))))))
), sale_pnl_matched_virtual_lots AS (
SELECT 'sale'::text AS pnl_side,
p.id AS purchase_id,
@@ -90,7 +94,7 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
sale_lot.id AS valued_lot_id,
sale_lot.lot_type AS valued_lot_type,
lqt.id AS lot_qt_id,
lcq.pnl_quantity,
lqt.lot_quantity AS pnl_quantity,
lcq.quantity_uom AS quantity_unit,
sl.product AS product_id,
COALESCE(shi.from_location, sint.from_location, sho.from_location, s.from_location) AS from_location_id,

9
ITSA_Tradon_Prod.md Normal file
View File

@@ -0,0 +1,9 @@
# ITSA_Tradon_Prod
## PostgreSQL Database
- Server: `72.61.163.139`
- Port: `5433`
- User name: `postgres`
- Password: `dsproject`
- Database name: `tradon`

9
OS_Tradon_Prod.md Normal file
View File

@@ -0,0 +1,9 @@
# OS_Tradon_Prod
## PostgreSQL Database
- Server: `62.72.36.116`
- Port: `5432`
- User name: `postgres`
- Password: `dsproject`
- Database name: `tradon`

View File

@@ -628,7 +628,7 @@ WHERE 1=1
AND D.Status <> 'Cancelled'
AND D.BuyOrSell = 1 -- Purchase contracts
AND ISNULL(D.OtherReference, '') NOT LIKE '%ACCT Matching%'
AND B.Description LIKE '%2026%'
AND ( B.Description LIKE '%2026%' )-- OR B.Description LIKE '%2025%' )
ORDER BY 3,1
@@ -831,7 +831,7 @@ WHERE 1=1
AND D.Status <> 'Cancelled'
AND D.BuyOrSell = -1 -- Sale contracts
AND ISNULL(D.OtherReference, '') NOT LIKE '%ACCT Matching%'
AND (B.Description LIKE '%2026%')
AND (B.Description LIKE '%2026%' OR B.Description LIKE '%2025%')
ORDER BY 3,1
@@ -874,7 +874,7 @@ WHERE 1=1
AND D.Status <> 'Cancelled'
AND D.BuyOrSell = 1 -- Purchase contracts
AND ISNULL(D.OtherReference, '') NOT LIKE '%ACCT Matching%'
AND (B.Description LIKE '%2026%')
AND (B.Description LIKE '%2026%' OR B.Description LIKE '%2025%')
AND ER.FormulaGroup NOT IN (1,2) -- Not Price or MtM
ORDER BY 1
@@ -948,7 +948,7 @@ WHERE 1=1
AND D.Status <> 'Cancelled'
AND D.BuyOrSell <> 1 -- Sale contracts
AND ISNULL(D.OtherReference, '') NOT LIKE '%ACCT Matching%'
AND (B.Description LIKE '%2026%')
AND (B.Description LIKE '%2026%' OR B.Description LIKE '%2025%' )
AND ER.FormulaGroup NOT IN (1,2) -- Not Price or MtM
ORDER BY 1

View File

@@ -20,14 +20,14 @@ PRICE_INDEXES_CSV = 'Reference Data\python_project\loaders\Price_Indexes.csv'
# XML-RPC Configuration (for Proteus interaction)
HTTPS = 'https://'
SERVER_URL = 'itsa.open-squared.tech'
SERVER_URL = 'prod.open-squared.tech'
DATABASE_NAME = 'tradon'
USERNAME = 'admin'
PASSWORD = 'dsproject'
# PostgreSQL Configuration (for direct database access if needed)
DB_HOST = '72.61.163.139'
DB_PORT = 5433
DB_HOST = '62.72.36.116'
DB_PORT = 5432
DB_USER = 'postgres'
DB_PASSWORD = 'dsproject'