BEGIN;

WITH 
targ AS (
    SELECT shipgrp, dsm, factor::numeric factor FROM (VALUES
('THE HOME DEPOT','50802 - TONY LANDINO','0.440751824'),
('VAS AGRICULTURAL SUPPLY','12024 - JORDAN BUKOWSKI','-0.8601909665'),
('GABRIEL FARMS INC','30053 - SKYE SAWYER','-0.0715868208'),
('ALTMAN PLANTS','13028 - RICHARD MEULE','0.016339572'),
('COSTA','13028 - RICHARD MEULE','0.2508189317'),
('GREENLEAF NURSERY','10040 - RYAN CHITWOOD','-0.412598872'),
('GREENLEAF NURSERY','10041 - TAMARA RISKEN','0.0199982064'),
('AMAZON.COM','90015 - ANN MARIE FOX','-0.5665240102'),
('MENARDS','50802 - TONY LANDINO','-0.5519801472'),
('DIAMOND R','12024 - JORDAN BUKOWSKI','0.0104182224'),
('EXCEL FARMS','10039 - DUSTIN KUYKENDOLL','-0.0000011839'),
('BRON & SONS NURSERY','40042 - TOM MORRIS','0.0000014073'),
('K&M','10039 - DUSTIN KUYKENDOLL','-0.0000135002'),
('PACIFIC NURSERY POTS','30054 - JASON MOTTIN','-0.6312431332'),
('JOHNSON FARMS','10043 - CHERISSE GILSTROP','-1'),
('BLUE SKY NURSERY','40039 - DAVE BODO','0.0012046155'),
('BFG SUPPLY','12024 - JORDAN BUKOWSKI','-0.366117146'),
('J FRANK SCHMIDT & SON','30053 - SKYE SAWYER','-0.0009623929'),
('RAILROAD NURSERY','10039 - DUSTIN KUYKENDOLL','-0.0000057726'),
('HYDROFARM','10043 - CHERISSE GILSTROP','-0.5000064822'),
('HYDROFARM','30035 - RODNEY RIOS','-0.8226750126'),
('GRIFFIN','12024 - JORDAN BUKOWSKI','2.3176518423'),
('ARIS KEEPSAKE','10039 - DUSTIN KUYKENDOLL','0.0000016618'),
('BWI','12024 - JORDAN BUKOWSKI','-0.136024701'),
('MOREJON FARMS','10039 - DUSTIN KUYKENDOLL','-0.0000021757'),
('GREEN ISLAND DISTRIBUTORS INC','10042 - JEREMY RHAULT','-0.0999971942'),
('LOUIS DAVINO SR LLC','12010 - CHRIS SOLTIS','0.0000272248'),
('WALNUT SPRINGS - GLENWOOD','10043 - CHERISSE GILSTROP','-1'),
('CLI COLOR','10039 - DUSTIN KUYKENDOLL','-0.0000349348'),
('FRED MEYER','12026 - JAMEY SCHIESSWOHL','-0.1316064985'),
('EMERALD COAST GROWERS','10043 - CHERISSE GILSTROP','0'),
('EMERALD COAST GROWERS','10049 - STEVEN STUPPIELLO','0'),
('GREENHOUSE MEGASTORE','13027 - STEVE RUSTEBERG','-0.1236816944'),
('CY GROWERS SUPPLIES LTD','40042 - TOM MORRIS','-0.1094421705'),
('JR SIMPLOT','30053 - SKYE SAWYER','-0.0734864387'),
('MEANS NURSERY','30053 - SKYE SAWYER','-0.0795608156'),
('A MILIAN','10039 - DUSTIN KUYKENDOLL','0.0000497803'),
('KINNEY BONDED','10041 - TAMARA RISKEN','0.019962672'),
('PLANT ODYSSEY INC','10041 - TAMARA RISKEN','0.0199875015'),
('HAPPY PLANTS','10046 - DUSTIN KUYKENDOLL 2','-0.0000047103'),
('RA DUDLEY','10040 - RYAN CHITWOOD','-1'),
('CIVANO NURSERY','30035 - RODNEY RIOS','-0.2980987747'),
('BABIKOW GREENHOUSES','10043 - CHERISSE GILSTROP','0.0000196166'),
('HERITAGE LANDSCAPE','12024 - JORDAN BUKOWSKI','-0.04285507'),
('BYLANDS','40042 - TOM MORRIS','-0.0053753495'),
('WINDMILL NURSERY','13028 - RICHARD MEULE','-1'),
('GRAYS ORNAMENTAL','10039 - DUSTIN KUYKENDOLL','-0.3226838413'),
('DALLAS JOHNSON GREENHOUSE','13025 - JAMES REGER','-1'),
('CONROE GREENHOUSES INC','10041 - TAMARA RISKEN','15.8241676329'),
('GREEN CIRCLE','13025 - JAMES REGER','-1'),
('GRC AGROINDUSTRIAL','10039 - DUSTIN KUYKENDOLL','0.0000150273'),
('CARLIN HORTICULTURAL SUPP','13027 - STEVE RUSTEBERG','-0.29834931'),
('BRANTLEY NURSERIES','10049 - STEVEN STUPPIELLO','-0.0000117946'),
('SPANISH RIVER NURSERY','10039 - DUSTIN KUYKENDOLL','-0.0000481066'),
('RICHARDSON BROS GREENHOUSE INC','13027 - STEVE RUSTEBERG','-0.0000166548'),
('THREE VOLCANOES FARM','10049 - STEVEN STUPPIELLO','0.000003968'),
('DICKMAN FARM & GREENHOUSE','10042 - JEREMY RHAULT','-1'),
('SMITH GARDENS INC','30053 - SKYE SAWYER','-0.0167235656'),
('SMITH GARDENS INC','30054 - JASON MOTTIN','-1'),
('YODERS PRODUCE','10048 - PHILIP BIEDENBACH','-0.1236827566'),
('FULL BLOOM MARKET GDNS','10042 - JEREMY RHAULT','-0.0000232378'),
('TERIS SUPPLY SERVICES','40043 - JEFFREY SCHAEFER','0.0679511504'),
('LA FERME GROVER INC','40043 - JEFFREY SCHAEFER','-0.0765125598'),
('FARMERS COOP','10035 - MATTHEW STAAL','-1'),
('OCEAN STATE JOBBERS','12026 - JAMEY SCHIESSWOHL','-0.5254427663'),
('NATURES WAY NRSY OF MIAMI INC','10039 - DUSTIN KUYKENDOLL','-0.00000336'),
('BEAVER NURSERY','12028 - JACOB WILKINSON','0.248451206'),
('AL PAR PEAT CO','10035 - MATTHEW STAAL','-1'),
('WYATT QUARLES','10040 - RYAN CHITWOOD','-0.058431792'),
('DEWAR NURSERIES','10046 - DUSTIN KUYKENDOLL 2','0.6966861322'),
('CALIFORNIA PLANT CO','30035 - RODNEY RIOS','-1'),
('PLANTPEDDLER INC','13027 - STEVE RUSTEBERG','-0.3000161715'),
('KRUEGER-MADDUX GREENHOUSES','10048 - PHILIP BIEDENBACH','-1'),
('MCALLISTER GREENHOUSES','10040 - RYAN CHITWOOD','-1'),
('YOUNGS PLANT FARM INC','13025 - JAMES REGER','-1'),
('SEPERS NURSERY','10043 - CHERISSE GILSTROP','-0.0000009416'),
('WILSON NURSERY & GARDEN CENTER','10040 - RYAN CHITWOOD','0.0000097942'),
('MICHAELS NURSERY','10041 - TAMARA RISKEN','0.0200335767'),
('REKKER GARDENS INC','40040 - TINA PETTIGREW','0'),
('PURA INDUSTRIES NY LLC','10042 - JEREMY RHAULT','-0.0000115999'),
('BLOOM MASTERS','10049 - STEVEN STUPPIELLO','0.0000301392'),
('BAMBOO HAMMOCK','10039 - DUSTIN KUYKENDOLL','-1'),
('METROLINA','13025 - JAMES REGER','-1'),
('GARDEN STATE GROWERS','10043 - CHERISSE GILSTROP','-1'),
('JC BAKKER & SONS','40039 - DAVE BODO','-1'),
('DEVRY GREENHOUSES','40042 - TOM MORRIS','-1'),
('THREE RIVERS NURSERY','10049 - STEVEN STUPPIELLO','-0.0000209756'),
('DOUG INGRAM NURSERY','10039 - DUSTIN KUYKENDOLL','-0.000036888'),
('JOLLY FARMER CO INC','10042 - JEREMY RHAULT','0.0250241111'),
('NUTRIEN AG SOLUTIONS','30035 - RODNEY RIOS','-0.5080022231'),
('NUTRIEN AG SOLUTIONS','40042 - TOM MORRIS','-1'),
('ARETT SALES','12026 - JAMEY SCHIESSWOHL','0.0338398347'),
('CAVICCHIO GREENHOUSES INC','10042 - JEREMY RHAULT','0.0000008435'),
('HYBELS','10035 - MATTHEW STAAL','-1'),
('RECORD BUCK FARMS INC','10046 - DUSTIN KUYKENDOLL 2','-0.0000122924'),
('THE ARBORY','40039 - DAVE BODO','-0.0000225592'),
('INTEGRITY PROPAGATION LLC','10043 - CHERISSE GILSTROP','-0.0032525443'),
('RAINBOW GREENHOUSES','40042 - TOM MORRIS','-0.000104256'),
('FRANTZ WHOLESALE NSY LLC','30054 - JASON MOTTIN','-0.3196442316'),
('ARMSTRONG GROWERS','30035 - RODNEY RIOS','-0.212703206'),
('RED OAK GREENHOUSES','13027 - STEVE RUSTEBERG','-0.3000260875'),
('OBC NORTHWEST INC','30053 - SKYE SAWYER','0.0206653268'),
('JIFFY PRODUCTS OF AMERICA','10048 - PHILIP BIEDENBACH','-1'),
('MAAX BATH INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('VM INNOVATIONS-IN','90015 - ANN MARIE FOX','-1'),
('POLY PLASTIC','70011 - DNU-SUSAN MURTAUGH','-1'),
('MAPLE LEAF NURSERIES LTD','40040 - TINA PETTIGREW','-0.8443683117'),
('DESERT TREE FARM','30035 - RODNEY RIOS','-1'),
('GROWERS DEPOT INC','30035 - RODNEY RIOS','-0.5281922805'),
('WELBY GARDENS','12028 - JACOB WILKINSON','-0.0561280093'),
('MINDERS NURSERY - MANHEIM','10043 - CHERISSE GILSTROP','-0.0000393453'),
('SUR-SEAL PACKAGING','70011 - DNU-SUSAN MURTAUGH','-1'),
('IWASAKI BROS INC','30053 - SKYE SAWYER','-0.0126515783'),
('VAN WINGERDEN INTERNATIONAL','10040 - RYAN CHITWOOD','-1'),
('MATSUDAS','30035 - RODNEY RIOS','-0.2886618125'),
('OLEANDER AVE','30054 - JASON MOTTIN','-1'),
('AMBS FOLIAGE INC','10046 - DUSTIN KUYKENDOLL 2','0.0000034137'),
('HOLLANDIA NURSERY','30054 - JASON MOTTIN','-0.3004302354'),
('K & M NURSERY','10039 - DUSTIN KUYKENDOLL','-1'),
('FOLIDAGE CREEK NURSERY','10041 - TAMARA RISKEN','0.0199707404'),
('CANADIAN TIRE CORP LTD','12026 - JAMEY SCHIESSWOHL','-0.0220333464'),
('CANDLELIGHT CABINETRY','70011 - DNU-SUSAN MURTAUGH','-1'),
('QUALITY GHSE & PERENNIAL FARM','10048 - PHILIP BIEDENBACH','-1'),
('ONE FLORAL','40039 - DAVE BODO','-1'),
('RAZBUTONS INC','10046 - DUSTIN KUYKENDOLL 2','0.0000159734'),
('CUPP & SONS NURSERY','10042 - JEREMY RHAULT','-1'),
('HJS WHOLESALE LTD','40040 - TINA PETTIGREW','0.00009371'),
('CM BROWN NURSERIES INC','10048 - PHILIP BIEDENBACH','-1'),
('KENT''S NURSERY','10041 - TAMARA RISKEN','0.0200605171'),
('RUIBALS PLANTS OF TEXAS','10041 - TAMARA RISKEN','0.0200042193'),
('VM INNOVATIONS-PA','90015 - ANN MARIE FOX','1.5920580878'),
('ACOSTA','10039 - DUSTIN KUYKENDOLL','0.0000257142'),
('KC SCHAEFER SUPPLY','10043 - CHERISSE GILSTROP','-0.5000270916'),
('ENCHANTED GARDENS','10041 - TAMARA RISKEN','0.0199827174'),
('J&R EXOTIC FOLIAGE','10039 - DUSTIN KUYKENDOLL','0.0000257142'),
('ALLSEATING CORPORATION  (C)','70011 - DNU-SUSAN MURTAUGH','-1'),
('WILLIAMS PLANT FARM','10040 - RYAN CHITWOOD','-0.0000415724'),
('WOLFPACK PACKAGING INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('HYDROGARDEN SUPPLY SERVICES','40040 - TINA PETTIGREW','-0.0000030116'),
('JOSEPH DAVINO & SONS','10043 - CHERISSE GILSTROP','-1'),
('PIONEER PACKAGING','70011 - DNU-SUSAN MURTAUGH','-1'),
('KITH FURNITURE','70011 - DNU-SUSAN MURTAUGH','-1'),
('GREAT DANE NURSERY','10046 - DUSTIN KUYKENDOLL 2','-0.0000286859'),
('GEORGE SANT & SONS','40039 - DAVE BODO','-1'),
('AARON''S CREEK FARMS INC','10040 - RYAN CHITWOOD','-0.0002477164'),
('GREENHOUSE & GARDEN SUPPLY INC','12028 - JACOB WILKINSON','0.0997796775'),
('DO IT BEST','12026 - JAMEY SCHIESSWOHL','1.0535583302'),
('PLEASANT VALLEY FARM INC','10041 - TAMARA RISKEN','0.0306236644'),
('DEGOEDE BROTHERS LLC','30053 - SKYE SAWYER','-0.0405669773'),
('ROCKWELL FARMS','13025 - JAMES REGER','-1'),
('URBAN GROWERS','10048 - PHILIP BIEDENBACH','-1'),
('FRANK SMITH NURSERY','10040 - RYAN CHITWOOD','0.0001029045'),
('LEIDER GREENHOUSES','13027 - STEVE RUSTEBERG','-1'),
('REDDING FARMS LLC','10039 - DUSTIN KUYKENDOLL','0.0000325335'),
('BAUCOMS NURSERY COMPANY','10040 - RYAN CHITWOOD','0.0000415918'),
('RIVERBEND NURSERY LLC','10040 - RYAN CHITWOOD','-1'),
('PERENNIAL FAVORITES','12028 - JACOB WILKINSON','-0.1000068838'),
('BRADFORD CO-OP STORAGE LTD','40040 - TINA PETTIGREW','0.0001125369'),
('SKAGIT','30054 - JASON MOTTIN','-1'),
('HILLCREST NURSERY','10043 - CHERISSE GILSTROP','0.0000254784'),
('TREELAND NURSERIES','30035 - RODNEY RIOS','-0.2876943211'),
('CLINTON NURSERIES INC.','10042 - JEREMY RHAULT','-0.0000028571'),
('DS COLE GROWERS','10042 - JEREMY RHAULT','-0.0000385037'),
('PROFESSIONAL GARDENER CO','40042 - TOM MORRIS','-0.0070326166'),
('MAGIC GREENS','10039 - DUSTIN KUYKENDOLL','0.0000998055'),
('ELGIN TREE FARM INC','30035 - RODNEY RIOS','-0.2343502839'),
('KUBE PAK CORPORATION','10043 - CHERISSE GILSTROP','0.0001013'),
('METROLINA GREENHOUSES','13025 - JAMES REGER','-1'),
('CAL COLOR','30054 - JASON MOTTIN','-1'),
('BAILEY NURSERIES INC','10040 - RYAN CHITWOOD','-1'),
('BAILEY NURSERIES INC','13027 - STEVE RUSTEBERG','-1'),
('GREEN THINGS','30035 - RODNEY RIOS','-1'),
('FLOWERLAND GARDEN CTR OF CLEVE','13025 - JAMES REGER','-1'),
('FREEMAN HERBS','40039 - DAVE BODO','0.0000638169'),
('ISLAND GROWER SUPPLIES LLC','30035 - RODNEY RIOS','0.0307130885'),
('T&L NURSERY INC','30053 - SKYE SAWYER','-0.0042972977'),
('HARDING NURSERY','12028 - JACOB WILKINSON','0.1499256715'),
('LINWYCK GARDENS','10043 - CHERISSE GILSTROP','-0.0000210014'),
('HUMMERT INTERNATIONAL','13027 - STEVE RUSTEBERG','-0.3002573298'),
('RADEBAUGH GREENHOUSE','10043 - CHERISSE GILSTROP','-1'),
('CREACH GREENHOUSES','30053 - SKYE SAWYER','0.0730369292'),
('WOODBURN NURSERY','30053 - SKYE SAWYER','-1'),
('INDOOR SUN HYDRO','30054 - JASON MOTTIN','-1'),
('HIONIS GREENHOUSE INC','10043 - CHERISSE GILSTROP','-0.0409862709'),
('BAJA CACTUS AND SUCCULENTS','30054 - JASON MOTTIN','0.0072846828'),
('JOSEPH''S NURSERY','10041 - TAMARA RISKEN','0.0200076151'),
('CHARLES SPITZNER','10042 - JEREMY RHAULT','0.1500830025'),
('A-MILLIAN PLANTS','10039 - DUSTIN KUYKENDOLL','-1'),
('VM INNOVATIONS-NV','90015 - ANN MARIE FOX','-1'),
('KURT WEISS','10042 - JEREMY RHAULT','-1'),
('EVERBLOOM GROWERS INC','10039 - DUSTIN KUYKENDOLL','0.0000604212'),
('MANNINGS GREENHOUSE','12028 - JACOB WILKINSON','-0.0000531462'),
('BI WATER FARM & GREENHOUSE','10048 - PHILIP BIEDENBACH','0.0119085591'),
('PACK''S NURSERY INC','10049 - STEVEN STUPPIELLO','-1'),
('DISTRIBUTION FRANKARL INC','40043 - JEFFREY SCHAEFER','0.0713028573'),
('BOETHING TREE FARM','30035 - RODNEY RIOS','0.3263039225'),
('CLIFFORDS PERENNIAL & VINE','10040 - RYAN CHITWOOD','-1'),
('EVERDE','30035 - RODNEY RIOS','-1'),
('DUTCHMAN TREE FARM','10035 - MATTHEW STAAL','0.0309023282'),
('RED BARN SUPPLY','13027 - STEVE RUSTEBERG','-0.306708479'),
('CASSCO','10049 - STEVEN STUPPIELLO','-1'),
('F & B FARMS','30053 - SKYE SAWYER','-0.0033209346'),
('GULLEY GREENHOUSE','12028 - JACOB WILKINSON','-0.1501501531'),
('KAWAHARA NURSERY','30054 - JASON MOTTIN','5.7110911724'),
('CHAPARRAL PLUMBING CO INC','10041 - TAMARA RISKEN','0.0200520833'),
('EDWARDS GNHSE & FLOWERSHOP LLC','12028 - JACOB WILKINSON','0.000020116'),
('EAGLE CREEK WHOLESALE','10048 - PHILIP BIEDENBACH','-1'),
('MORTELLAROS NURSERY','10041 - TAMARA RISKEN','0.0199538016'),
('PACIFIC GROWER','30053 - SKYE SAWYER','0.0241844078'),
('NORTHLAND TREE FARM','40039 - DAVE BODO','-0.0000268663'),
('PASTANCH LLC','10042 - JEREMY RHAULT','-0.2999789467'),
('HOLMBERG FARMS INC','10039 - DUSTIN KUYKENDOLL','0.0000609575'),
('CROSS CREEK / HANOVER FARMS','10040 - RYAN CHITWOOD','0.0000692419'),
('NEAL MAST & SON GREENHOUSES','10035 - MATTHEW STAAL','-1'),
('WILLOWBROOK NURSERIES INC','40039 - DAVE BODO','-1'),
('VM INNOVATIONS-GA','90015 - ANN MARIE FOX','-1'),
('OLSONS GREENHOUSE GARDENS','12028 - JACOB WILKINSON','0.000037714'),
('VERAS NURSERY INC','13028 - RICHARD MEULE','-1'),
('ACE HARDWARE','12026 - JAMEY SCHIESSWOHL','-0.3712496921'),
('KEMBER FLOORS WAREHOUSE','70011 - DNU-SUSAN MURTAUGH','-1'),
('A&R BELLEY','70011 - DNU-SUSAN MURTAUGH','-1'),
('NANA''S BLOOMERS','12028 - JACOB WILKINSON','0.1498426531'),
('JOHN WEDDINGTON GREENHOUSE','10040 - RYAN CHITWOOD','-1'),
('GRAVANO FARMS','10040 - RYAN CHITWOOD','-0.8373113252'),
('WALLA WALLA NURSERY CO','30053 - SKYE SAWYER','-0.0004426839'),
('SALMON WHOLESALE NURSERY','10049 - STEVEN STUPPIELLO','-0.0000122924'),
('CATOCTIN MOUNTAIN GROWERS','10043 - CHERISSE GILSTROP','-1'),
('WENGERLAWN NURSERY CO','10048 - PHILIP BIEDENBACH','-1'),
('BIOFLORAL INC','40043 - JEFFREY SCHAEFER','0.0141502354'),
('BRADS BEDDING PLANTS INC','10039 - DUSTIN KUYKENDOLL','0.0000399548'),
('MILARCH NURSERY INC','10035 - MATTHEW STAAL','-0.1495858143'),
('KEMBER INTERIORS CARTERSVILLE','70011 - DNU-SUSAN MURTAUGH','-1'),
('VM INNOVATIONS-TX','90015 - ANN MARIE FOX','-1'),
('VARNERS GREENHOUSE','10035 - MATTHEW STAAL','-1'),
('C STARS NURSERY','30035 - RODNEY RIOS','0.8597159708'),
('RONA','12026 - JAMEY SCHIESSWOHL','-0.0946765369'),
('AMA PLASTICS','40040 - TINA PETTIGREW','-0.0001141491'),
('EVERDE - HUNTINGTON BEACH','30035 - RODNEY RIOS','-1'),
('GREENBELT GROWERS','30035 - RODNEY RIOS','-0.0035076531'),
('SPARETIME SUPPLY','30054 - JASON MOTTIN','-1'),
('OSI PACKAGING LLC','70011 - DNU-SUSAN MURTAUGH','-1'),
('5 STAR','10040 - RYAN CHITWOOD','-1'),
('AJ BILLES DC CANADIAN TIRE','12026 - JAMEY SCHIESSWOHL','0.4251180352'),
('ORLANDO NURSERY INC','10039 - DUSTIN KUYKENDOLL','-1'),
('ARIZONA EAST','10046 - DUSTIN KUYKENDOLL 2','0.0000044107'),
('THE GROOVY PLANTS RANCH LLC','10048 - PHILIP BIEDENBACH','-0.0149155531'),
('GERTEX DISTRIBUTING INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('GLOBAL CASEGOODS','70011 - DNU-SUSAN MURTAUGH','-1'),
('PREMIER COLOR','30035 - RODNEY RIOS','0.2114662861'),
('B&T GROWERS SUPPLY','10041 - TAMARA RISKEN','-1'),
('VAN WINGERDEN GREENHOUSES','30053 - SKYE SAWYER','0.0406244163'),
('KEMBER INTERIORS','70011 - DNU-SUSAN MURTAUGH','-1'),
('OTTO-EMMAS','10042 - JEREMY RHAULT','0'),
('HYDRO EASY GROW','10041 - TAMARA RISKEN','-1'),
('SUPPLYONE CANADA INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('J BERRY NURSERY','10041 - TAMARA RISKEN','-1'),
('NIAGARA CONSERVATION CORP.','70011 - DNU-SUSAN MURTAUGH','-1'),
('FERNWOOD NURSERIES INC','10047 - RYAN CHITWOOD 2','-1'),
('MEYERS FRUIT FARM','70011 - DNU-SUSAN MURTAUGH','-1'),
('MARTINS PRODUCE','10048 - PHILIP BIEDENBACH','2.6023433902'),
('JONGS ORGANIC FERTILIZER','30035 - RODNEY RIOS','-1'),
('ZINO NURSERIES','10042 - JEREMY RHAULT','-1'),
('MONTEREY BOTANICALS','30054 - JASON MOTTIN','-0.085653176'),
('BATEMAN GREENHOUSES','10042 - JEREMY RHAULT','-0.0000634523'),
('DUARTE NURSERY','30054 - JASON MOTTIN','-0.0621968551'),
('PURE BEAUTY FARMS','10040 - RYAN CHITWOOD','-0.0000294542'),
('MOUSER CABINETRY','70011 - DNU-SUSAN MURTAUGH','-1'),
('NORTEX NURSERIES','10041 - TAMARA RISKEN','0.0204598002'),
('GRAINGER FARMERS CO-OP','10040 - RYAN CHITWOOD','0.000204654'),
('VANDENBERG BULB CO INC','10035 - MATTHEW STAAL','-1'),
('BRADLEY CALDWELL INC','12026 - JAMEY SCHIESSWOHL','0.4966431753'),
('MOUNTAIN VIEW GREENHOUSES','10040 - RYAN CHITWOOD','-1'),
('W ATLEE BURPEE & CO','10048 - PHILIP BIEDENBACH','-1'),
('PIKE NURSERIES','10040 - RYAN CHITWOOD','-1'),
('SUBURBAN LAWN & GDN INC','10041 - TAMARA RISKEN','0.0200565389'),
('ROEBUCK WHOLESALE NURSERY','10040 - RYAN CHITWOOD','-1'),
('DBA COUNTRYSIDE GREENHOUSE INC','10035 - MATTHEW STAAL','-1'),
('RITCHIE FEED & SEED','40043 - JEFFREY SCHAEFER','-0.0281052901'),
('EARL MAY AMES','13027 - STEVE RUSTEBERG','-0.3500851409'),
('THREE H FURNITURE','70011 - DNU-SUSAN MURTAUGH','-1'),
('HOME HARDWARE STORES','12026 - JAMEY SCHIESSWOHL','0.3281120678'),
('EARL MAY SEED','13027 - STEVE RUSTEBERG','-0.1502231632'),
('WADE NURSERY','10040 - RYAN CHITWOOD','-1'),
('MOSS GREENHOUSES, INC.','12028 - JACOB WILKINSON','-0.0998029064'),
('SLAPPENDEL GREENHOUSES','40039 - DAVE BODO','-1'),
('BAUMAN FARMS','30053 - SKYE SAWYER','-1'),
('RUSTY OAK NURSERY LTD','10048 - PHILIP BIEDENBACH','0.0063656121'),
('GREEN LAKE NURSERY','10041 - TAMARA RISKEN','0.0200507993'),
('CANOYERS-NE','13027 - STEVE RUSTEBERG','-0.3002345676'),
('RUSHTON FARMS','10035 - MATTHEW STAAL','-0.1140616141'),
('SELECT TREES INC','10040 - RYAN CHITWOOD','-1'),
('RIVERSIDE SUPPLY','10042 - JEREMY RHAULT','-1'),
('PLEASANT VIEW GARDENS','13028 - RICHARD MEULE','-1'),
('DOWNSVIEW KITCHENS','70011 - DNU-SUSAN MURTAUGH','-1'),
('LENERTZ INDUSTRIAL SUPPLY CO','70011 - DNU-SUSAN MURTAUGH','-1'),
('SILVER CANYON NURSERY','30035 - RODNEY RIOS','0.7939294575'),
('WALLACES GARDEN CENTER','13027 - STEVE RUSTEBERG','-1'),
('WEIGEL FARMS - GIBSONVILLE','10040 - RYAN CHITWOOD','-1'),
('AMHERST GREENHOUSE','10048 - PHILIP BIEDENBACH','-1'),
('COLLIERS GREENHOUSE','10040 - RYAN CHITWOOD','-1'),
('GREEN LEGACY','10048 - PHILIP BIEDENBACH','-1'),
('KROGER','12026 - JAMEY SCHIESSWOHL','-0.0200505497'),
('IMPERIAL DADE CANADA INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('COOKS FARM & GHSE','12028 - JACOB WILKINSON','0.0005816715'),
('NOEL WILSON INC','40043 - JEFFREY SCHAEFER','0.1669751449'),
('DEBONO GREENHOUSES LTD','40040 - TINA PETTIGREW','-1'),
('K W COUNTERTOP','70011 - DNU-SUSAN MURTAUGH','-1'),
('HENDRIKS & SON GREENHOUSE','40039 - DAVE BODO','-1'),
('PINEAE GREENHOUSES & DIST INC','12028 - JACOB WILKINSON','0.0002667378'),
('CONFREDA GREENHOUSE','10042 - JEREMY RHAULT','0'),
('DAVIDS NURSERY (DIV. SHEELIE)','10041 - TAMARA RISKEN','0.0201554448'),
('CASCADES CONTAINERBOARD PKG','70011 - DNU-SUSAN MURTAUGH','-1'),
('TRUE VALUE','12026 - JAMEY SCHIESSWOHL','-1'),
('ESHRAGHI NURSERIES LLC','30053 - SKYE SAWYER','-1'),
('WCP SOLUTIONS','70011 - DNU-SUSAN MURTAUGH','-1'),
('FREE STATE GROWERS INC','10041 - TAMARA RISKEN','0.0204279214'),
('DIXIE GREEN','10049 - STEVEN STUPPIELLO','-1'),
('DOWN HOME RANCH','10041 - TAMARA RISKEN','0.0201178726'),
('HORTMARK','10035 - MATTHEW STAAL','-1'),
('BELL NURSERY','10040 - RYAN CHITWOOD','-1'),
('GRACE ROSE FARM','30035 - RODNEY RIOS','-1'),
('AYA KITCHENS AND BATH LTD','70011 - DNU-SUSAN MURTAUGH','-1'),
('SKH WHOLESALE DIST','12026 - JAMEY SCHIESSWOHL','-1'),
('FOX HOLLOW FARMS INC','40039 - DAVE BODO','-0.0000114658'),
('TOM STRAIN AND SONS','10048 - PHILIP BIEDENBACH','-0.0003152852'),
('ZYWICKI GREENHOUSE','10035 - MATTHEW STAAL','-1'),
('ALLWOOD PRODUCTS','70011 - DNU-SUSAN MURTAUGH','-1'),
('SOUTH CENTRAL GROWERS INC','13025 - JAMES REGER','0.133992561'),
('PARSONS NURSERY INC','10040 - RYAN CHITWOOD','0.0004602117'),
('SUNBLEST GARDENS','10049 - STEVEN STUPPIELLO','23.2454076168'),
('TOTALTOYS INC','12026 - JAMEY SCHIESSWOHL','0.028277635'),
('INTERMOUNTAIN FARMERS ASSN','12026 - JAMEY SCHIESSWOHL','-0.0112696963'),
('NEIL VANDERKRUK HOLDINGS','40039 - DAVE BODO','-1'),
('APPLE VALLEY GREENHOUSE','12028 - JACOB WILKINSON','-1'),
('ALLIANCE INTERNATIONAL LLC','12026 - JAMEY SCHIESSWOHL','-0.5074741986'),
('DEANS GREENHOUSE INC','10048 - PHILIP BIEDENBACH','-1'),
('SEWICKLEY CREEK GREENHOUSE','10048 - PHILIP BIEDENBACH','-1'),
('FEDERATED CO-OPERATIVES LTD','12026 - JAMEY SCHIESSWOHL','1.0361043655'),
('TRUE LEAF','12028 - JACOB WILKINSON','-1'),
('PEPINIERE ABBOTSFORD','40043 - JEFFREY SCHAEFER','-1'),
('GUTHRIE GREENHOUSES','10041 - TAMARA RISKEN','1.018860266'),
('NAUSET ENTERPRISES','70011 - DNU-SUSAN MURTAUGH','-1'),
('ROWE PLANT FARM','10041 - TAMARA RISKEN','0.0199105766'),
('PR BEAN CO LLC','70011 - DNU-SUSAN MURTAUGH','-1'),
('HORIZON PLANTS LLC','10035 - MATTHEW STAAL','-1'),
('SUPPLYONE PHILADELPHIA','70011 - DNU-SUSAN MURTAUGH','-1'),
('WILDHAGEN GREENHOUSES','40039 - DAVE BODO','-1'),
('EAST COAST NURSERIES','10042 - JEREMY RHAULT','-1'),
('CCF INDUSTRIES','70011 - DNU-SUSAN MURTAUGH','-1'),
('SHIPPERS SUPPLY INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('FOSTERS INC','12026 - JAMEY SCHIESSWOHL','-1'),
('JOYFUL BUTTERFLY','10040 - RYAN CHITWOOD','-1'),
('ALDERSHOT GREENHOUSES','40039 - DAVE BODO','20.6720986337'),
('STACKTECK','OTH - OTHER ACCOUNTS - REP UNDEFINED','-1'),
('PEPINIERE LEMAY INC','40043 - JEFFREY SCHAEFER','-1'),
('CANAPA VALLEY','10035 - MATTHEW STAAL','-1'),
('IVY ACRES','10042 - JEREMY RHAULT','-1'),
('KEMMERS PLANTS','10048 - PHILIP BIEDENBACH','0.0416666667'),
('WARDS GREENHOUSE','12028 - JACOB WILKINSON','-1'),
('GENERAL FILMS, INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('POSSIBILITY PLACE NURSERY','13027 - STEVE RUSTEBERG','-0.3512132822'),
('MISSOURI WILDFLOWERS NURSERY','13027 - STEVE RUSTEBERG','-0.3015414258'),
('DA HOERR & SONS INC','13027 - STEVE RUSTEBERG','-0.2891111438'),
('MAPLE GREENHOUSES','40039 - DAVE BODO','-1'),
('FLRISH FARMS','30054 - JASON MOTTIN','-1'),
('KERKSIEK WOOD DESIGN INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('WORTHINGTON FARMS INC','10040 - RYAN CHITWOOD','0.0000818398'),
('KOCH & CO. INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('HORIZON DISTRIBUTION INC','12026 - JAMEY SCHIESSWOHL','-1'),
('FULCRUM ACOUSTIC LLC','70011 - DNU-SUSAN MURTAUGH','-1'),
('JOE PYE','10043 - CHERISSE GILSTROP','-1'),
('ADARIO SALES','10048 - PHILIP BIEDENBACH','-1'),
('THE BOX MAKER INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('BURO UNIQUE DESIGNS, INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('SALIBA, MARTIN','40039 - DAVE BODO','-1'),
('HARTS GREENHOUSE & FLORIST','10042 - JEREMY RHAULT','-1'),
('POST GARDENS','10035 - MATTHEW STAAL','-1'),
('OLSONS GREENHOUSE','10042 - JEREMY RHAULT','0.0984783754'),
('ERVA TOOL & DIE CO','12026 - JAMEY SCHIESSWOHL','0.1337457512'),
('POTVIN CONSTRUCTION LIMITED','70011 - DNU-SUSAN MURTAUGH','-1'),
('DARRELL NORRIS','10048 - PHILIP BIEDENBACH','-1'),
('WALDO & ASSOCIATES','10048 - PHILIP BIEDENBACH','-1'),
('GREEN TECH GREENHOUSES','10040 - RYAN CHITWOOD','-1'),
('HAFNER''S GREENHOUSES','13027 - STEVE RUSTEBERG','-1'),
('COIVIC CONTRACTING LTD','40040 - TINA PETTIGREW','-1'),
('LANDA PACKAGING DISTRIBUTIONS','70011 - DNU-SUSAN MURTAUGH','-1'),
('WHITEBIRD','70011 - DNU-SUSAN MURTAUGH','-1'),
('MARLIN ORCHARDS &GARDEN CENTRE','40040 - TINA PETTIGREW','-1'),
('GREEN LEAF PLANT FARM','10040 - RYAN CHITWOOD','-1'),
('TAWAKONI PLANT FARM','10041 - TAMARA RISKEN','0.02'),
('NUNAN THE FLORIST','10042 - JEREMY RHAULT','-1'),
('CW KITCHENS INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('NURSERYLAND','12026 - JAMEY SCHIESSWOHL','-1'),
('BUCKERFIELDS ABBOTSFORD','12026 - JAMEY SCHIESSWOHL','0.4237712854'),
('KURTZ CHRISTMAS TREE FARM','10048 - PHILIP BIEDENBACH','-0.041662683'),
('GAB - INDUSPAC LTEE','70011 - DNU-SUSAN MURTAUGH','-1'),
('CANAC MARQUIS GRENIER','12026 - JAMEY SCHIESSWOHL','-1'),
('ECONOBOX - SPRINGBROOK','70011 - DNU-SUSAN MURTAUGH','-1'),
('TEMPO FRAMING SYSTEMS','70011 - DNU-SUSAN MURTAUGH','-1'),
('MIKE & JOHN ROUSH','10048 - PHILIP BIEDENBACH','-1'),
('WALNUT HILL FARM','10042 - JEREMY RHAULT','0.0988065397'),
('MARC DANIEL ENTERPRISES, INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('CANYON CREEK CABINET CO.','70011 - DNU-SUSAN MURTAUGH','-1'),
('ALS GARDEN CENTER','30053 - SKYE SAWYER','-1'),
('CIMARRON LUMBER CO','12026 - JAMEY SCHIESSWOHL','1.719878515'),
('VAN WINGERDEN GREENHOUSE LLC','10043 - CHERISSE GILSTROP','-1'),
('WOJO GREENHOUSES','10035 - MATTHEW STAAL','-1'),
('BUCHWALTER GREENHOUSE','10048 - PHILIP BIEDENBACH','0.1293386367'),
('ERICH GUMTO GREENHOUSE','10048 - PHILIP BIEDENBACH','-1'),
('GREENE BEE GREENHOUSE','10042 - JEREMY RHAULT','-1'),
('BOYERTS GREENHOUSE','10048 - PHILIP BIEDENBACH','-1'),
('DANIEL J WAGNER','10035 - MATTHEW STAAL','-1'),
('GARDEN AVE GREENHOUSE','12028 - JACOB WILKINSON','-1'),
('HALIFAX SEED CO INC','40040 - TINA PETTIGREW','-0.0016432951'),
('RUHLIG FARMS & GARDEN','10035 - MATTHEW STAAL','-1'),
('PL ROHRER & BRO INC     RET','12026 - JAMEY SCHIESSWOHL','-1'),
('MONTEREY BAY NURSERY','30054 - JASON MOTTIN','-1'),
('LIBERTY DISTRIBUTORS, INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('TRILLIUM HILL GREENHOUSES','40039 - DAVE BODO','-1'),
('MARIANI NURSERY INC','13027 - STEVE RUSTEBERG','-0.2755555556'),
('GOTTAS FARM','10042 - JEREMY RHAULT','-1'),
('SOUTHWEST PLANT SUPPLY','30035 - RODNEY RIOS','-1'),
('DRUMMER LANDSCAPE & GARDEN CTR','13027 - STEVE RUSTEBERG','-1'),
('NATALEX MANUFACTURING LTD','70011 - DNU-SUSAN MURTAUGH','-1'),
('CAMPBELLS GREENHOUSE','10035 - MATTHEW STAAL','-1'),
('SUNWIZE POWER AND BATTERY','70011 - DNU-SUSAN MURTAUGH','-1'),
('KW GREENERY','13027 - STEVE RUSTEBERG','-1'),
('CRYSTAL LAKE GREENHOUSE','10042 - JEREMY RHAULT','-1'),
('JONES GREENHOUSE','10047 - RYAN CHITWOOD 2','-1'),
('LUPINE LADY PORCUPINE GNHSE','12028 - JACOB WILKINSON','-1'),
('ARCHITECTUAL BRASS','10040 - RYAN CHITWOOD','-1'),
('BOBS MARKET & GREENHOUSE','10048 - PHILIP BIEDENBACH','-1'),
('HALVERSON FAMILY FARM','10048 - PHILIP BIEDENBACH','-1'),
('KEEPU GROWING LLC','10048 - PHILIP BIEDENBACH','0.0034904014'),
('ABELE GREENHOUSES','10035 - MATTHEW STAAL','-1'),
('ALTON GREENHOUSES','40040 - TINA PETTIGREW','-1'),
('HATCHER LAWN & GREENHOUSE','10048 - PHILIP BIEDENBACH','-1'),
('RIDGEVIEW ORCHARDS LIMITED','40040 - TINA PETTIGREW','-1'),
('SUNRISE GREENHOUSE','10035 - MATTHEW STAAL','-1'),
('CANADIAN FOOD INSPECTION AG','40043 - JEFFREY SCHAEFER','-1'),
('ALLPACK SOLUTIONS INC','70011 - DNU-SUSAN MURTAUGH','-1'),
('CAROLINA PACKAGING & SUPPLY','70011 - DNU-SUSAN MURTAUGH','-1'),
('BARRY WOODLEY GREENHOUSE','40040 - TINA PETTIGREW','-1'),
('PATRICK LYONS GREENHOUSES','10042 - JEREMY RHAULT','-1'),
('TERRA GREENHOUSES LTD','40040 - TINA PETTIGREW','-1'),
('FULLERS NURSERY','10041 - TAMARA RISKEN','0.0244259065'),
('HILLARDS GREENHOUSES','10042 - JEREMY RHAULT','-1'),
('BONNIE BROOKE GARDENS','13027 - STEVE RUSTEBERG','-0.2818671454'),
('SPANISH FORK','12028 - JACOB WILKINSON','-1'),
('TWELVE OAKS FARM','10035 - MATTHEW STAAL','-1'),
('MIKE PARRAN','10035 - MATTHEW STAAL','-1'),
('PERINO''S GARDEN CENTER','10041 - TAMARA RISKEN','0.0282603582'),
('MISSOURI BOTANICAL GARDEN','13027 - STEVE RUSTEBERG','-0.3074854589'),
('FLORIDA STATE UNIVERSITY','10046 - DUSTIN KUYKENDOLL 2','-1'),
('SEMINIS VEGETABLE SEEDS','30035 - RODNEY RIOS','-1'),
('HOOPERS NURSERY GREENHOUSE','12028 - JACOB WILKINSON','-1'),
('PATRICK GIBSON','13027 - STEVE RUSTEBERG','-1'),
('KOHLER LANDSCAPING','13027 - STEVE RUSTEBERG','0.0225489297'),
('SCHROTH WHOLESALE SUPPLY CO','13027 - STEVE RUSTEBERG','-1'),
('THE GARDEN NETWORK','40043 - JEFFREY SCHAEFER','-1'),
('SIERRA VISTA GROWERS','12028 - JACOB WILKINSON','-1'),
('WILSONS GARDEN CENTER','10048 - PHILIP BIEDENBACH','-1'),
('GOODE GREENHOUSE INC','13027 - STEVE RUSTEBERG','-1'),
('BIG BLOOMERS','10040 - RYAN CHITWOOD','-1'),
('ANTONS GREENHOUSE','13027 - STEVE RUSTEBERG','-0.3037974684'),
('SRC CORPORATION','12028 - JACOB WILKINSON','-1'),
('JJ''S ACRES','50105 - GLENKIRK ASSOCIATES INC','-1'),
('MIDDLETOWN NURSERY','10042 - JEREMY RHAULT','-1'),
('PAN AMERICAN SEED','13027 - STEVE RUSTEBERG','-1'),
('TELLYS GREENHOUSE','10035 - MATTHEW STAAL','-1'),
('BLUE SKY FLOWER FARM LLC','13027 - STEVE RUSTEBERG','-1'),
('CARL BREHOB & SON','10048 - PHILIP BIEDENBACH','-1'),
('CBI OPERATIONS LLC','10042 - JEREMY RHAULT','-1'),
('WJ STRASSELL & SONS INC','10048 - PHILIP BIEDENBACH','-1'),
('YOUNGBLOOD NURSERY','30053 - SKYE SAWYER','-1'),
('MADISON TREE FARMS, LLC','10048 - PHILIP BIEDENBACH','-1'),
('LANCASTER GREENHOUSE','10048 - PHILIP BIEDENBACH','-1'),
('CK GREENHOUSES','10042 - JEREMY RHAULT','-1'),
('HIDDEN SPRINGS GREENHOUSE','10043 - CHERISSE GILSTROP','-1'),
('GWINNETT GREENHOUSE','10040 - RYAN CHITWOOD','-1'),
('VIADUCT GARDENS','13027 - STEVE RUSTEBERG','-1'),
('NC WILDLIFE RESOURCE COMM','10040 - RYAN CHITWOOD','-1'),
('STEINBRINK LANDSCAPING CENTER','13027 - STEVE RUSTEBERG','-1'),
('BFG','30053 - SKYE SAWYER','-1'),
('ARAUJO FARMS','10042 - JEREMY RHAULT','-1'),
('PETITTI GARDEN CENTER','50105 - GLENKIRK ASSOCIATES INC','-1'),
('CHATTAHOOCHEE NATURE CENTER','10040 - RYAN CHITWOOD','-1'),
('CANOYERS-IA','13027 - STEVE RUSTEBERG','-1'),
('RICHLAND COMMUNITY COLLEGE','13027 - STEVE RUSTEBERG','-1'),
('BOULEVARD FLOWER GARDENS','50105 - GLENKIRK ASSOCIATES INC','-1'),
('HOLLANDALE LANDSCAPING','40040 - TINA PETTIGREW','-1'),
('MICHIGAN BLUEBERRY GROWERS','10035 - MATTHEW STAAL','-1'),
('QUAD CITY BOTANICAL CTR','13027 - STEVE RUSTEBERG','-1'),
('WINDING CREEK NURSERY','13027 - STEVE RUSTEBERG','-0.3390439932'),
('WILDWOOD ARTISANS','70011 - DNU-SUSAN MURTAUGH','-1'),
('CREATIVE TOUCH FLORAL & GHSE','13027 - STEVE RUSTEBERG','-1'),
('PRIVY PINE','13028 - RICHARD MEULE','-1'),
('FROG HOLLOW FARM','30053 - SKYE SAWYER','-1'),
('BROHLS GREENHOUSE','10035 - MATTHEW STAAL','-1'),
('INDIAN TRAIL GARDEN CENTER','10048 - PHILIP BIEDENBACH','-1'),
('NESSRALLA''S OF AVON INC','10042 - JEREMY RHAULT','-1'),
('LOCKWOOD GHSE & FARM','10042 - JEREMY RHAULT','-1'),
('FARMERS MARKET','10048 - PHILIP BIEDENBACH','-1'),
('MANDEL GREENHOUSE','10035 - MATTHEW STAAL','-1'),
('DRAGONFLY NATIVES LLC','10042 - JEREMY RHAULT','-1'),
('GOLDEN STATE FC','50801 - DNU-MARK WILKINSON','-1'),
('ULSTER AMERICAN HOMSTEAD','10040 - RYAN CHITWOOD','-1'),
('MILLCREEK GARDENS INC','12028 - JACOB WILKINSON','-1'),
('KIM ROSSI','10039 - DUSTIN KUYKENDOLL','-1'),
('AGWAY OF ORLEANS','10042 - JEREMY RHAULT','-1'),
('JENS NORTHSHORE NURSERY','13027 - STEVE RUSTEBERG','-1'),
('CARAS NURSERY','12028 - JACOB WILKINSON','-1'),
('JOST GREENHOUSE','13027 - STEVE RUSTEBERG','-1'),
('DGI PROPAGATORS','10035 - MATTHEW STAAL','-1'),
('LEGACY GROWERS AND NURSERY','10041 - TAMARA RISKEN','-1')
) x(shipgrp,dsm,factor)
-- WHERE 
--     factor::numeric > 0
)
--SELECT * FROM agg_curr
----------------create a log entry--------------------
,log AS (
    INSERT INTO
           rlarp.osm_log(doc)
    SELECT 
        $${
            "message":"forecasted pounds",
            "tag":"baseline",
            "type":"build" 
        }$$::jsonb doc 
    RETURNING *
)
-------build adjustment rows collapsed for all iterations----------
,dv AS (
    SELECT
         o.fspr
        ,o.plnt          ---master data 
        ,o.promo          --history date mix
        ,o.terms
        ,o.bill_cust_descr          --history cust mix
        ,o.ship_cust_descr          --history cust mix
        ,o.dsm
        ,o.quota_rep_descr          --master data 
        ,o.director
        ,o.billto_group          --master data 
        ,o.shipto_group
        ,o.chan          --master data 
        ,o.chansub
        ,o.chan_retail
        ,o.part
        ,o.part_descr
        ,o.part_group
        ,o.branding
        ,o.majg_descr
        ,o.ming_descr
        ,o.majs_descr
        ,o.mins_descr
        ,o.segm
        ,o.substance
        ,o.fs_line          --master data 
        ,o.r_currency          --history cust mix
        ,o.r_rate          --master data 
        ,o.c_currency          --master data 
        ,o.c_rate          --master data 
        ,SUM(Round(o.units*s.factor      /*- o.units     */ ,2)) units
        ,SUM(Round(o.value_loc*s.factor  /*- o.value_loc */ ,2)) value_loc
        ,SUM(Round(o.value_usd*s.factor  /*- o.value_usd */ ,2)) value_usd
        ,SUM(Round(o.cost_loc*s.factor   /*- o.cost_loc  */ ,2)) cost_loc
        ,SUM(Round(o.cost_usd*s.factor   /*- o.cost_usd  */ ,2)) 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
        ,'b26' aS version
        ,'fc pounds' iter
        ,log.id
        ,coalescE(log.doc->>'tag','') AS "tag"
        ,log.doc->>'message' AS "comment"
        ,log.doc->>'type' module
        ,SUM(round(o.pounds*s.factor    ,2)) pounds
    FROM
        rlarp.osm_pool o
        INNER JOIN targ s ON
            s.shipgrp = o.shipto_group
            AND s.dsm = o.quota_rep_descr
        CROSS JOIN log
    WHERE
        o.order_season = 2026
        AND o.order_month IN ('11 - Apr','12 - May')
    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          --master data 
        ,o.r_currency          --history cust mix
        ,o.r_rate          --master data 
        ,o.c_currency          --master data 
        ,o.c_rate          --master data 
        ,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
        ,log.id
        ,coalescE(log.doc->>'tag','')
        ,log.doc->>'message'
        ,log.doc->>'type'
)
-- SELECT * FROM dv
INSERT INTO rlarp.osm_pool SELECT * FROM dv;
--SELECT
--    billto_group
--    ,sum(value_usd) val
--    ,sum(cost_usd) AS cost
--    ,sum(units) units
--FROM
--    dv
--GROUP BY
--    billto_group

COMMIT;
