beca-ui 2.0.19-beta.7 → 2.0.19-beta.70
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/dist/ConvertVietnameseNumber.js +136 -0
- package/dist/DynamicWorkflowScript.js +1142 -0
- package/dist/beca-ui.js +141259 -92694
- package/dist/components/Layout/Layout.d.ts +1 -10
- package/dist/components/Layout/index.d.ts +1 -0
- package/dist/components/Menu/Menu.types.d.ts +2 -2
- package/dist/components/Menu/index.d.ts +1 -2
- package/dist/components/Select/index.d.ts +2 -2
- package/dist/components/WorkflowForm/WorkflowForm.d.ts +1 -1
- package/dist/components/WorkflowForm/WorkflowForm.types.d.ts +3 -1
- package/dist/components/WorkflowForm/components/AddRelatedWorkModal.d.ts +13 -0
- package/dist/components/WorkflowForm/components/DynamicAttachTable/DynamicAttachTable.d.ts +1 -1
- package/dist/components/{BecaCard → WorkflowForm/components/DynamicAttachTable/components}/BecaCard.d.ts +1 -1
- package/dist/components/{BecaCard → WorkflowForm/components/DynamicAttachTable/components}/BecaCard.types.d.ts +1 -1
- package/dist/components/WorkflowForm/components/NewUserWorkflow/ProcessModal.d.ts +25 -0
- package/dist/components/WorkflowForm/components/ProcessSection/ProcessDetailModal.d.ts +13 -0
- package/dist/components/WorkflowForm/components/ProcessSection/ProcessSection.d.ts +12 -0
- package/dist/components/WorkflowForm/components/ProcessStepItem.d.ts +16 -0
- package/dist/components/WorkflowForm/components/RelatedUserWorkflowSection.d.ts +13 -0
- package/dist/components/WorkflowForm/components/UserWorkflowShare/AddUserWorkflowShareModal.d.ts +10 -0
- package/dist/components/WorkflowForm/components/UserWorkflowShare/UpdateUserWorkflowShareModal.d.ts +8 -0
- package/dist/components/WorkflowForm/hooks/processHooks.d.ts +15 -0
- package/dist/components/WorkflowForm/models/AddUserWorkflowShareModel.d.ts +1 -1
- package/dist/components/WorkflowForm/models/UserWorkflowModel.d.ts +1 -1
- package/dist/components/WorkflowForm/models/UserWorkflowShareModel.d.ts +1 -1
- package/dist/components/WorkflowForm/models/WorkflowStepModel.d.ts +7 -2
- package/dist/components/WorkflowForm/models/flowModels/FlowModel.d.ts +6 -0
- package/dist/components/WorkflowForm/models/flowModels/InitialDataModel.d.ts +3 -0
- package/dist/components/WorkflowForm/models/flowModels/{IInitialEdgeModel.d.ts → InitialEdgeModel.d.ts} +1 -1
- package/dist/components/WorkflowForm/models/flowModels/InitialNodeModels.d.ts +14 -0
- package/dist/components/WorkflowForm/models/flowModels/InitialPositionModel.d.ts +4 -0
- package/dist/components/WorkflowForm/models/flowModels/{IInitialStyleModel.d.ts → InitialStyleModel.d.ts} +1 -1
- package/dist/components/WorkflowForm/models/ui/index.d.ts +1 -1
- package/dist/components/WorkflowForm/services/{DataServices.d.ts → DataServices2.d.ts} +2 -2
- package/dist/components/WorkflowForm/services/PermissionService.d.ts +6 -0
- package/dist/components/WorkflowForm/services/SendWorkflowService.d.ts +1 -1
- package/dist/components/WorkflowForm/services/UserCheckListService.d.ts +1 -1
- package/dist/components/WorkflowForm/services/UserWorkflowService.d.ts +1 -1
- package/dist/components/WorkflowForm/services/UserWorkflowShareService.d.ts +15 -0
- package/dist/components/WorkflowForm/services/WorkflowService.d.ts +67 -0
- package/dist/components/WorkflowForm/services/index.d.ts +22 -0
- package/dist/components/WorkflowForm/utils/index.d.ts +0 -4
- package/dist/components/index.d.ts +0 -1
- package/dist/data/LocalesTexts/EnglishTexts.d.ts +4 -0
- package/dist/data/LocalesTexts/VietnameseTexts.d.ts +4 -0
- package/dist/hooks/ApiHooks.d.ts +23 -0
- package/dist/hooks/LocaleHook.d.ts +4 -0
- package/dist/hooks/WorkflowHooks.d.ts +49 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/main.css +1 -1
- package/dist/models/Core/Result.d.ts +1 -1
- package/dist/theme/styles.d.ts +2 -1
- package/package.json +4 -3
- package/dist/components/BecaCard/index.d.ts +0 -2
- package/dist/components/WorkflowForm/models/flowModels/IFlowModel.d.ts +0 -6
- package/dist/components/WorkflowForm/models/flowModels/IInitialDataModel.d.ts +0 -3
- package/dist/components/WorkflowForm/models/flowModels/IInitialNodeModels.d.ts +0 -14
- package/dist/components/WorkflowForm/models/flowModels/IInitialPositionModel.d.ts +0 -4
- /package/dist/{theme → components/WorkflowForm/theme}/Colors.d.ts +0 -0
|
@@ -0,0 +1,1142 @@
|
|
|
1
|
+
const docTien = new DocTienBangChu();
|
|
2
|
+
const DEFAULT_MONEY_UNIT = 'đồng';
|
|
3
|
+
|
|
4
|
+
var isDetail = false;
|
|
5
|
+
var isMasterDetail = false;
|
|
6
|
+
var colName = undefined;
|
|
7
|
+
var mdCellId = undefined;
|
|
8
|
+
var masterDetailId = undefined;
|
|
9
|
+
|
|
10
|
+
function capitalize(word = '') {
|
|
11
|
+
word = word.toLowerCase();
|
|
12
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function runScript(scriptString) {
|
|
16
|
+
eval(scriptString);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isNumeric(n) {
|
|
20
|
+
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getMoneyUnitName(unit) {
|
|
24
|
+
switch (unit) {
|
|
25
|
+
case 'VND':
|
|
26
|
+
return 'đồng';
|
|
27
|
+
case 'USD':
|
|
28
|
+
return 'đô la';
|
|
29
|
+
case 'EUR':
|
|
30
|
+
return 'ơ-rô';
|
|
31
|
+
case 'JPY':
|
|
32
|
+
return 'yên';
|
|
33
|
+
case 'SGD':
|
|
34
|
+
return 'đô la Singapore';
|
|
35
|
+
case 'KRW':
|
|
36
|
+
return 'won';
|
|
37
|
+
default:
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function docSoTien(number, unit = DEFAULT_MONEY_UNIT, locale = 'vi') {
|
|
43
|
+
let result = '';
|
|
44
|
+
const numbers = number?.toString().split('.');
|
|
45
|
+
|
|
46
|
+
if (locale === 'en') {
|
|
47
|
+
const numberText1 = numberToTextEN(Number(numbers[0]));
|
|
48
|
+
result = numberText1.trim();
|
|
49
|
+
} else {
|
|
50
|
+
const numberText1 = docTien.doc(numbers[0]);
|
|
51
|
+
result = numberText1.trim();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (numbers.length === 2) {
|
|
55
|
+
if (locale === 'en') {
|
|
56
|
+
const numberText2 = numberToTextEN(numbers[1]);
|
|
57
|
+
result += ` point ${numberText2.toLowerCase()}`;
|
|
58
|
+
} else {
|
|
59
|
+
const numberText2 = docTien.doc(numbers[1]);
|
|
60
|
+
result += ` phẩy ${numberText2.toLowerCase()}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
result = capitalize(result);
|
|
64
|
+
if (unit?.trim() !== '') {
|
|
65
|
+
result += ` ${unit}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function fetchDataFromApi(api, from, property, to, fromName) {
|
|
72
|
+
var htmlElement = document.getElementById('field_' + fromName);
|
|
73
|
+
if (htmlElement && htmlElement.tagName === 'SPAN') {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (from && from[property]) {
|
|
77
|
+
if (!isNumeric(from[property])) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
api = window.location.origin + api + from[property];
|
|
81
|
+
var myHeaders = new Headers();
|
|
82
|
+
myHeaders.append('Accept', '*/*');
|
|
83
|
+
myHeaders.append('Accept-Language', 'en');
|
|
84
|
+
myHeaders.append('Accept-Encoding', 'gzip, deflate, br');
|
|
85
|
+
myHeaders.append('Connection', 'keep-alive');
|
|
86
|
+
var requestOptions = {
|
|
87
|
+
method: 'GET',
|
|
88
|
+
headers: myHeaders,
|
|
89
|
+
redirect: 'follow',
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
fetch(api, requestOptions)
|
|
93
|
+
.then(response => response.text())
|
|
94
|
+
.then(result => {
|
|
95
|
+
result = result.replace(/"/g, '');
|
|
96
|
+
|
|
97
|
+
const textValue = document.getElementById('field_' + to);
|
|
98
|
+
|
|
99
|
+
if (textValue) {
|
|
100
|
+
if (result) {
|
|
101
|
+
textValue.innerHTML = result;
|
|
102
|
+
} else {
|
|
103
|
+
textValue.innerHTML = '';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
.catch(error => console.log('error', error));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getPathFromUrl(url) {
|
|
112
|
+
return url.split(/[?#]/)[0];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function searchDataByProperyName(api, from, to) {
|
|
116
|
+
api = window.location.origin + api + encodeURIComponent(from.value);
|
|
117
|
+
var myHeaders = new Headers();
|
|
118
|
+
myHeaders.append('Accept', '*/*');
|
|
119
|
+
myHeaders.append('Accept-Language', 'en');
|
|
120
|
+
myHeaders.append('Accept-Encoding', 'gzip, deflate, br');
|
|
121
|
+
myHeaders.append('Connection', 'keep-alive');
|
|
122
|
+
var requestOptions = {
|
|
123
|
+
method: 'GET',
|
|
124
|
+
headers: myHeaders,
|
|
125
|
+
redirect: 'follow',
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
fetch(api, requestOptions)
|
|
129
|
+
.then(response => response.json())
|
|
130
|
+
.then(result => {
|
|
131
|
+
mapArrayIntoChoiceProperty(to, result);
|
|
132
|
+
})
|
|
133
|
+
.catch(error => console.log('error', error));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function _searchDataAndMapIntoDropdown(api, from, to) {
|
|
137
|
+
searchDataAndMapIntoDropdown(api, from, to);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function searchDataAndMapIntoDropdown(api, from, to) {
|
|
141
|
+
if (from && !isHtmlCollection(from)) {
|
|
142
|
+
api = window.location.origin + api + encodeURIComponent(from.value);
|
|
143
|
+
var myHeaders = new Headers();
|
|
144
|
+
myHeaders.append('Accept', '*/*');
|
|
145
|
+
myHeaders.append('Accept-Language', 'en');
|
|
146
|
+
myHeaders.append('Accept-Encoding', 'gzip, deflate, br');
|
|
147
|
+
myHeaders.append('Connection', 'keep-alive');
|
|
148
|
+
var requestOptions = {
|
|
149
|
+
method: 'GET',
|
|
150
|
+
headers: myHeaders,
|
|
151
|
+
redirect: 'follow',
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
fetch(api, requestOptions)
|
|
155
|
+
.then(response => {
|
|
156
|
+
if (response.ok) {
|
|
157
|
+
return response.json();
|
|
158
|
+
}
|
|
159
|
+
console.log('Error: searchDataAndMapIntoDropdown');
|
|
160
|
+
throw new Error();
|
|
161
|
+
})
|
|
162
|
+
.then(result => {
|
|
163
|
+
mapDropDownValueIntoProperty(to, result);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function _searchDataFromMDAndMapIntoMD(api, from, to, fromName) {
|
|
169
|
+
searchDataFromMDAndMapIntoMD(api, from, to, fromName);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function mapMDFromMD({
|
|
173
|
+
from,
|
|
174
|
+
fromName = 'value',
|
|
175
|
+
masterDetailId,
|
|
176
|
+
fromMDName,
|
|
177
|
+
filterName = 'UserWorkflowId',
|
|
178
|
+
toMDName,
|
|
179
|
+
}) {
|
|
180
|
+
searchDataFromMDAndMapIntoMD(
|
|
181
|
+
`/api/v2/workflowReport/SearchDataFromMDAndMapIntoMD/${masterDetailId}?filterName=${filterName}&mdName=${fromMDName}&filterValue=`,
|
|
182
|
+
from,
|
|
183
|
+
`${toMDName}`,
|
|
184
|
+
fromName
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function searchDataFromMDAndMapIntoMD(api, from, to, fromName) {
|
|
189
|
+
if (from) {
|
|
190
|
+
api =
|
|
191
|
+
window.location.origin +
|
|
192
|
+
api +
|
|
193
|
+
encodeURIComponent(from[fromName ?? 'value']);
|
|
194
|
+
|
|
195
|
+
var myHeaders = new Headers();
|
|
196
|
+
|
|
197
|
+
myHeaders.append('Accept', '*/*');
|
|
198
|
+
myHeaders.append('Accept-Language', 'en');
|
|
199
|
+
myHeaders.append('Accept-Encoding', 'gzip, deflate, br');
|
|
200
|
+
myHeaders.append('Connection', 'keep-alive');
|
|
201
|
+
|
|
202
|
+
var requestOptions = {
|
|
203
|
+
method: 'GET',
|
|
204
|
+
headers: myHeaders,
|
|
205
|
+
redirect: 'follow',
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
fetch(api, requestOptions)
|
|
209
|
+
.then(response => response.json())
|
|
210
|
+
.then(result => {
|
|
211
|
+
mapMdValueIntoMD(to, result);
|
|
212
|
+
})
|
|
213
|
+
.catch(error => console.log('error', error));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// function reSearchDataByProperyName(api, from, fromProperty, to) {
|
|
218
|
+
// console.log('searchDataByProperyName');
|
|
219
|
+
// api = window.location.origin + api + from[fromProperty];
|
|
220
|
+
// var myHeaders = new Headers();
|
|
221
|
+
// myHeaders.append('Accept', '*/*');
|
|
222
|
+
// myHeaders.append('Accept-Language', 'en');
|
|
223
|
+
// myHeaders.append('Accept-Encoding', 'gzip, deflate, br');
|
|
224
|
+
// myHeaders.append('Connection', 'keep-alive');
|
|
225
|
+
// var requestOptions = {
|
|
226
|
+
// method: 'GET',
|
|
227
|
+
// headers: myHeaders,
|
|
228
|
+
// redirect: 'follow',
|
|
229
|
+
// };
|
|
230
|
+
|
|
231
|
+
// fetch(api, requestOptions)
|
|
232
|
+
// .then(response => response.json())
|
|
233
|
+
// .then(result => {
|
|
234
|
+
// console.log(result);
|
|
235
|
+
// mapArrayIntoChoiceProperty(to, result);
|
|
236
|
+
// })
|
|
237
|
+
// .catch(error => console.log('error', error));
|
|
238
|
+
// }
|
|
239
|
+
|
|
240
|
+
function fromSelectToText(dataFrom, dataTo) {
|
|
241
|
+
const selectElement = document.getElementById(dataFrom);
|
|
242
|
+
if (selectElement) {
|
|
243
|
+
const selectItems = selectElement.getElementsByClassName(
|
|
244
|
+
'ant-select-selection-item'
|
|
245
|
+
);
|
|
246
|
+
if (selectItems && selectItems.length > 0) {
|
|
247
|
+
const title = selectItems[0].title;
|
|
248
|
+
const textValue = document.getElementById('field_' + dataTo);
|
|
249
|
+
if (textValue) {
|
|
250
|
+
const value = title.split('=')[0].trim();
|
|
251
|
+
textValue.innerHTML = value;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function _numberToText(dataFrom, dataTo, unitId, locale) {
|
|
258
|
+
numberToText(dataFrom, dataTo, unitId, locale);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function numberToText(dataFrom, dataTo, unitId, locale) {
|
|
262
|
+
if (isDetail === undefined || isDetail === null || isDetail === false) {
|
|
263
|
+
let numberValue = getValue(dataFrom);
|
|
264
|
+
if (numberValue !== undefined && numberValue !== null) {
|
|
265
|
+
// numberValue = formatNumberString(numberValue, locale);
|
|
266
|
+
|
|
267
|
+
const textValueElement = getElementById(dataTo);
|
|
268
|
+
if (textValueElement) {
|
|
269
|
+
if (numberValue !== undefined && numberValue !== null) {
|
|
270
|
+
let unit = DEFAULT_MONEY_UNIT;
|
|
271
|
+
|
|
272
|
+
if (unitId) {
|
|
273
|
+
const unitElement = getElementById(unitId);
|
|
274
|
+
|
|
275
|
+
if (unitElement) {
|
|
276
|
+
const itemValue = getValue(unitId);
|
|
277
|
+
if (itemValue !== undefined) {
|
|
278
|
+
const unitName = getMoneyUnitName(itemValue);
|
|
279
|
+
unit = unitName;
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
unit = unitId;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
let text = docSoTien(numberValue.toString(), unit, locale);
|
|
286
|
+
text = text?.replaceAll(' ', ' ');
|
|
287
|
+
textValueElement.innerHTML = text;
|
|
288
|
+
} else {
|
|
289
|
+
textValueElement.innerHTML = '';
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
numberToTextDetail(dataFrom, dataTo, unitId, locale);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function numberToTextEN(n) {
|
|
299
|
+
if (n < 0) return false;
|
|
300
|
+
|
|
301
|
+
// Arrays to hold words for single-digit, double-digit, and below-hundred numbers
|
|
302
|
+
single_digit = [
|
|
303
|
+
'',
|
|
304
|
+
'One',
|
|
305
|
+
'Two',
|
|
306
|
+
'Three',
|
|
307
|
+
'Four',
|
|
308
|
+
'Five',
|
|
309
|
+
'Six',
|
|
310
|
+
'Seven',
|
|
311
|
+
'Eight',
|
|
312
|
+
'Nine',
|
|
313
|
+
];
|
|
314
|
+
double_digit = [
|
|
315
|
+
'Ten',
|
|
316
|
+
'Eleven',
|
|
317
|
+
'Twelve',
|
|
318
|
+
'Thirteen',
|
|
319
|
+
'Fourteen',
|
|
320
|
+
'Fifteen',
|
|
321
|
+
'Sixteen',
|
|
322
|
+
'Seventeen',
|
|
323
|
+
'Eighteen',
|
|
324
|
+
'Nineteen',
|
|
325
|
+
];
|
|
326
|
+
below_hundred = [
|
|
327
|
+
'Twenty',
|
|
328
|
+
'Thirty',
|
|
329
|
+
'Forty',
|
|
330
|
+
'Fifty',
|
|
331
|
+
'Sixty',
|
|
332
|
+
'Seventy',
|
|
333
|
+
'Eighty',
|
|
334
|
+
'Ninety',
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
if (n === 0) return 'Zero';
|
|
338
|
+
|
|
339
|
+
// Recursive function to translate the number into words
|
|
340
|
+
function translate(n) {
|
|
341
|
+
let word = '';
|
|
342
|
+
if (n < 10) {
|
|
343
|
+
word = single_digit[n] + ' ';
|
|
344
|
+
} else if (n < 20) {
|
|
345
|
+
word = double_digit[n - 10] + ' ';
|
|
346
|
+
} else if (n < 100) {
|
|
347
|
+
let rem = translate(n % 10);
|
|
348
|
+
word = below_hundred[(n - (n % 10)) / 10 - 2] + ' ' + rem;
|
|
349
|
+
} else if (n < 1000) {
|
|
350
|
+
word =
|
|
351
|
+
single_digit[Math.trunc(n / 100)] + ' Hundred ' + translate(n % 100);
|
|
352
|
+
} else if (n < 1000000) {
|
|
353
|
+
word =
|
|
354
|
+
translate(parseInt(n / 1000)).trim() +
|
|
355
|
+
' Thousand ' +
|
|
356
|
+
translate(n % 1000);
|
|
357
|
+
} else if (n < 1000000000) {
|
|
358
|
+
word =
|
|
359
|
+
translate(parseInt(n / 1000000)).trim() +
|
|
360
|
+
' Million ' +
|
|
361
|
+
translate(n % 1000000);
|
|
362
|
+
} else {
|
|
363
|
+
word =
|
|
364
|
+
translate(parseInt(n / 1000000000)).trim() +
|
|
365
|
+
' Billion ' +
|
|
366
|
+
translate(n % 1000000000);
|
|
367
|
+
}
|
|
368
|
+
return word;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Get the result by translating the given number
|
|
372
|
+
let result = translate(n);
|
|
373
|
+
return result.trim();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function readNumber(dataFrom, unitId, locale, dataTo = colName) {
|
|
377
|
+
if (isDetail === undefined || isDetail === null || isDetail === false) {
|
|
378
|
+
let numberValue = getFieldValue(dataFrom);
|
|
379
|
+
if (numberValue !== undefined && numberValue !== null) {
|
|
380
|
+
numberValue = formatNumberString(numberValue, locale);
|
|
381
|
+
const textValueElement = getElementById(dataTo);
|
|
382
|
+
if (textValueElement) {
|
|
383
|
+
if (numberValue !== undefined && numberValue !== null) {
|
|
384
|
+
let unit = DEFAULT_MONEY_UNIT;
|
|
385
|
+
if (unitId) {
|
|
386
|
+
const unitElement = getElementById(unitId);
|
|
387
|
+
if (unitElement) {
|
|
388
|
+
const itemValue = getValue(unitId);
|
|
389
|
+
if (itemValue !== undefined) {
|
|
390
|
+
const unitName = getMoneyUnitName(itemValue);
|
|
391
|
+
unit = unitName;
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
unit = unitId;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
let text = docSoTien(numberValue.toString(), unit, locale);
|
|
398
|
+
text = text?.replaceAll(' ', ' ');
|
|
399
|
+
// textValueElement.innerHTML = text;
|
|
400
|
+
setValue(dataTo, text);
|
|
401
|
+
} else {
|
|
402
|
+
// textValueElement.innerHTML = '';
|
|
403
|
+
setValue(dataTo, '');
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
numberToTextDetail(dataFrom, dataTo, unitId, locale);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function numberToTextDetail(dataFrom, dataTo, unitId, locale) {
|
|
413
|
+
let unit = DEFAULT_MONEY_UNIT;
|
|
414
|
+
if (unitId) {
|
|
415
|
+
const unitElement = document.querySelector(`#${unitId}`);
|
|
416
|
+
if (unitElement) {
|
|
417
|
+
const itemElement = unitElement.querySelector(
|
|
418
|
+
'.ant-select-selection-item'
|
|
419
|
+
);
|
|
420
|
+
if (itemElement && itemElement.title) {
|
|
421
|
+
const unitName = getMoneyUnitName(itemElement.title);
|
|
422
|
+
unit = unitName;
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
unit = unitId;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const numberValue = getValueMD(dataFrom);
|
|
430
|
+
if (numberValue) {
|
|
431
|
+
const value = formatNumberString(numberValue);
|
|
432
|
+
const textValue = getElementById(dataTo, true);
|
|
433
|
+
if (textValue) {
|
|
434
|
+
if (value !== undefined && value !== null) {
|
|
435
|
+
let text = docSoTien(value, unit, locale);
|
|
436
|
+
text = text?.replaceAll(' ', ' ');
|
|
437
|
+
textValue.innerHTML = text;
|
|
438
|
+
} else {
|
|
439
|
+
textValue.innerHTML = '';
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function textNumberToText(dataFrom, dataTo, unitId) {
|
|
446
|
+
const fromElement = document.getElementById('field_' + dataFrom);
|
|
447
|
+
if (fromElement) {
|
|
448
|
+
const fromValue = fromElement.innerHTML;
|
|
449
|
+
const numberValue = formatNumberString(fromValue);
|
|
450
|
+
const toElement = document.getElementById('field_' + dataTo);
|
|
451
|
+
if (toElement) {
|
|
452
|
+
if (numberValue) {
|
|
453
|
+
let unit = DEFAULT_MONEY_UNIT;
|
|
454
|
+
if (unitId) {
|
|
455
|
+
const unitElement = document.querySelector(`#${unitId}`);
|
|
456
|
+
if (unitElement) {
|
|
457
|
+
const itemElement = unitElement.querySelector(
|
|
458
|
+
'.ant-select-selection-item'
|
|
459
|
+
);
|
|
460
|
+
if (itemElement && itemElement.title) {
|
|
461
|
+
const unitName = getMoneyUnitName(itemElement.title);
|
|
462
|
+
unit = unitName;
|
|
463
|
+
}
|
|
464
|
+
} else {
|
|
465
|
+
unit = unitId;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
let text = docSoTien(numberValue.toString(), unit);
|
|
469
|
+
text = text?.replaceAll(' ', ' ');
|
|
470
|
+
toElement.innerHTML = text;
|
|
471
|
+
} else {
|
|
472
|
+
toElement.innerHTML = '';
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function _textNumberToText(dataFrom, dataTo, unitId) {
|
|
479
|
+
textNumberToText(dataFrom, dataTo, unitId);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// Locale: "vi" | "en"
|
|
483
|
+
function formatNumberString(number, locale = 'vi') {
|
|
484
|
+
let result = '0';
|
|
485
|
+
if (locale === 'vi') {
|
|
486
|
+
result = number
|
|
487
|
+
? number?.toString().replaceAll('.', '').replaceAll('= ', '')
|
|
488
|
+
: '0';
|
|
489
|
+
result = result.replaceAll(',', '.');
|
|
490
|
+
} else {
|
|
491
|
+
result = number;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return Number(result);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function setValue(toId, value, isMD = false) {
|
|
498
|
+
const name = toId ?? getCurrentId();
|
|
499
|
+
window.setFieldValue(name, value, isMD ? masterDetailId : undefined);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function setValueMD(name, value, mdId) {
|
|
503
|
+
window.setFieldValue(name, value, mdId);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function calc(name, string) {
|
|
507
|
+
try {
|
|
508
|
+
if (string && string.length > 0) {
|
|
509
|
+
const split = string.split(`'`);
|
|
510
|
+
for (let i in split) {
|
|
511
|
+
const splitItem = split[i].trim();
|
|
512
|
+
|
|
513
|
+
if (splitItem.length > 0 && isStringValid(splitItem)) {
|
|
514
|
+
string = calcSub(splitItem, string);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
const money = eval(string);
|
|
518
|
+
setValue(name, money);
|
|
519
|
+
// const ele = document.getElementById('field_' + name);
|
|
520
|
+
// if (ele) {
|
|
521
|
+
// if (ele.innerHTML.includes(' %')) {
|
|
522
|
+
// result += ' %';
|
|
523
|
+
// }
|
|
524
|
+
// ele.innerHTML = result;
|
|
525
|
+
// }
|
|
526
|
+
}
|
|
527
|
+
} catch (e) {
|
|
528
|
+
console.log(e);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const getFieldValue = (name, isMD) => {
|
|
533
|
+
return window.getFieldValue(name, isMD);
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
const handleFormular = (formularString, isMD) => {
|
|
537
|
+
if (formularString?.length > 0) {
|
|
538
|
+
formularString = formularString.replace(/\s/g, '');
|
|
539
|
+
let name = '';
|
|
540
|
+
let adding = false;
|
|
541
|
+
const ids = [];
|
|
542
|
+
|
|
543
|
+
for (let i = 0; i < formularString.length; i++) {
|
|
544
|
+
if (formularString[i] === '[') {
|
|
545
|
+
adding = true;
|
|
546
|
+
} else if (formularString[i] === ']') {
|
|
547
|
+
ids.push(name);
|
|
548
|
+
adding = false;
|
|
549
|
+
name = '';
|
|
550
|
+
} else if (adding === true) {
|
|
551
|
+
name += formularString[i];
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
let formular = formularString;
|
|
556
|
+
|
|
557
|
+
if (ids.length > 0) {
|
|
558
|
+
ids.forEach(id => {
|
|
559
|
+
const value = getFieldValue(id, isMD) ?? 0;
|
|
560
|
+
formular = formular.replaceAll(`[${id}]`, value);
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return { math: formular, elementIds: ids };
|
|
565
|
+
} else {
|
|
566
|
+
return { math: formularString, elementIds: [] };
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
function calculate(calcText, to = colName) {
|
|
571
|
+
try {
|
|
572
|
+
console.log('calculate');
|
|
573
|
+
if (calcText && calcText.length > 0) {
|
|
574
|
+
const formular = handleFormular(calcText, isMasterDetail);
|
|
575
|
+
const result = eval(formular.math);
|
|
576
|
+
setValue(to, result, masterDetailId);
|
|
577
|
+
}
|
|
578
|
+
} catch (e) {
|
|
579
|
+
console.log(e);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function _calculate(calcText, to) {
|
|
584
|
+
calculate(calcText, to);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function _calc(calcText, to) {
|
|
588
|
+
calc(calcText, to);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function calcSub(name, string) {
|
|
592
|
+
try {
|
|
593
|
+
let element =
|
|
594
|
+
getElementById(name) ??
|
|
595
|
+
document.getElementById(`dynamicWorkflowForm_${name}`);
|
|
596
|
+
if (element) {
|
|
597
|
+
const num = getValue(name) ?? 0;
|
|
598
|
+
string = string.replaceAll(
|
|
599
|
+
`'${name}'`,
|
|
600
|
+
`
|
|
601
|
+
${num}
|
|
602
|
+
`
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
} catch (e) {
|
|
606
|
+
console.log('calcSub', e);
|
|
607
|
+
}
|
|
608
|
+
return string;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function isHtmlCollection(element) {
|
|
612
|
+
return HTMLCollection.prototype.isPrototypeOf(element);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function mapData(name, from, to, type) {
|
|
616
|
+
if (isHtmlCollection(from)) return;
|
|
617
|
+
|
|
618
|
+
let value = from ? from[name] : undefined;
|
|
619
|
+
|
|
620
|
+
if (value && type === 'number') {
|
|
621
|
+
value = convertNumberToText(value);
|
|
622
|
+
}
|
|
623
|
+
setValue(to, value);
|
|
624
|
+
// const toElement = getElementById(to);
|
|
625
|
+
// if (toElement) {
|
|
626
|
+
// toElement.innerHTML = value ?? '';
|
|
627
|
+
// }
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function _mapData(name, from, to, type) {
|
|
631
|
+
mapData(name, from, to, type);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function mapDataMasterDetail(
|
|
635
|
+
from,
|
|
636
|
+
fromProperty,
|
|
637
|
+
to,
|
|
638
|
+
id,
|
|
639
|
+
type,
|
|
640
|
+
isEditMasterDetail
|
|
641
|
+
) {
|
|
642
|
+
try {
|
|
643
|
+
if (!isEditMasterDetail) {
|
|
644
|
+
if (fromProperty && to && id !== undefined) {
|
|
645
|
+
let value = '';
|
|
646
|
+
if (from) {
|
|
647
|
+
value = from[fromProperty];
|
|
648
|
+
// if (value && type === 'number') {
|
|
649
|
+
// value = '= ' + convertNumberToText(value);
|
|
650
|
+
// }
|
|
651
|
+
}
|
|
652
|
+
// toElement.innerHTML = value ?? '';
|
|
653
|
+
setValueMD(to, value ?? '', id);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
} catch (e) {
|
|
657
|
+
console.log('mapDataMasterDetailError:', e);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function _mapDataMasterDetail(from, fromProperty, to, id, isEditMasterDetail) {
|
|
662
|
+
mapDataMasterDetail(from, fromProperty, to, id, isEditMasterDetail);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function sendLinkToWebView(path, fileName) {
|
|
666
|
+
try {
|
|
667
|
+
let pathSendToWebView =
|
|
668
|
+
window.location.protocol +
|
|
669
|
+
'//' +
|
|
670
|
+
window.location.host +
|
|
671
|
+
path.replace('downloadFile', 'downloadFileAnonymous');
|
|
672
|
+
let data = {
|
|
673
|
+
path: pathSendToWebView,
|
|
674
|
+
fileName: fileName,
|
|
675
|
+
};
|
|
676
|
+
window.parent.postMessage(JSON.stringify(data), window.parent.origin);
|
|
677
|
+
window.postMessage(JSON.stringify(data), window.parent.origin);
|
|
678
|
+
window.ReactNativeWebView.postMessage(JSON.stringify(data));
|
|
679
|
+
} catch (error) {
|
|
680
|
+
console.log(error);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function fromSelectToTextMasterDetail(from, fromProperty, to, id) {
|
|
685
|
+
if (from) {
|
|
686
|
+
let value = from[fromProperty];
|
|
687
|
+
const toId = id.toString() + '_' + to;
|
|
688
|
+
const toElement = document.getElementById(toId);
|
|
689
|
+
if (toElement) {
|
|
690
|
+
if (value) {
|
|
691
|
+
const textValue = value.split('=')[0].trim();
|
|
692
|
+
toElement.innerHTML = textValue;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function isStringValid(string) {
|
|
699
|
+
let format = /[!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?]+/;
|
|
700
|
+
return !format.test(string);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function _mapNumberMD2F(fromId, toNumberId, toTextId) {
|
|
704
|
+
const num = _mapFromMasterDetail(fromId, toNumberId);
|
|
705
|
+
|
|
706
|
+
_numberToTextFromMD(num, toTextId);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function _mapFromMasterDetail(fromId, toId) {
|
|
710
|
+
let result;
|
|
711
|
+
const fromElement = getElementById(fromId, true);
|
|
712
|
+
if (fromElement) {
|
|
713
|
+
const fromValue = getValueMD(fromId) ?? 0;
|
|
714
|
+
const toElement = document.querySelector(`#field_${toId}`);
|
|
715
|
+
if (toElement) {
|
|
716
|
+
toElement.innerHTML = fromValue;
|
|
717
|
+
result = fromValue;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return result;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function _numberToTextFromMD(num, dataTo) {
|
|
724
|
+
const toElement = document.querySelector(`#field_${dataTo}`);
|
|
725
|
+
if (toElement) {
|
|
726
|
+
if (num) {
|
|
727
|
+
let number = formatNumberString(num);
|
|
728
|
+
if (toElement) {
|
|
729
|
+
if (number) {
|
|
730
|
+
toElement.innerHTML = docTien.doc(number);
|
|
731
|
+
} else {
|
|
732
|
+
toElement.innerHTML = '';
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
} else {
|
|
736
|
+
toElement.innerHTML = '';
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function removeDuplicates(arr) {
|
|
742
|
+
return arr.filter((item, index) => arr.indexOf(item) === index);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
function calcMD(calcText, to, id) {
|
|
746
|
+
try {
|
|
747
|
+
// const toElement = document.getElementById(`${id}_${to}`);
|
|
748
|
+
const toElement = to ? getElementById(`${to}`, true) : getCurrentElement();
|
|
749
|
+
let text = calcText.replace(/[^a-zA-Z0-9 ]/g, ' ');
|
|
750
|
+
|
|
751
|
+
text = text.trim().replace(/\s+/g, ' ');
|
|
752
|
+
let variables = text.split(' ');
|
|
753
|
+
|
|
754
|
+
if (toElement && variables.length > 0) {
|
|
755
|
+
variables = removeDuplicates(variables);
|
|
756
|
+
|
|
757
|
+
const names = [];
|
|
758
|
+
|
|
759
|
+
variables.forEach(variable => {
|
|
760
|
+
if (isNaN(variable)) {
|
|
761
|
+
names.push(variable);
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
let calc = calcText;
|
|
766
|
+
names.forEach(name => {
|
|
767
|
+
try {
|
|
768
|
+
const numberValue = getValueMD(name) ?? 0;
|
|
769
|
+
// const num = numberElement
|
|
770
|
+
// ? Number(
|
|
771
|
+
// formatNumberString(
|
|
772
|
+
// numberElement.replace('= ', '').replace(' %', '')
|
|
773
|
+
// )
|
|
774
|
+
// )
|
|
775
|
+
// : 0;
|
|
776
|
+
|
|
777
|
+
calc = calc.replaceAll(`'${name}'`, numberValue);
|
|
778
|
+
} catch (e) {
|
|
779
|
+
throw 'Not found element: ' + name;
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
const result = eval(calc);
|
|
783
|
+
|
|
784
|
+
// toElement.innerHTML = result;
|
|
785
|
+
// toElement.dataValue = result;
|
|
786
|
+
setValueMD(to, result, id ?? masterDetailId);
|
|
787
|
+
// toElement.innerHTML = `= ${Intl.NumberFormat('vi-VN', {}).format(
|
|
788
|
+
// result
|
|
789
|
+
// )}`;
|
|
790
|
+
}
|
|
791
|
+
} catch (e) {
|
|
792
|
+
console.log(e);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function map(from, to) {}
|
|
797
|
+
|
|
798
|
+
function _calcMMD(calcText, to) {
|
|
799
|
+
calcMMD(calcText, to);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function calcMMD(calcText, to) {
|
|
803
|
+
try {
|
|
804
|
+
const toElement = to ? getElementById(`${to}`) : getCurrentElement();
|
|
805
|
+
|
|
806
|
+
// const calcText = `('num1_mdsum' - 'num2_mdsum')`;
|
|
807
|
+
let calc = calcText;
|
|
808
|
+
let text = calcText.replaceAll('+', ' ');
|
|
809
|
+
text = text.replaceAll('-', ' ');
|
|
810
|
+
text = text.replaceAll('*', ' ');
|
|
811
|
+
text = text.replaceAll('/', ' ');
|
|
812
|
+
text = text.replaceAll('(', ' ');
|
|
813
|
+
text = text.replaceAll(')', ' ');
|
|
814
|
+
text = text.replaceAll("'", ' ');
|
|
815
|
+
text = text.replaceAll('"', ' ');
|
|
816
|
+
|
|
817
|
+
text = text.trim().replace(/\s+/g, ' ');
|
|
818
|
+
|
|
819
|
+
let variables = text.split(' ');
|
|
820
|
+
|
|
821
|
+
if (toElement && variables.length > 0) {
|
|
822
|
+
variables = removeDuplicates(variables);
|
|
823
|
+
|
|
824
|
+
const names = [];
|
|
825
|
+
|
|
826
|
+
variables.forEach(variable => {
|
|
827
|
+
if (isNaN(variable)) {
|
|
828
|
+
names.push(variable);
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
names.forEach(name => {
|
|
833
|
+
let val = 0;
|
|
834
|
+
const nameSplit = name.split('_');
|
|
835
|
+
if (nameSplit.length === 2) {
|
|
836
|
+
const tableElement = document.getElementById(`${nameSplit[0]}`);
|
|
837
|
+
if (tableElement) {
|
|
838
|
+
const valueElement = tableElement.querySelector(
|
|
839
|
+
`.sum-${nameSplit[1]}`
|
|
840
|
+
);
|
|
841
|
+
|
|
842
|
+
if (valueElement) {
|
|
843
|
+
val = valueElement.innerHTML;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (val !== 0) {
|
|
848
|
+
val = formatNumberString(val);
|
|
849
|
+
}
|
|
850
|
+
calc = calc.replaceAll(`'${name}'`, val ?? 0);
|
|
851
|
+
});
|
|
852
|
+
const result = eval(calc !== '()' ? calc : '');
|
|
853
|
+
setValue(to, result);
|
|
854
|
+
// toElement.innerHTML = Intl.NumberFormat('vi-VN', {}).format(result);
|
|
855
|
+
}
|
|
856
|
+
} catch (e) {
|
|
857
|
+
console.log(e);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
const getElementById = (name, isMD) => {
|
|
862
|
+
if (name) {
|
|
863
|
+
let isMasterDetailT = isMD;
|
|
864
|
+
if (!isMasterDetailT) {
|
|
865
|
+
const splitName = name.split('-');
|
|
866
|
+
if (splitName.length === 2 && splitName[0] === 'md') {
|
|
867
|
+
isMasterDetailT = true;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
// check if master detail
|
|
871
|
+
if (isMasterDetailT && mdCellId) {
|
|
872
|
+
const ids = mdCellId.split('_');
|
|
873
|
+
if (ids.length === 3) {
|
|
874
|
+
const id = `${ids[0]}_${ids[1]}_${name}`;
|
|
875
|
+
const ele = document.getElementById(id);
|
|
876
|
+
if (ele) {
|
|
877
|
+
const element = ele.querySelector(`#${name}`);
|
|
878
|
+
if (element) {
|
|
879
|
+
return element;
|
|
880
|
+
} else {
|
|
881
|
+
return ele;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
} else {
|
|
886
|
+
const ele = document.getElementById('field_' + name);
|
|
887
|
+
|
|
888
|
+
if (ele) {
|
|
889
|
+
return ele;
|
|
890
|
+
} else {
|
|
891
|
+
const classEle = document.querySelector(`.field_${name}`);
|
|
892
|
+
if (classEle) {
|
|
893
|
+
return classEle;
|
|
894
|
+
}
|
|
895
|
+
return document.getElementById('dynamicWorkflowForm_' + name);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
const getValueMD = (name, mdId) => {
|
|
902
|
+
return getValue(name, mdId ?? masterDetailId ?? true);
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
const getValue = (name, mdId) => {
|
|
906
|
+
return window.getFieldValue(name, mdId);
|
|
907
|
+
// const element = getElementById(name, isMD);
|
|
908
|
+
|
|
909
|
+
// if (element) {
|
|
910
|
+
// if (element.role === 'combobox') {
|
|
911
|
+
// const parentElement = element.parentElement?.parentElement;
|
|
912
|
+
// if (parentElement) {
|
|
913
|
+
// const selectItem = parentElement.querySelector(
|
|
914
|
+
// '.ant-select-selection-item'
|
|
915
|
+
// );
|
|
916
|
+
// if (selectItem) {
|
|
917
|
+
// return selectItem.title;
|
|
918
|
+
// }
|
|
919
|
+
// }
|
|
920
|
+
// }
|
|
921
|
+
|
|
922
|
+
// if (element.value) {
|
|
923
|
+
// return element.value;
|
|
924
|
+
// }
|
|
925
|
+
// return element.innerHTML;
|
|
926
|
+
// }
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
const getCurrentElement = isMD => {
|
|
930
|
+
let isMasterDetailT = isMasterDetail;
|
|
931
|
+
if (isMD !== undefined) {
|
|
932
|
+
isMasterDetailT = isMD;
|
|
933
|
+
}
|
|
934
|
+
if (isMasterDetailT) {
|
|
935
|
+
return document.getElementById(mdCellId);
|
|
936
|
+
} else {
|
|
937
|
+
return document.getElementById('field_' + colName);
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
const getCurrentId = isMD => {
|
|
942
|
+
let isMasterDetailT = isMasterDetail;
|
|
943
|
+
if (isMD !== undefined) {
|
|
944
|
+
isMasterDetailT = isMD;
|
|
945
|
+
}
|
|
946
|
+
if (isMasterDetailT) {
|
|
947
|
+
return mdCellId;
|
|
948
|
+
} else {
|
|
949
|
+
return colName;
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
function isValidDate(str) {
|
|
954
|
+
return dayjs(str, 'YYYY-MM-DD', true).isValid();
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
const datetime = {
|
|
958
|
+
formatDayjs(date) {
|
|
959
|
+
if (date) {
|
|
960
|
+
if (dayjs.isDayjs(date)) {
|
|
961
|
+
return date;
|
|
962
|
+
}
|
|
963
|
+
let dateTime;
|
|
964
|
+
if (date.length === 10) {
|
|
965
|
+
let dateSplit = date.split('/');
|
|
966
|
+
|
|
967
|
+
if (dateSplit[2].length === 4) {
|
|
968
|
+
dateSplit = dateSplit.reverse();
|
|
969
|
+
}
|
|
970
|
+
dateTime = dateSplit.join('/') + ' 00:00';
|
|
971
|
+
} else if (date.length === 16) {
|
|
972
|
+
const dateTimes = date.split(' ');
|
|
973
|
+
const dateSplit = dateTimes[0].split('/');
|
|
974
|
+
dateTime = dateSplit.reverse().join('/') + ` ${dateTimes[1]}`;
|
|
975
|
+
} else if (date.length === 19) {
|
|
976
|
+
return dayjs(date, 'YYYY-MM-DDTHH:mm:ss');
|
|
977
|
+
}
|
|
978
|
+
if (dateTime) {
|
|
979
|
+
return dayjs(dateTime, 'YYYY/MM/DD HH:mm');
|
|
980
|
+
} else if (isValidDate(date)) {
|
|
981
|
+
return dayjs(date);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
},
|
|
985
|
+
|
|
986
|
+
count(type, fromDateName, toDateName, toId = colName) {
|
|
987
|
+
let result = '';
|
|
988
|
+
|
|
989
|
+
const fromDateValue = getFieldValue(fromDateName, isMasterDetail);
|
|
990
|
+
const toDateValue = getFieldValue(toDateName, isMasterDetail);
|
|
991
|
+
|
|
992
|
+
if (
|
|
993
|
+
fromDateValue &&
|
|
994
|
+
fromDateValue !== 'Invalid Date' &&
|
|
995
|
+
toDateValue &&
|
|
996
|
+
toDateValue !== 'Invalid Date'
|
|
997
|
+
) {
|
|
998
|
+
let fromDate = this.formatDayjs(fromDateValue);
|
|
999
|
+
let toDate = this.formatDayjs(toDateValue);
|
|
1000
|
+
|
|
1001
|
+
let diff = '';
|
|
1002
|
+
switch (type) {
|
|
1003
|
+
case 'minutes':
|
|
1004
|
+
diff = toDate.diff(fromDate, 'minutes');
|
|
1005
|
+
break;
|
|
1006
|
+
case 'hours':
|
|
1007
|
+
diff = toDate.diff(fromDate, 'hours');
|
|
1008
|
+
break;
|
|
1009
|
+
case 'days':
|
|
1010
|
+
diff = toDate.diff(fromDate, 'days') + 1;
|
|
1011
|
+
break;
|
|
1012
|
+
case 'months':
|
|
1013
|
+
diff = toDate.diff(fromDate, 'months');
|
|
1014
|
+
break;
|
|
1015
|
+
case 'years':
|
|
1016
|
+
diff = toDate.diff(fromDate, 'years');
|
|
1017
|
+
break;
|
|
1018
|
+
|
|
1019
|
+
default:
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
result = diff.toString();
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
setValue(toId, result, isMasterDetail);
|
|
1026
|
+
// toElement.innerHTML = result;
|
|
1027
|
+
},
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
const countYears = (fromDateName, toDateName, toId) => {
|
|
1031
|
+
datetime.count('years', fromDateName, toDateName, toId);
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
const countMonths = (fromDateName, toDateName, toId) => {
|
|
1035
|
+
datetime.count('months', fromDateName, toDateName, toId);
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
const countDays = (fromDateName, toDateName, toId) => {
|
|
1039
|
+
datetime.count('days', fromDateName, toDateName, toId);
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
const countHours = (fromDateName, toDateName, toId) => {
|
|
1043
|
+
datetime.count('hours', fromDateName, toDateName, toId);
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
const countMinutes = (fromDateName, toDateName, toId) => {
|
|
1047
|
+
datetime.count('minutes', fromDateName, toDateName, toId);
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
const validateDatesRange = (startDate, toDate, dateType, count) => {
|
|
1051
|
+
window.validateDatesRange(startDate, toDate, dateType, count);
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
const validatePhoneNumber = name => {
|
|
1055
|
+
window.validatePhoneNumber(name);
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
const validateEmail = name => {
|
|
1059
|
+
window.validateEmail(name);
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
const convertNumberToText = value => {
|
|
1063
|
+
return new Intl.NumberFormat('vi-VN').format(Number(value));
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
const displayNumber = elementId => {
|
|
1067
|
+
const id = elementId ?? colName;
|
|
1068
|
+
const element = getElementById(id);
|
|
1069
|
+
if (element) {
|
|
1070
|
+
const value = getValue(id) ?? 0;
|
|
1071
|
+
if (!value.includes('.')) {
|
|
1072
|
+
element.innerHTML = new Intl.NumberFormat('vi-VN').format(Number(value));
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
const _displayNumber = elementId => {
|
|
1078
|
+
displayNumber(elementId);
|
|
1079
|
+
};
|
|
1080
|
+
|
|
1081
|
+
const validateForm = (isValid, elementIds, isMD) => {
|
|
1082
|
+
window.handleActionButtons(isValid, elementIds, isMD);
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
const compareNumbers = (compareString, isMD) => {
|
|
1086
|
+
const formular = handleFormularString(compareString, isMD);
|
|
1087
|
+
|
|
1088
|
+
window.handleActionButtons(eval(formular.math), formular.elementIds, isMD);
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
const compareNumbersMD = compareString => {
|
|
1092
|
+
compareNumbers(compareString, true);
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
const handleFormularString = (formularString, isMD) => {
|
|
1096
|
+
if (formularString?.length > 0) {
|
|
1097
|
+
formularString = formularString.replace(/\s/g, '');
|
|
1098
|
+
let name = '';
|
|
1099
|
+
let adding = false;
|
|
1100
|
+
const ids = [];
|
|
1101
|
+
|
|
1102
|
+
for (let i = 0; i < formularString.length; i++) {
|
|
1103
|
+
if (formularString[i] === '[') {
|
|
1104
|
+
adding = true;
|
|
1105
|
+
} else if (formularString[i] === ']') {
|
|
1106
|
+
ids.push(name);
|
|
1107
|
+
adding = false;
|
|
1108
|
+
name = '';
|
|
1109
|
+
} else if (adding === true) {
|
|
1110
|
+
name += formularString[i];
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
let formular = formularString;
|
|
1115
|
+
if (ids.length > 0) {
|
|
1116
|
+
ids.forEach(id => {
|
|
1117
|
+
const value = formatNumberString(
|
|
1118
|
+
isMD ? getValueMD(id) : getValue(id) ?? '0'
|
|
1119
|
+
);
|
|
1120
|
+
formular = formular.replaceAll(`[${id}]`, value);
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
return { math: formular, elementIds: ids };
|
|
1124
|
+
} else {
|
|
1125
|
+
return { math: formularString, elementIds: [] };
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
const valid = () => {
|
|
1130
|
+
window.handleActionButtons(true);
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
const invalid = () => {
|
|
1134
|
+
window.handleActionButtons(false);
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
const convertVIToENNumber = num => {
|
|
1138
|
+
num = num.replaceAll(',', '-');
|
|
1139
|
+
num = num.replaceAll('.', ',');
|
|
1140
|
+
num = num.replaceAll('-', '.');
|
|
1141
|
+
return num;
|
|
1142
|
+
};
|