Merge pull request #3278 from CihanSenturk/fix-create-new-currency-decimal-and-thousands-field-control

Create new currency decimal and thousands field control
This commit is contained in:
Cihan Şentürk 2025-03-28 11:09:54 +03:00 committed by GitHub
commit 19adb56f52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 1 deletions

View File

@ -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-]+$/',
];
}
}

View File

@ -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.
*

View File

@ -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;
},
}
});