vault backup: 2023-11-15 13:47:00
This commit is contained in:
parent
428d73dbbc
commit
87d2bd39cd
13
api.ts
13
api.ts
@ -34,18 +34,27 @@ const query = await Deno.readTextFile("sql/get.pg.sql");
|
|||||||
const query_dseg = await Deno.readTextFile("sql/get_dseg.pg.sql");
|
const query_dseg = await Deno.readTextFile("sql/get_dseg.pg.sql");
|
||||||
|
|
||||||
// exact scenario for existing codes
|
// exact scenario for existing codes
|
||||||
router.get('/code_price/:billcode/:shipcode/:partcode/:qty', async (ctx) => {
|
router.get('/code/:billcode/:shipcode/:partcode/:qty', async (ctx) => {
|
||||||
const { billcode, shipcode, partcode, qty } = ctx.params;
|
const { billcode, shipcode, partcode, qty } = ctx.params;
|
||||||
const result = await client.queryObject({args: [billcode, shipcode, partcode, qty], text: query} );
|
const result = await client.queryObject({args: [billcode, shipcode, partcode, qty], text: query} );
|
||||||
ctx.response.body = apply_guidance(result.rows[0]["doc"]);
|
ctx.response.body = apply_guidance(result.rows[0]["doc"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// specific customres codes but generic style code and data segment to accomodate custom colors and branding
|
||||||
|
router.get('/dseg/:billcode/:shipcode/:stlc/:dseg/:qty', async (ctx) => {
|
||||||
|
const { billcode, shipcode, stlc, dseg, qty } = ctx.params;
|
||||||
|
const result = await client.queryObject({args: [billcode, shipcode, stlc, dseg, qty], text: query_dseg} );
|
||||||
|
ctx.response.body = apply_guidance(result.rows[0]["doc"]);
|
||||||
|
});
|
||||||
|
|
||||||
// specific customres codes but generic style code and data segment to accomodate custom colors and branding
|
// specific customres codes but generic style code and data segment to accomodate custom colors and branding
|
||||||
router.get('/dseg_price/:billcode/:shipcode/:stlc/:dseg/:qty', async (ctx) => {
|
router.get('/dseg_price/:billcode/:shipcode/:stlc/:dseg/:qty', async (ctx) => {
|
||||||
const { billcode, shipcode, stlc, dseg, qty } = ctx.params;
|
const { billcode, shipcode, stlc, dseg, qty } = ctx.params;
|
||||||
const result = await client.queryObject({args: [billcode, shipcode, stlc, dseg, qty], text: query_dseg} );
|
const result = await client.queryObject({args: [billcode, shipcode, stlc, dseg, qty], text: query_dseg} );
|
||||||
ctx.response.body = apply_guidance(result.rows[0]["doc"]);
|
const ag = apply_guidance(result.rows[0]["doc"]);
|
||||||
|
ctx.response.body = ag.guidance.FinalReason;
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
app.use(router.allowedMethods());
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
|
@ -1,6 +1,21 @@
|
|||||||
export function apply_guidance(doc: any) {
|
export function apply_guidance(doc: any) {
|
||||||
|
|
||||||
|
function getAdjValue(number) {
|
||||||
|
const data = [
|
||||||
|
{f: 2.001, t: 1000, snap: 3, adj: 0 },
|
||||||
|
{f: 1.001, t: 2, snap: 2, adj: 0 },
|
||||||
|
{f: 0.1, t: 1, snap: 1, adj: 0 },
|
||||||
|
{f: 0, t: 0.1, snap: 0, adj: 0 },
|
||||||
|
{f: -1, t: -0.00001, snap: -1, adj: 0.05},
|
||||||
|
{f: -2, t: -0.999999, snap: -2, adj: 0.05},
|
||||||
|
{f: -1000, t: -2.001, snap: -3, adj: 0.10},
|
||||||
|
];
|
||||||
|
const match = data.find(row => number >= row.f && number <= row.t);
|
||||||
|
return match ? match.adj : null;
|
||||||
|
}
|
||||||
|
|
||||||
const targetPrice = doc.pricing?.v1tp ?? doc.pricing?.v0tp;
|
const targetPrice = doc.pricing?.v1tp ?? doc.pricing?.v0tp;
|
||||||
|
const priceBand = doc.pricing?.v1stdv ?? doc.pricing?.v0stdv;
|
||||||
const earlyPrice = doc.hist?.cust?.early_price;
|
const earlyPrice = doc.hist?.cust?.early_price;
|
||||||
const earlySeason = doc.hist?.cust?.early_season;
|
const earlySeason = doc.hist?.cust?.early_season;
|
||||||
const bridgePremium = doc.pricing?.bridgePremium ?? 1.00000;
|
const bridgePremium = doc.pricing?.bridgePremium ?? 1.00000;
|
||||||
@ -25,6 +40,14 @@ export function apply_guidance(doc: any) {
|
|||||||
const inflation = Math.max(...Object.keys(iidx).map(Number));
|
const inflation = Math.max(...Object.keys(iidx).map(Number));
|
||||||
const inflationFactor = iidx[inflation] + 1;
|
const inflationFactor = iidx[inflation] + 1;
|
||||||
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
|
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
|
||||||
|
|
||||||
|
//-------set basic customer pricing--------------
|
||||||
|
custPrice = Number((earlyPrice * bridgePremium).toFixed(5));
|
||||||
|
anchorPrice = custPrice;
|
||||||
|
let anchor_sd = priceBand ? ((anchorPrice - targetPrice) / priceBand).toFixed(2) : 0
|
||||||
|
let optimization = getAdjValue(anchor_sd);
|
||||||
|
|
||||||
|
|
||||||
// ------if there is not target price just exit---------------
|
// ------if there is not target price just exit---------------
|
||||||
if (!targetPrice) {
|
if (!targetPrice) {
|
||||||
anchorSource = "No target pricing setup";
|
anchorSource = "No target pricing setup";
|
||||||
@ -33,14 +56,12 @@ export function apply_guidance(doc: any) {
|
|||||||
// if there is no customer anchor price use target
|
// if there is no customer anchor price use target
|
||||||
if (earlyPrice) {
|
if (earlyPrice) {
|
||||||
// translate alternate product history to current product quoted
|
// translate alternate product history to current product quoted
|
||||||
custPrice = Number((earlyPrice * bridgePremium).toFixed(5));
|
|
||||||
anchorPrice = custPrice;
|
|
||||||
// --------if the price needs bridged, add the details to the description--------
|
// --------if the price needs bridged, add the details to the description--------
|
||||||
if (bridgePremium === 1) {
|
if (bridgePremium === 1) {
|
||||||
anchorSource = earlySeason + ' Customer Price ' + earlyPrice;
|
anchorSource = earlySeason + ' Price ' + earlyPrice;
|
||||||
custSource = anchorSource;
|
custSource = anchorSource;
|
||||||
} else {
|
} else {
|
||||||
anchorSource = earlySeason + ' Similar (' + altHist + ') Customer Price ' + earlyPrice + ' x ' + bridgePremium + ' = ' + anchorPrice;
|
anchorSource = earlySeason + ' Similar (' + altHist + ') Price ' + earlyPrice + ' x ' + bridgePremium + ' = ' + anchorPrice;
|
||||||
custSource = anchorSource;
|
custSource = anchorSource;
|
||||||
}
|
}
|
||||||
// --------after the early price is translated see if target is still less-------
|
// --------after the early price is translated see if target is still less-------
|
||||||
|
@ -64,13 +64,13 @@ BEGIN
|
|||||||
,item
|
,item
|
||||||
,idxk
|
,idxk
|
||||||
,prefer
|
,prefer
|
||||||
,(SELECT unti FROM "CMS.CUSLG".itemm WHERE item = best.item)
|
,pltq
|
||||||
INTO
|
INTO
|
||||||
_mold
|
_mold
|
||||||
,_item
|
,_item
|
||||||
,_iidx
|
,_iidx
|
||||||
,_itemr
|
,_itemr
|
||||||
,_unti
|
,_pltq
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
@ -79,6 +79,7 @@ BEGIN
|
|||||||
,i.stlc
|
,i.stlc
|
||||||
,i.v1ds
|
,i.v1ds
|
||||||
,i.v0ds
|
,i.v0ds
|
||||||
|
,i.pltq
|
||||||
,jsonb_strip_nulls(jsonb_build_object('assc',CASE WHEN i.assc <> '' THEN i.assc ELSE null::text END,'majg',i.majg::int,'coltier',i.coltier)) idxk
|
,jsonb_strip_nulls(jsonb_build_object('assc',CASE WHEN i.assc <> '' THEN i.assc ELSE null::text END,'majg',i.majg::int,'coltier',i.coltier)) idxk
|
||||||
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END prefer
|
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END prefer
|
||||||
FROM
|
FROM
|
||||||
@ -92,6 +93,7 @@ BEGIN
|
|||||||
,i.stlc
|
,i.stlc
|
||||||
,i.v1ds
|
,i.v1ds
|
||||||
,i.v0ds
|
,i.v0ds
|
||||||
|
,i.pltq
|
||||||
,jsonb_strip_nulls(jsonb_build_object('assc',CASE WHEN i.assc <> '' THEN i.assc ELSE null::text END,'majg',i.majg::int,'coltier',i.coltier))
|
,jsonb_strip_nulls(jsonb_build_object('assc',CASE WHEN i.assc <> '' THEN i.assc ELSE null::text END,'majg',i.majg::int,'coltier',i.coltier))
|
||||||
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END
|
,CASE WHEN i.v1ds = _v1ds THEN 2 ELSE CASE WHEN i.v0ds = _v0ds THEN 1 ELSE 0 END END
|
||||||
) best
|
) best
|
||||||
@ -100,35 +102,17 @@ BEGIN
|
|||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
_product :=
|
_product :=
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
|
'product'
|
||||||
|
,jsonb_build_object(
|
||||||
'mold',_mold
|
'mold',_mold
|
||||||
,'item',_item
|
,'item',_item
|
||||||
,'itemrel',_itemr
|
,'itemrel',_itemr
|
||||||
,'iidx',_iidx
|
,'iidx',_iidx
|
||||||
,'unti',_unti
|
,'pltq',_pltq
|
||||||
|
)
|
||||||
);
|
);
|
||||||
--RAISE NOTICE 'item data %', jsonb_pretty(_product||_input);
|
--RAISE NOTICE 'item data %', jsonb_pretty(_product||_input);
|
||||||
|
|
||||||
----------------pallet quantity-----------------------------
|
|
||||||
SELECT
|
|
||||||
ROUND(uom.nm/uom.dm,1) pltq
|
|
||||||
INTO
|
|
||||||
_pltq
|
|
||||||
FROM
|
|
||||||
(
|
|
||||||
SELECT
|
|
||||||
jsonb_agg(row_to_json(d)::jsonb) jdoc
|
|
||||||
FROM
|
|
||||||
(
|
|
||||||
select distinct
|
|
||||||
_item partn
|
|
||||||
,'PLT' fu
|
|
||||||
,_unti tu
|
|
||||||
) d
|
|
||||||
) c
|
|
||||||
JOIN LATERAL rlarp.uom_array(c.jdoc) uom ON TRUE;
|
|
||||||
|
|
||||||
_product := jsonb_build_object('product',_product||jsonb_build_object('pltq',_pltq));
|
|
||||||
|
|
||||||
----------------channel-------------------------------------
|
----------------channel-------------------------------------
|
||||||
|
|
||||||
SELECT rlarp.channel_code(_bill, _ship) INTO _chan;
|
SELECT rlarp.channel_code(_bill, _ship) INTO _chan;
|
||||||
|
Loading…
Reference in New Issue
Block a user