diff --git a/dist/bundle.js b/dist/bundle.js index ceb1ddf..c99fe47 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -42,16 +42,20 @@ return undefined; }; - var productsGroupedByStatus = function productsGroupedByStatus(stock) { - return Object.keys(stock).reduce(function (grouped, product) { - var status = stock[product].status; + var productsGroupedByStatus = function productsGroupedByStatus(stock, products) { + return Object.keys(stock).reduce(function (grouped, productId) { + var isRelevant = !!find(products, function (product) { + return product._id === productId; + }); + var status = stock[productId].status; + if (!isRelevant) { + return grouped; + } if (status) { - grouped[status].push(product); - } else { - grouped['unknown'].push(product); + grouped[status].push(productId); } return grouped; - }, { understock: [], 're-stock': [], ok: [], overstock: [], unknown: [] }); + }, { understock: [], 're-stock': [], ok: [], overstock: [] }); }; var sumAllocations = function sumAllocations(sum, stock) { @@ -195,7 +199,7 @@ }; if (stockCount.location && stockCount.location.lga) { - var groupedByStatus = productsGroupedByStatus(stockCount.stock); + var groupedByStatus = productsGroupedByStatus(stockCount.stock, products); stockCount.reStockNeeded = !!(groupedByStatus.understock.length + groupedByStatus['re-stock'].length); } else { // states and zones @@ -208,17 +212,19 @@ }; var addStockLevelStatusField = function addStockLevelStatusField(stockCount) { - var unknownProducts = productsGroupedByStatus(stockCount.stock).unknown.length; - var understockedProducts = productsGroupedByStatus(stockCount.stock).understock.length; + var grouped = productsGroupedByStatus(stockCount.stock, products); + var understockedProducts = grouped.understock.length; + var totalGrouped = Object.keys(grouped).reduce(function (sum, group) { + return sum + grouped[group].length; + }, 0); + stockCount.stockLevelStatus = 'unknown'; if (stockCount.location) { if (understockedProducts >= _this2.STOCK_STATUSES.alert.threshold) { stockCount.stockLevelStatus = _this2.STOCK_STATUSES.alert.id; } else if (understockedProducts >= _this2.STOCK_STATUSES.warning.threshold) { stockCount.stockLevelStatus = _this2.STOCK_STATUSES.warning.id; - } else if (unknownProducts) { - stockCount.stockLevelStatus = 'unknown'; - } else { + } else if (totalGrouped > 0) { stockCount.stockLevelStatus = _this2.STOCK_STATUSES.ok.id; } } diff --git a/dist/bundle.min.js b/dist/bundle.min.js index 7c725b7..a83733a 100644 --- a/dist/bundle.min.js +++ b/dist/bundle.min.js @@ -1 +1 @@ -!function(t){"use strict";t="default"in t?t["default"]:t;var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var n=0;n0&&(t[n]+=e[n].allocation),t},t)},a=function(){function t(e,o,r,i,c,a,s,u){n(this,t),this.$q=e,this.smartId=o,this.STOCK_STATUSES=r,this.lgasService=i,this.statesService=c,this.zonesService=a,this.thresholdsService=s,this.productListService=u}return o(t,[{key:"stateRequiredAllocationsByZone",value:function(t){var e=this;return t.reduce(function(t,n){if(n.location&&n.location.state&&!n.location.lga&&n.reStockNeeded){var o=e.smartId.idify({zone:n.location.zone},"locationId");t[o]=t[o]||{},t[o]=c(t[o],n.stock)}return t},{})}},{key:"decorateWithIndicators",value:function(t){var n=this,o=void 0,c=void 0,a=void 0,s=void 0,u=function(t,n,o,i){var c=i.location.lga,a=i.location.state;if(c)return r(t,function(t){return t.id===c});if(a)return r(n,function(t){return t.id===a});var s=function(){var t=i.location.zone;return{v:r(o,function(e){return e.id===t})}}();return"object"===("undefined"==typeof s?"undefined":e(s))?s.v:void 0},l=function(t,e){var i=u(o,c,a,e),l=void 0;l=i&&"zone"===i.level?n.thresholdsService.calculateThresholds(i,e,s,t[i._id],{version:"last"}):n.thresholdsService.calculateThresholds(i,e,s);var d=e.stock,f=Object.keys(d).reduce(function(t,e){var n=d[e],o=void 0,i=void 0,c=void 0,a=r(s,function(t){return t._id===e});if(l&&(c=l[e])){o="overstock",n0?u+(a.presentation-f):u}}return t[e]={status:o,amount:n,allocation:i,thresholds:c},t},{});return e.stock=f,e},d=function(t){var e=function(e,n){return t.stock[n].allocation>0&&(e+=t.stock[n].allocation),e};if(t.location&&t.location.lga){var n=i(t.stock);t.reStockNeeded=!!(n.understock.length+n["re-stock"].length)}else if(t.stock){var o=Object.keys(t.stock).reduce(e,0);t.reStockNeeded=o>0}return t},f=function(t){var e=i(t.stock).unknown.length,o=i(t.stock).understock.length;return t.location&&(t.stockLevelStatus=o>=n.STOCK_STATUSES.alert.threshold?n.STOCK_STATUSES.alert.id:o>=n.STOCK_STATUSES.warning.threshold?n.STOCK_STATUSES.warning.id:e?"unknown":n.STOCK_STATUSES.ok.id),t},v=function(t){return t.stock&&Object.keys(t.stock).length},S=function(t){return t.location&&t.location.zone&&!t.location.state},h=function(t){return!S(t)},k=function(t,e,r){return o=r.lgas,c=r.states,a=r.zones||[],s=r.products,t=t.map(l.bind(null,null)).map(d),e=e.map(l.bind(null,n.stateRequiredAllocationsByZone(t))).map(d),t.concat(e).map(f)},y={lgas:this.lgasService.list(),states:this.statesService.list(),products:this.productListService.relevant()};if(t=t.filter(v),!t.length)return this.$q.when(t);var g=t.filter(S),T=t.filter(h);return g.length&&(y.zones=this.zonesService.list()),this.$q.all(y).then(k.bind(null,T,g))}}]),t}();a.$inject=["$q","smartId","STOCK_STATUSES","lgasService","statesService","zonesService","thresholdsService","productListService"],t.module("angularNavStateIndicators",["ngSmartId","angularNavData","angularNavThresholds"]).service("stateIndicatorsService",a)}(angular); \ No newline at end of file +!function(t){"use strict";t="default"in t?t["default"]:t;var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},r=function(){function t(t,e){for(var n=0;n0&&(t[n]+=e[n].allocation),t},t)},a=function(){function t(e,r,o,i,c,a,s,u){n(this,t),this.$q=e,this.smartId=r,this.STOCK_STATUSES=o,this.lgasService=i,this.statesService=c,this.zonesService=a,this.thresholdsService=s,this.productListService=u}return r(t,[{key:"stateRequiredAllocationsByZone",value:function(t){var e=this;return t.reduce(function(t,n){if(n.location&&n.location.state&&!n.location.lga&&n.reStockNeeded){var r=e.smartId.idify({zone:n.location.zone},"locationId");t[r]=t[r]||{},t[r]=c(t[r],n.stock)}return t},{})}},{key:"decorateWithIndicators",value:function(t){var n=this,r=void 0,c=void 0,a=void 0,s=void 0,u=function(t,n,r,i){var c=i.location.lga,a=i.location.state;if(c)return o(t,function(t){return t.id===c});if(a)return o(n,function(t){return t.id===a});var s=function(){var t=i.location.zone;return{v:o(r,function(e){return e.id===t})}}();return"object"===("undefined"==typeof s?"undefined":e(s))?s.v:void 0},l=function(t,e){var i=u(r,c,a,e),l=void 0;l=i&&"zone"===i.level?n.thresholdsService.calculateThresholds(i,e,s,t[i._id],{version:"last"}):n.thresholdsService.calculateThresholds(i,e,s);var d=e.stock,f=Object.keys(d).reduce(function(t,e){var n=d[e],r=void 0,i=void 0,c=void 0,a=o(s,function(t){return t._id===e});if(l&&(c=l[e])){r="overstock",n0?u+(a.presentation-f):u}}return t[e]={status:r,amount:n,allocation:i,thresholds:c},t},{});return e.stock=f,e},d=function(t){var e=function(e,n){return t.stock[n].allocation>0&&(e+=t.stock[n].allocation),e};if(t.location&&t.location.lga){var n=i(t.stock,s);t.reStockNeeded=!!(n.understock.length+n["re-stock"].length)}else if(t.stock){var r=Object.keys(t.stock).reduce(e,0);t.reStockNeeded=r>0}return t},f=function(t){var e=i(t.stock,s),r=e.understock.length,o=Object.keys(e).reduce(function(t,n){return t+e[n].length},0);return t.stockLevelStatus="unknown",t.location&&(r>=n.STOCK_STATUSES.alert.threshold?t.stockLevelStatus=n.STOCK_STATUSES.alert.id:r>=n.STOCK_STATUSES.warning.threshold?t.stockLevelStatus=n.STOCK_STATUSES.warning.id:o>0&&(t.stockLevelStatus=n.STOCK_STATUSES.ok.id)),t},v=function(t){return t.stock&&Object.keys(t.stock).length},S=function(t){return t.location&&t.location.zone&&!t.location.state},h=function(t){return!S(t)},k=function(t,e,o){return r=o.lgas,c=o.states,a=o.zones||[],s=o.products,t=t.map(l.bind(null,null)).map(d),e=e.map(l.bind(null,n.stateRequiredAllocationsByZone(t))).map(d),t.concat(e).map(f)},y={lgas:this.lgasService.list(),states:this.statesService.list(),products:this.productListService.relevant()};if(t=t.filter(v),!t.length)return this.$q.when(t);var g=t.filter(S),T=t.filter(h);return g.length&&(y.zones=this.zonesService.list()),this.$q.all(y).then(k.bind(null,T,g))}}]),t}();a.$inject=["$q","smartId","STOCK_STATUSES","lgasService","statesService","zonesService","thresholdsService","productListService"],t.module("angularNavStateIndicators",["ngSmartId","angularNavData","angularNavThresholds"]).service("stateIndicatorsService",a)}(angular); \ No newline at end of file