|
139 | 139 | if (!(plans && plans.weeksOfStock)) {
|
140 | 140 | throw new Error('cannot find version of weeksOfStock for location ' + location._id + ' and date ' + date);
|
141 | 141 | }
|
142 |
| - return plans.weeksOfStock; |
| 142 | + |
| 143 | + return plans; |
143 | 144 | };
|
144 | 145 |
|
145 | 146 | var getTargetPopulations = function getTargetPopulations(location, date) {
|
|
194 | 195 | if (version === 1) {
|
195 | 196 | return {
|
196 | 197 | weeklyLevels: getWeeklyLevels(location, date),
|
197 |
| - weeksOfStock: weeksOfStock, |
| 198 | + supplyPlan: weeksOfStock, |
198 | 199 | monthlyTargetPopulations: monthlyTargetPopulations
|
199 | 200 | };
|
200 | 201 | }
|
|
204 | 205 |
|
205 | 206 | return {
|
206 | 207 | weeklyLevels: weeklyLevels,
|
207 |
| - weeksOfStock: weeksOfStock, |
| 208 | + supplyPlan: weeksOfStock, |
208 | 209 | monthlyTargetPopulations: monthlyTargetPopulations
|
209 | 210 | };
|
210 | 211 | });
|
|
266 | 267 | }
|
267 | 268 |
|
268 | 269 | var _locationFactors = locationFactors,
|
269 |
| - weeksOfStock = _locationFactors.weeksOfStock, |
| 270 | + supplyPlan = _locationFactors.supplyPlan, |
270 | 271 | weeklyLevels = _locationFactors.weeklyLevels,
|
271 | 272 | monthlyTargetPopulations = _locationFactors.monthlyTargetPopulations;
|
272 | 273 |
|
|
283 | 284 | presentation = parseInt(product.presentation, 10);
|
284 | 285 | }
|
285 | 286 |
|
286 |
| - index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) { |
287 |
| - var level = weeklyLevel * weeksOfStock[threshold]; |
| 287 | + // Original version 1 plans only allow |
| 288 | + // one supply plan for all products |
| 289 | + var productPlan = supplyPlan.weeksOfStock; |
| 290 | + if (supplyPlan.version === 2) { |
| 291 | + productPlan = supplyPlan.products[productId]; |
| 292 | + } |
| 293 | + |
| 294 | + index[productId] = Object.keys(productPlan).reduce(function (productThresholds, threshold) { |
| 295 | + var level = weeklyLevel * productPlan[threshold]; |
288 | 296 | var roundedLevel = Math.ceil(level / presentation) * presentation;
|
289 | 297 | productThresholds[threshold] = roundedLevel;
|
290 | 298 |
|
|
0 commit comments