get rid of more old one-off scripts

This commit is contained in:
Paul Trowbridge 2021-07-12 10:46:40 -04:00
parent a498b79630
commit 1a6121d564
32 changed files with 2 additions and 18701 deletions

View File

@ -1,8 +0,0 @@
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

@ -1,357 +0,0 @@
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

View File

@ -1 +0,0 @@
curl -H "Content-Type: application/json" -X POST -d@retail_volume.json https://usmidlnx01:8080/scale_v --insecure

View File

@ -1,21 +0,0 @@
{
"scenario": {
"segm": "Retail",
"version": "b22",
"iter": [
"copy",
"adj volume",
"adj price",
"upload volume",
"upload price"
]
},
"stamp": "2021-06-10 08:34:07",
"user": "Trowbridge, Paul",
"source": "adj",
"message": "first scale volume to hit target std cost 36.6-13.2",
"tag": "retail plug",
"type": "scale_v",
"amount": 931051.61,
"qty": 1013419.06
}

View File

@ -1,578 +0,0 @@
/*----------------replace these tags--------------
target_increment
scenario = submitted
target_month
---------------------------------------------------*/
WITH
target AS (select target_increment incr)
,testv AS (
SELECT
sum(units) tot
,sum(units) FILTER (WHERE iter = 'copy') base
,COALESCE(sum(units) FILTER (WHERE module = 'new basket'),0) newpart
,sum(value_loc *r_rate) totsales
,sum(value_loc *r_rate) FILTER (WHERE iter = 'copy') basesales
,COALESCE(sum(value_loc *r_rate) FILTER (WHERE module = 'new basket'),0) newpartsales
FROM
rlarp.osm_pool
WHERE
-----------------scenario----------------------------
scenario = target_scenario
-----------------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
,CASE WHEN totsales = 0 THEN
CASE WHEN basesales = 0 THEN
CASE WHEN newpartsales = 0 THEN
'no price'
ELSE
'scale new part'
END
ELSE
'scale copy'
END
ELSE
'scale all'
END flagsales
FROM
testv
)
,GLD AS (
SELECT
N1COMP COMP
,N1CCYY FSYR
,KPMAXP PERDS
,N1FSPP PERD
,to_char(N1FSYP,'FM0000') FSPR
,N1SD01 SDAT
,N1ED01 EDAT
,daterange(n1sd01, n1ed01,'[]') drange
,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'
)
,mseq AS (
SELECT * FROM
(
VALUES
('01 - Jun',1,6,-1)
,('02 - Jul',2,7,-1)
,('03 - Aug',3,8,-1)
,('04 - Sep',4,9,-1)
,('05 - Oct',5,10,-1)
,('06 - Nov',6,11,-1)
,('07 - Dec',7,12,-1)
,('08 - Jan',8,1,0)
,('09 - Feb',9,2,0)
,('10 - Mar',10,3,0)
,('11 - Apr',11,4,0)
,('12 - May',12,5,0)
) x(m,s,cal,yr)
)
,alldates AS (
SELECT
promo
,terms
,order_month
,mseq.s seq
,order_date
,request_date
,ship_date
,sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) value_usd
FROM
rlarp.osm_pool
LEFT OUTER JOIN mseq ON
mseq.m = order_month
WHERE
-----------------scenario----------------------------
scenario = target_scenario
-----------------additional params-------------------
AND version = 'b21'
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
promo
,terms
,order_month
,mseq.s
,order_date
,request_date
,ship_date
HAVING
sum(CASE (SELECT flagsales FROM flagv) WHEN 'no price'THEN 1.0 ELSE value_usd END) <> 0
)
--select * from alldates
,dom AS (
SELECT
extract(day FROM order_date) dom
,sum(value_usd) value_usd
FROM
alldates
GROUP BY
extract(day FROM order_date)
)
---------------------may want ot look at a top-5 mix solution in the future facilitated by sum() over (order by sales desc)---------------
,mmix AS (
SELECT
to_char(order_date,'Mon') _month
,seq
,promo
,sum(extract(day from order_date)*value_usd) dom_wa
--,request_date-order_date rlag
,sum((request_date-order_date)*(value_usd)) rlag_wa
--,ship_date - request_date slag
,sum((ship_date - request_date)*(value_usd)) slag_wa
,sum(value_usd) value_usd
FROM
alldates
GROUP BY
to_char(order_date,'Mon')
,seq
,promo
--,extract(day from order_date)
--,request_date-order_date
--,ship_date - request_date
)
,targm AS (select s, m from mseq where m = 'target_month' )
,mmixp AS (
SELECT
_month
,seq
,promo
,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom
,round((rlag_wa/value_usd)::numeric,0)::int rlag
,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) vperc
FROM
mmix
)
,closest AS (
SELECT
_month, targm.s, m
FROM
mmixp
CROSS JOIN targm
ORDER BY
abs(seq - targm.s) ASC
LIMIT 1
)
--SELECT * FROM mmixp order by seq asc, vperc desc
,basemix AS (
SELECT
plnt ---master data
,0::numeric(11,0) "ddord#" --0
,0::numeric(11,0) "dditm#" --0
,0::numeric(11,0) "fgbol#" --0
,0::numeric(11,0) "fgent#" --0
,0::numeric(9,0) "diinv#" --0
,0::numeric(3,0) "dilin#" --0
,null::text promo --history date mix
,null::text return_reas --0
,terms
,''::text custpo --0
,'I' dhincr --0
,null::numeric diext
,null::numeric ditdis
,null::date dcodat --calculated date mix
,null::date ddqdat --calculated date mix
,null::date dcmdat --calculated date mix
,null::date dhidat --calculated date mix
,null::text fspr --calculated date mix
,remit_to --master data
,bill_class --master data
,bill_cust --history cust mix
,bill_rep --master data
,bill_terr --master data
,ship_class --master data
,ship_cust --history cust mix
,ship_rep --master data
,ship_terr --master data
,quota_rep --master data
,account --master data
,shipgrp --master data
,geo --master data
,chan --master data
,orig_ctry --master data
,orig_prov --master data
,orig_post --master data
,dest_ctry --master data
,dest_prov --master data
,dest_post --master data
,part --history part mix
,ord_gldc --master data
,majg --master data
,ming --master data
,majs --master data
,mins --master data
,gldc --master data
,glec --master data
,harm --master data
,clss --master data
,brand --master data
,assc --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,0::numeric(15,5) ddqtoi --0
,0::numeric(15,5) ddqtsi --0
,0::numeric(15,5) fgqshp --0
,0::numeric(15,5) diqtsh --0
,sum(coalesce(units,0)) units --history value
,sum(coalesce(fb_cst_loc,0)) fb_cst_loc --history part mix
,sum(coalesce(fb_cst_loc_cur,0)) fb_cst_loc_cur --master data
,sum(coalesce(fb_cst_loc_fut,0)) fb_cst_loc_fut --master data
,sum(coalesce(value_loc,0)) value_loc --history value
,sum(coalesce(value_loc_pl,0)) value_loc_pl --0
,calc_status --0
,flag --0
,null::date order_date --history date mix
,null::date request_date --history date mix
,null::date ship_date --history date mix
,null::date order_date --history
,null::date adj_request_date --history
,null::date ship_date --history
---------------ui columns-------------------------
,null::numeric order_season
,null::text order_month
,null::numeric ship_season
,null::text ship_month
,null::numeric request_season
,null::text request_month
,part_descr
,part_family
,part_group
,branding
,color
,segm
,bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,mod_chan
,mod_chansub
,quota_rep_descr
,director_descr
,null value_loc
,null value_usd
,null cost_loc
,null cost_usd
,null units
FROM
rlarp.osm_pool
WHERE
-----------------scenario----------------------------
scenario = target_scenario
-----------------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
plnt ---master data
,terms
,remit_to --master data
,bill_class --master data
,bill_cust --history cust mix
,bill_rep --master data
,bill_terr --master data
,ship_class --master data
,ship_cust --history cust mix
,ship_rep --master data
,ship_terr --master data
,quota_rep --master data
,account --master data
,shipgrp --master data
,geo --master data
,chan --master data
,orig_ctry --master data
,orig_prov --master data
,orig_post --master data
,dest_ctry --master data
,dest_prov --master data
,dest_post --master data
,part --history part mix
,ord_gldc --master data
,majg --master data
,ming --master data
,majs --master data
,mins --master data
,gldc --master data
,glec --master data
,harm --master data
,clss --master data
,brand --master data
,assc --master data
,fs_line --master data
,r_currency --history cust mix
,r_rate --master data
,c_currency --master data
,c_rate --master data
,calc_status
,flag
,part_descr
,part_family
,part_group
,branding
,color
,segm
,bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,mod_chan
,mod_chansub
,quota_rep_descr
,director_descr
)
,scale AS (
SELECT
(SELECT incr::numeric FROM target) incr
,(SELECT sum(units) FROM basemix) base
,(SELECT incr::numeric FROM target)/(SELECT sum(units) FROM basemix) factor
)
,final AS (
SELECT
b.plnt --master data
,b."ddord#" --0
,b."dditm#" --0
,b."fgbol#" --0
,b."fgent#" --0
,b."diinv#" --0
,b."dilin#" --0
,m.promo --history date mix
,b.return_reas --0
,b.terms --history cust mix
,b.custpo --0
,b.dhincr --0
,b.diext --0
,b.ditdis --0
,b.dcodat --calculated date mix
,b.ddqdat --calculated date mix
,b.dcmdat --calculated date mix
,b.dhidat --calculated date mix
,b.fspr --calculated date mix
,b.remit_to --master data
,b.bill_class --master data
,b.bill_cust --history cust mix
,b.bill_rep --master data
,b.bill_terr --master data
,b.ship_class --master data
,b.ship_cust --history cust mix
,b.ship_rep --master data
,b.ship_terr --master data
,b.quota_rep --master data
,b.account --master data
,b.shipgrp --master data
,b.geo --master data
,b.chan --master data
,b.orig_ctry --master data
,b.orig_prov --master data
,b.orig_post --master data
,b.dest_ctry --master data
,b.dest_prov --master data
,b.dest_post --master data
,b.part --history part mix
,b.ord_gldc --master data
,b.majg --master data
,b.ming --master data
,b.majs --master data
,b.mins --master data
,b.gldc --master data
,b.glec --master data
,b.harm --master data
,b.clss --master data
,b.brand --master data
,b.assc --master data
,b.fs_line --master data
,b.r_currency --history cust mix
,b.r_rate --master data
,b.c_currency --master data
,b.c_rate --master data
,b.ddqtoi --0
,b.ddqtsi --0
,b.fgqshp --0
,b.diqtsh --0
,b.units*s.factor*m.momix units
,b.fb_cst_loc*s.factor*m.momix fb_cst_loc
,b.fb_cst_loc_cur*s.factor*m.momix fb_cst_loc_cur
,b.fb_cst_loc_fut*s.factor*m.momix fb_cst_loc_fut
,b.value_loc*s.factor*m.momix value_loc
,b.value_loc_pl*s.factor*m.momix value_loc_pl
,b.calc_status --0
,b.flag --0
,make_date(mseq.yr + 2020,mseq.cal,m.odom) order_date
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag request_date
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag ship_date
,make_date(mseq.yr + 2020,mseq.cal,m.odom) order_date
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_request_date
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag ship_date
,'replace_version' "version" --calculated
,'replace_source'||' volume' iter --calculated
-----------------------ui columns--------------------------------
,'replace_iterdet' iterdet
,$$replace_iterdef$$::jsonb iterdef
,od.ssyr order_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
,sd.ssyr ship_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,rd.ssyr request_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month
,b.part_descr
,b.part_family
,b.part_group
,b.branding
,b.color
,b.segm
,b.bill_cust_descr
,b.billto_group
,b.ship_cust_descr
,b.shipto_group
,b.majg_descr
,b.ming_descr
,b.majs_descr
,b.mins_descr
,b.mod_chan
,b.mod_chansub
,b.quota_rep_descr
,b.director_descr
,(b.value_loc*s.factor*m.momix)::numeric value_loc
,(b.value_loc*s.factor*m.momix*r_rate)::numeric value_usd
,(b.fb_cst_loc*s.factor*m.momix)::numeric cost_loc
,(b.fb_cst_loc*s.factor*m.momix*c_rate)::numeric cost_usd
,(b.units*s.factor*m.momix)::numeric units
FROM
basemix b
CROSS JOIN scale s
CROSS JOIN mmixp m
CROSS JOIN closest
LEFT OUTER JOIN mseq ON
mseq.m = closest.m
LEFT OUTER JOIN gld od ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
WHERE
m._month = (SELECT _month FROM closest)
)
, ins AS (
INSERT INTO rlarp.osm_pool SELECT * FROM final RETURNING *
)
,insagg AS (
SELECT
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director_descr
,segm
,mod_chan
,mod_chansub
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,brand
,part_family
,part_group
,branding
,color
,part_descr
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
,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
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director_descr
,segm
,mod_chan
,mod_chansub
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,brand
,part_family
,part_group
,branding
,color
,part_descr
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
)
SELECT json_agg(row_to_json(insagg)) x from insagg

View File

@ -1,52 +0,0 @@
WITH
pool AS (
SELECT
substr(a.v6part,1,3) "family"
,substr(a.v6part,1,8) mold
,a.v6part part
,COALESCE(m.avmajg,p.awmajg) majg
,COALESCE(m.avming,p.awming) ming
,COALESCE(m.avmajs,p.awmajs) majs
,COALESCE(m.avmins,p.awmins) mins
FROM
lgdat.stka a
LEFT OUTER JOIN lgdat.stkmm m ON
m.avpart = v6part
LEFT OUTER JOIN lgdat.stkmp p ON
p.awpart = a.v6part
WHERE
COALESCE(awgled, avgled) = '1RE'
AND v6stat = 'A'
--and avmajg = '910'
GROUP BY
a.v6part
,COALESCE(m.avmajg,p.awmajg)
,COALESCE(m.avming,p.awming)
,COALESCE(m.avmajs,p.awmajs)
,COALESCE(m.avmins,p.awmins)
)
,llist AS (
SELECT
family
,mold
,min(part) part
,jsonb_agg(majg) majg
,jsonb_agg(ming) ming
,jsonb_agg(majs) majs
,jsonb_agg(mins) mins
FROM
pool
GROUP BY
family
,mold
)
SELECT
family
,mold
,part
,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.majg) a(e)) x) majg
,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.ming) a(e)) x) ming
,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.majs) a(e)) x) majs
,(SELECT jsonb_agg(x.e) FROM (SELECT DISTINCT a.e FROM jsonb_array_elements(llist.mins) a(e)) x) mins
FROM
llist

View File

@ -1,518 +0,0 @@
BEGIN;
DROP TABLE rlarp.osm_fcpool;
--EXPLAIN
--\timing
CREATE TABLE rlarp.osm_fcpool AS (
WITH
---------------------------------------last actual date------------------------------------------------------------------------------------------------------------------------------------------------
SALES_CUTOFF AS (
SELECT MAX(FSPR) MAX_FSPR FROM RLARP.OSM
)
,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
--if the period date is less than the first forecasted order it is actual from perspective of the plan
,CASE WHEN MAX_FSPR = to_char(N1FSYP,'FM0000') THEN 'C' ELSE CASE WHEN SALES_CUTOFF.MAX_FSPR > to_char(N1FSYP,'FM0000') THEN 'P' ELSE 'F' END END CM
,CASE
WHEN MAX_FSPR = to_char(N1FSYP,'FM0000') THEN
'C'
ELSE
CASE
WHEN SALES_CUTOFF.MAX_FSPR > to_char(N1FSYP,'FM0000') THEN
CASE
WHEN SUBSTR(SALES_CUTOFF.MAX_FSPR,1,2) > SUBSTR(to_char(N1FSYP,'FM0000'),1,2) THEN
'P'
ELSE
'C'
END
ELSE
'F'
END
END CY
FROM
LGDAT.GLDATREF
INNER JOIN LGDAT.GLDATE ON
KPCOMP = N1COMP AND
KPCCYY = N1CCYY
CROSS JOIN SALES_CUTOFF
WHERE
N1COMP = 93
--AND DIGITS(N1FSYP) = '1901'
)
--SELECT * FROM gld
--CREATE INDEX SE_DAT ON gld (sdat, edat);
--SELECT daterange(MIN(SDAT),CURRENT_DATE,'[]') INTO _ytd FROM GLD WHERE CY = 'C';
--SELECT ssyr INTO _y FROM gld WHERE current_date <@ daterange(sdat,edat);
--CREATE TEMP TABLE rslt AS
--RETURN QUERY
---------------------------------------segments--------------------------------------------------------------------------------------------------------------------------------------------------------
,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)
)
---------------------------------------branding flag---------------------------------------------------------------------------------------------------------------------------------------------------
,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)
)
---------------------------------------directors-------------------------------------------------------------------------------------------------------------------------------------------------------
,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,'') <> ''
)
----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------
,seas AS(
SELECT
ssyr
,daterange(MIN(sdat),MAX(edat),'[]') dr
,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy
FROM
gld
GROUP BY
ssyr
ORDER BY
ssyr DESC
)
,intv AS (
SELECT current_date - lower(dr) dy from seas where cy = true
)
,std AS (
SELECT
s.ssyr
,s.dr
,s.cy
,daterange(lower(dr),dy + LOWER(dr),'[]') ytd
FROM
seas s
CROSS JOIN intv
)
--select * from std
---------------------------------------union actual and forecast---------------------------------------------------------------------------------------------------------------------------------------
,UN AS (
--plan
SELECT
osm.plnt
,osm."ddord#"
,osm."dditm#"
,osm."fgbol#"
,osm."fgent#"
,osm."diinv#"
,osm."dilin#"
,osm.promo
,osm.return_reas
,osm.terms
,osm.custpo
,osm.dhincr
,osm.diext
,osm.ditdis
,osm.dcodat
,osm.ddqdat
,osm.dcmdat
,osm.dhidat
,osm.fspr
,osm.remit_to
,osm.bill_class
,osm.bill_cust
,osm.bill_rep
,osm.bill_terr
,osm.ship_class
,osm.ship_cust
,osm.ship_rep
,osm.ship_terr
,osm.quota_rep
,osm.account
,osm.shipgrp
,osm.geo
,osm.chan
,osm.orig_ctry
,osm.orig_prov
,osm.orig_post
,osm.dest_ctry
,osm.dest_prov
,osm.dest_post
,osm.part
,osm.ord_gldc
,osm.majg
,osm.ming
,osm.majs
,osm.mins
,osm.gldc
,osm.glec
,osm.harm
,osm.clss
,osm.brand
,osm.assc
,osm.fs_line
,osm.r_currency
,osm.r_rate
,osm.c_currency
,osm.c_rate
,osm.ddqtoi
,osm.ddqtsi
,osm.fgqshp
,osm.diqtsh
,osm.fb_qty
,osm.fb_cst_loc
,osm.fb_cst_loc_cur
,osm.fb_cst_loc_fut
,osm.fb_val_loc
,osm.fb_val_loc_pl
,osm.calc_status
,osm.flag
,osm.orderdate
,osm.requestdate
,greatest(least(osm.shipdate,sd.edat),sd.sdat) shipdate
,osm.adj_orderdate
,osm.adj_requestdate
,osm.adj_shipdate
,osm."version"
,osm.iter
----------------presentation columns----------------------------------------------
,null::text iterdet
,null::jsonb iterdef
,OD.SSYR order_season
,to_char(osm.adj_orderdate,'Mon') order_month
,SD.SSYR ship_season
,to_char(osm.adj_shipdate,'Mon') ship_month
,RD.SSYR request_season
,to_char(osm.adj_requestdate,'Mon') request_month
,osm.PART ||COALESCE(' - '|| RTRIM(COALESCE(AVDES1, AWDES1)),'') part_descr
,F.F3||COALESCE(' - '||F.DESCR,'') part_family
,SUBSTRING(PART,1,8)||COALESCE(' - '||MD.DESCR,'') part_group
,COALESCE(MG.GRP,'Unbranded') branding
,CASE WHEN substring(osm.glec,1,1) <= '2' THEN SUBSTRING(osm.part,9,3) ELSE '' END color
,COALESCE(SEG.SEGM,'Other') segm
,osm.bill_cust || COALESCE(' - '|| RTRIM(BC.BVNAME),'') bill_cust_descr
,osm.account billto_group
,osm.ship_cust || COALESCE(' - '|| RTRIM(SC.BVNAME),'') ship_cust_descr
,osm.shipgrp shipto_group
,osm.MAJG||COALESCE(' - '||BQDES,'') majg_descr
,osm.MING||COALESCE(' - '||BRDES,'') ming_descr
,osm.MAJS||COALESCE(' - '||SJ.BSDES1,'') majs_descr
,osm.MINS||COALESCE(' - '||SI.BSDES1,'') mins_descr
,CASE COALESCE(SEG.SEGM,'Other')
WHEN 'Retail' THEN coalesce(L.RETAIL)
ELSE osm.CHAN
END mod_chan
,CASE COALESCE(SEG.SEGM,'Other')
WHEN 'Retail' THEN coalesce(L.RETAILSUB)
ELSE ''
END mod_chansub
,COALESCE(REPC.REPP,osm.QUOTA_REP) quota_rep_descr
,COALESCE(REPC.DIRECTOR,osm.QUOTA_REP) director_descr
,fb_val_loc value_loc
,fb_val_loc * r_rate value_usd
,fb_cst_loc cost_loc
,fb_cst_loc * c_rate cost_usd
,fb_qty units
FROM
rlarp.osmfs osm
LEFT OUTER JOIN GLD SD ON
osm.FSPR = sd.FSPR
LEFT OUTER JOIN GLD OD ON
osm.ADJ_ORDERDATE BETWEEN od.SDAT AND od.EDAT
LEFT OUTER JOIN GLD RD ON
osm.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT
LEFT OUTER JOIN SEG ON
SEG.GLEC = osm.GLEC
--AND SEG.SEGM <> 'Other'
LEFT OUTER JOIN MG ON
MG.F1 = SUBSTR(osm.PART,16,1)
AND MG.MING = osm.MING
LEFT OUTER JOIN RLARP.FAMILY F ON
F.F3 = SUBSTR(osm.PART,1,3)
LEFT OUTER JOIN LGDAT.STKMM M ON
M.AVPART = osm.PART
LEFT OUTER JOIN LGDAT.STKMP P ON
P.AWPART = osm.PART
LEFT OUTER JOIN MD ON
MD.MOLD = SUBSTR(osm.PART,1,8)
LEFT OUTER JOIN RLARP.FFCHNL L ON
L.BILL = osm.BILL_CLASS
AND L.SHIP = osm.SHIP_CLASS
LEFT OUTER JOIN LGDAT.CUST BC ON
BC.BVCUST = osm.BILL_CUST
LEFT OUTER JOIN LGDAT.CUST SC ON
SC.BVCUST = osm.SHIP_CUST
LEFT OUTER JOIN REPC ON
REPC.RCODE = osm.QUOTA_REP
LEFT OUTER JOIN SI ON
SI.BSMJCD = osm.MAJS
AND SI.BSMNCD = osm.MINS
LEFT OUTER JOIN SJ ON
SJ.BSMJCD = osm.MAJS
LEFT OUTER JOIN LGDAT.MAJG ON
BQGRP = osm.MAJG
LEFT OUTER JOIN LGDAT.MMGP ON
BRMGRP = osm.MING
AND BRGRP = osm.MAJG
WHERE
osm.FS_LINE = '41010'
AND osm.CALC_STATUS <> 'CANCELED'
AND SUBSTR(osm.GLEC,1,1) <= '2'
/*
UNION ALL
SELECT
osm.plnt
,osm."ddord#"
,osm."dditm#"
,osm."fgbol#"
,osm."fgent#"
,osm."diinv#"
,osm."dilin#"
,osm.promo
,osm.return_reas
,osm.terms
,osm.custpo
,osm.dhincr
,osm.diext
,osm.ditdis
,osm.dcodat
,osm.ddqdat
,osm.dcmdat
,osm.dhidat
,osm.fspr
,osm.remit_to
,osm.bill_class
,osm.bill_cust
,osm.bill_rep
,osm.bill_terr
,osm.ship_class
,osm.ship_cust
,osm.ship_rep
,osm.ship_terr
,osm.quota_rep
,osm.account
,osm.shipgrp
,osm.geo
,osm.chan
,osm.orig_ctry
,osm.orig_prov
,osm.orig_post
,osm.dest_ctry
,osm.dest_prov
,osm.dest_post
,osm.part
,osm.ord_gldc
,osm.majg
,osm.ming
,osm.majs
,osm.mins
,osm.gldc
,osm.glec
,osm.harm
,osm.clss
,osm.brand
,osm.assc
,osm.fs_line
,osm.r_currency
,osm.r_rate
,osm.c_currency
,osm.c_rate
,osm.ddqtoi
,osm.ddqtsi
,osm.fgqshp
,osm.diqtsh
,osm.fb_qty
,osm.fb_cst_loc
,osm.fb_cst_loc_cur
,osm.fb_cst_loc_fut
,osm.fb_val_loc
,osm.fb_val_loc_pl
,osm.calc_status
,osm.flag
,osm.orderdate
,osm.requestdate
,greatest(least(osm.shipdate,sd.edat),sd.sdat) shipdate
,osm.adj_orderdate
,osm.adj_requestdate
,osm.adj_shipdate
,osm."version"
,osm.iter
----------------presentation columns----------------------------------------------
,null::text iterdet
,null::jsonb iterdef
,OD.SSYR order_season
,to_char(osm.adj_orderdate,'Mon') order_month
,SD.SSYR ship_season
,to_char(osm.adj_shipdate,'Mon') ship_month
,RD.SSYR request_season
,to_char(osm.adj_requestdate,'Mon') request_month
,PART ||' - '|| RTRIM(COALESCE(AVDES1, AWDES1)) part_descr
,F.F3||' - '||F.DESCR part_family
,SUBSTRING(PART,1,8)||' - '||MD.DESCR part_group
,COALESCE(MG.GRP,'Unbranded') branding
,CASE WHEN substring(osm.glec,1,1) <= '2' THEN SUBSTRING(osm.part,9,3) ELSE '' END color
,COALESCE(SEG.SEGM,'Other') segm
,osm.bill_cust ||' - '|| RTRIM(BC.BVNAME) bill_cust_descr
,osm.account billto_group
,osm.ship_cust ||' - '|| RTRIM(SC.BVNAME) ship_cust_descr
,osm.shipgrp shipto_group
,osm.MAJG||COALESCE(' - '||BQDES,'') majg_descr
,osm.MING||COALESCE(' - '||BRDES,'') ming_descr
,osm.MAJS||COALESCE(' - '||SJ.BSDES1,'') majs_descr
,osm.MINS||COALESCE(' - '||SI.BSDES1,'') mins_descr
,CASE COALESCE(SEG.SEGM,'Other')
WHEN 'Retail' THEN coalesce(L.RETAIL,'')
ELSE osm.CHAN
END mod_chan
,CASE COALESCE(SEG.SEGM,'Other')
WHEN 'Retail' THEN coalesce(L.RETAILSUB,'')
ELSE ''
END mod_chansub
,COALESCE(REPC.REPP,osm.QUOTA_REP) quota_rep_descr
,COALESCE(REPC.DIRECTOR,osm.QUOTA_REP) director_descr
,osm.fb_val_loc::numeric value_loc
,(osm.fb_val_loc * osm.r_rate)::numeric value_usd
,osm.fb_cst_loc::numeric cost_loc
,(osm.fb_cst_loc * osm.c_rate)::numeric cost_usd
,osm.fb_qty::numeric units
FROM
rlarp.osmfs osm
LEFT OUTER JOIN GLD SD ON
osm.FSPR = sd.FSPR
LEFT OUTER JOIN GLD OD ON
osm.ADJ_ORDERDATE BETWEEN od.SDAT AND od.EDAT
LEFT OUTER JOIN GLD RD ON
osm.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT
LEFT OUTER JOIN SEG ON
SEG.GLEC = osm.GLEC
--AND SEG.SEGM <> 'Other'
LEFT OUTER JOIN MG ON
MG.F1 = SUBSTR(osm.PART,16,1)
AND MG.MING = osm.MING
LEFT OUTER JOIN RLARP.FAMILY F ON
F.F3 = SUBSTR(osm.PART,1,3)
LEFT OUTER JOIN LGDAT.STKMM M ON
M.AVPART = osm.PART
LEFT OUTER JOIN LGDAT.STKMP P ON
P.AWPART = osm.PART
LEFT OUTER JOIN MD ON
MD.MOLD = SUBSTR(osm.PART,1,8)
LEFT OUTER JOIN RLARP.FFCHNL L ON
L.BILL = osm.BILL_CLASS
AND L.SHIP = osm.SHIP_CLASS
LEFT OUTER JOIN LGDAT.CUST BC ON
BC.BVCUST = osm.BILL_CUST
LEFT OUTER JOIN LGDAT.CUST SC ON
SC.BVCUST = osm.SHIP_CUST
LEFT OUTER JOIN REPC ON
REPC.RCODE = osm.QUOTA_REP
LEFT OUTER JOIN SI ON
SI.BSMJCD = osm.MAJS
AND SI.BSMNCD = osm.MINS
LEFT OUTER JOIN SJ ON
SJ.BSMJCD = osm.MAJS
LEFT OUTER JOIN LGDAT.MAJG ON
BQGRP = osm.MAJG
LEFT OUTER JOIN LGDAT.MMGP ON
BRMGRP = osm.MING
AND BRGRP = osm.MAJG
WHERE
osm.fs_line = '41010'
AND osm.calc_status <> 'CANCELED'
AND SUBSTRING(osm.glec,1,1) <= '2'
AND osm.version = 'ACTUALS'
AND osm.adj_orderdate BETWEEN '2017-06-01' AND '2018-05-31'
*/
)
SELECT * FROM UN
);
COMMIT;

View File

@ -1,3 +1,5 @@
----change shipdates for a specific order/shipping month combination in the first where clause below
----generally drawn from monthly slots on a order/ship matrix to target those whole selecctions for a different shipping date
WITH
---------collapse iterations--------------------------------------
collapse AS (

File diff suppressed because it is too large Load Diff

View File

@ -1,547 +0,0 @@
BEGIN;
--\timing
truncate table rlarp.osmfs;
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
,price 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
FROM
rlarp.osm
WHERE
fs_line = '41010'
AND calc_status <> 'CANCELED'
AND COALESCE(part,'') <> ''
AND fb_qty <> 0
AND orderdate IS NOT NULL
ORDER BY
part
,bill_cust
,ship_cust
,orderdate
)
,cop AS (
SELECT
o.plnt
,o."ddord#"
,o."dditm#"
,o."fgbol#"
,o."fgent#"
,o."diinv#"
,o."dilin#"
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.dhincr
,o.diext
,o.ditdis
,o.dcodat
,o.ddqdat
,o.dcmdat
,o.dhidat
,o.fspr
,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.quota_rep
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.ord_gldc
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,sum(o.fb_qty) fb_qty
,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
,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_pl) fb_val_loc_pl
,o.calc_status
,o.flag
,o.orderdate
,o.requestdate
,greatest(least(o.shipdate,gld.edat),gld.sdat) shipdate
,o.adj_orderdate
,o.adj_requestdate
,greatest(least(o.adj_shipdate,gld.edat),gld.sdat) adj_shipdate
,'9p3' "version"
,'actual' iter
FROM
rlarp.osm o
LEFT OUTER JOIN gld ON
gld.fspr = o.fspr
WHERE
(
o.adj_orderdate BETWEEN '2018-06-01' AND '2019-03-24'
OR o.calc_status IN ('OPEN','BACKORDER')
OR o.fspr BETWEEN '1901' AND '1910'
)
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
--AND adj_orderdate <= adj_shipdate --exclude poorly date
GROUP BY
o.plnt
,o."ddord#"
,o."dditm#"
,o."fgbol#"
,o."fgent#"
,o."diinv#"
,o."dilin#"
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.dhincr
,o.diext
,o.ditdis
,o.dcodat
,o.ddqdat
,o.dcmdat
,o.dhidat
,o.fspr
,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.quota_rep
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.ord_gldc
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,o.calc_status
,o.flag
,o.orderdate
,o.requestdate
,greatest(least(o.shipdate,gld.edat),gld.sdat)
,o.adj_orderdate
,o.adj_requestdate
,greatest(least(o.adj_shipdate,gld.edat),gld.sdat)
UNION ALL
SELECT
o.plnt
,o."ddord#"
,o."dditm#"
,o."fgbol#"
,o."fgent#"
,o."diinv#"
,o."dilin#"
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.dhincr
,o.diext
,o.ditdis
,o.dcodat
,o.ddqdat
,o.dcmdat
,o.dhidat
,o.fspr
,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.quota_rep
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.ord_gldc
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,sum(o.fb_qty) fb_qty
,sum(COALESCE(o.fb_qty * coalesce(m.cgstcs, pr.chstcs, r.y0stcs),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
,sum(COALESCE(o.fb_qty * p.price,o.fb_val_loc)) fb_val_loc
,sum(o.fb_val_loc) fb_val_loc_pl
,'CLOSED' calc_status
,'SHIPMENT' flag
,o.orderdate
,o.requestdate
,greatest(least(o.shipdate,gld.edat),gld.sdat) shipdate
,o.adj_orderdate
,o.adj_requestdate
,greatest(least(o.adj_shipdate,gld.edat),gld.sdat) adj_shipdate
,'9p3' "version"
,'forecast' iter
FROM
rlarp.osmf o
LEFT OUTER JOIN gld ON
gld.fspr = o.fspr
LEFT OUTER JOIN price p ON
p.part = o.part
AND p.bill_cust = o.bill_cust
AND p.ship_cust = o.ship_cust
AND p.rn = 1
LEFT OUTER JOIN lgdat.icstm m ON
m.cgpart = o.part
AND m.cgplnt = o.plnt
LEFT OUTER JOIN lgdat.icstp pr ON
pr.chpart = o.part
AND pr.chplnt = o.plnt
LEFT OUTER JOIN lgdat.icstr r ON
y0part = o.part
AND y0plnt = o.plnt
WHERE
o.adj_orderdate BETWEEN '2019-03-25' AND '2019-05-31'
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate --exclude bogus ship date orders
GROUP BY
o.plnt
,o."ddord#"
,o."dditm#"
,o."fgbol#"
,o."fgent#"
,o."diinv#"
,o."dilin#"
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.dhincr
,o.diext
,o.ditdis
,o.dcodat
,o.ddqdat
,o.dcmdat
,o.dhidat
,o.fspr
,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.quota_rep
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.ord_gldc
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,o.orderdate
,o.requestdate
,greatest(least(o.shipdate,gld.edat),gld.sdat)
,o.adj_orderdate
,o.adj_requestdate
,greatest(least(o.adj_shipdate,gld.edat),gld.sdat)
)
,incr AS (
SELECT
o.plnt
,o."ddord#"
,o."dditm#"
,o."fgbol#"
,o."fgent#"
,o."diinv#"
,o."dilin#"
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.dhincr
,o.diext
,o.ditdis
,o.dcodat
,o.ddqdat
,o.dcmdat
,o.dhidat
,gld.fspr
,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.quota_rep
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.ord_gldc
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,sum(o.fb_qty) fb_qty
,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
,sum(o.fb_val_loc) fb_val_loc
,sum(o.fb_val_loc_pl) fb_val_loc_pl
,o.calc_status
,o.flag
----these dates should already be snapped since the derive from the adjusted set
,o.orderdate + interval '1 year' orderdate
,o.requestdate + interval '1 year' requestdate
,o.shipdate + interval '1 year' shipdate
,o.adj_orderdate + interval '1 year' adj_orderdate
,o.adj_requestdate + interval '1 year' adj_requestdate
,o.adj_shipdate + interval '1 year' adj_shipdate
,'b20' "version"
,'copy' iter
FROM
cop o
LEFT OUTER JOIN gld ON
(o.adj_shipdate + interval '1 year') BETWEEN gld.sdat AND gld.edat
WHERE
adj_orderdate BETWEEN '2018-06-01' AND '2019-05-31'
GROUP BY
o.plnt
,o."ddord#"
,o."dditm#"
,o."fgbol#"
,o."fgent#"
,o."diinv#"
,o."dilin#"
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.dhincr
,o.diext
,o.ditdis
,o.dcodat
,o.ddqdat
,o.dcmdat
,o.dhidat
,gld.fspr
,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.quota_rep
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.ord_gldc
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,o.calc_status
,o.flag
,o.orderdate + interval '1 year'
,o.requestdate + interval '1 year'
,o.shipdate + interval '1 year'
,o.adj_orderdate + interval '1 year'
,o.adj_requestdate + interval '1 year'
,o.adj_shipdate + interval '1 year'
)
INSERT INTO rlarp.osmfs
SELECT * FROM incr
UNION ALL
SELECT * FROM cop;
---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;
COMMIT;

File diff suppressed because it is too large Load Diff

View File

@ -1,241 +0,0 @@
WITH
---------collapse iterations--------------------------------------
collapse AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,SUM(o.units) units
,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,SUM(o.cost_loc) cost_loc
,SUM(o.cost_usd) 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
FROM
rlarp.osm_pool o
--need to join to itemm to get the product from osm_pool
WHERE
--all June and earlier orders originally shipping in October now move back to June ship date
ship_season||substring(ship_month,1,2) = '202202'
and order_season||substring(order_month,1,2) BETWEEN '202110' AND '202110'
and segm = 'Nursery'
GROUP BY
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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,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
--HAVING
-- sum(o.units) <> 0
)
--SELECT
-- sum(value_usd)
--FROM
-- collapse
------------------create a log entry--------------------
,log AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
$${
"message":"NU sales smooth",
"tag":"NU sales smooth",
"type":"build"
}$$::jsonb doc
RETURNING *
)
,rem AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,-units units
,-value_loc value_loc
,-value_usd value_usd
------exclude any prior pricing adjustments from the "current" price in the forecast------
,-cost_loc cost_loc
,-cost_usd 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
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
,ins AS (
SELECT
'2210' fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,units
,value_loc
,value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,cost_loc
,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
,'2022-04-01'::date ship_date --history date mix
,'11 - Apr' ship_month
,2022 ship_season
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
INSERT INTO
rlarp.osm_pool
SELECT * FROM rem
UNION ALL
SELECT * FROM ins;

View File

@ -1,241 +0,0 @@
WITH
---------collapse iterations--------------------------------------
collapse AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,SUM(o.units) units
,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,SUM(o.cost_loc) cost_loc
,SUM(o.cost_usd) 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
FROM
rlarp.osm_pool o
--need to join to itemm to get the product from osm_pool
WHERE
--all June and earlier orders originally shipping in October now move back to June ship date
ship_season||substring(ship_month,1,2) = '202201'
and order_season||substring(order_month,1,2) BETWEEN '202103' AND '202106'
and segm = 'Nursery'
GROUP BY
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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,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
--HAVING
-- sum(o.units) <> 0
)
--SELECT
-- sum(value_usd)
--FROM
-- collapse
------------------create a log entry--------------------
,log AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
$${
"message":"NU sales smooth",
"tag":"NU sales smooth",
"type":"build"
}$$::jsonb doc
RETURNING *
)
,rem AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,-units units
,-value_loc value_loc
,-value_usd value_usd
------exclude any prior pricing adjustments from the "current" price in the forecast------
,-cost_loc cost_loc
,-cost_usd 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
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
,ins AS (
SELECT
'2203' fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,units
,value_loc
,value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,cost_loc
,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
,'2021-08-01'::date ship_date --history date mix
,'01 - Aug' ship_month
,2022 ship_season
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
INSERT INTO
rlarp.osm_pool
SELECT * FROM rem
UNION ALL
SELECT * FROM ins;

View File

@ -1,241 +0,0 @@
WITH
---------collapse iterations--------------------------------------
collapse AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,SUM(o.units) units
,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,SUM(o.cost_loc) cost_loc
,SUM(o.cost_usd) 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
FROM
rlarp.osm_pool o
--need to join to itemm to get the product from osm_pool
WHERE
--all June and earlier orders originally shipping in October now move back to June ship date
ship_season||substring(ship_month,1,2) = '202201'
and order_season||substring(order_month,1,2) BETWEEN '202109' AND '202109'
and segm = 'Nursery'
GROUP BY
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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,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
--HAVING
-- sum(o.units) <> 0
)
--SELECT
-- sum(value_usd)
--FROM
-- collapse
------------------create a log entry--------------------
,log AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
$${
"message":"NU sales smooth",
"tag":"NU sales smooth",
"type":"build"
}$$::jsonb doc
RETURNING *
)
,rem AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,-units units
,-value_loc value_loc
,-value_usd value_usd
------exclude any prior pricing adjustments from the "current" price in the forecast------
,-cost_loc cost_loc
,-cost_usd 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
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
,ins AS (
SELECT
'2207' fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,units
,value_loc
,value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,cost_loc
,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
,'2021-12-01'::date ship_date --history date mix
,'07 - Dec' ship_month
,2022 ship_season
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
INSERT INTO
rlarp.osm_pool
SELECT * FROM rem
UNION ALL
SELECT * FROM ins;

View File

@ -1,241 +0,0 @@
WITH
---------collapse iterations--------------------------------------
collapse AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,SUM(o.units) units
,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,SUM(o.cost_loc) cost_loc
,SUM(o.cost_usd) 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
FROM
rlarp.osm_pool o
--need to join to itemm to get the product from osm_pool
WHERE
--all June and earlier orders originally shipping in October now move back to June ship date
ship_season||substring(ship_month,1,2) = '202201'
and order_season||substring(order_month,1,2) BETWEEN '202111' AND '202111'
and segm = 'Nursery'
GROUP BY
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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,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
--HAVING
-- sum(o.units) <> 0
)
--SELECT
-- sum(value_usd)
--FROM
-- collapse
------------------create a log entry--------------------
,log AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
$${
"message":"NU sales smooth",
"tag":"NU sales smooth",
"type":"build"
}$$::jsonb doc
RETURNING *
)
,rem AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,-units units
,-value_loc value_loc
,-value_usd value_usd
------exclude any prior pricing adjustments from the "current" price in the forecast------
,-cost_loc cost_loc
,-cost_usd 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
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
,ins AS (
SELECT
'2209' fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,units
,value_loc
,value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,cost_loc
,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
,'2022-02-01'::date ship_date --history date mix
,'09 - Feb' ship_month
,2022 ship_season
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
INSERT INTO
rlarp.osm_pool
SELECT * FROM rem
UNION ALL
SELECT * FROM ins;

View File

@ -1,241 +0,0 @@
WITH
---------collapse iterations--------------------------------------
collapse AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,SUM(o.units) units
,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,SUM(o.cost_loc) cost_loc
,SUM(o.cost_usd) 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
FROM
rlarp.osm_pool o
--need to join to itemm to get the product from osm_pool
WHERE
--all June and earlier orders originally shipping in October now move back to June ship date
ship_season||substring(ship_month,1,2) = '202202'
and order_season||substring(order_month,1,2) BETWEEN '202112' AND '202112'
and segm = 'Nursery'
GROUP BY
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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,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
--HAVING
-- sum(o.units) <> 0
)
--SELECT
-- sum(value_usd)
--FROM
-- collapse
------------------create a log entry--------------------
,log AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
$${
"message":"NU sales smooth",
"tag":"NU sales smooth",
"type":"build"
}$$::jsonb doc
RETURNING *
)
,rem AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,-units units
,-value_loc value_loc
,-value_usd value_usd
------exclude any prior pricing adjustments from the "current" price in the forecast------
,-cost_loc cost_loc
,-cost_usd 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
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
,ins AS (
SELECT
'2212' fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,units
,value_loc
,value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,cost_loc
,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
,'2022-05-01'::date ship_date --history date mix
,'12 - May' ship_month
,2022 ship_season
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
INSERT INTO
rlarp.osm_pool
SELECT * FROM rem
UNION ALL
SELECT * FROM ins;

View File

@ -1,241 +0,0 @@
WITH
---------collapse iterations--------------------------------------
collapse AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,SUM(o.units) units
,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,SUM(o.cost_loc) cost_loc
,SUM(o.cost_usd) 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
FROM
rlarp.osm_pool o
--need to join to itemm to get the product from osm_pool
WHERE
--all June and earlier orders originally shipping in October now move back to June ship date
ship_season||substring(ship_month,1,2) = '202201'
and order_season||substring(order_month,1,2) BETWEEN '202107' AND '202107'
and segm = 'Nursery'
GROUP BY
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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,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
--HAVING
-- sum(o.units) <> 0
)
--SELECT
-- sum(value_usd)
--FROM
-- collapse
------------------create a log entry--------------------
,log AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
$${
"message":"NU sales smooth",
"tag":"NU sales smooth",
"type":"build"
}$$::jsonb doc
RETURNING *
)
,rem AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,-units units
,-value_loc value_loc
,-value_usd value_usd
------exclude any prior pricing adjustments from the "current" price in the forecast------
,-cost_loc cost_loc
,-cost_usd 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
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
,ins AS (
SELECT
'2205' fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,units
,value_loc
,value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,cost_loc
,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
,'2021-10-01'::date ship_date --history date mix
,'01 - Oct' ship_month
,2022 ship_season
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
INSERT INTO
rlarp.osm_pool
SELECT * FROM rem
UNION ALL
SELECT * FROM ins;

View File

@ -1,241 +0,0 @@
WITH
---------collapse iterations--------------------------------------
collapse AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,SUM(o.units) units
,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,SUM(o.cost_loc) cost_loc
,SUM(o.cost_usd) 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
FROM
rlarp.osm_pool o
--need to join to itemm to get the product from osm_pool
WHERE
--all June and earlier orders originally shipping in October now move back to June ship date
ship_season||substring(ship_month,1,2) = '202210'
and order_season||substring(order_month,1,2) BETWEEN '202202' AND '202205'
and segm = 'Retail'
GROUP BY
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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,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
--HAVING
-- sum(o.units) <> 0
)
--SELECT
-- sum(value_usd)
--FROM
-- collapse
------------------create a log entry--------------------
,log AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
$${
"message":"RE sales smooth",
"tag":"RE sales smooth",
"type":"build"
}$$::jsonb doc
RETURNING *
)
,rem AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,-units units
,-value_loc value_loc
,-value_usd value_usd
------exclude any prior pricing adjustments from the "current" price in the forecast------
,-cost_loc cost_loc
,-cost_usd 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
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
,ins AS (
SELECT
'2212' fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,units
,value_loc
,value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,cost_loc
,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
,'2022-05-01'::date ship_date --history date mix
,'12 - May' ship_month
,2022 ship_season
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
INSERT INTO
rlarp.osm_pool
SELECT * FROM rem
UNION ALL
SELECT * FROM ins;

View File

@ -1,241 +0,0 @@
WITH
---------collapse iterations--------------------------------------
collapse AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,SUM(o.units) units
,SUM(o.value_loc) value_loc
,SUM(o.value_usd) value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,SUM(o.cost_loc) cost_loc
,SUM(o.cost_usd) 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
FROM
rlarp.osm_pool o
--need to join to itemm to get the product from osm_pool
WHERE
--all June and earlier orders originally shipping in October now move back to June ship date
ship_season||substring(ship_month,1,2) = '202205'
and order_season||substring(order_month,1,2) <= '202201'
and segm = 'Greenhouse'
GROUP BY
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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,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
--HAVING
-- sum(o.units) <> 0
)
--SELECT
-- sum(value_usd)
--FROM
-- collapse
----------------create a log entry--------------------
,log AS (
INSERT INTO
rlarp.osm_log(doc)
SELECT
$${
"message":"GH sales smooth",
"tag":"sales smooth",
"type":"build"
}$$::jsonb doc
RETURNING *
)
,rem AS (
SELECT
o.fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,-units units
,-value_loc value_loc
,-value_usd value_usd
------exclude any prior pricing adjustments from the "current" price in the forecast------
,-cost_loc cost_loc
,-cost_usd 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
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
,ins AS (
SELECT
'2201' fspr
,o.plnt
,o.promo
,o.terms
,o.bill_cust_descr
,o.ship_cust_descr
,o.dsm
,o.quota_rep_descr
,o.director
,o.billto_group
,o.shipto_group
,o.chan
,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
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,units
,value_loc
,value_usd
-----exclude any prior pricing adjustments from the "current" price in the forecast------
,cost_loc
,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
,'2020-06-01'::date ship_date --history date mix
,'01 - Jun' ship_month
,2022 ship_season
---this iteration has to be listed in the master template file in order to be effectively included---
,'b22' AS version
,'upload volume' iter
,log.id
,COALESCE(log.doc->>'tag','') "tag"
,log.doc->>'message' "comment"
,log.doc->>'type' module
FROM
collapse o
,log
)
INSERT INTO
rlarp.osm_pool
SELECT * FROM rem
UNION ALL
SELECT * FROM ins;

View File

@ -1,803 +0,0 @@
WITH
/*
the volume must be expressed in terms of units, since that is what it will be scaling
*/
target AS (select $$replace_request$$::json def)
--select * from newm
,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'
)
,mseq AS (
SELECT * FROM
(
VALUES
('Jun',1,6,-1)
,('Jul',2,7,-1)
,('Aug',3,8,-1)
,('Sep',4,9,-1)
,('Oct',5,10,-1)
,('Nov',6,11,-1)
,('Dec',7,12,-1)
,('Jan',8,1,0)
,('Feb',9,2,0)
,('Mar',10,3,0)
,('Apr',11,4,0)
,('May',12,5,0)
) x(m,s,cal,yr)
)
,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
)
,alldates AS (
SELECT
promo
,terms
,order_month
,mseq.s seq
,orderdate
,requestdate
,shipdate
,sum(value_usd) value_usd
FROM
rlarp.osm_fcpool
LEFT OUTER JOIN mseq ON
mseq.m = order_month
WHERE
-----------------scenario----------------------------
where_clause
-----------------additional params-------------------
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate
GROUP BY
promo
,terms
,order_month
,mseq.s
,orderdate
,requestdate
,shipdate
HAVING
sum(value_usd) <> 0
)
--select * from alldates
,dom AS (
SELECT
extract(day FROM orderdate) DOM
,sum(value_usd) value_usd
FROM
alldates
GROUP BY
extract(day FROM orderdate)
)
---------------------may want ot look at a top-5 mix solution in the future facilitated by sum() over (order by sales desc)---------------
,mmix AS (
SELECT
to_char(orderdate,'Mon') _month
,seq
,promo
,sum(extract(day from orderdate)*value_usd) dom_wa
--,requestdate-orderdate rlag
,sum((requestdate-orderdate)*(value_usd)) rlag_wa
--,shipdate - requestdate slag
,sum((shipdate - requestdate)*(value_usd)) slag_wa
,sum(value_usd) value_usd
FROM
alldates
GROUP BY
to_char(orderdate,'Mon')
,seq
,promo
--,extract(day from orderdate)
--,requestdate-orderdate
--,shipdate - requestdate
)
,targm AS (
SELECT
je.key as month
,r.amount
,r.qty
,s
,cal
,yr
FROM
target
JOIN LATERAL json_each(def->'months') je ON true
JOIN LATERAL json_to_record(je.value) as r (amount numeric, qty numeric) ON TRUE
LEFT OUTER JOIN mseq ON
mseq.m = je.key
)
,mmixp AS (
SELECT
_month
,seq
,promo
,round((dom_wa/value_usd)::numeric,0)::int odom
,round((rlag_wa/value_usd)::numeric,0)::int rlag
,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) vperc
FROM
mmix
)
--month cross join mix
,mxm AS (
SELECT
t.month
,t.amount
,t.qty
,t.s
,t.cal
,t.yr
,x.momix
,x.odom
,x.rlag
,x.slag
,x.promo
FROM
targm t
LEFT OUTER JOIN mmixp x ON
x._month = (
SELECT
_month
FROM
mmixp
ORDER BY
abs(seq - t.s) ASC
LIMIT 1
)
)
--SELECT * FROM mmixp order by seq asc, vperc desc
,basemix AS (
SELECT
null::text plnt ---master data
,0::numeric(11,0) "ddord#"
,0::numeric(11,0) "dditm#"
,0::numeric(11,0) "fgbol#"
,0::numeric(11,0) "fgent#"
,0::numeric(9,0) "diinv#"
,0::numeric(3,0) "dilin#"
,null::text promo --history
,null::text return_reas
,null::text terms
,''::text custpo
,'I' dhincr
,null::numeric diext
,null::numeric ditdis
,null::date dcodat
,null::date ddqdat
,null::date dcmdat
,null::date dhidat
,null::text fspr
,remit_to
,bill_class
,bill_cust
,bill_rep
,bill_terr
,ship_class
,ship_cust
,ship_rep
,ship_terr
,quota_rep
,account
,shipgrp
,geo
,chan
,orig_ctry
,orig_prov
,orig_post
,dest_ctry
,dest_prov
,dest_post
,null::text part --history part mix
,null::text ord_gldc
,null::text majg
,null::text ming
,null::text majs
,null::text mins
,null::text gldc
,null::text glec
,null::text harm
,null::text clss
,null::text brand
,null::text assc
,fs_line
,r_currency
,r_rate
,null::text c_currency
,null::numeric c_rate
,0::numeric(15,5) ddqtoi
,0::numeric(15,5) ddqtsi
,0::numeric(15,5) fgqshp
,0::numeric(15,5) diqtsh
,0::numeric fb_qty --history value
,0::numeric fb_cst_loc --history part mix
,0::numeric fb_cst_loc_cur
,0::numeric fb_cst_loc_fut
,0::numeric fb_val_loc --history value
,0::numeric fb_val_loc_pl
,calc_status
,flag
,null::date orderdate --history
,null::date requestdate --history
,null::date shipdate --history
,null::date adj_orderdate --history
,null::date adj_requestdate --history
,null::date adj_shipdate --history
,null::text "version"
,null::text iter
---------------ui columns-------------------------
,null::numeric order_season
,null::text order_month
,null::numeric ship_season
,null::text ship_month
,null::numeric request_season
,null::text request_month
,null::text part_descr
,null::text part_family
,null::text part_group
,null::text branding
,null::text color
,null::text segm
,bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,null::text majg_descr
,null::text ming_descr
,null::text majs_descr
,null::text mins_descr
,mod_chan
,mod_chansub
,quota_rep_descr
,director_descr
,null::numeric value_loc
,null::numeric value_usd
,null::numeric cost_loc
,null::numeric cost_usd
,null::numeric units
,sum(coalesce(fb_val_loc * r_rate,0)) agg
FROM
rlarp.osm_fcpool
WHERE
-----------------scenario----------------------------
where_clause
-----------------additional params-------------------
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate
GROUP BY
remit_to
,bill_class
,bill_cust
,bill_rep
,bill_terr
,ship_class
,ship_cust
,ship_rep
,ship_terr
,quota_rep
,account
,shipgrp
,geo
,chan
,orig_ctry
,orig_prov
,orig_post
,dest_ctry
,dest_prov
,dest_post
,fs_line
,r_currency
,r_rate
,calc_status
,flag
,bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,mod_chan
,mod_chansub
,quota_rep_descr
,director_descr
)
,applyx AS (
SELECT
b.plnt --master data
,b."ddord#"
,b."dditm#"
,b."fgbol#"
,b."fgent#"
,b."diinv#"
,b."dilin#"
,mxm.promo --history
,b.return_reas
,b.terms --history cust mix
,b.custpo
,b.dhincr
,b.diext
,b.ditdis
,b.dcodat
,b.ddqdat
,b.dcmdat
,b.dhidat
,sd.fspr fspr
,b.remit_to --master data
,b.bill_class --master data
,b.bill_cust --history cust mix
,b.bill_rep --master data
,b.bill_terr --master data
,b.ship_class --master data
,b.ship_cust --history cust mix
,b.ship_rep --master data
,b.ship_terr --master data
,b.quota_rep --master data
,b.account --master data
,b.shipgrp --master data
,b.geo --master data
,b.chan --master data
,b.orig_ctry --master data
,b.orig_prov --master data
,b.orig_post --master data
,b.dest_ctry --master data
,b.dest_prov --master data
,b.dest_post --master data
,(SELECT (regexp_match(def->>'newpart','(.*) - '::text))[1] FROM target) part --history part mix
,b.ord_gldc --master data
,b.majg --master data
,b.ming --master data
,b.majs --master data
,b.mins --master data
,b.gldc --master data
,b.glec --master data
,b.harm --master data
,b.clss --master data
,b.brand --master data
,b.assc --master data
,b.fs_line --master data
,b.r_currency --history cust mix
,b.r_rate --master data
,b.c_currency --master data
,b.c_rate --master data
,b.ddqtoi
,b.ddqtsi
,b.fgqshp
,b.diqtsh
,(b.agg/sum(b.agg) OVER (partition by mxm.*))*mxm.momix*mxm.qty fb_qty
,b.fb_cst_loc
,b.fb_cst_loc_cur
,b.fb_cst_loc_fut
,(b.agg/sum(b.agg) OVER (partition by mxm.*))*mxm.momix*mxm.amount fb_val_loc
,b.fb_val_loc_pl
,b.calc_status
,b.flag
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) orderdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag requestdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag shipdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) adj_orderdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag adj_requestdate
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag adj_shipdate
,'replace_version' "version"
,'replace_source'||' volume' iter
-----------------------ui columns--------------------------------
,'replace_iterdet' iterdet
,$$replace_iterdef$$::json iterdef
,od.ssyr order_season
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom),'Mon') order_month
,sd.ssyr ship_season
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag,'Mon') ship_month
,rd.ssyr request_season
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag,'Mon') request_month
,b.part_descr
,b.part_family
,b.part_group
,b.branding
,b.color
,b.segm
,b.bill_cust_descr
,b.billto_group
,b.ship_cust_descr
,b.shipto_group
,b.majg_descr
,b.ming_descr
,b.majs_descr
,b.mins_descr
,b.mod_chan
,b.mod_chansub
,b.quota_rep_descr
,b.director_descr
,b.value_loc
,b.value_usd
,b.cost_loc
,b.cost_usd
,b.units
--,(b.agg/sum(b.agg) OVER (partition by mxm.*)) bmix
--,mxm.*
FROM
basemix b
CROSS JOIN mxm
LEFT OUTER JOIN gld od ON
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
)
,final AS (
SELECT
COALESCE(m.avdplt,p.awdplt) plnt --master data
,b."ddord#"
,b."dditm#"
,b."fgbol#"
,b."fgent#"
,b."diinv#"
,b."dilin#"
,b.promo --history
,b.return_reas
,bc.bvterm terms --history cust mix
,b.custpo
,b.dhincr
,b.diext
,b.ditdis
,b.dcodat
,b.ddqdat
,b.dcmdat
,b.dhidat
,b.fspr
,b.remit_to --master data
,b.bill_class --master data
,b.bill_cust --history cust mix
,b.bill_rep --master data
,b.bill_terr --master data
,b.ship_class --master data
,b.ship_cust --history cust mix
,b.ship_rep --master data
,b.ship_terr --master data
,b.quota_rep --master data
,b.account --master data
,b.shipgrp --master data
,b.geo --master data
,b.chan --master data
,b.orig_ctry --master data
,b.orig_prov --master data
,b.orig_post --master data
,b.dest_ctry --master data
,b.dest_prov --master data
,b.dest_post --master data
,(SELECT (regexp_match(def->>'newpart','(.*) - '::text))[1] FROM target) part --history part mix
,COALESCE(m.avglcd, p.awgldc) ord_gldc --master data
,COALESCE(m.avmajg,p.awmajg) majg --master data
,COALESCE(m.avming,p.awming) ming --master data
,COALESCE(m.avmajs,p.awmajs) majs --master data
,COALESCE(m.avmins,p.awmins) mins --master data
,COALESCE(m.avglcd,p.awgldc) gldc --master data
,COALESCE(m.avgled,p.awgled) glec --master data
,COALESCE(m.avharm,p.awharm) harm --master data
,COALESCE(m.avclss,p.awclss) clss --master data
,SUBSTR(COALESCE(m."avcpt#",p."awvpt#"),1,1) brand --master data
,COALESCE(m.avassc,p.awassc) assc --master data
,b.fs_line --master data
,b.r_currency --history cust mix
,b.r_rate --master data
,copr.curr c_currency --master data
,cx.rate c_rate --master data
,b.ddqtoi
,b.ddqtsi
,b.fgqshp
,b.diqtsh
,b.fb_qty
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty fb_cst_loc
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty fb_cst_loc_cur
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty fb_cst_loc_fut
,b.fb_val_loc
,b.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"
,b.iter
-----------------------ui columns--------------------------------
,b.iterdet
,b.iterdef
,b.order_season
,b.order_month
,b.ship_season
,b.ship_month
,b.request_season
,b.request_month
,b.part ||' - '|| RTRIM(COALESCE(m.AVDES1, p.AWDES1)) part_descr
,F.F3||' - '||F.DESCR part_family
,SUBSTRING(b.part,1,8)||' - '||MD.DESCR part_group
,COALESCE(MG.GRP,'Unbranded') branding
,CASE WHEN substring(COALESCE(m.avgled, p.awgled),1,1) <= '2' THEN SUBSTRING(b.part,9,3) ELSE '' END color
,COALESCE(SEG.SEGM,'Other') segm
,b.bill_cust_descr
,b.billto_group
,b.ship_cust_descr
,b.shipto_group
,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
,CASE COALESCE(SEG.SEGM,'Other')
WHEN 'Retail' THEN L.RETAIL
ELSE b.CHAN
END mod_chan
,CASE COALESCE(SEG.SEGM,'Other')
WHEN 'Retail' THEN L.RETAILSUB
ELSE ''
END mod_chansub
,b.quota_rep_descr
,b.director_descr
,b.fb_val_loc value_loc
,b.fb_val_loc *r_rate value_usd
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty cost_loc
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.fb_qty*cx.rate cost_usd
,b.fb_qty units
FROM
applyx b
LEFT OUTER JOIN LGDAT.STKMM M ON
M.AVPART = b.PART
LEFT OUTER JOIN LGDAT.STKMP P ON
P.AWPART = b.PART
LEFT OUTER JOIN lgdat.stka a ON
v6part = b.part
AND v6plnt = 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(b.PART,16,1)
AND MG.MING = COALESCE(m.avming,p.awming)
LEFT OUTER JOIN RLARP.FAMILY F ON
F.F3 = SUBSTR(b.PART,1,3)
LEFT OUTER JOIN MD ON
MD.MOLD = SUBSTR(b.PART,1,8)
LEFT OUTER JOIN RLARP.FFCHNL L ON
L.BILL = b.BILL_CLASS
AND L.SHIP = b.SHIP_CLASS
LEFT OUTER JOIN LGDAT.CUST BC ON
BC.BVCUST = b.BILL_CUST
LEFT OUTER JOIN LGDAT.CUST SC ON
SC.BVCUST = b.BILL_CUST
LEFT OUTER JOIN REPC ON
REPC.RCODE = b.QUOTA_REP
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.icstm im ON
im.cgpart = b.part
AND im.cgplnt = a.v6plnt
LEFT OUTER JOIN lgdat.icstp ip ON
ip.chpart = b.part
AND ip.chplnt = a.v6plnt
LEFT OUTER JOIN lgdat.icstr ir ON
ir.y0part = b.part
AND ir.y0plnt = a.v6plnt
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'
)
,ins AS (
INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING *
)
,insagg AS (
SELECT
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director_descr
,segm
,mod_chan
,mod_chansub
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,brand
,part_family
,part_group
,branding
,color
,part_descr
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
,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
bill_cust_descr
,billto_group
,ship_cust_descr
,shipto_group
,quota_rep_descr
,director_descr
,segm
,mod_chan
,mod_chansub
,majg_descr
,ming_descr
,majs_descr
,mins_descr
,brand
,part_family
,part_group
,branding
,color
,part_descr
,order_season
,order_month
,ship_season
,ship_month
,request_season
,request_month
,promo
,version
,iter
)
--SELECT * FROM insagg
SELECT json_agg(row_to_json(insagg)) x from insagg

View File

@ -1,96 +0,0 @@
BEGIN;
WITH
mseq AS (
SELECT * FROM
(
VALUES
('Jun',1,6,-1)
,('Jul',2,7,-1)
,('Aug',3,8,-1)
,('Sep',4,9,-1)
,('Oct',5,10,-1)
,('Nov',6,11,-1)
,('Dec',7,12,-1)
,('Jan',8,1,0)
,('Feb',9,2,0)
,('Mar',10,3,0)
,('Apr',11,4,0)
,('May',12,5,0)
) x(m,s,cal,yr)
)
,alldates AS (
SELECT
shipgrp
,to_char(orderdate,'Mon') orderm
,extract(month FROM age(requestdate,orderdate)) rmo
,(sum((shipdate - requestdate)* (fb_val_loc * r_rate))/sum(fb_val_loc * r_rate))::int wav_lag
--,sum(fb_val_loc * r_rate) value_usd
FROM
rlarp.osm
WHERE
adj_orderdate >= '2017-06-01'
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND adj_orderdate <= adj_shipdate
AND fspr IS NOT NULL
GROUP BY
shipgrp
,to_char(orderdate,'Mon')
,extract(month FROM age(requestdate,orderdate))
HAVING
sum(fb_val_loc * r_rate) <> 0
)
,lag AS (
SELECT
shipgrp
,orderm
,rmo
,wav_lag
FROM
alldates
ORDER BY
shipgrp
,orderm
,rmo
)
,opord AS (
SELECT
shipgrp
,orderdate
,requestdate
,shipdate
,to_char(orderdate,'Mon') orderm
,extract(month FROM age(requestdate,orderdate)) rmo
,sum(fb_val_loc * r_rate) value_usd
FROM
rlarp.osm
WHERE
calc_status NOT IN ('CANCELED','CLOSED')
GROUP BY
shipgrp
,orderdate
,requestdate
,shipdate
,to_char(orderdate,'Mon')
,extract(month FROM age(requestdate,orderdate))
ORDER BY
value_usd DESC
)
,upd AS (
UPDATE rlarp.osmfs o SET
adj_shipdate = greatest(shipdate + lag.wav_lag + 5 ,shipdate)
FROM
lag
WHERE
lag.shipgrp = o.shipgrp
AND lag.orderm = to_char(o.orderdate,'Mon')
AND lag.rmo = extract(month FROM age(o.requestdate,o.orderdate))
AND o.calc_status in ('BACKORDER','OPEN')
RETURNING *
)
SELECT
sum(fb_val_loc *r_rate) filter (where adj_shipdate < '2019-04-01')
,sum(fb_val_loc *r_rate) filter (where adj_shipdate >= '2019-04-01')
from upd;
COMMIT;

View File

@ -1,27 +0,0 @@
WITH
act As (
SELECT DISTINCT
v6part part
FROM
lgdat.stka
WHERE
(
v6stat = 'A'
OR v6part in ('TWA10203G18B027','TWA10203G18D050','MIH09000G18E001')
)
OR v6type = 'C'
)
,stkm AS (
SELECT
act.part || ' - ' ||rtrim(COALESCE(m.avdes1,p.awdes1)) part
--,COALESCE(m.avgled, p.awgled) glec
FROM
act
LEFT OUTER JOIN lgdat.stkmm m ON
m.avpart = act.part
LEFT OUTER JOIN lgdat.stkmp p ON
p.awpart = act.part
WHERE
substr(COALESCE(m.avgled, p.awgled),1,1) <= '2'
)
select part from stkm

View File

@ -1,38 +0,0 @@
BEGIN;
WITH
plist AS (
SELECT DISTINCT
part
,plnt
FROM
rlarp.osm_fcpool
)
,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.osm_fcpool o
SET
fb_cst_loc_cur = c.stdcost * o.fb_qty
FROM
clist c
WHERE
c.part = o.part
AND c.plnt = o.plnt;
commit;

View File

@ -1,38 +0,0 @@
BEGIN;
WITH
plist AS (
SELECT DISTINCT
part
,plnt
FROM
rlarp.osm_fcpool
)
,clist AS (
SELECT
p.part
,p.plnt
,COALESCE(im.cnstcs,ip.costcs, ir.y3stcs) stdcost
FROM
plist p
LEFT OUTER JOIN lgdat.ftcstm im ON
im.cnpart = p.part
AND im.cnplnt = p.plnt
LEFT OUTER JOIN lgdat.ftcstp ip ON
ip.copart = p.part
AND ip.coplnt = p.plnt
LEFT OUTER JOIN lgdat.ftcstr ir ON
ir.y3part = p.part
AND ir.y3plnt = p.plnt
)
UPDATE
rlarp.osm_fcpool o
SET
fb_cst_loc_fut = c.stdcost * o.fb_qty
FROM
clist c
WHERE
c.part = o.part
AND c.plnt = o.plnt;
commit;

View File

@ -1,29 +0,0 @@
UPDATE
rlarp.osmfs 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.adj_shipdate BETWEEN gld.sdat AND gld.edat

View File

@ -1,336 +0,0 @@
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

@ -1,112 +0,0 @@
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

@ -1,39 +0,0 @@
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