diff --git a/app/Http/Requests/Setting/Currency.php b/app/Http/Requests/Setting/Currency.php index 0b8a74a82..7bcffbf22 100644 --- a/app/Http/Requests/Setting/Currency.php +++ b/app/Http/Requests/Setting/Currency.php @@ -29,8 +29,9 @@ class Currency extends FormRequest 'rate' => 'required|gt:0', 'enabled' => 'integer|boolean', 'default_currency' => 'nullable|boolean', + 'decimal_mark' => 'required|string|different:thousands_separator|regex:/^[A-Za-z.,_-\s-]+$/', 'symbol_first' => 'nullable|boolean', - 'thousands_separator' => 'different:decimal_mark', + 'thousands_separator' => 'different:decimal_mark|regex:/^[A-Za-z.,_-`\s-]+$/', ]; } } diff --git a/app/Models/Setting/Currency.php b/app/Models/Setting/Currency.php index 1ddac30e3..04fb33f7f 100644 --- a/app/Models/Setting/Currency.php +++ b/app/Models/Setting/Currency.php @@ -102,6 +102,16 @@ class Currency extends Model return $this->contacts()->whereIn('contacts.type', (array) $this->getVendorTypes()); } + /** + * Get the default currency. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function default() + { + return $this->code(default_currency())->first(); + } + /** * Scope currency by code. * diff --git a/resources/assets/js/views/settings/currencies.js b/resources/assets/js/views/settings/currencies.js index 52e2633ee..71048cb70 100644 --- a/resources/assets/js/views/settings/currencies.js +++ b/resources/assets/js/views/settings/currencies.js @@ -38,6 +38,10 @@ const app = new Vue({ }, onChangeCode(code) { + if (! code) { + return; + } + axios.get(url + '/settings/currencies/config', { params: { code: code @@ -62,5 +66,23 @@ const app = new Vue({ this.form.rate = 1; } }, + 'form.decimal_mark': function (newVal, oldVal) { + const regex = /^[A-Za-z.,_-\s-]+$/; + + if (newVal && ! regex.test(newVal)) { + newVal = newVal.replace(/[^A-Za-z.,_-\s-]+/g, "."); + } + + this.form.decimal_mark = newVal; + }, + 'form.thousands_separator': function (newVal, oldVal) { + const regex = /^[A-Za-z.,_-\s-]+$/; + + if (newVal && ! regex.test(newVal)) { + newVal = newVal.replace(/[^A-Za-z.,_-\s-]+/g, ","); + } + + this.form.thousands_separator = newVal; + }, } });