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,388 @@
1
+ import { SchemaStruct } from "../../Interfaces/SchemaStruct";
2
+ import { InvoiceObj } from "../../Structure/InvoiceObj";
3
+ import { RecordSingle } from "../../Structure/RecordSingle";
4
+ import { BaseParse } from "./BaseParse";
5
+ import { CommaParser } from "./CommaParser";
6
+ import { LogicalOperatorParser } from "./LogicalOperatorParse";
7
+ import { OperatorParser } from "./OperatorParse";
8
+ import { ExpresionLogicService } from "../ExpresionLogicService";
9
+
10
+ export class IfParse extends BaseParse {
11
+
12
+ public conditionParse:BaseParse[]=[];
13
+ public conditionTrueParse:BaseParse[]=[];
14
+ public conditionFalseParse:BaseParse[]=[];
15
+
16
+ public constructor( valueExpression:string,funname:string)
17
+ {
18
+ super(valueExpression,funname);
19
+ var dd = ExpresionLogicService.GetExpressions(this.Expression, this);
20
+ if(dd==null)
21
+ {
22
+ return;
23
+ }
24
+ var current:BaseParse[]= [];
25
+ for(let i=0;i<dd.length;i++)
26
+ {
27
+ current=this.logic(current,dd[i]);
28
+ }
29
+
30
+ this.logic(current, null);
31
+ if(this.conditionParse.length==0|| this.conditionTrueParse.length==0|| this.conditionFalseParse.length==0)
32
+ {
33
+ throw "Can't parse if stategment "+valueExpression+"!";
34
+ }
35
+ }
36
+
37
+ public Evaluate(obj: InvoiceObj, critm: RecordSingle, record: any, item: SchemaStruct):any {
38
+ var candidates= this.conditionParse.filter(x => x instanceof LogicalOperatorParser);
39
+ var finishResult:boolean|null = false;
40
+ if(candidates.length==0)
41
+ {
42
+ finishResult = this.validateExpression(obj, critm, record, item, this.conditionParse);
43
+
44
+ }
45
+ else{
46
+ let condition:any[] = [];
47
+ let result:BaseParse[] = [];
48
+
49
+ for(let i=0;i< this.conditionParse.length;i++)
50
+ {
51
+ let c= this.conditionParse[i];
52
+ if(c instanceof LogicalOperatorParser)
53
+ {
54
+ var res = this.validateExpression(obj, critm, record, item, result);
55
+ result=[];
56
+ condition.push(res);
57
+ condition.push(c.Expression);
58
+ continue;
59
+ }
60
+
61
+ }
62
+ if(result.length>0)
63
+ {
64
+ var res = this.validateExpression(obj, critm, record, item, result);
65
+ condition.push(res);
66
+ }
67
+
68
+ finishResult = condition[0];
69
+ for(var i=1;i<condition.length;i+=2)
70
+ {
71
+ var c=condition[i];
72
+ switch(c)
73
+ {
74
+ case "&&":
75
+ {
76
+ finishResult = finishResult && condition[i + 1];
77
+
78
+ break;
79
+ }
80
+ case "||":
81
+ {
82
+ finishResult = finishResult || condition[i + 1];
83
+
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ }
89
+ finish:
90
+ if (finishResult == true)
91
+ {
92
+
93
+ return ExpresionLogicService.ConcatValues(this.conditionTrueParse, obj, critm, record, item);
94
+ }
95
+
96
+ return ExpresionLogicService.ConcatValues(this.conditionFalseParse, obj, critm, record, item);
97
+
98
+ }
99
+ private logic(list:BaseParse[], c:BaseParse|null)
100
+ {
101
+ if (c==null||c instanceof CommaParser)
102
+ {
103
+ if(this.conditionParse.length==0)
104
+ {
105
+ this.conditionParse = list;
106
+ }
107
+ else if (this.conditionTrueParse.length==0)
108
+ {
109
+ this.conditionTrueParse = list;
110
+ }
111
+ else if (this.conditionFalseParse.length==0)
112
+ {
113
+ this.conditionFalseParse = list;
114
+ }
115
+
116
+ return [];
117
+ }
118
+ list.push(c);
119
+ return list;
120
+ }
121
+ private validateExpression( obj:InvoiceObj, critm:RecordSingle, record:any, item:SchemaStruct, oneCondition:BaseParse[]):boolean|null
122
+ {
123
+
124
+ let result:boolean|null = null;
125
+ var candidates = oneCondition.filter(x => x instanceof OperatorParser);
126
+ if (candidates.length==0)
127
+ {
128
+ if (oneCondition.length == 1)
129
+ {
130
+ var evaluated = oneCondition[0].Evaluate(obj, critm, record, item);
131
+ if (typeof evaluated == "boolean")
132
+ {
133
+ result = evaluated;
134
+ //goto evaluatedCond;
135
+ }
136
+ /*if (evaluated == null&&(obj.currentInvoiceMode==InvoiceObj.InvoiceMode.GetInit|| obj.currentInvoiceMode == InvoiceObj.InvoiceMode.GetInitNFE))
137
+ {
138
+ result = false; goto evaluatedCond;
139
+ }*/
140
+ if(evaluated == null &&item.TypeNET=="bool")
141
+ {
142
+ result = false; //goto evaluatedCond;
143
+ }
144
+ if (typeof evaluated == "string")
145
+ {
146
+ var temp = evaluated;
147
+ if (temp.trim().toLowerCase()=="false")
148
+ {
149
+ result = false;
150
+ //goto evaluatedCond;
151
+ }
152
+ if (temp.trim().toLowerCase()=="true")
153
+ {
154
+ result = true;
155
+ //goto evaluatedCond;
156
+ }
157
+ //goto evaluatedCond;
158
+ }
159
+ }
160
+ }
161
+ else
162
+ {
163
+ let leftSideL:BaseParse[] = [];
164
+ let rightSideL:BaseParse[] = [];
165
+ var current = leftSideL;
166
+ for(let i=0;i<oneCondition.length;i++)
167
+ {
168
+ if(oneCondition[i] instanceof OperatorParser)
169
+ {
170
+ current = rightSideL; continue;
171
+ }
172
+ current.push(oneCondition[i]);
173
+ }
174
+
175
+ var leftEval = ExpresionLogicService.ConcatValues(leftSideL, obj, critm, record, item);
176
+ var rightEval = ExpresionLogicService.ConcatValues(rightSideL, obj, critm, record, item);
177
+ if (leftEval == null || rightEval == null)
178
+ {
179
+ switch (candidates[0].Expression)
180
+ {
181
+ case "=":
182
+ case "==":
183
+ {
184
+ result = leftEval == rightEval;
185
+ return this.evaluateCondition(result);
186
+ }
187
+ case "!=":
188
+ case "<>":
189
+ {
190
+ result = leftEval != rightEval;
191
+ return this.evaluateCondition(result);
192
+ }
193
+ }
194
+ }
195
+
196
+ if (typeof leftEval == "number" && typeof rightEval == "number")
197
+ {
198
+ var leftSide = leftEval;
199
+ var rightSide = rightEval;
200
+ switch (candidates[0].Expression)
201
+ {
202
+ case ">=":
203
+ {
204
+ result = leftSide >= rightSide;
205
+ return this.evaluateCondition(result);
206
+ }
207
+ case "<=":
208
+ {
209
+ result = leftSide <= rightSide;
210
+ return this.evaluateCondition(result);
211
+ }
212
+ case "!=":
213
+ case "<>":
214
+ {
215
+ result = leftSide != rightSide;
216
+ return this.evaluateCondition(result);
217
+ }
218
+ case "<":
219
+ {
220
+ result = leftSide < rightSide;
221
+ return this.evaluateCondition(result);
222
+ }
223
+ case ">":
224
+ {
225
+ result = leftSide > rightSide;
226
+ return this.evaluateCondition(result);
227
+ }
228
+ case "==":
229
+ case "=":
230
+ {
231
+ result = leftSide == rightSide;
232
+ return this.evaluateCondition(result);
233
+ }
234
+ default:
235
+ {
236
+ throw "Operator "+candidates[0].Expression+" not supported on condition decimal and decimal";
237
+ }
238
+ }
239
+ }
240
+ if (typeof leftEval =="string" && typeof rightEval =="string")
241
+ {
242
+
243
+ if((leftEval.toLowerCase()=="false"||leftEval.toLowerCase()=="true")&&
244
+ (rightEval.toLowerCase()=="false"||rightEval.toLowerCase()=="true"))
245
+ {
246
+ let lSide=Boolean(leftEval);
247
+ let rside=Boolean(rightEval);
248
+ switch (candidates[0].Expression)
249
+ {
250
+
251
+ case "!=":
252
+ case "<>":
253
+ {
254
+ result = lSide != rside;
255
+ return this.evaluateCondition(result);
256
+ }
257
+
258
+ case "==":
259
+ case "=":
260
+ {
261
+ result = lSide == rside;
262
+ return this.evaluateCondition(result);
263
+ }
264
+ default:
265
+ {
266
+ throw "Operator "+candidates[0].Expression+" not supported on condition bool and bool";
267
+ }
268
+ }
269
+ }
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+ result = this.StringCompare(leftEval, rightEval, candidates[0].Expression);
280
+ return this.evaluateCondition(result);
281
+ }
282
+ if(leftEval instanceof Date &&typeof rightEval == "string")
283
+ {
284
+ var leftSideD = BaseParse.getIsoDateTime(leftEval);
285
+
286
+ result = this.StringCompare(leftSideD, rightEval, candidates[0].Expression);
287
+ return this.evaluateCondition(result);
288
+ }
289
+ if (typeof leftEval == "string" && rightEval instanceof Date)
290
+ {
291
+
292
+
293
+ var rightSideD = BaseParse.getIsoDateTime(rightEval);
294
+ result = this.StringCompare(leftEval, rightSideD, candidates[0].Expression);
295
+ return this.evaluateCondition(result);
296
+
297
+ }
298
+ if (leftEval instanceof Date && rightEval instanceof Date)
299
+ {
300
+
301
+ switch (candidates[0].Expression)
302
+ {
303
+
304
+ case ">=":
305
+ {
306
+ result = leftEval >= rightEval;
307
+ return this.evaluateCondition(result);
308
+ }
309
+ case "<=":
310
+ {
311
+ result = leftEval <= rightEval;
312
+ return this.evaluateCondition(result);
313
+ }
314
+ case "!=":
315
+ case "<>":
316
+ {
317
+ result = leftEval != rightEval;
318
+ return this.evaluateCondition(result);
319
+ }
320
+ case "<":
321
+ {
322
+ result = leftEval < rightEval;
323
+ return this.evaluateCondition(result);
324
+ }
325
+ case ">":
326
+ {
327
+ result = leftEval > rightEval;
328
+ return this.evaluateCondition(result);
329
+ }
330
+ case "==":
331
+ case "=":
332
+ {
333
+ result = leftEval == rightEval;
334
+ return this.evaluateCondition(result);
335
+ }
336
+ default:
337
+ {
338
+ throw "Operator "+candidates[0].Expression+" not supported on condition string";
339
+ }
340
+ }
341
+ }
342
+ }
343
+ return this.evaluateCondition(result);
344
+
345
+
346
+
347
+
348
+
349
+
350
+ }
351
+ private evaluateCondition(result:boolean|null):boolean{
352
+ if(result==null)
353
+ {
354
+ throw "Can't eval "+this.Expression+"!";
355
+ }
356
+ return result;
357
+ }
358
+ private StringCompare(leftSide:string|null,rightSide:string|null,oper:string):boolean
359
+ {
360
+ switch (oper)
361
+ {
362
+
363
+ case "!=":
364
+ case "<>":
365
+ {
366
+ return leftSide != rightSide;
367
+
368
+ }
369
+
370
+ case "==":
371
+ case "=":
372
+ {
373
+ return leftSide == rightSide;
374
+
375
+ }
376
+ default:
377
+ {
378
+ throw "Operator "+oper+" not supported on condition string";
379
+ }
380
+ }
381
+ }
382
+ }
383
+
384
+
385
+
386
+
387
+
388
+