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