-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(barcodes): implement barcode scanning modal
This commit implements the barcode scanning modal for the cash payments page. This commit only adds the rough HTML and JS outline - it is a work in progress.
- Loading branch information
Showing
7 changed files
with
191 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
angular.module('bhima.services') | ||
.service('BarcodeService', BarcodeService); | ||
|
||
BarcodeService.$inject = [ '$http', 'util' ]; | ||
|
||
function BarcodeService($http, util) { | ||
var service = this; | ||
|
||
// TODO - barcode redirection | ||
service.redirect = angular.noop; | ||
|
||
service.search = function search(code) { | ||
return $http.get('/barcode/'.concat(code)) | ||
.then(util.unwrapHTTPResponse); | ||
}; | ||
|
||
return service; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<form name="BarcodeForm" bh-form-defaults novalidate style="min-height:400px;"> | ||
|
||
<div class="modal-header"> | ||
<ol class="headercrumb"> | ||
<li class="static">{{ ::CashBarCtrl.cashbox.label }}</li> | ||
<li class="title" translate>CASH.BARCODE.TITLE</li> | ||
</ol> | ||
</div> | ||
|
||
<div class="modal-body text-center"> | ||
|
||
<!-- state: awaiting barcode input --> | ||
<h1 class="text-muted"> | ||
Scan Barcode <br /> | ||
<i class="fa fa-barcode fa-3x"></i> | ||
</h1> | ||
|
||
<p> | ||
<span class="text-muted" ng-if="vm.step === vm.INITIALIZED"> | ||
<span>Waiting for Input</span> | ||
</span> | ||
|
||
<span class="text-primary" ng-if="vm.step === vm.LOADING"> | ||
<i class="fa fa-info-circle"></i> | ||
<span>Barcode Read! Looking up the Invoice ...</span> | ||
</span> | ||
|
||
<span class="text-success" ng-if="vm.step === vm.READ_SUCCESS"> | ||
<i class="fa fa-check-circle-o"></i> Found Invoice IV.HEV.12! | ||
</span> | ||
|
||
<span class="text-danger" ng-if="vm.step === vm.READ_ERROR"> | ||
<i class="fa fa-danger-sign"></i> Unreadable Barcode! Please enter the barcode manually. | ||
</span> | ||
</p> | ||
|
||
<!-- state: gathering required information --> | ||
<h1 hidden> | ||
<i class="fa fa-barcode"></i> Scanned Invoice Barcode! | ||
<br /> | ||
<small>Gathering required information...</small> | ||
</h1> | ||
|
||
<!-- hidden barcode input --> | ||
<input ng-model="CashBarCtrl.barcode" ng-change="CashBarCtrl.triggerBarcodeRead()" hidden autofocus> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
angular.module('bhima.controllers') | ||
.controller('CashBarcodeScannerModalController', CashBarController); | ||
|
||
CashBarController.$inject = [ | ||
'$state', 'CashboxService', 'NotifyService', 'BarcodeService', 'PatientService' | ||
]; | ||
|
||
/** | ||
* @module cash/modals/CashBarController | ||
* | ||
* @description | ||
* This controller is responsible for scanning barcodes and then configuring the CashForm with the barcode | ||
*/ | ||
function CashBarController($state, Cashboxes, Notify, Barcodes, Patients) { | ||
var vm = this; | ||
var id = $state.params.id; | ||
|
||
vm.triggerBarcodeRead = triggerBarcodeRead; | ||
|
||
vm.loading = true; | ||
|
||
vm.INITIALIZED = 'initialized'; | ||
vm.LOADING = 'loading'; | ||
vm.READ_ERROR = 'read-error'; | ||
vm.READ_SUCCESS = 'found'; | ||
|
||
// the first step is initialized | ||
vm.step = vm.INITILIZED; | ||
|
||
// determine if the input was a valid barcode | ||
function isValidBarcode(input) { | ||
return false; | ||
} | ||
|
||
function triggerBarcodeRead() { | ||
|
||
console.log('TriggerBarcodeRead with:', vm.barcode); | ||
|
||
if (!isValidBarcode(vm.barcode)) { | ||
vm.step = vm.READ_ERROR; | ||
} else { | ||
searchForBarcode(vm.barcode); | ||
} | ||
} | ||
|
||
// send an HTTP request based on the barcode to get the invoice in question, | ||
// then load the patient information in the background | ||
function searchForBarcode(barcode) { | ||
|
||
// set the loading step | ||
vm.step = vm.LOADING; | ||
|
||
Barcodes.search(barcode) | ||
.then(function (invoice) { | ||
vm.invoice = invoice; | ||
return Patients.search({ debtor_uuid : invoice.debtor_uuid }); | ||
}).then(function (patients) { | ||
|
||
// destructure search array | ||
var patient = patients[0]; | ||
|
||
vm.patient = patient; | ||
|
||
// signal | ||
vm.step = vm.READ_SUCCESS; | ||
}) | ||
.catch(function (error) { | ||
vm.step = vm.READ_ERROR; | ||
}); | ||
} | ||
|
||
// fired on state startup | ||
function startup() { | ||
|
||
Cashboxes.read(id) | ||
.then(function (cashbox) { | ||
vm.cashbox = cashbox; | ||
}) | ||
.catch(Notify.handleError); | ||
} | ||
|
||
startup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters