diff --git a/resources/assets/js/views/common/companies.js b/resources/assets/js/views/common/companies.js index c43366979..d7d831cc6 100644 --- a/resources/assets/js/views/common/companies.js +++ b/resources/assets/js/views/common/companies.js @@ -47,5 +47,41 @@ const app = new Vue({ this.form.submit(); }, + + // Change currency get money + onChangeCurrency(currency_code) { + if (! currency_code) { + return; + } + + if (! this.all_currencies.length) { + let currency_promise = Promise.resolve(window.axios.get((url + '/settings/currencies'))); + + currency_promise.then(response => { + if (response.data.success) { + this.all_currencies = response.data.data; + } + + this.all_currencies.forEach(function (currency, index) { + if (currency_code == currency.code) { + this.currency = currency; + + this.form.currency = currency.code; + } + }, this); + }) + .catch(error => { + this.onChangeCurrency(currency_code); + }); + } else { + this.all_currencies.forEach(function (currency, index) { + if (currency_code == currency.code) { + this.currency = currency; + + this.form.currency = currency.code; + } + }, this); + } + }, } }); diff --git a/resources/assets/js/views/settings/settings.js b/resources/assets/js/views/settings/settings.js index afbea3a8b..ba3ee7e75 100644 --- a/resources/assets/js/views/settings/settings.js +++ b/resources/assets/js/views/settings/settings.js @@ -159,6 +159,42 @@ const app = new Vue({ } else { this.quantity_name_input = false; } - } + }, + + // Change currency get money + onChangeCurrency(currency_code) { + if (! currency_code) { + return; + } + + if (! this.all_currencies.length) { + let currency_promise = Promise.resolve(window.axios.get((url + '/settings/currencies'))); + + currency_promise.then(response => { + if (response.data.success) { + this.all_currencies = response.data.data; + } + + this.all_currencies.forEach(function (currency, index) { + if (currency_code == currency.code) { + this.currency = currency; + + this.form.currency = currency.code; + } + }, this); + }) + .catch(error => { + this.onChangeCurrency(currency_code); + }); + } else { + this.all_currencies.forEach(function (currency, index) { + if (currency_code == currency.code) { + this.currency = currency; + + this.form.currency = currency.code; + } + }, this); + } + }, } });