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
|
||||
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
|
||||
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(customer)
|
||||
const result = await client.queryObject({args: [billcode, shipcode, partcode, qty], text: query} );
|
||||
const procd = apply_guidance(result.rows[0]["doc"])
|
||||
ctx.response.body = procd
|
||||
ctx.response.body = result.rows;
|
||||
});
|
||||
|
||||
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 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;
|
||||
_cust text;
|
||||
_v1ds text;
|
||||
_v0ds text;
|
||||
_chan text;
|
||||
_regn text;
|
||||
_rslt jsonb;
|
||||
@ -29,35 +28,29 @@ BEGIN
|
||||
|
||||
|
||||
----------------base product--------------------------------
|
||||
|
||||
SELECT
|
||||
m.part_group, i.v1ds,i.v0ds
|
||||
m.part_group, i.v1ds
|
||||
INTO
|
||||
_mold,_v1ds ,_v0ds
|
||||
_mold,_v1ds
|
||||
FROM
|
||||
"CMS.CUSLG".itemmv i
|
||||
INNER JOIN rlarp.molds m ON
|
||||
m.stlc = i.stlc
|
||||
WHERE
|
||||
i.item = _item;
|
||||
--RAISE NOTICE 'mold %', _mold;
|
||||
--RAISE NOTICE 'v1ds %', _v1ds;
|
||||
_rslt := jsonb_build_object('mold',_mold,'v1ds',_v1ds,'v0ds',_v0ds);
|
||||
RAISE NOTICE 'mold %', _mold;
|
||||
RAISE NOTICE 'v1ds %', _v1ds;
|
||||
|
||||
----------------channel-------------------------------------
|
||||
|
||||
SELECT rlarp.channel_code(_bill, _ship) INTO _chan;
|
||||
_rslt := _rslt||jsonb_build_object('chan',_chan);
|
||||
--RAISE NOTICE '%', _chan;
|
||||
RAISE NOTICE '%', _chan;
|
||||
|
||||
----------------customer------------------------------------
|
||||
|
||||
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-------------------------------
|
||||
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;
|
||||
|
||||
----------------target pricing------------------------------
|
||||
@ -77,13 +70,11 @@ BEGIN
|
||||
AND season = _seas
|
||||
AND data_segment = _v1ds
|
||||
AND region = 'ALL';
|
||||
--RAISE NOTICE 'target: %', jsonb_pretty(_targ);
|
||||
_rslt := _rslt||COALESCE(_targ,'{}'::jsonb);
|
||||
RAISE NOTICE 'target: %', jsonb_pretty(_targ);
|
||||
|
||||
----------------list ppricing-------------------------------
|
||||
SELECT coalesce(rlarp.get_list(_bill, _ship, _item, _qty),'{}'::jsonb) INTO _list;
|
||||
_rslt := _rslt||COALESCE(_list,'{}'::jsonb);
|
||||
--RAISE NOTICE 'list: %', jsonb_pretty(_list);
|
||||
SELECT rlarp.get_list(_bill, _ship, _item, _qty) INTO _list;
|
||||
RAISE NOTICE 'list: %', jsonb_pretty(_list);
|
||||
|
||||
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
|
||||
LANGUAGE plv8
|
||||
AS $function$
|
||||
|
||||
|
||||
function findMostRecentPrice(data) {
|
||||
function findMostRecentPrice(data, cust, prod) {
|
||||
let mostRecentPrice = null;
|
||||
let mostRecentYear = null;
|
||||
|
||||
// Iterate through each product
|
||||
data.forEach( data.hist => {
|
||||
data.forEach(product => {
|
||||
// Check if the product matches the customer channel and version
|
||||
if (product.chan === cust && (product.v1ds === prod || product.v0ds === prod)) {
|
||||
// Iterate through the seasons for the product
|
||||
@ -30,7 +30,7 @@ function findMostRecentPrice(data) {
|
||||
}
|
||||
|
||||
// Example usage:
|
||||
const jsonData = data;
|
||||
const jsonData = _p;
|
||||
|
||||
const cust = 'W'; // or 'D', depending on the customer
|
||||
const prod = 'TUH10000'; // the product version you're interested in
|
||||
|
Loading…
Reference in New Issue
Block a user