js-gei 1.0.0

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.
Files changed (71) hide show
  1. package/Evaluator/ExpresionLogicService.ts +669 -0
  2. package/Evaluator/Parser/AddLeadZerosParse.ts +70 -0
  3. package/Evaluator/Parser/AppearParse.ts +67 -0
  4. package/Evaluator/Parser/BaseParse.ts +93 -0
  5. package/Evaluator/Parser/CalcDateParse.ts +73 -0
  6. package/Evaluator/Parser/CheckParse.ts +99 -0
  7. package/Evaluator/Parser/CommaParser.ts +17 -0
  8. package/Evaluator/Parser/ConcatParse.ts +34 -0
  9. package/Evaluator/Parser/CountParse.ts +26 -0
  10. package/Evaluator/Parser/EmptyParse.ts +41 -0
  11. package/Evaluator/Parser/ExistParse.ts +69 -0
  12. package/Evaluator/Parser/IfParse.ts +388 -0
  13. package/Evaluator/Parser/IfStategment.ts +345 -0
  14. package/Evaluator/Parser/InDetailParse.ts +109 -0
  15. package/Evaluator/Parser/InListParse.ts +57 -0
  16. package/Evaluator/Parser/LiteralValueParse.ts +36 -0
  17. package/Evaluator/Parser/LogicalOperatorParse.ts +16 -0
  18. package/Evaluator/Parser/OnlyExpressionParse.ts +137 -0
  19. package/Evaluator/Parser/OperatorParse.ts +17 -0
  20. package/Evaluator/Parser/StartsParse.ts +36 -0
  21. package/Evaluator/Parser/SubstrParse.ts +110 -0
  22. package/Evaluator/Parser/SumParse.ts +15 -0
  23. package/Evaluator/Parser/ToNullParser.ts +0 -0
  24. package/Evaluator/Parser/TrimParse.ts +30 -0
  25. package/Evaluator/Parser/UpperLoverParse.ts +41 -0
  26. package/Evaluator/Parser/ValueFromObjParse.ts +37 -0
  27. package/Evaluator/Parser/ValueParse.ts +61 -0
  28. package/HelperSessionStorage.ts +13 -0
  29. package/Interfaces/SchemaStruct.ts +28 -0
  30. package/Library/jsonrpc-2.0.js +869 -0
  31. package/Structure/InvoiceObj.ts +691 -0
  32. package/Structure/RecordArray.ts +145 -0
  33. package/Structure/RecordSingle.ts +1076 -0
  34. package/Structure/TableLevel.ts +248 -0
  35. package/dist/Evaluator/ExpresionLogicService.js +505 -0
  36. package/dist/Evaluator/Parser/AddLeadZerosParse.js +55 -0
  37. package/dist/Evaluator/Parser/AppearParse.js +48 -0
  38. package/dist/Evaluator/Parser/BaseParse.js +89 -0
  39. package/dist/Evaluator/Parser/CalcDateParse.js +54 -0
  40. package/dist/Evaluator/Parser/CheckParse.js +80 -0
  41. package/dist/Evaluator/Parser/CommaParser.js +13 -0
  42. package/dist/Evaluator/Parser/ConcatParse.js +29 -0
  43. package/dist/Evaluator/Parser/CountParse.js +23 -0
  44. package/dist/Evaluator/Parser/EmptyParse.js +35 -0
  45. package/dist/Evaluator/Parser/ExistParse.js +57 -0
  46. package/dist/Evaluator/Parser/IfParse.js +296 -0
  47. package/dist/Evaluator/Parser/IfStategment.js +287 -0
  48. package/dist/Evaluator/Parser/InDetailParse.js +79 -0
  49. package/dist/Evaluator/Parser/InListParse.js +40 -0
  50. package/dist/Evaluator/Parser/LiteralValueParse.js +26 -0
  51. package/dist/Evaluator/Parser/LogicalOperatorParse.js +13 -0
  52. package/dist/Evaluator/Parser/OnlyExpressionParse.js +106 -0
  53. package/dist/Evaluator/Parser/OperatorParse.js +13 -0
  54. package/dist/Evaluator/Parser/StartsParse.js +30 -0
  55. package/dist/Evaluator/Parser/SubstrParse.js +83 -0
  56. package/dist/Evaluator/Parser/SumParse.js +13 -0
  57. package/dist/Evaluator/Parser/ToNullParser.js +1 -0
  58. package/dist/Evaluator/Parser/TrimParse.js +25 -0
  59. package/dist/Evaluator/Parser/UpperLoverParse.js +32 -0
  60. package/dist/Evaluator/Parser/ValueFromObjParse.js +29 -0
  61. package/dist/Evaluator/Parser/ValueParse.js +59 -0
  62. package/dist/HelperSessionStorage.js +12 -0
  63. package/dist/Interfaces/SchemaStruct.js +2 -0
  64. package/dist/Structure/InvoiceObj.js +610 -0
  65. package/dist/Structure/RecordArray.js +102 -0
  66. package/dist/Structure/RecordSingle.js +950 -0
  67. package/dist/Structure/TableLevel.js +162 -0
  68. package/dist/index.js +19 -0
  69. package/index.ts +20 -0
  70. package/package.json +20 -0
  71. package/tsconfig.json +103 -0
@@ -0,0 +1,950 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecordSingle = void 0;
4
+ const IfStategment_1 = require("../Evaluator/Parser/IfStategment");
5
+ const TableLevel_1 = require("./TableLevel");
6
+ const BaseParse_1 = require("../Evaluator/Parser/BaseParse");
7
+ const ExpresionLogicService_1 = require("../Evaluator/ExpresionLogicService");
8
+ class RecordSingle {
9
+ constructor(obj, def, objectInfo, parent) {
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
11
+ this.Details = null;
12
+ this.byLevelSources = [
13
+ "MAPPEDINV",
14
+ "INVOICE",
15
+ "MAPPEDSYS",
16
+ "SYSTEM"
17
+ ];
18
+ this.Parent = parent;
19
+ if (((_a = this.Parent) === null || _a === void 0 ? void 0 : _a.Tablename) == "EU_Invoices") {
20
+ if (!obj["DeliveryType"]) {
21
+ obj["DeliveryType"] = "Domestic";
22
+ }
23
+ if (!obj["InvTotalVatAmountCC"]) {
24
+ obj["InvTotalVatAmountCC"] = 0;
25
+ }
26
+ //obj["BuyerRegNum"] = "BuyerRegNumValue";
27
+ /* if(this.Parent.Root?.service.aboutOrganisation["InvDateOpen"]==true)
28
+ {
29
+ if(obj["InvIssueDate"]==null)
30
+ {
31
+ let date = new Date();
32
+ obj["InvIssueDate"]=BaseParse.getIsoDateTime(date);
33
+ }
34
+ else
35
+ {
36
+ obj["InvIssueDate"]=obj["InvIssueDate"]
37
+ }
38
+ }
39
+ else
40
+ {
41
+
42
+ if(obj["Step"]<35&&(this.Parent.Root?.service.aboutOrganisation["InvDateOpen"]==false||this.Parent.Root?.service.aboutOrganisation["InvDateOpen"]==null))
43
+ {
44
+ let date = new Date();
45
+ obj["InvIssueDate"]=BaseParse.getIsoDateTime(date);
46
+ }
47
+ else
48
+ {
49
+ obj["InvIssueDate"]=obj["InvIssueDate"]
50
+ }
51
+
52
+ }*/
53
+ }
54
+ else if (((_b = this.Parent) === null || _b === void 0 ? void 0 : _b.Tablename) == "EU_Invoices_Items") {
55
+ if (((_d = (_c = this.Parent.Root) === null || _c === void 0 ? void 0 : _c.GetMasterRecord()) === null || _d === void 0 ? void 0 : _d.Record.InvSaleTypeSC__Code) == "Retailsale") {
56
+ // obj["ItemRetailPriceInp"] = obj["ItemRetailPrice"]??0.0;
57
+ }
58
+ }
59
+ const dateCurrent = new Date();
60
+ if (((_e = this.Parent) === null || _e === void 0 ? void 0 : _e.Tablename) != null) {
61
+ const tablePart = objectInfo[(_f = this.Parent) === null || _f === void 0 ? void 0 : _f.Tablename];
62
+ if (tablePart != null) {
63
+ const keys = Object.keys(tablePart);
64
+ for (let i = 0; i < keys.length; i++) {
65
+ const key = keys[i];
66
+ if (key == "InvDueDate") {
67
+ if (obj[key] != null) {
68
+ obj[key] = BaseParse_1.BaseParse.parseDate(obj[key]);
69
+ }
70
+ else {
71
+ let copy = new Date(dateCurrent.valueOf());
72
+ copy.setDate(copy.getDate() + 15);
73
+ obj["InvDueDate"] = copy;
74
+ }
75
+ continue;
76
+ }
77
+ if (tablePart[key].TypeDDD == "Date" || tablePart[key].TypeDDD == "DateTime") {
78
+ if (obj[key] == null && [""].indexOf(key) != -1) {
79
+ let copy = new Date(dateCurrent.valueOf());
80
+ obj[key] = copy;
81
+ }
82
+ else if (obj[key] != null) {
83
+ if (tablePart[key].TypeDDD == "Date") {
84
+ obj[key] = BaseParse_1.BaseParse.parseDate(obj[key]);
85
+ }
86
+ else if (tablePart[key].TypeDDD == "DateTime") {
87
+ obj[key] = BaseParse_1.BaseParse.parseDateTime(obj[key]);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ if (((_g = this.Parent) === null || _g === void 0 ? void 0 : _g.Tablename) == "EU_Invoices") {
95
+ }
96
+ if (obj["_details"] != null) {
97
+ this.Details = [];
98
+ for (let key in obj["_details"]) {
99
+ this.Details.push(new TableLevel_1.TableLevel(key, obj["_details"][key], def["_details"][key], objectInfo, (_j = (_h = this.Parent) === null || _h === void 0 ? void 0 : _h.Root) !== null && _j !== void 0 ? _j : null));
100
+ }
101
+ delete obj["_details"];
102
+ }
103
+ this.Record = obj;
104
+ if (parent != null) {
105
+ this.TableObjectInfo = objectInfo[parent.Tablename];
106
+ }
107
+ }
108
+ GetObject() {
109
+ var obj = JSON.parse(JSON.stringify(this.Record));
110
+ if (this.Details != null) {
111
+ let details = JSON.parse("{}");
112
+ for (let i = 0; i < this.Details.length; i++) {
113
+ let det = this.Details[i].GetObject();
114
+ if (det == null) {
115
+ continue;
116
+ }
117
+ details[this.Details[i].Tablename] = det;
118
+ }
119
+ obj["_details"] = details;
120
+ }
121
+ return obj;
122
+ }
123
+ TranslateObj(obj) {
124
+ if (this.Details != null) {
125
+ for (let i = 0; i < this.Details.length; i++) {
126
+ this.Details[i].TranslateObj(obj);
127
+ }
128
+ }
129
+ var keys = Object.keys(this.Record);
130
+ var keysTr = Object.keys(obj);
131
+ var keysFilter = keys.filter(x => keysTr.indexOf(x) != -1);
132
+ if (keysFilter.length > 0) {
133
+ keysFilter.forEach(x => {
134
+ var value = obj[x].data[this.Record[obj[x].key]];
135
+ if (value != null) {
136
+ this.Record[x] = obj[x].data[this.Record[obj[x].key]];
137
+ }
138
+ });
139
+ }
140
+ }
141
+ Inicialize(skippedLevels) {
142
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
143
+ if (this.Details != null) {
144
+ for (let i = 0; i < this.Details.length; i++) {
145
+ this.Details[i].Inicialize(skippedLevels);
146
+ }
147
+ }
148
+ if (((_a = this.Parent) === null || _a === void 0 ? void 0 : _a.Tablename) != null && skippedLevels.indexOf((_b = this.Parent) === null || _b === void 0 ? void 0 : _b.Tablename) != -1) {
149
+ return;
150
+ }
151
+ if (((_c = this.Parent) === null || _c === void 0 ? void 0 : _c.Tablename) == "EU_Invoices_Items") {
152
+ const nonNullFields = ["Quantity", "LineAllowPercent"];
153
+ if (((_e = (_d = this.Parent.Root) === null || _d === void 0 ? void 0 : _d.GetMasterRecord()) === null || _e === void 0 ? void 0 : _e.Record.InvSaleTypeSC__Code) == "Retailsale") {
154
+ nonNullFields.push("ItemRetailPriceInp");
155
+ }
156
+ else {
157
+ nonNullFields.push("ItemNetPrice");
158
+ }
159
+ for (let i = 0; i < nonNullFields.length; i++) {
160
+ if (this.Record[nonNullFields[i]] == null) {
161
+ this.Record[nonNullFields[i]] = 0;
162
+ }
163
+ }
164
+ }
165
+ let map = new Map();
166
+ for (let key in this.TableObjectInfo) {
167
+ const source = this.TableObjectInfo[key].Source;
168
+ if (this.byLevelSources.indexOf(source) == -1) {
169
+ continue;
170
+ }
171
+ if (!map.has(source)) {
172
+ map.set(source, []);
173
+ }
174
+ (_f = map.get(source)) === null || _f === void 0 ? void 0 : _f.push(this.TableObjectInfo[key]);
175
+ /*if ((this.TableObjectInfo[key].Source == "SYSTEM"||this.TableObjectInfo[key].Source == "MAPPEDINV") && this.TableObjectInfo[key].GetValueFrom == "Expression" && this.TableObjectInfo[key].CalcPhase != null) {
176
+ array.push(this.TableObjectInfo[key]);
177
+ }*/
178
+ }
179
+ // console.log(map)
180
+ if (map.size == 0) {
181
+ return;
182
+ }
183
+ for (let x = 0; x < this.byLevelSources.length; x++) {
184
+ const key = this.byLevelSources[x];
185
+ if (!map.has(key)) {
186
+ continue;
187
+ }
188
+ // console.log(key);
189
+ const array = map.get(key);
190
+ if (array == null) {
191
+ continue;
192
+ }
193
+ var sortedArray = array.sort((n1, n2) => {
194
+ if (n1.CalcPhase > n2.CalcPhase) {
195
+ return 1;
196
+ }
197
+ if (n1.CalcPhase < n2.CalcPhase) {
198
+ return -1;
199
+ }
200
+ return 0;
201
+ });
202
+ // console.log(sortedArray)
203
+ for (var i = 0; i < sortedArray.length; i++) {
204
+ let item = sortedArray[i];
205
+ if (item.CreateNewInit == "Suggested") {
206
+ if (item.FieldName == "ItemClassCode" || item.FieldName == "ItemClassCodeSchID") {
207
+ if (this.Record[item.FieldName] != null) {
208
+ continue;
209
+ }
210
+ }
211
+ else {
212
+ continue;
213
+ }
214
+ }
215
+ if (item.CreateNewInit == "Fixed") {
216
+ continue;
217
+ }
218
+ if (item.Type != "decimal" && item.Type != "integer" && item.Type != "boolean" && item.Type != "string") {
219
+ //if (item.Type != "decimal" && item.Type != "integer" && item.Type != "boolean") {
220
+ continue;
221
+ }
222
+ if (item.EvalOnlyIfEmpty === true && this.Record[item.FieldName] != null) {
223
+ continue;
224
+ }
225
+ // console.log('item: ' + JSON.stringify(item))
226
+ switch (item.GetValueFrom) {
227
+ case "Expression":
228
+ {
229
+ try {
230
+ if (item.ValueExpression == null) {
231
+ continue;
232
+ }
233
+ let ex = this.ParseExpressionAndReturnValue((_g = item.ValueExpression) !== null && _g !== void 0 ? _g : "", item);
234
+ console.log("Parsed:" + ex);
235
+ if (ex == null) {
236
+ this.Record[item.FieldName] = null;
237
+ continue;
238
+ }
239
+ if (typeof ex != "string") {
240
+ this.Record[item.FieldName] = ex;
241
+ continue;
242
+ }
243
+ // console.log(ex);
244
+ try {
245
+ switch (ex.toUpperCase()) {
246
+ case "FALSE":
247
+ {
248
+ this.Record[item.FieldName] = false;
249
+ continue;
250
+ }
251
+ case "TRUE":
252
+ {
253
+ this.Record[item.FieldName] = true;
254
+ continue;
255
+ }
256
+ }
257
+ if (item.Type == "decimal" || item.Type == "integer" || item.Type == "boolean") {
258
+ let evaluated = eval(ex !== null && ex !== void 0 ? ex : "");
259
+ if (evaluated != "") {
260
+ if (item.RoundTo != null) {
261
+ evaluated = BaseParse_1.BaseParse.roundUp(evaluated, item.RoundTo);
262
+ }
263
+ }
264
+ this.Record[item.FieldName] = evaluated;
265
+ }
266
+ else {
267
+ this.Record[item.FieldName] = ex;
268
+ }
269
+ // console.log(eval(ex ?? ""));
270
+ }
271
+ catch (e) {
272
+ console.error(e);
273
+ }
274
+ }
275
+ catch (ee) {
276
+ console.log(ee);
277
+ }
278
+ break;
279
+ }
280
+ case "Mappings":
281
+ {
282
+ if (this.Record[item.FieldName] == null) {
283
+ continue;
284
+ }
285
+ if (((_j = (_h = this.Parent) === null || _h === void 0 ? void 0 : _h.Root) === null || _j === void 0 ? void 0 : _j.mappings[item.FieldName]) == null) {
286
+ console.error("Can't find mapping for " + item.FieldName);
287
+ continue;
288
+ }
289
+ const array = (_l = (_k = this.Parent) === null || _k === void 0 ? void 0 : _k.Root) === null || _l === void 0 ? void 0 : _l.mappings[item.FieldName];
290
+ for (let m = 0; m < array.length; m++) {
291
+ const map = array[m];
292
+ let valid = false;
293
+ if (map["value"] != null && map["value"] == this.Record[item.FieldName]) {
294
+ valid = true;
295
+ }
296
+ else if (map["value"] == null) {
297
+ valid = true;
298
+ }
299
+ if (valid == false) {
300
+ continue;
301
+ }
302
+ const destField = map.map["DestField"];
303
+ const destvalue = map.map["DestValue"];
304
+ let ex = this.ParseExpressionAndReturnValue(destvalue, item);
305
+ console.log("ParsedMap:" + ex);
306
+ try {
307
+ if (typeof ex != "string") {
308
+ this.Record[destField] = ex;
309
+ continue;
310
+ }
311
+ switch ((ex !== null && ex !== void 0 ? ex : "").toUpperCase()) {
312
+ case "FALSE":
313
+ {
314
+ this.Record[destField] = false;
315
+ continue;
316
+ }
317
+ case "TRUE":
318
+ {
319
+ this.Record[destField] = true;
320
+ continue;
321
+ }
322
+ }
323
+ let evaluated = eval(ex !== null && ex !== void 0 ? ex : "");
324
+ if (evaluated != "") {
325
+ if (item.RoundTo != null) {
326
+ evaluated = BaseParse_1.BaseParse.roundUp(evaluated, item.RoundTo);
327
+ }
328
+ }
329
+ this.Record[destField] = evaluated;
330
+ // console.log("Mapped:" + destField + " Value:" + ex + "Evaluated:" + evaluated)
331
+ }
332
+ catch (e) {
333
+ console.error(e);
334
+ }
335
+ break;
336
+ }
337
+ break;
338
+ }
339
+ }
340
+ }
341
+ }
342
+ //todo here need to start initin like on server
343
+ }
344
+ ParseExpressionAndReturnValue(valueExp, schemaitem) {
345
+ return this.ParseExpressionAndReturnValueNew(valueExp, schemaitem);
346
+ }
347
+ ParseExpressionAndReturnValueNew(valueExp, schemaitem) {
348
+ var _a;
349
+ if (((_a = this.Parent) === null || _a === void 0 ? void 0 : _a.Root) == null) {
350
+ return null;
351
+ }
352
+ var val = ExpresionLogicService_1.ExpresionLogicService.ParseAndFillExpression(valueExp, schemaitem, this.Parent.Root, this, this.Record, false, false);
353
+ return val;
354
+ }
355
+ ParseExpressionAndReturnValueOld(valueExp, schemaitem) {
356
+ var _a, _b, _c, _d, _e, _f, _g, _h;
357
+ if (valueExp.indexOf("%") == -1) {
358
+ if (valueExp == "null") {
359
+ return null;
360
+ }
361
+ if (valueExp.indexOf("SUM(") == -1 && valueExp.indexOf("IF(") == -1 && valueExp.indexOf("COUNT(") == -1 && valueExp.indexOf("indetail(") == -1) {
362
+ return valueExp;
363
+ }
364
+ }
365
+ let valueExpression = valueExp;
366
+ const listCommands = [];
367
+ let currentCommand = "";
368
+ while (valueExpression.length > 0) {
369
+ if (valueExpression.startsWith("%")) {
370
+ listCommands.push(currentCommand);
371
+ currentCommand = "%";
372
+ valueExpression = valueExpression.substring(1);
373
+ currentCommand += valueExpression.substring(0, valueExpression.indexOf("%") + 1);
374
+ valueExpression = valueExpression.substring(valueExpression.indexOf("%") + 1);
375
+ listCommands.push(currentCommand);
376
+ currentCommand = "";
377
+ continue;
378
+ }
379
+ if (valueExpression.startsWith("N.%")) {
380
+ listCommands.push(currentCommand);
381
+ currentCommand = "%";
382
+ valueExpression = valueExpression.substring(3);
383
+ currentCommand += valueExpression.substring(0, valueExpression.indexOf("%") + 1);
384
+ valueExpression = valueExpression.substring(valueExpression.indexOf("%") + 1);
385
+ listCommands.push(currentCommand);
386
+ currentCommand = "";
387
+ continue;
388
+ }
389
+ if (valueExpression.startsWith("(")) {
390
+ var end = this.FindEnd(valueExpression);
391
+ listCommands.push(currentCommand);
392
+ currentCommand = "";
393
+ currentCommand += valueExpression.substring(0, end + 1);
394
+ valueExpression = valueExpression.substring(end + 1);
395
+ listCommands.push(currentCommand);
396
+ currentCommand = "";
397
+ continue;
398
+ }
399
+ if (valueExpression.startsWith("IF(")) {
400
+ var end = this.FindEnd(valueExpression);
401
+ listCommands.push(currentCommand);
402
+ currentCommand = "";
403
+ currentCommand += valueExpression.substring(0, end + 1);
404
+ valueExpression = valueExpression.substring(end + 1);
405
+ listCommands.push(currentCommand);
406
+ currentCommand = "";
407
+ continue;
408
+ }
409
+ if (valueExpression.startsWith("IF (")) {
410
+ var end = this.FindEnd(valueExpression);
411
+ listCommands.push(currentCommand);
412
+ currentCommand = "";
413
+ currentCommand += valueExpression.substring(0, end + 1);
414
+ valueExpression = valueExpression.substring(end + 1);
415
+ listCommands.push(currentCommand);
416
+ currentCommand = "";
417
+ continue;
418
+ }
419
+ if (valueExpression.startsWith("SUM(")) {
420
+ var end = this.FindEnd(valueExpression);
421
+ listCommands.push(currentCommand);
422
+ currentCommand = "";
423
+ currentCommand += valueExpression.substring(0, end + 1);
424
+ valueExpression = valueExpression.substring(end + 1);
425
+ listCommands.push(currentCommand);
426
+ currentCommand = "";
427
+ continue;
428
+ }
429
+ if (valueExpression.startsWith("COUNT(")) {
430
+ var end = this.FindEnd(valueExpression);
431
+ listCommands.push(currentCommand);
432
+ currentCommand = "";
433
+ currentCommand += valueExpression.substring(0, end + 1);
434
+ valueExpression = valueExpression.substring(end + 1);
435
+ listCommands.push(currentCommand);
436
+ currentCommand = "";
437
+ continue;
438
+ }
439
+ if (valueExpression.toUpperCase().startsWith("INDETAIL(")) {
440
+ var end = this.FindEnd(valueExpression);
441
+ listCommands.push(currentCommand);
442
+ currentCommand = "";
443
+ currentCommand += valueExpression.substring(0, end + 1);
444
+ valueExpression = valueExpression.substring(end + 1);
445
+ listCommands.push(currentCommand);
446
+ currentCommand = "";
447
+ continue;
448
+ }
449
+ if (valueExpression.startsWith("TRIM(")) {
450
+ var end = this.FindEnd(valueExpression);
451
+ listCommands.push(currentCommand);
452
+ currentCommand = "";
453
+ currentCommand += valueExpression.substring(0, end + 1);
454
+ valueExpression = valueExpression.substring(end + 1);
455
+ listCommands.push(currentCommand);
456
+ currentCommand = "";
457
+ continue;
458
+ }
459
+ if (valueExpression.startsWith("CALCDATE(")) {
460
+ var end = this.FindEnd(valueExpression);
461
+ listCommands.push(currentCommand);
462
+ currentCommand = "";
463
+ currentCommand += valueExpression.substring(0, end + 1);
464
+ valueExpression = valueExpression.substring(end + 1);
465
+ listCommands.push(currentCommand);
466
+ currentCommand = "";
467
+ continue;
468
+ }
469
+ currentCommand += valueExpression.substring(0, 1);
470
+ valueExpression = valueExpression.substring(1);
471
+ }
472
+ if (currentCommand != "") {
473
+ listCommands.push(currentCommand);
474
+ }
475
+ // console.log(listCommands);
476
+ let builder = "";
477
+ for (let i = 0; i < listCommands.length; i++) {
478
+ let l = listCommands[i];
479
+ if (l.startsWith("%") && l.endsWith("%")) {
480
+ var value = this.ValueExpresion(l);
481
+ if (value != null) {
482
+ builder += value;
483
+ }
484
+ else {
485
+ builder += "null";
486
+ }
487
+ //TODO what is Null??
488
+ }
489
+ else if (l.startsWith("(")) {
490
+ var cur = l.substring(1, l.length - 1);
491
+ builder += "(" + this.ParseExpressionAndReturnValue(cur, schemaitem) + ")";
492
+ }
493
+ else if (l.startsWith("IF(") || l.startsWith("IF (")) {
494
+ let ifStat = "";
495
+ if (l.startsWith("IF(")) {
496
+ ifStat = l.substring(3, l.length - 1);
497
+ }
498
+ else {
499
+ ifStat = l.substring(4, l.length - 1);
500
+ }
501
+ var split = ifStat.split(",");
502
+ if (split.length != 3) {
503
+ ifStat = (_a = this.ParseExpressionAndReturnValue(ifStat, schemaitem)) !== null && _a !== void 0 ? _a : "";
504
+ split = ifStat.split(",");
505
+ if (split.length != 3) {
506
+ continue;
507
+ }
508
+ }
509
+ var ifStategment = new IfStategment_1.IfStategment(split[0]);
510
+ let value = null;
511
+ if (ifStategment.Validate(this)) {
512
+ value = this.ParseExpressionAndReturnValue(split[1], schemaitem);
513
+ }
514
+ else {
515
+ value = this.ParseExpressionAndReturnValue(split[2], schemaitem);
516
+ }
517
+ if (value == null) {
518
+ builder += "null";
519
+ }
520
+ else {
521
+ builder += value;
522
+ }
523
+ }
524
+ else if (l.startsWith("CALCDATE(")) {
525
+ var tAndF = l.substring(9, l.length - 1);
526
+ /*const split=tAndF.split(",");
527
+ let datePart=this.ParseExpressionAndReturnValue(split[0],schemaitem);
528
+ const offsetany:any=this.ParseExpressionAndReturnValue(split[1],schemaitem);
529
+ let date1=new Date();
530
+ if(datePart instanceof Date)
531
+ {
532
+ date1=datePart;
533
+ }
534
+
535
+ let offset:number=0;
536
+ if(offsetany)
537
+ {
538
+ offset=parseInt(offsetany);
539
+ }
540
+ let date:Date=new Date(date1);
541
+ date.setDate(date.getDate()+offset);
542
+
543
+ return this.getIsoDateTime(date);*/
544
+ }
545
+ else if (l.startsWith("SUM(")) {
546
+ var tAndF = l.substring(4, l.length - 1);
547
+ builder += (_c = (_b = this.Parent) === null || _b === void 0 ? void 0 : _b.Root) === null || _c === void 0 ? void 0 : _c.SumByKey(tAndF);
548
+ }
549
+ else if (l.toUpperCase().startsWith("INDETAIL(")) {
550
+ try {
551
+ var tAndF = l.substring(9, l.length - 1);
552
+ console.log("tAndF:" + tAndF);
553
+ var index = this.FindEnd(tAndF);
554
+ var valStirng = tAndF.substring(1, index);
555
+ console.log("valStirng:" + tAndF);
556
+ var values = valStirng.split(",");
557
+ var tableAndField = tAndF.substring(index + 2);
558
+ console.log("tableAndField:" + tableAndField);
559
+ var split = tableAndField.split(".");
560
+ var table = split[0];
561
+ var field = split[1];
562
+ var level = (_e = (_d = this.Parent) === null || _d === void 0 ? void 0 : _d.Root) === null || _e === void 0 ? void 0 : _e.FindTableLevel(table);
563
+ if (level == null) {
564
+ return "false";
565
+ }
566
+ if (level.Records == null) {
567
+ return "false";
568
+ }
569
+ for (var x = 0; x < level.Records.Records.length; x++) {
570
+ if (values.indexOf(level.Records.Records[x].Record[field]) != -1) {
571
+ return "true";
572
+ }
573
+ }
574
+ return "false";
575
+ }
576
+ catch (exc) {
577
+ console.error(exc);
578
+ return "false";
579
+ }
580
+ }
581
+ else if (l.startsWith("TRIM(")) {
582
+ try {
583
+ var tAndF = l.substring(5, l.length - 1);
584
+ var value = this.ValueExpresion(tAndF);
585
+ if (value != null) {
586
+ value = value.trim();
587
+ }
588
+ builder += value;
589
+ }
590
+ catch (EX) {
591
+ }
592
+ }
593
+ else if (l.startsWith("COUNT(")) {
594
+ var table = l.substring(6, l.length - 1);
595
+ var level = (_g = (_f = this.Parent) === null || _f === void 0 ? void 0 : _f.Root) === null || _g === void 0 ? void 0 : _g.FindTableLevel(table);
596
+ if (level == null) {
597
+ builder += "-1";
598
+ }
599
+ else {
600
+ builder += (_h = level.Records) === null || _h === void 0 ? void 0 : _h.Records.length;
601
+ }
602
+ }
603
+ else {
604
+ builder += l;
605
+ }
606
+ }
607
+ if (builder == "" || builder == null) {
608
+ if (builder.trim() == "null") {
609
+ return null;
610
+ }
611
+ }
612
+ return builder;
613
+ }
614
+ valueToType(value) {
615
+ if (value == null || value == "null") {
616
+ return null;
617
+ }
618
+ if (typeof value !== "string") {
619
+ return value;
620
+ }
621
+ if (value.toLocaleLowerCase() == "true") {
622
+ return true;
623
+ }
624
+ if (value.toLocaleLowerCase() == "false") {
625
+ return false;
626
+ }
627
+ if (!isNaN(parseFloat(value))) {
628
+ return parseFloat(value);
629
+ }
630
+ return value;
631
+ }
632
+ ValueExpresion(exp) {
633
+ var _a, _b, _c;
634
+ if (exp == null) {
635
+ return null;
636
+ }
637
+ if (!exp.startsWith("%") || !exp.endsWith("%")) {
638
+ return this.valueToType(exp);
639
+ }
640
+ let tabelAndKey = exp.substring(1, exp.length - 1);
641
+ let split = tabelAndKey.split(".");
642
+ var prefix = split[0];
643
+ switch (prefix) {
644
+ case "V":
645
+ {
646
+ console.warn("V not supported!");
647
+ return null;
648
+ }
649
+ case "E":
650
+ {
651
+ const tableName = split[1];
652
+ const field = split[2];
653
+ if (tableName == "EU_AOrg") {
654
+ // return this.Parent?.Root?.service.aboutOrganisation[field];
655
+ }
656
+ else if (tableName == "EU_SCR") {
657
+ //return this.Parent?.Root?.service.aboutOrganisation[field];
658
+ }
659
+ else if (tableName == "Session") {
660
+ /*var instance= this.Parent?.Root?.service.sessionInfo;
661
+ var path = "";
662
+ for (var i = 2; i < split.length; i++)
663
+ {
664
+ instance=instance[split[i]]
665
+ if(!instance)
666
+ {
667
+ return null;
668
+ }
669
+ }
670
+ return this.valueToType(instance);*/
671
+ }
672
+ else {
673
+ console.warn("Other E not supported!");
674
+ return null;
675
+ }
676
+ }
677
+ case "S":
678
+ {
679
+ console.warn("S not supported!");
680
+ return null;
681
+ }
682
+ default:
683
+ {
684
+ if (split.length == 2) {
685
+ const table = split[0];
686
+ if (table == ((_a = this.Parent) === null || _a === void 0 ? void 0 : _a.Tablename)) {
687
+ return this.Record[split[1]];
688
+ }
689
+ else {
690
+ let tableLevel = (_c = (_b = this.Parent) === null || _b === void 0 ? void 0 : _b.Root) === null || _c === void 0 ? void 0 : _c.FindTableLevel(table);
691
+ if (tableLevel != null) {
692
+ if (tableLevel.Record != null) {
693
+ if ((tableLevel === null || tableLevel === void 0 ? void 0 : tableLevel.Record) != null) {
694
+ return this.valueToType(tableLevel === null || tableLevel === void 0 ? void 0 : tableLevel.Record.Record[split[1]]);
695
+ }
696
+ }
697
+ }
698
+ }
699
+ }
700
+ break;
701
+ }
702
+ }
703
+ return null;
704
+ }
705
+ FindEnd(expresion) {
706
+ var bC = 0;
707
+ var bO = 0;
708
+ for (var i = 0; i < expresion.length; i++) {
709
+ if (expresion.substring(i, i + 1) == "(") {
710
+ bO++;
711
+ }
712
+ else if (expresion.substring(i, i + 1) == ")") {
713
+ bC++;
714
+ }
715
+ if (bO > 0 && bO == bC) {
716
+ return i;
717
+ }
718
+ }
719
+ return -1;
720
+ }
721
+ getSaveObject(objectInfoUIEdit) {
722
+ var _a, _b, _c;
723
+ const result = {};
724
+ if (this.Details != null) {
725
+ const details = {};
726
+ for (let i = 0; i < this.Details.length; i++) {
727
+ const obj = this.Details[i].getSaveObject(objectInfoUIEdit);
728
+ if (obj == null) {
729
+ continue;
730
+ }
731
+ details[this.Details[i].Tablename] = obj;
732
+ }
733
+ if (Object.keys(details).length > 0) {
734
+ result["_details"] = details;
735
+ }
736
+ }
737
+ if (((_a = this.Parent) === null || _a === void 0 ? void 0 : _a.Tablename) == null) {
738
+ return null;
739
+ }
740
+ const tablePart = objectInfoUIEdit[(_b = this.Parent) === null || _b === void 0 ? void 0 : _b.Tablename];
741
+ const keys = Object.keys(tablePart);
742
+ for (let i = 0; i < keys.length; i++) {
743
+ const key = keys[i];
744
+ /*if ("InvIssueDate"==key&&this.Parent?.Tablename == "EU_Invoices") {
745
+ if(this.Parent.Root?.service.aboutOrganisation["InvDateOpen"]==null||
746
+ this.Parent.Root?.service.aboutOrganisation["InvDateOpen"]==false)
747
+ {
748
+
749
+ let date = new Date();
750
+ result[key]=BaseParse.getIsoDateTime(date);
751
+ }
752
+ else
753
+ {
754
+ result[key]=BaseParse.getIsoDateTime(this.Record[key]);
755
+ }
756
+ continue;
757
+ }*/
758
+ const type = tablePart[key].TypeDDD;
759
+ // console.log('type: ' + type);
760
+ switch (type) {
761
+ case "Date": {
762
+ result[key] = BaseParse_1.BaseParse.getIsoDate(this.Record[key]);
763
+ break;
764
+ }
765
+ case "DateTime": {
766
+ result[key] = BaseParse_1.BaseParse.getIsoDateTime(this.Record[key]);
767
+ break;
768
+ }
769
+ default: {
770
+ result[key] = this.Record[key];
771
+ break;
772
+ }
773
+ }
774
+ }
775
+ if (this.Record["Id"] != null) {
776
+ result["Id"] = this.Record["Id"];
777
+ }
778
+ if (((_c = this.Parent) === null || _c === void 0 ? void 0 : _c.Tablename) == "EU_Invoices") {
779
+ /* result["InvTotalVatAmountCCInp"]=this.Record["InvTotalVatAmountCC"];
780
+ result["InvAmountInclVatInp"]=this.Record["InvAmountInclVat"];
781
+ if(this.Parent.Root?.service.BuyerRefArray!=null)
782
+ {
783
+ const savedTags=[];
784
+ if(this.Record["__AdditonalRef"].length>0)
785
+ {
786
+ for(let x=0;x<this.Record["__AdditonalRef"].length;x++)
787
+ {
788
+ const addRef=this.Record["__AdditonalRef"][x];
789
+ for(let i=0;i<this.Parent.Root?.service.BuyerRefArray.length;i++)
790
+ {
791
+ const item=this.Parent.Root?.service.BuyerRefArray[i];
792
+ if(addRef.key==item.Tag&&addRef.value!=null)
793
+ {
794
+
795
+ result[item.WriteToField]=addRef.value;
796
+ savedTags.push(item.Tag);
797
+ }
798
+
799
+ }
800
+ }
801
+ }
802
+
803
+ for(let i=0;i<this.Parent.Root?.service.BuyerRefArray.length;i++)
804
+ {
805
+ const item=this.Parent.Root?.service.BuyerRefArray[i];
806
+ if(savedTags.indexOf(item.Tag)==-1)
807
+ {
808
+ result[item.WriteToField]=null;
809
+ }
810
+ }
811
+
812
+ }*/
813
+ //result["DeliveryDateActual"]=result["InvEndDate"];
814
+ }
815
+ if (Object.keys(result).length > 0) {
816
+ return result;
817
+ }
818
+ return null;
819
+ }
820
+ getFullObject(objectInfo) {
821
+ var _a, _b, _c;
822
+ const result = {};
823
+ if (this.Details != null) {
824
+ const details = {};
825
+ for (let i = 0; i < this.Details.length; i++) {
826
+ const obj = this.Details[i].getSaveObject(objectInfo);
827
+ if (obj == null) {
828
+ continue;
829
+ }
830
+ details[this.Details[i].Tablename] = obj;
831
+ }
832
+ if (Object.keys(details).length > 0) {
833
+ result["_details"] = details;
834
+ }
835
+ }
836
+ if (((_a = this.Parent) === null || _a === void 0 ? void 0 : _a.Tablename) == null) {
837
+ return null;
838
+ }
839
+ const tablePart = objectInfo[(_b = this.Parent) === null || _b === void 0 ? void 0 : _b.Tablename];
840
+ const keys = Object.keys(tablePart);
841
+ for (let i = 0; i < keys.length; i++) {
842
+ const key = keys[i];
843
+ /*if ("InvIssueDate"==key&&this.Parent?.Tablename == "EU_Invoices") {
844
+ if(this.Parent.Root?.service.aboutOrganisation["InvDateOpen"]==null||
845
+ this.Parent.Root?.service.aboutOrganisation["InvDateOpen"]==false)
846
+ {
847
+
848
+ let date = new Date();
849
+ result[key]=BaseParse.getIsoDateTime(date);
850
+ }
851
+ else
852
+ {
853
+ result[key]=BaseParse.getIsoDateTime(this.Record[key]);
854
+ }
855
+ continue;
856
+ }*/
857
+ const type = tablePart[key].TypeDDD;
858
+ // console.log('type: ' + type);
859
+ switch (type) {
860
+ case "Date": {
861
+ result[key] = BaseParse_1.BaseParse.getIsoDate(this.Record[key]);
862
+ break;
863
+ }
864
+ case "DateTime": {
865
+ result[key] = BaseParse_1.BaseParse.getIsoDateTime(this.Record[key]);
866
+ break;
867
+ }
868
+ default: {
869
+ result[key] = this.Record[key];
870
+ break;
871
+ }
872
+ }
873
+ }
874
+ if (this.Record["Id"] != null) {
875
+ result["Id"] = this.Record["Id"];
876
+ }
877
+ if (((_c = this.Parent) === null || _c === void 0 ? void 0 : _c.Tablename) == "EU_Invoices") {
878
+ result["InvTotalVatAmountCCInp"] = this.Record["InvTotalVatAmountCC"];
879
+ result["InvAmountInclVatInp"] = this.Record["InvAmountInclVat"];
880
+ /*if(this.Parent.Root?.service.BuyerRefArray!=null)
881
+ {
882
+ const savedTags=[];
883
+ if(this.Record["__AdditonalRef"].length>0)
884
+ {
885
+ for(let x=0;x<this.Record["__AdditonalRef"].length;x++)
886
+ {
887
+ const addRef=this.Record["__AdditonalRef"][x];
888
+ for(let i=0;i<this.Parent.Root?.service.BuyerRefArray.length;i++)
889
+ {
890
+ const item=this.Parent.Root?.service.BuyerRefArray[i];
891
+ if(addRef.key==item.Tag&&addRef.value!=null)
892
+ {
893
+
894
+ result[item.WriteToField]=addRef.value;
895
+ savedTags.push(item.Tag);
896
+ }
897
+
898
+ }
899
+ }
900
+ }
901
+
902
+ for(let i=0;i<this.Parent.Root?.service.BuyerRefArray.length;i++)
903
+ {
904
+ const item=this.Parent.Root?.service.BuyerRefArray[i];
905
+ if(savedTags.indexOf(item.Tag)==-1)
906
+ {
907
+ result[item.WriteToField]=null;
908
+ }
909
+ }
910
+
911
+ }*/
912
+ //result["DeliveryDateActual"]=result["InvEndDate"];
913
+ }
914
+ if (Object.keys(result).length > 0) {
915
+ return result;
916
+ }
917
+ return null;
918
+ }
919
+ Validate() {
920
+ if (this.TableObjectInfo == null) {
921
+ return null;
922
+ }
923
+ const detailsErrors = [];
924
+ const validateDetailsErrors = [];
925
+ if (this.Details != null) {
926
+ for (let i = 0; i < this.Details.length; i++) {
927
+ let err = this.Details[i].Validate();
928
+ if (err != null) {
929
+ detailsErrors.push(err.combineErrors);
930
+ validateDetailsErrors.push(...err.validateErrors);
931
+ // console.log('err record single validateDetailsErrors:' + JSON.stringify(validateDetailsErrors));
932
+ }
933
+ }
934
+ }
935
+ const keys = Object.keys(this.TableObjectInfo);
936
+ const missingKeys = [];
937
+ for (let i = 0; i < keys.length; i++) {
938
+ let item = this.TableObjectInfo[keys[i]];
939
+ // console.log('item["Mandatory"]' + JSON.stringify(item));
940
+ if (item["Mandatory"] == true && (this.Record[keys[i]] === null || (item.Type === 'string' && this.Record[keys[i]] === ''))) {
941
+ missingKeys.push(keys[i]);
942
+ }
943
+ }
944
+ if (missingKeys.length == 0 && detailsErrors.length == 0) {
945
+ return null;
946
+ }
947
+ return { "missingKeys": missingKeys.join(", "), "details": detailsErrors.length == 0 ? null : detailsErrors, "validateDetailsErrors": validateDetailsErrors[0] };
948
+ }
949
+ }
950
+ exports.RecordSingle = RecordSingle;