zet-lib 3.1.0 → 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.
@@ -53,56 +53,63 @@ router.get('/', async function (req, res, next) {
53
53
  }
54
54
  })
55
55
  if(copyMenu){
56
+ copyMenu.json = '[]';
56
57
  copyMenu.updated_by = res.locals.userId;
57
58
  copyMenu.created_by = res.locals.userId;
58
59
  copyMenu.created_at = Util.now();
59
60
  copyMenu.updated_at = Util.now();
60
61
  copyMenu.company_id = companyId;
62
+ company.name = 'Default';
61
63
  delete copyMenu.id;
62
64
  await connection.insert({
63
65
  table : "zmenu",
64
66
  data : copyMenu
65
67
  });
66
68
  }
69
+ rows= await connection.results({
70
+ table: "zmenu",
71
+ where : {
72
+ company_id : companyId
73
+ }
74
+ });
67
75
  }
68
- if (rows.length > 0) {
69
- hasAccessMenu = true;
70
- //check id changes
71
- let rowsChanges = rows.filter((item) => item.active == 1);
72
- idChanges = rowsChanges[0].id;
73
- if (id) {
74
- await connection.update({
75
- table : "zmenu",
76
- data: {
77
- active:0
78
- },
79
- where : {
80
- company_id: companyId
81
- }
82
- });
83
- await connection.update({
84
- table : "zmenu",
85
- data : {
86
- active : 1,
87
- },
88
- where : {
89
- id: id
90
- }
91
- });
92
- } else {
93
- id =1;
94
- let selected = rows.filter(item=>item.active == 1)[0] || {}
95
- id = selected.id;
96
- name = selected.name;
97
- }
76
+ hasAccessMenu = true;
77
+ //check id changes
78
+ let rowsChanges = rows.filter((item) => item.active == 1);
79
+ idChanges = rowsChanges.length > 0 ? rowsChanges[0].id : null;
80
+ if (id) {
81
+ await connection.update({
82
+ table : "zmenu",
83
+ data: {
84
+ active:0
85
+ },
86
+ where : {
87
+ company_id: companyId
88
+ }
89
+ });
90
+ await connection.update({
91
+ table : "zmenu",
92
+ data : {
93
+ active : 1,
94
+ },
95
+ where : {
96
+ id: id
97
+ }
98
+ });
99
+ } else {
100
+ id =1;
101
+ let selected = rows.filter(item=>item.active == 1)[0] || {}
102
+ id = selected.id;
103
+ name = selected.name;
98
104
  }
105
+
99
106
  findArr = await connection.results({
100
107
  table:"zmenu",
101
108
  where: {
102
109
  id:id
103
110
  }
104
111
  });
105
- arr = findArr[0].json;
112
+ arr = findArr && findArr.length > 0 && findArr[0].json ? findArr[0].json : arr;
106
113
  let refresh = 0;
107
114
  if (id != idChanges) {
108
115
  refresh = 1;
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
- obj[key].value = data[key] ? `${widgets[key].symbol} ${Util.formatNumber(data[key], ".")}` : "";
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 || "," }',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"