Merge branch 'feature/newparts' into dev

This commit is contained in:
Paul Trowbridge 2019-06-19 23:40:49 -04:00
commit 4b6cbd3ac5
8 changed files with 666 additions and 179 deletions

View File

@ -174,7 +174,7 @@ target AS (select target_increment incr)
_month _month
,seq ,seq
,promo ,promo
,round((dom_wa/value_usd)::numeric,0)::int odom ,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom
,round((rlag_wa/value_usd)::numeric,0)::int rlag ,round((rlag_wa/value_usd)::numeric,0)::int rlag
,round((slag_wa/value_usd)::numeric,0)::int slag ,round((slag_wa/value_usd)::numeric,0)::int slag
,value_usd/sum(value_usd) over (partition by _month) momix ,value_usd/sum(value_usd) over (partition by _month) momix

View File

@ -169,7 +169,7 @@ target AS (select target_volume vincr, target_price pincr)
_month _month
,seq ,seq
,promo ,promo
,round((dom_wa/value_usd)::numeric,0)::int odom ,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom
,round((rlag_wa/value_usd)::numeric,0)::int rlag ,round((rlag_wa/value_usd)::numeric,0)::int rlag
,round((slag_wa/value_usd)::numeric,0)::int slag ,round((slag_wa/value_usd)::numeric,0)::int slag
,value_usd/sum(value_usd) over (partition by _month) momix ,value_usd/sum(value_usd) over (partition by _month) momix

View File

@ -11,177 +11,176 @@ repl AS (
FROM FROM
( (
VALUES VALUES
('GAB12000DE2','Garden Bowl - Slate Blue','GAB12000A34C012LRTOQ'), ('GAB12000DE2','Garden Bowl - Slate Blue','GAB12000A34C012LRTOQ',0.93886),
('GAB14000DE2','Garden Bowl - Slate Blue','GAB14000A34C012LRTOT'), ('GAB14000DE2','Garden Bowl - Slate Blue','GAB14000A34C012LRTOT',1.30893),
('GAB18000DE2','Garden Bowl - Slate Blue','GAB18000A34C006LRTOW'), ('GAB18000DE2','Garden Bowl - Slate Blue','GAB18000A34C006LRTOW',2.04076),
('GAB22000DE2','Garden Bowl - Slate Blue','GAB22000A34C006LRTOZ'), ('GAB22000DE2','Garden Bowl - Slate Blue','GAB22000A34C006LRTOZ',3.54985),
('GAB12000BG3','Garden Bowl - Teal','GAB12000A34C012LRTOQ'), ('GAB12000BG3','Garden Bowl - Teal','GAB12000A34C012LRTOQ',0.93886),
('GAB14000BG3','Garden Bowl - Teal','GAB14000A34C012LRTOT'), ('GAB14000BG3','Garden Bowl - Teal','GAB14000A34C012LRTOT',1.30893),
('GAB18000BG3','Garden Bowl - Teal','GAB18000A34C006LRTOW'), ('GAB18000BG3','Garden Bowl - Teal','GAB18000A34C006LRTOW',2.04076),
('GAB22000BG3','Garden Bowl - Teal','GAB22000A34C006LRTOZ'), ('GAB22000BG3','Garden Bowl - Teal','GAB22000A34C006LRTOZ',3.54985),
('CNA06000A42','Caribbean Planter - Warm Gray','CNA06000A50C024LRCGA'), ('CNA06000A42','Caribbean Planter - Warm Gray','CNA06000A50C024LRCGA',0.36037),
('CNA08000A42','Caribbean Planter - Warm Gray','CNA08000A50C024LRCGC'), ('CNA08000A42','Caribbean Planter - Warm Gray','CNA08000A50C024LRCGC',0.44575),
('CNA06000F89','Caribbean Planter - Raspberry','CNA06000A50C024LRCGA'), ('CNA06000F89','Caribbean Planter - Raspberry','CNA06000A50C024LRCGA',0.36222),
('CNA08000F89','Caribbean Planter - Raspberry','CNA08000A50C024LRCGC'), ('CNA08000F89','Caribbean Planter - Raspberry','CNA08000A50C024LRCGC',0.45024),
('CNA10000F89','Caribbean Planter - Raspberry','CNA10000A42C012LRBXI'), ('CNA10000F89','Caribbean Planter - Raspberry','CNA10000A42C012LRBXI',0.65195),
('CNA12000F89','Caribbean Planter - Raspberry','CNA12000A42C012LRBXJ'), ('CNA12000F89','Caribbean Planter - Raspberry','CNA12000A42C012LRBXJ',1.63119),
('CNA06000BG3','Caribbean Planter - Teal','CNA06000A50C024LRCGA'), ('CNA06000BG3','Caribbean Planter - Teal','CNA06000A50C024LRCGA',0.36222),
('CNA08000BG3','Caribbean Planter - Teal','CNA08000A50C024LRCGC'), ('CNA08000BG3','Caribbean Planter - Teal','CNA08000A50C024LRCGC',0.45024),
('CNA10000BG3','Caribbean Planter - Teal','CNA10000A42C012LRBXI'), ('CNA10000BG3','Caribbean Planter - Teal','CNA10000A42C012LRBXI',0.65195),
('CNA12000BG3','Caribbean Planter - Teal','CNA12000A42C012LRBXJ'), ('CNA12000BG3','Caribbean Planter - Teal','CNA12000A42C012LRBXJ',1.63119),
('CNA06000A10','Caribbean Planter - White','CNA06000A50C024LRCGA'), ('CNA06000A10','Caribbean Planter - White','CNA06000A50C024LRCGA',0.35215),
('CNA08000A10','Caribbean Planter - White','CNA08000A50C024LRCGC'), ('CNA08000A10','Caribbean Planter - White','CNA08000A50C024LRCGC',0.44641),
('CNA10000A10','Caribbean Planter - White','CNA10000A42C012LRBXI'), ('CNA10000A10','Caribbean Planter - White','CNA10000A42C012LRBXI',0.64485),
('CNA12000A10','Caribbean Planter - White','CNA12000A42C012LRBXJ'), ('CNA12000A10','Caribbean Planter - White','CNA12000A42C012LRBXJ',1.61797),
('CNA30000A10','Caribbean Planter - White','CNA30000G18C002LRCDG'), ('CNA30000A10','Caribbean Planter - White','CNA30000G18C002LRCDG',28.85),
('LIA06000DE2','Classic Planter - Slate Blue','LIA06000A34C024LRTIV'), ('LIA06000DE2','Classic Planter - Slate Blue','LIA06000A34C024LRTIV',0.35842),
('LIA08000DE2','Classic Planter - Slate Blue','LIA08000A34C024LRTIZ'), ('LIA08000DE2','Classic Planter - Slate Blue','LIA08000A34C024LRTIZ',0.56212),
('LIA10000DE2','Classic Planter - Slate Blue','LIA10000A34C012LRTJD'), ('LIA10000DE2','Classic Planter - Slate Blue','LIA10000A34C012LRTJD',1.8113),
('LIA12000DE2','Classic Planter - Slate Blue','LIA12000A34C012LRTJH'), ('LIA12000DE2','Classic Planter - Slate Blue','LIA12000A34C012LRTJH',2.42383),
('LIA14000DE2','Classic Planter - Slate Blue','LIA14000A34C012LRTJL'), ('LIA14000DE2','Classic Planter - Slate Blue','LIA14000A34C012LRTJL',2.73708),
('LIA16000DE2','Classic Planter - Slate Blue','LIA16000A34C006LRTJP'), ('LIA16000DE2','Classic Planter - Slate Blue','LIA16000A34C006LRTJP',3.05778),
('LIA20000DE2','Classic Planter - Slate Blue','LIA20000A34C006LRTJT'), ('LIA20000DE2','Classic Planter - Slate Blue','LIA20000A34C006LRTJT',5.63275),
('LIA24000DE2','Classic Planter - Slate Blue','LIA24000A34C006LRTJY'), ('LIA24000DE2','Classic Planter - Slate Blue','LIA24000A34C006LRTJY',6.35725),
('LIA06000B78','Classic Planter - Seafoam','LIA06000A34C024LRTIV'), ('LIA06000B78','Classic Planter - Seafoam','LIA06000A34C024LRTIV',0.35842),
('LIA08000B78','Classic Planter - Seafoam','LIA08000A34C024LRTIZ'), ('LIA08000B78','Classic Planter - Seafoam','LIA08000A34C024LRTIZ',0.56212),
('LIA10000B78','Classic Planter - Seafoam','LIA10000A34C012LRTJD'), ('LIA10000B78','Classic Planter - Seafoam','LIA10000A34C012LRTJD',1.8113),
('LIA12000B78','Classic Planter - Seafoam','LIA12000A34C012LRTJH'), ('LIA12000B78','Classic Planter - Seafoam','LIA12000A34C012LRTJH',2.42383),
('LIA14000B78','Classic Planter - Seafoam','LIA14000A34C012LRTJL'), ('LIA14000B78','Classic Planter - Seafoam','LIA14000A34C012LRTJL',2.73708),
('LIA16000B78','Classic Planter - Seafoam','LIA16000A34C006LRTJP'), ('LIA16000B78','Classic Planter - Seafoam','LIA16000A34C006LRTJP',3.05778),
('LIA20000B78','Classic Planter - Seafoam','LIA20000A34C006LRTJT'), ('LIA20000B78','Classic Planter - Seafoam','LIA20000A34C006LRTJT',5.63275),
('LIA24000B78','Classic Planter - Seafoam','LIA24000A34C006LRTJY'), ('LIA24000B78','Classic Planter - Seafoam','LIA24000A34C006LRTJY',6.35725),
('SLI06000DE2','Classic Saucer - Slate Blue','SLI06000A34C024LRTKB'), ('SLI06000DE2','Classic Saucer - Slate Blue','SLI06000A34C024LRTKB',0.18237),
('SLI08000DE2','Classic Saucer - Slate Blue','SLI08000A34C024LRTKF'), ('SLI08000DE2','Classic Saucer - Slate Blue','SLI08000A34C024LRTKF',0.29674),
('SLI10000DE2','Classic Saucer - Slate Blue','SLI10000A34C012LRTKJ'), ('SLI10000DE2','Classic Saucer - Slate Blue','SLI10000A34C012LRTKJ',0.54887),
('SLI12000DE2','Classic Saucer - Slate Blue','SLI12000A34C012LAH13'), ('SLI12000DE2','Classic Saucer - Slate Blue','SLI12000A34C012LAH13',0.72483),
('SLI14000DE2','Classic Saucer - Slate Blue','SLI14000A34C012LAH16'), ('SLI14000DE2','Classic Saucer - Slate Blue','SLI14000A34C012LAH16',0.99295),
('SLI17000DE2','Classic Saucer - Slate Blue','SLI17000A34C012LAH19'), ('SLI17000DE2','Classic Saucer - Slate Blue','SLI17000A34C012LAH19',1.10433),
('SLI20000DE2','Classic Saucer - Slate Blue','SLI20000A34C006LAH24'), ('SLI20000DE2','Classic Saucer - Slate Blue','SLI20000A34C006LAH24',1.0319),
('SLI24000DE2','Classic Saucer - Slate Blue','SLI24000A34C006LRTLD'), ('SLI24000DE2','Classic Saucer - Slate Blue','SLI24000A34C006LRTLD',1.95471),
('SLI06000B78','Classic Saucer - Seafoam','SLI06000A34C024LRTKB'), ('SLI06000B78','Classic Saucer - Seafoam','SLI06000A34C024LRTKB',0.18237),
('SLI08000B78','Classic Saucer - Seafoam','SLI08000A34C024LRTKF'), ('SLI08000B78','Classic Saucer - Seafoam','SLI08000A34C024LRTKF',0.29674),
('SLI10000B78','Classic Saucer - Seafoam','SLI10000A34C012LRTKJ'), ('SLI10000B78','Classic Saucer - Seafoam','SLI10000A34C012LRTKJ',0.54887),
('SLI12000B78','Classic Saucer - Seafoam','SLI12000A34C012LAH13'), ('SLI12000B78','Classic Saucer - Seafoam','SLI12000A34C012LAH13',0.72483),
('SLI14000B78','Classic Saucer - Seafoam','SLI14000A34C012LAH16'), ('SLI14000B78','Classic Saucer - Seafoam','SLI14000A34C012LAH16',0.99295),
('SLI16000B78','Classic Saucer - Seafoam','SAA14001A10C006LRCDJ'), ('SLI16000B78','Classic Saucer - Seafoam','SAA14001A10C006LRCDJ',1.10433),
('SLI20000B78','Classic Saucer - Seafoam','SLI20000A34C006LAH24'), ('SLI20000B78','Classic Saucer - Seafoam','SLI20000A34C006LAH24',1.0319),
('SLI24000B78','Classic Saucer - Seafoam','SLI24000A34C006LRTLD'), ('SLI24000B78','Classic Saucer - Seafoam','SLI24000A34C006LRTLD',1.95471),
('ECA06000DE2','Eclipse Planter - Slate Blue','ECA06000A101009LRCIG'), ('ECA06000DE2','Eclipse Planter - Slate Blue','ECA06000A101009LRCIG',0.42036),
('ECA08000DE2','Eclipse Planter - Slate Blue','ECA08000A101006LRCID'), ('ECA08000DE2','Eclipse Planter - Slate Blue','ECA08000A101006LRCID',0.63429),
('ECA10000DE2','Eclipse Planter - Slate Blue','ECA10000A341020LRCEL'), ('ECA10000DE2','Eclipse Planter - Slate Blue','ECA10000A341020LRCEL',0.92453),
('ECA12000DE2','Eclipse Planter - Slate Blue','ECA12000A101006LRCIA'), ('ECA12000DE2','Eclipse Planter - Slate Blue','ECA12000A101006LRCIA',1.25858),
('ECA16000DE2','Eclipse Planter - Slate Blue','ECA16000A34C010LRCEX'), ('ECA16000DE2','Eclipse Planter - Slate Blue','ECA16000A34C010LRCEX',2.57535),
('ECA20000DE2','Eclipse Planter - Slate Blue','ECA20000A341006LRCEU'), ('ECA20000DE2','Eclipse Planter - Slate Blue','ECA20000A341006LRCEU',4.17568),
('ECA06000B78','Eclipse Planter - Seafoam','ECA06000A101009LRCIG'), ('ECA06000B78','Eclipse Planter - Seafoam','ECA06000A101009LRCIG',0.42036),
('ECA08000B78','Eclipse Planter - Seafoam','ECA08000A101006LRCID'), ('ECA08000B78','Eclipse Planter - Seafoam','ECA08000A101006LRCID',0.63429),
('ECA10000B78','Eclipse Planter - Seafoam','ECA10000A341020LRCEL'), ('ECA10000B78','Eclipse Planter - Seafoam','ECA10000A341020LRCEL',0.92453),
('ECA12000B78','Eclipse Planter - Seafoam','ECA12000A101006LRCIA'), ('ECA12000B78','Eclipse Planter - Seafoam','ECA12000A101006LRCIA',1.25858),
('ECA16000B78','Eclipse Planter - Seafoam','ECA16000A34C010LRCEX'), ('ECA16000B78','Eclipse Planter - Seafoam','ECA16000A34C010LRCEX',2.57535),
('ECA20000B78','Eclipse Planter - Seafoam','ECA20000A341006LRCEU'), ('ECA20000B78','Eclipse Planter - Seafoam','ECA20000A341006LRCEU',4.17568),
('GDP08000DE2','Hanging Garden Planter - Slate Blue','SAA14001A10C006LRCDJ'), ('GDP08000DE2','Hanging Garden Planter - Slate Blue','SAA14001A10C006LRCDJ',1.5),
('GDP08000BG3','Hanging Garden Planter - Teal','SAA14001A10C006LRCDJ'), ('GDP08000BG3','Hanging Garden Planter - Teal','SAA14001A10C006LRCDJ',1.5),
('MSA12001DE2','Marina Planter - Slate Blue','MSA12001A341008LRCFQ'), ('MSA12001DE2','Marina Planter - Slate Blue','MSA12001A341008LRCFQ',1.85199),
('MSA16001DE2','Marina Planter - Slate Blue','MSA16001A34C004LRAYN'), ('MSA16001DE2','Marina Planter - Slate Blue','MSA16001A34C004LRAYN',2.80127),
('MSA20001DE2','Marina Planter - Slate Blue','MSA20001A34C004LRCFW'), ('MSA20001DE2','Marina Planter - Slate Blue','MSA20001A34C004LRCFW',4.88869),
('MSA12001A42','Marina Planter - Warm Gray','MSA12001A341008LRCFQ'), ('MSA12001A42','Marina Planter - Warm Gray','MSA12001A341008LRCFQ',1.85199),
('MSA16001A42','Marina Planter - Warm Gray','MSA16001A34C004LRAYN'), ('MSA16001A42','Marina Planter - Warm Gray','MSA16001A34C004LRAYN',2.80127),
('MSA20001A42','Marina Planter - Warm Gray','MSA20001A34C004LRCFW'), ('MSA20001A42','Marina Planter - Warm Gray','MSA20001A34C004LRCFW',4.88869),
('MSA12001B78','Marina Planter - Seafoam','MSA12001A341008LRCFQ'), ('MSA12001B78','Marina Planter - Seafoam','MSA12001A341008LRCFQ',1.85199),
('MSA16001B78','Marina Planter - Seafoam','MSA16001A34C004LRAYN'), ('MSA16001B78','Marina Planter - Seafoam','MSA16001A34C004LRAYN',2.80127),
('MSA20001B78','Marina Planter - Seafoam','MSA20001A34C004LRCFW'), ('MSA20001B78','Marina Planter - Seafoam','MSA20001A34C004LRCFW',4.88869),
('SEA07001DE2','Sedona Planter - Slate Blue','SEA07001B15C008LRAZR'), ('SEA07001DE2','Sedona Planter - Slate Blue','SEA07001B15C008LRAZR',0.60131),
('SEA09001DE2','Sedona Planter - Slate Blue','SEA09001B15C008LRAZS'), ('SEA09001DE2','Sedona Planter - Slate Blue','SEA09001B15C008LRAZS',0.91061),
('SEA12001DE2','Sedona Planter - Slate Blue','SEA12001B15C006LRAZU'), ('SEA12001DE2','Sedona Planter - Slate Blue','SEA12001B15C006LRAZU',1.55347),
('SEA14001DE2','Sedona Planter - Slate Blue','SEA14001B15C006LRAZT'), ('SEA14001DE2','Sedona Planter - Slate Blue','SEA14001B15C006LRAZT',2.14701),
('SEA16000DE2','Sedona Planter - Slate Blue','SAA14001A10C006LRCDJ'), ('SEA16000DE2','Sedona Planter - Slate Blue','SAA14001A10C006LRCDJ',2.51344),
('SEA07001B78','Sedona Planter - Seafoam','SEA07001B15C008LRAZR'), ('SEA07001B78','Sedona Planter - Seafoam','SEA07001B15C008LRAZR',0.60131),
('SEA09001B78','Sedona Planter - Seafoam','SEA09001B15C008LRAZS'), ('SEA09001B78','Sedona Planter - Seafoam','SEA09001B15C008LRAZS',0.91061),
('SEA12001B78','Sedona Planter - Seafoam','SEA12001B15C006LRAZU'), ('SEA12001B78','Sedona Planter - Seafoam','SEA12001B15C006LRAZU',1.55347),
('SEA14001B78','Sedona Planter - Seafoam','SEA14001B15C006LRAZT'), ('SEA14001B78','Sedona Planter - Seafoam','SEA14001B15C006LRAZT',2.14701),
('SEA16000B78','Sedona Planter - Seafoam','SAA14001A10C006LRCDJ'), ('SEA16000B78','Sedona Planter - Seafoam','SAA14001A10C006LRCDJ',2.51344),
('SEA07001A42','Sedona Planter - Warm Gray','SEA07001B15C008LRAZR'), ('SEA07001A42','Sedona Planter - Warm Gray','SEA07001B15C008LRAZR',0.60131),
('SEA09001A42','Sedona Planter - Warm Gray','SEA09001B15C008LRAZS'), ('SEA09001A42','Sedona Planter - Warm Gray','SEA09001B15C008LRAZS',0.91061),
('SEA12001A42','Sedona Planter - Warm Gray','SEA12001B15C006LRAZU'), ('SEA12001A42','Sedona Planter - Warm Gray','SEA12001B15C006LRAZU',1.55347),
('SEA14001A42','Sedona Planter - Warm Gray','SEA14001B15C006LRAZT'), ('SEA14001A42','Sedona Planter - Warm Gray','SEA14001B15C006LRAZT',2.14701),
('SEA16000A42','Sedona Planter - Warm Gray','SAA14001A10C006LRCDJ'), ('SEA16000A42','Sedona Planter - Warm Gray','SAA14001A10C006LRCDJ',2.51344),
('VNP18000A42','Venetian Flower Box - Warm Gray','VNP18000A34C006LRTPN'), ('VNP18000A42','Venetian Flower Box - Warm Gray','VNP18000A34C006LRTPN',1.44406),
('VNP24000A42','Venetian Flower Box - Warm Gray','VNP24000A34C006LRTPR'), ('VNP24000A42','Venetian Flower Box - Warm Gray','VNP24000A34C006LRTPR',1.63875),
('VNP30000A42','Venetian Flower Box - Warm Gray','VNP30000A34C006LRTPV'), ('VNP30000A42','Venetian Flower Box - Warm Gray','VNP30000A34C006LRTPV',2.31994),
('VNP18000A10','Venetian Flower Box - White','VNP18000A34C006LRTPN'), ('VNP18000A10','Venetian Flower Box - White','VNP18000A34C006LRTPN',1.44406),
('VNP24000A10','Venetian Flower Box - White','VNP24000A34C006LRTPR'), ('VNP24000A10','Venetian Flower Box - White','VNP24000A34C006LRTPR',1.63875),
('VNP30000A10','Venetian Flower Box - White','VNP30000A34C006LRTPV'), ('VNP30000A10','Venetian Flower Box - White','VNP30000A34C006LRTPV',2.31994),
('SVN18000A42','Venetian Flower Box Tray - Warm Gray','SVN18000A34C006LRTPZ'), ('SVN18000A42','Venetian Flower Box Tray - Warm Gray','SVN18000A34C006LRTPZ',0.94787),
('SVN24000A42','Venetian Flower Box Tray - Warm Gray','SVN24000A34C006LRTQD'), ('SVN24000A42','Venetian Flower Box Tray - Warm Gray','SVN24000A34C006LRTQD',1.04921),
('SVN30000A42','Venetian Flower Box Tray - Warm Gray','SVN30000A34C006LRTQH'), ('SVN30000A42','Venetian Flower Box Tray - Warm Gray','SVN30000A34C006LRTQH',1.25193),
('SVN18000A10','Venetian Flower Box Tray - White','SVN18000A34C006LRTPZ'), ('SVN18000A10','Venetian Flower Box Tray - White','SVN18000A34C006LRTPZ',0.94787),
('SVN24000A10','Venetian Flower Box Tray - White','SVN24000A34C006LRTQD'), ('SVN24000A10','Venetian Flower Box Tray - White','SVN24000A34C006LRTQD',1.04921),
('SVN30000A10','Venetian Flower Box Tray - White','SVN30000A34C006LRTQH'), ('SVN30000A10','Venetian Flower Box Tray - White','SVN30000A34C006LRTQH',1.25193),
('ASP06000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ASP06000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ',0.852601662887377),
('ASP08000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ASP08000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ',1.4348492660222),
('ASP10000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ASP10000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ',2.69581191222571),
('ASP12000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ASP12000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ',4.1862917611489),
('ASP16000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ASP16000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ',9.09797526283241),
('ASP06000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ASP06000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ',0.852601662887377),
('ASP08000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ASP08000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ',1.4348492660222),
('ASP10000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ASP10000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ',2.69581191222571),
('ASP12000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ASP12000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ',4.1862917611489),
('ASP16000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ASP16000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ',9.09797526283241),
('ASP06000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ASP06000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ',0.852601662887377),
('ASP08000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ASP08000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ',1.4348492660222),
('ASP10000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ASP10000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ',2.69581191222571),
('ASP12000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ASP12000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ',4.1862917611489),
('ASP16000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ASP16000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ',9.09797526283241),
('ASP06000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ASP06000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ',0.852601662887377),
('ASP08000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ASP08000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ',1.4348492660222),
('ASP10000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ASP10000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ',2.69581191222571),
('ASP12000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ASP12000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ',4.1862917611489),
('ASP16000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ASP16000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ',9.09797526283241),
('ARP06000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ARP06000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ',0.70132159315339),
('ARP08000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ARP08000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ',1.16639446371434),
('ARP10000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ARP10000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ',2.06032580911152),
('ARP12000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ARP12000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ',3.3063246409675),
('ARP16000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'), ('ARP16000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ',7.29303859560353),
('ARP06000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ARP06000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ',0.70132159315339),
('ARP08000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ARP08000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ',1.16639446371434),
('ARP10000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ARP10000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ',2.06032580911152),
('ARP12000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ARP12000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ',3.3063246409675),
('ARP16000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'), ('ARP16000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ',7.29303859560353),
('ARP06000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ARP06000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ',0.70132159315339),
('ARP08000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ARP08000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ',1.16639446371434),
('ARP10000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ARP10000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ',2.06032580911152),
('ARP12000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ARP12000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ',3.3063246409675),
('ARP16000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('ARP16000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ',7.29303859560353),
('ARP06000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ARP06000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ',0.70132159315339),
('ARP08000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ARP08000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ',1.16639446371434),
('ARP10000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ARP10000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ',2.06032580911152),
('ARP12000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ARP12000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ',3.3063246409675),
('ARP16000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'), ('ARP16000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ',7.29303859560353),
('ANP12000A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ'), ('ANP12000A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ',7.09567010761259),
('ANP15000A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ'), ('ANP15000A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ',10.3452077597572),
('ANP17500A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ'), ('ANP17500A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ',14.4071298249379),
('CAS12000P26','Cascade Tall Square Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('CAS12000P26','Cascade Tall Square Planter - Black Onyx','SAA14001A10C006LRCDJ',6.29314316635745),
('CAS15000P26','Cascade Tall Square Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('CAS15000P26','Cascade Tall Square Planter - Black Onyx','SAA14001A10C006LRCDJ',15.3787074829932),
('CAS12000P80','Cascade Tall Square Planter - Glossy White','SAA14001A10C006LRCDJ'), ('CAS12000P80','Cascade Tall Square Planter - Glossy White','SAA14001A10C006LRCDJ',6.29314316635745),
('CAS15000P80','Cascade Tall Square Planter - Glossy White','SAA14001A10C006LRCDJ'), ('CAS15000P80','Cascade Tall Square Planter - Glossy White','SAA14001A10C006LRCDJ',15.3787074829932),
('CAR12000P26','Cascade Tall Round Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('CAR12000P26','Cascade Tall Round Planter - Black Onyx','SAA14001A10C006LRCDJ',8.71982072275551),
('CAR15000P26','Cascade Tall Round Planter - Black Onyx','SAA14001A10C006LRCDJ'), ('CAR15000P26','Cascade Tall Round Planter - Black Onyx','SAA14001A10C006LRCDJ',15.8462292221236),
('CAR12000P80','Cascade Tall Round Planter - Glossy White','SAA14001A10C006LRCDJ'), ('CAR12000P80','Cascade Tall Round Planter - Glossy White','SAA14001A10C006LRCDJ',8.71982072275551),
('CAR15000P80','Cascade Tall Round Planter - Glossy White','SAA14001A10C006LRCDJ'), ('CAR15000P80','Cascade Tall Round Planter - Glossy White','SAA14001A10C006LRCDJ',15.8462292221236),
('SKR12000G27','Santa Fe Round Planter - Black Sand','SAA14001A10C006LRCDJ'), ('SKR12000G27','Santa Fe Round Planter - Black Sand','SAA14001A10C006LRCDJ',4.42057974300831),
('SKR16000G27','Santa Fe Round Planter - Black Sand','SAA14001A10C006LRCDJ'), ('SKR16000G27','Santa Fe Round Planter - Black Sand','SAA14001A10C006LRCDJ',9.79167124866476),
('SKR12000E66','Santa Fe Round Planter - Cavern Clay','SAA14001A10C006LRCDJ'), ('SKR12000E66','Santa Fe Round Planter - Cavern Clay','SAA14001A10C006LRCDJ',4.42057974300831),
('SKR16000E66','Santa Fe Round Planter - Cavern Clay','SAA14001A10C006LRCDJ'), ('SKR16000E66','Santa Fe Round Planter - Cavern Clay','SAA14001A10C006LRCDJ',9.79167124866476),
('SKR12000A56','Santa Fe Round Planter - Pebble Gray','SAA14001A10C006LRCDJ'), ('SKR12000A56','Santa Fe Round Planter - Pebble Gray','SAA14001A10C006LRCDJ',4.42057974300831),
('SKR16000A56','Santa Fe Round Planter - Pebble Gray','SAA14001A10C006LRCDJ'), ('SKR16000A56','Santa Fe Round Planter - Pebble Gray','SAA14001A10C006LRCDJ',9.79167124866476),
('SKS12000G27','Santa Fe Square Planter - Black Sand','SAA14001A10C006LRCDJ'), ('SKS12000G27','Santa Fe Square Planter - Black Sand','SAA14001A10C006LRCDJ',5.54815910808768),
('SKS16000G27','Santa Fe Square Planter - Black Sand','SAA14001A10C006LRCDJ'), ('SKS16000G27','Santa Fe Square Planter - Black Sand','SAA14001A10C006LRCDJ',10.8425160791589),
('SKS12000E66','Santa Fe Square Planter - Cavern Clay','SAA14001A10C006LRCDJ'), ('SKS12000E66','Santa Fe Square Planter - Cavern Clay','SAA14001A10C006LRCDJ',5.54815910808768),
('SKS16000E66','Santa Fe Square Planter - Cavern Clay','SAA14001A10C006LRCDJ'), ('SKS16000E66','Santa Fe Square Planter - Cavern Clay','SAA14001A10C006LRCDJ',10.8425160791589),
('SKS12000A56','Santa Fe Square Planter - Pebble Gray','SAA14001A10C006LRCDJ'), ('SKS12000A56','Santa Fe Square Planter - Pebble Gray','SAA14001A10C006LRCDJ',5.54815910808768),
('SKS16000A56','Santa Fe Square Planter - Pebble Gray','SAA14001A10C006LRCDJ'), ('SKS16000A56','Santa Fe Square Planter - Pebble Gray','SAA14001A10C006LRCDJ',10.8425160791589),
('WBP16000P82','Whiskey Barrel Planter - Aged Oak','SAA14001A10C006LRCDJ'), ('WBP16000P82','Whiskey Barrel Planter - Aged Oak','SAA14001A10C006LRCDJ',4.5)
('0','Planter Trellis 6-Pack - Black','SAA14001A10C006LRCDJ') ) x("target","descr","clone","cost")
) x("target","descr","clone")
) )
,istka AS ( ,istka AS (
INSERT INTO lgdat.stka INSERT INTO lgdat.stka
@ -878,7 +877,7 @@ repl AS (
,cgburv ,cgburv
,cgtptd ,cgtptd
,cgsdat ,cgsdat
,cgstcs ,cost cgstcs
,cgaccs ,cgaccs
,cgavcs ,cgavcs
,cgstoc ,cgstoc
@ -930,7 +929,7 @@ repl AS (
,chscr ,chscr
,chlcr ,chlcr
,chsdat ,chsdat
,chstcs ,cost chstcs
,chaccs ,chaccs
,chavcs ,chavcs
,chsdr ,chsdr
@ -976,7 +975,7 @@ repl AS (
SELECT SELECT
target y0part target y0part
,y0plnt ,y0plnt
,y0stcs ,cost y0stcs
,y0accs ,y0accs
,y0avcs ,y0avcs
,y0suc ,y0suc

View File

@ -33,6 +33,7 @@ SELECT
,to_char(sum(sales_adj),'999,999,999') sales_adj ,to_char(sum(sales_adj),'999,999,999') sales_adj
,to_char(sum(sales_adj - scogs_adj),'999,999,999') margin_adj ,to_char(sum(sales_adj - scogs_adj),'999,999,999') margin_adj
,count(iterdef) "# of changes" ,count(iterdef) "# of changes"
,(max(iterdef->>'stamp'))::timestamptz "last edit"
FROM FROM
preagg preagg
GROUP BY GROUP BY

View File

@ -0,0 +1,336 @@
BEGIN;
WITH
repl AS (
SELECT * FROM
(
VALUES
('MOW24000A47E880','MOW24000A47E880')
) as x(orig,fix)
)
,SEG AS (
SELECT
x.GLEC
,x.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)
)
,MG AS (
SELECT
X.F1, X.MING, X.GRP
FROM
(
VALUES
('L','000','Branded'),
('L','B10','Branded'),
('L','B11','Branded'),
('L','B52','Branded'),
('L','C10','Branded'),
('L','D12','Branded'),
('L','M11','Branded'),
('L','P12','Branded'),
('L','P13','Branded'),
('L','S10','Branded'),
('L','Y10','Branded'),
('L','Y11','Branded'),
('L','Y12','Branded'),
('P','B10','Branded'),
('P','B11','Branded'),
('P','B52','Branded')
) AS X (F1, MING, GRP)
)
,REPC AS (
SELECT
LTRIM(RTRIM(C.A9)) RCODE
,LTRIM(RTRIM(C.A9)) || ' - ' || 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'
)
--MOLD DESCRIPTIONS
,MD AS (
SELECT
U.MOLD
,MAX(U.DESCR) DESCR
FROM
(
SELECT
SUBSTR(M.AVPART,1,8) MOLD
,MAX(M.AVDES1) DESCR
FROM
LGDAT.STKMM M
WHERE
LENGTH(M.AVPART) > 8
AND SUBSTR(M.AVGLED,1,1) <= '2'
GROUP BY
SUBSTR(M.AVPART,1,8)
UNION ALL
SELECT
SUBSTR(P.AWPART,1,8) MOLD
,MAX(P.AWDES1) DESCR
FROM
LGDAT.STKMP P
WHERE
LENGTH(P.AWPART) > 8
AND SUBSTR(P.AWGLED,1,1) <= '2'
GROUP BY
SUBSTR(P.AWPART,1,8)
) U
GROUP BY
U.MOLD
)
----------------------------------------------------sales major codes----------------------------------------------------------------------------------------------------------------------------------
,SJ AS (
SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = ''
)
----------------------------------------------------sales minor codes----------------------------------------------------------------------------------------------------------------------------------
,SI AS (
SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> ''
)
,copr AS (
SELECT
LTRIM(RTRIM(A9)) AS COMP,
A30 AS DESCR,
SUBSTR(C.A249,242,2) CURR,
SUBSTR(C.A249,32,4) AS GL,
SUBSTR(C.A249,190,4) AS AR,
SUBSTR(C.A249,182,4) AS AP,
SUBSTR(C.A249,198,4) AS FA,
SUBSTR(C.A249,238,4) AS IC ,
SUBSTR(D.A249,9,5) CONS_FUNC
FROM
LGDAT.CODE
LEFT OUTER JOIN LGDAT.NAME C ON
'C0000'||LTRIM(RTRIM(A9)) = C.A7
LEFT OUTER JOIN LGDAT.NAME D ON
'D0000'||LTRIM(RTRIM(A9)) = D.A7
WHERE
A2 = 'AA' OR A2 IS NULL
)
,x AS (
SELECT
o.part origpart
,repl.fix as part
,COALESCE(m.avdplt,p.awdplt) plnt
,COALESCE(m.avglcd, p.awgldc) ord_gldc
,COALESCE(m.avmajg,p.awmajg) majg
,COALESCE(m.avming,p.awming) ming
,COALESCE(m.avmajs,p.awmajs) majs
,COALESCE(m.avmins,p.awmins) mins
,COALESCE(m.avglcd,p.awgldc) gldc
,COALESCE(m.avgled,p.awgled) glec
,COALESCE(m.avharm,p.awharm) harm
,COALESCE(m.avclss,p.awclss) clss
,SUBSTR(COALESCE(m."avcpt#",p."awvpt#"),1,1) brand
,COALESCE(m.avassc,p.awassc) assc
,COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) stdcost
,copr.curr c_currency
,cx.rate c_rate
,SUBSTR(repl.fix,1,3)||coalesce(' - '||F.DESCR,'') part_family
,SUBSTRING(repl.fix,1,8)||coalesce(' - '||MD.DESCR,'') part_group
,COALESCE(MG.GRP,'Unbranded') branding
,CASE WHEN substring(COALESCE(m.avgled, p.awgled),1,1) <= '2' THEN SUBSTRING(repl.fix,9,3) ELSE '' END color
,COALESCE(SEG.SEGM,'Other') segm
,COALESCE(m.avmajg,p.awmajg)||COALESCE(' - '||BQDES,'') majg_descr
,COALESCE(m.avming,p.awming)||COALESCE(' - '||BRDES,'') ming_descr
,COALESCE(m.avmajs,p.awmajs)||COALESCE(' - '||SJ.BSDES1,'') majs_descr
,COALESCE(m.avmins,p.awmins)||COALESCE(' - '||SI.BSDES1,'') mins_descr
--quota rep--------------------------------------------
,RTRIM(
COALESCE(
--retail items go to currep, or if null go to 90005
CASE WHEN COALESCE(m.avgled,p.awgled) IN ('1RE','1CU') THEN
CASE WHEN bc.bvctry = 'CAN' THEN
--Rachel Bowman
'50300'
ELSE
--retail chain got to Mark Wilkinson
CASE COALESCE(cg.cgrp,bc.bvname)
WHEN 'THE HOME DEPOT' THEN '90005'
WHEN 'DO IT BEST' THEN '90005'
WHEN 'ACE HARDWARE' THEN '90005'
WHEN 'ALDI' THEN '90005'
WHEN 'AMAZON.COM' THEN '90005'
WHEN 'GARDEN RIDGE CORP' THEN '90005'
--all other retail goes to Doran Marable
ELSE '50200'
END
END
ELSE
CASE WHEN COALESCE(m.avming,p.awming) = 'B52' THEN
'PW'
--gdir, ndir go to bill-to rep
ELSE
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
bc.bvsalm
ELSE
sc.bvsalm
END
END
END
,''
)
) quota_rep
,repc.repp quota_rep_descr
,repc.director director_descr
FROM
repl
INNER JOIN rlarp.osm_fcpool o ON
o.part = repl.orig
LEFT OUTER JOIN lgdat.stkmm m ON
m.avpart = repl.fix
LEFT OUTER JOIN lgdat.stkmp p ON
p.awpart = repl.fix
LEFT OUTER JOIN lgdat.stka a ON
a.v6part = repl.fix
AND a.v6plnt = COALESCE(m.avdplt,p.awdplt)
LEFT OUTER JOIN lgdat.icstm cm ON
cm.cgpart = repl.fix
AND cm.cgplnt = COALESCE(m.avdplt,p.awdplt)
LEFT OUTER JOIN lgdat.icstp cp ON
cp.chpart = repl.fix
AND cp.chplnt = COALESCE(m.avdplt,p.awdplt)
LEFT OUTER JOIN lgdat.icstr cr ON
cr.y0part = repl.fix
AND cr.y0plnt = COALESCE(m.avdplt,p.awdplt)
LEFT OUTER JOIN SEG ON
SEG.GLEC = COALESCE(m.avgled,p.awgled)
--AND SEG.SEGM <> 'Other'
LEFT OUTER JOIN MG ON
MG.F1 = SUBSTR(repl.fix,16,1)
AND MG.MING = COALESCE(m.avming,p.awming)
LEFT OUTER JOIN rlarp.family F ON
F.F3 = SUBSTR(repl.fix,1,3)
LEFT OUTER JOIN MD ON
MD.MOLD = SUBSTR(repl.fix,1,8)
LEFT OUTER JOIN SI ON
SI.BSMJCD = COALESCE(m.avmajs,p.awmajs)
AND SI.BSMNCD = COALESCE(m.avmins,p.awmins)
LEFT OUTER JOIN SJ ON
SJ.BSMJCD = COALESCE(m.avmajs,p.awmajs)
LEFT OUTER JOIN LGDAT.MAJG ON
BQGRP = COALESCE(m.avmajg,p.awmajg)
LEFT OUTER JOIN LGDAT.MMGP ON
BRMGRP = COALESCE(m.avming,p.awming)
AND BRGRP = COALESCE(m.avmajg,p.awmajg)
LEFT OUTER JOIN lgdat.plnt ON
yaplnt = a.v6plnt
LEFT OUTER JOIN copr ON
copr.comp = yacomp::text
LEFT OUTER JOIN rlarp.ffcret cx ON
cx.perd = '1910'
AND cx.rtyp = 'MA'
AND cx.fcur = copr.curr
AND cx.tcur = 'US'
------for quota rep------------
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 RLARP.FFCUST CG ON
CG.CUSTN = BC.BVCUST
LEFT OUTER JOIN RLARP.FFCUST SG ON
SG.CUSTN = SC.BVCUST
LEFT OUTER JOIN REPC ON
REPC.RCODE = RTRIM(
COALESCE(
--retail items go to currep, or if null go to 90005
CASE WHEN COALESCE(m.avgled,p.awgled) IN ('1RE','1CU') THEN
CASE WHEN bc.bvctry = 'CAN' THEN
--Rachel Bowman
'50300'
ELSE
--retail chain got to Mark Wilkinson
CASE COALESCE(cg.cgrp,bc.bvname)
WHEN 'THE HOME DEPOT' THEN '90005'
WHEN 'DO IT BEST' THEN '90005'
WHEN 'ACE HARDWARE' THEN '90005'
WHEN 'ALDI' THEN '90005'
WHEN 'AMAZON.COM' THEN '90005'
WHEN 'GARDEN RIDGE CORP' THEN '90005'
--all other retail goes to Doran Marable
ELSE '50200'
END
END
ELSE
CASE WHEN COALESCE(m.avming,p.awming) = 'B52' THEN
'PW'
--gdir, ndir go to bill-to rep
ELSE
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
bc.bvsalm
ELSE
sc.bvsalm
END
END
END
,''
)
)
)
,u AS (
UPDATE
rlarp.osm_fcpool o
SET
part = x.part
,plnt = x.plnt
,ord_gldc = x.ord_gldc
,majg = x.majg
,ming = x.ming
,majs = x.majs
,mins = x.mins
,gldc = x.gldc
,glec = x.glec
,harm = x.harm
,clss = x.clss
,assc = x.assc
,brand = x.brand
,fb_cst_loc = o.fb_qty * x.stdcost
--,fb_cst_loc_cur = o.fb_qty * x.stdcost
--,fb_cst_loc_fut = o.fb_qty * x.stdcost
,cost_loc = o.fb_qty * x.stdcost
,cost_usd = o.fb_qty * x.stdcost * x.c_rate
,c_currency = x.c_currency
,c_rate = x.c_rate
,part_family = x.part_family
,part_group = x.part_group
,branding = x.branding
,color = x.color
,segm = x.segm
,majg_descr = x.majg_descr
,ming_descr = x.ming_descr
,majs_descr = x.majs_descr
,mins_descr = x.mins_descr
,quota_rep = x.quota_rep
,quota_rep_descr = x.quota_rep_descr
,director_descr = x.director_descr
FROM
x
WHERE
x.origpart = o.part
RETURNING o.*
)
SELECT * FROM u;
--ROLLBACK;
--COMMIT;

View File

@ -0,0 +1,112 @@
With
REPC AS (
SELECT
LTRIM(RTRIM(C.A9)) RCODE
,LTRIM(RTRIM(C.A9)) || ' - ' || 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'
)
,r AS (
SELECT
b.quota_rep base_rep
--quota rep--------------------------------------------
,RTRIM(
COALESCE(
--retail items go to currep, or if null go to 90005
CASE WHEN COALESCE(b.glec) IN ('1RE','1CU') THEN
CASE WHEN bc.bvctry = 'CAN' THEN
--Rachel Bowman
'50300'
ELSE
--retail chain got to Mark Wilkinson
CASE COALESCE(cg.cgrp,bc.bvname)
WHEN 'THE HOME DEPOT' THEN '90005'
WHEN 'DO IT BEST' THEN '90005'
WHEN 'ACE HARDWARE' THEN '90005'
WHEN 'ALDI' THEN '90005'
WHEN 'AMAZON.COM' THEN '90005'
WHEN 'GARDEN RIDGE CORP' THEN '90005'
--all other retail goes to Doran Marable
ELSE '50200'
END
END
ELSE
CASE WHEN COALESCE(b.ming) = 'B52' THEN
'PW'
--gdir, ndir go to bill-to rep
ELSE
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
bc.bvsalm
ELSE
sc.bvsalm
END
END
END
,''
)
) revised_rep
,sum(fb_val_loc * r_rate) sales
FROM
rlarp.osm_fcpool b
LEFT OUTER JOIN LGDAT.CUST BC ON
BC.BVCUST = b.BILL_CUST
LEFT OUTER JOIN LGDAT.CUST SC ON
SC.BVCUST = b.SHIP_CUST
LEFT OUTER JOIN RLARP.FFCUST CG ON
CG.CUSTN = BC.BVCUST
LEFT OUTER JOIN RLARP.FFCUST SG ON
SG.CUSTN = SC.BVCUST
GROUP BY
b.quota_rep
--quota rep--------------------------------------------
,RTRIM(
COALESCE(
--retail items go to currep, or if null go to 90005
CASE WHEN COALESCE(b.glec) IN ('1RE','1CU') THEN
CASE WHEN bc.bvctry = 'CAN' THEN
--Rachel Bowman
'50300'
ELSE
--retail chain got to Mark Wilkinson
CASE COALESCE(cg.cgrp,bc.bvname)
WHEN 'THE HOME DEPOT' THEN '90005'
WHEN 'DO IT BEST' THEN '90005'
WHEN 'ACE HARDWARE' THEN '90005'
WHEN 'ALDI' THEN '90005'
WHEN 'AMAZON.COM' THEN '90005'
WHEN 'GARDEN RIDGE CORP' THEN '90005'
--all other retail goes to Doran Marable
ELSE '50200'
END
END
ELSE
CASE WHEN COALESCE(b.ming) = 'B52' THEN
'PW'
--gdir, ndir go to bill-to rep
ELSE
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
bc.bvsalm
ELSE
sc.bvsalm
END
END
END
,''
)
)
)
SELECT
b.repp
,v.repp
,r.sales
FROM
r
LEFT OUTER JOIN REPC b on
b.rcode = r.base_rep
LEFT OUTER JOIN REPC v on
v.rcode = r.revised_rep

View File

@ -0,0 +1,39 @@
WITH nc AS (
select
part
,plnt
, to_char(sum(fb_val_loc * r_rate),'9,999,999') sales
, to_char(sum(fb_qty),'9,999,999') units
from
rlarp.osm_fcpool
where
(
(
fb_qty <> 0
and coalesce(fb_cst_loc,0) = 0
)
or plnt is null
)
and version = 'b20'
group by
part
,plnt
)
SELECT
nc.*
,v6stat
,coalesce(cgstcs, chstcs,y0stcs) stcs
FROM
nc
left outer join lgdat.stka ON
v6part = part
and v6plnt = plnt
left outer join lgdat.icstm ON
cgpart = part
and cgplnt = plnt
left outer join lgdat.icstp ON
chpart = part
and chplnt = plnt
left outer join lgdat.icstr ON
y0part = part
and y0plnt = plnt

View File

@ -247,7 +247,7 @@ target AS (select $$replace_request$$::json def)
_month _month
,seq ,seq
,promo ,promo
,round((dom_wa/value_usd)::numeric,0)::int odom ,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom
,round((rlag_wa/value_usd)::numeric,0)::int rlag ,round((rlag_wa/value_usd)::numeric,0)::int rlag
,round((slag_wa/value_usd)::numeric,0)::int slag ,round((slag_wa/value_usd)::numeric,0)::int slag
,value_usd/sum(value_usd) over (partition by _month) momix ,value_usd/sum(value_usd) over (partition by _month) momix