From 097461ae8cab27f3950f26f5d2c0b418580f9a0d Mon Sep 17 00:00:00 2001 From: DedrickEnc Date: Mon, 23 Oct 2017 13:51:49 +0100 Subject: [PATCH] feat(grid): Alert a user if there is not stock in the depot --- client/src/i18n/en/stock.json | 1 + client/src/i18n/fr/stock.json | 1 + .../js/components/bhGridLoadingIndicator.js | 1 + client/src/modules/stock/entry/entry.html | 116 +++---- client/src/modules/stock/exit/exit.html | 6 + client/src/modules/stock/exit/exit.js | 300 +++++++++--------- .../bhGridLoadingIndicator.tmpl.html | 2 +- 7 files changed, 210 insertions(+), 217 deletions(-) diff --git a/client/src/i18n/en/stock.json b/client/src/i18n/en/stock.json index 27e19a23e5..790ef2e8d1 100644 --- a/client/src/i18n/en/stock.json +++ b/client/src/i18n/en/stock.json @@ -16,6 +16,7 @@ "DETAILS" : "Details", "DOCUMENT" : "Document", "DONATION" : "Donation", + "EMPTY" : "No stock found", "ENTRY" : "Stock Entry", "ENTRY_DATE" : "Entry Date", "ENTRY_DOCUMENT" : "Entry Document", diff --git a/client/src/i18n/fr/stock.json b/client/src/i18n/fr/stock.json index ebcb69a475..480c8113ff 100644 --- a/client/src/i18n/fr/stock.json +++ b/client/src/i18n/fr/stock.json @@ -16,6 +16,7 @@ "DETAILS" : "Details", "DOCUMENT" : "Document", "DONATION" : "Donation", + "EMPTY" : "Pas de stock trouvé", "ENTRY" : "Entrée de stock", "ENTRY_DATE" : "Date d'entrée", "ENTRY_DOCUMENT" : "Document d'entrée", diff --git a/client/src/js/components/bhGridLoadingIndicator.js b/client/src/js/components/bhGridLoadingIndicator.js index d5fa6eb342..b3624150d4 100644 --- a/client/src/js/components/bhGridLoadingIndicator.js +++ b/client/src/js/components/bhGridLoadingIndicator.js @@ -4,6 +4,7 @@ angular.module('bhima.components') loadingState : '<', emptyState : '<', errorState : '<', + messageState : ' - -
- - -
+ +
+ + +
- -
-
- - - + +
+
+ + + - -
-
-
- -
-
+ +
+
- -

- - FORM.INFO.NO_SOURCE -

+ +

+ + FORM.INFO.NO_SOURCE +

- - - + + + +
-
- -
-
+ +
+
- -
-
-
- - - FORM.BUTTONS.SUBMIT - + + FORM.BUTTONS.SUBMIT + +
-
-
+
\ No newline at end of file diff --git a/client/src/modules/stock/exit/exit.html b/client/src/modules/stock/exit/exit.html index 9084b3c825..58a9743928 100644 --- a/client/src/modules/stock/exit/exit.html +++ b/client/src/modules/stock/exit/exit.html @@ -118,6 +118,12 @@ style="height: 300px; width: 100%;" ui-grid-auto-resize ui-grid-resize-columns> + + diff --git a/client/src/modules/stock/exit/exit.js b/client/src/modules/stock/exit/exit.js index 54332c1f39..888253b15f 100644 --- a/client/src/modules/stock/exit/exit.js +++ b/client/src/modules/stock/exit/exit.js @@ -23,16 +23,16 @@ function StockExitController( ) { var vm = this; var mapExit = { - patient : { description : 'STOCK.EXIT_PATIENT', find : findPatient, submit : submitPatient }, - service : { description : 'STOCK.EXIT_SERVICE', find : findService, submit : submitService }, - depot : { description : 'STOCK.EXIT_DEPOT', find : findDepot, submit : submitDepot }, - loss : { description : 'STOCK.EXIT_LOSS', find : configureLoss, submit : submitLoss }, + patient: { description: 'STOCK.EXIT_PATIENT', find: findPatient, submit: submitPatient }, + service: { description: 'STOCK.EXIT_SERVICE', find: findService, submit: submitService }, + depot: { description: 'STOCK.EXIT_DEPOT', find: findDepot, submit: submitDepot }, + loss: { description: 'STOCK.EXIT_LOSS', find: configureLoss, submit: submitLoss }, }; var cache = new AppCache('StockExit'); vm.util = util; - vm.Stock = new StockForm('StockExit'); + vm.stockForm = new StockForm('StockExit'); vm.movement = {}; // bind methods @@ -50,75 +50,75 @@ function StockExitController( // grid options var gridOptions = { - appScopeProvider : vm, - enableSorting : false, - enableColumnMenus : false, - columnDefs : [ + appScopeProvider: vm, + enableSorting: false, + enableColumnMenus: false, + columnDefs: [ { - field : 'status', - width : 25, - displayName : '', - cellTemplate : 'modules/stock/exit/templates/status.tmpl.html', + field: 'status', + width: 25, + displayName: '', + cellTemplate: 'modules/stock/exit/templates/status.tmpl.html', }, { - field : 'code', - width : 120, - displayName : 'INVENTORY.CODE', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/code.tmpl.html', + field: 'code', + width: 120, + displayName: 'INVENTORY.CODE', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/code.tmpl.html', }, { - field : 'description', - displayName : 'TABLE.COLUMNS.DESCRIPTION', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/description.tmpl.html', + field: 'description', + displayName: 'TABLE.COLUMNS.DESCRIPTION', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/description.tmpl.html', }, { - field : 'lot', - width : 150, - displayName : 'TABLE.COLUMNS.LOT', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/lot.tmpl.html', + field: 'lot', + width: 150, + displayName: 'TABLE.COLUMNS.LOT', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/lot.tmpl.html', }, { - field : 'unit_price', - width : 150, - displayName : 'TABLE.COLUMNS.UNIT_PRICE', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/price.tmpl.html', + field: 'unit_price', + width: 150, + displayName: 'TABLE.COLUMNS.UNIT_PRICE', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/price.tmpl.html', }, { - field : 'quantity', - width : 150, - displayName : 'TABLE.COLUMNS.QUANTITY', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/quantity.tmpl.html', - treeAggregationType : uiGridGroupingConstants.aggregation.SUM, + field: 'quantity', + width: 150, + displayName: 'TABLE.COLUMNS.QUANTITY', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/quantity.tmpl.html', + treeAggregationType: uiGridGroupingConstants.aggregation.SUM, }, { - field : 'unit_type', - width : 75, - displayName : 'TABLE.COLUMNS.UNIT', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/unit.tmpl.html', + field: 'unit_type', + width: 75, + displayName: 'TABLE.COLUMNS.UNIT', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/unit.tmpl.html', }, { - field : 'available_lot', - width : 150, - displayName : 'TABLE.COLUMNS.AVAILABLE', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/available.tmpl.html', + field: 'available_lot', + width: 150, + displayName: 'TABLE.COLUMNS.AVAILABLE', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/available.tmpl.html', }, { - field : 'amount', - width : 150, - displayName : 'TABLE.COLUMNS.AMOUNT', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/amount.tmpl.html', + field: 'amount', + width: 150, + displayName: 'TABLE.COLUMNS.AMOUNT', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/amount.tmpl.html', }, { - field : 'expiration_date', - width : 150, - displayName : 'TABLE.COLUMNS.EXPIRE_IN', - headerCellFilter : 'translate', - cellTemplate : 'modules/stock/exit/templates/expiration.tmpl.html', + field: 'expiration_date', + width: 150, + displayName: 'TABLE.COLUMNS.EXPIRE_IN', + headerCellFilter: 'translate', + cellTemplate: 'modules/stock/exit/templates/expiration.tmpl.html', }, - { field : 'actions', width : 25, cellTemplate : 'modules/stock/exit/templates/actions.tmpl.html' }, + { field: 'actions', width: 25, cellTemplate: 'modules/stock/exit/templates/actions.tmpl.html' }, ], - data : vm.Stock.store.data, - fastWatch : true, - flatEntityAccess : true, + data: vm.stockForm.store.data, + fastWatch: true, + flatEntityAccess: true, }; vm.gridOptions = gridOptions; @@ -132,19 +132,19 @@ function StockExitController( } function setupStock() { - vm.Stock.setup(); - vm.Stock.store.clear(); + vm.stockForm.setup(); + vm.stockForm.store.clear(); } // add items function addItems(n) { - vm.Stock.addItems(n); + vm.stockForm.addItems(n); checkValidity(); } // remove item function removeItem(item) { - vm.Stock.removeItem(item.index); + vm.stockForm.removeItem(item.index); checkValidity(); } @@ -152,7 +152,7 @@ function StockExitController( function configureItem(item) { item._initialised = true; // get lots - Stock.lots.read(null, { depot_uuid : vm.depot.uuid, inventory_uuid : item.inventory.inventory_uuid, includeEmptyLot : 0 }) + Stock.lots.read(null, { depot_uuid: vm.depot.uuid, inventory_uuid: item.inventory.inventory_uuid, includeEmptyLot: 0 }) .then(function (lots) { item.lots = lots; }) @@ -160,44 +160,43 @@ function StockExitController( } function startup() { + // setting params for grid loading state + vm.loading = true; + vm.hasError = false; + vm.message = 'STOCK.EMPTY'; + vm.movement = { - date : new Date(), - entity : {}, + date: new Date(), + entity: {}, }; vm.depot = cache.depot; - // make sure that the depot is loaded if it doesn't exist at startup. - if (vm.depot) { - setupStock(); - loadInventories(vm.depot); - checkValidity(); + if (!vm.depot) { + changeDepot(); } else { - changeDepot() - .then(setupStock) - .then(function () { - loadInventories(vm.depot); - checkValidity(); - }); + loadInventories(vm.depot); } } - // ============================ Inventories ========================== function loadInventories(depot) { - var givenDepot = depot || vm.depot; - Stock.inventories.read(null, { depot_uuid : givenDepot.uuid }) + // var givenDepot = depot || vm.depot; + setupStock(); + Stock.inventories.read(null, { depot_uuid: depot.uuid }) .then(function (inventories) { + vm.loading = false; vm.selectableInventories = angular.copy(inventories); + checkValidity(); }) .catch(Notify.handleError); } // check validity function checkValidity() { - var lotsExists = vm.Stock.store.data.every(function (item) { + var lotsExists = vm.stockForm.store.data.every(function (item) { return item.quantity > 0 && item.lot.uuid; }); - vm.validForSubmit = (lotsExists && vm.Stock.store.data.length); + vm.validForSubmit = (lotsExists && vm.stockForm.store.data.length); } // ============================ Modals ================================ @@ -207,9 +206,9 @@ function StockExitController( .then(function (patient) { if (!patient) { return; } vm.movement.entity = { - uuid : patient.uuid, - type : 'patient', - instance : patient, + uuid: patient.uuid, + type: 'patient', + instance: patient, }; setSelectedEntity(patient); @@ -223,9 +222,9 @@ function StockExitController( .then(function (service) { if (!service) { return; } vm.movement.entity = { - uuid : service.uuid, - type : 'service', - instance : service, + uuid: service.uuid, + type: 'service', + instance: service, }; setSelectedEntity(service); @@ -235,13 +234,13 @@ function StockExitController( // find depot function findDepot() { - StockModal.openFindDepot({ depot : vm.depot }) + StockModal.openFindDepot({ depot: vm.depot }) .then(function (depot) { if (!depot) { return; } vm.movement.entity = { - uuid : depot.uuid, - type : 'depot', - instance : depot, + uuid: depot.uuid, + type: 'depot', + instance: depot, }; setSelectedEntity(depot); @@ -252,9 +251,9 @@ function StockExitController( // configure loss function configureLoss() { vm.movement.entity = { - uuid : null, - type : 'loss', - instance : {}, + uuid: null, + type: 'loss', + instance: {}, }; setSelectedEntity(); @@ -283,21 +282,21 @@ function StockExitController( // submit patient function submitPatient() { var movement = { - depot_uuid : vm.depot.uuid, - entity_uuid : vm.movement.entity.uuid, - date : vm.movement.date, - description : vm.movement.description, - is_exit : 1, - flux_id : bhConstants.flux.TO_PATIENT, - user_id : Session.user.id, + depot_uuid: vm.depot.uuid, + entity_uuid: vm.movement.entity.uuid, + date: vm.movement.date, + description: vm.movement.description, + is_exit: 1, + flux_id: bhConstants.flux.TO_PATIENT, + user_id: Session.user.id, }; - var lots = vm.Stock.store.data.map(function (row) { + var lots = vm.stockForm.store.data.map(function (row) { return { - inventory_uuid : row.inventory.inventory_uuid, // needed for tracking consumption - uuid : row.lot.uuid, - quantity : row.quantity, - unit_cost : row.lot.unit_cost, + inventory_uuid: row.inventory.inventory_uuid, // needed for tracking consumption + uuid: row.lot.uuid, + quantity: row.quantity, + unit_cost: row.lot.unit_cost, }; }); @@ -305,7 +304,7 @@ function StockExitController( return Stock.movements.create(movement) .then(function (document) { - vm.Stock.store.clear(); + vm.stockForm.store.clear(); ReceiptModal.stockExitPatientReceipt(document.uuid, bhConstants.flux.TO_PATIENT); }) .catch(Notify.handleError); @@ -314,21 +313,21 @@ function StockExitController( // submit service function submitService() { var movement = { - depot_uuid : vm.depot.uuid, - entity_uuid : vm.movement.entity.uuid, - date : vm.movement.date, - description : vm.movement.description, - is_exit : 1, - flux_id : bhConstants.flux.TO_SERVICE, - user_id : Session.user.id, + depot_uuid: vm.depot.uuid, + entity_uuid: vm.movement.entity.uuid, + date: vm.movement.date, + description: vm.movement.description, + is_exit: 1, + flux_id: bhConstants.flux.TO_SERVICE, + user_id: Session.user.id, }; - var lots = vm.Stock.store.data.map(function (row) { + var lots = vm.stockForm.store.data.map(function (row) { return { - inventory_uuid : row.inventory.inventory_uuid, // needed for tracking consumption - uuid : row.lot.uuid, - quantity : row.quantity, - unit_cost : row.lot.unit_cost, + inventory_uuid: row.inventory.inventory_uuid, // needed for tracking consumption + uuid: row.lot.uuid, + quantity: row.quantity, + unit_cost: row.lot.unit_cost, }; }); @@ -336,7 +335,7 @@ function StockExitController( return Stock.movements.create(movement) .then(function (document) { - vm.Stock.store.clear(); + vm.stockForm.store.clear(); ReceiptModal.stockExitServiceReceipt(document.uuid, bhConstants.flux.TO_SERVICE); }) .catch(Notify.handleError); @@ -345,21 +344,21 @@ function StockExitController( // submit depot function submitDepot() { var movement = { - from_depot : vm.depot.uuid, - from_depot_is_warehouse : vm.depot.is_warehouse, - to_depot : vm.movement.entity.uuid, - date : vm.movement.date, - description : vm.movement.description, - isExit : true, - user_id : Session.user.id, + from_depot: vm.depot.uuid, + from_depot_is_warehouse: vm.depot.is_warehouse, + to_depot: vm.movement.entity.uuid, + date: vm.movement.date, + description: vm.movement.description, + isExit: true, + user_id: Session.user.id, }; - var lots = vm.Stock.store.data.map(function (row) { + var lots = vm.stockForm.store.data.map(function (row) { return { - inventory_uuid : row.inventory.inventory_uuid, // needed for tracking consumption - uuid : row.lot.uuid, - quantity : row.quantity, - unit_cost : row.lot.unit_cost, + inventory_uuid: row.inventory.inventory_uuid, // needed for tracking consumption + uuid: row.lot.uuid, + quantity: row.quantity, + unit_cost: row.lot.unit_cost, }; }); @@ -367,7 +366,7 @@ function StockExitController( return Stock.movements.create(movement) .then(function (document) { - vm.Stock.store.clear(); + vm.stockForm.store.clear(); ReceiptModal.stockExitDepotReceipt(document.uuid, bhConstants.flux.TO_OTHER_DEPOT); }) .catch(Notify.handleError); @@ -376,21 +375,21 @@ function StockExitController( // submit loss function submitLoss() { var movement = { - depot_uuid : vm.depot.uuid, - entity_uuid : vm.movement.entity.uuid, - date : vm.movement.date, - description : vm.movement.description, - is_exit : 1, - flux_id : bhConstants.flux.TO_LOSS, - user_id : Session.user.id, + depot_uuid: vm.depot.uuid, + entity_uuid: vm.movement.entity.uuid, + date: vm.movement.date, + description: vm.movement.description, + is_exit: 1, + flux_id: bhConstants.flux.TO_LOSS, + user_id: Session.user.id, }; - var lots = vm.Stock.store.data.map(function (row) { + var lots = vm.stockForm.store.data.map(function (row) { return { - inventory_uuid : row.inventory.inventory_uuid, // needed for tracking consumption - uuid : row.lot.uuid, - quantity : row.quantity, - unit_cost : row.lot.unit_cost, + inventory_uuid: row.inventory.inventory_uuid, // needed for tracking consumption + uuid: row.lot.uuid, + quantity: row.quantity, + unit_cost: row.lot.unit_cost, }; }); @@ -398,7 +397,7 @@ function StockExitController( return Stock.movements.create(movement) .then(function (document) { - vm.Stock.store.clear(); + vm.stockForm.store.clear(); ReceiptModal.stockExitLossReceipt(document.uuid, bhConstants.flux.TO_LOSS); }) .catch(Notify.handleError); @@ -409,6 +408,7 @@ function StockExitController( .then(function (depot) { vm.depot = depot; cache.depot = vm.depot; + loadInventories(vm.depot); }); } diff --git a/client/src/modules/templates/bhGridLoadingIndicator.tmpl.html b/client/src/modules/templates/bhGridLoadingIndicator.tmpl.html index d330617be6..69eb5b9e14 100644 --- a/client/src/modules/templates/bhGridLoadingIndicator.tmpl.html +++ b/client/src/modules/templates/bhGridLoadingIndicator.tmpl.html @@ -8,7 +8,7 @@
- TABLE.COLUMNS.EMPTY + {{ $ctrl.messageState || 'TABLE.COLUMNS.EMPTY' }}