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