From 19e7472597e4e4d36775b6448fa53a5f77068c02 Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Wed, 29 Jan 2020 08:16:11 +0100 Subject: [PATCH] chore(bhFindInvoice): allow external invoice uuids 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. --- client/src/i18n/en/barcode.json | 1 - client/src/i18n/fr/barcode.json | 1 - client/src/js/components/bhFindInvoice.js | 78 +++++++++++++++---- client/src/js/components/bhLoadingButton.js | 12 +-- .../invoices/patientInvoice.service.js | 13 ++-- .../stock/exit/modals/findPatient.modal.html | 9 +-- .../stock/exit/modals/findPatient.modal.js | 9 ++- .../modules/templates/bhFindInvoice.tmpl.html | 9 ++- 8 files changed, 88 insertions(+), 44 deletions(-) diff --git a/client/src/i18n/en/barcode.json b/client/src/i18n/en/barcode.json index 35e1216a37..45904416c0 100644 --- a/client/src/i18n/en/barcode.json +++ b/client/src/i18n/en/barcode.json @@ -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 {{reference}}.", "RESET_BUTTON" : "Read Barcode" } } diff --git a/client/src/i18n/fr/barcode.json b/client/src/i18n/fr/barcode.json index 286e261754..89d9af9d95 100644 --- a/client/src/i18n/fr/barcode.json +++ b/client/src/i18n/fr/barcode.json @@ -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 {{reference}}.", "RESET_BUTTON" : "Lire le code à barres" } } diff --git a/client/src/js/components/bhFindInvoice.js b/client/src/js/components/bhFindInvoice.js index 52a45eeffa..68f2ac6c4c 100644 --- a/client/src/js/components/bhFindInvoice.js +++ b/client/src/js/components/bhFindInvoice.js @@ -4,8 +4,9 @@ angular.module('bhima.components') templateUrl : 'modules/templates/bhFindInvoice.tmpl.html', bindings : { patientUuid : ' { + if (!invoice.details) { - vm.invoiceFound = false; + $ctrl.invoiceFound = false; return; } + // trigger form validation for the invoice search input form.$setSubmitted(); @@ -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 @@ -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(); @@ -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(); } } diff --git a/client/src/js/components/bhLoadingButton.js b/client/src/js/components/bhLoadingButton.js index 531877266b..30026bc2c1 100644 --- a/client/src/js/components/bhLoadingButton.js +++ b/client/src/js/components/bhLoadingButton.js @@ -2,15 +2,15 @@ angular.module('bhima.components') .component('bhLoadingButton', { transclude : true, template : - '', + ``.trim(), controller : LoadingButtonController, bindings : { loadingState : '<', - buttonClass : '@', - disabled : '<', + buttonClass : '@?', + disabled : ' @@ -45,12 +46,6 @@ BARCODE.SCAN - -

- - BARCODE.FOUND_RECORD - -

@@ -59,7 +54,7 @@ FORM.BUTTONS.CLOSE - + FORM.BUTTONS.SUBMIT diff --git a/client/src/modules/stock/exit/modals/findPatient.modal.js b/client/src/modules/stock/exit/modals/findPatient.modal.js index 5b02508430..0c00e7c284 100644 --- a/client/src/modules/stock/exit/modals/findPatient.modal.js +++ b/client/src/modules/stock/exit/modals/findPatient.modal.js @@ -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); } @@ -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); } diff --git a/client/src/modules/templates/bhFindInvoice.tmpl.html b/client/src/modules/templates/bhFindInvoice.tmpl.html index 5a105d7530..81294e4c6d 100644 --- a/client/src/modules/templates/bhFindInvoice.tmpl.html +++ b/client/src/modules/templates/bhFindInvoice.tmpl.html @@ -22,21 +22,22 @@ +

-
- {{ $ctrl.invoiceDescription }} +
+ {{$ctrl.invoice.details.reference}} {{ $ctrl.invoiceDescription }}
  • {{ item }}