Skip to content

Commit

Permalink
chore(bhFindInvoice): allow external invoice uuids
Browse files Browse the repository at this point in the history
Enhances the bhFindInvoice component to allow an external invoice uuid
to set the internal invoice.  This enhancement allows us to scan
external barcodes and use the component to display the result of that
scan.

Closes #3949.
  • Loading branch information
jniles committed Jan 29, 2020
1 parent 85573e3 commit bd387ad
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 44 deletions.
1 change: 0 additions & 1 deletion client/src/i18n/en/barcode.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"READ_ERROR" : "An error occurred during lookup. Please use another method to find the record.",
"NOT_FOUND" : "Cannot find a record with that code. Please search for the document manually.",
"LOST_FOCUS" : "The barcode input has lost focus. Please click \"Read Barcode\" to ready the barcode component.",
"FOUND_RECORD" : "Found a record with reference <u>{{reference}}</u>.",
"RESET_BUTTON" : "Read Barcode"
}
}
1 change: 0 additions & 1 deletion client/src/i18n/fr/barcode.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"READ_ERROR" : "Une erreur est survenue pendant la lecture du Code-barres. Veuillez utiliser une autre méthode pour trouver l'enregistrement",
"NOT_FOUND" : "Enregistrement non trouvé.",
"LOST_FOCUS" : "L'entrée du code à barres a perdu le focus. Veuillez cliquer sur \"Lire le code à barres\" pour préparer le composant de code à barres.",
"FOUND_RECORD" : "Trouvé un document avec reference <u>{{reference}}</u>.",
"RESET_BUTTON" : "Lire le code à barres"
}
}
78 changes: 62 additions & 16 deletions client/src/js/components/bhFindInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ angular.module('bhima.components')
templateUrl : 'modules/templates/bhFindInvoice.tmpl.html',
bindings : {
patientUuid : '<?', // patient uuid - to restrict search to this patient
invoiceUuid : '<?', // if a uuid exists, pass it in here.
onSearchComplete : '&', // bind callback to call when data is available
disabled : '<', // bind disable behavior
disabled : '<?', // bind disable behavior
},
});

Expand All @@ -17,7 +18,7 @@ FindInvoiceComponent.$inject = [
* The Find Invoice Component
*/
function FindInvoiceComponent(PatientInvoice, Notify, $window) {
const vm = this;
const $ctrl = this;

/* @const the enter key keycode */
const ENTER_KEY = 13;
Expand All @@ -26,26 +27,43 @@ function FindInvoiceComponent(PatientInvoice, Notify, $window) {
name : '',
};

vm.$onInit = function onInit() {
vm.disabled = vm.disabled || false;
$ctrl.$onInit = function onInit() {
$ctrl.disabled = $ctrl.disabled || false;
};

$ctrl.$onChanges = function $onChanges(changes) {
if (changes && changes.invoiceUuid && changes.invoiceUuid.currentValue) {
lookupInvoiceByUuid(changes.invoiceUuid.currentValue);
}
};

/* Expose functions and variables to the template view */
vm.search = search;
vm.onKeyPress = onKeyPress;
vm.translate = translate;
$ctrl.search = search;
$ctrl.onKeyPress = onKeyPress;
$ctrl.translate = translate;

/**
* @method search
*
* @description
* Fired when the user uses the search form to look up an invoice via its
* reference.
*/
function search(form) {
PatientInvoice.findConsumableInvoicePatient(vm.invoiceReference, vm.patientUuid)
const parameters = {
invoiceReference : $ctrl.invoiceReference,
patientUuid : $ctrl.patientUuid,
};

PatientInvoice.findConsumableInvoicePatient(parameters)
.then(invoice => {

if (!invoice.details) {
vm.invoiceFound = false;
$ctrl.invoiceFound = false;
return;
}


// trigger form validation for the invoice search input
form.$setSubmitted();

Expand All @@ -55,6 +73,34 @@ function FindInvoiceComponent(PatientInvoice, Notify, $window) {
.catch(Notify.handleError);
}

/**
* @method lookupInvoiceByUuid
*
* @description
* Fired when an invoiceUuid is passed in from outside of the component.
*/
function lookupInvoiceByUuid(invoiceUuid) {
const parameters = { invoiceUuid };
if ($ctrl.patientUuid) {
parameters.patientUuid = $ctrl.patientUuid;
}

PatientInvoice.findConsumableInvoicePatient(parameters)
.then(invoice => {

if (!invoice.details) {
$ctrl.invoiceFound = false;
return;
}

$ctrl.invoiceReference = invoice.details.reference;

// select invoice and fetch articles and services in the invoice
selectInvoice(invoice);
})
.catch(Notify.handleError);
}


/**
* @method selectInvoice
Expand All @@ -66,18 +112,18 @@ function FindInvoiceComponent(PatientInvoice, Notify, $window) {
* values, and calls the callback.
*/
function selectInvoice(invoice) {
vm.invoiceFound = true;
$ctrl.invoiceFound = true;

const elementId = 'search-button';
const searchButton = $window.document.getElementById(elementId);

if (invoice && typeof (invoice) === 'object') {
vm.translate.name = invoice.details.debtor_name;
vm.invoiceDescription = invoice.details.description;
vm.invoiceItems = invoice.items.map(item => `${item.text}: ${item.quantity} ${item.inventory_unit}`);
if (invoice && angular.isObject(invoice)) {
$ctrl.translate.name = invoice.details.debtor_name;
$ctrl.invoiceDescription = invoice.details.description;
$ctrl.invoiceItems = invoice.items.map(item => `${item.text}: ${item.quantity} ${item.inventory_unit}`);

// call the external function with patient
vm.onSearchComplete({ invoice });
$ctrl.onSearchComplete({ invoice });

// set focus on the search button after a search
searchButton.focus();
Expand All @@ -97,7 +143,7 @@ function FindInvoiceComponent(PatientInvoice, Notify, $window) {

// submit the find-invoice form
if (event.keyCode === ENTER_KEY) {
vm.search(form);
$ctrl.search(form);
event.preventDefault();
}
}
Expand Down
18 changes: 12 additions & 6 deletions client/src/js/components/bhLoadingButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ angular.module('bhima.components')
.component('bhLoadingButton', {
transclude : true,
template :
'<button type="submit" class="btn" ng-class="$ctrl.buttonClass" ng-disabled="$ctrl.loadingState || $ctrl.disabled" data-method="submit">'
+ '<span ng-show="$ctrl.loadingState"><span class="fa fa-circle-o-notch fa-spin"></span> <span translate>FORM.INFO.LOADING</span></span>'
+ '<span ng-hide="$ctrl.loadingState" ng-transclude><span translate>FORM.BUTTONS.SUBMIT</span></span>'
+ '</button>',
`<button type="submit"
class="btn"
ng-class="$ctrl.buttonClass"
ng-disabled="$ctrl.loadingState || $ctrl.disabled"
data-method="submit">
<span ng-show="$ctrl.loadingState">
<span class="fa fa-circle-o-notch fa-spin"></span> <span translate>FORM.INFO.LOADING</span>
</span>
<span ng-hide="$ctrl.loadingState" ng-transclude><span translate>FORM.BUTTONS.SUBMIT</span></span>
</button>`.trim(),
controller : LoadingButtonController,
bindings : {
loadingState : '<',
buttonClass : '@',
disabled : '<',
buttonClass : '@?',
disabled : '<?',
},
});

Expand Down
13 changes: 7 additions & 6 deletions client/src/modules/invoices/patientInvoice.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PatientInvoiceService.$inject = [
*/
function PatientInvoiceService(
Modal, Session, Api, Filters, AppCache, Periods, $httpParamSerializer,
Languages, bhConstants, Transactions, $translate
Languages, bhConstants, Transactions, $translate,
) {
const service = new Api('/invoices/');

Expand Down Expand Up @@ -193,12 +193,13 @@ function PatientInvoiceService(
};

/**
* find an invoice with its consumable inventories for a given patient
* @function findConsumableInvoicePatient
*
* @description
* Find an invoice with its consumable inventories for a given patient
*/
function findConsumableInvoicePatient(invoiceReference, patientUuid) {
const params = { invoiceReference, patientUuid };
const url = '/invoices/consumable/';
return this.$http.get(url, { params })
function findConsumableInvoicePatient(params = {}) {
return this.$http.get('/invoices/consumable/', { params })
.then(this.util.unwrapHttpResponse);
}

Expand Down
9 changes: 2 additions & 7 deletions client/src/modules/stock/exit/modals/findPatient.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<div ng-if="$ctrl.joinInvoice">
<bh-find-invoice
patient-uuid="$ctrl.selected.uuid"
invoice-uuid="$ctrl.scannedInvoice.uuid"
on-search-complete="$ctrl.setInvoice(invoice)"
disabled="!$ctrl.selected.uuid">
</bh-find-invoice>
Expand All @@ -45,12 +46,6 @@
<a href="" ng-click="$ctrl.openBarcodeScanner()">
<i class="fa fa-barcode"></i> <span translate>BARCODE.SCAN</span>
</a>

<p ng-if="$ctrl.i18nValues" class="text-success">
<span translate translate-values="$ctrl.i18nValues" translate-sanitize-strategy="'sce'">
BARCODE.FOUND_RECORD
</span>
</p>
</div>
</div>

Expand All @@ -59,7 +54,7 @@
FORM.BUTTONS.CLOSE
</button>

<bh-loading-button loading-state="FindForm.$loading" disabled="$ctrl.joinInvoice && !$ctrl.selected.invoice.details.uuid">
<bh-loading-button loading-state="FindForm.$loading">
<span translate>FORM.BUTTONS.SUBMIT</span>
</bh-loading-button>
</div>
Expand Down
9 changes: 6 additions & 3 deletions client/src/modules/stock/exit/modals/findPatient.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ function StockFindPatientModalController(Instance, Patients, Notify, Data, AppCa
}

function setInvoice(invoice) {
vm.selected.invoice = invoice;
vm.invoice = invoice;
}

// submit
function submit() {
vm.selected.invoice = vm.invoice;
Instance.close(vm.selected);
}

Expand All @@ -76,9 +77,11 @@ function StockFindPatientModalController(Instance, Patients, Notify, Data, AppCa
})
.then(patient => {
setPatient(patient);
setInvoice(invoice);

vm.i18nValues = { reference : invoice.reference };
// we need to wait for the bh-find-invoice component to call the setInvoice()
// since the invoice details have to be formatted in a particular way.
vm.joinInvoice = 1;
vm.scannedInvoice = invoice;
})
.catch(angular.noop);
}
Expand Down
9 changes: 5 additions & 4 deletions client/src/modules/templates/bhFindInvoice.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
</button>
</span>
</div>

<p
ng-if="!$ctrl.invoiceFound && FindInvoiceForm.$submitted"
ng-if="$ctrl.invoiceFound === false"
class="help-block"
translate="FORM.INFO.PATIENT_INVOICE_NOT_FOUND"
translate-values="{{ $ctrl.translate }}">
</p>
<p
ng-if="$ctrl.invoiceFound && FindInvoiceForm.$submitted"
ng-if="$ctrl.invoiceFound === true"
class="help-block"
translate="FORM.INFO.PATIENT_INVOICE_FOUND">
</p>
</div>

<div ng-if="$ctrl.invoiceFound && FindInvoiceForm.$submitted" class="alert alert-success">
{{ $ctrl.invoiceDescription }}
<div ng-if="$ctrl.invoiceFound === true && $ctrl.invoiceItems" class="alert alert-success">
<b>{{$ctrl.invoice.details.reference}}</b> {{ $ctrl.invoiceDescription }}
<ul>
<li ng-repeat="item in $ctrl.invoiceItems track by $index">{{ item }}</li>
</ul>
Expand Down

0 comments on commit bd387ad

Please sign in to comment.