update convert pool to target osmfs in its current state

This commit is contained in:
Paul Trowbridge 2023-03-07 11:44:22 -05:00
parent ef0c9175cd
commit a0c5482f6c

View File

@ -3,11 +3,12 @@ LANGUAGE plpgsql AS
$func$
BEGIN
DELETE FROM rlarp.osmfs_dev;
DELETE FROM rlarp.osmfs;
INSERT INTO
rlarp.osmfs_dev
rlarp.osmfs
SELECT
------------document ids---------------------
null::int4,
null::int4,
null::int4,
@ -16,14 +17,17 @@ SELECT
null::int4,
null::int4,
null::int4,
------------document dates-------------------
order_date,
request_date,
null::date,
null::date,
ship_date,
------------document flags-------------------
null::text,
null::text,
fspr,
------------document quantities--------------
null::numeric,
null::numeric,
null::numeric,
@ -31,6 +35,7 @@ SELECT
null::numeric,
null::numeric,
null::jsonb,
------------document attributes--------------
null::text,
plnt,
promo,
@ -38,6 +43,7 @@ SELECT
terms,
null::text,
null::text,
------------customer info---------------------
null::text,
rtrim(substring(bill_cust_descr,1,8)),
null::text,
@ -61,6 +67,7 @@ SELECT
null::text,
null::text,
null::text,
------------product info----------------------
part,
null::text,
null::text,
@ -84,8 +91,10 @@ SELECT
null::text,
null::text,
null::text,
null::text,
null::numeric,
null::numeric,
------------fiscal info-----------------------
null::text,
fs_line,
r_currency,
@ -101,12 +110,15 @@ SELECT
cost_loc,
null::numeric,
null::numeric,
------------status info-----------------------
calc_status,
flag,
order_date,
order_season,
request_date,
request_season,
null::date promise_date,
null::int promise_season,
ship_date,
ship_season,
version,
@ -115,37 +127,38 @@ SELECT
FROM
rlarp.osm_pool
WHERE
version <> 'actuals'
version <> 'actuals';
-------need to set item master values before other things-----------
UPDATE
RLARP.OSMFS_DEV O
RLARP.osmfs O
SET
STYC = M.STLC
,COLC = M.COLC
,COLGRP = M.COLGRP
,COLTIER = M.COLTIER
,COLSTAT = M.COLSTAT
,SIZC = M.SIZC
,PCKG = M.PACKAGE
,KIT = M.KIT
,BRND = M.BRANDING
,MAJG = M.MAJG
,MING = M.MING
,MAJS = M.MAJS
,MINS = M.MINS
,GLDC = M.GLCD
,GLEC = M.GLEC
,HARM = M.HARM
,CLSS = M.CLSS
,BRAND = M.BRAND
,ASSC = M.ASSC
,LBS = CASE M.NWUN WHEN 'KG' THEN 2.2046 ELSE 1 END*M.NWHT
,UNTI = M.UNTI
stlc = m.stlc
,colc = m.colc
,colgrp = m.colgrp
,coltier = m.coltier
,colstat = m.colstat
,sizc = m.sizc
,uomp = m.uomp
,suffix = m.suffix
,accs_ps = m.accs_ps
,brnd = m.branding
,majg = m.majg
,ming = m.ming
,majs = m.majs
,mins = m.mins
,gldc = m.glcd
,glec = m.glec
,harm = m.harm
,clss = m.clss
,brand = m.brand
,assc = m.assc
,lbs = CASE m.nwun WHEN 'kg' THEN 2.2046 ELSE 1 END*m.nwht
,unti = m.unti
FROM
RLARP.ITEMM M
"CMS.CUSLG".itemm m
WHERE
M.ITEM = O.PART;
m.item = o.part;
WITH
@ -154,7 +167,7 @@ plist AS (
part
,plnt
FROM
rlarp.osmfS_dev
rlarp.osmfs
)
,clist AS (
SELECT
@ -174,7 +187,7 @@ plist AS (
AND ir.y0plnt = p.plnt
)
UPDATE
rlarp.osmfs_dev o
rlarp.osmfs o
SET
fb_cst_loc_cur = c.stdcost * o.fb_qty
FROM
@ -186,7 +199,7 @@ WHERE
----------------------------SET BILL-TO REP------------------------------------
UPDATE
RLARP.OSMFS_DEV S
RLARP.osmfs S
SET
BILL_REP = C.BVSALM
,BILL_CLASS = C.BVCLAS
@ -213,7 +226,7 @@ WHERE
----------------------------SET SHIP-TO REP------------------------------------
UPDATE
RLARP.OSMFS_DEV S
RLARP.osmfs S
SET
SHIP_REP = C.BVSALM
,SHIP_CLASS = C.BVCLAS
@ -226,18 +239,18 @@ FROM
WHERE
C.BVCUST = S.SHIP_CUST
AND (
COALESCE(S.SHIP_REP,'') <> C.BVSALM
OR COALESCE(S.SHIP_CLASS,'') <> C.BVCLAS
OR COALESCE(S.SHIP_TERR,'') <> C.BVTERR
OR COALESCE(dest_CTRY,'') <> C.bvctry
OR COALESCE(dest_prov,'') <> C.bvprcd
OR COALESCE(dest_post,'') <> C.bvpost
COALESCE(s.ship_rep,'') <> c.bvsalm
OR COALESCE(s.ship_class,'') <> c.bvclas
OR COALESCE(s.ship_terr,'') <> c.bvterr
OR COALESCE(dest_ctry,'') <> c.bvctry
OR COALESCE(dest_prov,'') <> c.bvprcd
OR COALESCE(dest_post,'') <> c.bvpost
);
----------------------------SET BILLTO GROUP------------------------------------
UPDATE
RLARP.OSMFS_DEV O
RLARP.osmfs O
SET
ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM
@ -251,7 +264,7 @@ WHERE
----------------------------SET SHIPTO GROUP------------------------------------
UPDATE
RLARP.OSMFS_DEV O
RLARP.osmfs O
SET
SHIPGRP = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM
@ -265,7 +278,7 @@ WHERE
UPDATE
rlarp.osmFS_dev
rlarp.osmfs
SET
CHAN = CASE SUBSTRING(BILL_CLASS,2,3)
--if the bill to class is ditsributor, then it's either warehouse or drop
@ -321,7 +334,7 @@ WHERE
UPDATE
RLARP.OSMFS_DEV S
RLARP.osmfs S
SET
DSM = CR.QUOTA_REP
FROM
@ -349,8 +362,8 @@ FROM
END QUOTA_REP
FROM
RLARP.OSMFS_DEV S
LEFT OUTER JOIN LGDAT.CUST ON
RLARP.osmfs S
LEFT OUTER JOIN lgdat.cust ON
BVCUST = BILL_CUST
LEFT OUTER JOIN lgpgm.usrcust cu ON
cu.cucust = s.bill_cust
@ -358,7 +371,7 @@ FROM
COALESCE(GLEC,'') IS NOT NULL
) CR
WHERE
CR.VERSION = S.VERSION
CR.VERSION = S.VERSION
AND CR.GLEC = COALESCE(S.GLEC,'')
AND CR.MING = COALESCE(S.MING,'')
AND CR.BILL_CUST = S.BILL_CUST
@ -369,7 +382,7 @@ WHERE
-------------------set fiscal period--------------------------------------
UPDATE
rlarp.osmfs_dev f
rlarp.osmfs f
SET
fspr = gld.fspr
FROM
@ -430,7 +443,7 @@ WHERE
--DELETE FROM rlarp.osmf_dev WHERE iter IN ('adj price','adj volume');
--INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev;
--INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmf;
COMMIT;
END