add json sort to api, and don't apply LTP charge for dishes or hangers
This commit is contained in:
parent
a2322876e1
commit
eb0c969ec7
@ -1,5 +1,21 @@
|
|||||||
export function apply_guidance(doc: any) {
|
export function apply_guidance(doc: any) {
|
||||||
|
|
||||||
|
function sortObjectKeys(obj) {
|
||||||
|
// If the object is not an actual object or is an array, return it as is
|
||||||
|
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new object and sort the keys
|
||||||
|
const sortedObj = {};
|
||||||
|
Object.keys(obj).sort().forEach(key => {
|
||||||
|
// Recursively apply the function for nested objects
|
||||||
|
sortedObj[key] = sortObjectKeys(obj[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return sortedObj;
|
||||||
|
}
|
||||||
|
|
||||||
function getAdjValue(number) {
|
function getAdjValue(number) {
|
||||||
const data = [
|
const data = [
|
||||||
{f: 2.001, t: 1000, snap: 3, adj: 0 },
|
{f: 2.001, t: 1000, snap: 3, adj: 0 },
|
||||||
@ -76,9 +92,10 @@ export function apply_guidance(doc: any) {
|
|||||||
const inflationFactor = iidx[inflation];
|
const inflationFactor = iidx[inflation];
|
||||||
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;
|
||||||
const listUSD = list ? list * fxrate :null;
|
const listUSD = list ? list * fxrate :null;
|
||||||
|
const stlc = doc.inputs.stlc;
|
||||||
|
|
||||||
// ------------------calculate price adders------------------------------------------------------
|
// ------------------calculate price adders------------------------------------------------------
|
||||||
let ltp = qty < pltq ? 0.15 : null;
|
let ltp = stlc.includes("SDD") || stlc.includes("HZP") ? 0 : (qty < pltq ? 0.15 : null);
|
||||||
let anchor_sd = priceBand ? ((bridgedPrice - targetPrice) / priceBand).toFixed(2) : 0
|
let anchor_sd = priceBand ? ((bridgedPrice - targetPrice) / priceBand).toFixed(2) : 0
|
||||||
let optimization = getAdjValue(anchor_sd);
|
let optimization = getAdjValue(anchor_sd);
|
||||||
let custAdder = (ltp ?? 0) + optimization + inflationFactor;
|
let custAdder = (ltp ?? 0) + optimization + inflationFactor;
|
||||||
@ -103,7 +120,7 @@ export function apply_guidance(doc: any) {
|
|||||||
let targPrice = targetPrice ? r5(targetPrice * (1 + markAdder)) : null;
|
let targPrice = targetPrice ? r5(targetPrice * (1 + markAdder)) : null;
|
||||||
let targReason = `Target price ${pp(targetPrice)}${markAddReason}`;
|
let targReason = `Target price ${pp(targetPrice)}${markAddReason}`;
|
||||||
let listPrice = listUSD;
|
let listPrice = listUSD;
|
||||||
let listReason = fxrate === 1 ? "" : `list ${pp(list)} CAD ${pp(listUSD)} USD`
|
let listReason = fxrate === 1 ? `list ${pp(list)}` : `list ${pp(list)} CAD ${pp(listUSD)} USD`;
|
||||||
|
|
||||||
let prices = {
|
let prices = {
|
||||||
cust: [custPrice, custReason, "cust", ceiling(custPrice,snap)],
|
cust: [custPrice, custReason, "cust", ceiling(custPrice,snap)],
|
||||||
@ -123,5 +140,6 @@ export function apply_guidance(doc: any) {
|
|||||||
,optimization
|
,optimization
|
||||||
}
|
}
|
||||||
doc.guidance = guidance;
|
doc.guidance = guidance;
|
||||||
return doc;
|
//return doc;
|
||||||
|
return sortObjectKeys(doc);
|
||||||
}
|
}
|
||||||
|
@ -79,9 +79,10 @@ AS $function$
|
|||||||
const inflationFactor = iidx ? iidx[inflation] : 0;
|
const inflationFactor = iidx ? iidx[inflation] : 0;
|
||||||
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;
|
||||||
const listUSD = list ? list * fxrate :null;
|
const listUSD = list ? list * fxrate :null;
|
||||||
|
const stlc = doc.inputs.stlc;
|
||||||
|
|
||||||
// ------------------calculate price adders------------------------------------------------------
|
// ------------------calculate price adders------------------------------------------------------
|
||||||
let ltp = qty < pltq ? 0.15 : null;
|
let ltp = stlc.includes("SDD") || stlc.includes("HZP") ? 0 : (qty < pltq ? 0.15 : null);
|
||||||
let anchor_sd = priceBand ? ((bridgedPrice - targetPrice) / priceBand).toFixed(2) : 0
|
let anchor_sd = priceBand ? ((bridgedPrice - targetPrice) / priceBand).toFixed(2) : 0
|
||||||
let optimization = getAdjValue(anchor_sd);
|
let optimization = getAdjValue(anchor_sd);
|
||||||
let custAdder = (ltp ?? 0) + optimization + inflationFactor;
|
let custAdder = (ltp ?? 0) + optimization + inflationFactor;
|
||||||
@ -106,7 +107,7 @@ AS $function$
|
|||||||
let targPrice = targetPrice ? r5(targetPrice * (1 + markAdder)) : null;
|
let targPrice = targetPrice ? r5(targetPrice * (1 + markAdder)) : null;
|
||||||
let targReason = `Target price ${pp(targetPrice)}${markAddReason}`;
|
let targReason = `Target price ${pp(targetPrice)}${markAddReason}`;
|
||||||
let listPrice = listUSD;
|
let listPrice = listUSD;
|
||||||
let listReason = fxrate === 1 ? "" : `list ${pp(list)} CAD ${pp(listUSD)} USD`
|
let listReason = fxrate === 1 ? `list ${pp(list)}` : `list ${pp(list)} CAD ${pp(listUSD)} USD`;
|
||||||
|
|
||||||
let prices = {
|
let prices = {
|
||||||
cust: [custPrice, custReason, "cust", ceiling(custPrice,snap)],
|
cust: [custPrice, custReason, "cust", ceiling(custPrice,snap)],
|
||||||
|
Loading…
Reference in New Issue
Block a user