diff --git a/client/src/js/components/bhStockEntryExitType.js b/client/src/js/components/bhStockEntryExitType.js index 79eb9574ed..a8e0742afe 100644 --- a/client/src/js/components/bhStockEntryExitType.js +++ b/client/src/js/components/bhStockEntryExitType.js @@ -4,9 +4,9 @@ angular.module('bhima.components') controller: StockEntryExitTypeController, bindings: { onEntryExitTypeSelectCallback: '&?', - reference : '', - displayName : '', - isEntry : '<' + reference: '', + displayName: '', + isEntry: '<' }, }); @@ -20,16 +20,35 @@ function StockEntryExitTypeController() { $ctrl.selectedEntryExitType = null; $ctrl.entryExitTypeList = [ - { label: 'patient', labelKey: 'PATIENT_REG.ENTITY', descriptionKey: 'STOCK.PATIENT_DISTRIBUTION', isEntry : false }, - { label: 'service', labelKey: 'SERVICE.ENTITY', descriptionKey: 'STOCK.SERVICE_DISTRIBUTION', isEntry : false }, - { label: 'depot', labelKey: 'DEPOT.ENTITY', descriptionKey: 'STOCK.DEPOT_DISTRIBUTION', isEntry : false }, - { label: 'loss', labelKey: 'STOCK.EXIT_LOSS', descriptionKey: 'STOCK.LOSS_DISTRIBUTION', isEntry : false }, - { label: 'purchase', labelKey: 'STOCK.ENTRY_PURCHASE', descriptionKey: 'STOCK_FLUX.FROM_PURCHASE', isEntry : true }, - { label: 'integration', labelKey: 'STOCK.INTEGRATION', descriptionKey: 'STOCK_FLUX.FROM_INTEGRATION', isEntry : true }, - { label: 'donation', labelKey: 'STOCK.DONATION', descriptionKey: 'STOCK_FLUX.FROM_DONATION', isEntry : true }, - { label: 'transfer_reception', labelKey: 'STOCK.RECEPTION_TRANSFER', descriptionKey: 'STOCK_FLUX.FROM_TRANSFER', isEntry : true } + { label: 'patient', labelKey: 'PATIENT_REG.ENTITY', descriptionKey: 'STOCK.PATIENT_DISTRIBUTION', isEntry: false }, + { label: 'service', labelKey: 'SERVICE.ENTITY', descriptionKey: 'STOCK.SERVICE_DISTRIBUTION', isEntry: false }, + { label: 'depot', labelKey: 'DEPOT.ENTITY', descriptionKey: 'STOCK.DEPOT_DISTRIBUTION', isEntry: false }, + { label: 'loss', labelKey: 'STOCK.EXIT_LOSS', descriptionKey: 'STOCK.LOSS_DISTRIBUTION', isEntry: false }, + { label: 'purchase', labelKey: 'STOCK.ENTRY_PURCHASE', descriptionKey: 'STOCK_FLUX.FROM_PURCHASE', isEntry: true }, + { label: 'integration', labelKey: 'STOCK.INTEGRATION', descriptionKey: 'STOCK_FLUX.FROM_INTEGRATION', isEntry: true }, + { label: 'donation', labelKey: 'STOCK.DONATION', descriptionKey: 'STOCK_FLUX.FROM_DONATION', isEntry: true }, + { label: 'transfer_reception', labelKey: 'STOCK.RECEPTION_TRANSFER', descriptionKey: 'STOCK_FLUX.FROM_TRANSFER', isEntry: true } ]; + $ctrl.display = function () { + if ($ctrl.isEntry) { + return $ctrl.reference || ''; + } else { + var list = []; + + if ($ctrl.reference) { + list.push($ctrl.reference); + } + + if ($ctrl.displayName) { + list.push($ctrl.displayName); + + } + + return list.join(' - '); + } + } + $ctrl.selectEntryExitType = function (type) { $ctrl.selectedEntryExitType = type; $ctrl.onEntryExitTypeSelectCallback({ type: type }); diff --git a/client/src/modules/stock/entry/entry.js b/client/src/modules/stock/entry/entry.js index 295c8b45d0..d1e7185515 100644 --- a/client/src/modules/stock/entry/entry.js +++ b/client/src/modules/stock/entry/entry.js @@ -22,7 +22,7 @@ function StockEntryController(Depots, Inventory, Notify, var mapEntry = { purchase : { find: findPurchase, submit: submitPurchase }, donation : { find: angular.noop, submit: angular.noop }, // donation is not yet implemented - integration : { find: angular.noop, submit: submitIntegration}, + integration : { find: handleIntegrationSelection, submit: submitIntegration}, transfer_reception : {find: findTransfer, submit : submitTransferReception}, }; @@ -145,6 +145,8 @@ function StockEntryController(Depots, Inventory, Notify, // ============================ Modals ================================ // find purchase function findPurchase() { + initSelectedEntity(); + StockModal.openFindPurchase() .then(function(purchase) { if (!purchase) { return; } @@ -153,6 +155,8 @@ function StockEntryController(Depots, Inventory, Notify, type : 'purchase', instance : purchase[0], }; + + setSelectedEntity(purchase[0]); populate(purchase); }) .catch(Notify.handleError); @@ -160,6 +164,8 @@ function StockEntryController(Depots, Inventory, Notify, // find transfer function findTransfer(params) { + initSelectedEntity(); + StockModal.openFindTansfer({depot_uuid : vm.depot.uuid}) .then(function(transfers) { if (!transfers) { return; } @@ -174,6 +180,10 @@ function StockEntryController(Depots, Inventory, Notify, .catch(Notify.handleError); } + function handleIntegrationSelection (){ + initSelectedEntity(); + } + // populate the grid function populate(items) { if (!items.length) { return; } @@ -192,9 +202,18 @@ function StockEntryController(Depots, Inventory, Notify, }); } + function initSelectedEntity (){ + vm.reference = vm.displayName = ''; + } + + function setSelectedEntity (entity){ + var uniformEntity = Stock.uniformSelectedEntity(entity); + vm.reference = uniformEntity.reference; + vm.displayName = uniformEntity.displayName; + } + // ============================ lots management =========================== function setLots(inventory) { - console.log('inventaire', inventory); StockModal.openDefineLots({ inventory : inventory, entry_type : vm.movement.entry_type, diff --git a/client/src/modules/templates/bhStockEntryExitType.tmpl.html b/client/src/modules/templates/bhStockEntryExitType.tmpl.html index 3d773b0066..946317f566 100644 --- a/client/src/modules/templates/bhStockEntryExitType.tmpl.html +++ b/client/src/modules/templates/bhStockEntryExitType.tmpl.html @@ -8,12 +8,9 @@