commit: 2025-04-05 21:06:09

This commit is contained in:
Paul Trowbridge 2025-04-05 21:06:09 -04:00
parent 2ffb052722
commit fb749ffde5

View File

@ -184,6 +184,66 @@ GROUP BY
bill_cust_descr bill_cust_descr
,ship_cust_descr ,ship_cust_descr
) )
,alldates AS (
SELECT
bill_cust_descr
,ship_cust_descr
,promo
,terms
,r_currency
-- ,order_month
-- ,mseq.s seq
,order_date
-- ,request_date
,ship_date
-- ,ship_month
-- ,sum(value_usd) value_usd_net
,sum(pounds) pounds_net
-- ,sum(value_usd) FILTER (WHERE iter IN ('copy','actuals','actuals_plug')) value_usd_baseline
,sum(pounds) FILTER (WHERE iter IN ('copy','actuals','actuals_plug')) pounds_baseline
FROM
rlarp.osm_pool
LEFT OUTER JOIN mseq ON
mseq.m = order_month
WHERE
where_clause
-----------------scenario----------------------------
AND version = 'b26'
-----------------additional params-------------------
AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments
AND order_date <= ship_date
GROUP BY
bill_cust_descr
,ship_cust_descr
,promo
,terms
,r_currency
-- ,order_month
-- ,mseq.s seq
,order_date
-- ,request_date
,ship_date
-- ,ship_month
-- HAVING
-- sum(value_usd) <> 0
)
,date_mix as (
SELECT
bill_cust_descr
,ship_cust_descr
,promo
,terms
,r_currency
,order_date
,ship_date
,round(pounds_net / sum(pounds_net) OVER (),5) fc_mix
,round(pounds_baseline / sum(pounds_baseline) OVER (),5) baseline_mix
FROM
alldates
ORDER BY
order_date ASC
,ship_date ASC
)
-- select 'custs', * from custs -- select 'custs', * from custs
-- --
SELECT SELECT
@ -200,4 +260,6 @@ SELECT
,(SELECT jsonb_agg(tag) FROM tags) ,(SELECT jsonb_agg(tag) FROM tags)
,'customers' ,'customers'
,(SELECT jsonb_agg(row_to_json(custs)::jsonb) FROM custs) ,(SELECT jsonb_agg(row_to_json(custs)::jsonb) FROM custs)
,'date_mix'
,(SELECT jsonb_agg(row_to_json(date_mix)::jsonb) FROM date_mix)
) package ) package