Skip to content

Commit

Permalink
Use of tooltip and considering also warning about near to expire
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda committed Sep 3, 2020
1 parent 9ed88a7 commit 99cb675
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 60 deletions.
4 changes: 3 additions & 1 deletion client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@
"CLICK_TO_SEE":"Click here to see lots",
"SHOW_WARNINGS":"Click to show Warnings",
"NO_RISK_OF_EXPIRATION":"No lots with expiration risk",
"RISK_OF_EXPIRATION":"Expiration:{{expiration}} of {{quantity}} {{unit}}",
"RISK_OF_EXPIRATION":"There are {{quantity}} {{unit}} at risk of expiration",
"EXPIRED":"There are {{quantity}} {{unit}} expired",
"NEAR_EXPIRE":"There are {{quantity}} {{unit}} near to expire",
"SHOW_ONLY_RISKY_LOTS":"Show only inventories with risky lots"
},
"MOVEMENTS" : {
Expand Down
4 changes: 3 additions & 1 deletion client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@
"CLICK_TO_SEE":"Cliquez ici pour voir les lots",
"SHOW_WARNINGS":"Cliquer pour afficher les avertissements",
"NO_RISK_OF_EXPIRATION":"Aucun lots à risque de péremption",
"RISK_OF_EXPIRATION":"Expiration:{{expiration}} de {{quantity}} {{unit}}",
"RISK_OF_EXPIRATION":"Il y a {{quantity}} {{unit}} à risque d'expiration",
"EXPIRED":"Il y a {{quantity}} {{unit}} expirés",
"NEAR_EXPIRE":"Il y a {{quantity}} {{unit}} près d'expiration",
"SHOW_ONLY_RISKY_LOTS":"Afficher uniquement les articles ayant des lots à risque"
},
"MOVEMENTS" : {
Expand Down
30 changes: 5 additions & 25 deletions client/src/modules/stock/inventories/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ StockInventoriesController.$inject = [
'uiGridConstants', 'StockModalService', 'LanguageService', 'SessionService',
'GridGroupingService', 'bhConstants', 'GridStateService',
'$state', 'GridColumnService', '$httpParamSerializer', 'BarcodeService',
'moment',
];

/**
Expand All @@ -16,7 +15,7 @@ StockInventoriesController.$inject = [
function StockInventoriesController(
Stock, Notify, uiGridConstants, Modal, Languages,
Session, Grouping, bhConstants, GridState, $state, Columns,
$httpParamSerializer, Barcode, moment,
$httpParamSerializer, Barcode,
) {
const vm = this;
const cacheKey = 'stock-inventory-grid';
Expand Down Expand Up @@ -142,29 +141,6 @@ function StockInventoriesController(
vm.saveGridState = state.saveGridState;
vm.getQueryString = Stock.getQueryString;

vm.toggleTooltip = row => {
if (row.tooltipIsOpen) {
row.tooltipIsOpen = !row.tooltipIsOpen;
return;
}

Stock.lots.read(null, {
inventory_uuid : row.inventory_uuid,
depot_uuid : row.depot_uuid,
})
.then(lots => {
row.lots = lots
.filter(item => item.quantity > 0 && item.IS_IN_RISK_EXPIRATION === true)
.map(item => {
const delay = moment(new Date(item.expiration_date)).diff(new Date());
item.delay_expiration = moment.duration(delay).humanize(true);
return item;
});
row.tooltipIsOpen = true;
})
.catch(Notify.handleError);
};

function clearGridState() {
state.clearGridState();
$state.reload();
Expand Down Expand Up @@ -218,6 +194,10 @@ function StockInventoriesController(
}

function setStatusFlag(item) {
item.noAlert = !item.hasRiskyLots && !item.hasNearExpireLots && !item.hasExpiredLots;
item.alert = item.hasExpiredLots;
item.warning = !item.hasExpiredLots && (item.hasNearExpireLots || item.hasRiskyLots);

item.isSoldOut = item.status === bhConstants.stockStatus.IS_STOCK_OUT;
item.isInStock = item.status === bhConstants.stockStatus.IS_IN_STOCK;
item.hasSecurityWarning = item.status === bhConstants.stockStatus.HAS_SECURITY_WARNING;
Expand Down
60 changes: 31 additions & 29 deletions client/src/modules/stock/inventories/templates/warning.cell.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
<div ng-if="!row.groupHeader" style="cursor: pointer;" ng-click="grid.appScope.toggleTooltip(row.entity)" translate-attr="{'title': 'LOTS.SHOW_WARNINGS' }" class="ui-grid-cell-contents text-center" translate>
<div ng-if="!row.groupHeader" class="ui-grid-cell-contents text-center" translate>
<span
uib-popover-template="'warningLotsMessage.html'"
popover-trigger="none"
popover-is-open="row.entity.tooltipIsOpen"
popover-append-to-body="true"
uib-tooltip-template="'warningLotsMessage.html'"
tooltip-append-to-body="true"
translate>
<i ng-if="!row.entity.has_risky_lots" class="fa fa-check text-success"></i>

<i ng-if="row.entity.has_risky_lots" class="fa fa-warning text-danger"></i>
<i ng-if="row.entity.noAlert" class="fa fa-check text-success"></i>

<i ng-if="row.entity.alert" class="fa fa-exclamation-triangle text-danger"></i>

<i ng-if="row.entity.warning" class="fa fa-exclamation-circle text-warning"></i>
</span>
</div>

<script type="text/ng-template" id="warningLotsMessage.html">
<!-- no expiration risk -->
<div ng-if="!row.entity.lots.length">
<div ng-if="row.entity.noAlert">
<i class="fa fa-check text-success"></i> <span class="text-success" translate>LOTS.NO_RISK_OF_EXPIRATION</span>
</div>

<!-- expiration risk -->
<div ng-if="row.entity.lots.length">
<div ng-repeat="lot in row.entity.lots track by lot.uuid | limitTo: 3">
<i class="fa fa-warning text-danger"></i>
<span class="text-danger"
translate="LOTS.RISK_OF_EXPIRATION"
translate-values="{
quantity : lot.quantity,
unit : lot.unit_type,
label : lot.label,
expiration : lot.delay_expiration
}"></span>
</div>
<!-- risky lots -->
<div ng-if="row.entity.riskyLotsQuantity">
<i class="fa fa-warning text-warning"></i>
<span class="text-warning"
translate="LOTS.RISK_OF_EXPIRATION"
translate-values="{ quantity : row.entity.riskyLotsQuantity, unit : row.entity.unit_type }">
</span>
</div>

<div ng-if="row.entity.lots.length > 3">...</div>
<!-- expired lots -->
<div ng-if="row.entity.nearExpireLotsQuantity">
<i class="fa fa-warning text-warning"></i>
<span class="text-warning"
translate="LOTS.NEAR_EXPIRE"
translate-values="{ quantity : row.entity.nearExpireLotsQuantity, unit : row.entity.unit_type }">
</span>
</div>

<div class="text-right">
<a ui-sref="stockLots({ filters : [
{ key : 'inventory_uuid', value : row.entity.inventory_uuid, displayValue : row.entity.text, cacheable: false },
{ key : 'depot_uuid', value : row.entity.depot_uuid, displayValue : row.entity.depot_text, cacheable: false },
{ key : 'limit', value : 1000, cacheable: false }
]})" href>Voir les lots</a>
<!-- expired lots -->
<div ng-if="row.entity.expiredLotsQuantity">
<i class="fa fa-warning text-danger"></i>
<span class="text-danger"
translate="LOTS.EXPIRED"
translate-values="{ quantity : row.entity.expiredLotsQuantity, unit : row.entity.unit_type }">
</span>
</div>
</script>
34 changes: 30 additions & 4 deletions server/controllers/stock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,23 +634,49 @@ async function listInventoryDepot(req, res, next) {

for (let i = 0; i < inventories.length; i++) {
let hasRiskyLots = false;
let hasExpiredLots = false;
let hasNearExpireLots = false;

let riskyLotsQuantity = 0;
let expiredLotsQuantity = 0;
let nearExpireLotsQuantity = 0;

for (let j = 0; j < lots.length; j++) {
const hasSameDepot = lots[j].depot_uuid === inventories[i].depot_uuid;
const hasSameInventory = lots[j].inventory_uuid === inventories[i].inventory_uuid;
if (hasSameDepot && hasSameInventory) {
if (lots[j].IS_IN_RISK_EXPIRATION && lots[j].quantity > 0) {
const lot = lots[j];
if (lot.quantity <= 0) {
// lot exhausted
} else if (lot.lifetime < 0) {
// Equivalent to: lot.quantity > 0 && lot.lifetime < 0
hasExpiredLots = true;
expiredLotsQuantity += lot.quantity;
} else if (lot.IS_IN_RISK_EXPIRATION) {
// Equivalent to: lot.quantity > 0 && lot.lifetime >= 0 && lot.IS_IN_RISK_EXPIRATION
hasNearExpireLots = true;
nearExpireLotsQuantity += lot.quantity;
} else if (lot.S_RISK <= 0) {
// Equivalent to: lot.quantity > 0 && lot.lifetime >= 0 && lot.S_RISK <= 0
hasRiskyLots = true;
break;
riskyLotsQuantity += lot.quantity;
}
}
}
inventories[i].has_risky_lots = hasRiskyLots;

inventories[i].hasNearExpireLots = hasNearExpireLots;
inventories[i].hasRiskyLots = hasRiskyLots;
inventories[i].hasExpiredLots = hasExpiredLots;

inventories[i].nearExpireLotsQuantity = nearExpireLotsQuantity;
inventories[i].riskyLotsQuantity = riskyLotsQuantity;
inventories[i].expiredLotsQuantity = expiredLotsQuantity;
}

let rows = inventories;

if (params.show_only_risky) {
rows = inventories.filter(item => item.has_risky_lots === true);
rows = inventories.filter(item => (item.hasRiskyLots || item.hasNearExpireLots || item.hasExpiredLots));
}

res.status(200).json(rows);
Expand Down

0 comments on commit 99cb675

Please sign in to comment.