Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #36 from fielded/feat/product-supply-plan
Browse files Browse the repository at this point in the history
Allow per-product supply plan
  • Loading branch information
karlwestin authored Jan 28, 2019
2 parents 5c69f80 + 14b02dc commit 3cdcd24
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
20 changes: 14 additions & 6 deletions dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
if (!(plans && plans.weeksOfStock)) {
throw new Error('cannot find version of weeksOfStock for location ' + location._id + ' and date ' + date);
}
return plans.weeksOfStock;

return plans;
};

var getTargetPopulations = function getTargetPopulations(location, date) {
Expand Down Expand Up @@ -194,7 +195,7 @@
if (version === 1) {
return {
weeklyLevels: getWeeklyLevels(location, date),
weeksOfStock: weeksOfStock,
supplyPlan: weeksOfStock,
monthlyTargetPopulations: monthlyTargetPopulations
};
}
Expand All @@ -204,7 +205,7 @@

return {
weeklyLevels: weeklyLevels,
weeksOfStock: weeksOfStock,
supplyPlan: weeksOfStock,
monthlyTargetPopulations: monthlyTargetPopulations
};
});
Expand Down Expand Up @@ -266,7 +267,7 @@
}

var _locationFactors = locationFactors,
weeksOfStock = _locationFactors.weeksOfStock,
supplyPlan = _locationFactors.supplyPlan,
weeklyLevels = _locationFactors.weeklyLevels,
monthlyTargetPopulations = _locationFactors.monthlyTargetPopulations;

Expand All @@ -283,8 +284,15 @@
presentation = parseInt(product.presentation, 10);
}

index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) {
var level = weeklyLevel * weeksOfStock[threshold];
// Original version 1 plans only allow
// one supply plan for all products
var productPlan = supplyPlan.weeksOfStock;
if (supplyPlan.version === 2) {
productPlan = supplyPlan.products[productId];
}

index[productId] = Object.keys(productPlan).reduce(function (productThresholds, threshold) {
var level = weeklyLevel * productPlan[threshold];
var roundedLevel = Math.ceil(level / presentation) * presentation;
productThresholds[threshold] = roundedLevel;

Expand Down
2 changes: 1 addition & 1 deletion dist/bundle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3cdcd24

Please sign in to comment.