forecast_api/build/rec_act.sql

34 lines
1.2 KiB
SQL

SELECT
oseas
,go.drange
,go.sspr
,sum(fb_val_loc * r_rate)
FROM
rlarp.osm_dev o
--snap the ship dates of the historic fiscal period
--LEFT OUTER JOIN rlarp.gld ON
-- gld.fspr = o.fspr
LEFT OUTER JOIN rlarp.gld go ON
odate between go.sdat and go.edat
--get the shipping season for open orders based on the snapped date
--LEFT OUTER JOIN rlarp.gld ss ON
-- greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
WHERE
(
--base period orders booked....
o.odate BETWEEN '2020-06-01' AND '2021-04-04'
----...or any open orders currently booked before cutoff....
--OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2021-04-04')
----...or anything that shipped in that period
--OR o.fspr BETWEEN '2101' AND '2110'
)
AND fs_line = '41010'
AND calc_status <> 'CANCELED'
--AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
---exclude integrated quotes----
AND version = 'ACTUALS'
GROUP BY
oseas
,go.drange
,go.sspr