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 : '', // 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 }, }); @@ -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; @@ -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(); @@ -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 : '', }, }); diff --git a/client/src/modules/invoices/patientInvoice.service.js b/client/src/modules/invoices/patientInvoice.service.js index e045ca755e..ca281797e6 100644 --- a/client/src/modules/invoices/patientInvoice.service.js +++ b/client/src/modules/invoices/patientInvoice.service.js @@ -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/'); @@ -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); } diff --git a/client/src/modules/stock/exit/modals/findPatient.modal.html b/client/src/modules/stock/exit/modals/findPatient.modal.html index 119dae9af2..23a63c581b 100644 --- a/client/src/modules/stock/exit/modals/findPatient.modal.html +++ b/client/src/modules/stock/exit/modals/findPatient.modal.html @@ -35,6 +35,7 @@
@@ -59,7 +54,7 @@ FORM.BUTTONS.CLOSE -
-