Files
Implementation_ITSA/Database Backups/SQL Views/vw_bi_dim_purchase_physical_contract.sql
AzureAD\SylvainDUVERNAY af63a53372 Dump - ITSA views
2026-06-14 11:05:54 +02:00

63 lines
3.6 KiB
SQL

CREATE OR REPLACE VIEW public.vw_bi_dim_purchase_physical_contract AS
WITH pricingstatus AS (
SELECT pvl_1."intContractLineId",
pvl_1."strState"
FROM vw_utility_physical_valuation_line pvl_1
GROUP BY pvl_1."intContractLineId", pvl_1."strState"
)
SELECT dpc."intPurchaseLineId",
dpc."strContractNb" AS "Contract Nb",
dpc."strCounterparty" AS "Supplier",
dpc."strReference" AS "Contract Ref",
dpc."dtmContractDate" AS "Contract Date",
CASE
WHEN ((dpc."strContractStatus")::text = 'Draft'::text) THEN (((dpc."strContractStatus")::text || ' 🧾'::text))::character varying
WHEN ((dpc."strContractStatus")::text = 'Confirmed'::text) THEN (((dpc."strContractStatus")::text || ''::text))::character varying
WHEN ((dpc."strContractStatus")::text = 'Validated'::text) THEN (((dpc."strContractStatus")::text || ' ✔️'::text))::character varying
WHEN ((dpc."strContractStatus")::text = 'Processing'::text) THEN (((dpc."strContractStatus")::text || ''::text))::character varying
ELSE dpc."strContractStatus"
END AS "Contract Status",
dpc."strPaymentTerm" AS "Payment Terms",
dpc."strCurrency" AS "Currency",
dpc."strWeightBasis" AS "Weight Basis",
dpc."strBroker" AS "Broker",
dpc."strCertif" AS "Certification",
dpc."strAssociation" AS "Association",
dpc."strCrop" AS "Crop",
dpc."dblTolMinPct" AS "Tolerance Min %",
dpc."dblTolMaxPct" AS "Tolerance Max %",
dpc."strIncoterm" AS "Inco Terms",
dpc."strLoadingPlace" AS "Loading Place",
dpc."strDestinationPlace" AS "Destination Place",
dpc."strProduct" AS "Product",
dpc."strDeliveryPeriod" AS "Delivery Period",
dpc."strRegion" AS "Bassin",
dpc."strBookName" AS "Book",
dpc."strStrategyName" AS "Strategy",
dpc."strQuantityUom" AS "Quantity UOM",
dpc."dtmDeliveryDateFrom" AS "Delivery Date From",
dpc."dtmDeliveryDateTo" AS "Delivery Date To",
CASE
WHEN (dpc."dtmDeliveryDateTo" < CURRENT_DATE) THEN 'Overdue'::text
WHEN ((dpc."dtmDeliveryDateFrom" <= CURRENT_DATE) AND (dpc."dtmDeliveryDateTo" >= CURRENT_DATE)) THEN 'Current'::text
WHEN (dpc."dtmDeliveryDateFrom" > CURRENT_DATE) THEN 'Future'::text
ELSE 'Unknown'::text
END AS "Delivery Status",
CASE
WHEN ((dpc."strBookName")::text ~~ '%Projection%'::text) THEN 'Yes'::text
ELSE 'No'::text
END AS "Is Projection",
dpc."strIncotermCode" AS "Incoterm Code",
dpc."dtmEstimatedBLDate" AS "Estimated BL Date",
dpc."strPricingType" AS "Pricing Type",
COALESCE(mtm."strStrategy", 'Undefined'::character varying) AS "MtM Strategy",
COALESCE(mtm."strScenario", 'Undefined'::character varying) AS "MtM Scenario",
COALESCE(mtm."strComponentCurve", 'Undefined'::character varying) AS "MtM Component Curve",
dpc."strCounterpartyCountry" AS "Supplier Country",
COALESCE(pvl."strState", ('Undefined'::character varying)::text) AS "Price Fixing Status",
(dpc."intPurchaseLineId" || '_0'::text) AS "strTradeId",
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")));;