Dump - ITSA views
This commit is contained in:
13
Database Backups/SQL Views/vw_bi_dim_book.sql
Normal file
13
Database Backups/SQL Views/vw_bi_dim_book.sql
Normal 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);;
|
||||||
@@ -5,7 +5,9 @@ CREATE OR REPLACE VIEW public.vw_bi_dim_conformed_reference AS
|
|||||||
pc."Price Fixing Status",
|
pc."Price Fixing Status",
|
||||||
pc."Bassin",
|
pc."Bassin",
|
||||||
pc."Book",
|
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
|
FROM vw_bi_dim_purchase_physical_contract pc
|
||||||
WHERE ((1 = 1) AND (pc."intPurchaseLineId" > 0))
|
WHERE ((1 = 1) AND (pc."intPurchaseLineId" > 0))
|
||||||
UNION ALL
|
UNION ALL
|
||||||
@@ -15,7 +17,9 @@ UNION ALL
|
|||||||
sc."Price Fixing Status",
|
sc."Price Fixing Status",
|
||||||
sc."Bassin",
|
sc."Bassin",
|
||||||
sc."Book",
|
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
|
FROM vw_bi_dim_sale_physical_contract sc
|
||||||
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0))
|
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0))
|
||||||
UNION ALL
|
UNION ALL
|
||||||
@@ -32,8 +36,20 @@ UNION ALL
|
|||||||
END AS "Price Fixing Status",
|
END AS "Price Fixing Status",
|
||||||
pc."Bassin",
|
pc."Bassin",
|
||||||
pc."Book",
|
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
|
FROM ((vw_bi_itsa_fct_shipments s
|
||||||
JOIN vw_bi_dim_purchase_physical_contract pc ON ((s."intPurchaseLineId" = pc."intPurchaseLineId")))
|
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")))
|
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";;
|
||||||
|
|||||||
@@ -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",
|
COALESCE(mtm."strComponentCurve", 'Undefined'::character varying) AS "MtM Component Curve",
|
||||||
dpc."strCounterpartyCountry" AS "Supplier Country",
|
dpc."strCounterpartyCountry" AS "Supplier Country",
|
||||||
COALESCE(pvl."strState", ('Undefined'::character varying)::text) AS "Price Fixing Status",
|
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
|
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 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")));;
|
LEFT JOIN pricingstatus pvl ON ((dpc."intPurchaseLineId" = pvl."intContractLineId")));;
|
||||||
|
|||||||
@@ -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",
|
COALESCE(mtm."strComponentCurve", 'Undefined'::character varying) AS "MtM Component Curve",
|
||||||
dpc."strCounterpartyCountry" AS "Customer Country",
|
dpc."strCounterpartyCountry" AS "Customer Country",
|
||||||
COALESCE(pvl."strState", ('Undefined'::character varying)::text) AS "Price Fixing Status",
|
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
|
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 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")));;
|
LEFT JOIN pricingstatus pvl ON ((dpc."intSaleLineId" = pvl."intContractLineId")));;
|
||||||
|
|||||||
23
Database Backups/SQL Views/vw_bi_fct_fee_allocation.sql
Normal file
23
Database Backups/SQL Views/vw_bi_fct_fee_allocation.sql
Normal 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;;
|
||||||
@@ -1,81 +1,70 @@
|
|||||||
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_full_pnl AS
|
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_full_pnl AS
|
||||||
WITH trade AS (
|
WITH trade AS (
|
||||||
SELECT pc."intPurchaseLineId" AS "intTradeId",
|
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
|
FROM vw_utility_dim_physical_purchase_contract pc
|
||||||
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
|
('0_'::text || sc."intSaleLineId") AS "strTradeId",
|
||||||
|
'Sale'::text AS "strTradeType",
|
||||||
|
sc."strBookName"
|
||||||
FROM vw_utility_dim_physical_sale_contract sc
|
FROM vw_utility_dim_physical_sale_contract sc
|
||||||
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0))
|
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0))
|
||||||
)
|
)
|
||||||
SELECT 2 AS "intPnlTypeId",
|
SELECT
|
||||||
trade.strtradeid AS "strConformedReferenceId",
|
CASE
|
||||||
|
WHEN ((trade."strBookName")::text ~~ '%Projection%'::text) THEN 1
|
||||||
|
ELSE 2
|
||||||
|
END AS "intPnlTypeId",
|
||||||
|
trade."strTradeId" AS "strConformedReferenceId",
|
||||||
contracts."intPriceGroupId",
|
contracts."intPriceGroupId",
|
||||||
contracts."Line Description",
|
contracts."Line Description",
|
||||||
contracts."Open Quantity Signed",
|
contracts."Open Quantity Signed",
|
||||||
contracts."Price",
|
contracts."Price",
|
||||||
contracts."Open Cost Amount" AS amount,
|
contracts."Open Cost Amount" AS amount,
|
||||||
contracts."Estimated BL Date" AS "Delivery Date",
|
contracts."Estimated BL Date" AS "Delivery Date",
|
||||||
contracts."Line Group"
|
CASE
|
||||||
FROM (vw_bi_itsa_physical_open_costs contracts
|
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")))
|
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
|
UNION ALL
|
||||||
SELECT 3 AS "intPnlTypeId",
|
SELECT 3 AS "intPnlTypeId",
|
||||||
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
|
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
|
||||||
1 AS "intPriceGroupId",
|
CASE
|
||||||
'Purchase'::character varying AS "Line Description",
|
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."Shipped Quantity" AS "Open Quantity Signed",
|
||||||
shipment."Purchase Price" AS "Price",
|
fee_alloc."Price",
|
||||||
(shipment."Shipped Quantity" * (shipment."Purchase Price")::double precision) AS amount,
|
(fee_alloc."Amount" * fee_alloc."Sign Multiplier") AS amount,
|
||||||
shipment."BL Date" AS "Delivery Date",
|
shipment."BL Date" AS "Delivery Date",
|
||||||
'Purchase'::text AS "Line Group"
|
fee_alloc."Cost Group" AS "Line Group",
|
||||||
FROM vw_bi_itsa_fct_shipments shipment
|
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
|
UNION ALL
|
||||||
SELECT 3 AS "intPnlTypeId",
|
SELECT 3 AS "intPnlTypeId",
|
||||||
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
|
'0_0'::text 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",
|
|
||||||
2 AS "intPriceGroupId",
|
2 AS "intPriceGroupId",
|
||||||
fees."Fee" AS "Line Description",
|
ifrs."Comments" AS "Line Description",
|
||||||
shipment."Shipped Quantity" AS "Open Quantity Signed",
|
0 AS "Open Quantity Signed",
|
||||||
fees."Price",
|
0 AS "Price",
|
||||||
(shipment."Shipped Quantity" * (fees."Price")::double precision) AS amount,
|
ifrs."Amount" AS amount,
|
||||||
shipment."BL Date" AS "Delivery Date",
|
ifrs."Adjustment Date" AS "Delivery Date",
|
||||||
fees."Cost Group" AS "Line Group"
|
'Monthly Adjustment'::text AS "Line Group",
|
||||||
FROM (vw_bi_itsa_fct_shipment_fees fees
|
ifrs."intBookId",
|
||||||
JOIN vw_bi_itsa_fct_shipments shipment ON ((fees."intShipmentId" = shipment."intShipmentId")))
|
0 AS "Open Quantity",
|
||||||
UNION ALL
|
'Section 5'::text AS "Code Section"
|
||||||
SELECT fees."intPnlTypeId",
|
FROM vw_bi_itsa_monthly_trade_ifrs_adjustments ifrs;;
|
||||||
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);;
|
|
||||||
|
|||||||
@@ -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",
|
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
|
||||||
2 AS "intPriceGroupId",
|
2 AS "intPriceGroupId",
|
||||||
ctr_fees."Fee" AS "Line Description",
|
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",
|
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",
|
shipment."BL Date" AS "Delivery Date",
|
||||||
ctr_fees."Cost Group" AS "Line Group"
|
ctr_fees."Cost Group" AS "Line Group",
|
||||||
FROM (vw_bi_itsa_fct_shipments shipment
|
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")))
|
JOIN vw_bi_itsa_fct_contract_fees ctr_fees ON ((ctr_fees."intContractLineId" = shipment."intPurchaseLineId")))
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT 3 AS "intPnlTypeId",
|
SELECT 3 AS "intPnlTypeId",
|
||||||
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
|
((shipment."intPurchaseLineId" || '_'::text) || shipment."intSaleLineId") AS "strConformedReferenceId",
|
||||||
2 AS "intPriceGroupId",
|
2 AS "intPriceGroupId",
|
||||||
fees."Fee" AS "Line Description",
|
fees."Fee" AS "Line Description",
|
||||||
shipment."Shipped Quantity" AS "Open Quantity Signed",
|
(shipment."Shipped Quantity")::double precision AS "Open Quantity Signed",
|
||||||
fees."Price",
|
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",
|
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
|
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",
|
SELECT all_fees."intPnlTypeId",
|
||||||
all_fees."strConformedReferenceId",
|
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."Price",
|
||||||
all_fees."Amount",
|
all_fees."Amount",
|
||||||
all_fees."Delivery Date",
|
all_fees."Delivery Date",
|
||||||
all_fees."Line Group"
|
all_fees."Line Group",
|
||||||
|
all_fees."intBookId"
|
||||||
FROM all_fees
|
FROM all_fees
|
||||||
WHERE ((all_fees."Line Description")::text <> 'Profit sharing'::text)
|
WHERE ((all_fees."Line Description")::text <> 'Profit sharing'::text)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
@@ -44,7 +47,8 @@ UNION ALL
|
|||||||
ranked."Price",
|
ranked."Price",
|
||||||
ranked."Amount",
|
ranked."Amount",
|
||||||
ranked."Delivery Date",
|
ranked."Delivery Date",
|
||||||
ranked."Line Group"
|
ranked."Line Group",
|
||||||
|
ranked."intBookId"
|
||||||
FROM ( SELECT all_fees."intPnlTypeId",
|
FROM ( SELECT all_fees."intPnlTypeId",
|
||||||
all_fees."strConformedReferenceId",
|
all_fees."strConformedReferenceId",
|
||||||
all_fees."intPriceGroupId",
|
all_fees."intPriceGroupId",
|
||||||
@@ -54,6 +58,7 @@ UNION ALL
|
|||||||
all_fees."Amount",
|
all_fees."Amount",
|
||||||
all_fees."Delivery Date",
|
all_fees."Delivery Date",
|
||||||
all_fees."Line Group",
|
all_fees."Line Group",
|
||||||
|
all_fees."intBookId",
|
||||||
row_number() OVER (PARTITION BY all_fees."strConformedReferenceId" ORDER BY all_fees."Price" DESC) AS rn
|
row_number() OVER (PARTITION BY all_fees."strConformedReferenceId" ORDER BY all_fees."Price" DESC) AS rn
|
||||||
FROM all_fees
|
FROM all_fees
|
||||||
WHERE ((all_fees."Line Description")::text = 'Profit sharing'::text)) ranked
|
WHERE ((all_fees."Line Description")::text = 'Profit sharing'::text)) ranked
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_shipments_v2 AS
|
|||||||
q.bl_date AS "BL Date",
|
q.bl_date AS "BL Date",
|
||||||
q.delivery_date_from AS "Delivery Date From",
|
q.delivery_date_from AS "Delivery Date From",
|
||||||
q.delivery_date_to AS "Delivery Date To",
|
q.delivery_date_to AS "Delivery Date To",
|
||||||
q.valued_lot_type AS "Lot Type"
|
q.valued_lot_type AS "Lot Type",
|
||||||
FROM ((vw_utility_trade_pnl_quantities q
|
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_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_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));;
|
WHERE ((q.ignored_by_finished_rule = false) AND (q.shipment_id IS NOT NULL));;
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_monthly_trade_ifrs_adjustments AS
|
|||||||
"dtmAdjustmentDate" AS "Adjustment Date",
|
"dtmAdjustmentDate" AS "Adjustment Date",
|
||||||
"dblAmount" AS "Amount",
|
"dblAmount" AS "Amount",
|
||||||
"strCurrency" AS "Currency",
|
"strCurrency" AS "Currency",
|
||||||
"strComments" AS "Comments"
|
"strComments" AS "Comments",
|
||||||
|
"intBookId"
|
||||||
FROM vw_utility_monthly_trade_ifrs_adjustments;;
|
FROM vw_utility_monthly_trade_ifrs_adjustments;;
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_physical_open_costs AS
|
|||||||
), contract_open_quantity AS (
|
), contract_open_quantity AS (
|
||||||
SELECT 'Purchase'::text AS "TradeType",
|
SELECT 'Purchase'::text AS "TradeType",
|
||||||
pc."intPurchaseLineId" AS "TradeLineId",
|
pc."intPurchaseLineId" AS "TradeLineId",
|
||||||
pc."dblTheoriticalQuantity" AS "TheoriticalQuantity",
|
|
||||||
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)
|
||||||
@@ -30,8 +28,6 @@ CREATE OR REPLACE VIEW public.vw_bi_itsa_physical_open_costs AS
|
|||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT 'Sale'::text AS "TradeType",
|
SELECT 'Sale'::text AS "TradeType",
|
||||||
pc."intSaleLineId" AS "TradeLineId",
|
pc."intSaleLineId" AS "TradeLineId",
|
||||||
pc."dblTheoreticalQuantity" AS "TheoriticalQuantity",
|
|
||||||
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)
|
||||||
|
|||||||
217
Database Backups/SQL Views/vw_bi_itsa_physical_open_costs_v2.sql
Normal file
217
Database Backups/SQL Views/vw_bi_itsa_physical_open_costs_v2.sql
Normal 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));;
|
||||||
@@ -14,7 +14,8 @@ CREATE OR REPLACE VIEW public.vw_utility_book_dimension AS
|
|||||||
'Physical'::text AS "strTradeCategory",
|
'Physical'::text AS "strTradeCategory",
|
||||||
'Purchase'::text AS "strTradeType",
|
'Purchase'::text AS "strTradeType",
|
||||||
bv."valueCode" AS "strValueCode",
|
bv."valueCode" AS "strValueCode",
|
||||||
bv."valueName" AS "strValueName"
|
bv."valueName" AS "strValueName",
|
||||||
|
bv."valueId" AS "intBookId"
|
||||||
FROM ((analytic_dimension_assignment aa
|
FROM ((analytic_dimension_assignment aa
|
||||||
JOIN bookvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
|
JOIN bookvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
|
||||||
JOIN purchase_line pl ON ((aa.purchase = pl.purchase)))
|
JOIN purchase_line pl ON ((aa.purchase = pl.purchase)))
|
||||||
@@ -25,7 +26,8 @@ UNION ALL
|
|||||||
'Physical'::text AS "strTradeCategory",
|
'Physical'::text AS "strTradeCategory",
|
||||||
'Sale'::text AS "strTradeType",
|
'Sale'::text AS "strTradeType",
|
||||||
bv."valueCode" AS "strValueCode",
|
bv."valueCode" AS "strValueCode",
|
||||||
bv."valueName" AS "strValueName"
|
bv."valueName" AS "strValueName",
|
||||||
|
bv."valueId" AS "intBookId"
|
||||||
FROM ((analytic_dimension_assignment aa
|
FROM ((analytic_dimension_assignment aa
|
||||||
JOIN bookvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
|
JOIN bookvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
|
||||||
JOIN sale_line sl ON ((sl.sale = aa.sale)))
|
JOIN sale_line sl ON ((sl.sale = aa.sale)))
|
||||||
|
|||||||
@@ -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 purchase_purchase pur ON ((pur.id = pl.purchase)))
|
||||||
JOIN party_party pp ON ((pp.id = pur.party)))
|
JOIN party_party pp ON ((pp.id = pur.party)))
|
||||||
JOIN currency_currency cur ON ((cur.id = pur.currency)))
|
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));;
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
CREATE OR REPLACE VIEW public.vw_utility_monthly_trade_ifrs_adjustments AS
|
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",
|
SELECT apti.id AS "intAdjustmentId",
|
||||||
apti.date AS "dtmAdjustmentDate",
|
apti.date AS "dtmAdjustmentDate",
|
||||||
apti.amount AS "dblAmount",
|
apti.amount AS "dblAmount",
|
||||||
cur.name AS "strCurrency",
|
cur.name AS "strCurrency",
|
||||||
apti.comment AS "strComments"
|
apti.comment AS "strComments",
|
||||||
FROM (account_physical_trade_ifrs apti
|
books."intBookId"
|
||||||
JOIN currency_currency cur ON ((cur.id = apti.currency)));;
|
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)));;
|
||||||
|
|||||||
89
Database Backups/SQL Views/vw_utility_open_position.sql
Normal file
89
Database Backups/SQL Views/vw_utility_open_position.sql
Normal 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;;
|
||||||
@@ -10,7 +10,9 @@ CREATE OR REPLACE VIEW public.vw_utility_physical_mtm_definition AS
|
|||||||
pc_mtm.ratio AS "strComponentRatioPct",
|
pc_mtm.ratio AS "strComponentRatioPct",
|
||||||
ft.name AS "strComponentFixType",
|
ft.name AS "strComponentFixType",
|
||||||
pi.price_desc AS "strComponentCurve",
|
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
|
FROM (((((((((purchase_strategy ps
|
||||||
JOIN purchase_line pl ON ((pl.id = ps.line)))
|
JOIN purchase_line pl ON ((pl.id = ps.line)))
|
||||||
JOIN purchase_purchase pp ON ((pp.id = pl.purchase)))
|
JOIN purchase_purchase pp ON ((pp.id = pl.purchase)))
|
||||||
@@ -33,7 +35,9 @@ UNION ALL
|
|||||||
pc_mtm.ratio AS "strComponentRatioPct",
|
pc_mtm.ratio AS "strComponentRatioPct",
|
||||||
ft.name AS "strComponentFixType",
|
ft.name AS "strComponentFixType",
|
||||||
pi.price_desc AS "strComponentCurve",
|
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
|
FROM (((((((((sale_strategy sa
|
||||||
JOIN sale_line sl ON ((sl.id = sa.sale_line)))
|
JOIN sale_line sl ON ((sl.id = sa.sale_line)))
|
||||||
JOIN sale_sale ss ON ((ss.id = sl.sale)))
|
JOIN sale_sale ss ON ((ss.id = sl.sale)))
|
||||||
|
|||||||
@@ -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);;
|
||||||
@@ -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);;
|
||||||
@@ -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((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(inst.dblinstructedqty, (0)::double precision) AS "dblInInstructedQuantity",
|
||||||
COALESCE(bl.estimated_date, pl.to_del) AS "dtmEstimatedBLDate",
|
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
|
FROM (((((((((((purchase_line pl
|
||||||
JOIN purchase_purchase pc ON ((pl.purchase = pc.id)))
|
JOIN purchase_purchase pc ON ((pl.purchase = pc.id)))
|
||||||
JOIN product_uom pu1 ON ((pl.unit = pu1.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
|
FROM vw_utility_instructed_lots t1
|
||||||
GROUP BY t1."intPurchaseLineId") inst ON ((pl.id = inst."intPurchaseLineId")))
|
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))))
|
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));;
|
||||||
|
|||||||
@@ -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",
|
((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(bl.estimated_date, sl.from_del) AS "dtmEstimatedBLDate",
|
||||||
COALESCE(instructed.dblinstructedqty, ((0)::numeric)::double precision) AS "dblInstructedQuantity",
|
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
|
FROM ((((((sale_line sl
|
||||||
JOIN sale_sale sc ON ((sl.sale = sc.id)))
|
JOIN sale_sale sc ON ((sl.sale = sc.id)))
|
||||||
JOIN product_uom pu1 ON ((sl.unit = pu1.id)))
|
JOIN product_uom pu1 ON ((sl.unit = pu1.id)))
|
||||||
|
|||||||
@@ -44,13 +44,14 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
|
|||||||
FROM virtual_shipment_lots
|
FROM virtual_shipment_lots
|
||||||
), shipment_context AS (
|
), shipment_context AS (
|
||||||
SELECT shipment_lots.shipment_id,
|
SELECT shipment_lots.shipment_id,
|
||||||
|
shipment_lots.lot_id,
|
||||||
shipment_lots.purchase_line_id,
|
shipment_lots.purchase_line_id,
|
||||||
shipment_lots.sale_line_id,
|
shipment_lots.sale_line_id,
|
||||||
shipment_lots.shipment_unit_id,
|
shipment_lots.shipment_unit_id,
|
||||||
sum(COALESCE(shipment_lots.shipment_quantity, (0)::numeric)) AS shipment_quantity
|
sum(COALESCE(shipment_lots.shipment_quantity, (0)::numeric)) AS shipment_quantity
|
||||||
FROM shipment_lots
|
FROM shipment_lots
|
||||||
WHERE (shipment_lots.shipment_id IS NOT NULL)
|
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 (
|
), shipment_base AS (
|
||||||
SELECT shipment_context.shipment_id,
|
SELECT shipment_context.shipment_id,
|
||||||
sum(shipment_context.shipment_quantity) AS shipment_quantity
|
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
|
ELSE NULL::integer
|
||||||
END AS priority,
|
END AS priority,
|
||||||
sb.shipment_id,
|
sb.shipment_id,
|
||||||
NULL::integer AS purchase_line_id,
|
|
||||||
NULL::integer AS sale_line_id,
|
|
||||||
f_1.product AS product_id,
|
f_1.product AS product_id,
|
||||||
f_1.supplier AS supplier_id,
|
f_1.supplier AS supplier_id,
|
||||||
f_1.mode AS packaging,
|
f_1.mode AS packaging,
|
||||||
@@ -82,18 +81,17 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
|
|||||||
CASE
|
CASE
|
||||||
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN 1
|
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN 1
|
||||||
ELSE '-1'::integer
|
ELSE '-1'::integer
|
||||||
END AS sign_multiplier
|
END AS sign_multiplier,
|
||||||
|
NULL::text AS forced_cost_group
|
||||||
FROM (shipment_base sb
|
FROM (shipment_base sb
|
||||||
JOIN fee_fee f_1 ON ((f_1.shipment_in = sb.shipment_id)))
|
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[]))
|
WHERE ((f_1.type)::text = ANY (ARRAY[('ordered'::character varying)::text, ('scheduled'::character varying)::text]))
|
||||||
), shipment_fee_allocated AS (
|
), shipment_fee_limits AS (
|
||||||
SELECT c.fee_id,
|
SELECT c.fee_id,
|
||||||
c.fee_source,
|
c.fee_source,
|
||||||
c.fee_type,
|
c.fee_type,
|
||||||
c.priority,
|
c.priority,
|
||||||
c.shipment_id,
|
c.shipment_id,
|
||||||
c.purchase_line_id,
|
|
||||||
c.sale_line_id,
|
|
||||||
c.product_id,
|
c.product_id,
|
||||||
c.supplier_id,
|
c.supplier_id,
|
||||||
c.packaging,
|
c.packaging,
|
||||||
@@ -106,8 +104,34 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
|
|||||||
c.currency_id,
|
c.currency_id,
|
||||||
c.unit_id,
|
c.unit_id,
|
||||||
c.sign_multiplier,
|
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
|
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 (
|
), shipment_fee_coverage AS (
|
||||||
SELECT shipment_fee_allocated.shipment_id,
|
SELECT shipment_fee_allocated.shipment_id,
|
||||||
shipment_fee_allocated.product_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,
|
f_1.type AS fee_type,
|
||||||
3 AS priority,
|
3 AS priority,
|
||||||
sc.shipment_id,
|
sc.shipment_id,
|
||||||
|
sc.lot_id,
|
||||||
sc.purchase_line_id,
|
sc.purchase_line_id,
|
||||||
NULL::integer AS sale_line_id,
|
sc.sale_line_id,
|
||||||
f_1.product AS product_id,
|
f_1.product AS product_id,
|
||||||
f_1.supplier AS supplier_id,
|
f_1.supplier AS supplier_id,
|
||||||
f_1.mode AS packaging,
|
f_1.mode AS packaging,
|
||||||
@@ -137,7 +162,8 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
|
|||||||
CASE
|
CASE
|
||||||
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN '-1'::integer
|
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN '-1'::integer
|
||||||
ELSE 1
|
ELSE 1
|
||||||
END AS sign_multiplier
|
END AS sign_multiplier,
|
||||||
|
NULL::text AS forced_cost_group
|
||||||
FROM (shipment_context sc
|
FROM (shipment_context sc
|
||||||
JOIN fee_fee f_1 ON ((f_1.line = sc.purchase_line_id)))
|
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))
|
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,
|
f_1.type AS fee_type,
|
||||||
3 AS priority,
|
3 AS priority,
|
||||||
sc.shipment_id,
|
sc.shipment_id,
|
||||||
NULL::integer AS purchase_line_id,
|
sc.lot_id,
|
||||||
|
sc.purchase_line_id,
|
||||||
sc.sale_line_id,
|
sc.sale_line_id,
|
||||||
f_1.product AS product_id,
|
f_1.product AS product_id,
|
||||||
f_1.supplier AS supplier_id,
|
f_1.supplier AS supplier_id,
|
||||||
@@ -162,7 +189,8 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
|
|||||||
CASE
|
CASE
|
||||||
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN 1
|
WHEN (upper((f_1.p_r)::text) = 'REC'::text) THEN 1
|
||||||
ELSE '-1'::integer
|
ELSE '-1'::integer
|
||||||
END AS sign_multiplier
|
END AS sign_multiplier,
|
||||||
|
NULL::text AS forced_cost_group
|
||||||
FROM (shipment_context sc
|
FROM (shipment_context sc
|
||||||
JOIN fee_fee f_1 ON ((f_1.sale_line = sc.sale_line_id)))
|
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))
|
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.fee_type,
|
||||||
c.priority,
|
c.priority,
|
||||||
c.shipment_id,
|
c.shipment_id,
|
||||||
|
c.lot_id,
|
||||||
c.purchase_line_id,
|
c.purchase_line_id,
|
||||||
c.sale_line_id,
|
c.sale_line_id,
|
||||||
c.product_id,
|
c.product_id,
|
||||||
@@ -185,15 +214,66 @@ CREATE OR REPLACE VIEW public.vw_utility_shipment_fee_allocation AS
|
|||||||
c.currency_id,
|
c.currency_id,
|
||||||
c.unit_id,
|
c.unit_id,
|
||||||
c.sign_multiplier,
|
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
|
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))))
|
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 (
|
), final_fees AS (
|
||||||
SELECT shipment_fee_allocated.fee_id,
|
SELECT shipment_fee_allocated.fee_id,
|
||||||
shipment_fee_allocated.fee_source,
|
shipment_fee_allocated.fee_source,
|
||||||
shipment_fee_allocated.fee_type,
|
shipment_fee_allocated.fee_type,
|
||||||
shipment_fee_allocated.priority,
|
shipment_fee_allocated.priority,
|
||||||
shipment_fee_allocated.shipment_id,
|
shipment_fee_allocated.shipment_id,
|
||||||
|
shipment_fee_allocated.lot_id,
|
||||||
shipment_fee_allocated.purchase_line_id,
|
shipment_fee_allocated.purchase_line_id,
|
||||||
shipment_fee_allocated.sale_line_id,
|
shipment_fee_allocated.sale_line_id,
|
||||||
shipment_fee_allocated.product_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.fee_price,
|
||||||
shipment_fee_allocated.currency_id,
|
shipment_fee_allocated.currency_id,
|
||||||
shipment_fee_allocated.unit_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
|
FROM shipment_fee_allocated
|
||||||
WHERE (shipment_fee_allocated.allocated_quantity > (0)::numeric)
|
WHERE (shipment_fee_allocated.allocated_quantity > (0)::numeric)
|
||||||
UNION ALL
|
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.fee_type,
|
||||||
contract_budgeted_allocated.priority,
|
contract_budgeted_allocated.priority,
|
||||||
contract_budgeted_allocated.shipment_id,
|
contract_budgeted_allocated.shipment_id,
|
||||||
|
contract_budgeted_allocated.lot_id,
|
||||||
contract_budgeted_allocated.purchase_line_id,
|
contract_budgeted_allocated.purchase_line_id,
|
||||||
contract_budgeted_allocated.sale_line_id,
|
contract_budgeted_allocated.sale_line_id,
|
||||||
contract_budgeted_allocated.product_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.fee_price,
|
||||||
contract_budgeted_allocated.currency_id,
|
contract_budgeted_allocated.currency_id,
|
||||||
contract_budgeted_allocated.unit_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
|
FROM contract_budgeted_allocated
|
||||||
WHERE (contract_budgeted_allocated.allocated_quantity > (0)::numeric)
|
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",
|
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_source AS "strFeeSource",
|
||||||
f.fee_type AS "strFeeType",
|
f.fee_type AS "strFeeType",
|
||||||
f.priority AS "intPriority",
|
f.priority AS "intPriority",
|
||||||
f.purchase_line_id AS "intPurchaseLineId",
|
COALESCE(f.purchase_line_id, 0) AS "intPurchaseLineId",
|
||||||
f.sale_line_id AS "intSaleLineId",
|
COALESCE(f.sale_line_id, 0) AS "intSaleLineId",
|
||||||
f.product_id AS "intProductId",
|
COALESCE(f.product_id, 0) AS "intProductId",
|
||||||
p.code AS "strFee",
|
COALESCE(p.code, ''::character varying) AS "strFee",
|
||||||
f.supplier_id AS "intSupplierId",
|
COALESCE(f.supplier_id, 0) AS "intSupplierId",
|
||||||
sup.name AS "strSupplier",
|
COALESCE(sup.name, ''::character varying) AS "strSupplier",
|
||||||
f.packaging AS "strPackaging",
|
COALESCE(f.packaging, ''::character varying) AS "strPackaging",
|
||||||
f.pay_or_rec AS "strPayOrRec",
|
COALESCE(f.pay_or_rec, ''::character varying) AS "strPayOrRec",
|
||||||
f.state AS "strState",
|
COALESCE(f.state, ''::character varying) AS "strState",
|
||||||
CASE
|
CASE
|
||||||
WHEN (upper((f.weight_type)::text) = 'BRUT'::text) THEN 'Gross'::text
|
WHEN (upper((f.weight_type)::text) = 'BRUT'::text) THEN 'Gross'::text
|
||||||
ELSE 'Net'::text
|
ELSE 'Net'::text
|
||||||
END AS "strWeighingType",
|
END AS "strWeighingType",
|
||||||
f.fee_quantity AS "dblQuantity",
|
f.fee_quantity AS "dblQuantity",
|
||||||
(f.fee_price * (f.sign_multiplier)::numeric) AS "dblPrice",
|
f.fee_price AS "dblPrice",
|
||||||
cur.name AS "strCurrency",
|
COALESCE(cur.name, ''::character varying) AS "strCurrency",
|
||||||
COALESCE(uom.name, 'Mt'::character varying) AS "strUnit",
|
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
|
CASE
|
||||||
WHEN (upper((p.code)::text) ~~ '%FREIGHT%'::text) THEN 'Freight'::text
|
WHEN (upper((p.code)::text) ~~ '%FREIGHT%'::text) THEN 'Freight'::text
|
||||||
WHEN (upper((p.code)::text) ~~ '%PROFIT SHARING%'::text) THEN 'ProfitSharing'::text
|
WHEN (upper((p.code)::text) ~~ '%PROFIT SHARING%'::text) THEN 'Profit Sharing'::text
|
||||||
ELSE 'OtherCosts'::text
|
ELSE 'Other Costs'::text
|
||||||
END AS "strCostGroup"
|
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
|
FROM ((((final_fees f
|
||||||
JOIN product_product p ON ((p.id = f.product_id)))
|
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 currency_currency cur ON ((cur.id = f.currency_id)))
|
||||||
LEFT JOIN product_uom uom ON ((uom.id = f.unit_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;;
|
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
|
|||||||
p.reference AS purchase_reference,
|
p.reference AS purchase_reference,
|
||||||
pl.id AS purchase_line_id,
|
pl.id AS purchase_line_id,
|
||||||
pl.finished AS purchase_line_finished,
|
pl.finished AS purchase_line_finished,
|
||||||
NULL::integer AS sale_id,
|
s.id AS sale_id,
|
||||||
NULL::character varying AS sale_number,
|
s.number AS sale_number,
|
||||||
NULL::character varying AS sale_reference,
|
s.reference AS sale_reference,
|
||||||
NULL::integer AS sale_line_id,
|
sl.id AS sale_line_id,
|
||||||
NULL::boolean AS sale_line_finished,
|
sl.finished AS sale_line_finished,
|
||||||
l.id AS valued_lot_id,
|
l.id AS valued_lot_id,
|
||||||
l.lot_type AS valued_lot_type,
|
l.lot_type AS valued_lot_type,
|
||||||
NULL::integer AS lot_qt_id,
|
NULL::integer AS lot_qt_id,
|
||||||
@@ -33,10 +33,12 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
|
|||||||
shi.bl_date,
|
shi.bl_date,
|
||||||
pl.from_del AS delivery_date_from,
|
pl.from_del AS delivery_date_from,
|
||||||
pl.to_del AS delivery_date_to
|
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 purchase_purchase p ON ((p.id = pl.purchase)))
|
||||||
JOIN lot_lot l ON ((l.line = pl.id)))
|
JOIN lot_lot l ON ((l.line = pl.id)))
|
||||||
JOIN lot_current_qty lcq ON ((lcq.lot_id = l.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_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_internal sint ON ((sint.id = l.lot_shipment_internal)))
|
||||||
LEFT JOIN stock_shipment_out sho ON ((sho.id = l.lot_shipment_out)))
|
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_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_internal sint ON ((sint.id = l.lot_shipment_internal)))
|
||||||
LEFT JOIN stock_shipment_out sho ON ((sho.id = l.lot_shipment_out)))
|
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 (
|
), sale_pnl_matched_virtual_lots AS (
|
||||||
SELECT 'sale'::text AS pnl_side,
|
SELECT 'sale'::text AS pnl_side,
|
||||||
p.id AS purchase_id,
|
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.id AS valued_lot_id,
|
||||||
sale_lot.lot_type AS valued_lot_type,
|
sale_lot.lot_type AS valued_lot_type,
|
||||||
lqt.id AS lot_qt_id,
|
lqt.id AS lot_qt_id,
|
||||||
lcq.pnl_quantity,
|
lqt.lot_quantity AS pnl_quantity,
|
||||||
lcq.quantity_uom AS quantity_unit,
|
lcq.quantity_uom AS quantity_unit,
|
||||||
sl.product AS product_id,
|
sl.product AS product_id,
|
||||||
COALESCE(shi.from_location, sint.from_location, sho.from_location, s.from_location) AS from_location_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
9
ITSA_Tradon_Prod.md
Normal 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
9
OS_Tradon_Prod.md
Normal 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`
|
||||||
@@ -628,7 +628,7 @@ WHERE 1=1
|
|||||||
AND D.Status <> 'Cancelled'
|
AND D.Status <> 'Cancelled'
|
||||||
AND D.BuyOrSell = 1 -- Purchase contracts
|
AND D.BuyOrSell = 1 -- Purchase contracts
|
||||||
AND ISNULL(D.OtherReference, '') NOT LIKE '%ACCT Matching%'
|
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
|
ORDER BY 3,1
|
||||||
|
|
||||||
|
|
||||||
@@ -831,7 +831,7 @@ WHERE 1=1
|
|||||||
AND D.Status <> 'Cancelled'
|
AND D.Status <> 'Cancelled'
|
||||||
AND D.BuyOrSell = -1 -- Sale contracts
|
AND D.BuyOrSell = -1 -- Sale contracts
|
||||||
AND ISNULL(D.OtherReference, '') NOT LIKE '%ACCT Matching%'
|
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
|
ORDER BY 3,1
|
||||||
|
|
||||||
|
|
||||||
@@ -874,7 +874,7 @@ WHERE 1=1
|
|||||||
AND D.Status <> 'Cancelled'
|
AND D.Status <> 'Cancelled'
|
||||||
AND D.BuyOrSell = 1 -- Purchase contracts
|
AND D.BuyOrSell = 1 -- Purchase contracts
|
||||||
AND ISNULL(D.OtherReference, '') NOT LIKE '%ACCT Matching%'
|
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
|
AND ER.FormulaGroup NOT IN (1,2) -- Not Price or MtM
|
||||||
ORDER BY 1
|
ORDER BY 1
|
||||||
|
|
||||||
@@ -948,7 +948,7 @@ WHERE 1=1
|
|||||||
AND D.Status <> 'Cancelled'
|
AND D.Status <> 'Cancelled'
|
||||||
AND D.BuyOrSell <> 1 -- Sale contracts
|
AND D.BuyOrSell <> 1 -- Sale contracts
|
||||||
AND ISNULL(D.OtherReference, '') NOT LIKE '%ACCT Matching%'
|
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
|
AND ER.FormulaGroup NOT IN (1,2) -- Not Price or MtM
|
||||||
ORDER BY 1
|
ORDER BY 1
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -20,14 +20,14 @@ PRICE_INDEXES_CSV = 'Reference Data\python_project\loaders\Price_Indexes.csv'
|
|||||||
|
|
||||||
# XML-RPC Configuration (for Proteus interaction)
|
# XML-RPC Configuration (for Proteus interaction)
|
||||||
HTTPS = 'https://'
|
HTTPS = 'https://'
|
||||||
SERVER_URL = 'itsa.open-squared.tech'
|
SERVER_URL = 'prod.open-squared.tech'
|
||||||
DATABASE_NAME = 'tradon'
|
DATABASE_NAME = 'tradon'
|
||||||
USERNAME = 'admin'
|
USERNAME = 'admin'
|
||||||
PASSWORD = 'dsproject'
|
PASSWORD = 'dsproject'
|
||||||
|
|
||||||
# PostgreSQL Configuration (for direct database access if needed)
|
# PostgreSQL Configuration (for direct database access if needed)
|
||||||
DB_HOST = '72.61.163.139'
|
DB_HOST = '62.72.36.116'
|
||||||
DB_PORT = 5433
|
DB_PORT = 5432
|
||||||
DB_USER = 'postgres'
|
DB_USER = 'postgres'
|
||||||
DB_PASSWORD = 'dsproject'
|
DB_PASSWORD = 'dsproject'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user