Compare commits

..

No commits in common. "6bee5571dc023d06835b22becd20a24cec84a9f8" and "ffee472954358e2f91ffd9c947f1ae9d05e5ab0c" have entirely different histories.

2 changed files with 17 additions and 30 deletions

View File

@ -145,11 +145,11 @@ gld AS (
WHERE WHERE
( (
--base period orders booked.... --base period orders booked....
o.odate BETWEEN '2019-06-01' AND '2020-02-29' o.odate BETWEEN '2019-06-01' AND '2020-01-31'
--...or any open orders currently booked before cutoff.... --...or any open orders currently booked before cutoff....
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-03-01') OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-02-01')
--...or anything that shipped in that period --...or anything that shipped in that period
OR o.fspr BETWEEN '2001' AND '2009' OR o.fspr BETWEEN '2001' AND '2008'
) )
AND fs_line = '41010' AND fs_line = '41010'
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
@ -289,7 +289,7 @@ gld AS (
LEFT OUTER JOIN gld ss ON LEFT OUTER JOIN gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
WHERE WHERE
o.odate BETWEEN '2019-03-01' AND '2019-05-31' o.odate BETWEEN '2019-02-01' AND '2019-05-31'
AND fs_line = '41010' AND fs_line = '41010'
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
------exclude actuals for now and use forecast to get the plug for the rest of the year ------exclude actuals for now and use forecast to get the plug for the rest of the year
@ -429,7 +429,7 @@ gld AS (
LEFT OUTER JOIN gld ss ON LEFT OUTER JOIN gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
WHERE WHERE
o.odate BETWEEN '2020-03-01' AND '2020-05-31' o.odate BETWEEN '2020-02-01' AND '2020-05-31'
AND fs_line = '41010' AND fs_line = '41010'
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
GROUP BY GROUP BY

View File

@ -72,7 +72,6 @@ target AS (select $$replace_request$$::json def)
,REPC AS ( ,REPC AS (
SELECT SELECT
LTRIM(RTRIM(C.A9)) RCODE LTRIM(RTRIM(C.A9)) RCODE
,c.a30 rname
,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP
,COALESCE(Q.DIR,'Other') DIRECTOR ,COALESCE(Q.DIR,'Other') DIRECTOR
FROM FROM
@ -106,7 +105,6 @@ 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
@ -127,7 +125,6 @@ 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
@ -153,9 +150,6 @@ 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
@ -168,7 +162,6 @@ 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
@ -195,8 +188,6 @@ 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
@ -220,8 +211,6 @@ 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
@ -241,8 +230,6 @@ 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
@ -281,14 +268,14 @@ SELECT
b.fspr b.fspr
,i.dplt plnt ,i.dplt plnt
,b.promo ,b.promo
,COALESCE(b.terms,bc.bvterm) 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 rcode FROM repc WHERE repp = log.doc->'scenario'->>'quota_rep_descr') dsm
,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr ,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr
,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director ,(SELECT director FROM repc WHERE repp = log.doc->'scenario'->>'quota_rep_descr') director
,COALESCE(CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END,b.bill_cust_descr) billto_group ,CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END billto_group
,COALESCE(CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE bc.BVADR6 END,b.ship_cust_descr) shipto_group ,CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE bc.BVADR6 END shipto_group
,CASE SUBSTRING(bc.bvclas,2,3) ,CASE SUBSTRING(bc.bvclas,2,3)
--if the bill to class is ditsributor, then it's either warehouse or drop --if the bill to class is ditsributor, then it's either warehouse or drop
WHEN 'DIS' THEN WHEN 'DIS' THEN
@ -324,12 +311,12 @@ 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
,b.r_currency --history cust mix ,bc.bvcurr 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
,b.units ,b.units
,b.value_usd / COALESCE(rx.rate,1) --b.value is denominated in USD, need to apply currency to get to local, assume 1 if using a fake customer ,b.value_usd / rx.rate --b.value is denominated in USD, need to apply currency to get to local
,b.value_usd value_usd --b.value is already denominated in usd ,b.value_usd value_usd --b.value is already denominated in usd
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units cost_loc ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units cost_loc
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_usd ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_usd
@ -422,14 +409,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 = '2101' cx.perd = '2008'
AND cx.rtyp = 'BG' AND cx.rtyp = 'MA'
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 = '2101' rx.perd = '2008'
AND rx.rtyp = 'BG' AND rx.rtyp = 'MA'
AND rx.fcur = COALESCE(bc.bvcurr,b.r_currency) AND rx.fcur = bc.bvcurr
AND rx.tcur = 'US' AND rx.tcur = 'US'
) )
, ins AS ( , ins AS (