Compare commits
No commits in common. "29e7be99f32e669ac725dbca782cc89c9bf763a3" and "5074f5b8e514895eed1f523679b6a48229e3daae" have entirely different histories.
29e7be99f3
...
5074f5b8e5
7
api.ts
7
api.ts
@ -31,10 +31,6 @@ await client.connect();
|
|||||||
// Load SQL from file
|
// Load SQL from file
|
||||||
const query = await Deno.readTextFile("sql/get.pg.sql");
|
const query = await Deno.readTextFile("sql/get.pg.sql");
|
||||||
|
|
||||||
function apply_guidance(doc: any) {
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define a route to retrieve values from the database using parameters
|
// Define a route to retrieve values from the database using parameters
|
||||||
router.get('/code_price/:billcode/:shipcode/:partcode/:qty', async (ctx) => {
|
router.get('/code_price/:billcode/:shipcode/:partcode/:qty', async (ctx) => {
|
||||||
|
|
||||||
@ -46,8 +42,7 @@ router.get('/code_price/:billcode/:shipcode/:partcode/:qty', async (ctx) => {
|
|||||||
//console.log(partcode)
|
//console.log(partcode)
|
||||||
//console.log(customer)
|
//console.log(customer)
|
||||||
const result = await client.queryObject({args: [billcode, shipcode, partcode, qty], text: query} );
|
const result = await client.queryObject({args: [billcode, shipcode, partcode, qty], text: query} );
|
||||||
const procd = apply_guidance(result.rows[0]["doc"])
|
ctx.response.body = result.rows;
|
||||||
ctx.response.body = procd
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
|
@ -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,7 +13,6 @@ 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;
|
||||||
@ -29,35 +28,29 @@ BEGIN
|
|||||||
|
|
||||||
|
|
||||||
----------------base product--------------------------------
|
----------------base product--------------------------------
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
m.part_group, i.v1ds,i.v0ds
|
m.part_group, i.v1ds
|
||||||
INTO
|
INTO
|
||||||
_mold,_v1ds ,_v0ds
|
_mold,_v1ds
|
||||||
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;
|
||||||
_rslt := _rslt||jsonb_build_object('chan',_chan);
|
RAISE NOTICE '%', _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 ;
|
||||||
_rslt = _rslt||jsonb_build_object('cust',_cust);
|
RAISE NOTICE 'cust %', _cust;
|
||||||
--RAISE NOTICE 'cust %', _cust;
|
|
||||||
|
|
||||||
----------------price history-------------------------------
|
----------------price history-------------------------------
|
||||||
SELECT _rslt||jsonb_build_object('hist',rlarp.gethist(_mold, _cust)) INTO _rslt ;
|
SELECT jsonb_build_object('hist',rlarp.gethist(_mold, _cust)) INTO _rslt ;
|
||||||
--RAISE NOTICE '%', _rslt;
|
--RAISE NOTICE '%', _rslt;
|
||||||
|
|
||||||
----------------target pricing------------------------------
|
----------------target pricing------------------------------
|
||||||
@ -77,13 +70,11 @@ 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 coalesce(rlarp.get_list(_bill, _ship, _item, _qty),'{}'::jsonb) INTO _list;
|
SELECT rlarp.get_list(_bill, _ship, _item, _qty) INTO _list;
|
||||||
_rslt := _rslt||COALESCE(_list,'{}'::jsonb);
|
RAISE NOTICE 'list: %', jsonb_pretty(_list);
|
||||||
--RAISE NOTICE 'list: %', jsonb_pretty(_list);
|
|
||||||
|
|
||||||
RETURN _rslt;
|
RETURN _rslt;
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
CREATE OR REPLACE FUNCTION rlarp.apply_guid(data jsonb)
|
CREATE OR REPLACE FUNCTION rlarp.guidancejsd(_p jsonb, cust text, prod text)
|
||||||
RETURNS jsonb
|
RETURNS jsonb
|
||||||
LANGUAGE plv8
|
LANGUAGE plv8
|
||||||
AS $function$
|
AS $function$
|
||||||
|
|
||||||
|
|
||||||
function findMostRecentPrice(data) {
|
function findMostRecentPrice(data, cust, prod) {
|
||||||
let mostRecentPrice = null;
|
let mostRecentPrice = null;
|
||||||
let mostRecentYear = null;
|
let mostRecentYear = null;
|
||||||
|
|
||||||
// Iterate through each product
|
// Iterate through each product
|
||||||
data.forEach( data.hist => {
|
data.forEach(product => {
|
||||||
// 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) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Example usage:
|
// Example usage:
|
||||||
const jsonData = data;
|
const jsonData = _p;
|
||||||
|
|
||||||
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