diff --git a/route_sql/swap_post.sql b/route_sql/swap_post.sql index f126d61..518d69f 100644 --- a/route_sql/swap_post.sql +++ b/route_sql/swap_post.sql @@ -99,7 +99,7 @@ target AS (SELECT $$swap_doc$$::jsonb swap) ,repl AS ( SELECT fspr - ,plnt ---master data + ,m.dplt plnt ---master data ,promo --history date mix ,terms ,bill_cust_descr --history cust mix @@ -116,22 +116,22 @@ target AS (SELECT $$swap_doc$$::jsonb swap) ,m.item || ' - ' || m.descr partd ,substring(pl.replace,1,8) part_group ,m.branding branding - ,m.majgd majg_descr - ,m.mingd ming_descr - ,m.majsd majs_descr - ,m.minsd mins_descr + ,m.majg||' - '||m.majgd majg_descr + ,m.ming||' - '||m.mingd ming_descr + ,m.majs||' - '||m.majsd majs_descr + ,m.mins||' - '||m.minsd mins_descr ,seg.segm ,substance ,fs_line --master data ,r_currency --history cust mix ,r_rate --master data - ,c_currency --master data - ,c_rate --master data + ,r.curr c_currency --master data + ,x.rate c_rate --master data ,-units units ,-value_loc value_loc ,-value_usd value_usd - ,-cost_loc cost_loc - ,-cost_usd cost_usd + ,-units * c.std cost_loc + ,-units * c.std * x.rate cost_usd ,calc_status --0 ,flag --0 ,order_date --history date mix @@ -154,7 +154,17 @@ target AS (SELECT $$swap_doc$$::jsonb swap) INNER JOIN pl ON pl.original = o.part INNER JOIN rlarp.itemmv m ON - m.item = o.part + m.item = pl.replace + LEFT OUTER JOIN rlarp.icstx c ON + c.part = pl.replace + AND c.plnt = m.dplt + LEFT OUTER JOIN rlarp.plpr r ON + yaplnt = m.dplt + LEFT OUTER JOIN rlarp.ffcret x ON + x.fcur = r.curr + AND x.tcur = 'US' + AND x.rtyp = 'BG' + AND x.perd = '2101' LEFT OUTER JOIN seg ON seg.glec = m.glec )