zet-lib 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/zMenuRouter.js +2 -1
- package/lib/zRoute.js +47 -1
- package/package.json +1 -1
package/lib/zMenuRouter.js
CHANGED
|
@@ -53,12 +53,13 @@ router.get('/', async function (req, res, next) {
|
|
|
53
53
|
}
|
|
54
54
|
})
|
|
55
55
|
if(copyMenu){
|
|
56
|
-
copyMenu.json =
|
|
56
|
+
copyMenu.json = '[]';
|
|
57
57
|
copyMenu.updated_by = res.locals.userId;
|
|
58
58
|
copyMenu.created_by = res.locals.userId;
|
|
59
59
|
copyMenu.created_at = Util.now();
|
|
60
60
|
copyMenu.updated_at = Util.now();
|
|
61
61
|
copyMenu.company_id = companyId;
|
|
62
|
+
company.name = 'Default';
|
|
62
63
|
delete copyMenu.id;
|
|
63
64
|
await connection.insert({
|
|
64
65
|
table : "zmenu",
|
package/lib/zRoute.js
CHANGED
|
@@ -3766,7 +3766,9 @@ zRoute.viewForm = (
|
|
|
3766
3766
|
obj[key].value = data[key] ? Util.formatNumber(data[key], ".") : "";
|
|
3767
3767
|
break;
|
|
3768
3768
|
case "money":
|
|
3769
|
-
|
|
3769
|
+
// Set value in standard format (number with dot as decimal separator)
|
|
3770
|
+
// Let formatCurrency handle the formatting
|
|
3771
|
+
obj[key].value = data[key] ? `${widgets[key].symbol || ""} ${Util.formatNumber(data[key], widgets[key].thousandSeparator)}` : "";
|
|
3770
3772
|
break;
|
|
3771
3773
|
case "typeahead":
|
|
3772
3774
|
obj[key].type = "text";
|
|
@@ -4277,6 +4279,50 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4277
4279
|
if(moneys.length > 0) {
|
|
4278
4280
|
let moneyScript = ``
|
|
4279
4281
|
moneys.map((money) => {
|
|
4282
|
+
// Clean and normalize the value to standard format (number with dot as decimal separator)
|
|
4283
|
+
// This must be done BEFORE formatCurrency is called
|
|
4284
|
+
moneyScript += `var ${money}Val = $('#${money}').val();`
|
|
4285
|
+
moneyScript += `if(${money}Val) {`
|
|
4286
|
+
// Remove all non-numeric characters (symbols, spaces, etc)
|
|
4287
|
+
moneyScript += ` ${money}Val = ${money}Val.toString().replace(/[^0-9.,-]/g, '');`
|
|
4288
|
+
// Normalize to standard format based on thousand separator configuration
|
|
4289
|
+
moneyScript += ` if('${widgets[money].thousandSeparator || "."}' === '.') {`
|
|
4290
|
+
// Thousand separator is ".", so "," is decimal separator
|
|
4291
|
+
// If value has multiple dots or comma, it's already formatted - normalize it
|
|
4292
|
+
moneyScript += ` var dotCount = (${money}Val.match(/\\./g) || []).length;`
|
|
4293
|
+
moneyScript += ` var commaCount = (${money}Val.match(/,/g) || []).length;`
|
|
4294
|
+
moneyScript += ` if(dotCount > 1 || commaCount > 0) {`
|
|
4295
|
+
// Remove all dots (thousand separators) and replace comma with dot (decimal separator)
|
|
4296
|
+
moneyScript += ` ${money}Val = ${money}Val.replace(/\\./g, '').replace(',', '.');`
|
|
4297
|
+
moneyScript += ` }`
|
|
4298
|
+
// If dotCount === 1 and commaCount === 0, value is already in standard format, keep it
|
|
4299
|
+
moneyScript += ` } else {`
|
|
4300
|
+
// Thousand separator is ",", so "." is decimal separator
|
|
4301
|
+
moneyScript += ` var commaCount = (${money}Val.match(/,/g) || []).length;`
|
|
4302
|
+
moneyScript += ` if(commaCount > 1) {`
|
|
4303
|
+
// Multiple commas means formatted - remove all commas (thousand separators)
|
|
4304
|
+
moneyScript += ` ${money}Val = ${money}Val.replace(/,/g, '');`
|
|
4305
|
+
moneyScript += ` }`
|
|
4306
|
+
// If commaCount <= 1, value is already in standard format, keep it
|
|
4307
|
+
moneyScript += ` }`
|
|
4308
|
+
// Convert to number first to ensure we have a valid number, then back to string
|
|
4309
|
+
moneyScript += ` var ${money}Num = parseFloat(${money}Val);`
|
|
4310
|
+
moneyScript += ` if(!isNaN(${money}Num)) {`
|
|
4311
|
+
// Always use toFixed to ensure proper decimal format
|
|
4312
|
+
moneyScript += ` var ${money}Decimals = ${widgets[money].digitDecimal || 0};`
|
|
4313
|
+
moneyScript += ` ${money}Val = ${money}Num.toFixed(${money}Decimals);`
|
|
4314
|
+
// If thousand separator is ".", formatCurrency expects comma as decimal separator
|
|
4315
|
+
// So we need to replace dot with comma before formatCurrency processes it
|
|
4316
|
+
moneyScript += ` if('${widgets[money].thousandSeparator || "."}' === '.') {`
|
|
4317
|
+
moneyScript += ` ${money}Val = ${money}Val.replace('.', ',');`
|
|
4318
|
+
moneyScript += ` }`
|
|
4319
|
+
moneyScript += ` } else {`
|
|
4320
|
+
moneyScript += ` ${money}Val = '';`
|
|
4321
|
+
moneyScript += ` }`
|
|
4322
|
+
// Set the normalized value back to input
|
|
4323
|
+
moneyScript += ` $('#${money}').val(${money}Val);`
|
|
4324
|
+
moneyScript += `}`
|
|
4325
|
+
// Now formatCurrency will format the standard format value correctly
|
|
4280
4326
|
moneyScript += `$('#${money}').formatCurrency({
|
|
4281
4327
|
symbol: '${widgets[money].symbol || "" }',
|
|
4282
4328
|
decimalSymbol: '${widgets[money].decimalPlaces || "," }',
|