Skip to content

Commit

Permalink
Add barcode scans for stock assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Apr 25, 2022
1 parent 6e08946 commit 55ad27f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"TITLE" : "Assets",
"VIEW_IN_INVENTORY" : "View Asset in Inventory",
"VIEW_IN_STOCK" : "View Asset in Stock",
"WARN_ALREADY_ASSIGNED" : "This asset/lot is already assigned. Remove the assignment before reassigning it !",
"CONDITION" : {
"NEW" : "New",
"GOOD" : "Good",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"TITLE" : "Actifs",
"VIEW_IN_INVENTORY" : "Visualiser l'actif dans l'inventaire",
"VIEW_IN_STOCK" : "Visualiser l'actif dans stock",
"WARN_ALREADY_ASSIGNED" : "Cet actif/lot est déjà assignée. Supprimez cette assignation avant de la réassigner !",
"CONDITION" : {
"NEW" : "Nouveau",
"GOOD" : "Bon",
Expand Down
16 changes: 12 additions & 4 deletions client/src/modules/assets/modals/assign.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
novalidate>

<div class="modal-header">
<ol class="headercrumb">
<li class="static" translate>ASSIGN.STOCK_ASSIGN</li>
<li class="title" translate>FORM.LABELS.CREATE</li>
</ol>
<div style="display: inline-block">
<ol class="headercrumb">
<li class="static" translate>ASSIGN.STOCK_ASSIGN</li>
<li class="title" translate>FORM.LABELS.CREATE</li>
</ol>
</div>
<div style="display: inline-block; float: right; margin-right: 10px;">
<a href class="btn btn-success"
ng-click="$ctrl.assignByBarcode()">
<span class="fa fa-plus"></span> <span class="hidden-xs" translate>BARCODE</span>
</a>
</div>
</div>

<div class="modal-body" ng-if="$ctrl.loading">
Expand Down
39 changes: 34 additions & 5 deletions client/src/modules/assets/modals/assign.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ angular.module('bhima.controllers')

// dependencies injections
AssetAssignmentModalController.$inject = [
'appcache', '$state', 'data',
'DepotService', 'NotifyService', '$uibModalInstance',
'StockService', 'util', 'ReceiptModal',
'appcache', '$state', 'data', '$uibModalInstance', 'ModalService',
'BarcodeService', 'NotifyService', 'ReceiptModal', 'StockService', 'util',
];

function AssetAssignmentModalController(AppCache, $state, data, Depots, Notify, Modal, Stock, Util, Receipts) {
function AssetAssignmentModalController(
AppCache, $state, data, Modal, ModalService,
Barcode, Notify, Receipts, Stock, Util) {
const vm = this;
const cache = AppCache('stock-assign-grid');
const cache = AppCache('stock-assign-modal');

// global variables
vm.model = {
Expand Down Expand Up @@ -76,6 +77,34 @@ function AssetAssignmentModalController(AppCache, $state, data, Depots, Notify,
}
}

vm.assignByBarcode = function assignByBarcode() {
Barcode.modal({ shouldSearch : false, title : 'ASSET.SCAN_ASSET_BARCODE' })
.then(record => {
Stock.lots.read(null, { barcode : record.uuid })
.then(lots => {
if (lots.length > 0) {
const lot = lots[0];
vm.model.depot_uuid = lot.depot_uuid;
loadAvailableInventories(lot.depot_uuid)
.then(() => {
const lotFound = vm.availableInventories.find(elt => elt.uuid === lot.uuid);
if (lotFound) {
vm.selectedInventory = lotFound;
vm.inventory_uuid = lot.inventory_uuid;
onSelectInventory(vm.selectedInventory);
vm.model.lot_uuid = lot.uuid;
onSelectLot(lot);
} else {
// If the lot has already been assigned, warn the user that
// it must be unassigned first.
ModalService.alert('ASSET.WARN_ALREADY_ASSIGNED');
}
});
}
});
});
};

vm.onSelectEntity = onSelectEntity;
function onSelectEntity(entity) {
vm.model.entity_uuid = entity.uuid;
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/templates/modals/alert.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- translateable prompt -->
<p class="text-left">
<span class="glyphicon glyphicon-alert text-warning"></span>
<span translate>{{ AlertModalCtrl.prompt }}</span>
<span translate style="margin-left: 0.5em"> {{ AlertModalCtrl.prompt }} </span>
</p>
</div>

Expand Down

0 comments on commit 55ad27f

Please sign in to comment.