IO-3605 Material Threshold Calculations
Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
@@ -315,7 +315,12 @@ function CalculateRatesTotals(ratesList) {
|
||||
if (item.mod_lbr_ty) {
|
||||
//Check to see if it has 0 hours and a price instead.
|
||||
//Extend for when there are hours and a price.
|
||||
if (item.lbr_op === "OP14" && item.act_price > 0 && (!item.part_type || item.mod_lb_hrs === 0) && !IsAdditionalCost(item)) {
|
||||
if (
|
||||
item.lbr_op === "OP14" &&
|
||||
item.act_price > 0 &&
|
||||
(!item.part_type || item.mod_lb_hrs === 0) &&
|
||||
!IsAdditionalCost(item)
|
||||
) {
|
||||
//Scenario where SGI may pay out hours using a part price.
|
||||
if (!ret[item.mod_lbr_ty.toLowerCase()].total) {
|
||||
ret[item.mod_lbr_ty.toLowerCase()].total = Dinero();
|
||||
@@ -339,38 +344,30 @@ function CalculateRatesTotals(ratesList) {
|
||||
let subtotal = Dinero({ amount: 0 });
|
||||
let rates_subtotal = Dinero({ amount: 0 });
|
||||
|
||||
for (const property in ret) {
|
||||
for (const [property, values] of Object.entries(ret)) {
|
||||
//Skip calculating mapa and mash if we got the amounts.
|
||||
if (!((property === "mapa" && hasMapaLine) || (property === "mash" && hasMashLine))) {
|
||||
if (!ret[property].total) {
|
||||
ret[property].total = Dinero();
|
||||
}
|
||||
let threshold;
|
||||
//Check if there is a max for this type.
|
||||
if (ratesList.materials && ratesList.materials[property]) {
|
||||
//
|
||||
if (ratesList.materials[property].cal_maxdlr && ratesList.materials[property].cal_maxdlr > 0) {
|
||||
//It has an upper threshhold.
|
||||
threshold = Dinero({
|
||||
amount: Math.round(ratesList.materials[property].cal_maxdlr * 100)
|
||||
});
|
||||
}
|
||||
}
|
||||
const shouldSkipCalculation = (property === "mapa" && hasMapaLine) || (property === "mash" && hasMashLine);
|
||||
|
||||
if (!shouldSkipCalculation) {
|
||||
values.total ??= Dinero();
|
||||
|
||||
//Check if there is a max for this type and apply it.
|
||||
const maxDollar =
|
||||
ratesList.materials?.[property]?.cal_maxdlr || ratesList.materials?.[property.toUpperCase()]?.cal_maxdlr;
|
||||
const threshold = maxDollar > 0 ? Dinero({ amount: Math.round(maxDollar * 100) }) : null;
|
||||
|
||||
const total = Dinero({
|
||||
amount: Math.round((ret[property].rate || 0) * 100)
|
||||
}).multiply(ret[property].hours);
|
||||
amount: Math.round((values.rate || 0) * 100)
|
||||
}).multiply(values.hours);
|
||||
|
||||
if (threshold && total.greaterThanOrEqual(threshold)) {
|
||||
ret[property].total = ret[property].total.add(threshold);
|
||||
} else {
|
||||
ret[property].total = ret[property].total.add(total);
|
||||
}
|
||||
values.total = values.total.add(threshold && total.greaterThanOrEqual(threshold) ? threshold : total);
|
||||
}
|
||||
|
||||
subtotal = subtotal.add(ret[property].total);
|
||||
subtotal = subtotal.add(values.total);
|
||||
|
||||
if (property !== "mapa" && property !== "mash") rates_subtotal = rates_subtotal.add(ret[property].total);
|
||||
if (property !== "mapa" && property !== "mash") {
|
||||
rates_subtotal = rates_subtotal.add(values.total);
|
||||
}
|
||||
}
|
||||
|
||||
ret.subtotal = subtotal;
|
||||
|
||||
Reference in New Issue
Block a user