Merge branch 'terms' of hc-companies/forecast_api into dev

This commit is contained in:
pt 2020-02-27 17:24:13 +00:00 committed by Gitea
commit d5f3c74c6f

View File

@ -106,6 +106,7 @@ target AS (select $$replace_request$$::json def)
SELECT SELECT
promo promo
,terms ,terms
,r_currency
,order_month ,order_month
,mseq.s seq ,mseq.s seq
,order_date ,order_date
@ -126,6 +127,7 @@ target AS (select $$replace_request$$::json def)
GROUP BY GROUP BY
promo promo
,terms ,terms
,r_currency
,order_month ,order_month
,mseq.s ,mseq.s
,order_date ,order_date
@ -151,6 +153,9 @@ target AS (select $$replace_request$$::json def)
to_char(order_date,'Mon') _month to_char(order_date,'Mon') _month
,seq ,seq
,promo ,promo
,terms
,(SELECT r_currency FROM alldates GROUP BY r_currency ORDER BY SUM(value_usd) DESC LIMIT 1) r_currency
--should terms be included here?
,sum(extract(day from order_date)*value_usd) dom_wa ,sum(extract(day from order_date)*value_usd) dom_wa
--,request_date-order_date rlag --,request_date-order_date rlag
,sum((request_date-order_date)*(value_usd)) rlag_wa ,sum((request_date-order_date)*(value_usd)) rlag_wa
@ -163,6 +168,7 @@ target AS (select $$replace_request$$::json def)
to_char(order_date,'Mon') to_char(order_date,'Mon')
,seq ,seq
,promo ,promo
,terms
--,extract(day from order_date) --,extract(day from order_date)
--,request_date-order_date --,request_date-order_date
--,ship_date - request_date --,ship_date - request_date
@ -189,6 +195,8 @@ target AS (select $$replace_request$$::json def)
_month _month
,seq ,seq
,promo ,promo
,terms
,r_currency
,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom ,greatest(least(round((dom_wa/value_usd)::numeric,0)::int,28),1) odom
,round((rlag_wa/value_usd)::numeric,0)::int rlag ,round((rlag_wa/value_usd)::numeric,0)::int rlag
,round((slag_wa/value_usd)::numeric,0)::int slag ,round((slag_wa/value_usd)::numeric,0)::int slag
@ -212,6 +220,8 @@ SELECT
,x.rlag ,x.rlag
,x.slag ,x.slag
,x.promo ,x.promo
,x.terms
,x.r_currency
FROM FROM
targm t targm t
LEFT OUTER JOIN mmixp x ON LEFT OUTER JOIN mmixp x ON
@ -231,6 +241,8 @@ FROM
SELECT SELECT
sd.fspr sd.fspr
,mxm.promo ,mxm.promo
,mxm.terms
,mxm.r_currency
,jr.bill_cust_descr ,jr.bill_cust_descr
,jr.ship_cust_descr ,jr.ship_cust_descr
,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part ,(regexp_match(jr.part_descr,'(.*?)(?= - |$)'))[1] part
@ -269,7 +281,7 @@ SELECT
b.fspr b.fspr
,i.dplt plnt ,i.dplt plnt
,b.promo ,b.promo
,bc.bvterm terms ,COALESCE(b.terms,bc.bvterm) terms
,b.bill_cust_descr ,b.bill_cust_descr
,b.ship_cust_descr ,b.ship_cust_descr
,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm ,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm
@ -312,7 +324,7 @@ SELECT
,seg.segm ,seg.segm
,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance ,CASE WHEN i.majg = '610' THEN 'Fiber' ELSE 'Plastic' END substance
,'41010' fs_line --master data ,'41010' fs_line --master data
,bc.bvcurr r_currency --history cust mix ,b.r_currency --history cust mix
,rx.rate r_rate --master data ,rx.rate r_rate --master data
,copr.curr c_currency --master data ,copr.curr c_currency --master data
,cx.rate c_rate --master data ,cx.rate c_rate --master data
@ -410,14 +422,14 @@ FROM
LEFT OUTER JOIN copr ON LEFT OUTER JOIN copr ON
copr.comp = yacomp::text copr.comp = yacomp::text
LEFT OUTER JOIN rlarp.ffcret cx ON LEFT OUTER JOIN rlarp.ffcret cx ON
cx.perd = '2008' cx.perd = '2101'
AND cx.rtyp = 'MA' AND cx.rtyp = 'BG'
AND cx.fcur = copr.curr AND cx.fcur = copr.curr
AND cx.tcur = 'US' AND cx.tcur = 'US'
LEFT OUTER JOIN rlarp.ffcret rx ON LEFT OUTER JOIN rlarp.ffcret rx ON
rx.perd = '2008' rx.perd = '2101'
AND rx.rtyp = 'MA' AND rx.rtyp = 'BG'
AND rx.fcur = bc.bvcurr AND rx.fcur = COALESCE(bc.bvcurr,b.r_currency)
AND rx.tcur = 'US' AND rx.tcur = 'US'
) )
, ins AS ( , ins AS (