The Est Extended Cost is calculated based on the following formula.
Est Extended Cost = [ Location Total Value/ Location on Hand ] * transaction quantity
Location Total Value = Location On Hand * location average cost.
Here the item location inventory quantity on hand is 10 and average cost is 20 and transaction quantity is 10.
Then the location total value = 10 * 20 =200
Est Extended cost = [200/10] * 10 =200.
Here we have used a search to fetch the average cost when the quantity is less than zero.
const itemSearch = (item, location) => {
let avgCost, quanOnHand;
if (checkForParameter(item) && checkForParameter(location)) {
let itemSearchObj = search.create({
type: “item”,
filters: [[“internalid”, “is”, item], “AND”,
[“inventorylocation.internalid”, “anyof”, location]
],
columns:
[
search.createColumn({
name: “internalid”,
join: “inventoryLocation”,
label: “Internal ID”
}),
search.createColumn({
name: “name”,
join: “inventoryLocation”,
label: “Name”
}),
search.createColumn({ name: “locationaveragecost”, label: “Location Average Cost” }), search.createColumn({ name: “locationquantityonhand”, label: “Location On Hand” })
] });
itemSearchObj.run().each(function (result) {
quanOnHand = result.getValue({ name: ‘locationquantityonhand’ });
console.log(“on hand”, quanOnHand)
console.log(“average cost “, result.getValue({ name: ‘locationaveragecost’ }));
if (quanOnHand <= 0) {
avgCost = result.getValue({ name: ‘locationaveragecost’ });
console.log(“avgCost”, avgCost)
}
return true;
});
}
if (quanOnHand <= 0 && avgCost) {
return avgCost;
}
else {
return 0;
}
}