From 2d29a83e1e6b0317b15f2834679ce90acb504f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Fri, 28 Mar 2025 11:08:25 +0300 Subject: [PATCH] create new currency decimal and thousands field control --- app/Http/Requests/Setting/Currency.php | 3 ++- app/Models/Setting/Currency.php | 10 +++++++++ .../assets/js/views/settings/currencies.js | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) 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; + }, } });