merge dev branch

This commit is contained in:
Paul Trowbridge 2021-04-07 10:17:12 -04:00
commit e4604a16f5
37 changed files with 3503 additions and 302 deletions

BIN
Master Template 1.6.xlsm Normal file

Binary file not shown.

View File

@ -0,0 +1,2 @@
DELETE FROM rlarp.osmf_dev WHERE dsm = 'PW';
INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev;

View File

@ -0,0 +1,163 @@
BEGIN;
DELETE FROM rlarp.osm_pool WHERE quota_rep_descr = 'PW';
INSERT INTO rlarp.osm_pool
WITH
repc AS (
SELECT
LTRIM(RTRIM(C.A9)) RCODE
,C.A30 REPP
,COALESCE(Q.DIR,'Other') DIRECTOR
FROM
LGDAT.CODE C
LEFT OUTER JOIN RLARP.QRH Q ON
Q.QR = LTRIM(RTRIM(C.A9))
WHERE
C.A2 = 'MM'
)
,SEG AS (
SELECT
GLEC
,SEGM
FROM
(
VALUES
('1CU','Retail'),
('1GR','Greenhouse'),
('1NU','Nursery'),
('1RE','Retail'),
('2WI','Greenhouse'),
('3BM','Other'),
('3CO','Other'),
('3PE','Other'),
('3PP','Other'),
('4CO','Other'),
('4RA','Other'),
('9MI','Other'),
('9SA','Other'),
('9TO','Other')
) X(GLEC, SEGM)
)
----------------------------------------------------sales major codes----------------------------------------------------------------------------------------------------------------------------------
,SJ AS (
SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = ''
)
----------------------------------------------------sales minor codes----------------------------------------------------------------------------------------------------------------------------------
,SI AS (
SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> ''
)
SELECT
fspr
,plnt
,promo
,terms
,bill_cust||' - '||bc.bvname bill_cust_descr
,ship_cust||' - '||sc.bvname ship_cust_descr
,dsm
,coalesce(repc.repp,dsm) quota_rep_descr
,repc.director
,account billto_group
,shipgrp shipto_group
,chan
,chansub
,CASE seg.segm
WHEN 'Retail' THEN
CASE o.bill_class
WHEN 'RMAS' THEN 'MASS'
WHEN 'RNAT' THEN 'NATIONAL'
ELSE 'OTHER'
END
ELSE o.chan
END chan_retail
,part
,part||coalesce(' - '||i.descr,'') part_descr
,stlcd part_group
,brnd branding
,o.majg||' - '||i.majgd majg_descr
,o.ming||' - '||i.mingd ming_descr
,o.majs||' - '||i.majsd majs_descr
,o.mins||' - '||i.minsd mins_descr
,seg.segm
,CASE WHEN o.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
,fs_line
,r_currency
,r_rate
,c_currency
,c_rate
,fb_qty units
,fb_val_loc value_loc
,fb_val_loc * r_rate value_usd
,fb_cst_loc_cur cost_loc
,fb_cst_loc_cur * c_rate cost_usd
,calc_status
,flag
,o.odate order_date
,to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month
,oseas order_season
,rdate request_date
,to_char(CASE WHEN extract(month FROM o.rdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.rdate),'FM00')||' - '||to_char(o.rdate,'TMMon') request_month
,rseas request_season
,sdate ship_date
,to_char(CASE WHEN extract(month FROM o.sdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.sdate),'FM00')||' - '||to_char(o.sdate,'TMMon') ship_month
,sseas ship_season
,version
,iter
,logload.id logid
,logload.doc->>'tag' tag
,logload.doc->>'message' "comment"
,logload.doc->>'type' module
FROM
rlarp.osmfs_dev o
INNER JOIN rlarp.osm_log logload ON
logload.id = 1
LEFT OUTER JOIN lgdat.cust bc ON
bc.bvcust = o.bill_cust
LEFT OUTER JOIN lgdat.cust sc ON
sc.bvcust = o.ship_cust
LEFT OUTER JOIN repc ON
repc.rcode = o.dsm
/*
LEFT OUTER JOIN lgdat.majg ON
bqgrp = o.majg
LEFT OUTER JOIN lgdat.mmgp ON
brmgrp = o.ming
AND BRGRP = o.majg
LEFT OUTER JOIN si ON
si.bsmjcd = o.majs
AND si.bsmncd = o.mins
LEFT OUTER JOIN sj ON
sj.bsmjcd = o.majs
*/
LEFT OUTER JOIN seg ON
seg.glec = o.glec
LEFT OUTER JOIN rlarp.itemm i ON
i.item = o.part
WHERE
dsm = 'PW';
/*
SELECT
"version",
iter,
order_season,
order_month ,
sum(value_usd ) value_usd
FROM
RLARP.osm_pool op
WHERE
--oseas = 2020
fs_line = '41010'
--AND odate < '2020-04-01'
AND CALC_STATUS <> 'CANCELED'
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
GROUP BY
"version",
iter,
order_season,
order_month;
*/
--ROLLBACK;
commit;

View File

@ -0,0 +1,43 @@
BEGIN;
WITH
plist AS (
SELECT DISTINCT
part
,plnt
FROM
rlarp.osmfs_dev
-----prevent a list of fake parts
INNER JOIN lgdat.stka ON
v6part = part
AND v6plnt = plnt
)
,clist AS (
SELECT
p.part
,p.plnt
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs) stdcost
FROM
plist p
LEFT OUTER JOIN lgdat.icstm im ON
im.cgpart = p.part
AND im.cgplnt = p.plnt
LEFT OUTER JOIN lgdat.icstp ip ON
ip.chpart = p.part
AND ip.chplnt = p.plnt
LEFT OUTER JOIN lgdat.icstr ir ON
ir.y0part = p.part
AND ir.y0plnt = p.plnt
)
UPDATE
rlarp.osmfs_dev o
SET
fb_cst_loc_cur = c.stdcost * o.fb_qty
FROM
clist c
WHERE
c.part = o.part
AND c.plnt = o.plnt;
--AND version = 'b21';
commit;

View File

@ -0,0 +1,209 @@
----------------------------SET BILL-TO REP------------------------------------
UPDATE
RLARP.OSMFS_DEV S
SET
BILL_REP = C.BVSALM
,BILL_CLASS = C.BVCLAS
,BILL_TERR = C.BVTERR
,BILL_CTRY = C.bvctry
,bill_prov = C.bvprcd
,bill_post = C.bvpost
,remit_to = c.bvcomp
,ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM
LGDAT.CUST C
WHERE
C.BVCUST = S.BILL_CUST
AND (
COALESCE(S.BILL_REP,'') <> C.BVSALM
OR COALESCE(S.BILL_CLASS,'') <> C.BVCLAS
OR COALESCE(S.BILL_TERR,'') <> C.BVTERR
OR COALESCE(BILL_CTRY,'') <> C.bvctry
OR COALESCE(bill_prov,'') <> C.bvprcd
OR COALESCE(bill_post,'') <> C.bvpost
OR COALESCE(remit_to,'') <> c.bvcomp::text
);
----------------------------SET SHIP-TO REP------------------------------------
UPDATE
RLARP.OSMFS_DEV S
SET
SHIP_REP = C.BVSALM
,SHIP_CLASS = C.BVCLAS
,SHIP_TERR = C.BVTERR
,dest_CTRY = C.bvctry
,dest_prov = C.bvprcd
,dest_post = C.bvpost
FROM
LGDAT.CUST C
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
);
----------------------------SET BILLTO GROUP------------------------------------
UPDATE
RLARP.OSMFS_DEV O
SET
ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM
LGDAT.CUST C
WHERE
C.BVCUST = O.BILL_CUST
AND coalesce(account,'') <> CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END;
----------------------------SET SHIPTO GROUP------------------------------------
UPDATE
RLARP.OSMFS_DEV O
SET
SHIPGRP = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM
LGDAT.CUST C
WHERE
C.BVCUST = O.SHIP_CUST
AND CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END <> COALESCE(O.SHIPGRP,'');
---------------------------SET CHANNEL-----------------------------------------
UPDATE
rlarp.osmfs_dev
SET
CHAN = CASE SUBSTRING(BILL_CLASS,2,3)
--if the bill to class is ditsributor, then it's either warehouse or drop
WHEN 'DIS' THEN
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
CASE SUBSTRING(SHIP_CLASS,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE 'DRP'
END
--CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END
--everything else does not involve a distributor and is considered direct
ELSE 'DIR'
END,
CHANSUB = CASE SUBSTRING(BILL_CLASS,2,3)
WHEN 'DIS' THEN
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
CASE SUBSTRING(SHIP_CLASS,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
END
WHEN 'MAS' THEN 'RMN'
WHEN 'NAT' THEN 'RMN'
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
END
WHERE
COALESCE(CHAN,'') <> CASE SUBSTRING(BILL_CLASS,2,3)
--if the bill to class is ditsributor, then it's either warehouse or drop
WHEN 'DIS' THEN
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
CASE SUBSTRING(SHIP_CLASS,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE 'DRP'
END
--CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END
--everything else does not involve a distributor and is considered direct
ELSE 'DIR'
END
OR
COALESCE(CHANSUB,'') <> CASE SUBSTRING(BILL_CLASS,2,3)
WHEN 'DIS' THEN
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
CASE SUBSTRING(SHIP_CLASS,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
END
WHEN 'MAS' THEN 'RMN'
WHEN 'NAT' THEN 'RMN'
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
END;
---------------------------SET QUOTA REP---------------------------------------
UPDATE
RLARP.OSMFS_DEV S
SET
DSM = CR.QUOTA_REP
FROM
(
SELECT DISTINCT
VERSION,
COALESCE(GLEC,'') GLEC,
COALESCE(MING,'') MING,
BILL_CUST,
SHIP_CUST,
------------quota rep column--------------
RTRIM(
--retail items go to currep, or if null go to 90005
CASE WHEN S.GLEC IN ('1RE','1CU') THEN
CASE WHEN BVCTRY = 'CAN' THEN
--Rachel Bowman
'50300'
ELSE
--select customers go to select reps
CASE ACCOUNT
------Alecia Latini-------------------------------
WHEN 'DO IT BEST' THEN '90006'
WHEN 'ACE HARDWARE' THEN '90006'
WHEN 'ALDI' THEN '90006'
WHEN 'AMAZON.COM' THEN '90006'
WHEN 'GARDEN RIDGE CORP' THEN '90006' --AKA "At Home"
WHEN 'TRUE VALUE' THEN '90006'
WHEN 'WAYFAIR' THEN '90006'
WHEN 'GRIFFIN' THEN '90006'
WHEN 'WAL-MART' THEN '90006'
------Tony Landino--------------------------------
WHEN 'THE HOME DEPOT' THEN '50802'
WHEN 'FRED MEYER' THEN '50802'
WHEN 'MENARDS' THEN '50802'
WHEN 'KROGER' THEN '50802'
WHEN 'OCEAN STATE JOBBERS' THEN '50802'
WHEN 'AURORA WHOLESALE' THEN '50802'
WHEN 'LEON KORRAL' THEN '50802'
--all other retail goes to Doran Marable-----------
ELSE '50200'
END
END
--minor group b52 goes to dedicated rep
ELSE
CASE WHEN MING = 'B52' THEN
'PW'
--gdir, ndir go to bill-to rep
ELSE
CASE WHEN BILL_CLASS IN ('GDIR','NDIR') THEN
BILL_REP
ELSE
SHIP_REP
END
END
END
) QUOTA_REP
FROM
RLARP.OSMFS_DEV S
LEFT OUTER JOIN LGDAT.CUST ON
BVCUST = BILL_CUST
WHERE
COALESCE(GLEC,'') IS NOT NULL
) CR
WHERE
CR.VERSION = S.VERSION
AND CR.GLEC = COALESCE(S.GLEC,'')
AND CR.MING = COALESCE(S.MING,'')
AND CR.BILL_CUST = S.BILL_CUST
AND CR.SHIP_CUST = S.SHIP_CUST
AND COALESCE(S.DSM,'') <> CR.QUOTA_REP;

View File

@ -0,0 +1,30 @@
UPDATE
rlarp.osmfs_dev f
SET
fspr = gld.fspr
FROM
(
SELECT
N1COMP COMP
,N1CCYY FSYRq
,KPMAXP PERDS
,N1FSPP PERD
,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT
,N1ED01 EDAT
,to_char(N1ED01,'yymm') CAPR
,N1ED01 - N1SD01 +1 NDAYS
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
FROM
LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON
KPCOMP = N1COMP AND
KPCCYY = N1CCYY
WHERE
N1COMP = 93
--AND DIGITS(N1FSYP) = '1901'
) gld
WHERE
f.sdate BETWEEN gld.sdat AND gld.edat
AND coalesce(f.fspr,'') <> gld.fspr;

View File

@ -0,0 +1,9 @@
------------update fx rates-----------------------------------------------------------------
UPDATE rlarp.osmf_dev SET r_rate = .7518 WHERE r_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osmf_dev SET r_rate = 1.0000 WHERE r_currency = 'US' AND version = 'b21';
UPDATE rlarp.osmf_dev SET c_rate = .7518 WHERE c_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osmf_dev SET c_rate = 1.0000 WHERE c_currency = 'US' AND version = 'b21';
UPDATE rlarp.osm_pool SET r_rate = .7518 WHERE r_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osm_pool SET value_usd = value_loc * r_rate WHERE r_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osm_pool SET c_rate = .7518 WHERE c_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osm_pool SET cost_usd = cost_loc * c_rate WHERE c_currency = 'CA' AND version = 'b21';

View File

@ -0,0 +1,27 @@
UPDATE
RLARP.OSMFS_DEV O
SET
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
FROM
RLARP.ITEMM M
WHERE
M.ITEM = O.PART

View File

@ -0,0 +1,299 @@
--\timing
truncate table rlarp.osmfs_dev;
WITH
gld AS (
SELECT
N1COMP COMP
,N1CCYY FSYR
,KPMAXP PERDS
,N1FSPP PERD
,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT
,N1ED01 EDAT
,to_char(N1ED01,'yymm') CAPR
,N1ED01 - N1SD01 +1 NDAYS
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
FROM
LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON
KPCOMP = N1COMP AND
KPCCYY = N1CCYY
WHERE
N1COMP = 93
--AND DIGITS(N1FSYP) = '1901'
)
--SELECT * FROM gld
,baseline AS (
SELECT
-----------documents-------------
null::int "ddord#"
,null::int "dditm#"
,null::int "fgbol#"
,null::int "fgent#"
,null::int "diinv#"
,null::int "dilin#"
,null::int quoten
,null::int quotel
----------dates/status------------------
,o.odate dcodat
,o.rdate ddqdat
,null::date dcmdat
,null::date fesdat
,greatest(least(o.sdate,gld.edat),gld.sdat) dhidat
,null::text fesind
,null::text dhpost
,o.fspr
-----------measures--------------------
,null::numeric ddqtoi
,null::numeric ddqtsi
,null::numeric fgqshp
,null::numeric diqtsh
,null::numeric diext
,null::numeric ditdis
,null::jsonb discj
,null::text dhincr
,plnt
,COALESCE(o.promo,'') promo
,null::text return_reas
,o.terms
,null::text custpo
,null::text remit_to
,null::text bill_class
,o.bill_cust
,null::text bill_rep
,null::text bill_terr
,null::text ship_class
,ship_cust
,null::text ship_rep
,null::text ship_terr
,null::text dsm
,null::text account
,null::text shipgrp
,null::text geo
,null::text chan
,null::text chansub
,null::text orig_ctry
,null::text orig_prov
,null::text orig_post
,null::text bill_ctry
,null::text bill_prov
,null::text bill_post
,null::text dest_ctry
,null::text dest_prov
,null::text dest_post
,o.part
,null::text styc
,null::text colc
,null::text colgrp
,null::text coltier
,null::text colstat
,null::text sizc
,null::text pckg
,null::text kit
,null::text brnd
,null::text majg
,null::text ming
,null::text majs
,null::text mins
,null::text gldco
,null::text gldc
,null::text glec
,null::text harm
,null::text clss
,null::text brand
,null::text assc
,null::text ddunit
,null::text unti
,null::numeric lbs
,null::numeric plt
,null::text plcd
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,sum(o.fb_qty) fb_qty
,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_dis) fb_val_loc_dis
,sum(o.fb_val_loc_qt) fb_val_loc_qt
,sum(o.fb_val_loc_pl) fb_val_loc_pl
,sum(o.fb_val_loc_tar) fb_val_loc_tar
,sum(o.fb_cst_loc) fb_cst_loc
,sum(o.fb_cst_loc_cur) fb_cst_loc_cur
,sum(o.fb_cst_loc_fut) fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate
,o.oseas
,o.rdate
,o.rseas
-----when null, greatest/least is just going to act like coalesce
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
,ss.ssyr sseas
,'15mo' "version"
,'actuals' iter
FROM
rlarp.osm_dev o
--snap the ship dates of the historic fiscal period
LEFT OUTER JOIN gld ON
gld.fspr = o.fspr
--get the shipping season for open orders based on the snapped date
LEFT OUTER JOIN gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
WHERE
(
--base period orders booked....
o.odate BETWEEN '2019-06-01' AND '2020-05-31'
--...or any open orders currently booked before cutoff....
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-05-31')
OR o.fspr BETWEEN '2001' AND '2012'
)
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
AND version = 'ACTUALS'
AND dsm = 'PW'
GROUP BY
o.fspr
,plnt
,COALESCE(o.promo,'')
,o.terms
,o.bill_cust
,ship_cust
,o.part
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.calc_status
,o.flag
,o.odate
,o.oseas
,o.rdate
,o.rseas
,greatest(least(o.sdate,gld.edat),gld.sdat)
,ss.ssyr
)
,incr AS (
SELECT
o."ddord#"
,o."dditm#"
,o."fgbol#"
,o."fgent#"
,o."diinv#"
,o."dilin#"
,o.quoten
,o.quotel
,o.dcodat + interval '1 year' --incremented
,o.ddqdat + interval '1 year' --incremented
,o.dcmdat
,o.fesdat
,o.dhidat + interval '1 year' --incremented
,o.fesind
,o.dhpost
,gld.fspr --incremented
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,o.diext
,o.ditdis
,o.discj
,o.dhincr
,o.plnt
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.remit_to
,o.bill_class
,o.bill_cust
,o.bill_rep
,o.bill_terr
,o.ship_class
,o.ship_cust
,o.ship_rep
,o.ship_terr
,o.dsm
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.chansub
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.bill_ctry
,o.bill_prov
,o.bill_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.styc
,o.colc
,o.colgrp
,o.coltier
,o.colstat
,o.sizc
,o.pckg
,o.kit
,o.brnd
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldco
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.ddunit
,o.unti
,o.lbs
,o.plt
,o.plcd
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.fb_qty
,o.fb_val_loc
,o.fb_val_loc_dis
,o.fb_val_loc_qt
,o.fb_val_loc_pl
,o.fb_val_loc_tar
,o.fb_cst_loc
,o.fb_cst_loc_cur
,o.fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate + interval '1 year' --incremented
,o.oseas + 1 --incremented
,o.rdate + interval '1 year' --incremented
,o.rseas + 1 --incremented
,o.sdate + interval '1 year' --incremented
,o.sseas + 1 --incremented
,'b21' "version"
,'copy' iter
FROM
baseline o
LEFT OUTER JOIN gld ON
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
)
INSERT INTO rlarp.osmfs_dev
SELECT * FROM incr
UNION ALL
SELECT * FROM baseline;
---identify short ships: causes disconnect with actual sales-------------------------------------------------------------------
--UPDATE rlarp.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER';
---identify goofy ship dates: causes disconnect with sales when splicing in a forecast that has this problem-------------------
--UPDATE rlarp.osmfs SET iter = 'bad date' WHERE adj_shipdate < adj_orderdate;

View File

@ -54,7 +54,7 @@ gld AS (
,null::numeric ditdis
,null::jsonb discj
,null::text dhincr
,plnt
,o.plnt
,COALESCE(o.promo,'') promo
,null::text return_reas
,o.terms
@ -65,10 +65,10 @@ gld AS (
,null::text bill_rep
,null::text bill_terr
,null::text ship_class
,ship_cust
,o.ship_cust
,null::text ship_rep
,null::text ship_terr
,null::text dsm
,o.dsm
,null::text account
,null::text shipgrp
,null::text geo
@ -111,9 +111,9 @@ gld AS (
,null::text plcd
,o.fs_line
,o.r_currency
,null::numeric r_rate
,o.r_rate
,o.c_currency
,null::numeric c_rate
,o.c_rate
,sum(o.fb_qty) fb_qty
,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_dis) fb_val_loc_dis
@ -145,26 +145,31 @@ gld AS (
WHERE
(
--base period orders booked....
o.odate BETWEEN '2019-06-01' AND '2020-02-29'
o.odate BETWEEN '2020-06-01' AND '2021-04-04'
--...or any open orders currently booked before cutoff....
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-03-01')
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2021-04-04')
--...or anything that shipped in that period
OR o.fspr BETWEEN '2001' AND '2009'
OR o.fspr BETWEEN '2101' AND '2110'
)
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
---exclude integrated quotes----
AND version = 'ACTUALS'
GROUP BY
o.fspr
,plnt
,o.plnt
,COALESCE(o.promo,'')
,o.terms
,o.bill_cust
,ship_cust
,o.ship_cust
,o.dsm
,o.part
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.calc_status
,o.flag
,o.odate
@ -216,7 +221,7 @@ gld AS (
,ship_cust
,null::text ship_rep
,null::text ship_terr
,null::text dsm
,o.dsm
,null::text account
,null::text shipgrp
,null::text geo
@ -259,9 +264,9 @@ gld AS (
,null::text plcd
,o.fs_line
,o.r_currency
,null::numeric r_rate
,o.r_rate
,o.c_currency
,null::numeric c_rate
,o.c_rate
,sum(o.fb_qty) fb_qty
,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_dis) fb_val_loc_dis
@ -289,22 +294,25 @@ gld AS (
LEFT OUTER JOIN gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
WHERE
o.odate BETWEEN '2019-03-01' AND '2019-05-31'
o.odate BETWEEN '2020-04-05' AND '2020-05-31'
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
------exclude actuals for now and use forecast to get the plug for the rest of the year
AND false
AND version = 'ACTUALS'
GROUP BY
o.fspr
,plnt
,COALESCE(o.promo,'')
,o.terms
,o.bill_cust
,ship_cust
,o.ship_cust
,o.dsm
,o.part
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.calc_status
,o.flag
,o.odate
@ -429,9 +437,11 @@ gld AS (
LEFT OUTER JOIN gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
WHERE
o.odate BETWEEN '2020-03-01' AND '2020-05-31'
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
false
--o.odate BETWEEN '2020-03-01' AND '2020-05-31'
--AND fs_line = '41010'
--AND calc_status <> 'CANCELED'
------dont pull forecast for a baseline this time around--
GROUP BY
o.fspr
,plnt
@ -555,14 +565,14 @@ SELECT
,o.rseas + 1 --incremented
,o.sdate + interval '1 year' --incremented
,o.sseas + 1 --incremented
,'b21' "version"
,'b22' "version"
,'copy' iter
FROM
baseline o
LEFT OUTER JOIN gld ON
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
WHERE
o.odate + interval '1 year' >= '2020-06-01'
o.odate + interval '1 year' >= '2021-06-01'
)
INSERT INTO rlarp.osmf_dev
SELECT * FROM incr

View File

@ -1,10 +1,10 @@
SELECT
order_season
,sum(value_usd) value_usd
,sum(coalesce(value_usd,0)) value_usd
FROM
rlarp.osm_pool
WHERE
order_season = 2021
order_season = 2022
--AND version = 'b21'
GROUP BY
order_season
@ -15,8 +15,8 @@ SELECT
FROM
rlarp.osmf_dev
WHERE
oseas = 2021
AND version = 'b21'
oseas = 2022
AND version = 'b22'
GROUP BY
oseas

View File

@ -286,85 +286,88 @@ WHERE
---------------------------SET QUOTA REP---------------------------------------
UPDATE
RLARP.OSMFS_DEV S
rlarp.osmfs_dev s
SET
DSM = CR.QUOTA_REP
dsm = cr.quota_rep
FROM
(
SELECT DISTINCT
VERSION,
COALESCE(GLEC,'') GLEC,
COALESCE(MING,'') MING,
MING,
BILL_CUST,
SHIP_CUST,
------------quota rep column--------------
RTRIM(
--retail items go to currep, or if null go to 90005
CASE WHEN S.GLEC IN ('1RE','1CU') THEN
CASE WHEN BVCTRY = 'CAN' THEN
--Rachel Bowman
'50300'
ELSE
--select customers go to select reps
CASE ACCOUNT
------Alecia Latini-------------------------------
WHEN 'DO IT BEST' THEN '90006'
WHEN 'ACE HARDWARE' THEN '90006'
WHEN 'ALDI' THEN '90006'
WHEN 'AMAZON.COM' THEN '90006'
WHEN 'GARDEN RIDGE CORP' THEN '90006' --AKA "At Home"
WHEN 'TRUE VALUE' THEN '90006'
WHEN 'WAYFAIR' THEN '90006'
WHEN 'GRIFFIN' THEN '90006'
WHEN 'WAL-MART' THEN '90006'
------Tony Landino--------------------------------
WHEN 'THE HOME DEPOT' THEN '50802'
WHEN 'FRED MEYER' THEN '50802'
WHEN 'MENARDS' THEN '50802'
WHEN 'KROGER' THEN '50802'
WHEN 'OCEAN STATE JOBBERS' THEN '50802'
WHEN 'AURORA WHOLESALE' THEN '50802'
WHEN 'LEON KORRAL' THEN '50802'
--all other retail goes to Doran Marable-----------
ELSE '50200'
END
END
--minor group b52 goes to dedicated rep
CASE WHEN COALESCE(ming,'') = 'B52' THEN 'PW' ELSE
--if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available
CASE WHEN COALESCE(glec,'') = '1RE' AND COALESCE(cu.currep,'') <> '' THEN
cu.currep
--default logic
ELSE
CASE WHEN MING = 'B52' THEN
'PW'
--gdir, ndir go to bill-to rep
ELSE
CASE WHEN BILL_CLASS IN ('GDIR','NDIR') THEN
BILL_REP
CASE SUBSTR(bill_class,2,3)
WHEN 'DIS' THEN
ship_rep
ELSE
SHIP_REP
END
bill_rep
END
END
) QUOTA_REP
END QUOTA_REP
FROM
RLARP.OSMFS_DEV S
LEFT OUTER JOIN LGDAT.CUST ON
BVCUST = BILL_CUST
rlarp.osmfs_dev s
LEFT OUTER JOIN lgdat.cust ON
bvcust = bill_cust
LEFT OUTER JOIN lgpgm.usrcust cu ON
cu.cucust = s.bill_cust
WHERE
COALESCE(GLEC,'') IS NOT NULL
version = 'ACTUALS'
) CR
WHERE
CR.VERSION = S.VERSION
AND CR.GLEC = COALESCE(S.GLEC,'')
AND CR.MING = COALESCE(S.MING,'')
AND CR.MING = S.MING
AND CR.BILL_CUST = S.BILL_CUST
AND CR.SHIP_CUST = S.SHIP_CUST
AND COALESCE(S.DSM,'') <> CR.QUOTA_REP;
-------------------set fiscal period--------------------------------------
UPDATE
rlarp.osmfs_dev f
SET
fspr = gld.fspr
FROM
(
SELECT
N1COMP COMP
,N1CCYY FSYRq
,KPMAXP PERDS
,N1FSPP PERD
,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT
,N1ED01 EDAT
,to_char(N1ED01,'yymm') CAPR
,N1ED01 - N1SD01 +1 NDAYS
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
FROM
LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON
KPCOMP = N1COMP AND
KPCCYY = N1CCYY
WHERE
N1COMP = 93
--AND DIGITS(N1FSYP) = '1901'
) gld
WHERE
f.sdate BETWEEN gld.sdat AND gld.edat
AND coalesce(f.fspr,'') <> gld.fspr;
UPDATE
rlarp.osmfS_dev
SET
r_rate = .7518
r_rate = .7900
WHERE
r_currency = 'CA';
@ -378,7 +381,7 @@ WHERE
UPDATE
rlarp.osmfS_dev
SET
c_rate = .7518
c_rate = .7900
WHERE
c_currency = 'CA';

428
build/convert_pool_all.sql Normal file
View File

@ -0,0 +1,428 @@
BEGIN;
DELETE FROM rlarp.osmfs_dev;
INSERT INTO
rlarp.osmfs_dev
SELECT
null::int4,
null::int4,
null::int4,
null::int4,
null::int4,
null::int4,
null::int4,
null::int4,
order_date,
request_date,
null::date,
null::date,
ship_date,
null::text,
null::text,
fspr,
null::numeric,
null::numeric,
null::numeric,
null::numeric,
null::numeric,
null::numeric,
null::jsonb,
null::text,
plnt,
promo,
null::text,
terms,
null::text,
null::text,
null::text,
rtrim(substring(bill_cust_descr,1,8)),
null::text,
null::text,
null::text,
rtrim(substring(ship_cust_descr,1,8)),
null::text,
null::text,
dsm,
billto_group,
shipto_group,
null::text,
chan,
chan,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
part,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::text,
null::numeric,
null::numeric,
null::text,
fs_line,
r_currency,
r_rate,
c_currency,
c_rate,
units,
value_loc,
null::numeric,
null::numeric,
null::numeric,
null::numeric,
cost_loc,
null::numeric,
null::numeric,
calc_status,
flag,
order_date,
order_season,
request_date,
request_season,
ship_date,
ship_season,
version,
iter
FROM
rlarp.osm_pool;
WITH
plist AS (
SELECT DISTINCT
part
,plnt
FROM
rlarp.osmfS_dev
)
,clist AS (
SELECT
p.part
,p.plnt
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs) stdcost
FROM
plist p
LEFT OUTER JOIN lgdat.icstm im ON
im.cgpart = p.part
AND im.cgplnt = p.plnt
LEFT OUTER JOIN lgdat.icstp ip ON
ip.chpart = p.part
AND ip.chplnt = p.plnt
LEFT OUTER JOIN lgdat.icstr ir ON
ir.y0part = p.part
AND ir.y0plnt = p.plnt
)
UPDATE
rlarp.osmfs_dev o
SET
fb_cst_loc_cur = c.stdcost * o.fb_qty
FROM
clist c
WHERE
c.part = o.part
AND c.plnt = o.plnt;
----------------------------SET BILL-TO REP------------------------------------
UPDATE
RLARP.OSMFS_DEV S
SET
BILL_REP = C.BVSALM
,BILL_CLASS = C.BVCLAS
,BILL_TERR = C.BVTERR
,BILL_CTRY = C.bvctry
,bill_prov = C.bvprcd
,bill_post = C.bvpost
,remit_to = c.bvcomp
,ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM
LGDAT.CUST C
WHERE
C.BVCUST = S.BILL_CUST
AND (
COALESCE(S.BILL_REP,'') <> C.BVSALM
OR COALESCE(S.BILL_CLASS,'') <> C.BVCLAS
OR COALESCE(S.BILL_TERR,'') <> C.BVTERR
OR COALESCE(BILL_CTRY,'') <> C.bvctry
OR COALESCE(bill_prov,'') <> C.bvprcd
OR COALESCE(bill_post,'') <> C.bvpost
OR COALESCE(remit_to,'') <> c.bvcomp::text
);
----------------------------SET SHIP-TO REP------------------------------------
UPDATE
RLARP.OSMFS_DEV S
SET
SHIP_REP = C.BVSALM
,SHIP_CLASS = C.BVCLAS
,SHIP_TERR = C.BVTERR
,dest_CTRY = C.bvctry
,dest_prov = C.bvprcd
,dest_post = C.bvpost
FROM
LGDAT.CUST C
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
);
----------------------------SET BILLTO GROUP------------------------------------
UPDATE
RLARP.OSMFS_DEV O
SET
ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM
LGDAT.CUST C
WHERE
C.BVCUST = O.BILL_CUST
AND coalesce(account,'') <> CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END;
----------------------------SET SHIPTO GROUP------------------------------------
UPDATE
RLARP.OSMFS_DEV O
SET
SHIPGRP = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
FROM
LGDAT.CUST C
WHERE
C.BVCUST = O.SHIP_CUST
AND CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END <> COALESCE(O.SHIPGRP,'');
---------------------------SET CHANNEL-----------------------------------------
UPDATE
rlarp.osmFS_dev
SET
CHAN = CASE SUBSTRING(BILL_CLASS,2,3)
--if the bill to class is ditsributor, then it's either warehouse or drop
WHEN 'DIS' THEN
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
CASE SUBSTRING(SHIP_CLASS,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE 'DRP'
END
--CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END
--everything else does not involve a distributor and is considered direct
ELSE 'DIR'
END,
CHANSUB = CASE SUBSTRING(BILL_CLASS,2,3)
WHEN 'DIS' THEN
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
CASE SUBSTRING(SHIP_CLASS,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
END
WHEN 'MAS' THEN 'RMN'
WHEN 'NAT' THEN 'RMN'
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
END
WHERE
COALESCE(CHAN,'') <> CASE SUBSTRING(BILL_CLASS,2,3)
--if the bill to class is ditsributor, then it's either warehouse or drop
WHEN 'DIS' THEN
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
CASE SUBSTRING(SHIP_CLASS,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE 'DRP'
END
--CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END
--everything else does not involve a distributor and is considered direct
ELSE 'DIR'
END
OR
COALESCE(CHANSUB,'') <> CASE SUBSTRING(BILL_CLASS,2,3)
WHEN 'DIS' THEN
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
CASE SUBSTRING(SHIP_CLASS,2,3)
WHEN 'DIS' THEN 'WHS'
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
END
WHEN 'MAS' THEN 'RMN'
WHEN 'NAT' THEN 'RMN'
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
END;
---------------------------SET QUOTA REP---------------------------------------
UPDATE
RLARP.OSMFS_DEV S
SET
DSM = CR.QUOTA_REP
FROM
(
SELECT DISTINCT
VERSION,
COALESCE(GLEC,'') GLEC,
COALESCE(MING,'') MING,
BILL_CUST,
SHIP_CUST,
------------quota rep column--------------
CASE WHEN COALESCE(ming,'') = 'B52' THEN 'PW' ELSE
--if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available
CASE WHEN COALESCE(glec,'') = '1RE' AND COALESCE(cu.currep,'') <> '' THEN
cu.currep
--default logic
ELSE
CASE SUBSTR(bill_class,2,3)
WHEN 'DIS' THEN
ship_rep
ELSE
bill_rep
END
END
END QUOTA_REP
FROM
RLARP.OSMFS_DEV S
LEFT OUTER JOIN LGDAT.CUST ON
BVCUST = BILL_CUST
LEFT OUTER JOIN lgpgm.usrcust cu ON
cu.cucust = s.bill_cust
WHERE
COALESCE(GLEC,'') IS NOT NULL
) CR
WHERE
CR.VERSION = S.VERSION
AND CR.GLEC = COALESCE(S.GLEC,'')
AND CR.MING = COALESCE(S.MING,'')
AND CR.BILL_CUST = S.BILL_CUST
AND CR.SHIP_CUST = S.SHIP_CUST
AND COALESCE(S.DSM,'') <> CR.QUOTA_REP;
-------------------set fiscal period--------------------------------------
UPDATE
rlarp.osmfs_dev f
SET
fspr = gld.fspr
FROM
(
SELECT
N1COMP COMP
,N1CCYY FSYRq
,KPMAXP PERDS
,N1FSPP PERD
,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT
,N1ED01 EDAT
,to_char(N1ED01,'yymm') CAPR
,N1ED01 - N1SD01 +1 NDAYS
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
FROM
LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON
KPCOMP = N1COMP AND
KPCCYY = N1CCYY
WHERE
N1COMP = 93
--AND DIGITS(N1FSYP) = '1901'
) gld
WHERE
f.sdate BETWEEN gld.sdat AND gld.edat
AND coalesce(f.fspr,'') <> gld.fspr;
UPDATE
rlarp.osmfS_dev
SET
r_rate = .7900
WHERE
r_currency = 'CA';
UPDATE
rlarp.osmfS_dev
SET
r_rate = 1
WHERE
r_currency = 'US';
UPDATE
rlarp.osmfS_dev
SET
c_rate = .7900
WHERE
c_currency = 'CA';
UPDATE
rlarp.osmfS_dev
SET
c_rate = 1
WHERE
c_currency = 'US';
UPDATE
RLARP.OSMFS_DEV O
SET
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
FROM
RLARP.ITEMM M
WHERE
M.ITEM = O.PART;
--DELETE FROM rlarp.osmf_dev WHERE iter IN ('adj price','adj volume');
--INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev;
COMMIT;

View File

@ -1,3 +1,3 @@
DELETE FROM rlarp.osmf_dev WHERE odate < '2020-05-01';
INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2020-05-01';
DELETE FROM rlarp.osmf_dev WHERE odate < '2020-06-01';
INSERT INTO rlarp.osmf_dev SELECT * FROM rlarp.osmfs_dev WHERE odate < '2020-06-01';

View File

@ -1,6 +1,6 @@
BEGIN;
DELETE FROM rlarp.osm_pool WHERE order_date < '2020-05-01';
DELETE FROM rlarp.osm_pool WHERE order_date < '2020-06-01';
INSERT INTO rlarp.osm_pool
WITH
@ -134,7 +134,7 @@ FROM
LEFT OUTER JOIN rlarp.itemm i ON
i.item = o.part
WHERE
odate < '2020-05-01';
odate < '2020-06-01';
SELECT

View File

@ -145,11 +145,11 @@ gld AS (
WHERE
(
--base period orders booked....
o.odate <@ daterange('2019-06-01','2020-05-01')
o.odate <@ daterange('2019-06-01','2020-06-01')
--...or any open orders currently booked before cutoff....
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-05-01')
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-06-01')
--...or anything that shipped in that period
OR o.fspr BETWEEN '2001' AND '2011'
OR o.fspr BETWEEN '2001' AND '2012'
)
AND fs_line = '41010'
AND calc_status <> 'CANCELED'

View File

@ -0,0 +1,111 @@
WITH
targ AS (
SELECT * FROM (VALUES
('Pierre','Nursery','HYDROFARM',267888.16),
('Pierre','Nursery','ALTMAN PLANTS',71626.22),
('Pierre','Nursery','RS GROWERS SUPPLY',17154.0599999999),
('Pierre','Nursery','MID-AMERICAN GROWERS',51663.75),
('Pierre','Nursery','KAWAHARA NURSERY',48859.2),
('Baggetta','Nursery','PACIFIC NURSERY POTS',194412.359999999),
('Baggetta','Nursery','FARRAND',171375.300000001),
('Baggetta','Nursery','ALPHA FOLIAGE',59200.45),
('Baggetta','Nursery','HOLMBERG FARMS INC',52911.6),
('Baggetta','Nursery','MATSUDAS BY GREEN ACRES LLC',46723.47),
('Baggetta','Nursery','GREENLEAF NURSERY CO',24829.2),
('Baggetta','Nursery','GREENHOUSE MEGASTORE',22552.0399999999),
('Baggetta','Nursery','HICKORY HILL NURSERY',11072.7),
('Baggetta','Nursery','BRANTLEY NURSERIES',9762.47999999998),
('Baggetta','Nursery','DALLAS JOHNSON GREENHOUSE',8229.6),
('Baggetta','Nursery','BAMA GREEN',1165.5),
('Vander Deen','Greenhouse','HJS WHOLESALE LTD',310027.34),
('Vander Deen','Greenhouse','DEGOEYS NURSERY FLOWERS',26858.558706),
('Vander Deen','Greenhouse','DEVRY GREENHOUSES',10713.15),
('Vander Deen','Greenhouse','BIOFLORAL INC',9192.59000000001),
('Baggetta','Greenhouse','COSTA',600234.409999999),
('Baggetta','Greenhouse','SPARETIME SUPPLY',37966.8499999999),
('Baggetta','Greenhouse','ALPHA FOLIAGE',32183.66),
('Baggetta','Greenhouse','CASSCO',24248.74)
) x(director,glec,account,amount)
)
,sdate AS (
SELECT
targ.director
,targ.glec
,targ.account
,targ.amount
,p.order_season
,p.order_date
,p.ship_date
,p.ship_season
,p.part
,sum(p.value_usd) value_usd
FROM
rlarp.osm_pool p
INNER JOIN targ ON
p.billto_group = targ.account
AND p.segm = targ.glec
AND p.director = targ.director
WHERE
--order_season = 2021
ship_season = 2021
GROUP BY
targ.director
,targ.glec
,targ.account
,targ.amount
,p.order_season
,p.order_date
,p.ship_date
,p.ship_season
,p.part
)
,rev AS (
SELECT
director
,glec
,account
,amount
,order_season
,order_date
,part
,ship_date
,ship_season
,(ship_date + INTERVAL '1 year')::date rev_date
,gld.ssyr
,gld.fspr
,value_usd
,sum(value_usd) OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC, part) agg
,row_number() OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC) rn
,CASE WHEN sum(value_usd) OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC, part) >= amount THEN true ELSE false END flag
FROM
sdate
LEFT OUTER JOIN rlarp.gld gld ON
gld.drange @> (ship_date + INTERVAL '1 year')::date
ORDER BY
director
,glec
,account
,order_season
,amount
,ship_date DESC
)
,rnk AS (
SELECT
director,glec ,account
,min(rn) FILTER (WHERE flag = true) mflag
FROM
rev
GROUP BY
director,glec ,account ,account
)
,rejoin AS (
SELECT
rev.*
,rnk.mflag
,account || ' - '||to_char(amount,'FM999,999') goal
,rev.rn <= rnk.mflag AS include
FROM
rnk
NATURAL JOIN rev
)
SELECT * FROM rejoin

View File

@ -0,0 +1,260 @@
WITH
targ AS (
SELECT * FROM (VALUES
('Pierre','Nursery','HYDROFARM',267888.16),
('Pierre','Nursery','ALTMAN PLANTS',71626.22),
('Pierre','Nursery','RS GROWERS SUPPLY',17154.0599999999),
('Pierre','Nursery','MID-AMERICAN GROWERS',51663.75),
('Pierre','Nursery','KAWAHARA NURSERY',48859.2),
('Baggetta','Nursery','PACIFIC NURSERY POTS',194412.359999999),
('Baggetta','Nursery','FARRAND',171375.300000001),
('Baggetta','Nursery','ALPHA FOLIAGE',59200.45),
('Baggetta','Nursery','HOLMBERG FARMS INC',52911.6),
('Baggetta','Nursery','MATSUDAS BY GREEN ACRES LLC',46723.47),
('Baggetta','Nursery','GREENLEAF NURSERY CO',24829.2),
('Baggetta','Nursery','GREENHOUSE MEGASTORE',22552.0399999999),
('Baggetta','Nursery','HICKORY HILL NURSERY',11072.7),
('Baggetta','Nursery','BRANTLEY NURSERIES',9762.47999999998),
('Baggetta','Nursery','DALLAS JOHNSON GREENHOUSE',8229.6),
('Baggetta','Nursery','BAMA GREEN',1165.5),
('Vander Deen','Greenhouse','HJS WHOLESALE LTD',310027.34),
('Vander Deen','Greenhouse','DEGOEYS NURSERY FLOWERS',26858.558706),
('Vander Deen','Greenhouse','DEVRY GREENHOUSES',10713.15),
('Vander Deen','Greenhouse','BIOFLORAL INC',9192.59000000001),
('Baggetta','Greenhouse','COSTA',600234.409999999),
('Baggetta','Greenhouse','SPARETIME SUPPLY',37966.8499999999),
('Baggetta','Greenhouse','ALPHA FOLIAGE',32183.66),
('Baggetta','Greenhouse','CASSCO',24248.74)
) x(director,glec,account,amount)
)
,sdate AS (
SELECT
targ.director
,targ.glec
,targ.account
,targ.amount
,p.order_season
,p.order_date
,p.ship_date
,p.ship_season
,p.part
,sum(p.value_usd) value_usd
FROM
rlarp.osm_pool p
INNER JOIN targ ON
p.billto_group = targ.account
AND p.segm = targ.glec
AND p.director = targ.director
WHERE
--order_season = 2021
ship_season = 2021
GROUP BY
targ.director
,targ.glec
,targ.account
,targ.amount
,p.order_season
,p.order_date
,p.ship_date
,p.ship_season
,p.part
)
,rev AS (
SELECT
director
,glec
,account
,amount
,order_season
,order_date
,part
,ship_date
,ship_season
,(ship_date + INTERVAL '1 year')::date rev_date
,gld.ssyr
,gld.fspr
,value_usd
,sum(value_usd) OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC, part) agg
,row_number() OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC) rn
,CASE WHEN sum(value_usd) OVER (PARTITION BY director, glec, account, amount ORDER BY ship_date DESC, part) >= amount THEN true ELSE false END flag
FROM
sdate
LEFT OUTER JOIN rlarp.gld gld ON
gld.drange @> (ship_date + INTERVAL '1 year')::date
ORDER BY
director
,glec
,account
,order_season
,amount
,ship_date DESC
)
,rnk AS (
SELECT
director,glec ,account
,min(rn) FILTER (WHERE flag = true) mflag
FROM
rev
GROUP BY
director,glec ,account ,account
)
,rejoin AS (
SELECT
rev.*
,rnk.mflag
,account || ' - '||to_char(amount,'FM999,999') goal
,rev.rn <= rnk.mflag AS include
FROM
rnk
NATURAL JOIN rev
)
--SELECT * FROM rejoin
,logl AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
jsonb_build_object(
'stamp',current_timestamp
,'user','Trowbridge, Paul'
,'source','script'
,'tag','smooth sales'
,'message','need to carry more orders to reflect what happened in 2020'
,'type','smooth sales'
,'version','b21'
) doc RETURNING *
)
,remove AS (
SELECT
p.fspr
,p.plnt
,p.promo
,p.terms
,p.bill_cust_descr
,p.ship_cust_descr
,p.dsm
,p.quota_rep_descr
,p.director
,p.billto_group
,p.shipto_group
,p.chan
,p.chansub
,p.chan_retail
,p.part
,p.part_descr
,p.part_group
,p.branding
,p.majg_descr
,p.ming_descr
,p.majs_descr
,p.mins_descr
,p.segm
,p.substance
,p.fs_line
,p.r_currency
,p.r_rate
,p.c_currency
,p.c_rate
,-p.units units
,-p.value_loc value_loc
,-p.value_usd value_usd
,-p.cost_loc cost_loc
,-p.cost_usd cost_usd
,p.calc_status
,p.flag
,p.order_date
,p.order_month
,p.order_season
,p.request_date
,p.request_month
,p.request_season
,p.ship_date
,p.ship_month
,p.ship_season
,'b21' AS version
,'adj timing' iter
,logl.id logid
,logl.doc->>'tag' tag
,logl.doc->>'message' "comment"
,logl.doc->>'type' module
FROM
rlarp.osm_pool p
INNER JOIN rejoin r ON
r.account = p.billto_group
AND r.director = p.director
AND r.glec = p.segm
AND r.order_date = p.order_date
AND r.ship_date = p.ship_date
AND r.part = p.part
CROSS JOIN logl
WHERE
r.include
)
,repl AS (
SELECT
gld.fspr
,p.plnt
,p.promo
,p.terms
,p.bill_cust_descr
,p.ship_cust_descr
,p.dsm
,p.quota_rep_descr
,p.director
,p.billto_group
,p.shipto_group
,p.chan
,p.chansub
,p.chan_retail
,p.part
,p.part_descr
,p.part_group
,p.branding
,p.majg_descr
,p.ming_descr
,p.majs_descr
,p.mins_descr
,p.segm
,p.substance
,p.fs_line
,p.r_currency
,p.r_rate
,p.c_currency
,p.c_rate
,p.units units
,p.value_loc value_loc
,p.value_usd value_usd
,p.cost_loc cost_loc
,p.cost_usd cost_usd
,p.calc_status
,p.flag
,p.order_date
,p.order_month
,p.order_season
,p.request_date
,p.request_month
,p.request_season
,p.ship_date + INTERVAL '1 year'
,gld.sspr || ' - ' || to_char(p.ship_date,'Mon') ship_month
,gld.ssyr ship_season
,'b21' AS version
,'adj timing' iter
,logl.id logid
,logl.doc->>'tag' tag
,logl.doc->>'message' "comment"
,logl.doc->>'type' module
FROM
rlarp.osm_pool p
INNER JOIN rejoin r ON
r.account = p.billto_group
AND r.director = p.director
AND r.glec = p.segm
AND r.order_date = p.order_date
AND r.ship_date = p.ship_date
AND r.part = p.part
CROSS JOIN logl
LEFT OUTER JOIN rlarp.gld gld ON
gld.drange @> (p.ship_date + INTERVAL '1 year')::date
WHERE
r.include
)
INSERT INTO rlarp.osm_pool SELECT * FROM remove UNION ALL SELECT * FROM repl;

View File

@ -0,0 +1,8 @@
SELECT
ship_cust_descr, order_date, ship_date, sum(value_usd) sales
from
rlarp.osm_pool
where
ship_season = 2021
group by
ship_cust_descr, order_date, ship_date;

View File

@ -0,0 +1,79 @@
BEGIN;
with
logl AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
jsonb_build_object(
'stamp',current_timestamp
,'user','Trowbridge, Paul'
,'source','script'
,'tag','remove other'
,'message','remove budget for quota reps rolling into director Other'
,'type','remove other'
,'version','b21'
) doc RETURNING *
)
,targ as (
select
p.fspr
,p.plnt
,p.promo
,p.terms
,p.bill_cust_descr
,p.ship_cust_descr
,p.dsm
,p.quota_rep_descr
,p.director
,p.billto_group
,p.shipto_group
,p.chan
,p.chansub
,p.chan_retail
,p.part
,p.part_descr
,p.part_group
,p.branding
,p.majg_descr
,p.ming_descr
,p.majs_descr
,p.mins_descr
,p.segm
,p.substance
,p.fs_line
,p.r_currency
,p.r_rate
,p.c_currency
,p.c_rate
,-p.units units
,-p.value_loc value_loc
,-p.value_usd value_usd
,-p.cost_loc cost_loc
,-p.cost_usd cost_usd
,p.calc_status
,p.flag
,p.order_date
,p.order_month
,p.order_season
,p.request_date
,p.request_month
,p.request_season
,p.ship_date
,p.ship_month
,p.ship_season
,'b21' AS version
,'adj volume' iter
,logl.id logid
,logl.doc->>'tag' tag
,logl.doc->>'message' "comment"
,logl.doc->>'type' module
from
rlarp.osm_pool p
CROSS JOIN logl
where
director = 'Other'
and (order_season >= 2021 or ship_season >= 2021)
)
INSERT INTO rlarp.osm_pool SELECT * FROM targ;
COMMIT;

View File

@ -0,0 +1,357 @@
BEGIN;
WITH
move AS (
SELECT * FROM (VALUES
('HOME0004 - ALLIANCE INTERNATIONAL LLC',CAST('10/7/2019' AS DATE),CAST('6/1/2020' AS DATE),11322.85,CAST('7/2/2020' AS DATE)),
('CORS0004 - CORSOS PERENNIALS',CAST('10/23/2019' AS DATE),CAST('6/1/2020' AS DATE),30916.44,CAST('7/2/2020' AS DATE)),
('MONR0007 - MONROVIA - VISALIA CA',CAST('2/3/2020' AS DATE),CAST('6/1/2020' AS DATE),8409.6,CAST('7/2/2020' AS DATE)),
('BATT0001 - BATTLEFIELD FARMS',CAST('2/5/2020' AS DATE),CAST('6/1/2020' AS DATE),2285,CAST('7/2/2020' AS DATE)),
('BABI0001 - BABIKOW GREENHOUSES',CAST('2/7/2020' AS DATE),CAST('6/1/2020' AS DATE),9640.8,CAST('7/2/2020' AS DATE)),
('KALA0002 - KALAMAZOO FLOWER GROUP LLC',CAST('2/10/2020' AS DATE),CAST('6/1/2020' AS DATE),1005.4,CAST('7/2/2020' AS DATE)),
('HATR0001 - H.A. TREICHLER SONS',CAST('2/11/2020' AS DATE),CAST('6/1/2020' AS DATE),13425.44,CAST('7/2/2020' AS DATE)),
('KALA0002 - KALAMAZOO FLOWER GROUP LLC',CAST('3/13/2020' AS DATE),CAST('6/1/2020' AS DATE),2464,CAST('7/2/2020' AS DATE)),
('METR0002 - METROLINA GREENHOUSES',CAST('3/17/2020' AS DATE),CAST('6/1/2020' AS DATE),17619.12,CAST('7/2/2020' AS DATE)),
('JOHN0020 - JOHN BARONEDBA BARONE FARM',CAST('3/23/2020' AS DATE),CAST('6/1/2020' AS DATE),5571.85,CAST('7/2/2020' AS DATE)),
('JENS0002 - JENSEN DISTRIBUTION SERVICES',CAST('3/24/2020' AS DATE),CAST('6/1/2020' AS DATE),487.15,CAST('7/2/2020' AS DATE)),
('DIST0007 - TERIS SERVICES-PICK UP ONLY U',CAST('3/31/2020' AS DATE),CAST('6/1/2020' AS DATE),5318.78,CAST('7/2/2020' AS DATE)),
('DIST0007 - TERIS SERVICES-PICK UP ONLY U',CAST('4/7/2020' AS DATE),CAST('6/1/2020' AS DATE),400.28,CAST('7/2/2020' AS DATE)),
('BELA0001 - BELA FLOR NURSERIES',CAST('4/15/2020' AS DATE),CAST('6/1/2020' AS DATE),1219.71,CAST('7/2/2020' AS DATE)),
('JENS0002 - JENSEN DISTRIBUTION SERVICES',CAST('4/15/2020' AS DATE),CAST('6/1/2020' AS DATE),395.01,CAST('7/2/2020' AS DATE)),
('LLNU0003 - LL NURSERY SUPPLY INC WA',CAST('4/16/2020' AS DATE),CAST('6/1/2020' AS DATE),656.7,CAST('7/2/2020' AS DATE)),
('INTE0003 - GREENHOUSE MEGASTORE',CAST('4/23/2020' AS DATE),CAST('6/1/2020' AS DATE),283.06,CAST('7/2/2020' AS DATE)),
('CALC0004 - CAL COLOR GROWERS LLC',CAST('4/28/2020' AS DATE),CAST('6/1/2020' AS DATE),8273.25,CAST('7/2/2020' AS DATE)),
('BATT0001 - BATTLEFIELD FARMS',CAST('5/1/2020' AS DATE),CAST('6/1/2020' AS DATE),18919.26,CAST('7/2/2020' AS DATE)),
('LOWE3110 - LOWES OF MILTON CANADA # 3110',CAST('5/4/2020' AS DATE),CAST('6/1/2020' AS DATE),8901.3,CAST('7/2/2020' AS DATE)),
('SILV0007 - SILVERLEAF GHSE',CAST('5/6/2020' AS DATE),CAST('6/1/2020' AS DATE),19368.3,CAST('7/2/2020' AS DATE)),
('HOME0004 - ALLIANCE INTERNATIONAL LLC',CAST('5/11/2020' AS DATE),CAST('6/1/2020' AS DATE),6312.37,CAST('7/2/2020' AS DATE)),
('SHAD0009 - SHADY CREEK GREENHOUSES',CAST('5/12/2020' AS DATE),CAST('6/1/2020' AS DATE),1395.9,CAST('7/2/2020' AS DATE)),
('ISLA0008 - ISLAND GROWER SUPPLIES LLC',CAST('5/13/2020' AS DATE),CAST('6/1/2020' AS DATE),2160,CAST('7/2/2020' AS DATE)),
('LYSH0001 - LYS HYDRO GARDEN FRESNO',CAST('5/13/2020' AS DATE),CAST('6/1/2020' AS DATE),5383.08,CAST('7/2/2020' AS DATE)),
('LLNU0003 - LL NURSERY SUPPLY INC WA',CAST('5/13/2020' AS DATE),CAST('6/1/2020' AS DATE),667.89,CAST('7/2/2020' AS DATE)),
('STAN0009 - STANDEX ELECTRONICS',CAST('5/15/2020' AS DATE),CAST('6/1/2020' AS DATE),47.25,CAST('7/2/2020' AS DATE)),
('BRAD0020 - BRADFORD CO-OP STORAGE LTD (U)',CAST('5/15/2020' AS DATE),CAST('6/1/2020' AS DATE),460.8,CAST('7/2/2020' AS DATE)),
('CANA0034 - CANADIAN TIRE RETAIL DC 9004',CAST('5/16/2020' AS DATE),CAST('6/1/2020' AS DATE),4908.09,CAST('7/2/2020' AS DATE)),
('AJBI0001 - AJ BILLES DC CANADIAN TIRE',CAST('5/16/2020' AS DATE),CAST('6/1/2020' AS DATE),29620.77,CAST('7/2/2020' AS DATE)),
('LOWE3110 - LOWES OF MILTON CANADA # 3110',CAST('5/18/2020' AS DATE),CAST('6/1/2020' AS DATE),1595.47,CAST('7/2/2020' AS DATE)),
('BATT0001 - BATTLEFIELD FARMS',CAST('5/19/2020' AS DATE),CAST('6/1/2020' AS DATE),2088,CAST('7/2/2020' AS DATE)),
('HYDR0010 - HYDROFARM INC',CAST('5/20/2020' AS DATE),CAST('6/1/2020' AS DATE),22368.8,CAST('7/2/2020' AS DATE)),
('WILD0012 - WILDWOODS-PACIFIC NURSERY POTS',CAST('5/20/2020' AS DATE),CAST('6/1/2020' AS DATE),4180,CAST('7/2/2020' AS DATE)),
('GULF0002 - SUNBLEST GARDENS',CAST('5/20/2020' AS DATE),CAST('6/1/2020' AS DATE),21501.89,CAST('7/2/2020' AS DATE)),
('LOUI0001 - LOUIS DAVINO SR LLC',CAST('5/20/2020' AS DATE),CAST('6/1/2020' AS DATE),38150.76,CAST('7/2/2020' AS DATE)),
('DIST0007 - TERIS SERVICES-PICK UP ONLY U',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),3626.73,CAST('7/2/2020' AS DATE)),
('FRED0038 - FRED MEYER STORES',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),38706.76,CAST('7/2/2020' AS DATE)),
('LLNU0003 - LL NURSERY SUPPLY INC WA',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),3205.89,CAST('7/2/2020' AS DATE)),
('DOIT0008 - DO IT BEST CORP',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),551.34,CAST('7/2/2020' AS DATE)),
('BATT0001 - BATTLEFIELD FARMS',CAST('5/21/2020' AS DATE),CAST('6/1/2020' AS DATE),25150,CAST('7/2/2020' AS DATE)),
('AJBI0001 - AJ BILLES DC CANADIAN TIRE',CAST('5/23/2020' AS DATE),CAST('6/1/2020' AS DATE),339.94,CAST('7/2/2020' AS DATE)),
('AMAZ0033 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),998.94,CAST('7/2/2020' AS DATE)),
('AMAZ0134 - AMAZON LGB6',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),1058.85,CAST('7/2/2020' AS DATE)),
('AMAZ0115 - AMAZON.COM LGB4 LLC',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),743.79,CAST('7/2/2020' AS DATE)),
('AMAZ0093 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),3087.16,CAST('7/2/2020' AS DATE)),
('AMAZ0055 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),772.44,CAST('7/2/2020' AS DATE)),
('AMAZ0008 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),1735.38,CAST('7/2/2020' AS DATE)),
('AMAZ0123 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),720.9,CAST('7/2/2020' AS DATE)),
('AMAZ0156 - AMAZON - MEM1',CAST('5/25/2020' AS DATE),CAST('6/1/2020' AS DATE),750.12,CAST('7/2/2020' AS DATE)),
('FRED0038 - FRED MEYER STORES',CAST('5/26/2020' AS DATE),CAST('6/1/2020' AS DATE),4972.75,CAST('7/2/2020' AS DATE)),
('INTE0003 - GREENHOUSE MEGASTORE',CAST('5/26/2020' AS DATE),CAST('6/1/2020' AS DATE),16602.93,CAST('7/2/2020' AS DATE)),
('AMAZ0156 - AMAZON - MEM1',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),14.46,CAST('7/2/2020' AS DATE)),
('AMAZ0159 - AMAZON - SCK1',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
('AMAZ0045 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
('STON0028 - STONINGTON GARDENS',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),1370.99,CAST('7/2/2020' AS DATE)),
('AMAZ0083 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),130.14,CAST('7/2/2020' AS DATE)),
('AMAZ0073 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
('AMAZ0012 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),28.92,CAST('7/2/2020' AS DATE)),
('AMAZ0127 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
('AMAZ0093 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),14.46,CAST('7/2/2020' AS DATE)),
('AMAZ0043 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
('AMAZ0140 - AMAZON - CLT3',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
('AMAZ0114 - AMAZON.COM SERVICES,INC.',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),81.81,CAST('7/2/2020' AS DATE)),
('COPP0002 - COPPERSTATE FARMS MGMT LLC',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),16156.8,CAST('7/2/2020' AS DATE)),
('AMAZ0148 - AMAZON - IND9 9912622',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),14.46,CAST('7/2/2020' AS DATE)),
('AMAZ0144 - AMAZON - CMH3',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),27.27,CAST('7/2/2020' AS DATE)),
('INTE0003 - GREENHOUSE MEGASTORE',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),16810.8,CAST('7/2/2020' AS DATE)),
('DCME0009 - 9 DIS ASM DC 7103 MERCH WM',CAST('5/27/2020' AS DATE),CAST('6/1/2020' AS DATE),26970.81,CAST('7/2/2020' AS DATE)),
('AMAZ0019 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
('AMAZ0155 - AMAZON - XIX7',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
('AMAZ0107 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),65.4,CAST('7/2/2020' AS DATE)),
('AMAZ0099 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
('AMAZ0108 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
('AMAZ0090 - AMAZON.COM FULFILLMENT CTRCHH2',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
('GOLD0038 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('7/2/2020' AS DATE)),
('GASK0001 - GASKO GREENHOUSES',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),39166.05,CAST('7/2/2020' AS DATE)),
('EAGL0001 - EAGLE CREEK WHOLESALE',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),489.5,CAST('8/2/2020' AS DATE)),
('AMAZ0123 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('AMAZ0127 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('AMAZ0029 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('DIST0007 - TERIS SERVICES-PICK UP ONLY U',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),19122.39,CAST('8/2/2020' AS DATE)),
('BEAU0002 - BEAUTIFUL LAND PRODUCTS',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),282.85,CAST('8/2/2020' AS DATE)),
('AMAZ0068 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('AMAZ0045 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('AMAZ0121 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('AMAZ0058 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('AMAZ0051 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('DEWA0001 - DEWAR NURSERIES',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),24181.3,CAST('8/2/2020' AS DATE)),
('AMAZ0091 - AMAZON.COM SERVICES,INC.',CAST('5/28/2020' AS DATE),CAST('6/1/2020' AS DATE),46.32,CAST('8/2/2020' AS DATE)),
('LUPI0001 - LUPINE LADY PORCUPINE GNHSE',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),112.42,CAST('8/2/2020' AS DATE)),
('YODE0010 - YODERS PRODUCE INC',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),228.75,CAST('8/2/2020' AS DATE)),
('JACK0020 - JACKSON COUNTY ARC INC',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),63.2,CAST('8/2/2020' AS DATE)),
('RAND0011 - RANDY WESTRATE GREENHOUSE',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),420.75,CAST('8/2/2020' AS DATE)),
('JOSE0006 - JOSE OCHOA',CAST('5/29/2020' AS DATE),CAST('6/1/2020' AS DATE),520.86,CAST('8/2/2020' AS DATE)),
('WERA0001 - WE RADTKE INC',CAST('5/30/2020' AS DATE),CAST('6/1/2020' AS DATE),1747.05,CAST('8/2/2020' AS DATE)),
('ERNS0003 - ERNST NURSERY',CAST('9/9/2019' AS DATE),CAST('6/2/2020' AS DATE),23493.6,CAST('8/2/2020' AS DATE)),
('SANM0002 - SAN MARCOS-AMER HORT SUPPLY',CAST('10/7/2019' AS DATE),CAST('6/2/2020' AS DATE),23118.67,CAST('8/2/2020' AS DATE)),
('CORS0004 - CORSOS PERENNIALS',CAST('10/23/2019' AS DATE),CAST('6/2/2020' AS DATE),18034.59,CAST('8/2/2020' AS DATE)),
('ALTM0034 - ALTMAN PLANTS - SALINAS',CAST('11/15/2019' AS DATE),CAST('6/2/2020' AS DATE),6092.7,CAST('8/2/2020' AS DATE)),
('ALTM0021 - ALTMANS SPECIALTY PLANTS PERRI',CAST('11/15/2019' AS DATE),CAST('6/2/2020' AS DATE),36831.64,CAST('8/2/2020' AS DATE)),
('WILL0064 - WILLOWBROOK NURSERIES INC',CAST('11/25/2019' AS DATE),CAST('6/2/2020' AS DATE),3474,CAST('8/2/2020' AS DATE)),
('CAVI0001 - CAVICCHIO GREENHOUSES INC',CAST('12/10/2019' AS DATE),CAST('6/2/2020' AS DATE),12716.82,CAST('8/2/2020' AS DATE)),
('ENVI0008 - EVL NURSERY',CAST('12/16/2019' AS DATE),CAST('6/2/2020' AS DATE),3551.31,CAST('8/2/2020' AS DATE)),
('MONR0018 - MONROVIA - DAYTON OR',CAST('1/6/2020' AS DATE),CAST('6/2/2020' AS DATE),29433.6,CAST('8/2/2020' AS DATE)),
('WALD0003 - WALDO ASSOCIATES',CAST('1/30/2020' AS DATE),CAST('6/2/2020' AS DATE),924.93,CAST('8/2/2020' AS DATE)),
('METR0002 - METROLINA GREENHOUSES',CAST('2/11/2020' AS DATE),CAST('6/2/2020' AS DATE),13200,CAST('8/2/2020' AS DATE)),
('HEAR0011 - HEARTLAND-SUN WAREHOUSE24HR N',CAST('2/28/2020' AS DATE),CAST('6/2/2020' AS DATE),4442.04,CAST('8/2/2020' AS DATE)),
('FORE0005 - FOREST GLEN GREENHOUSES (C)',CAST('3/4/2020' AS DATE),CAST('6/2/2020' AS DATE),1747.44,CAST('8/2/2020' AS DATE)),
('VPNU0002 - VP NURSERY',CAST('3/6/2020' AS DATE),CAST('6/2/2020' AS DATE),19356.48,CAST('8/2/2020' AS DATE)),
('ACOS0002 - ACOSTA FARMS NURSERY INC',CAST('3/9/2020' AS DATE),CAST('6/2/2020' AS DATE),4391.78,CAST('8/2/2020' AS DATE)),
('ACOS0002 - ACOSTA FARMS NURSERY INC',CAST('3/10/2020' AS DATE),CAST('6/2/2020' AS DATE),8700,CAST('8/2/2020' AS DATE)),
('PLEA0026 - PLEASANT VALLEY FARM INC',CAST('3/11/2020' AS DATE),CAST('6/2/2020' AS DATE),731.2,CAST('8/2/2020' AS DATE)),
('ROCK0026 - ROCKWELL FARMS',CAST('3/16/2020' AS DATE),CAST('6/2/2020' AS DATE),15949.44,CAST('8/2/2020' AS DATE)),
('CLEA0015 - CLEARVIEW GREENHOUSES',CAST('3/16/2020' AS DATE),CAST('6/2/2020' AS DATE),6698.45,CAST('8/2/2020' AS DATE)),
('OLDN0001 - OLD NORTH GROWERS',CAST('3/16/2020' AS DATE),CAST('6/2/2020' AS DATE),7484.51,CAST('8/2/2020' AS DATE)),
('METR0002 - METROLINA GREENHOUSES',CAST('3/17/2020' AS DATE),CAST('6/2/2020' AS DATE),6767.1,CAST('8/2/2020' AS DATE)),
('BAMA0001 - BAMA GREEN',CAST('3/17/2020' AS DATE),CAST('6/2/2020' AS DATE),13264.85,CAST('8/2/2020' AS DATE)),
('WALD0003 - WALDO ASSOCIATES',CAST('3/18/2020' AS DATE),CAST('6/2/2020' AS DATE),1234.9,CAST('8/2/2020' AS DATE)),
('TREE0044 - TREESAP FARMS-FOREST GROVE OR',CAST('3/24/2020' AS DATE),CAST('6/2/2020' AS DATE),3047.22,CAST('8/2/2020' AS DATE)),
('HEAR0011 - HEARTLAND-SUN WAREHOUSE24HR N',CAST('3/24/2020' AS DATE),CAST('6/2/2020' AS DATE),271,CAST('8/2/2020' AS DATE)),
('YOUN0005 - YOUNGS PLANT FARM INC - FARM 2',CAST('3/25/2020' AS DATE),CAST('6/2/2020' AS DATE),44807.6,CAST('8/2/2020' AS DATE)),
('YOUN0004 - YOUNGS PLANT FARM INC - FARM 1',CAST('3/25/2020' AS DATE),CAST('6/2/2020' AS DATE),27216.51,CAST('8/2/2020' AS DATE)),
('DIXI0001 - DIXIE GREEN INC.',CAST('3/26/2020' AS DATE),CAST('6/2/2020' AS DATE),8568,CAST('8/2/2020' AS DATE)),
('WILL0028 - WILLIAMS PLANT FARM',CAST('3/31/2020' AS DATE),CAST('6/2/2020' AS DATE),2812.5,CAST('8/2/2020' AS DATE)),
('PLEA0026 - PLEASANT VALLEY FARM INC',CAST('4/2/2020' AS DATE),CAST('6/2/2020' AS DATE),468.18,CAST('8/2/2020' AS DATE)),
('SPAR0001 - SPARETIME SUPPLY',CAST('4/2/2020' AS DATE),CAST('6/2/2020' AS DATE),17690.4,CAST('8/2/2020' AS DATE)),
('HYDR0010 - HYDROFARM INC',CAST('4/3/2020' AS DATE),CAST('6/2/2020' AS DATE),19445.93,CAST('8/2/2020' AS DATE)),
('CARL0001 - CARL BREHOB SON',CAST('4/10/2020' AS DATE),CAST('6/2/2020' AS DATE),450.6,CAST('8/2/2020' AS DATE)),
('ALPH0003 - ALPHA FOLIAGE',CAST('4/13/2020' AS DATE),CAST('6/2/2020' AS DATE),16207.16,CAST('8/2/2020' AS DATE)),
('FISH0009 - FISHER NURSERY INC - CA',CAST('4/13/2020' AS DATE),CAST('6/2/2020' AS DATE),2211.86,CAST('8/2/2020' AS DATE)),
('WALD0003 - WALDO ASSOCIATES',CAST('4/14/2020' AS DATE),CAST('6/2/2020' AS DATE),2769.33,CAST('8/2/2020' AS DATE)),
('ROCK0026 - ROCKWELL FARMS',CAST('4/15/2020' AS DATE),CAST('6/2/2020' AS DATE),5061.84,CAST('8/2/2020' AS DATE)),
('SCOT0019 - SCOTTS NURSERY LTD (C)',CAST('4/17/2020' AS DATE),CAST('6/2/2020' AS DATE),18909.45,CAST('8/2/2020' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('4/17/2020' AS DATE),CAST('6/2/2020' AS DATE),172.4,CAST('8/2/2020' AS DATE)),
('WALD0003 - WALDO ASSOCIATES',CAST('4/22/2020' AS DATE),CAST('6/2/2020' AS DATE),607.81,CAST('8/2/2020' AS DATE)),
('KMNU0003 - KM NURSERY',CAST('4/22/2020' AS DATE),CAST('6/2/2020' AS DATE),30531.6,CAST('8/2/2020' AS DATE)),
('SPAR0001 - SPARETIME SUPPLY',CAST('4/27/2020' AS DATE),CAST('6/2/2020' AS DATE),6633.9,CAST('2/2/2021' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('4/28/2020' AS DATE),CAST('6/2/2020' AS DATE),8518.61,CAST('2/2/2021' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('4/29/2020' AS DATE),CAST('6/2/2020' AS DATE),926.2,CAST('2/2/2021' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('4/30/2020' AS DATE),CAST('6/2/2020' AS DATE),6024.27,CAST('2/2/2021' AS DATE)),
('AJBI0001 - AJ BILLES DC CANADIAN TIRE',CAST('5/2/2020' AS DATE),CAST('6/2/2020' AS DATE),752.43,CAST('2/2/2021' AS DATE)),
('CARL0001 - CARL BREHOB SON',CAST('5/6/2020' AS DATE),CAST('6/2/2020' AS DATE),627.25,CAST('2/2/2021' AS DATE)),
('ENVI0008 - EVL NURSERY',CAST('5/6/2020' AS DATE),CAST('6/2/2020' AS DATE),1587.84,CAST('2/2/2021' AS DATE)),
('WALD0003 - WALDO ASSOCIATES',CAST('5/7/2020' AS DATE),CAST('6/2/2020' AS DATE),1734.3,CAST('2/2/2021' AS DATE)),
('LOWE3110 - LOWES OF MILTON CANADA # 3110',CAST('5/11/2020' AS DATE),CAST('6/2/2020' AS DATE),3066.42,CAST('2/2/2021' AS DATE)),
('BUCK0006 - BUCKHORN NURSERY',CAST('5/11/2020' AS DATE),CAST('6/2/2020' AS DATE),1804,CAST('2/2/2021' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/12/2020' AS DATE),CAST('6/2/2020' AS DATE),73.8,CAST('2/2/2021' AS DATE)),
('WALD0003 - WALDO ASSOCIATES',CAST('5/13/2020' AS DATE),CAST('6/2/2020' AS DATE),5142.12,CAST('2/2/2021' AS DATE)),
('WHIT0003 - WHITES NURSERY',CAST('5/14/2020' AS DATE),CAST('6/2/2020' AS DATE),1859.68,CAST('2/2/2021' AS DATE)),
('MENA3339 - MENARDS INC',CAST('5/18/2020' AS DATE),CAST('6/2/2020' AS DATE),1974.54,CAST('2/2/2021' AS DATE)),
('WEST0646 - NUTRIEN AG SOL. - WATSONVILLE',CAST('5/18/2020' AS DATE),CAST('6/2/2020' AS DATE),9660.19,CAST('2/2/2021' AS DATE)),
('HOMU5089 - THE HOME DEPOT #5089 PICK UP',CAST('5/19/2020' AS DATE),CAST('6/2/2020' AS DATE),4166.76,CAST('2/2/2021' AS DATE)),
('HOMU5642 - THE HOME DEPOT #5642 PICK UP',CAST('5/19/2020' AS DATE),CAST('6/2/2020' AS DATE),7687.15,CAST('2/2/2021' AS DATE)),
('HOMU5030 - THE HOME DEPOT #5030 PICK UP',CAST('5/19/2020' AS DATE),CAST('6/2/2020' AS DATE),4395.64,CAST('2/2/2021' AS DATE)),
('HYDR0010 - HYDROFARM INC',CAST('5/20/2020' AS DATE),CAST('6/2/2020' AS DATE),12492.62,CAST('2/2/2021' AS DATE)),
('CARL0001 - CARL BREHOB SON',CAST('5/20/2020' AS DATE),CAST('6/2/2020' AS DATE),1747.28,CAST('2/2/2021' AS DATE)),
('HOMU5034 - THE HOME DEPOT #5034 PICK UP',CAST('5/21/2020' AS DATE),CAST('6/2/2020' AS DATE),18292.72,CAST('2/2/2021' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/21/2020' AS DATE),CAST('6/2/2020' AS DATE),1104.45,CAST('2/2/2021' AS DATE)),
('WOOD0001 - WOODBURN NURSERY',CAST('5/21/2020' AS DATE),CAST('6/2/2020' AS DATE),6138,CAST('2/2/2021' AS DATE)),
('ROBE0014 - ROBERTAS YOUNG PLANTS',CAST('5/21/2020' AS DATE),CAST('6/2/2020' AS DATE),9819.29,CAST('2/2/2021' AS DATE)),
('HOMU5084 - THE HOME DEPOT #5084 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),6897.97,CAST('2/2/2021' AS DATE)),
('CASS0002 - CASSCO',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),20617.7,CAST('2/2/2021' AS DATE)),
('HOMU5085 - THE HOME DEPOT #5085 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),17337.57,CAST('2/2/2021' AS DATE)),
('HOMU5089 - THE HOME DEPOT #5089 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),9208.18,CAST('2/2/2021' AS DATE)),
('HOMU5643 - THE HOME DEPOT #5643 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),963.84,CAST('2/2/2021' AS DATE)),
('HOMU5642 - THE HOME DEPOT #5642 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),576.04,CAST('2/2/2021' AS DATE)),
('HOMU5520 - THE HOME DEPOT #5520 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),7713.04,CAST('2/2/2021' AS DATE)),
('HOMU5030 - THE HOME DEPOT #5030 PICK UP',CAST('5/22/2020' AS DATE),CAST('6/2/2020' AS DATE),5072.52,CAST('2/2/2021' AS DATE)),
('AMAZ0058 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/2/2020' AS DATE),578.27,CAST('2/2/2021' AS DATE)),
('LOWE3110 - LOWES OF MILTON CANADA # 3110',CAST('5/25/2020' AS DATE),CAST('6/2/2020' AS DATE),1637.71,CAST('2/2/2021' AS DATE)),
('AMAZ0006 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/2/2020' AS DATE),2438.8,CAST('2/2/2021' AS DATE)),
('AMAZ0085 - AMAZON.COM SERVICES,INC.',CAST('5/25/2020' AS DATE),CAST('6/2/2020' AS DATE),2800.81,CAST('2/2/2021' AS DATE)),
('HOMU5851 - THE HOME DEPOT #5851 PICK UP',CAST('5/26/2020' AS DATE),CAST('6/2/2020' AS DATE),19600.94,CAST('2/2/2021' AS DATE)),
('HOMU5520 - THE HOME DEPOT #5520 PICK UP',CAST('5/26/2020' AS DATE),CAST('6/2/2020' AS DATE),10885.09,CAST('5/2/2021' AS DATE)),
('HOMU5084 - THE HOME DEPOT #5084 PICK UP',CAST('5/26/2020' AS DATE),CAST('6/2/2020' AS DATE),3289.09,CAST('4/2/2021' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/26/2020' AS DATE),CAST('6/2/2020' AS DATE),1422.36,CAST('4/2/2021' AS DATE)),
('BRAN0014 - BRANTLEY NURSERIES-BUSHNELL',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),9762.48,CAST('5/2/2021' AS DATE)),
('BWIC000G - BWI - SPRINGFIELD MO',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),12315.24,CAST('3/2/2021' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),408,CAST('3/2/2021' AS DATE)),
('DIST0004 - TERIS SVSC DAPPROVISIONNEMNTC',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),1942.22,CAST('3/2/2021' AS DATE)),
('WALM602A - WALMART DC 6002A-ASM DIS',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),30551,CAST('3/2/2021' AS DATE)),
('CASS0002 - CASSCO',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),6635.15,CAST('3/2/2021' AS DATE)),
('HOMU5087 - THE HOME DEPOT #5087 PICK UP',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),12138.15,CAST('3/2/2021' AS DATE)),
('TJSG0001 - TJS GREENHOUSE LANDSCAPE',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),1085.19,CAST('3/2/2021' AS DATE)),
('HOMU5642 - THE HOME DEPOT #5642 PICK UP',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),4149.17,CAST('3/2/2021' AS DATE)),
('SCMD0001 - SCM DC 6063A-ASM DIS WM PICKUP',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),18407.75,CAST('3/2/2021' AS DATE)),
('HOMU5639 - THE HOME DEPOT #5639 PICK UP',CAST('5/27/2020' AS DATE),CAST('6/2/2020' AS DATE),4594.91,CAST('3/2/2021' AS DATE)),
('GRIF0001 - GRIFFIN GREENHOUSE - TEWKSBURY',CAST('5/28/2020' AS DATE),CAST('6/2/2020' AS DATE),660.9,CAST('3/2/2021' AS DATE)),
('CWKI0001 - CW KITCHENS INC',CAST('5/28/2020' AS DATE),CAST('6/2/2020' AS DATE),780.23,CAST('3/2/2021' AS DATE)),
('LLNU0001 - LL NURSERY SUPPLY INC CA',CAST('5/28/2020' AS DATE),CAST('6/2/2020' AS DATE),40536.37,CAST('3/2/2021' AS DATE)),
('ROSE0026 - ROSEVILLE FARMS',CAST('5/29/2020' AS DATE),CAST('6/2/2020' AS DATE),10254.6,CAST('3/2/2021' AS DATE)),
('PLEA0026 - PLEASANT VALLEY FARM INC',CAST('5/29/2020' AS DATE),CAST('6/2/2020' AS DATE),12979.2,CAST('3/2/2021' AS DATE)),
('BRAD0020 - BRADFORD CO-OP STORAGE LTD (U)',CAST('5/29/2020' AS DATE),CAST('6/2/2020' AS DATE),5908.07,CAST('3/2/2021' AS DATE)),
('GLOB0004 - GLOBAL HORTICULTURAL INC (C)',CAST('5/31/2019' AS DATE),CAST('6/3/2020' AS DATE),4159.13,CAST('3/2/2021' AS DATE)),
('GREE0092 - GREENSCAPE',CAST('8/13/2019' AS DATE),CAST('6/3/2020' AS DATE),565.45,CAST('3/2/2021' AS DATE)),
('QUAL0021 - QUALITY GHSE SITE 2',CAST('8/15/2019' AS DATE),CAST('6/3/2020' AS DATE),28746.9,CAST('3/2/2021' AS DATE)),
('MARK0020 - MARKET BASKET OF ST PETERS #6',CAST('9/5/2019' AS DATE),CAST('6/3/2020' AS DATE),89.16,CAST('3/2/2021' AS DATE)),
('TWIN0007 - TWIN OAKS GROWERS',CAST('9/9/2019' AS DATE),CAST('6/3/2020' AS DATE),2310,CAST('3/2/2021' AS DATE)),
('UCGM0001 - UGC - MARKET BASKET',CAST('9/17/2019' AS DATE),CAST('6/3/2020' AS DATE),133.77,CAST('3/2/2021' AS DATE)),
('DREA0005 - DREAMS WITH COLORS INC',CAST('10/3/2019' AS DATE),CAST('6/3/2020' AS DATE),11549.2,CAST('4/2/2021' AS DATE)),
('RSGR0004 - RS GROWERS SUPPLY INC',CAST('10/14/2019' AS DATE),CAST('6/3/2020' AS DATE),4339.84,CAST('4/2/2021' AS DATE)),
('WEAV0003 - WEAVERLAND VALLEY GREENHOUSE',CAST('10/18/2019' AS DATE),CAST('6/3/2020' AS DATE),1039.92,CAST('4/2/2021' AS DATE)),
('FOST0001 - FOSTERS INC RETAIL',CAST('10/22/2019' AS DATE),CAST('6/3/2020' AS DATE),1162.1,CAST('4/2/2021' AS DATE)),
('WETS0003 - BFG SUPPLY - HARRISONBURG(W13)',CAST('10/22/2019' AS DATE),CAST('6/3/2020' AS DATE),1788.07,CAST('4/2/2021' AS DATE)),
('BFGS0011 - BFG SUPPLY - ST PAUL',CAST('10/22/2019' AS DATE),CAST('6/3/2020' AS DATE),1448.7,CAST('4/2/2021' AS DATE)),
('BFGS0004 - BFG SUPPLY - GRAND RAPIDS(W04)',CAST('10/22/2019' AS DATE),CAST('6/3/2020' AS DATE),973.07,CAST('4/2/2021' AS DATE)),
('BFGS0015 - BFG SUPPLY - CHESWICK (W08)',CAST('10/23/2019' AS DATE),CAST('6/3/2020' AS DATE),2197.89,CAST('4/2/2021' AS DATE)),
('FOST0001 - FOSTERS INC RETAIL',CAST('10/25/2019' AS DATE),CAST('6/3/2020' AS DATE),1575.99,CAST('4/2/2021' AS DATE)),
('ARTK0002 - ART KNAPP - HESTIA PRODUCTIONS',CAST('10/28/2019' AS DATE),CAST('6/3/2020' AS DATE),610.56,CAST('4/2/2021' AS DATE)),
('EARL0012 - EARL MAY SEED NURSERY',CAST('10/28/2019' AS DATE),CAST('6/3/2020' AS DATE),174.23,CAST('4/2/2021' AS DATE)),
('DEGR0004 - DEGROOTS NURSERIES',CAST('10/31/2019' AS DATE),CAST('6/3/2020' AS DATE),205.12,CAST('4/2/2021' AS DATE)),
('PLAN0009 - PLANTERS SEED SPICE RET',CAST('11/1/2019' AS DATE),CAST('6/3/2020' AS DATE),234.61,CAST('4/2/2021' AS DATE)),
('CYGR0003 - CY GROWERS SUPPLIES LTD U',CAST('11/4/2019' AS DATE),CAST('6/3/2020' AS DATE),1566,CAST('4/2/2021' AS DATE)),
('BFGS0004 - BFG SUPPLY - GRAND RAPIDS(W04)',CAST('11/4/2019' AS DATE),CAST('6/3/2020' AS DATE),187.77,CAST('4/2/2021' AS DATE)),
('CISC0001 - CISCO COMPANIES (THE)',CAST('11/11/2019' AS DATE),CAST('6/3/2020' AS DATE),533.92,CAST('4/2/2021' AS DATE)),
('BERG0012 - BERGENS GREENHOUSE',CAST('11/12/2019' AS DATE),CAST('6/3/2020' AS DATE),84.46,CAST('4/2/2021' AS DATE)),
('BERG0029 - BERGEN NURSERY',CAST('11/12/2019' AS DATE),CAST('6/3/2020' AS DATE),759.73,CAST('4/2/2021' AS DATE)),
('GREE0223 - EDDIS WHOLESALE GDN SUPPLIES',CAST('11/13/2019' AS DATE),CAST('6/3/2020' AS DATE),87.58,CAST('4/2/2021' AS DATE)),
('KOLL0002 - KOLLMANS GREENHOUSE',CAST('11/15/2019' AS DATE),CAST('6/3/2020' AS DATE),174.67,CAST('4/2/2021' AS DATE)),
('ALTM0032 - ALTMAN PLANTS - TROUP',CAST('11/15/2019' AS DATE),CAST('6/3/2020' AS DATE),933,CAST('4/2/2021' AS DATE)),
('MISC0001 - MISC ACCT - (US )',CAST('11/18/2019' AS DATE),CAST('6/3/2020' AS DATE),0,CAST('4/2/2021' AS DATE)),
('DOIT0030 - DIB-ROLLIERS INC #4447',CAST('11/19/2019' AS DATE),CAST('6/3/2020' AS DATE),23.04,CAST('4/2/2021' AS DATE)),
('BWIC000T - BWI - TEXARKANA TX',CAST('11/20/2019' AS DATE),CAST('6/3/2020' AS DATE),21.77,CAST('4/2/2021' AS DATE)),
('GREE0005 - GREEN ISLAND DISTRIBUTORS INC.',CAST('11/20/2019' AS DATE),CAST('6/3/2020' AS DATE),156.56,CAST('4/2/2021' AS DATE)),
('MAPL0025 - MAPLE LEAF GARDEN',CAST('11/20/2019' AS DATE),CAST('6/3/2020' AS DATE),87.58,CAST('4/2/2021' AS DATE)),
('WYAT0007 - WYATT QUARLES SEED CO',CAST('11/21/2019' AS DATE),CAST('6/3/2020' AS DATE),506.32,CAST('4/2/2021' AS DATE)),
('BWIC000E - BWI - GREENVILLE-SPARTANBURG',CAST('11/22/2019' AS DATE),CAST('6/3/2020' AS DATE),662.73,CAST('4/2/2021' AS DATE)),
('HALI0002 - HALIFAX SEED DIST CENTER (C)',CAST('11/22/2019' AS DATE),CAST('6/3/2020' AS DATE),555.71,CAST('4/2/2021' AS DATE)),
('EDDI0001 - EDDIS WHOLESALE GDN SUPPLIES',CAST('12/2/2019' AS DATE),CAST('6/3/2020' AS DATE),86.01,CAST('4/2/2021' AS DATE)),
('MARI0030 - MARIA GARDENS',CAST('12/3/2019' AS DATE),CAST('6/3/2020' AS DATE),790.55,CAST('4/2/2021' AS DATE)),
('MARI0007 - MARIA GARDENS - N. ROYALTON',CAST('12/4/2019' AS DATE),CAST('6/3/2020' AS DATE),675.25,CAST('4/2/2021' AS DATE)),
('LLNU0003 - LL NURSERY SUPPLY INC WA',CAST('12/5/2019' AS DATE),CAST('6/3/2020' AS DATE),445.85,CAST('4/2/2021' AS DATE)),
('LLNU0001 - LL NURSERY SUPPLY INC CA',CAST('12/5/2019' AS DATE),CAST('6/3/2020' AS DATE),358.1,CAST('4/2/2021' AS DATE)),
('CAVI0001 - CAVICCHIO GREENHOUSES INC',CAST('12/6/2019' AS DATE),CAST('6/3/2020' AS DATE),2316.1,CAST('4/2/2021' AS DATE)),
('GRIF0010 - GRIFFIN GREENHOUSE - STAFFORD',CAST('12/6/2019' AS DATE),CAST('6/3/2020' AS DATE),527.51,CAST('4/2/2021' AS DATE)),
('BFGS0015 - BFG SUPPLY - CHESWICK (W08)',CAST('12/6/2019' AS DATE),CAST('6/3/2020' AS DATE),1640.54,CAST('4/2/2021' AS DATE)),
('COST0015 - COSTA FARMS-FOLIAGE DIV (CNF)',CAST('12/6/2019' AS DATE),CAST('6/3/2020' AS DATE),18673.2,CAST('4/2/2021' AS DATE)),
('BFGS0015 - BFG SUPPLY - CHESWICK (W08)',CAST('12/9/2019' AS DATE),CAST('6/3/2020' AS DATE),716.74,CAST('4/2/2021' AS DATE)),
('BFGS0004 - BFG SUPPLY - GRAND RAPIDS(W04)',CAST('12/9/2019' AS DATE),CAST('6/3/2020' AS DATE),521.93,CAST('4/2/2021' AS DATE)),
('HORI0005 - HORIZON DISTRIBUTION INC',CAST('12/10/2019' AS DATE),CAST('6/3/2020' AS DATE),133.47,CAST('4/2/2021' AS DATE)),
('CARL0002 - CARLIN HORTICULTURAL SUPP U',CAST('12/10/2019' AS DATE),CAST('6/3/2020' AS DATE),155.55,CAST('4/2/2021' AS DATE)),
('CAVI0001 - CAVICCHIO GREENHOUSES INC',CAST('12/10/2019' AS DATE),CAST('6/3/2020' AS DATE),1695.58,CAST('4/2/2021' AS DATE)),
('CARL0001 - CARL BREHOB SON',CAST('12/12/2019' AS DATE),CAST('6/3/2020' AS DATE),478.87,CAST('4/2/2021' AS DATE)),
('BWIC000G - BWI - SPRINGFIELD MO',CAST('12/12/2019' AS DATE),CAST('6/3/2020' AS DATE),68.23,CAST('4/2/2021' AS DATE)),
('GARD0095 - GARD N WISE SALT LAKE',CAST('12/12/2019' AS DATE),CAST('6/3/2020' AS DATE),214.58,CAST('4/2/2021' AS DATE)),
('GARD0122 - GARD N WISE DENVER',CAST('12/12/2019' AS DATE),CAST('6/3/2020' AS DATE),632.41,CAST('4/2/2021' AS DATE)),
('STRA0022 - STRADERS GARDEN SUPPLY',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),186.94,CAST('4/2/2021' AS DATE)),
('STRA0020 - STRADERS GARDEN CENTER #1',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),290.19,CAST('4/2/2021' AS DATE)),
('PLRO0001 - PL ROHRER BRO INC RET',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),21.77,CAST('4/2/2021' AS DATE)),
('STRA0001 - STRADERS GREENHOUSE-POWELL',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),119.62,CAST('4/2/2021' AS DATE)),
('STRA0023 - STRADERS GARDEN SUPPLY',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),186.94,CAST('4/2/2021' AS DATE)),
('STRA0002 - STRADERS GREENHOUSE-GROVE CITY',CAST('12/13/2019' AS DATE),CAST('6/3/2020' AS DATE),186.94,CAST('4/2/2021' AS DATE)),
('LUCA0001 - LUCAS GREENHOUSE',CAST('12/16/2019' AS DATE),CAST('6/3/2020' AS DATE),101062.73,CAST('4/2/2021' AS DATE)),
('ENVI0008 - EVL NURSERY',CAST('12/16/2019' AS DATE),CAST('6/3/2020' AS DATE),22023.66,CAST('4/2/2021' AS DATE)),
('WILD0012 - WILDWOODS-PACIFIC NURSERY POTS',CAST('12/16/2019' AS DATE),CAST('6/3/2020' AS DATE),14853.15,CAST('4/2/2021' AS DATE)),
('APAC0001 - APACHE SEEDS LTD',CAST('12/17/2019' AS DATE),CAST('6/3/2020' AS DATE),663.82,CAST('4/2/2021' AS DATE)),
('GALE0003 - GALES GARDEN CENTER',CAST('12/18/2019' AS DATE),CAST('6/3/2020' AS DATE),622.16,CAST('4/2/2021' AS DATE)),
('OTTO0004 - OTTEN BROS NRSY LANDSCPG INC',CAST('12/19/2019' AS DATE),CAST('6/3/2020' AS DATE),211.66,CAST('4/2/2021' AS DATE)),
('INTE0014 - INTERMOUNTAIN FARMERS ASSN',CAST('12/20/2019' AS DATE),CAST('6/3/2020' AS DATE),87.46,CAST('4/2/2021' AS DATE)),
('GARD0095 - GARD N WISE SALT LAKE',CAST('12/20/2019' AS DATE),CAST('6/3/2020' AS DATE),71.63,CAST('4/2/2021' AS DATE)),
('GRIF0002 - GRIFFIN GREENHOUSE - SCHENECTA',CAST('12/26/2019' AS DATE),CAST('6/3/2020' AS DATE),1849.79,CAST('4/2/2021' AS DATE)),
('COST0007 - COSTA COLOR-MIAMI FL',CAST('1/8/2020' AS DATE),CAST('6/3/2020' AS DATE),15629.4,CAST('4/2/2021' AS DATE)),
('COST0015 - COSTA FARMS-FOLIAGE DIV (CNF)',CAST('1/9/2020' AS DATE),CAST('6/3/2020' AS DATE),6652.8,CAST('4/2/2021' AS DATE)),
('COST0015 - COSTA FARMS-FOLIAGE DIV (CNF)',CAST('1/10/2020' AS DATE),CAST('6/3/2020' AS DATE),944,CAST('4/2/2021' AS DATE)),
('FOST0001 - FOSTERS INC RETAIL',CAST('1/13/2020' AS DATE),CAST('6/3/2020' AS DATE),888.04,CAST('4/2/2021' AS DATE)),
('INTE0003 - GREENHOUSE MEGASTORE',CAST('1/13/2020' AS DATE),CAST('6/3/2020' AS DATE),368.52,CAST('4/2/2021' AS DATE)),
('JOSE0009 - JOSEPH GEREMIA FARM',CAST('1/13/2020' AS DATE),CAST('6/3/2020' AS DATE),1739.3,CAST('4/2/2021' AS DATE)),
('COST0015 - COSTA FARMS-FOLIAGE DIV (CNF)',CAST('1/14/2020' AS DATE),CAST('6/3/2020' AS DATE),5026.94,CAST('4/2/2021' AS DATE)),
('RITC0001 - RITCHIE FEED SEED C',CAST('1/15/2020' AS DATE),CAST('6/3/2020' AS DATE),1.1,CAST('4/2/2021' AS DATE)),
('KUBE0001 - KUBE PAK CORPORATION',CAST('1/16/2020' AS DATE),CAST('6/3/2020' AS DATE),874.5,CAST('4/2/2021' AS DATE)),
('FRYS0001 - FRYSVILLE FARMS (MILES FRY)',CAST('1/17/2020' AS DATE),CAST('6/3/2020' AS DATE),1857.6,CAST('4/2/2021' AS DATE)),
('PRIN0001 - PRINCE CORPORATION',CAST('1/20/2020' AS DATE),CAST('6/3/2020' AS DATE),211.16,CAST('4/2/2021' AS DATE)),
('GALE0006 - GALES GARDEN CENTER',CAST('1/20/2020' AS DATE),CAST('6/3/2020' AS DATE),19.47,CAST('4/2/2021' AS DATE)),
('CKGR0004 - CK GREENHOUSES',CAST('1/20/2020' AS DATE),CAST('6/3/2020' AS DATE),4442.04,CAST('4/2/2021' AS DATE)),
('MATS0002 - MATSUDAS OF SACRAMENTO',CAST('1/20/2020' AS DATE),CAST('6/3/2020' AS DATE),57056.64,CAST('5/2/2021' AS DATE)),
('GRIF0005 - GRIFFIN GREENHOUSE - AUBURN',CAST('1/21/2020' AS DATE),CAST('6/3/2020' AS DATE),7399.49,CAST('5/2/2021' AS DATE)),
('GRIF0014 - GRIFFIN GREENHOUSE - MORGANTWN',CAST('1/21/2020' AS DATE),CAST('6/3/2020' AS DATE),16031.53,CAST('5/2/2021' AS DATE)),
('GRIF0004 - GRIFFIN GREENHOUSE - CHESHIRE',CAST('1/21/2020' AS DATE),CAST('6/3/2020' AS DATE),6166.24,CAST('5/2/2021' AS DATE)),
('GROW0001 - GROWER DIRECT FARMS INC',CAST('1/24/2020' AS DATE),CAST('6/3/2020' AS DATE),1199.44,CAST('5/2/2021' AS DATE)),
('CHAR0009 - CHARLES SPITZNER',CAST('1/24/2020' AS DATE),CAST('6/3/2020' AS DATE),7350,CAST('5/2/2021' AS DATE)),
('KURT0018 - KURTZ FARMS',CAST('1/27/2020' AS DATE),CAST('6/3/2020' AS DATE),3689.69,CAST('5/2/2021' AS DATE)),
('PARK0004 - PARKS BROTHERS FARMS',CAST('1/27/2020' AS DATE),CAST('6/3/2020' AS DATE),2250,CAST('5/2/2021' AS DATE)),
('JAYW0001 - JAY W GUILD',CAST('1/28/2020' AS DATE),CAST('6/3/2020' AS DATE),8388.9,CAST('5/2/2021' AS DATE)),
('VAND0001 - VANDENBERG BULB CO INC',CAST('1/29/2020' AS DATE),CAST('6/3/2020' AS DATE),70.35,CAST('5/2/2021' AS DATE)),
('LITT0001 - LITTLE MOUNTAIN GREENHOUSES U',CAST('2/3/2020' AS DATE),CAST('6/3/2020' AS DATE),61.92,CAST('5/2/2021' AS DATE)),
('JIFF0006 - JIFFY PRODUCTS OF AMERICA',CAST('2/4/2020' AS DATE),CAST('6/3/2020' AS DATE),16652.25,CAST('5/2/2021' AS DATE)),
('RSGR0004 - RS GROWERS SUPPLY INC',CAST('2/6/2020' AS DATE),CAST('6/3/2020' AS DATE),0.02,CAST('5/2/2021' AS DATE)),
('SCHL0001 - SCHLEGEL GRHSE',CAST('2/6/2020' AS DATE),CAST('6/3/2020' AS DATE),3646.58,CAST('5/2/2021' AS DATE)),
('VANW0013 - VAN WINGERDEN GREENHOUSE LLC',CAST('2/7/2020' AS DATE),CAST('6/3/2020' AS DATE),537.3,CAST('5/2/2021' AS DATE)),
('RITC0001 - RITCHIE FEED SEED C',CAST('2/7/2020' AS DATE),CAST('6/3/2020' AS DATE),179.46,CAST('5/2/2021' AS DATE)),
('LONG0002 - LONGFELLOWS GREENHOUSE',CAST('2/7/2020' AS DATE),CAST('6/3/2020' AS DATE),5536.48,CAST('5/2/2021' AS DATE)),
('AAPL0001 - AA PLANTS INC',CAST('2/7/2020' AS DATE),CAST('6/3/2020' AS DATE),3843,CAST('5/2/2021' AS DATE)),
('BFGS0004 - BFG SUPPLY - GRAND RAPIDS(W04)',CAST('2/10/2020' AS DATE),CAST('6/3/2020' AS DATE),553.3,CAST('5/2/2021' AS DATE)),
('KALA0002 - KALAMAZOO FLOWER GROUP LLC',CAST('2/10/2020' AS DATE),CAST('6/3/2020' AS DATE),502.7,CAST('5/2/2021' AS DATE)),
('DOIT0079 - DO IT BEST CORP',CAST('2/10/2020' AS DATE),CAST('6/3/2020' AS DATE),494.4,CAST('5/2/2021' AS DATE)),
('DOIT0004 - DO IT BEST CORP',CAST('2/11/2020' AS DATE),CAST('6/3/2020' AS DATE),82.4,CAST('5/2/2021' AS DATE)),
('GRIF0002 - GRIFFIN GREENHOUSE - SCHENECTA',CAST('2/12/2020' AS DATE),CAST('6/3/2020' AS DATE),376.6,CAST('5/2/2021' AS DATE)),
('NATU0027 - NATURALLY BEAUTIFUL PLANT PROD',CAST('2/12/2020' AS DATE),CAST('6/3/2020' AS DATE),31636.8,CAST('5/2/2021' AS DATE)),
('FARM0012 - FARMETTE GARDENS',CAST('2/13/2020' AS DATE),CAST('6/3/2020' AS DATE),6028.37,CAST('5/2/2021' AS DATE)),
('SPOR0002 - SPORTEL GREENHOUSE',CAST('2/13/2020' AS DATE),CAST('6/3/2020' AS DATE),3728.54,CAST('5/2/2021' AS DATE)),
('ARET0001 - ARETT SALES - BRISTOL',CAST('2/14/2020' AS DATE),CAST('6/3/2020' AS DATE),266.62,CAST('5/2/2021' AS DATE)),
('GREE0005 - GREEN ISLAND DISTRIBUTORS INC.',CAST('2/14/2020' AS DATE),CAST('6/3/2020' AS DATE),21.21,CAST('5/2/2021' AS DATE)),
('FARM0001 - FARMERS COOPERATIVE ELEVATOR',CAST('2/17/2020' AS DATE),CAST('6/3/2020' AS DATE),495,CAST('5/2/2021' AS DATE)),
('VANW0009 - VAN WINGERDEN INTERNATIONAL',CAST('2/17/2020' AS DATE),CAST('6/3/2020' AS DATE),908.6,CAST('5/2/2021' AS DATE)),
('CIVA0001 - CIVANO NURSERY',CAST('2/18/2020' AS DATE),CAST('6/3/2020' AS DATE),50700,CAST('5/2/2021' AS DATE))
) x(ship_cust_descr,order_date,ship_date,sales,revised)
)
,upd AS (
UPDATE
rlarp.osm_pool p
SET
ship_date = revised
FROM
move
WHERE
move.ship_cust_descr = p.ship_cust_descr
AND move.order_date = p.order_date
AND move.ship_date = p.ship_date
AND p.ship_season = 2021
RETURNING *
)
SELECT ship_month ,sum(value_usd) FROM upd group by ship_month;
UPDATE
rlarp.osm_pool
SET
ship_month = gld.sspr || ' - ' || to_char(ship_date,'FMMon')
,ship_season = gld.ssyr
,fspr = gld.fspr
FROM
rlarp.gld gld
WHERE
ship_date BETWEEN gld.sdat AND gld.edat
RETURNING *;
--ROLLBACK;
--SELECT
-- move.revised
-- ,sum(sales)
-- ,sum(value_usd)
--FROM
-- rlarp.osm_pool p
-- INNER JOIN move ON
-- move.ship_cust_descr = p.ship_cust_descr
-- AND move.order_date = p.order_date
-- AND move.ship_date = p.ship_date
--WHERE
-- ship_season = 2021
--GROUP BY
-- move.revised

33
build/rec_act.sql Normal file
View File

@ -0,0 +1,33 @@
SELECT
oseas
,go.drange
,go.sspr
,sum(fb_val_loc * r_rate)
FROM
rlarp.osm_dev o
--snap the ship dates of the historic fiscal period
--LEFT OUTER JOIN rlarp.gld ON
-- gld.fspr = o.fspr
LEFT OUTER JOIN rlarp.gld go ON
odate between go.sdat and go.edat
--get the shipping season for open orders based on the snapped date
--LEFT OUTER JOIN rlarp.gld ss ON
-- greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
WHERE
(
--base period orders booked....
o.odate BETWEEN '2020-06-01' AND '2021-04-04'
----...or any open orders currently booked before cutoff....
--OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2021-04-04')
----...or anything that shipped in that period
--OR o.fspr BETWEEN '2101' AND '2110'
)
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
--AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
---exclude integrated quotes----
AND version = 'ACTUALS'
GROUP BY
oseas
,go.drange
,go.sspr

44
build/snap_cust_osmfs.sql Normal file
View File

@ -0,0 +1,44 @@
UPDATE
RLARP.OSMFS_DEV S
SET
DSM = CR.QUOTA_REP
FROM
(
SELECT DISTINCT
VERSION,
COALESCE(GLEC,'') GLEC,
COALESCE(MING,'') MING,
BILL_CUST,
SHIP_CUST,
------------quota rep column--------------
CASE WHEN COALESCE(ming,'') = 'B52' THEN 'PW' ELSE
--if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available
CASE WHEN COALESCE(glec,'') = '1RE' AND COALESCE(cu.currep,'') <> '' THEN
cu.currep
--default logic
ELSE
CASE SUBSTR(bill_class,2,3)
WHEN 'DIS' THEN
ship_rep
ELSE
bill_rep
END
END
END QUOTA_REP
FROM
RLARP.OSMFS_DEV S
LEFT OUTER JOIN LGDAT.CUST ON
BVCUST = BILL_CUST
LEFT OUTER JOIN lgpgm.usrcust cu ON
cu.cucust = s.bill_cust
--WHERE
-- COALESCE(GLEC,'') IS NOT NULL
) CR
WHERE
CR.VERSION = S.VERSION
AND CR.GLEC = COALESCE(S.GLEC,'')
AND CR.MING = COALESCE(S.MING,'')
AND CR.BILL_CUST = S.BILL_CUST
AND CR.SHIP_CUST = S.SHIP_CUST
AND COALESCE(S.DSM,'') <> CR.QUOTA_REP;

View File

@ -28,51 +28,21 @@ SET
WHEN 'NAT' THEN 'RMN'
ELSE CASE SUBSTRING(s.bvclas,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
END,
dsm = RTRIM(
--retail items go to currep, or if null go to 90005
CASE WHEN o.segm IN ('Retail') THEN
CASE WHEN b.bvctry = 'CAN' THEN
--Rachel Bowman
'50300'
dsm =
------------quota rep column--------------
CASE WHEN COALESCE(substring(ming_descr,1,3),'') = 'B52' THEN 'PW' ELSE
--if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available
CASE WHEN COALESCE(o.segm,'') = 'Retail' AND COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust),'') <> ''
THEN
(SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust)
--default logic
ELSE
--select customers go to select reps
CASE CASE b.bvadr6 WHEN '' THEN b.bvname ELSE b.bvadr6 END
------Alecia Latini-------------------------------
WHEN 'DO IT BEST' THEN '90006'
WHEN 'ACE HARDWARE' THEN '90006'
WHEN 'ALDI' THEN '90006'
WHEN 'AMAZON.COM' THEN '90006'
WHEN 'GARDEN RIDGE CORP' THEN '90006' --AKA "At Home"
WHEN 'TRUE VALUE' THEN '90006'
WHEN 'WAYFAIR' THEN '90006'
WHEN 'GRIFFIN' THEN '90006'
WHEN 'WAL-MART' THEN '90006'
------Tony Landino--------------------------------
WHEN 'THE HOME DEPOT' THEN '50802'
WHEN 'FRED MEYER' THEN '50802'
WHEN 'MENARDS' THEN '50802'
WHEN 'KROGER' THEN '50802'
WHEN 'OCEAN STATE JOBBERS' THEN '50802'
WHEN 'AURORA WHOLESALE' THEN '50802'
WHEN 'LEON KORRAL' THEN '50802'
--all other retail goes to Doran Marable-----------
ELSE '50200'
CASE SUBSTR(b.bvclas,2,3)
WHEN 'DIS' THEN s.bvsalm
ELSE b.bvsalm
END
END
--minor group b52 goes to dedicated rep
ELSE
CASE WHEN SUBSTRING(o.ming_descr,1,3) = 'B52' THEN
'PW'
--gdir, ndir go to bill-to rep
ELSE
CASE WHEN b.bvclas IN ('GDIR','NDIR') THEN
b.bvsalm
ELSE
s.bvsalm
END
END
END
),
END,
billto_group = CASE b.bvadr6 WHEN '' THEN b.bvname ELSE b.bvadr6 END,
shipto_group = CASE s.bvadr6 WHEN '' THEN s.bvname ELSE s.bvadr6 END
FROM
@ -81,7 +51,6 @@ FROM
WHERE
b.bvcust = rtrim(substring(o.bill_cust_descr,1,8))
AND s.bvcust = rtrim(substring(o.ship_cust_descr,1,8));
--BEGIN;
UPDATE
@ -97,5 +66,10 @@ WHERE
and c.a2 = 'MM'
AND q.qr = LTRIM(RTRIM(c.a9));
<<<<<<< HEAD
COMMIT;
=======
COMMIT;
--ROLLBACK;
>>>>>>> dev

View File

@ -1,9 +1,9 @@
------------update fx rates-----------------------------------------------------------------
UPDATE rlarp.osmf_dev SET r_rate = .7518 WHERE r_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osmf_dev SET r_rate = 1.0000 WHERE r_currency = 'US' AND version = 'b21';
UPDATE rlarp.osmf_dev SET c_rate = .7518 WHERE c_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osmf_dev SET c_rate = 1.0000 WHERE c_currency = 'US' AND version = 'b21';
UPDATE rlarp.osm_pool SET r_rate = .7518 WHERE r_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osm_pool SET value_usd = value_loc * r_rate WHERE r_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osm_pool SET c_rate = .7518 WHERE c_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osm_pool SET cost_usd = cost_loc * c_rate WHERE c_currency = 'CA' AND version = 'b21';
UPDATE rlarp.osmf_dev SET r_rate = .7900 WHERE r_currency = 'CA' AND version = 'b22';
UPDATE rlarp.osmf_dev SET r_rate = 1.0000 WHERE r_currency = 'US' AND version = 'b22';
UPDATE rlarp.osmf_dev SET c_rate = .7900 WHERE c_currency = 'CA' AND version = 'b22';
UPDATE rlarp.osmf_dev SET c_rate = 1.0000 WHERE c_currency = 'US' AND version = 'b22';
UPDATE rlarp.osm_pool SET r_rate = .7900 WHERE r_currency = 'CA' AND version = 'b22';
UPDATE rlarp.osm_pool SET value_usd = value_loc * r_rate WHERE r_currency = 'CA' AND version = 'b22';
UPDATE rlarp.osm_pool SET c_rate = .7900 WHERE c_currency = 'CA' AND version = 'b22';
UPDATE rlarp.osm_pool SET cost_usd = cost_loc * c_rate WHERE c_currency = 'CA' AND version = 'b22';

View File

@ -1,7 +1,8 @@
UPDATE
RLARP.OSMF_DEV O
SET
COLC = M.COLC
STYC = M.STLC
,COLC = M.COLC
,COLGRP = M.COLGRP
,COLTIER = M.COLTIER
,COLSTAT = M.COLSTAT

63
build/snap_itemm_pool.sql Normal file
View File

@ -0,0 +1,63 @@
BEGIN;
WITH
SEG AS (
SELECT
GLEC
,SEGM
FROM
(
VALUES
('1CU','Retail'),
('1GR','Greenhouse'),
('1NU','Nursery'),
('1RE','Retail'),
('2WI','Greenhouse'),
('3BM','Other'),
('3CO','Other'),
('3PE','Other'),
('3PP','Other'),
('4CO','Other'),
('4RA','Other'),
('9MI','Other'),
('9SA','Other'),
('9TO','Other')
) X(GLEC, SEGM)
)
,fin AS (
SELECT DISTINCT
o.part
,i.item||coalesce(' - '||i.descr,'') part_descr
,i.stlc part_group
,i.branding
,i.majg||' - '||i.majgd majg_descr
,i.ming||' - '||i.mingd ming_descr
,i.majs||' - '||i.majsd majs_descr
,i.mins||' - '||i.minsd mins_descr
,seg.segm
,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
FROM
rlarp.osm_pool o
LEFT OUTER JOIN rlarp.itemm i ON
i.item = o.part
LEFT OUTER JOIN seg ON
seg.glec = i.glec
)
UPDATE
rlarp.osm_pool o
SET
part_descr = fin.part_descr
,part_group = fin.part_group
,branding = fin.branding
,majg_descr = fin.majg_descr
,ming_descr = fin.ming_descr
,majs_descr = fin.majs_descr
,mins_descr = fin.mins_descr
,segm = fin.segm
,substance = fin.substance
FROM
fin
WHERE
fin.part = o.part;
COMMIT;

View File

@ -1,29 +1,413 @@
with
fp as (
SEG AS (
SELECT
GLEC
,SEGM
FROM
(
VALUES
('1CU','Retail'),
('1GR','Greenhouse'),
('1NU','Nursery'),
('1RE','Retail'),
('2WI','Greenhouse'),
('3BM','Other'),
('3CO','Other'),
('3PE','Other'),
('3PP','Other'),
('4CO','Other'),
('4RA','Other'),
('9MI','Other'),
('9SA','Other'),
('9TO','Other')
) X(GLEC, SEGM)
)
,fp as (
SELECT
od.part,
sum(fb_val_loc * r_rate) sales,
sum(fb_cst_loc * c_rate) scost
sum(value_usd) sales,
sum(cost_usd) scost
FROM
rlarp.osmf_dev od
rlarp.osm_pool od
LEFT OUTER JOIN rlarp.itemmv m ON
m.item = od.part
WHERE
m.item is null
AND coalesce(od.part,'') <> ''
GROUP BY
od.part
)
,repl AS (
SELECT * FROM (VALUES
('ANP00001A39','ANP00001A39C003LRDBP','New 2020'),
('ANP12000A39','ANP12000A39C001LRCOM','New 2020'),
('ANP15000A39','ANP15000A39C001LRCON','New 2020'),
('ANP17500A39','ANP17500A39C001LRCOO','New 2020'),
('ARP06000DE3','ARP06000DE3C012LRDBQ','New 2020'),
('ARP06000P26','ARP06000P26C012LRDBR','New 2020'),
('ARP06000P80','ARP06000P80C012LRDBS','New 2020'),
('ARP06000P81','ARP06000P81C012LRDBT','New 2020'),
('ARP08000DE3','ARP08000DE3C012LRDBU','New 2020'),
('ARP08000P26','ARP08000P26C012LRDBV','New 2020'),
('ARP08000P80','ARP08000P80C012LRDBW','New 2020'),
('ARP08000P81','ARP08000P81C012LRDBX','New 2020'),
('ARP10000DE3','ARP10000DE3C010LRDBY','New 2020'),
('ARP10000P26','ARP10000P26C010LRDBZ','New 2020'),
('ARP10000P80','ARP10000P80C010LRDCA','New 2020'),
('ARP10000P81','ARP10000P81C010LRDCB','New 2020'),
('ARP12000DE3','ARP12000DE3C010LRDCC','New 2020'),
('ARP12000P26','ARP12000P26C010LRDCD','New 2020'),
('ARP12000P80','ARP12000P80C010LRDCE','New 2020'),
('ARP12000P81','ARP12000P81C010LRDCF','New 2020'),
('ARP16000DE3','ARP16000DE3C008LRDCG','New 2020'),
('ARP16000P26','ARP16000P26C008LRDCH','New 2020'),
('ARP16000P80','ARP16000P80C008LRDCI','New 2020'),
('ARP16000P81','ARP16000P81C008LRDCJ','New 2020'),
('ASP06000DE3','ASP06000DE3C012LRDCK','New 2020'),
('ASP06000P26','ASP06000P26C012LRDCL','New 2020'),
('ASP06000P80','ASP06000P80C012LRDCM','New 2020'),
('ASP06000P81','ASP06000P81C012LRDCN','New 2020'),
('ASP08000DE3','ASP08000DE3C012LRDCO','New 2020'),
('ASP08000P26','ASP08000P26C012LRDCP','New 2020'),
('ASP08000P80','ASP08000P80C012LRDCQ','New 2020'),
('ASP08000P81','ASP08000P81C012LRDCR','New 2020'),
('ASP10000DE3','ASP10000DE3C010LRDCS','New 2020'),
('ASP10000P26','ASP10000P26C010LRDCT','New 2020'),
('ASP10000P80','ASP10000P80C010LRDCU','New 2020'),
('ASP10000P81','ASP10000P81C010LRDCV','New 2020'),
('ASP12000DE3','ASP12000DE3C010LRDCW','New 2020'),
('ASP12000P26','ASP12000P26C010LRDCX','New 2020'),
('ASP12000P80','ASP12000P80C010LRDCY','New 2020'),
('ASP12000P81','ASP12000P81C010LRDCZ','New 2020'),
('ASP16000DE3','ASP16000DE3C008LRDDB','New 2020'),
('ASP16000P26','ASP16000P26C008LRDDC','New 2020'),
('ASP16000P80','ASP16000P80C008LRDDE','New 2020'),
('ASP16000P81','ASP16000P81C008LRDDF','New 2020'),
('CAR12000P26','CAR13000P261004LRDBE','New 2020'),
('CAR12000P80','CAR13000P801004LRDBF','New 2020'),
('CAR15000P26','CAR16000P261004LRDBG','New 2020'),
('CAR15000P80','CAR16000P801004LRDBH','New 2020'),
('CAS12000P26','CAS12000P261004LRDBI','New 2020'),
('CAS12000P80','CAS12000P801004LRDBJ','New 2020'),
('CAS15000P26','CAS15000P261004LRDBK','New 2020'),
('CAS15000P80','CAS15000P801004LRDBL','New 2020'),
('CNA06000A10','CNA06000A10C024LRCJJ','New 2020'),
('CNA06000A42','CNA06000A42C024LRCDC','New 2020'),
('CNA06000BG3','CNA06000BG3C024LRCJK','New 2020'),
('CNA06000F89','CNA06000F89C024LRCJL','New 2020'),
('CNA08000A10','CNA08000A10C024LRCJM','New 2020'),
('CNA08000A42','CNA08000A42C024LRBXH','New 2020'),
('CNA08000BG3','CNA08000BG3C024LRCJN','New 2020'),
('CNA08000F89','CNA08000F89C024LRCJO','New 2020'),
('CNA10000A10','CNA10000A10C012LRCJP','New 2020'),
('CNA10000BG3','CNA10000BG3C012LRCJQ','New 2020'),
('CNA10000F89','CNA10000F89C012LRCJR','New 2020'),
('CNA12000A10','CNA12000A10C012LRCJS','New 2020'),
('CNA12000BG3','CNA12000BG3C012LRCJT','New 2020'),
('CNA12000F89','CNA12000F89C012LRCJU','New 2020'),
('ECA06000B78','ECA06000B781028LRCJV','New 2020'),
('ECA06000DE2','ECA06000DE21028LRCJW','New 2020'),
('ECA08000B78','ECA08000B781024LRCJX','New 2020'),
('ECA08000DE2','ECA08000DE21024LRCJY','New 2020'),
('ECA10000B78','ECA10000B781020LRCJZ','New 2020'),
('ECA10000DE2','ECA10000DE21020LRCKA','New 2020'),
('ECA12000B78','ECA12000B781016LRCKB','New 2020'),
('ECA12000DE2','ECA12000DE21016LRCKC','New 2020'),
('ECA16000B78','ECA16000B781010LRCKD','New 2020'),
('ECA16000DE2','ECA16000DE21010LRCKE','New 2020'),
('ECA20000B78','ECA20000B781006LRCKF','New 2020'),
('ECA20000DE2','ECA20000DE21006LRCKG','New 2020'),
('GAB12000BG3','GAB12000BG3C012LRCKH','New 2020'),
('GAB12000DE2','GAB12000DE2C012LRCKI','New 2020'),
('GAB14000BG3','GAB14000BG3C012LRCKJ','New 2020'),
('GAB14000DE2','GAB14000DE2C012LRCKK','New 2020'),
('GAB18000BG3','GAB18000BG3C006LRCKL','New 2020'),
('GAB18000DE2','GAB18000DE2C006LRCKM','New 2020'),
('GAB22000BG3','GAB22000BG3C006LRCKN','New 2020'),
('GAB22000DE2','GAB22000DE2C006LRCKO','New 2020'),
('GDP08000BG3','GDP08000BG3C012LRCOJ','New 2020'),
('GDP08000DE2','GDP08000DE2C012LRCOK','New 2020'),
('LIA06000B78','LIA06000B78C024LRCKP','New 2020'),
('LIA06000DE2','LIA06000DE2C024LRCKQ','New 2020'),
('LIA08000B78','LIA08000B78C024LRCKR','New 2020'),
('LIA08000DE2','LIA08000DE2C024LRCKS','New 2020'),
('LIA10000B78','LIA10000B78C012LRCKT','New 2020'),
('LIA10000DE2','LIA10000DE2C012LRCKU','New 2020'),
('LIA12000B78','LIA12000B78C012LRCKV','New 2020'),
('LIA12000DE2','LIA12000DE2C012LRCKW','New 2020'),
('LIA14000B78','LIA14000B78C012LRCKX','New 2020'),
('LIA14000DE2','LIA14000DE2C012LRCKY','New 2020'),
('LIA16000B78','LIA16000B78C012LRCKZ','New 2020'),
('LIA16000DE2','LIA16000DE2C012LRCLA','New 2020'),
('LIA20000B78','LIA20000B78C006LRCLB','New 2020'),
('LIA20000DE2','LIA20000DE2C006LRCLC','New 2020'),
('LIA24000B78','LIA24000B78C006LRCLD','New 2020'),
('LIA24000DE2','LIA24000DE2C006LRCLE','New 2020'),
('MSA12001A42','MSA12001A421008LRCLF','New 2020'),
('MSA12001B78','MSA12001B781008LRCLG','New 2020'),
('MSA12001DE2','MSA12001DE21008LRCLH','New 2020'),
('MSA16001A42','MSA16001A42C004LRCLI','New 2020'),
('MSA16001B78','MSA16001B78C004LRCLJ','New 2020'),
('MSA16001DE2','MSA16001DE2C004LRCLK','New 2020'),
('MSA20001A42','MSA20001A42C004LRCLL','New 2020'),
('MSA20001B78','MSA20001B78C004LRCLM','New 2020'),
('MSA20001DE2','MSA20001DE2C004LRCLN','New 2020'),
('SEA07001A42','SEA07001A421008LRCLP','New 2020'),
('SEA07001B78','SEA07001B781008LRCLQ','New 2020'),
('SEA07001DE2','SEA07001DE21008LRCLR','New 2020'),
('SEA09001A42','SEA09001A421008LRCLT','New 2020'),
('SEA09001B78','SEA09001B781008LRCLU','New 2020'),
('SEA09001DE2','SEA09001DE21008LRCLV','New 2020'),
('SEA12001A42','SEA12001A421006LRCLX','New 2020'),
('SEA12001B78','SEA12001B781006LRCLY','New 2020'),
('SEA12001DE2','SEA12001DE21006LRCLZ','New 2020'),
('SEA14001A42','SEA14001A421006LRCMB','New 2020'),
('SEA14001B78','SEA14001B781006LRCMC','New 2020'),
('SEA14001DE2','SEA14001DE21006LRCMD','New 2020'),
('SEA16000A42','SEA16001A421006LRCMF','New 2020'),
('SEA16000B78','SEA16001B781006LRCMG','New 2020'),
('SEA16000DE2','SEA16001DE21006LRCMH','New 2020'),
('SKR12000A56','SKR12000A56C010LRDDI','New 2020'),
('SKR12000E66','SKR12000E66C010LRDDJ','New 2020'),
('SKR12000G27','SKR12000G27C010LRDDK','New 2020'),
('SKR16000A56','SKR16000A56C008LRDDL','New 2020'),
('SKR16000E66','SKR16000E66C008LRDDM','New 2020'),
('SKR16000G27','SKR16000G27C008LRDDN','New 2020'),
('SKS12000A56','SKS12000A56C010LRDDO','New 2020'),
('SKS12000E66','SKS12000E66C010LRDDP','New 2020'),
('SKS12000G27','SKS12000G27C010LRDDQ','New 2020'),
('SKS16000A56','SKS16000A56C008LRDDR','New 2020'),
('SKS16000E66','SKS16000E66C008LRDDS','New 2020'),
('SKS16000G27','SKS16000G27C008LRDDT','New 2020'),
('SLI06000B78','SLI06000B78C024LRCMI','New 2020'),
('SLI06000DE2','SLI06000DE2C024LRCMJ','New 2020'),
('SLI08000B78','SLI08000B78C024LRCMK','New 2020'),
('SLI08000DE2','SLI08000DE2C024LRCML','New 2020'),
('SLI10000B78','SLI10000B78C012LRCMM','New 2020'),
('SLI10000DE2','SLI10000DE2C012LRCMN','New 2020'),
('SLI12000B78','SLI12000B78C012LRCMO','New 2020'),
('SLI12000DE2','SLI12000DE2C012LRCMP','New 2020'),
('SLI14000B78','SLI14000B78C012LRCMQ','New 2020'),
('SLI14000DE2','SLI14000DE2C012LRCMR','New 2020'),
('SLI16000B78','SLI17000B78C012LRCMS','New 2020'),
('SLI17000DE2','SLI17000DE2C012LRCMT','New 2020'),
('SLI20000B78','SLI20000B78C006LRCMU','New 2020'),
('SLI20000DE2','SLI20000DE2C006LRCMV','New 2020'),
('SLI24000B78','SLI24000B78C006LRCMW','New 2020'),
('SLI24000DE2','SLI24000DE2C006LRCMX','New 2020'),
('SVN18000A10','SVN18000A10C006LRCMY','New 2020'),
('SVN18000A42','SVN18000A42C006LRCMZ','New 2020'),
('SVN24000A10','SVN24000A10C006LRCNA','New 2020'),
('SVN24000A42','SVN24000A42C006LRCNB','New 2020'),
('SVN30000A10','SVN30000A10C006LRCNC','New 2020'),
('SVN30000A42','SVN30000A42C006LRCND','New 2020'),
('VNP18000A10','VNP18000A10C006LRCNE','New 2020'),
('VNP18000A42','VNP18000A42C006LRCNF','New 2020'),
('VNP24000A10','VNP24000A10C006LRCNG','New 2020'),
('VNP24000A42','VNP24000A42C006LRCNH','New 2020'),
('VNP30000A10','VNP30000A10C006LRCNI','New 2020'),
('VNP30000A42','VNP30000A42C006LRCNJ','New 2020'),
('WBP16000P82','WBP16000P82C008LRDDG','New 2020'),
('ROS15500A42','ROS15500A42C012LRDFA','New 2021'),
('SRO15500A42','SRO15500A42C012LRDFB','New 2021'),
('CSB06000A58','CSB06000A58C020LRDHO','New 2021'),
('CSB06000E67','CSB06000E67C020LRDHM','New 2021'),
('CSB06000G28','CSB06000G28C020LRDHN','New 2021'),
('CSB08000A58','CSB08000A58C020LRDHU','New 2021'),
('CSB08000E67','CSB08000E67C020LRDHS','New 2021'),
('CSB08000G28','CSB08000G28C020LRDHT','New 2021'),
('CNA06000A02','CNA06000A02C024LRDGU','New 2021'),
('CNA06000CXX','CNA06000CXXC024LRDGV','New 2021'),
('CNA06000DE1','CNA06000DE1C024LRDGW','New 2021'),
('CNA08000A02','CNA08000A02C024LRDGX','New 2021'),
('CNA08000CXX','CNA08000CXXC024LRDGY','New 2021'),
('CNA08000DE1','CNA08000DE1C024LRDGZ','New 2021'),
('CNA10000A02','CNA10000A02C012LRDHA','New 2021'),
('CNA10000CXX','CNA10000CXXC012LRDHB','New 2021'),
('CNA10000DE1','CNA10000DE1C012LRDHC','New 2021'),
('CNA12000A02','CNA12000A02C012LRDHD','New 2021'),
('CNA12000CXX','CNA12000CXXC012LRDHE','New 2021'),
('CNA12000DE1','CNA12000DE1C012LRDHF','New 2021'),
('DFB06000A58','DFB06000A58C024LRDHR','New 2021'),
('DFB06000E67','DFB06000E67C024LRDHP','New 2021'),
('DFB06000G28','DFB06000G28C024LRDHQ','New 2021'),
('DFB08000A58','DFB08000A58C024LRDHX','New 2021'),
('DFB08000E67','DFB08000E67C024LRDHV','New 2021'),
('DFB08000G28','DFB08000G28C024LRDHW','New 2021'),
('ECH12000A42','ECH12000A421010LRDFM','New 2021'),
('ECH12000E21','ECH12000E211010LRDFK','New 2021'),
('ECH12000G18','ECH12000G181010LRDFL','New 2021'),
('ECA06000A02','ECA06000A021028LRDEJ','New 2021'),
('ECA06000A42','ECA06000A421028LRDEI','New 2021'),
('ECA08000A02','ECA08000A021024LRDEL','New 2021'),
('ECA08000A42','ECA08000A421024LRDEK','New 2021'),
('ECA10000A02','ECA10000A021020LRDEM','New 2021'),
('ECA10000A42','ECA10000A421020LRDEN','New 2021'),
('ECA12000A02','ECA12000A021016LRDEO','New 2021'),
('ECA12000A42','ECA12000A421016LRDEP','New 2021'),
('ECA16000A02','ECA16000A021010LRDES','New 2021'),
('ECA16000A42','ECA16000A421010LRDET','New 2021'),
('ECA20000A02','ECA20000A021006LRDEW','New 2021'),
('ECA20000A42','ECA20000A421006LRDEX','New 2021'),
('ECI12000A42','ECI12000A421010LRDFP','New 2021'),
('ECI12000E21','ECI12000E211010LRDFN','New 2021'),
('ECI12000G18','ECI12000G181010LRDFO','New 2021'),
('ECP06000A02','ECP06000A021028LRDGK','New 2021'),
('ECP06000A42','ECP06000A421028LRDGM','New 2021'),
('ECP06000DE2','ECP06000DE21028LRDGL','New 2021'),
('ECP06000E35','ECP06000E351028LRDGJ','New 2021'),
('ECP06000G18','ECP06000G181028LRDGI','New 2021'),
('ECP08000A02','ECP08000A021024LRDGP','New 2021'),
('ECP08000A42','ECP08000A421024LRDGR','New 2021'),
('ECP08000DE2','ECP08000DE21024LRDGQ','New 2021'),
('ECP08000E35','ECP08000E351024LRDGO','New 2021'),
('ECP08000G18','ECP08000G181024LRDGN','New 2021'),
('ECP10000A02','ECP10000A021020LRDGA','New 2021'),
('ECP10000A42','ECP10000A421020LRDGC','New 2021'),
('ECP10000DE2','ECP10000DE21020LRDGB','New 2021'),
('ECP10000E35','ECP10000E351020LRDFZ','New 2021'),
('ECP10000G18','ECP10000G181020LRDFY','New 2021'),
('ECP12000A02','ECP12000A021016LRDGF','New 2021'),
('ECP12000A42','ECP12000A421016LRDGH','New 2021'),
('ECP12000DE2','ECP12000DE21016LRDGG','New 2021'),
('ECP12000E35','ECP12000E351016LRDGE','New 2021'),
('ECP12000G18','ECP12000G181016LRDGD','New 2021'),
('ECW24000A10','ECW24000A101006LRDFQ','New 2021'),
('ECW24000A42','ECW24000A421006LRDFT','New 2021'),
('ECW24000E35','ECW24000E351006LRDFS','New 2021'),
('ECW24000G18','ECW24000G181006LRDFR','New 2021'),
('ECW30000A10','ECW30000A101006LRDFU','New 2021'),
('ECW30000A42','ECW30000A421006LRDFX','New 2021'),
('ECW30000E35','ECW30000E351006LRDFW','New 2021'),
('ECW30000G18','ECW30000G181006LRDFV','New 2021'),
('GAB12000A42','GAB12000A42C012LRDFC','New 2021'),
('GAB14000A42','GAB14000A42C012LRDFD','New 2021'),
('GAB22000A42','GAB22000A42C006LRDFE','New 2021'),
('GDP08000A10','GDP08000A10C012LRDFF','New 2021'),
('HBM12000H13','HBM12000H136010LRDIB','New 2021'),
('HBM12000H26','HBM12000H226010LRDIC','New 2021'),
('HBM12000H22','HBM12000H266010LRDIA','New 2021'),
('PA.08005B71',CAST(NULL AS VARCHAR(255)),'New 2021'),
('PA.08005E22','PA.08005E22C250LYHQO','New 2021'),
('SPP08000A58','SPP08000A581004LRDHZ','New 2021'),
('SPP08000E67','SPP08000E671004LRDHY','New 2021'),
('PZA09000YB5','PZA09000YB5C012LRDFG','New 2021'),
('PZA12000YB5','PZA12000YB5C012LRDFH','New 2021'),
('PZA16000YB5','PZA16000YB5C006LRDFI','New 2021'),
('PZA20000YB5','PZA20000YB5C006LRDFJ','New 2021'),
('SSP02500A58','SSP02500A58C020LRDHI','New 2021'),
('SSP02500E67','SSP02500E67C020LRDHG','New 2021'),
('SSP02500G28','SSP02500G28C020LRDHH','New 2021'),
('SSP03000A58','SSP03000A58C020LRDHL','New 2021'),
('SSP03000E67','SSP03000E67C020LRDHJ','New 2021'),
('SSP03000G28','SSP03000G28C020LRDHK','New 2021'),
('RZ.MT160G18',CAST(NULL AS VARCHAR(255)),'New 2021'),
('RZ.MT160A42',CAST(NULL AS VARCHAR(255)),'New 2021'),
('RZ.MT160XXX',CAST(NULL AS VARCHAR(255)),'New 2021'),
('RZ.WC2G3B66','RZ.WC2G3B66C020LRCOT','New 2021')
) x(f11,fp,note)
)
, fin AS (
SELECT
fp.part,
fp.sales,
min(item) item
min(item) item,
repl.fp,
COALESCE(repl.fp,min(item)) pick
FROM
fp
LEFT OUTER JOIN rlarp.itemmv m ON
substring(m.item,1,11) = fp.part
substring(m.item,1,11) = substring(fp.part,1,11)
LEFT OUTER JOIN repl ON
repl.f11 = substring(fp.part,1,11)
GROUP BY
fp.part,
fp.sales
fp.sales,
repl.fp
ORDER BY
fp.sales desc,`
fp.sales desc,
fp.part
)
--SELECT * FROM fin;
/*
,upd AS (
UPDATE
rlarp.osm_pool o
SET
part = fin.pick
FROM
fin
WHERE
fin.part = o.part
RETURNING *
)
SELECT * from upd;
*/
--SELECT * FROM rlarp.osm_pool o inner join fin on fin.part = o.part ;
select * from fin;
ROLLBACK;
/*
,ins AS (
SELECT
p.fspr
,p.plnt
,p.promo
,p.terms
,p.bill_cust_descr
,p.ship_cust_descr
,p.dsm
,p.quota_rep_descr
,p.director
,p.billto_group
,p.shipto_group
,p.chan
,p.chansub
,p.chan_retail
,fin.pick
,i.item||coalesce(' - '||i.descr,'') part_descr
,i.stlc part_group
,i.branding
,i.majg||' - '||i.majgd majg_descr
,i.ming||' - '||i.mingd ming_descr
,i.majs||' - '||i.majsd majs_descr
,i.mins||' - '||i.minsd mins_descr
,seg.segm
,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
,p.fs_line
,p.r_currency
,p.r_rate
,p.c_currency
,p.c_rate
,p.units
,p.value_loc
,p.value_usd
,p.cost_loc
,p.cost_usd
,p.calc_status
,p.flag
,p.order_date
,p.order_month
,p.order_season
,p.request_date
,p.request_month
,p.request_season
,p.ship_date + INTERVAL '1 year'
,ship_month
,ship_season
,'b21' AS version
,'fake parts' iter
,logl.id logid
,logl.doc->>'tag' tag
,logl.doc->>'message' "comment"
,logl.doc->>'type' module
FROM
rlarp.osm_pool p
INNER JOIN fin ON
fin.part = p.part
LEFT OUTER JOIN rlarp.itemm i ON
i.item = fin.pick
LEFT OUTER JOIN seg ON
seg.glec = i.glec;
*/

47
build/temp.sql Normal file
View File

@ -0,0 +1,47 @@
WITH
gld AS (
SELECT
N1COMP COMP
,N1CCYY FSYR
,KPMAXP PERDS
,N1FSPP PERD
,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT
,N1ED01 EDAT
,to_char(N1ED01,'yymm') CAPR
,N1ED01 - N1SD01 +1 NDAYS
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
FROM
LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON
KPCOMP = N1COMP AND
KPCCYY = N1CCYY
WHERE
N1COMP = 93
--AND DIGITS(N1FSYP) = '1901'
)
--SELECT * FROM gld
select oseas, sum(fb_val_loc * r_rate)
FROM
rlarp.osm_dev o
--snap the ship dates of the historic fiscal period
LEFT OUTER JOIN gld ON
gld.fspr = o.fspr
--get the shipping season for open orders based on the snapped date
LEFT OUTER JOIN gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
WHERE
(
--base period orders booked....
o.odate BETWEEN '2019-06-01' AND '2020-05-31'
--...or any open orders currently booked before cutoff....
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-05-31')
OR o.sseas BETWEEN '2001' AND '2012'
)
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
AND dsm = 'PW'
and version = 'ACTUALS'
group by oseas

View File

@ -7,7 +7,7 @@ ExecStart=/usr/bin/node //opt/forecast_api/index.js
Restart=always
User=fc_api
Environemnt=NODE_ENV=production
WorkingDirectory=//opt/forecast_api
WorkingDirectory=//opt/forecast_api/
[Install]
WantedBy=multi-user.target

View File

@ -294,8 +294,8 @@ server.get('/list_changes', bodyParser.json(), function(req, res) {
console.log(new Date().toISOString() + "-------------------------list changes:------------------------------")
console.log(req.body);
//parse the where clause into the main sql statement
sql = sql.replace(new RegExp("where_clause", 'g'), w)
//execute the sql and send the result
sql = sql.replace(new RegExp("replace_user", 'g'), req.body.scenario.quota_rep_descr)
//execute the sql and send the result
console.log(sql);
Postgres.FirstRow(sql, [], res)
};
@ -544,6 +544,48 @@ server.post('/scale_vp', bodyParser.json(), function(req, res) {
});
})
server.post('/scale_vp_sales', bodyParser.json(), function(req, res) {
var sql = "";
var w = "";
var c = 1;
var d = 1;
var args = [];
var path = './route_sql/scale_vupd.sql';
var callback = function(arg) {
sql = arg;
({ c, w, d } = build_where(req, c, w, d, args));
if (c == 1) {
res.send("no body was sent");
return;
}
console.log(new Date().toISOString() + "--------------------scale volume & price:-------------------");
req.body.stamp = new Date().toISOString()
console.log(req.body);
//console.log(args);
sql = sql.replace(new RegExp("where_clause", 'g'), w);
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version);
sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source);
sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body));
console.log(sql);
Postgres.FirstRow(sql, [], res)
}
fs.readFile(path, 'utf8', function(err, data) {
if (!err) {
callback(data);
} else {
console.log("fatal error pulling sql file")
callback(err);
}
});
})
server.post('/new_part', bodyParser.json(), function(req, res) {
var sql = "";

View File

@ -1,120 +1,316 @@
BEGIN;
with p AS (
--BEGIN;
WITH
incr AS (
SELECT * FROM (VALUES
('110','PP','B',0.25),
('110','PP','T',0.25),
('110','PP','L',0.4),
('110','PP','M',0.4),
('110','PP','P',0.4),
('110','PP','C',0.4),
('210','PE','B',0.25),
('210','PE','T',0.25),
('210','PE','L',0.25),
('210','PE','M',0.25),
('210','PE','P',0.25),
('210','PE','C',0.25),
('310','PE','B',0.15),
('310','PE','T',0.25),
('310','PE','L',0.25),
('310','PE','M',0.25),
('310','PE','P',0.25),
('310','PE','C',0.25),
('310','PP','B',0.13),
('310','PP','T',0.16),
('310','PP','L',0.16),
('310','PP','M',0.16),
('310','PP','P',0.16),
('310','PP','C',0.16),
('310','PS','B',0.13),
('310','PS','T',0.16),
('310','PS','L',0.16),
('310','PS','M',0.16),
('310','PS','P',0.16),
('310','PS','C',0.16),
('320','PE','B',0.25),
('320','PE','T',0.25),
('320','PE','L',0.25),
('320','PE','M',0.25),
('320','PE','P',0.25),
('320','PE','C',0.25),
('320','PP','B',0.25),
('320','PP','T',0.25),
('320','PP','L',0.25),
('320','PP','M',0.25),
('320','PP','P',0.25),
('320','PP','C',0.25),
('910','PE','B',0.15),
('910','PE','D',0.25),
('910','PE','F',0.25),
('910','PP','B',0.15),
('910','PP','D',0.25),
('910','PP','F',0.25),
('910','PS','B',0.15),
('910','','B',0.15),
('910','','D',0.25),
('910','','F',0.25),
('910','','T',0.25),
('910','','L',0.25),
('910','','M',0.25),
('910','','P',0.25),
('910','','C',0.25),
('910','PS','D',0.25),
('910','PS','F',0.25),
('610','','B',0.02),
('610','','S',0.02),
('610','','W',0.02)
) x(MAJG,ASSC,COLTIER,RATE)
)
,p AS (
SELECT
part
,bill_cust
,ship_cust
,round(fb_val_loc/fb_qty,10) AS price
,orderdate
,row_number() OVER (PARTITION BY part,bill_cust, ship_cust ORDER BY orderdate DESC) rn
o.part
,o.styc||'.'||o.colgrp||substring(o.sizc,2,3) product
,o.glec
,o.styc
,o.majg
,i.assc
,o.coltier
,o.sizc
,i.suffix
,substring(o.chan,1,1) chgrp
,o.account
,o.shipgrp
,o.fb_qty units
,o.fb_val_loc*r_rate val_usd
,round(o.fb_val_loc/o.fb_qty,10) AS price
,o.odate
,o.oseas
,row_number() OVER (PARTITION BY o.part,o.bill_cust, o.ship_cust ORDER BY o.odate DESC) rn
FROM
rlarp.osm
rlarp.osm_dev o
INNER JOIN rlarp.itemmv i ON
i.item = o.part
WHERE
fs_line = '41010'
AND calc_status <> 'CANCELED'
AND COALESCE(part,'') <> ''
AND fb_qty <> 0
AND orderdate IS NOT NULL
---exclude R&A's
o.fs_line = '41010'
---exclude canceled orders
AND o.calc_status <> 'CANCELED'
---exclude quotes
AND o.version = 'ACTUALS'
---only finished goods
AND substring(o.glec,1,1) <= '2'
---exclude blank parts
AND COALESCE(o.part,'') <> ''
---must have a quantity
AND o.fb_qty <> 0
---must have a price
AND o.fb_val_loc <> 0
---must come from and order
AND o.odate IS NOT NULL
---exclude samples
AND o.bill_class <> 'SALE'
---only use recent history
AND o.oseas >= 2020
ORDER BY
part
,bill_cust
,ship_cust
,orderdate
o.part
,o.styc
,o.coltier
,o.sizc
,i.suffix
,o.account
,o.shipgrp
,o.odate DESC
)
--SELECT * FROM p WHERE rn = 1
,incr AS (
,baseline AS (
SELECT
b.plnt
,b."ddord#"
,b."dditm#"
,b."fgbol#"
,b."fgent#"
,b."diinv#"
,b."dilin#"
,b.promo
,b.return_reas
,b.terms
,b.custpo
,b.dhincr
,b.diext
,b.ditdis
,b.dcodat
,b.ddqdat
,b.dcmdat
,b.dhidat
,b.fspr
,b.remit_to
,b.bill_class
,b.bill_cust
,b.bill_rep
,b.bill_terr
,b.ship_class
,b.ship_cust
,b.ship_rep
,b.ship_terr
,b.quota_rep
,b.account
,b.shipgrp
,b.geo
,b.chan
,b.orig_ctry
,b.orig_prov
,b.orig_post
,b.dest_ctry
,b.dest_prov
,b.dest_post
,b.part
,b.ord_gldc
,b.majg
,b.ming
,b.majs
,b.mins
,b.gldc
,b.glec
,b.harm
,b.clss
,b.brand
,b.assc
,b.fs_line
,b.r_currency
,b.r_rate
,b.c_currency
,b.c_rate
,b.ddqtoi
,b.ddqtsi
,b.fgqshp
,b.diqtsh
,0 fb_qty
,0 fb_cst_loc
,0 fb_cst_loc_cur
,0 fb_cst_loc_fut
,b.fb_qty * p.price - b.fb_val_loc fb_val_loc
,0 fb_val_loc_pl
,b.calc_status
,b.flag
,b.orderdate
,b.requestdate
,b.shipdate
,b.adj_orderdate
,b.adj_requestdate
,b.adj_shipdate
,b."version"
,'last price paid' iter
product
,majg
,assc
,chgrp
,round(sum(val_usd) FILTER (WHERE oseas = 2020)/sum(units) FILTER (WHERE oseas = 2020),5) py_gasp
FROM
rlarp.osmfs b
INNER JOIN p ON
p.part = b.part
AND p.bill_cust = b.bill_cust
AND p.ship_cust = b.ship_cust
AND p.rn = 1
WHERE
b.orderdate BETWEEN '2019-03-25' AND '2019-05-31'
OR b.orderdate BETWEEN '2020-03-25' AND '2020-05-31'
p
GROUP BY
product
,majg
,assc
,chgrp
)
, ins AS (
INSERT INTO rlarp.osmfs SELECT * FROM incr RETURNING *
)
SELECT fspr, sum(fb_val_loc *r_rate) FROM ins GROUP BY fspr;
,pivot AS (
SELECT
p.product
,p.styc
,p.glec
,p.majg
,p.assc
,p.coltier
,p.sizc
,p.suffix
,p.account
,p.shipgrp
,bl.py_gasp
,sum(units) FILTER (WHERE oseas = 2021) cy_units
,round(sum(val_usd) FILTER (WHERE oseas = 2020)/sum(units) FILTER (WHERE oseas = 2020),5) py_asp
,round(avg(price) FILTER (WHERE rn = 1),5) last_price
,max(odate) FILTER (WHERE rn = 1) last_order
,i.rate
,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL
THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
THEN 'unknown'
ELSE 'new'
END
ELSE CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
THEN 'lost'
ELSE 'repeat'
END
END flag
FROM
p
LEFT OUTER JOIN baseline bl ON
bl.product = p.product
AND bl.majg = p.majg
AND bl.assc = p.assc
AND bl.chgrp = p.chgrp
LEFT OUTER JOIN incr i ON
i.majg = p.majg
AND i.assc = p.assc
AND i.coltier = p.coltier
AND p.glec <> '1RE'
COMMIT;
GROUP BY
p.product
,p.styc
,p.glec
,p.majg
,p.assc
,p.coltier
,p.sizc
,p.suffix
,p.account
,p.shipgrp
,bl.py_gasp
,i.rate
)
,adj AS (
SELECT
p.product
,p.styc
,p.glec
,p.majg
,p.assc
,p.coltier
,p.sizc
,p.suffix
,p.account
,p.shipgrp
,p.py_gasp
,p.cy_units
,p.py_asp
,p.last_price
,p.last_order
,p.rate
,p.flag
,CASE p.flag
----------------------if repeat business then get to prior year + target %--------------------------------------------------------------
WHEN 'repeat' THEN greatest(py_asp * COALESCE(1+rate,1) - last_price,0)
WHEN 'lost' THEN greatest(py_asp * COALESCE(1+rate,1) - last_price,0)
----------------------if new business, move towards py_gasp + target % : lesser of py gloabl + target or last + target------------------
WHEN 'new' THEN least(last_price * COALESCE(1+rate,1) - last_price,greatest(py_gasp * COALESCE(1+rate,1) - last_price,0))
END price_increment
FROM
pivot p
)
,log AS (
--INSERT INTO
-- rlarp.osm_log(doc)
SELECT
$${
"message":"application of last price and target increases to all forecast orders",
"tag":"last price",
"type":"build"
}$$::jsonb doc
--RETURNING *
)
,ins AS (
SELECT
o.fspr
,o.plnt ---master data
,o.promo --history date mix
,o.terms
,o.bill_cust_descr --history cust mix
,o.ship_cust_descr --history cust mix
,o.dsm
,o.quota_rep_descr --master data
,o.director
,o.billto_group --master data
,o.shipto_group
,o.chan --master data
,o.chansub
,o.chan_retail
,o.part
,o.part_descr
,o.part_group
,o.branding
,o.majg_descr
,o.ming_descr
,o.majs_descr
,o.mins_descr
,o.segm
,o.substance
,o.fs_line --master data
,o.r_currency --history cust mix
,o.r_rate --master data
,o.c_currency --master data
,o.c_rate --master data
,0::numeric units
,ROUND(o.units * (a.price_increment/o.r_rate),2) value_loc
,ROUND(o.units * a.price_increment,2) value_usd
,0::numeric cost_loc
,0::numeric cost_usd
,o.calc_status --0
,o.flag --0
,o.order_date --history date mix
,o.order_month
,o.order_season
,o.request_date --history date mix
,o.request_month
,o.request_season
,o.ship_date --history date mix
,o.ship_month
,o.ship_season
,o.version
---this iteration has to be listed in the master template file in order to be effectively included---
,'upload price' iter
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
-------------------------------------
--,value_usd/units price
--,a.py_gasp
--,a.rate
--,a.last_price
--,a.price_increment
FROM
rlarp.osm_pool o
,rlarp.itemmv i
,adj a
,log
WHERE
i.item = o.part
AND a.product = i.stlc||'.'||i.colgrp||substring(i.sizc,2,3)
AND a.account = o.billto_group
AND a.shipgrp = o.shipto_group
AND a.price_increment <> 0
AND o.units <> 0
---only apply to 2022 orders----
AND o.order_date >= '2021-06-01'
)
SELECT
order_season
,sum(value_usd) val_usd
FROM
ins
GROUP BY
order_season;
--COMMIT;

View File

@ -323,14 +323,14 @@ SELECT
,b.cost_usd*s.factor*m.momix cost_usd
,b.calc_status
,b.flag
,make_date(mseq.yr + 2021,mseq.cal,m.odom) order_date
,od.sspr || ' - ' || to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom),'Mon') order_month
,make_date(mseq.yr + 2022,mseq.cal,m.odom) order_date
,od.sspr || ' - ' || to_char(make_date(mseq.yr + 2022,mseq.cal,m.odom),'Mon') order_month
,od.ssyr order_season
,make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag request_date
,rd.sspr || ' - ' ||to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag,'Mon') request_month
,make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag request_date
,rd.sspr || ' - ' ||to_char(make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag,'Mon') request_month
,rd.ssyr request_season
,make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag ship_date
,sd.sspr || ' - ' || to_char(make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag + slag ship_date
,sd.sspr || ' - ' || to_char(make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,sd.ssyr ship_season
,'replace_version' "version"
,'replace_source'||' volume' iter
@ -347,11 +347,11 @@ FROM
LEFT OUTER JOIN mseq ON
mseq.m = closest.m
LEFT OUTER JOIN gld od ON
make_date(mseq.yr + 2021,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
make_date(mseq.yr + 2022,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON
make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON
make_date(mseq.yr + 2021,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
make_date(mseq.yr + 2022,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
WHERE
m._month = (SELECT _month FROM closest)
)

View File

@ -19,7 +19,7 @@ FROM
LEFT OUTER JOIN rlarp.osm_log ON
id = logid
WHERE
order_season = 2021
order_season = 2022
GROUP BY
director
,quota_rep_descr

View File

@ -250,13 +250,13 @@ SELECT
,substring(jr.part_descr,1,8) part_group
,mxm.qty*mxm.momix*jr.mix units
,mxm.amount*mxm.momix*jr.mix value_usd --assume that target dollars are USD
,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) order_date
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) order_date
,od.sortmo order_month
,od.ssyr order_season
,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag request_date
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag request_date
,rd.sortmo request_month
,rd.ssyr request_season
,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag ship_date
,make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag + slag ship_date
,sd.sortmo ship_month
,sd.ssyr ship_season
,jr.mix
@ -266,11 +266,11 @@ SELECT
JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true
CROSS JOIN mxm
LEFT OUTER JOIN gld od ON
od.drange @> make_date(mxm.yr + 2021,mxm.cal,mxm.odom)
od.drange @> make_date(mxm.yr + 2022,mxm.cal,mxm.odom)
LEFT OUTER JOIN gld rd ON
rd.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag)
rd.drange @> (make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag)
LEFT OUTER JOIN gld sd ON
sd.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag)
sd.drange @> (make_date(mxm.yr + 2022,mxm.cal,mxm.odom) + rlag + slag)
)
--SELECT * FROM basemix
,log AS (

View File

@ -0,0 +1,379 @@
WITH
target AS (select target_vol vincr, target_prc pincr)
,testv AS (
SELECT
sum(units) tot
,sum(units) FILTER (WHERE iter = 'copy') base
,sum(units) FILTER (WHERE module = 'new basket') newpart
FROM
rlarp.osm_pool
WHERE
-----------------scenario----------------------------
where_clause
-----------------additional params-------------------
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND order_date <= ship_date
)
,flagv AS (
SELECT
tot
,base
,newpart
,CASE WHEN tot = 0 THEN
CASE WHEN base = 0 THEN
CASE WHEN newpart = 0 THEN
'unclean data. tested -> does not exist'
ELSE
'scale new part'
END
ELSE
'scale copy'
END
ELSE
'scale all'
END flag
FROM
testv
)
,basemix AS (
SELECT
fspr
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,director
,billto_group --master data
,shipto_group
,chan --master data
,chansub
,chan_retail
,part
,part_descr
,part_group
,branding
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,segm
,substance
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,sum(coalesce(units,0)) units --history value
,sum(coalesce(value_loc,0)) value_loc --history value
,sum(coalesce(value_usd,0)) value_usd --0
,sum(coalesce(cost_loc,0)) cost_loc --history part mix
,sum(coalesce(cost_usd,0)) cost_usd
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
,request_date --history date mix
,request_month
,request_season
,ship_date --history date mix
,ship_month
,ship_season
FROM
rlarp.osm_pool
WHERE
-----------------scenario----------------------------
where_clause
AND ship_season = 2022
-----------------additional params-------------------
AND CASE (SELECT flag FROM flagv)
WHEN 'scale all' THEN true
WHEN 'scale copy' THEN iter = 'copy'
WHEN 'scale new part' THEN module = 'new basket'
END
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND order_date <= ship_date
GROUP BY
fspr
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,director
,billto_group --master data
,shipto_group
,chan --master data
,chansub
,chan_retail
,part
,part_descr
,part_group
,branding
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,segm
,substance
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
,request_date --history date mix
,request_month
,request_season
,ship_date --history date mix
,ship_month
,ship_season
)
,vscale AS (
SELECT
(SELECT vincr::numeric FROM target) incr
,(SELECT sum(units)::numeric FROM basemix) base
,(SELECT vincr::numeric FROM target)/(SELECT sum(units)::numeric FROM basemix) factor
)
--select * from vscale
,log AS (
INSERT INTO rlarp.osm_log(doc) SELECT $$replace_iterdef$$::jsonb doc RETURNING *
)
,volume AS (
SELECT
fspr
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,director
,billto_group --master data
,shipto_group
,chan --master data
,chansub
,chan_retail
,part
,part_descr
,part_group
,branding
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,segm
,substance
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,units*s.factor units
,value_loc*s.factor value_loc
,value_usd*s.factor value_usd
,cost_loc*s.factor cost_loc
,cost_usd*s.factor cost_usd
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
,request_date --history date mix
,request_month
,request_season
,ship_date --history date mix
,ship_month
,ship_season
,'replace_version' "version"
,'replace_source'||' volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
basemix b
CROSS JOIN vscale s
CROSS JOIN log
)
,pscale AS (
SELECT
(SELECT pincr::numeric FROM target) incr
,(SELECT sum(value_loc * r_rate) FROM volume) base
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
--if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
0
ELSE
--if the target $amount is not achieved, adjust further
((SELECT pincr::numeric FROM target)-(SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(value_loc * r_rate) FROM volume)
END factor
,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume)) <> 0 THEN
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply
((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume)
ELSE
0
END
ELSE
0
END mod_price
)
--select * from pscale
,pricing AS (
SELECT
fspr
,plnt ---master data
,promo --history date mix
,terms
,bill_cust_descr --history cust mix
,ship_cust_descr --history cust mix
,dsm
,quota_rep_descr --master data
,director
,billto_group --master data
,shipto_group
,chan --master data
,chansub
,chan_retail
,part
,part_descr
,part_group
,branding
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,segm
,substance
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,0::numeric units
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_usd*s.factor END)::numeric value_usd
,0::numeric cost_loc
,0::numeric cost_usd
,calc_status --0
,flag --0
,order_date --history date mix
,order_month
,order_season
,request_date --history date mix
,request_month
,request_season
,ship_date --history date mix
,ship_month
,ship_season
,'replace_version' "version"
,'replace_source'||' price' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
volume b
CROSS JOIN pscale s
CROSS JOIN log
WHERE
s.factor <> 0 or s.mod_price <> 0
)
--select sum(value_usd), sum(units) from pricing
, ins AS (
INSERT INTO rlarp.osm_pool (SELECT * FROM pricing UNION ALL SELECT * FROM volume) RETURNING *
)
,insagg AS (
SELECT
---------customer info-----------------
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director
,segm
,substance
,chan
,chansub
---------product info------------------
,majg_descr
,ming_descr
,majs_descr
,mins_descr
--,brand
--,part_family
,part_group
,branding
--,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
,logid
,tag
,comment
--------values-------------------------
,sum(value_loc) value_loc
,sum(value_usd) value_usd
,sum(cost_loc) cost_loc
,sum(cost_usd) cost_usd
,sum(units) units
FROM
ins
GROUP BY
---------customer info-----------------
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director
,segm
,substance
,chan
,chansub
---------product info------------------
,majg_descr
,ming_descr
,majs_descr
,mins_descr
--,brand
--,part_family
,part_group
,branding
--,color
,part_descr
---------dates-------------------------
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
,logid
,tag
,comment
)
SELECT json_agg(row_to_json(insagg)) x from insagg

View File

@ -36,7 +36,7 @@ FROM
rlarp.osm_pool
WHERE
where_clause
AND order_season IN (2020,2021)
AND order_season IN (2021,2022)
GROUP BY
order_season
,order_month
@ -94,14 +94,14 @@ GROUP BY
SELECT
order_month
,seq
,SUM(units) FILTER (WHERE order_season = 2020) "2020 qty"
,SUM(units) FILTER (WHERE order_season = 2021 AND iter IN ('copy','short ship','bad_ship')) "2021 base qty"
,SUM(units) FILTER (WHERE order_season = 2021 AND iter NOT IN ('copy','short ship','bad_ship')) "2021 adj qty"
,SUM(units) FILTER (WHERE order_season = 2021) "2021 tot qty"
,SUM(value_usd) FILTER (WHERE order_season = 2020) "2020 value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2021 AND iter IN ('copy','short ship','bad_ship')) "2021 base value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2021 AND iter NOT IN ('copy','short ship','bad_ship')) "2021 adj value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2021) "2021 tot value_usd"
,SUM(units) FILTER (WHERE order_season = 2021) "2021 qty"
,SUM(units) FILTER (WHERE order_season = 2022 AND iter IN ('copy','short ship','bad_ship')) "2022 base qty"
,SUM(units) FILTER (WHERE order_season = 2022 AND iter NOT IN ('copy','short ship','bad_ship')) "2022 adj qty"
,SUM(units) FILTER (WHERE order_season = 2022) "2022 tot qty"
,SUM(value_usd) FILTER (WHERE order_season = 2021) "2021 value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2022 AND iter IN ('copy','short ship','bad_ship')) "2022 base value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2022 AND iter NOT IN ('copy','short ship','bad_ship')) "2022 adj value_usd"
,SUM(value_usd) FILTER (WHERE order_season = 2022) "2022 tot value_usd"
FROM
months
GROUP BY
@ -113,14 +113,14 @@ GROUP BY
,mlist AS (
SELECT
mseq.m order_month
,"2020 qty"
,"2021 base qty"
,"2021 adj qty"
,"2021 tot qty"
,"2020 value_usd"
,"2021 base value_usd"
,"2021 adj value_usd"
,"2021 tot value_usd"
,"2021 qty"
,"2022 base qty"
,"2022 adj qty"
,"2022 tot qty"
,"2021 value_usd"
,"2022 base value_usd"
,"2022 adj value_usd"
,"2022 tot value_usd"
FROM
mseq
LEFT OUTER JOIN mpvt ON