diff --git a/application/Espo/Resources/i18n/en_US/Admin.json b/application/Espo/Resources/i18n/en_US/Admin.json index 93e8161d0e..2e0e205d9a 100644 --- a/application/Espo/Resources/i18n/en_US/Admin.json +++ b/application/Espo/Resources/i18n/en_US/Admin.json @@ -29,7 +29,8 @@ "Field Manager": "Field Manager", "User Interface": "User Interface", "Auth Tokens": "Auth Tokens", - "Authentication": "Authentication" + "Authentication": "Authentication", + "Currency": "Currency" }, "layouts": { "list": "List", @@ -113,7 +114,8 @@ "fieldManager": "Create new fields or customize existing ones.", "userInterface": "Configure UI.", "authTokens": "Active auth sessions. IP address and last access date.", - "authentication": "Authentication settings." + "authentication": "Authentication settings.", + "currency": "Currency settings and rates." }, "options": { "previewSize": { diff --git a/application/Espo/Resources/i18n/en_US/Settings.json b/application/Espo/Resources/i18n/en_US/Settings.json index 51ce8dc499..06e46b6033 100644 --- a/application/Espo/Resources/i18n/en_US/Settings.json +++ b/application/Espo/Resources/i18n/en_US/Settings.json @@ -8,6 +8,10 @@ "thousandSeparator": "Thousand Separator", "decimalMark": "Decimal Mark", "defaultCurrency": "Default Currency", + "baseCurrency": "Base Currency", + "baseCurrency": "Base Currency", + "currencyRates": "Rate Values", + "currencyList": "Currency List", "language": "Language", @@ -62,6 +66,8 @@ "Locale": "Locale", "SMTP": "SMTP", "Configuration": "Configuration", - "Notifications": "Notifications" + "Notifications": "Notifications", + "Currency Settings": "Currency Settings", + "Currency Rtes": "Currency Rates" } } diff --git a/application/Espo/Resources/layouts/Settings/currency.json b/application/Espo/Resources/layouts/Settings/currency.json new file mode 100644 index 0000000000..660208efa9 --- /dev/null +++ b/application/Espo/Resources/layouts/Settings/currency.json @@ -0,0 +1,15 @@ +[ + { + "label": "Currency Settings", + "rows": [ + [{"name": "defaultCurrency"}, {"name": "currencyList"}] + ] + }, + { + "label": "Currency Rates", + "rows": [ + [{"name": "baseCurrency"}], + [{"name": "currencyRates"}] + ] + } +] diff --git a/application/Espo/Resources/layouts/Settings/settings.json b/application/Espo/Resources/layouts/Settings/settings.json index 236e2c6bd0..126b994740 100644 --- a/application/Espo/Resources/layouts/Settings/settings.json +++ b/application/Espo/Resources/layouts/Settings/settings.json @@ -12,7 +12,6 @@ [{"name": "dateFormat"}, {"name": "timeZone"}], [{"name": "timeFormat"}, {"name": "weekStart"}], [{"name": "thousandSeparator"}, {"name": "decimalMark"}], - [{"name": "defaultCurrency"}, {"name": "currencyList"}], [{"name": "language"}] ] } diff --git a/application/Espo/Resources/metadata/app/adminPanel.json b/application/Espo/Resources/metadata/app/adminPanel.json index 620d308a27..678376f374 100644 --- a/application/Espo/Resources/metadata/app/adminPanel.json +++ b/application/Espo/Resources/metadata/app/adminPanel.json @@ -17,6 +17,11 @@ "label":"Scheduled Jobs", "description":"scheduledJob" }, + { + "url":"#Admin/currency", + "label":"Currency", + "description":"currency" + }, { "url":"#Admin/upgrade", "label":"Upgrade", diff --git a/application/Espo/Resources/metadata/entityDefs/Settings.json b/application/Espo/Resources/metadata/entityDefs/Settings.json index 61ec23f914..451d869c0a 100644 --- a/application/Espo/Resources/metadata/entityDefs/Settings.json +++ b/application/Espo/Resources/metadata/entityDefs/Settings.json @@ -61,6 +61,15 @@ "default": "USD", "required": true }, + "baseCurrency": { + "type": "enum", + "default": "USD", + "required": true + }, + "currencyRates": { + "type": "base", + "view": "Settings.Fields.CurrencyRates" + }, "outboundEmailIsShared": { "type": "bool", "default": false diff --git a/frontend/client/res/templates/admin/settings/header-currency.tpl b/frontend/client/res/templates/admin/settings/header-currency.tpl new file mode 100644 index 0000000000..80fbd5531e --- /dev/null +++ b/frontend/client/res/templates/admin/settings/header-currency.tpl @@ -0,0 +1 @@ +

{{translate 'Administration'}} » {{translate 'Currency' scope='Admin'}}

diff --git a/frontend/client/res/templates/settings/fields/currency-rates/edit.tpl b/frontend/client/res/templates/settings/fields/currency-rates/edit.tpl new file mode 100644 index 0000000000..ed5d04b387 --- /dev/null +++ b/frontend/client/res/templates/settings/fields/currency-rates/edit.tpl @@ -0,0 +1,6 @@ +{{#each rateValues}} +
+ {{@key}} + +
+{{/each}} diff --git a/frontend/client/src/controllers/admin.js b/frontend/client/src/controllers/admin.js index 0c4b53114d..dbb6da7209 100644 --- a/frontend/client/src/controllers/admin.js +++ b/frontend/client/src/controllers/admin.js @@ -90,6 +90,22 @@ Espo.define('Controllers.Admin', 'Controller', function (Dep) { model.fetch(); }, + currency: function () { + var model = this.getSettingsModel(); + + model.once('sync', function () { + model.id = '1'; + this.main('Edit', { + model: model, + views: { + header: {template: 'admin.settings.header-currency'}, + body: {view: 'Admin.Currency'}, + }, + }); + }, this); + model.fetch(); + }, + authTokens: function () { this.collectionFactory.create('AuthToken', function (collection) { var searchManager = new Espo.SearchManager(collection, 'list', this.getStorage(), this.getDateTime()); diff --git a/frontend/client/src/models/settings.js b/frontend/client/src/models/settings.js index 35c2b79bbd..c2ebf2678b 100644 --- a/frontend/client/src/models/settings.js +++ b/frontend/client/src/models/settings.js @@ -27,6 +27,10 @@ Espo.define('Models.Settings', 'ModelOffline', function (Dep) { getDefaultCurrencyOptions: function () { return this.get('currencyList') || []; }, + + getBaseCurrencyOptions: function () { + return this.get('currencyList') || []; + }, }); diff --git a/frontend/client/src/views/admin/currency.js b/frontend/client/src/views/admin/currency.js new file mode 100644 index 0000000000..ba09af2a97 --- /dev/null +++ b/frontend/client/src/views/admin/currency.js @@ -0,0 +1,69 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: http://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://www.gnu.org/licenses/. + ************************************************************************/ + +Espo.define('Views.Admin.Currency', 'Views.Settings.Record.Edit', function (Dep) { + + return Dep.extend({ + + layoutName: 'currency', + + setup: function () { + Dep.prototype.setup.call(this); + }, + + afterRender: function () { + var currencyListField = this.getFieldView('currencyList'); + var defaultCurrencyField = this.getFieldView('defaultCurrency'); + var baseCurrencyField = this.getFieldView('baseCurrency'); + + var currencyRatesField = this.getFieldView('currencyRates'); + + if (currencyListField) { + this.listenTo(currencyListField, 'change', function () { + var data = currencyListField.fetch(); + var options = data.currencyList; + if (defaultCurrencyField) { + defaultCurrencyField.params.options = options; + defaultCurrencyField.render(); + } + if (baseCurrencyField) { + baseCurrencyField.params.options = options; + baseCurrencyField.render(); + } + if (currencyRatesField) { + currencyRatesField.render(); + } + }, this); + } + + if (baseCurrencyField) { + this.listenTo(baseCurrencyField, 'change', function () { + if (currencyRatesField) { + currencyRatesField.render(); + } + }, this); + } + }, + + }); + +}); + diff --git a/frontend/client/src/views/admin/settings.js b/frontend/client/src/views/admin/settings.js index f397bcf10a..90f6b2a04e 100644 --- a/frontend/client/src/views/admin/settings.js +++ b/frontend/client/src/views/admin/settings.js @@ -27,17 +27,7 @@ Espo.define('Views.Admin.Settings', 'Views.Settings.Record.Edit', function (Dep) afterRender: function () { Dep.prototype.afterRender.call(this); - - var currencyListField = this.getFieldView('currencyList'); - var defaultCurrencyField = this.getFieldView('defaultCurrency'); - if (currencyListField && defaultCurrencyField) { - this.listenTo(currencyListField, 'change', function () { - var data = currencyListField.fetch(); - var options = data.currencyList; - defaultCurrencyField.params.options = options; - defaultCurrencyField.render(); - }.bind(this)); - } + }, }); diff --git a/frontend/client/src/views/settings/fields/currency-rates.js b/frontend/client/src/views/settings/fields/currency-rates.js new file mode 100644 index 0000000000..6a23981394 --- /dev/null +++ b/frontend/client/src/views/settings/fields/currency-rates.js @@ -0,0 +1,65 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: http://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://www.gnu.org/licenses/. + ************************************************************************/ +Espo.define('Views.Settings.Fields.CurrencyRates', 'Views.Fields.Base', function (Dep) { + + return Dep.extend({ + + editTemplate: 'settings.fields.currency-rates.edit', + + data: function () { + var baseCurrency = this.model.get('baseCurrency'); + var currencyRates = this.model.get('currencyRates') || {}; + + var rateValues = {}; + this.model.get('currencyList').forEach(function (currency) { + if (currency != baseCurrency) { + rateValues[currency] = currencyRates[currency] || 1.00; + } + }, this); + + return { + rateValues: rateValues + }; + }, + + setup: function () { + }, + + fetch: function () { + var data = {}; + var currencyRates = {}; + + var baseCurrency = this.model.get('baseCurrency'); + + this.model.get('currencyList').forEach(function (currency) { + if (currency != baseCurrency) { + currencyRates[currency] = parseFloat(this.$el.find('input[data-currency="'+currency+'"]').val() || 1); + } + }, this); + + data[this.name] = currencyRates; + + return data; + }, + + }); + +});