add json sort to api, and don't apply LTP charge for dishes or hangers

This commit is contained in:
Paul Trowbridge 2023-12-01 13:53:23 -05:00
parent a2322876e1
commit eb0c969ec7
2 changed files with 24 additions and 5 deletions

View File

@ -1,5 +1,21 @@
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) {
const data = [
{f: 2.001, t: 1000, snap: 3, adj: 0 },
@ -76,9 +92,10 @@ export function apply_guidance(doc: any) {
const inflationFactor = iidx[inflation];
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
const listUSD = list ? list * fxrate :null;
const stlc = doc.inputs.stlc;
// ------------------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 optimization = getAdjValue(anchor_sd);
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 targReason = `Target price ${pp(targetPrice)}${markAddReason}`;
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 = {
cust: [custPrice, custReason, "cust", ceiling(custPrice,snap)],
@ -123,5 +140,6 @@ export function apply_guidance(doc: any) {
,optimization
}
doc.guidance = guidance;
return doc;
//return doc;
return sortObjectKeys(doc);
}

View File

@ -79,9 +79,10 @@ AS $function$
const inflationFactor = iidx ? iidx[inflation] : 0;
const list = doc.pricing?.list && doc.product?.itemrel === "2" ? doc.pricing?.list : null;
const listUSD = list ? list * fxrate :null;
const stlc = doc.inputs.stlc;
// ------------------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 optimization = getAdjValue(anchor_sd);
let custAdder = (ltp ?? 0) + optimization + inflationFactor;
@ -106,7 +107,7 @@ AS $function$
let targPrice = targetPrice ? r5(targetPrice * (1 + markAdder)) : null;
let targReason = `Target price ${pp(targetPrice)}${markAddReason}`;
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 = {
cust: [custPrice, custReason, "cust", ceiling(custPrice,snap)],