updates
This commit is contained in:
parent
5074f5b8e5
commit
4dc52b8826
@ -1,2 +1,2 @@
|
|||||||
--select gg.d from rlarp.get_guidance('DIAM0004','DIAM0004','AMK06000G18B054',5000,2024) gg(d);
|
--select gg.d from rlarp.get_guidance('DIAM0004','DIAM0004','AMK06000G18B054',5000,2024) gg(d);
|
||||||
select gg.d doc from rlarp.get_guidance($1,$2, $3, $4,2024) gg(d);
|
SELECT gg.d doc FROM rlarp.get_guidance($1,$2, $3, $4,2024) gg(d);
|
||||||
|
@ -13,6 +13,7 @@ DECLARE
|
|||||||
_mold text;
|
_mold text;
|
||||||
_cust text;
|
_cust text;
|
||||||
_v1ds text;
|
_v1ds text;
|
||||||
|
_v0ds text;
|
||||||
_chan text;
|
_chan text;
|
||||||
_regn text;
|
_regn text;
|
||||||
_rslt jsonb;
|
_rslt jsonb;
|
||||||
@ -28,29 +29,35 @@ BEGIN
|
|||||||
|
|
||||||
|
|
||||||
----------------base product--------------------------------
|
----------------base product--------------------------------
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
m.part_group, i.v1ds
|
m.part_group, i.v1ds,i.v0ds
|
||||||
INTO
|
INTO
|
||||||
_mold,_v1ds
|
_mold,_v1ds ,_v0ds
|
||||||
FROM
|
FROM
|
||||||
"CMS.CUSLG".itemmv i
|
"CMS.CUSLG".itemmv i
|
||||||
INNER JOIN rlarp.molds m ON
|
INNER JOIN rlarp.molds m ON
|
||||||
m.stlc = i.stlc
|
m.stlc = i.stlc
|
||||||
WHERE
|
WHERE
|
||||||
i.item = _item;
|
i.item = _item;
|
||||||
RAISE NOTICE 'mold %', _mold;
|
--RAISE NOTICE 'mold %', _mold;
|
||||||
RAISE NOTICE 'v1ds %', _v1ds;
|
--RAISE NOTICE 'v1ds %', _v1ds;
|
||||||
|
_rslt := jsonb_build_object('mold',_mold,'v1ds',_v1ds,'v0ds',_v0ds);
|
||||||
|
|
||||||
----------------channel-------------------------------------
|
----------------channel-------------------------------------
|
||||||
|
|
||||||
SELECT rlarp.channel_code(_bill, _ship) INTO _chan;
|
SELECT rlarp.channel_code(_bill, _ship) INTO _chan;
|
||||||
RAISE NOTICE '%', _chan;
|
_rslt := _rslt||jsonb_build_object('chan',_chan);
|
||||||
|
--RAISE NOTICE '%', _chan;
|
||||||
|
|
||||||
----------------customer------------------------------------
|
----------------customer------------------------------------
|
||||||
|
|
||||||
SELECT dba INTO _cust FROM rlarp.cust WHERE code = CASE WHEN _chan = 'DRP' THEN _ship ELSE _bill END ;
|
SELECT dba INTO _cust FROM rlarp.cust WHERE code = CASE WHEN _chan = 'DRP' THEN _ship ELSE _bill END ;
|
||||||
RAISE NOTICE 'cust %', _cust;
|
_rslt = _rslt||jsonb_build_object('cust',_cust);
|
||||||
|
--RAISE NOTICE 'cust %', _cust;
|
||||||
|
|
||||||
----------------price history-------------------------------
|
----------------price history-------------------------------
|
||||||
SELECT jsonb_build_object('hist',rlarp.gethist(_mold, _cust)) INTO _rslt ;
|
SELECT _rslt||jsonb_build_object('hist',rlarp.gethist(_mold, _cust)) INTO _rslt ;
|
||||||
--RAISE NOTICE '%', _rslt;
|
--RAISE NOTICE '%', _rslt;
|
||||||
|
|
||||||
----------------target pricing------------------------------
|
----------------target pricing------------------------------
|
||||||
@ -70,11 +77,13 @@ BEGIN
|
|||||||
AND season = _seas
|
AND season = _seas
|
||||||
AND data_segment = _v1ds
|
AND data_segment = _v1ds
|
||||||
AND region = 'ALL';
|
AND region = 'ALL';
|
||||||
RAISE NOTICE 'target: %', jsonb_pretty(_targ);
|
--RAISE NOTICE 'target: %', jsonb_pretty(_targ);
|
||||||
|
_rslt := _rslt||COALESCE(_targ,'{}'::jsonb);
|
||||||
|
|
||||||
----------------list ppricing-------------------------------
|
----------------list ppricing-------------------------------
|
||||||
SELECT rlarp.get_list(_bill, _ship, _item, _qty) INTO _list;
|
SELECT coalesce(rlarp.get_list(_bill, _ship, _item, _qty),'{}'::jsonb) INTO _list;
|
||||||
RAISE NOTICE 'list: %', jsonb_pretty(_list);
|
_rslt := _rslt||COALESCE(_list,'{}'::jsonb);
|
||||||
|
--RAISE NOTICE 'list: %', jsonb_pretty(_list);
|
||||||
|
|
||||||
RETURN _rslt;
|
RETURN _rslt;
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
CREATE OR REPLACE FUNCTION rlarp.guidancejsd(_p jsonb, cust text, prod text)
|
CREATE OR REPLACE FUNCTION rlarp.apply_guid(data jsonb)
|
||||||
RETURNS jsonb
|
RETURNS jsonb
|
||||||
LANGUAGE plv8
|
LANGUAGE plv8
|
||||||
AS $function$
|
AS $function$
|
||||||
|
|
||||||
|
|
||||||
function findMostRecentPrice(data, cust, prod) {
|
function findMostRecentPrice(data) {
|
||||||
let mostRecentPrice = null;
|
let mostRecentPrice = null;
|
||||||
let mostRecentYear = null;
|
let mostRecentYear = null;
|
||||||
|
|
||||||
// Iterate through each product
|
// Iterate through each product
|
||||||
data.forEach(product => {
|
data.forEach( data.hist => {
|
||||||
// Check if the product matches the customer channel and version
|
// Check if the product matches the customer channel and version
|
||||||
if (product.chan === cust && (product.v1ds === prod || product.v0ds === prod)) {
|
if (product.chan === cust && (product.v1ds === prod || product.v0ds === prod)) {
|
||||||
// Iterate through the seasons for the product
|
// Iterate through the seasons for the product
|
||||||
@ -30,7 +30,7 @@ function findMostRecentPrice(data, cust, prod) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Example usage:
|
// Example usage:
|
||||||
const jsonData = _p;
|
const jsonData = data;
|
||||||
|
|
||||||
const cust = 'W'; // or 'D', depending on the customer
|
const cust = 'W'; // or 'D', depending on the customer
|
||||||
const prod = 'TUH10000'; // the product version you're interested in
|
const prod = 'TUH10000'; // the product version you're interested in
|
||||||
|
Loading…
Reference in New Issue
Block a user