diff --git a/client/src/js/components/bhReceiptCurrency.js b/client/src/js/components/bhReceiptCurrency.js new file mode 100644 index 0000000000..c95bc8a96a --- /dev/null +++ b/client/src/js/components/bhReceiptCurrency.js @@ -0,0 +1,48 @@ +angular.module('bhima.components').component('bhReceiptCurrency', { + templateUrl : 'partials/templates/bhReceiptCurrency.tmpl.html', + controller : ReceiptCurrencyController, + bindings : { + onUpdate : '&' + } +}); + +ReceiptCurrencyController.$inject = ['CurrencyService', 'SessionService', 'AppCache', 'Store']; + +/** + * Receipt Currency Component + * + */ +function ReceiptCurrencyController(Currencies, Session, AppCache, Store) { + var ctrl = this; + var cache = new AppCache('ReceiptCurrencyComponent'); + + Currencies.read() + .then(function (currencies) { + ctrl.currencies = new Store(); + ctrl.currencies.setData(currencies); + loadDefaultCurrency(); + }); + + ctrl.update = function (currency) { + // update view with currency object (id and symbol) + ctrl.selectedCurrency = currency; + + // update cache with id to select this currency object on next load + cache.selectedCurrencyId = currency.id; + + // update bindings + ctrl.onUpdate({ currencyId : currency.id }); + }; + + function loadDefaultCurrency() { + // if the cache exists - use that + var cached = cache.selectedCurrencyId; + if (cached) { + ctrl.update(ctrl.currencies.get(cached)); + return; + } + + // no cached value - use the enterprise currency + ctrl.update(ctrl.currencies.get(Session.enterprise.currency_id)); + } +} diff --git a/client/src/partials/patient_invoice/registry/registry.html b/client/src/partials/patient_invoice/registry/registry.html index bc09b89419..5f5a8c8479 100644 --- a/client/src/partials/patient_invoice/registry/registry.html +++ b/client/src/partials/patient_invoice/registry/registry.html @@ -23,15 +23,8 @@
-
- - - -
+
diff --git a/client/src/partials/patient_invoice/registry/registry.js b/client/src/partials/patient_invoice/registry/registry.js index ee98d3f69d..cb8e889dee 100644 --- a/client/src/partials/patient_invoice/registry/registry.js +++ b/client/src/partials/patient_invoice/registry/registry.js @@ -4,7 +4,7 @@ angular.module('bhima.controllers') InvoiceRegistryController.$inject = [ 'PatientInvoiceService', 'bhConstants', 'NotifyService', 'SessionService', 'util', 'ReceiptModal', 'appcache', - 'uiGridConstants', 'CurrencyService' + 'uiGridConstants' ]; /** @@ -12,14 +12,13 @@ InvoiceRegistryController.$inject = [ * * This module is responsible for the management of Invoice Registry. */ -function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util, Receipt, AppCache, uiGridConstants, Currencies) { +function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util, Receipt, AppCache, uiGridConstants) { var vm = this; var cache = AppCache('InvoiceRegistry'); vm.search = search; vm.openReceiptModal = Receipt.invoice; - vm.setCurrency = setCurrency; vm.onRemoveFilter = onRemoveFilter; vm.clearFilters = clearFilters; vm.creditNote = creditNote; @@ -57,22 +56,13 @@ function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util, enableSorting : true, rowTemplate : '/partials/patient_invoice/templates/grid.creditNote.tmpl.html' }; + vm.receiptOptions = {}; - // receipt options - vm.selectedCurrency = { - id : vm.enterprise.currency_id, - symbol : vm.enterprise.currencySymbol + // receiptOptions are used in the bh-print directive under the receipt-action template + vm.setReceiptCurrency = function setReceiptCurrency(currencyId) { + vm.receiptOptions.currency = currencyId; }; - vm.receiptOptions = { - currency : vm.selectedCurrency.id - }; - - function setCurrency(currency) { - vm.selectedCurrency = currency; - vm.receiptOptions.currency = vm.selectedCurrency.id; - } - function handler(error) { vm.hasError = true; Notify.handleError(error); @@ -82,11 +72,6 @@ function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util, vm.loading = !vm.loading; } - Currencies.read() - .then(function (currencies) { - vm.currencies = currencies; - }); - // this function loads invoices from the database with search parameters // if passed in. function load(parameters) { diff --git a/client/src/partials/templates/bhReceiptCurrency.tmpl.html b/client/src/partials/templates/bhReceiptCurrency.tmpl.html new file mode 100644 index 0000000000..12b5773cfc --- /dev/null +++ b/client/src/partials/templates/bhReceiptCurrency.tmpl.html @@ -0,0 +1,11 @@ +
+ + + +