js-gei 1.0.3 → 1.1.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 (85) hide show
  1. package/dist/js-gei.es.js +1731 -0
  2. package/dist/js-gei.umd.js +2 -0
  3. package/package.json +15 -12
  4. package/{Evaluator → src/Evaluator}/ExpresionLogicService.ts +9 -3
  5. package/src/Evaluator/HelpersTables.ts +79 -0
  6. package/src/Evaluator/Parser/CleanParse.ts +84 -0
  7. package/src/Evaluator/Parser/DateTimeFormatParse.ts +81 -0
  8. package/src/Evaluator/Parser/UseFirstParse.ts +47 -0
  9. package/{HelperSessionStorage.ts → src/HelperSessionStorage.ts} +4 -1
  10. package/{Interfaces → src/Interfaces}/SchemaStruct.ts +10 -2
  11. package/src/Structure/InvoiceObj.ts +704 -0
  12. package/{Structure → src/Structure}/RecordArray.ts +18 -15
  13. package/src/Structure/RecordSingle.ts +652 -0
  14. package/{Structure → src/Structure}/TableLevel.ts +34 -27
  15. package/src/index.ts +1 -0
  16. package/src/main.ts +77 -0
  17. package/test/basic.test.ts +3 -0
  18. package/tsconfig.json +11 -100
  19. package/vite.config.ts +17 -0
  20. package/vitest.config.ts +8 -0
  21. package/Library/jsonrpc-2.0.js +0 -873
  22. package/Structure/InvoiceObj.ts +0 -691
  23. package/Structure/RecordSingle.ts +0 -1076
  24. package/dist/Evaluator/ExpresionLogicService.js +0 -505
  25. package/dist/Evaluator/Parser/AddLeadZerosParse.js +0 -55
  26. package/dist/Evaluator/Parser/AppearParse.js +0 -48
  27. package/dist/Evaluator/Parser/BaseParse.js +0 -89
  28. package/dist/Evaluator/Parser/CalcDateParse.js +0 -54
  29. package/dist/Evaluator/Parser/CheckParse.js +0 -80
  30. package/dist/Evaluator/Parser/CommaParser.js +0 -13
  31. package/dist/Evaluator/Parser/ConcatParse.js +0 -29
  32. package/dist/Evaluator/Parser/CountParse.js +0 -23
  33. package/dist/Evaluator/Parser/EmptyParse.js +0 -35
  34. package/dist/Evaluator/Parser/ExistParse.js +0 -57
  35. package/dist/Evaluator/Parser/IfParse.js +0 -296
  36. package/dist/Evaluator/Parser/IfStategment.js +0 -287
  37. package/dist/Evaluator/Parser/InDetailParse.js +0 -79
  38. package/dist/Evaluator/Parser/InListParse.js +0 -40
  39. package/dist/Evaluator/Parser/LiteralValueParse.js +0 -26
  40. package/dist/Evaluator/Parser/LogicalOperatorParse.js +0 -13
  41. package/dist/Evaluator/Parser/OnlyExpressionParse.js +0 -106
  42. package/dist/Evaluator/Parser/OperatorParse.js +0 -13
  43. package/dist/Evaluator/Parser/StartsParse.js +0 -30
  44. package/dist/Evaluator/Parser/SubstrParse.js +0 -83
  45. package/dist/Evaluator/Parser/SumParse.js +0 -13
  46. package/dist/Evaluator/Parser/ToNullParser.js +0 -1
  47. package/dist/Evaluator/Parser/TrimParse.js +0 -25
  48. package/dist/Evaluator/Parser/UpperLoverParse.js +0 -32
  49. package/dist/Evaluator/Parser/ValueFromObjParse.js +0 -29
  50. package/dist/Evaluator/Parser/ValueParse.js +0 -59
  51. package/dist/HelperSessionStorage.js +0 -12
  52. package/dist/Interfaces/SchemaStruct.js +0 -2
  53. package/dist/Library/RpcClient.js +0 -284
  54. package/dist/Structure/InvoiceObj.js +0 -610
  55. package/dist/Structure/RecordArray.js +0 -102
  56. package/dist/Structure/RecordSingle.js +0 -950
  57. package/dist/Structure/TableLevel.js +0 -162
  58. package/dist/index.js +0 -35
  59. package/index.ts +0 -42
  60. /package/{Evaluator → src/Evaluator}/Parser/AddLeadZerosParse.ts +0 -0
  61. /package/{Evaluator → src/Evaluator}/Parser/AppearParse.ts +0 -0
  62. /package/{Evaluator → src/Evaluator}/Parser/BaseParse.ts +0 -0
  63. /package/{Evaluator → src/Evaluator}/Parser/CalcDateParse.ts +0 -0
  64. /package/{Evaluator → src/Evaluator}/Parser/CheckParse.ts +0 -0
  65. /package/{Evaluator → src/Evaluator}/Parser/CommaParser.ts +0 -0
  66. /package/{Evaluator → src/Evaluator}/Parser/ConcatParse.ts +0 -0
  67. /package/{Evaluator → src/Evaluator}/Parser/CountParse.ts +0 -0
  68. /package/{Evaluator → src/Evaluator}/Parser/EmptyParse.ts +0 -0
  69. /package/{Evaluator → src/Evaluator}/Parser/ExistParse.ts +0 -0
  70. /package/{Evaluator → src/Evaluator}/Parser/IfParse.ts +0 -0
  71. /package/{Evaluator → src/Evaluator}/Parser/IfStategment.ts +0 -0
  72. /package/{Evaluator → src/Evaluator}/Parser/InDetailParse.ts +0 -0
  73. /package/{Evaluator → src/Evaluator}/Parser/InListParse.ts +0 -0
  74. /package/{Evaluator → src/Evaluator}/Parser/LiteralValueParse.ts +0 -0
  75. /package/{Evaluator → src/Evaluator}/Parser/LogicalOperatorParse.ts +0 -0
  76. /package/{Evaluator → src/Evaluator}/Parser/OnlyExpressionParse.ts +0 -0
  77. /package/{Evaluator → src/Evaluator}/Parser/OperatorParse.ts +0 -0
  78. /package/{Evaluator → src/Evaluator}/Parser/StartsParse.ts +0 -0
  79. /package/{Evaluator → src/Evaluator}/Parser/SubstrParse.ts +0 -0
  80. /package/{Evaluator → src/Evaluator}/Parser/SumParse.ts +0 -0
  81. /package/{Evaluator → src/Evaluator}/Parser/ToNullParser.ts +0 -0
  82. /package/{Evaluator → src/Evaluator}/Parser/TrimParse.ts +0 -0
  83. /package/{Evaluator → src/Evaluator}/Parser/UpperLoverParse.ts +0 -0
  84. /package/{Evaluator → src/Evaluator}/Parser/ValueFromObjParse.ts +0 -0
  85. /package/{Evaluator → src/Evaluator}/Parser/ValueParse.ts +0 -0
@@ -0,0 +1,1731 @@
1
+ class TableLevel {
2
+ constructor(e, t, s, n) {
3
+ this.Root = null, this.Record = null, this.Records = null, this.validateDetailsErrors = [], this.Tablename = e, this.Root = n, this.ObjectInfo = s[e], Array.isArray(t) ? this.Records = new RecordArray(t, this.DefaultRecord, s) : this.Record = new RecordSingle(t, s, this);
4
+ }
5
+ Evaluate(e) {
6
+ this.Records != null ? this.Records.EvaluateInner(e) : this.Record != null && this.Record.EvaluateInner(e);
7
+ }
8
+ MapToId(e) {
9
+ this.Records != null ? this.Records.MapToId(e) : this.Record != null && this.Record.MapToId(e);
10
+ }
11
+ GetObject() {
12
+ let e = JSON.parse("{}");
13
+ return this.Record != null ? e[this.Tablename] = this.Record.GetObject() : this.Records != null && (e[this.Tablename] = this.Records.GetObject()), e;
14
+ }
15
+ TranslateObj(e) {
16
+ this.Record != null ? this.Record?.TranslateObj(e) : this.Records != null && this.Records?.TranslateObj(e);
17
+ }
18
+ getSaveObject(e) {
19
+ if (e[this.Tablename] == null)
20
+ return null;
21
+ let t = null;
22
+ if (this.Record != null) {
23
+ let s = this.Record.getSaveObject(e);
24
+ if (s == null)
25
+ return null;
26
+ t = s;
27
+ }
28
+ if (this.Records != null) {
29
+ let s = this.Records.getSaveObject(e);
30
+ if (s == null)
31
+ return null;
32
+ t = s;
33
+ }
34
+ return t;
35
+ }
36
+ getFullObject(e) {
37
+ if (e[this.Tablename] == null)
38
+ return null;
39
+ let t = null;
40
+ if (this.Record != null) {
41
+ let s = this.Record.getFullObject(e);
42
+ if (s == null)
43
+ return null;
44
+ t = s;
45
+ }
46
+ if (this.Records != null) {
47
+ let s = this.Records.getFullObject(e);
48
+ if (s == null)
49
+ return null;
50
+ t = s;
51
+ }
52
+ return t;
53
+ }
54
+ Validate() {
55
+ this.validateDetailsErrors = [];
56
+ let e = [], t = "", s = "";
57
+ if (this.Record != null) {
58
+ let r = this.Record.Validate();
59
+ if (r == null)
60
+ return null;
61
+ r.missingKeys != null && (t = "Missing mandatory keys:" + r.missingKeys, e.push(r.missingKeys)), r.validateDetailsErrors != null && this.validateDetailsErrors.push(...r.validateDetailsErrors), r.details != null && r.details.length > 0 && (s = r.details), s != "" && (t == null ? t = s : t += `
62
+ ` + s);
63
+ }
64
+ if (this.Records != null) {
65
+ let r = this.Records.Validate(), i = null, a = null;
66
+ if (r != null && (i = r.errorMessage, a = r.validateDetailsErrors), i == null || (t = i.toString(), a == null))
67
+ return null;
68
+ a.length > 0 && e.push(r.validateDetailsErrors);
69
+ }
70
+ let n = "Missing data on level " + this.Tablename + ": " + t;
71
+ return { combineErrors: n == "" ? null : n, validateErrors: e, validateDeatailErrors: this.validateDetailsErrors.length > 0 ? this.validateDetailsErrors : [] };
72
+ }
73
+ }
74
+ const N = class N {
75
+ constructor(e, t) {
76
+ this.Expression = "", this.FunName = null, t == null || t == "" ? this.Expression = e : (this.Expression = e.substring(t.length, e.length - 1), this.FunName = t);
77
+ }
78
+ static getIsoDateWithTime(e, t) {
79
+ return e == null ? null : typeof e == "string" ? e : e.getFullYear() + "-" + this.formatToTwoNumber(e.getMonth() + 1) + "-" + this.formatToTwoNumber(e.getDate()) + t;
80
+ }
81
+ static getIsoDateTime(e) {
82
+ return e == null ? null : typeof e == "string" ? e : e.getFullYear() + "-" + this.formatToTwoNumber(e.getMonth() + 1) + "-" + this.formatToTwoNumber(e.getDate()) + "T" + this.formatToTwoNumber(e.getHours()) + ":" + this.formatToTwoNumber(e.getMinutes()) + ":" + this.formatToTwoNumber(e.getSeconds());
83
+ }
84
+ static parseDateTime(e) {
85
+ return new Date(e);
86
+ }
87
+ static parseDate(e) {
88
+ return new Date(e);
89
+ }
90
+ static formatToTwoNumber(e) {
91
+ return e < 10 ? "0" + e : e.toString();
92
+ }
93
+ static getIsoDate(e) {
94
+ return e == null ? null : typeof e == "string" ? e : e.getFullYear() + "-" + this.formatToTwoNumber(e.getMonth() + 1) + "-" + this.formatToTwoNumber(e.getDate()) + "T00:00:00";
95
+ }
96
+ static roundUp(e, t) {
97
+ let s = !1;
98
+ e < 0 ? s = !0 : s = !1, s ? e = e - 10 ** -13 : e = e + 10 ** -13, e = Math.abs(e);
99
+ let n = Math.round(e * Math.pow(10, t)) / Math.pow(10, t);
100
+ return s ? -1 * n : n;
101
+ }
102
+ };
103
+ N.operators = ["<=", ">=", "!=", "<>", "==", "<", ">", "="], N.logicaloperators = ["&&", "||"];
104
+ let BaseParse = N;
105
+ class OperatorParser extends BaseParse {
106
+ constructor(e) {
107
+ super(e, null);
108
+ }
109
+ Evaluate(e, t, s, n) {
110
+ return this.Expression;
111
+ }
112
+ }
113
+ class LiteralValueParse extends BaseParse {
114
+ constructor(e) {
115
+ super(e, null);
116
+ }
117
+ Evaluate(e, t, s, n) {
118
+ if (this.Expression == "null")
119
+ return null;
120
+ if (this.Expression.startsWith("N.") && typeof this.Expression == "string")
121
+ try {
122
+ return parseFloat(this.Expression);
123
+ } catch {
124
+ throw "Value " + this.Expression + " can't be transformed to numeric!";
125
+ }
126
+ return this.Expression;
127
+ }
128
+ }
129
+ class ValueFromObjParse extends BaseParse {
130
+ constructor(e, t) {
131
+ super(e, null), this.Numeric = !1, this.Numeric = t;
132
+ }
133
+ Evaluate(e, t, s, n) {
134
+ var r = ExpresionLogicService.ValueExpresion(n, this.Expression, e, t);
135
+ if (r == null)
136
+ return null;
137
+ if (this.Numeric) {
138
+ if (typeof r == "string")
139
+ return parseFloat(r);
140
+ if (typeof r == "number")
141
+ return r;
142
+ throw "Value is " + typeof r + " isn't number type!";
143
+ }
144
+ return r;
145
+ }
146
+ }
147
+ const w = class w extends BaseParse {
148
+ constructor(e) {
149
+ super(e, null), this.subParse = [];
150
+ for (var t = [], s = ""; e.length > 0; ) {
151
+ var n = !1;
152
+ for (let h = 0; h < BaseParse.operators.length; h++) {
153
+ let u = BaseParse.operators[h];
154
+ if (e.startsWith(u)) {
155
+ t.push(new OperatorParser(e.substring(0, u.length))), e = e.substring(u.length), n = !0;
156
+ break;
157
+ }
158
+ }
159
+ if (n)
160
+ continue;
161
+ if (["%", "(", ")"].indexOf(e.substring(0, 1)) == -1 && !ExpresionLogicService.StartsWithFunction(e)) {
162
+ s += e.substring(0, 1), e = e.substring(1);
163
+ continue;
164
+ }
165
+ if (s != "" && (t.push(new LiteralValueParse(s)), s = ""), e.startsWith("N.%")) {
166
+ var r = e.substring(3).indexOf("%") + 1;
167
+ t.push(new ValueFromObjParse(e.substring(2, r - 1), !0)), e = e.substring(r + 1);
168
+ continue;
169
+ }
170
+ if (e.startsWith("%")) {
171
+ var r = e.substring(1).indexOf("%") + 1;
172
+ t.push(new ValueFromObjParse(e.substring(0, r + 1), !1)), e = e.substring(r + 1);
173
+ continue;
174
+ }
175
+ var i = !1;
176
+ const f = Object.keys(ExpresionLogicService._suportedFunctions);
177
+ for (let h = 0; h < f.length; h++) {
178
+ let u = f[h];
179
+ if (e.startsWith(u)) {
180
+ s != "" && (t.push(new w(s)), s = "");
181
+ var a = ExpresionLogicService.FindEnd(e);
182
+ if (a == -1)
183
+ throw "Unbalanced brackets!!!! Expression:" + e;
184
+ let d = Reflect.construct(ExpresionLogicService._suportedFunctions[u], [e.substring(0, a + 1), u]);
185
+ t.push(d), a < e.length ? e = e.substring(a + 1) : e = "", i = !0;
186
+ break;
187
+ }
188
+ }
189
+ if (!i) {
190
+ var o = !1;
191
+ for (let h = 0; h < w._literalValues.length; h++) {
192
+ var c = w._literalValues[h];
193
+ if (e.substring(0, 1) == c) {
194
+ t.push(new LiteralValueParse(c)), e = e.substring(1), o = !0;
195
+ break;
196
+ }
197
+ }
198
+ }
199
+ }
200
+ s != "" && t.push(new LiteralValueParse(s)), this.subParse = t;
201
+ }
202
+ Evaluate(e, t, s, n) {
203
+ return this.subParse.length == 1 ? this.subParse[0].Evaluate(e, t, s, n) : ExpresionLogicService.ConcatValues(this.subParse, e, t, s, n);
204
+ }
205
+ };
206
+ w._literalValues = ["(", ")"];
207
+ let OnlyExpressionParse = w;
208
+ class CommaParser extends BaseParse {
209
+ constructor(e, t) {
210
+ super(e, t);
211
+ }
212
+ Evaluate(e, t, s, n) {
213
+ return this.Expression;
214
+ }
215
+ }
216
+ class LogicalOperatorParser extends BaseParse {
217
+ constructor(e) {
218
+ super(e, null);
219
+ }
220
+ Evaluate(e, t, s, n) {
221
+ return this.Expression;
222
+ }
223
+ }
224
+ class AddLeadZerosParse extends BaseParse {
225
+ constructor(e, t) {
226
+ super(e, t), this.value = [], this.numOfZeros = [];
227
+ var s = ExpresionLogicService.GetExpressions(this.Expression, this);
228
+ if (s == null)
229
+ return;
230
+ var n = s.filter((i) => i instanceof CommaParser);
231
+ if (n.length == 0)
232
+ throw "No comma in AddLeadZeros function";
233
+ let r = [];
234
+ s.forEach((i) => {
235
+ i instanceof CommaParser ? (this.value = r, r = []) : r.push(i);
236
+ }), this.numOfZeros = r;
237
+ }
238
+ Evaluate(e, t, s, n) {
239
+ var r = ExpresionLogicService.ConcatValues(this.value, e, t, s, n), i = ExpresionLogicService.ConcatValues(this.numOfZeros, e, t, s, n);
240
+ if (r == null || i == null)
241
+ return null;
242
+ let a = -1;
243
+ if (typeof i == "number" ? a = i : typeof i == "string" && (a = parseInt(i)), a == -1)
244
+ throw "AddLeadZeros function can't be evaluated! expression: " + this.Expression;
245
+ for (var o = r.ToString(); o.Length < a; )
246
+ o = "0" + o;
247
+ return o;
248
+ }
249
+ }
250
+ class AppearParse extends BaseParse {
251
+ constructor(e, t) {
252
+ super(e, t), this.FieldName = "";
253
+ var s = this.Expression.split(".");
254
+ this.Table = s[0], s.length > 1 && (this.FieldName = s[1]);
255
+ }
256
+ Evaluate(e, t, s, n) {
257
+ var r = e.FindTableLevel(this.Table);
258
+ if (r == null)
259
+ return !1;
260
+ let i = [];
261
+ if (r.Record != null)
262
+ i.push(r.Record);
263
+ else if (r.Records != null) {
264
+ var a = r.Records;
265
+ if (a.Records.length == 0)
266
+ return !1;
267
+ a.Records.forEach((c) => {
268
+ i.push(c);
269
+ });
270
+ }
271
+ if (i.length == 0)
272
+ return !1;
273
+ if (this.FieldName == "")
274
+ return !0;
275
+ for (var o = 0; o < i.length; o++)
276
+ if (i[o].Record[this.FieldName] != null)
277
+ return !0;
278
+ return !1;
279
+ }
280
+ }
281
+ class IfParse extends BaseParse {
282
+ constructor(e, t) {
283
+ super(e, t), this.conditionParse = [], this.conditionTrueParse = [], this.conditionFalseParse = [];
284
+ var s = ExpresionLogicService.GetExpressions(this.Expression, this);
285
+ if (s != null) {
286
+ var n = [];
287
+ for (let r = 0; r < s.length; r++)
288
+ n = this.logic(n, s[r]);
289
+ if (this.logic(n, null), this.conditionParse.length == 0 || this.conditionTrueParse.length == 0 || this.conditionFalseParse.length == 0)
290
+ throw "Can't parse if stategment " + e + "!";
291
+ }
292
+ }
293
+ Evaluate(e, t, s, n) {
294
+ var r = this.conditionParse.filter((f) => f instanceof LogicalOperatorParser), i = !1;
295
+ if (r.length == 0)
296
+ i = this.validateExpression(e, t, s, n, this.conditionParse);
297
+ else {
298
+ let f = [], h = [];
299
+ for (let u = 0; u < this.conditionParse.length; u++) {
300
+ let d = this.conditionParse[u];
301
+ if (d instanceof LogicalOperatorParser) {
302
+ var a = this.validateExpression(e, t, s, n, h);
303
+ h = [], f.push(a), f.push(d.Expression);
304
+ continue;
305
+ }
306
+ }
307
+ if (h.length > 0) {
308
+ var a = this.validateExpression(e, t, s, n, h);
309
+ f.push(a);
310
+ }
311
+ i = f[0];
312
+ for (var o = 1; o < f.length; o += 2) {
313
+ var c = f[o];
314
+ switch (c) {
315
+ case "&&": {
316
+ i = i && f[o + 1];
317
+ break;
318
+ }
319
+ case "||": {
320
+ i = i || f[o + 1];
321
+ break;
322
+ }
323
+ }
324
+ }
325
+ }
326
+ return i == !0 ? ExpresionLogicService.ConcatValues(this.conditionTrueParse, e, t, s, n) : ExpresionLogicService.ConcatValues(this.conditionFalseParse, e, t, s, n);
327
+ }
328
+ logic(e, t) {
329
+ return t == null || t instanceof CommaParser ? (this.conditionParse.length == 0 ? this.conditionParse = e : this.conditionTrueParse.length == 0 ? this.conditionTrueParse = e : this.conditionFalseParse.length == 0 && (this.conditionFalseParse = e), []) : (e.push(t), e);
330
+ }
331
+ validateExpression(e, t, s, n, r) {
332
+ let i = null;
333
+ var a = r.filter((p) => p instanceof OperatorParser);
334
+ if (a.length == 0) {
335
+ if (r.length == 1) {
336
+ var o = r[0].Evaluate(e, t, s, n);
337
+ if (typeof o == "boolean" && (i = o), o == null && n.TypeNET == "bool" && (i = !1), typeof o == "string") {
338
+ var c = o;
339
+ c.trim().toLowerCase() == "false" && (i = !1), c.trim().toLowerCase() == "true" && (i = !0);
340
+ }
341
+ }
342
+ } else {
343
+ let p = [], g = [];
344
+ var f = p;
345
+ for (let R = 0; R < r.length; R++) {
346
+ if (r[R] instanceof OperatorParser) {
347
+ f = g;
348
+ continue;
349
+ }
350
+ f.push(r[R]);
351
+ }
352
+ var h = ExpresionLogicService.ConcatValues(p, e, t, s, n), u = ExpresionLogicService.ConcatValues(g, e, t, s, n);
353
+ if (h == null || u == null)
354
+ switch (a[0].Expression) {
355
+ case "=":
356
+ case "==":
357
+ return i = h == u, this.evaluateCondition(i);
358
+ case "!=":
359
+ case "<>":
360
+ return i = h != u, this.evaluateCondition(i);
361
+ }
362
+ if (typeof h == "number" && typeof u == "number") {
363
+ var d = h, v = u;
364
+ switch (a[0].Expression) {
365
+ case ">=":
366
+ return i = d >= v, this.evaluateCondition(i);
367
+ case "<=":
368
+ return i = d <= v, this.evaluateCondition(i);
369
+ case "!=":
370
+ case "<>":
371
+ return i = d != v, this.evaluateCondition(i);
372
+ case "<":
373
+ return i = d < v, this.evaluateCondition(i);
374
+ case ">":
375
+ return i = d > v, this.evaluateCondition(i);
376
+ case "==":
377
+ case "=":
378
+ return i = d == v, this.evaluateCondition(i);
379
+ default:
380
+ throw "Operator " + a[0].Expression + " not supported on condition decimal and decimal";
381
+ }
382
+ }
383
+ if (typeof h == "string" && typeof u == "string") {
384
+ if ((h.toLowerCase() == "false" || h.toLowerCase() == "true") && (u.toLowerCase() == "false" || u.toLowerCase() == "true")) {
385
+ let R = !!h, I = !!u;
386
+ switch (a[0].Expression) {
387
+ case "!=":
388
+ case "<>":
389
+ return i = R != I, this.evaluateCondition(i);
390
+ case "==":
391
+ case "=":
392
+ return i = R == I, this.evaluateCondition(i);
393
+ default:
394
+ throw "Operator " + a[0].Expression + " not supported on condition bool and bool";
395
+ }
396
+ }
397
+ return i = this.StringCompare(h, u, a[0].Expression), this.evaluateCondition(i);
398
+ }
399
+ if (h instanceof Date && typeof u == "string") {
400
+ var E = BaseParse.getIsoDateTime(h);
401
+ return i = this.StringCompare(E, u, a[0].Expression), this.evaluateCondition(i);
402
+ }
403
+ if (typeof h == "string" && u instanceof Date) {
404
+ var b = BaseParse.getIsoDateTime(u);
405
+ return i = this.StringCompare(h, b, a[0].Expression), this.evaluateCondition(i);
406
+ }
407
+ if (h instanceof Date && u instanceof Date)
408
+ switch (a[0].Expression) {
409
+ case ">=":
410
+ return i = h >= u, this.evaluateCondition(i);
411
+ case "<=":
412
+ return i = h <= u, this.evaluateCondition(i);
413
+ case "!=":
414
+ case "<>":
415
+ return i = h != u, this.evaluateCondition(i);
416
+ case "<":
417
+ return i = h < u, this.evaluateCondition(i);
418
+ case ">":
419
+ return i = h > u, this.evaluateCondition(i);
420
+ case "==":
421
+ case "=":
422
+ return i = h == u, this.evaluateCondition(i);
423
+ default:
424
+ throw "Operator " + a[0].Expression + " not supported on condition string";
425
+ }
426
+ }
427
+ return this.evaluateCondition(i);
428
+ }
429
+ evaluateCondition(e) {
430
+ if (e == null)
431
+ throw "Can't eval " + this.Expression + "!";
432
+ return e;
433
+ }
434
+ StringCompare(e, t, s) {
435
+ switch (s) {
436
+ case "!=":
437
+ case "<>":
438
+ return e != t;
439
+ case "==":
440
+ case "=":
441
+ return e == t;
442
+ default:
443
+ throw "Operator " + s + " not supported on condition string";
444
+ }
445
+ }
446
+ }
447
+ class SumParse extends BaseParse {
448
+ constructor(e, t) {
449
+ super(e, t);
450
+ }
451
+ Evaluate(e, t, s, n) {
452
+ return e.SumByKey(this.Expression);
453
+ }
454
+ }
455
+ class CalcDateParse extends BaseParse {
456
+ constructor(e, t) {
457
+ super(e, t), this.value = "", this.offset = "";
458
+ var s = this.Expression.split(",");
459
+ s.length == 2 && (this.value = s[0], this.offset = s[1]);
460
+ }
461
+ Evaluate(e, t, s, n) {
462
+ if (this.value == "" || this.offset == "")
463
+ return null;
464
+ var r = new OnlyExpressionParse(this.value), i = r.Evaluate(e, t, s, n), a = new OnlyExpressionParse(this.offset), o = a.Evaluate(e, t, s, n), c = null, f = null;
465
+ if (i.constructor.name == "Date" ? c = i : typeof i == "string" && (c = new Date(i)), typeof o == "number" ? f = o : typeof o == "string" && (f = parseInt(o)), f != null && c != null) {
466
+ if (c.setDate(c.getDate() + f), n.TypeDDD == "Date")
467
+ return BaseParse.getIsoDate(c);
468
+ if (n.TypeDDD == "DateTime")
469
+ return BaseParse.getIsoDateTime(c);
470
+ } else
471
+ debugger;
472
+ return this.Expression;
473
+ }
474
+ }
475
+ class UpperLowerParse extends BaseParse {
476
+ constructor(e, t) {
477
+ super(e, t), this.lower = !0, t.toLowerCase() == "upper(" && (this.lower = !1);
478
+ }
479
+ Evaluate(e, t, s, n) {
480
+ var r = ExpresionLogicService.GetExpressions(this.Expression, this);
481
+ if (r == null)
482
+ return null;
483
+ var i = ExpresionLogicService.ConcatValues(r, e, t, s, n);
484
+ return i == null ? null : typeof i == "string" ? this.lower ? i.toLowerCase() : i.toUpperCase() : i;
485
+ }
486
+ }
487
+ class INListParser extends BaseParse {
488
+ constructor(e, t) {
489
+ if (super(e, t), this.Negate = !1, this.FieldSet = "", this.aviableValues = [], this.Expression != null && this.Expression.startsWith("(")) {
490
+ var s = ExpresionLogicService.FindEnd(this.Expression), n = this.Expression.substring(1, s);
491
+ this.FieldSet = this.Expression.substring(s + 2), this.aviableValues = n.split(","), t?.toLowerCase() == "notinlist(" && (this.Negate = !0);
492
+ }
493
+ }
494
+ Evaluate(e, t, s, n) {
495
+ var r = new ValueFromObjParse(this.FieldSet, !1), i = r.Evaluate(e, t, s, n);
496
+ if (i == null || this.aviableValues.length == 0)
497
+ return !1;
498
+ var a = this.aviableValues.indexOf(i.toString());
499
+ return this.Negate ? a == -1 : a != -1;
500
+ }
501
+ }
502
+ class InDetailParse extends BaseParse {
503
+ constructor(e, t) {
504
+ if (super(e, t), this.Negate = !1, this.TableAndField = "", this.Table = "", this.Field = "", this.aviableValues = [], this.Expression != null && this.Expression.startsWith("(")) {
505
+ var s = ExpresionLogicService.FindEnd(this.Expression), n = this.Expression.substring(1, s);
506
+ if (this.TableAndField = this.Expression.substring(s + 2), this.TableAndField == null || this.TableAndField == "")
507
+ throw "Invalid expresion InDetail - table.field is empty!";
508
+ if (n == null || n == "")
509
+ throw "Invalid expresion InDetail - set of values is empty!";
510
+ var r = this.TableAndField.split(".");
511
+ if (r.length == 2)
512
+ this.Table = r[0], this.Field = r[1];
513
+ else
514
+ throw "Invalid expresion InDetail - table.field not in correction format!";
515
+ this.aviableValues = n.split(","), t?.toLowerCase() == "notindetail(" && (this.Negate = !0);
516
+ }
517
+ }
518
+ Evaluate(e, t, s, n) {
519
+ var r = e.FindTableLevel(this.Table);
520
+ if (r == null)
521
+ return !1;
522
+ if (r.Records != null)
523
+ if (r.Records.Records, this.Negate) {
524
+ for (var i = 0; i < r.Records.Records.length; i++) {
525
+ let o = r.Records.Records[i];
526
+ if (o.Record[this.Field] == null)
527
+ continue;
528
+ if (this.aviableValues.filter((f) => f != o.Record[this.Field].toString()).length > 0)
529
+ return !0;
530
+ }
531
+ return !1;
532
+ } else {
533
+ for (var i = 0; i < r.Records.Records.length; i++) {
534
+ let a = r.Records.Records[i];
535
+ if (a.Record[this.Field] == null)
536
+ continue;
537
+ if (this.aviableValues.filter((c) => c == a.Record[this.Field].toString()).length > 0)
538
+ return !0;
539
+ }
540
+ return !1;
541
+ }
542
+ }
543
+ }
544
+ class StartsParse extends BaseParse {
545
+ constructor(e, t) {
546
+ super(e, t), this.starts = null, this.value = null;
547
+ var s = this.Expression.split(",");
548
+ s.length == 2 && (this.starts = new OnlyExpressionParse(s[0]), this.value = new OnlyExpressionParse(s[1]));
549
+ }
550
+ Evaluate(e, t, s, n) {
551
+ var r = this.starts?.Evaluate(e, t, s, n), i = this.value?.Evaluate(e, t, s, n);
552
+ if (r == null || i == null)
553
+ return !1;
554
+ var a = r.ToString(), o = i.ToString(), c = o.startsWith(a);
555
+ return c;
556
+ }
557
+ }
558
+ class SubstrParse extends BaseParse {
559
+ constructor(e, t) {
560
+ super(e, t), this.starts = [], this.value = [], this.length = [];
561
+ var s = ExpresionLogicService.GetExpressions(this.Expression, this), n = [];
562
+ if (s != null) {
563
+ for (let r = 0; r < s.length; r++)
564
+ n = this.logic(n, s[r]);
565
+ if (this.logic(n, null), this.value.length == 0 || this.starts.length == 0 || this.length.length == 0)
566
+ throw "Can't parse if stategment " + e + "!";
567
+ }
568
+ }
569
+ Evaluate(e, t, s, n) {
570
+ var r = ExpresionLogicService.ConcatValues(this.value, e, t, s, n);
571
+ if (r == null)
572
+ return null;
573
+ var i = r.ToString();
574
+ let a = -1;
575
+ var o = ExpresionLogicService.ConcatValues(this.starts, e, t, s, n);
576
+ if (typeof o == "number" ? a = o : typeof o == "string" && (a = parseInt(o)), a == -1)
577
+ throw "Substr start index can't be parsed! Value: " + o + "!";
578
+ a--;
579
+ let c = -1;
580
+ var f = ExpresionLogicService.ConcatValues(this.length, e, t, s, n);
581
+ if (typeof f == "number" ? c = f : f == "string" && (c = parseInt(f)), c == -1)
582
+ throw "Substr length index can't be parsed! Value: " + f + "!";
583
+ if (i.Length <= a)
584
+ return null;
585
+ var h = i.substring(a);
586
+ return h.Length <= c ? h : h.substring(0, c);
587
+ }
588
+ logic(e, t) {
589
+ return t == null || t instanceof CommaParser ? (this.value.length == 0 ? this.value = e : this.starts.length == 0 ? this.starts = e : this.length.length == 0 && (this.length = e), []) : (e.push(t), e);
590
+ }
591
+ }
592
+ class CountParse extends BaseParse {
593
+ constructor(e, t) {
594
+ super(e, t), this.Table = ";", this.Table = this.Expression;
595
+ }
596
+ Evaluate(e, t, s, n) {
597
+ if (this.Table == "")
598
+ throw "Function count don't have defined table!";
599
+ var r = e.FindTableLevel(this.Table);
600
+ return r == null ? -1 : r.Records?.Records.length;
601
+ }
602
+ }
603
+ class ExistParser extends BaseParse {
604
+ constructor(e, t) {
605
+ super(e, t), this.Table = "", this.FieldName = "", this.Negate = !1, t.toLowerCase() == "notexists(" && (this.Negate = !0);
606
+ var s = this.Expression.split(".");
607
+ s.length != 2, this.Table = s[0], this.FieldName = s[1], this.Table?.startsWith("!") && (this.Table = this.Table.substring(1), this.Negate = !0);
608
+ }
609
+ Evaluate(e, t, s, n) {
610
+ if (this.Table == null)
611
+ throw "No table";
612
+ var r = e.FindTableLevel(this.Table);
613
+ if (r == null)
614
+ throw "Table level " + this.Table + " don't exist in object!";
615
+ let i = !1;
616
+ if (r == e.rootLevel) {
617
+ var a = r.Record;
618
+ i = a?.Record.Record[this.FieldName] != null;
619
+ } else {
620
+ var o = r.Records;
621
+ if (o == null)
622
+ throw "Table level " + this.Table + " don't have active records!";
623
+ var c = o.Records.indexOf(t);
624
+ if (c == -1)
625
+ throw "Table level " + this.Table + " not the same as record!" + t?.Parent?.Tablename;
626
+ i = o.Records[c].Record[this.FieldName] != null;
627
+ }
628
+ return this.Negate && (i = !i), i;
629
+ }
630
+ }
631
+ class EmptyParse extends BaseParse {
632
+ constructor(e, t) {
633
+ super(e, t), this.valueExp = null;
634
+ var s = ExpresionLogicService.GetExpressions(this.Expression, this);
635
+ if (s != null)
636
+ if (s.length == 1 && s[0] instanceof OnlyExpressionParse)
637
+ this.valueExp = s[0];
638
+ else
639
+ throw "Expression '" + this.Expression + "' isn't ValueFromObjParse";
640
+ }
641
+ Evaluate(e, t, s, n) {
642
+ var r = this.valueExp?.Evaluate(e, t, s, n);
643
+ if (r == null)
644
+ return !0;
645
+ if (typeof r == "string") {
646
+ var i = r;
647
+ return i == "" || i.trim() == "";
648
+ }
649
+ return !1;
650
+ }
651
+ }
652
+ class ConcatParse extends BaseParse {
653
+ constructor(e, t) {
654
+ super(e, t), this.sections = [], this.sections = ExpresionLogicService.GetExpressions(this.Expression, this) ?? [];
655
+ }
656
+ Evaluate(e, t, s, n) {
657
+ for (var r = "", i = 0; i < this.sections.length; i++) {
658
+ let o = this.sections[i];
659
+ if (!(o instanceof CommaParser)) {
660
+ var a = o.Evaluate(e, t, s, n);
661
+ a != null && (r += a);
662
+ }
663
+ }
664
+ return r;
665
+ }
666
+ }
667
+ class CheckParse extends BaseParse {
668
+ constructor(e, t) {
669
+ super(e, t), this.Detail = "", this.Exp = "", this.Parameter = "";
670
+ var s = this.Expression.split(",");
671
+ if (s.length == 2) {
672
+ var s = this.Expression.split(",");
673
+ if (s.length != 3)
674
+ throw "Check have more or less parameters that 3";
675
+ this.Detail = s[0], this.Exp = s[1], this.Parameter = s[2];
676
+ }
677
+ }
678
+ Evaluate(e, t, s, n) {
679
+ var r = [];
680
+ if (!InvoiceObj.isMultiple(this.Detail)) {
681
+ var i = e.FindTableLevel(this.Detail);
682
+ if (i == null)
683
+ throw "Can't find level {Detail}";
684
+ if (i.Record != null)
685
+ throw "Table level isn't detail!";
686
+ if (i.Records == null)
687
+ throw "Table level doesn't have records!";
688
+ for (var a = i.Records.Records, o = 0; o < a.length; o++)
689
+ r.push(a[o]);
690
+ }
691
+ for (var c = 0, o = 0; o < r.length; o++)
692
+ ;
693
+ if (this.Parameter?.toLocaleLowerCase() == "one")
694
+ return !1;
695
+ if (this.Parameter?.toLocaleLowerCase() == "all")
696
+ return c == r.length;
697
+ throw "Check prameter isn't valid!Valid:One,All.Provided:" + this.Parameter;
698
+ }
699
+ }
700
+ class TrimParse extends BaseParse {
701
+ constructor(e, t) {
702
+ super(e, t);
703
+ }
704
+ Evaluate(e, t, s, n) {
705
+ var r = ExpresionLogicService.GetExpressions(this.Expression, this);
706
+ if (r == null)
707
+ return null;
708
+ if (r.length == 1) {
709
+ var i = r[0].Evaluate(e, t, s, n);
710
+ return typeof i == "string" ? i.trim() : i;
711
+ }
712
+ return r.length;
713
+ }
714
+ }
715
+ class ValueParse extends BaseParse {
716
+ constructor(e, t) {
717
+ super(e, null), this.Table = "", this.FieldName = "", this.Position = "";
718
+ var s = this.Expression.split(","), n = "first";
719
+ s.length == 2 && (n = s[1]);
720
+ var r = s[0].split(".");
721
+ this.Table = r[0], this.FieldName = r[1], this.Position = n;
722
+ }
723
+ Evaluate(e, t, s, n) {
724
+ var r = e.FindTableLevel(this.Table);
725
+ if (r == null)
726
+ return null;
727
+ let i = null;
728
+ if (r.Record != null)
729
+ i = r.Record;
730
+ else if (r.Records != null) {
731
+ var a = r.Records;
732
+ if (a.Records.length == 0)
733
+ return null;
734
+ this.Position.toLowerCase() == "first" ? i = a.Records[0].Record : this.Position.toLowerCase() == "first" && (i = a.Records[a.Records.length - 1].Record);
735
+ }
736
+ if (i == null)
737
+ throw "Can't find valid record for " + this.Table + "!";
738
+ if (i[this.FieldName] == null)
739
+ throw "Value not defined for fieldname " + this.FieldName + "!";
740
+ var o = i[this.FieldName];
741
+ return o == null ? null : typeof o == "number" ? o : o.ToString();
742
+ }
743
+ }
744
+ class UseFirstParse extends BaseParse {
745
+ constructor(e, t) {
746
+ super(e, t), this.useFirstExpressions = [];
747
+ var s = [], n = ExpresionLogicService.GetExpressions(this.Expression, this);
748
+ n?.forEach((r) => {
749
+ if (r instanceof CommaParser && s.length > 0) {
750
+ this.useFirstExpressions.push(s), s = [];
751
+ return;
752
+ }
753
+ s.push(r);
754
+ }), s.length > 0 && this.useFirstExpressions.push(s);
755
+ }
756
+ Evaluate(e, t, s, n) {
757
+ for (var r = 0; r < this.useFirstExpressions.length; r++) {
758
+ var i = this.useFirstExpressions[r], a = ExpresionLogicService.ConcatValues(i, e, t, s, n);
759
+ if (a != null && a != null)
760
+ return a;
761
+ }
762
+ return null;
763
+ }
764
+ }
765
+ const _ExpresionLogicService = class _ExpresionLogicService {
766
+ constructor() {
767
+ }
768
+ static GetExpressions(l, e) {
769
+ let t = [];
770
+ for (var s = 0, n = ""; l.length > 0; ) {
771
+ if (!this.HasFunctionInside(l) && l.indexOf(",") == -1) {
772
+ t.push(new OnlyExpressionParse(l));
773
+ break;
774
+ }
775
+ if (l.substring(s, s + 1) == "(") {
776
+ var r = this.FindEnd(l);
777
+ if (r == -1)
778
+ throw "Unbalanced brackets!!!! Expression:" + l;
779
+ n != "" && (t.push(new LiteralValueParse(n)), n = ""), t.push(new OnlyExpressionParse(l.substring(0, r + 1))), r < l.length ? l = l.substring(r + 1) : l = "";
780
+ continue;
781
+ }
782
+ if (l.startsWith("N.%")) {
783
+ n != "" && (t.push(new LiteralValueParse(n)), n = "");
784
+ var i = l.substring(3).indexOf("%") + 1;
785
+ t.push(new ValueFromObjParse(l.substring(2, i + 3), !0)), l = l.substring(i + 3);
786
+ continue;
787
+ }
788
+ if (l.substring(0, 1) == "%") {
789
+ n != "" && (t.push(new LiteralValueParse(n)), n = "");
790
+ var i = l.substring(1).indexOf("%") + 1;
791
+ t.push(new ValueFromObjParse(l.substring(0, i + 1), !1)), l = l.substring(i + 1);
792
+ continue;
793
+ }
794
+ if (l.substring(s, s + 1) == ",") {
795
+ n != "" && (t.push(new OnlyExpressionParse(n)), n = ""), t.push(new CommaParser(l.substring(0, 1), "")), 1 < l.length ? l = l.substring(1) : l = "";
796
+ continue;
797
+ }
798
+ var a = !1;
799
+ if (BaseParse.operators.forEach((h) => {
800
+ if (l.startsWith(h)) {
801
+ n != "" && (t.push(new OnlyExpressionParse(n)), n = ""), t.push(new OperatorParser(l.substring(0, h.length))), l = l.substring(h.length), a = !0;
802
+ return;
803
+ }
804
+ }), a)
805
+ continue;
806
+ for (let h = 0; h < BaseParse.logicaloperators.length; h++) {
807
+ let u = BaseParse.logicaloperators[h];
808
+ if (l.startsWith(u)) {
809
+ n != "" && (t.push(new OnlyExpressionParse(n)), n = ""), t.push(new LogicalOperatorParser(l.substring(0, u.length))), l = l.substring(u.length), a = !0;
810
+ break;
811
+ }
812
+ }
813
+ if (a)
814
+ continue;
815
+ var o = !1;
816
+ let f = l.toLowerCase();
817
+ var c = Object.keys(_ExpresionLogicService._suportedFunctions);
818
+ for (let h = 0; h < c.length; h++) {
819
+ let u = c[h];
820
+ if (f.startsWith(u)) {
821
+ n != "" && (t.push(new OnlyExpressionParse(n)), n = "");
822
+ var r = this.FindEnd(l);
823
+ if (r == -1)
824
+ throw "Unbalanced brackets!!!! Expression:" + l;
825
+ let v = Reflect.construct(_ExpresionLogicService._suportedFunctions[u], [l.substring(0, r + 1), u]);
826
+ t.push(v), r < l.length ? l = l.substring(r + 1) : l = "", o = !0;
827
+ break;
828
+ }
829
+ }
830
+ o || (n += l.substring(0, 1), l = l.substring(1));
831
+ }
832
+ return n != "" && (t.push(new OnlyExpressionParse(n)), n = ""), t;
833
+ }
834
+ static HasFunctionInside(l) {
835
+ if (l == null || l == "")
836
+ return !1;
837
+ var e = !1;
838
+ const t = l.toLowerCase();
839
+ return Object.keys(_ExpresionLogicService._suportedFunctions).forEach((s) => {
840
+ if (t.indexOf(s) != -1) {
841
+ e = !0;
842
+ return;
843
+ }
844
+ }), e;
845
+ }
846
+ static StartsWithFunction(l) {
847
+ const e = l.toLowerCase();
848
+ var t = !1;
849
+ return Object.keys(_ExpresionLogicService._suportedFunctions).forEach((s) => {
850
+ if (e.startsWith(s)) {
851
+ t = !0;
852
+ return;
853
+ }
854
+ }), t;
855
+ }
856
+ static FindEnd(l) {
857
+ for (var e = 0, t = 0, s = 0; s < l.length; s++)
858
+ if (l.substring(s, s + 1) == "(" ? t++ : l.substring(s, s + 1) == ")" && e++, t > 0 && t == e)
859
+ return s;
860
+ return -1;
861
+ }
862
+ static ConcatValues(l, e, t, s, n) {
863
+ if (l.length == 1)
864
+ return l[0].Evaluate(e, t, s, n);
865
+ let r = "";
866
+ for (let i = 0; i < l.length; i++) {
867
+ let a = l[i].Evaluate(e, t, s, n);
868
+ typeof a == "number" ? r += a.toString() : a instanceof Date ? r += a.toISOString() : r += a;
869
+ }
870
+ return r;
871
+ }
872
+ static CastToTypeNet(l, e) {
873
+ let t = null;
874
+ if (e == null)
875
+ return null;
876
+ switch (l.TypeNET) {
877
+ case "decimal": {
878
+ t = parseFloat(e);
879
+ break;
880
+ }
881
+ case "int": {
882
+ t = parseInt(e);
883
+ break;
884
+ }
885
+ case "bool": {
886
+ this.toString().toLowerCase() == "true" || this.toString().toLowerCase() == "false" || (t = e);
887
+ break;
888
+ }
889
+ default: {
890
+ t = e;
891
+ break;
892
+ }
893
+ }
894
+ return t;
895
+ }
896
+ static ParseAndFillExpression(valueExp, item, obj, citm, record, tryEvaluate, init) {
897
+ if (obj == null)
898
+ return null;
899
+ var value = _ExpresionLogicService.ParseExpressionAndReturnValue(valueExp, obj, item, citm, 0);
900
+ if (console.log(item.FieldName + " " + item.ValueExpression + " " + value), value != null)
901
+ if (tryEvaluate || item.TypeNET == "decimal" || item.TypeNET == "int")
902
+ try {
903
+ if (value == "0/0")
904
+ return citm.Record[item.FieldName] = 0, 0;
905
+ if (value == "*(-1)")
906
+ return null;
907
+ var ret = eval(value);
908
+ return console.log(item.FieldName + " " + item.ValueExpression + " RET: " + value), ret;
909
+ } catch (l) {
910
+ if (init)
911
+ return console.log(item.FieldName + " " + item.ValueExpression + " Err: 0"), 0;
912
+ var val = _ExpresionLogicService.CastToTypeNet(item, value);
913
+ return console.log(item.FieldName + " " + item.ValueExpression + " Err: " + val), val;
914
+ }
915
+ else {
916
+ var val = _ExpresionLogicService.CastToTypeNet(item, value);
917
+ return console.log(item.FieldName + " " + item.ValueExpression + " Ret: " + val), val;
918
+ }
919
+ else
920
+ return console.log(item.FieldName + " " + item.ValueExpression + " Value: " + value), value;
921
+ }
922
+ static ParseExpressionAndReturnValue(l, e, t, s, n) {
923
+ if (l == null || e == null)
924
+ return null;
925
+ let r = null;
926
+ try {
927
+ r = _ExpresionLogicService.GetExpressions(l, null);
928
+ } catch {
929
+ debugger;
930
+ }
931
+ if (r == null)
932
+ return null;
933
+ r[0] instanceof OnlyExpressionParse;
934
+ var i = s.Record;
935
+ if (r.length == 1) {
936
+ var a = r[0].Evaluate(e, s, i, t);
937
+ if (a == null)
938
+ return null;
939
+ if (a instanceof Date) {
940
+ if (t.TypeDDD == "Date")
941
+ return BaseParse.getIsoDate(a);
942
+ if (t.TypeDDD == "DateTime")
943
+ return BaseParse.getIsoDateTime(a);
944
+ } else if (typeof a == "number")
945
+ return a.toString();
946
+ return a.toString();
947
+ }
948
+ return _ExpresionLogicService.ConcatValues(r, e, s, i, t)?.toString();
949
+ }
950
+ static ValueExpresion(l, e, t, s) {
951
+ if (e == "null")
952
+ return null;
953
+ if (!e.startsWith("%") && !e.endsWith("%"))
954
+ return e;
955
+ let n = "";
956
+ try {
957
+ n = e.substring(1, e.length - 1);
958
+ } catch (p) {
959
+ throw l != null ? l.FieldName + " " + l.ValueExpression + " Expression:" + e + p : e + p;
960
+ }
961
+ var r = n.split("."), i = r[0];
962
+ switch (i) {
963
+ default: {
964
+ if (r.length == 2) {
965
+ var a = r[0], o = r[1];
966
+ if (a == s?.Parent?.Tablename) {
967
+ var c = _ExpresionLogicService.ReturnFromObject(s.Record, o);
968
+ if (c.found === !0)
969
+ return c.return;
970
+ }
971
+ var f = t.FindTableLevel(a);
972
+ if (f != null) {
973
+ if (f.Record != null) {
974
+ var h = f.Record, c = _ExpresionLogicService.ReturnFromObject(h.Record, o);
975
+ if (c.found === !0)
976
+ return c.return;
977
+ if (c.found === !1 && o == "InvIssueDate")
978
+ return null;
979
+ if (c.found === !1 && o.indexOf("__") != -1) {
980
+ var u = _ExpresionLogicService.ReturnFromObject(h.Record, o);
981
+ if (u.found === !0)
982
+ return u.return;
983
+ }
984
+ if (u.found === !1 && o != "Mode")
985
+ throw "Can't evaluate " + e + " key:" + l.FieldName;
986
+ return null;
987
+ } else if (f.Records != null) {
988
+ var d = f.Records, v = d.Records.filter((p) => p == s);
989
+ if (v.length > 0) {
990
+ var E = v[0], b = E.Record, c = _ExpresionLogicService.ReturnFromObject(b, o);
991
+ if (c.found === !0)
992
+ return c.return;
993
+ if (c.found === !1 && o.indexOf("__") != -1) {
994
+ var u = _ExpresionLogicService.ReturnFromObject(E.Record, o);
995
+ if (u.found === !0)
996
+ return u.return;
997
+ }
998
+ throw "Can't evaluate " + e + " key:" + l.FieldName;
999
+ }
1000
+ }
1001
+ }
1002
+ }
1003
+ break;
1004
+ }
1005
+ }
1006
+ return null;
1007
+ }
1008
+ static ReturnFromObject(l, e) {
1009
+ return Object.keys(l).indexOf(e) == -1 ? { found: !1, return: null } : l[e] == null ? { found: !0, return: null } : l[e] instanceof Date ? { found: !0, return: l[e] } : { found: !0, return: l[e].toString() };
1010
+ }
1011
+ };
1012
+ _ExpresionLogicService._suportedFunctions = {
1013
+ "sum(": SumParse,
1014
+ "if(": IfParse,
1015
+ "addleadzeros(": AddLeadZerosParse,
1016
+ "appear(": AppearParse,
1017
+ "calcdate(": CalcDateParse,
1018
+ "upper(": UpperLowerParse,
1019
+ "lower(": UpperLowerParse,
1020
+ "inlist(": INListParser,
1021
+ "notinlist(": INListParser,
1022
+ "indetail(": InDetailParse,
1023
+ "notindetail(": InDetailParse,
1024
+ "starts(": StartsParse,
1025
+ "substr(": SubstrParse,
1026
+ "count(": CountParse,
1027
+ "check(": CheckParse,
1028
+ "concat(": ConcatParse,
1029
+ "empty(": EmptyParse,
1030
+ "exists(": ExistParser,
1031
+ "notexists(": ExistParser,
1032
+ "trim(": TrimParse,
1033
+ "value(": ValueParse,
1034
+ "usefirst(": UseFirstParse
1035
+ };
1036
+ let ExpresionLogicService = _ExpresionLogicService;
1037
+ class RecordSingle {
1038
+ constructor(e, t, s) {
1039
+ if (this.Details = null, this.IsDefaultRecord = !1, this._LeftInstance = null, this.Parent = s, e._details != null) {
1040
+ var n = {}, r = Object.keys(e._details);
1041
+ r.forEach((i) => {
1042
+ n[i] = new TableLevel(i, e._details[i], t, this.Parent?.Root ?? null);
1043
+ }), this.Details = n, delete e._details;
1044
+ }
1045
+ this.Record = e;
1046
+ }
1047
+ SetLeftInstanceReference(e) {
1048
+ this._LeftInstance = e;
1049
+ }
1050
+ GetLeftInstanceReference() {
1051
+ return this._LeftInstance;
1052
+ }
1053
+ AddDetail(e, t) {
1054
+ this.Details == null && (this.Details = {}), this.Details[e] = t;
1055
+ }
1056
+ GetDetail(e) {
1057
+ return this.Details == null ? null : this.Details[e];
1058
+ }
1059
+ HasDetails(e) {
1060
+ return this.Details == null ? !1 : this.Details[e] != null;
1061
+ }
1062
+ SetValueToKey(e, t, s) {
1063
+ if (t == null) {
1064
+ this.Record[e.FieldName] = null;
1065
+ return;
1066
+ }
1067
+ if (e.FieldName != null) {
1068
+ if (typeof t == "string")
1069
+ switch (e.Type) {
1070
+ case "int": {
1071
+ t = parseInt(t);
1072
+ break;
1073
+ }
1074
+ case "decimal": {
1075
+ t = parseFloat(t);
1076
+ break;
1077
+ }
1078
+ case "bool":
1079
+ case "boolean": {
1080
+ t = (r) => r.trim().toLowerCase() === "true";
1081
+ break;
1082
+ }
1083
+ }
1084
+ if (e.RoundTo != null) {
1085
+ var n = e.RoundTo;
1086
+ typeof t == "number" && (t = this.roundUp(t, n));
1087
+ }
1088
+ }
1089
+ this.Record[e.FieldName] = t;
1090
+ }
1091
+ roundUp(e, t) {
1092
+ let s = !1;
1093
+ e < 0 ? s = !0 : s = !1, s ? e = e - 10 ** -13 : e = e + 10 ** -13, e = Math.abs(e);
1094
+ let n = Math.round(e * Math.pow(10, t)) / Math.pow(10, t);
1095
+ return s ? -1 * n : n;
1096
+ }
1097
+ GetObject() {
1098
+ var e = JSON.parse(JSON.stringify(this.Record));
1099
+ if (this.Details != null) {
1100
+ let t = JSON.parse("{}");
1101
+ for (let s = 0; s < this.Details.length; s++) {
1102
+ let n = this.Details[s].GetObject();
1103
+ n != null && (t[this.Details[s].Tablename] = n);
1104
+ }
1105
+ e._details = t;
1106
+ }
1107
+ return e;
1108
+ }
1109
+ TranslateObj(e) {
1110
+ if (this.Details != null)
1111
+ for (let r = 0; r < this.Details.length; r++)
1112
+ this.Details[r].TranslateObj(e);
1113
+ var t = Object.keys(this.Record), s = Object.keys(e), n = t.filter((r) => s.indexOf(r) != -1);
1114
+ n.length > 0 && n.forEach((r) => {
1115
+ var i = e[r].data[this.Record[e[r].key]];
1116
+ i != null && (this.Record[r] = e[r].data[this.Record[e[r].key]]);
1117
+ });
1118
+ }
1119
+ MapToId(e) {
1120
+ e.length != 0 && e.forEach((t) => {
1121
+ this.MapToIdItem(t);
1122
+ });
1123
+ }
1124
+ MapToIdItem(e) {
1125
+ }
1126
+ EvaluateInner(e) {
1127
+ e.length != 0 && e.forEach((t) => {
1128
+ if (this.Parent?.Root?.EvalType == "Init") {
1129
+ if (this.Record[t.FieldName] != null && t.ValueExpresionInit != null) {
1130
+ var s = ExpresionLogicService.ParseAndFillExpression(t.ValueExpresionInit, t, this?.Parent?.Root ?? null, this, this.Record, !0, !1);
1131
+ this.Record[t.FieldName] = s;
1132
+ }
1133
+ } else this.Parent?.Root?.EvalType == "Eval" && this.Evaluate(t);
1134
+ });
1135
+ }
1136
+ Evaluate(e) {
1137
+ if (!(e.EvalOnlyIfEmpty === !0 && this.Record[e.FieldName] != null)) {
1138
+ if (e.EvaluateOnlyIF != null) {
1139
+ var t = ExpresionLogicService.ParseExpressionAndReturnValue(e.EvaluateOnlyIF, this?.Parent?.Root ?? null, e, this, 0);
1140
+ if (t == null || t.toUpperCase() != "TRUE")
1141
+ return;
1142
+ }
1143
+ if (e.ValueExpression != null) {
1144
+ var s = ExpresionLogicService.ParseAndFillExpression(e.ValueExpression, e, this?.Parent?.Root ?? null, this, this.Record, !0, !1);
1145
+ this.Record[e.FieldName] = s;
1146
+ } else
1147
+ this.Record[e.FieldName] == null && (this.Record[e.FieldName] = null);
1148
+ e.GetValueFrom;
1149
+ }
1150
+ }
1151
+ ParseExpressionAndReturnValue(e, t) {
1152
+ return this.ParseExpressionAndReturnValueNew(e, t);
1153
+ }
1154
+ ParseExpressionAndReturnValueNew(e, t) {
1155
+ if (this.Parent?.Root == null)
1156
+ return null;
1157
+ var s = ExpresionLogicService.ParseAndFillExpression(e, t, this.Parent.Root, this, this.Record, !1, !1);
1158
+ return s;
1159
+ }
1160
+ valueToType(e) {
1161
+ return e == null || e == "null" ? null : typeof e != "string" ? e : e.toLocaleLowerCase() == "true" ? !0 : e.toLocaleLowerCase() == "false" ? !1 : isNaN(parseFloat(e)) ? e : parseFloat(e);
1162
+ }
1163
+ ValueExpresion(e) {
1164
+ if (e == null)
1165
+ return null;
1166
+ if (!e.startsWith("%") || !e.endsWith("%"))
1167
+ return this.valueToType(e);
1168
+ let s = e.substring(1, e.length - 1).split(".");
1169
+ var n = s[0];
1170
+ switch (n) {
1171
+ case "V":
1172
+ return console.warn("V not supported!"), null;
1173
+ case "E": {
1174
+ const r = s[1];
1175
+ if (s[2], r != "EU_AOrg") {
1176
+ if (r != "EU_SCR") {
1177
+ if (r != "Session") return console.warn("Other E not supported!"), null;
1178
+ }
1179
+ }
1180
+ }
1181
+ case "S":
1182
+ return console.warn("S not supported!"), null;
1183
+ default: {
1184
+ if (s.length == 2) {
1185
+ const r = s[0];
1186
+ if (r == this.Parent?.Tablename)
1187
+ return this.Record[s[1]];
1188
+ {
1189
+ let i = this.Parent?.Root?.FindTableLevel(r);
1190
+ if (i != null && i.Record != null && i?.Record != null)
1191
+ return this.valueToType(i?.Record.Record[s[1]]);
1192
+ }
1193
+ }
1194
+ break;
1195
+ }
1196
+ }
1197
+ return null;
1198
+ }
1199
+ FindEnd(e) {
1200
+ for (var t = 0, s = 0, n = 0; n < e.length; n++)
1201
+ if (e.substring(n, n + 1) == "(" ? s++ : e.substring(n, n + 1) == ")" && t++, s > 0 && s == t)
1202
+ return n;
1203
+ return -1;
1204
+ }
1205
+ getSaveObject(e) {
1206
+ const t = {};
1207
+ if (this.Details != null) {
1208
+ const r = {};
1209
+ for (let i = 0; i < this.Details.length; i++) {
1210
+ const a = this.Details[i].getSaveObject(e);
1211
+ a != null && (r[this.Details[i].Tablename] = a);
1212
+ }
1213
+ Object.keys(r).length > 0 && (t._details = r);
1214
+ }
1215
+ if (this.Parent?.Tablename == null)
1216
+ return null;
1217
+ const s = e[this.Parent?.Tablename], n = Object.keys(s);
1218
+ for (let r = 0; r < n.length; r++) {
1219
+ const i = n[r];
1220
+ switch (s[i].TypeDDD) {
1221
+ case "Date": {
1222
+ t[i] = BaseParse.getIsoDate(this.Record[i]);
1223
+ break;
1224
+ }
1225
+ case "DateTime": {
1226
+ t[i] = BaseParse.getIsoDateTime(this.Record[i]);
1227
+ break;
1228
+ }
1229
+ default: {
1230
+ t[i] = this.Record[i];
1231
+ break;
1232
+ }
1233
+ }
1234
+ }
1235
+ return this.Record.Id != null && (t.Id = this.Record.Id), this.Parent?.Tablename == "EU_Invoices", Object.keys(t).length > 0 ? t : null;
1236
+ }
1237
+ getFullObject(e) {
1238
+ const t = {};
1239
+ if (this.Details != null) {
1240
+ const r = {};
1241
+ for (let i = 0; i < this.Details.length; i++) {
1242
+ const a = this.Details[i].getSaveObject(e);
1243
+ a != null && (r[this.Details[i].Tablename] = a);
1244
+ }
1245
+ Object.keys(r).length > 0 && (t._details = r);
1246
+ }
1247
+ if (this.Parent?.Tablename == null)
1248
+ return null;
1249
+ const s = e[this.Parent?.Tablename], n = Object.keys(s);
1250
+ for (let r = 0; r < n.length; r++) {
1251
+ const i = n[r];
1252
+ switch (s[i].TypeDDD) {
1253
+ case "Date": {
1254
+ t[i] = BaseParse.getIsoDate(this.Record[i]);
1255
+ break;
1256
+ }
1257
+ case "DateTime": {
1258
+ t[i] = BaseParse.getIsoDateTime(this.Record[i]);
1259
+ break;
1260
+ }
1261
+ default: {
1262
+ t[i] = this.Record[i];
1263
+ break;
1264
+ }
1265
+ }
1266
+ }
1267
+ return this.Record.Id != null && (t.Id = this.Record.Id), this.Parent?.Tablename == "EU_Invoices" && (t.InvTotalVatAmountCCInp = this.Record.InvTotalVatAmountCC, t.InvAmountInclVatInp = this.Record.InvAmountInclVat), Object.keys(t).length > 0 ? t : null;
1268
+ }
1269
+ Validate() {
1270
+ }
1271
+ }
1272
+ class RecordArray {
1273
+ constructor(e, t, s) {
1274
+ this.Records = [], this.Parent = s, this.ObjectInfo = t;
1275
+ for (let r = 0; r < e.length; r++) {
1276
+ var n = e[r];
1277
+ this.Records.push(new RecordSingle(n, t, s));
1278
+ }
1279
+ }
1280
+ MapToId(e) {
1281
+ if (this.Records != null)
1282
+ for (let t = 0; t < this.Records.length; t++)
1283
+ this.Records[t].MapToId(e);
1284
+ }
1285
+ EvaluateInner(e) {
1286
+ if (this.Records != null)
1287
+ for (let t = 0; t < this.Records.length; t++)
1288
+ this.Records[t].EvaluateInner(e);
1289
+ }
1290
+ TranslateObj(e) {
1291
+ if (this.Records.length != 0)
1292
+ for (let t = 0; t < this.Records.length; t++)
1293
+ this.Records[t].TranslateObj(e);
1294
+ }
1295
+ GetObject() {
1296
+ if (this.Records.length == 0)
1297
+ return null;
1298
+ var e = [];
1299
+ for (let t = 0; t < this.Records.length; t++)
1300
+ e.push(this.Records[t].GetObject());
1301
+ return e;
1302
+ }
1303
+ getSaveObject(e) {
1304
+ if (this.Records == null)
1305
+ return null;
1306
+ var t = [];
1307
+ if (this.Parent?.Tablename == "EU_Invoices_Items_Classes" && this.Records.length == 1) {
1308
+ var s = this.Records[0];
1309
+ if (s.Record.ItemClassCodeSchID == null && s.Record.ItemClassCode == null)
1310
+ return t;
1311
+ }
1312
+ for (let n = 0; n < this.Records.length; n++)
1313
+ t.push(this.Records[n].getSaveObject(e));
1314
+ return t;
1315
+ }
1316
+ getFullObject(e) {
1317
+ if (this.Records == null)
1318
+ return null;
1319
+ var t = [];
1320
+ for (let s = 0; s < this.Records.length; s++)
1321
+ t.push(this.Records[s].getSaveObject(e));
1322
+ return t;
1323
+ }
1324
+ Validate() {
1325
+ if (this.Records == null)
1326
+ return null;
1327
+ const e = {};
1328
+ for (let r = 0; r < this.Records.length; r++) {
1329
+ let i = this.Records[r].Validate();
1330
+ i != null && (e[r.toString()] = i);
1331
+ }
1332
+ if (Object.keys(e).length == 0)
1333
+ return null;
1334
+ const t = Object.keys(e);
1335
+ let s = "", n = [];
1336
+ for (let r = 0; r < t.length; r++) {
1337
+ let i = "";
1338
+ const a = t[r];
1339
+ let o = e[a];
1340
+ o.missingKeys != null && (i = "Missing mandatory keys:" + o.missingKeys), i != null && (s += "Errors on index " + a + ": " + i, n.push([a, o.missingKeys]));
1341
+ }
1342
+ return { errorMessage: s == "" ? null : s, validateDetailsErrors: n };
1343
+ }
1344
+ }
1345
+ const m = class m {
1346
+ static IsDetailTable(e) {
1347
+ return this._objectTablesDetail.indexOf(e) != -1;
1348
+ }
1349
+ static isMultiple(e) {
1350
+ return e == "EU_Invoices_Items_Classes" || e == "EU_Invoices_Items_AllowsCharges" || e == "EU_Invoices_CN_IICRefs_Items" || e == "EU_Invoices_AdvanceUsage" || e == "EU_Invoices_AdvanceUsageVatCode" || e == "EU_Invoices_Items_Attributes";
1351
+ }
1352
+ static GetMultipleParent(e) {
1353
+ return this.__multipleParent[e] ? this.__multipleParent[e] : null;
1354
+ }
1355
+ static GetTableForAlias(e) {
1356
+ return this._dicAliasMap[e] ?? e;
1357
+ }
1358
+ static GetTableFromAlias(e) {
1359
+ for (var t = Object.keys(this._dicAliasMap), s = 0; s < t.length; s++)
1360
+ if (this._dicAliasMap[t[s]] == e)
1361
+ return t[s];
1362
+ return e;
1363
+ }
1364
+ };
1365
+ m.masterEntity = "EU_Invoices", m.itemsEntity = "EU_Invoices_Items", m.vatEntity = "EU_Invoices_Vats", m.paymentInstrsEntity = "EU_Invoices_PaymentInstrs", m._objectTablesDetail = [
1366
+ "EU_Invoices_Items",
1367
+ "EU_Invoices_Items_Classes",
1368
+ "EU_Invoices_Items_Attributes",
1369
+ "EU_Invoices_Items_AllowsCharges",
1370
+ "EU_Invoices_Errors",
1371
+ "EU_Invoices_PaymentInstrs",
1372
+ "EU_Invoices_Vats",
1373
+ "EU_Invoices_VatsFisc",
1374
+ "EU_Invoices_VatsCatCode",
1375
+ "EU_Invoices_VatsUI",
1376
+ "EU_Invoices_PrecedInvs",
1377
+ "EU_Invoices_AllowsCharges",
1378
+ "EU_Invoices_AddRefDocs",
1379
+ "EU_Invoices_AdvanceUsage"
1380
+ ], m._dicAliasMap = {
1381
+ EU_Invoices: "Invoice",
1382
+ EU_Invoices_CN_IICRefs: "CreditNoteRefs",
1383
+ EU_Invoices_Items: "Items",
1384
+ EU_Invoices_PaymentInstrs: "Payments",
1385
+ EU_Invoices_AddRefDocs: "Attachments"
1386
+ }, m.__multipleParent = {
1387
+ EU_Invoices_Items_Classes: "EU_Invoices_Items",
1388
+ EU_Invoices_Items_AllowsCharges: "EU_Invoices_Items",
1389
+ EU_Invoices_CN_IICRefs_Items: "EU_Invoices_Items",
1390
+ EU_Invoices_Items_Attributes: "EU_Invoices_Items"
1391
+ };
1392
+ let HelpersTables = m;
1393
+ class InvoiceObj {
1394
+ constructor(e, t) {
1395
+ this.rootLevel = null, this.LeftObject = null, this.EvalType = "Init", this.Mappings = null, this.CodeListCache = {}, this.LeftObject = e, this.ObjectInfo = t?.ObjectInfo ?? {}, this.CodeListCache = t?.CodeListCache ?? {};
1396
+ }
1397
+ static isMultiple(e) {
1398
+ return e == "EU_Invoices_Items_Classes" || e == "EU_Invoices_Items_AllowsCharges" || e == "EU_Invoices_CN_IICRefs_Items" || e == "EU_Invoices_AdvanceUsage" || e == "EU_Invoices_AdvanceUsageVatCode";
1399
+ }
1400
+ InitAfterConst() {
1401
+ }
1402
+ FindTableLevel(e) {
1403
+ var t = this.RecursiveFindLevel(this.rootLevel, e);
1404
+ return t ?? (console.error("Can't find level " + e), null);
1405
+ }
1406
+ RecursiveFindLevel(e, t) {
1407
+ if (e == null)
1408
+ return null;
1409
+ if (e?.Tablename == t)
1410
+ return e;
1411
+ if (e.Record != null && e.Record.Details != null)
1412
+ for (let s = 0; s < e.Record.Details.length; s++) {
1413
+ const n = this.RecursiveFindLevel(e.Record.Details[s], t);
1414
+ if (n != null)
1415
+ return n;
1416
+ }
1417
+ return null;
1418
+ }
1419
+ GetObject() {
1420
+ return this.rootLevel?.GetObject();
1421
+ }
1422
+ SumByKey(e) {
1423
+ var t = e.split(","), s = t[0].split(".");
1424
+ if (s.length != 2)
1425
+ throw "Key isn't well formmed! " + e;
1426
+ var n = this.RecursiveFindLevel(this.rootLevel, s[0]);
1427
+ if (n == null)
1428
+ throw "Can't find table level " + s[0];
1429
+ let r = null;
1430
+ if (t.length == 2) {
1431
+ var i = t[1].split(".");
1432
+ r = i[1];
1433
+ }
1434
+ let a = 0;
1435
+ if (n.Records != null)
1436
+ for (var o = n.Records, c = 0; c < o.Records.length; c++) {
1437
+ const f = o.Records[c];
1438
+ if (f.Record[s[1]] != null) {
1439
+ if (r != null && !f.Record[r])
1440
+ continue;
1441
+ a += f.Record[s[1]];
1442
+ }
1443
+ }
1444
+ return a;
1445
+ }
1446
+ getSaveObject() {
1447
+ return {};
1448
+ }
1449
+ getFullObject() {
1450
+ const e = {};
1451
+ return e[this.rootLevel?.Tablename ?? "EU_Invoices"] = this.rootLevel?.getFullObject(this.ObjectInfo), e;
1452
+ }
1453
+ ValidateBeforeSave() {
1454
+ }
1455
+ ConcateErrors(e, t) {
1456
+ return e == "" ? (e = t, e) : (e += " " + t, e);
1457
+ }
1458
+ TranslateObj(e) {
1459
+ this.rootLevel?.TranslateObj(e);
1460
+ }
1461
+ prepareSchemaStruct() {
1462
+ var e = [], t = Object.keys(this.ObjectInfo);
1463
+ return t.forEach((s) => {
1464
+ var n = Object.keys(this.ObjectInfo[s]);
1465
+ n.forEach((r) => {
1466
+ e.push(this.ObjectInfo[s][r]);
1467
+ });
1468
+ }), e;
1469
+ }
1470
+ Evaluate() {
1471
+ var e = this.prepareSchemaStruct(), t = e.filter((s) => s.ValueExpressionInit != null);
1472
+ return this.InicializeEval("Init", t), t = e.filter((s) => s.EvalStep == "PRE" && (s.ValueExpression != null || s.GetValueFrom == "Mappings" || s.GetValueFrom == "Code")), this.InicializeEval("Eval", t), t = e.filter((s) => s.ConnField), this.MapToId(t), t = e.filter((s) => s.EvalStep == "EVAL"), this.InicializeEval("Eval", t), t = e.filter((s) => s.EvalStep == "POST" && s.Group == "Vats"), this.vatsPrepare(t), t = e.filter((s) => s.EvalStep == "POST" && s.Group != "Vats"), this.InicializeEval("Eval", t), !0;
1473
+ }
1474
+ InicializeEval(e, t) {
1475
+ if (this.EvalType = e, t.length == 0)
1476
+ return !0;
1477
+ try {
1478
+ var s = t.sort((i, a) => (i.CalcPhase ?? 0) - (a.CalcPhase ?? 0)), n = [], r = null;
1479
+ for (let i = 0; i < s.length; i++) {
1480
+ const a = s[i];
1481
+ if (r == null) {
1482
+ r = a.TableName, n.push(a);
1483
+ continue;
1484
+ }
1485
+ r != a.TableName && (this.InicializeEvalInner(r ?? "", n), n = [], r = a.TableName), n.push(a);
1486
+ }
1487
+ n.length > 0 && this.InicializeEvalInner(r ?? "", n);
1488
+ } catch {
1489
+ return !1;
1490
+ }
1491
+ return !0;
1492
+ }
1493
+ FillInvoiceDataIntoObjStuct(e, t, s, n) {
1494
+ var r = this.rootLevel?.Record;
1495
+ if (t.length > 0) {
1496
+ const Y = n ? HelpersTables.masterEntity : "Invoice";
1497
+ var i = e[Y], a = i._details, o = /* @__PURE__ */ new Map(), c = this.RecursiveFindLevel(null, HelpersTables.masterEntity), r = c?.Record, f = this.groupBy(t, "TableName"), h = Object.keys(f);
1498
+ if (i != null || a != null)
1499
+ for (var u = 0; u < h.length; u++) {
1500
+ var d = h[u], v = f[d];
1501
+ if (d == HelpersTables.masterEntity) {
1502
+ if (i == null || r == null)
1503
+ continue;
1504
+ for (var E = 0; E < v.length; E++) {
1505
+ var b = v[E];
1506
+ this.setValueForObject(i, r, b, n, null);
1507
+ }
1508
+ } else if (HelpersTables.IsDetailTable(d)) {
1509
+ if (a == null)
1510
+ continue;
1511
+ if (HelpersTables.isMultiple(d)) {
1512
+ o.set(d, v);
1513
+ continue;
1514
+ }
1515
+ var p = n ? d : HelpersTables.GetTableForAlias(d);
1516
+ if (a[p] == null || a[p].length == 0)
1517
+ continue;
1518
+ var g = this.RecursiveFindLevel(this.rootLevel, d);
1519
+ if (g == null || g == null)
1520
+ continue;
1521
+ var R = [], I = a[p], C = {};
1522
+ if (g?.Records != null && g.Records?.Records.length > 0) {
1523
+ var j = g.Records.Records[0];
1524
+ j.IsDefaultRecord = !1;
1525
+ for (var k = Object.keys(j.Record), P = 0; P < k.length; P++) {
1526
+ var _ = k[P];
1527
+ C[_] = j.Record[_];
1528
+ }
1529
+ }
1530
+ for (var u = 0; u < I.length; u++) {
1531
+ for (var A = JSON.parse(JSON.stringify(C)), F = I[u], y = new RecordSingle(A, s, g), T = 0; v.length; T++) {
1532
+ var b = v[T];
1533
+ this.setValueForObject(F, y, b, n, null);
1534
+ }
1535
+ y.SetLeftInstanceReference(F), R.push(y);
1536
+ }
1537
+ g.Records = new RecordArray(R, s, g);
1538
+ }
1539
+ }
1540
+ else
1541
+ for (var H = t.filter((x) => x.FromInputKey != null), f = this.groupBy(H, "TableName"), u = 0; u < h.length; u++) {
1542
+ var d = h[u], v = f[d];
1543
+ if (d == HelpersTables.masterEntity && r != null)
1544
+ for (var E = 0; E < v.length; E++) {
1545
+ var b = v[E];
1546
+ this.setValueForObject(i, r, b, n, null);
1547
+ }
1548
+ else {
1549
+ var p = HelpersTables.GetTableForAlias(d), g = this.RecursiveFindLevel(null, d);
1550
+ if (g == null)
1551
+ continue;
1552
+ var R = [], Z = "", I = this.FindJArray(e, v[0]?.FromInputKey?.split(".") ?? [], Z), C = {};
1553
+ if (g.Records?.Records == null || g.Records.Records.length === 0 || g.Records.Records[0].Record == null)
1554
+ continue;
1555
+ for (var M = g.Records.Records[0].Record, B = Object.keys(M), P = 0; P < B.length; P++) {
1556
+ var _ = B[P];
1557
+ C[_] = M.Record[_];
1558
+ }
1559
+ for (var u = 0; u < I.length; u++) {
1560
+ for (var A = JSON.parse(JSON.stringify(C)), F = I[u], y = new RecordSingle(A, s, g), T = 0; v.length; T++) {
1561
+ var b = v[T];
1562
+ this.setValueForObject(F, y, b, n, null);
1563
+ }
1564
+ y.SetLeftInstanceReference(F), R.push(y);
1565
+ }
1566
+ g.Records = new RecordArray(R, s, g);
1567
+ }
1568
+ }
1569
+ if (o.size > 0)
1570
+ return;
1571
+ for (const [O, x] of o) {
1572
+ var G = HelpersTables.GetMultipleParent(O);
1573
+ if (G == null)
1574
+ throw "Can't find parent for multiple table " + O;
1575
+ var W = this.RecursiveFindLevel(this.rootLevel, G);
1576
+ if (W != null)
1577
+ for (var L = W.Records?.Records ?? [], u = 0; u < L?.length; u++) {
1578
+ var J = L[u].GetLeftInstanceReference();
1579
+ if (J == null)
1580
+ continue;
1581
+ var z = J._details;
1582
+ if (z == null)
1583
+ continue;
1584
+ var D = z[O];
1585
+ if (D == null || D.length == 0)
1586
+ continue;
1587
+ let S = null;
1588
+ if (L[u].HasDetails(O)) {
1589
+ if (S = L[u].GetDetail(O), S == null)
1590
+ continue;
1591
+ } else
1592
+ S = new TableLevel(O, [], this.ObjectInfo, this), L[u].AddDetail(O, S);
1593
+ for (var U = S.Records?.Records, K = [], u = 0; u < D.Count; u++) {
1594
+ D[u];
1595
+ let V = null;
1596
+ U && U.length > u ? V = U[u] : (V = new RecordSingle({}, this.ObjectInfo, S), K.push(V));
1597
+ for (var T = 0; x.length; T++) {
1598
+ var b = x[T];
1599
+ this.setValueForObject(F, V, b, n, null);
1600
+ }
1601
+ }
1602
+ }
1603
+ }
1604
+ }
1605
+ }
1606
+ FindJArray(e, t, s) {
1607
+ if (t.length == 0)
1608
+ return null;
1609
+ if (s != "" && (s += "."), s += t[0], e[t[0]] != null && Array.isArray(e[t[0]])) {
1610
+ var n = e[t[0]], r = JSON.parse(JSON.stringify(t));
1611
+ return r.splice(0, 1), n.length == 1 && t.length > 2 ? this.FindJArray(n[0], r, s) : n;
1612
+ }
1613
+ var i = JSON.parse(JSON.stringify(t));
1614
+ return i.splice(0, 1), this.FindJArray(e[t[0]], i, s);
1615
+ }
1616
+ setValueForObject(e, t, s, n, r) {
1617
+ if (e != null) {
1618
+ var i = n ? s.FieldName : s.Alias;
1619
+ if (e[i] == null) {
1620
+ var a = t.Record;
1621
+ t.SetValueToKey(s, e[i], a);
1622
+ } else if (s.FromInputKey != null)
1623
+ for (var o = s.FromInputKey.split("??"), c = 0; c < o.length; c++) {
1624
+ var f = o[c];
1625
+ if (r != null && (f = f.replace(r + ".", "")), e.Get(f) != null) {
1626
+ var a = t.Record;
1627
+ t.SetValueToKey(s, e.Get(f), a);
1628
+ }
1629
+ }
1630
+ }
1631
+ }
1632
+ InicializeEvalInner(e, t) {
1633
+ var s = this.RecursiveFindLevel(null, e);
1634
+ return s == null ? !1 : (s.Evaluate(t), !0);
1635
+ }
1636
+ MapToId(e) {
1637
+ if (e.length == 0)
1638
+ return !0;
1639
+ try {
1640
+ var t = e.sort((r, i) => (r.CalcPhase ?? 0) - (i.CalcPhase ?? 0)), s = [], n = null;
1641
+ for (let r = 0; r < t.length; r++) {
1642
+ const i = t[r];
1643
+ if (n == null) {
1644
+ n = i.TableName, s.push(i);
1645
+ continue;
1646
+ }
1647
+ n != i.TableName && (this.MapToIdInner(n ?? "", s), s = [], n = i.TableName), s.push(i);
1648
+ }
1649
+ s.length > 0 && this.MapToIdInner(n ?? "", s);
1650
+ } catch {
1651
+ return !1;
1652
+ }
1653
+ return !0;
1654
+ }
1655
+ MapToIdInner(e, t) {
1656
+ var s = this.RecursiveFindLevel(null, e);
1657
+ return s == null ? !1 : (s.MapToId(t), !0);
1658
+ }
1659
+ vatsPrepare(e) {
1660
+ if (e.length != 0) {
1661
+ var t = this.RecursiveFindLevel(null, "EU_Invoices_Items"), s = this.groupBy(e, "TableName");
1662
+ for (const a in s) {
1663
+ var n = this.RecursiveFindLevel(null, a);
1664
+ n == null && (n = new TableLevel(a, [], this.ObjectInfo, this)), n.Records == null && (n.Records = new RecordArray([], this.ObjectInfo[a], n));
1665
+ var r = {};
1666
+ t?.Records?.Records.forEach((c) => {
1667
+ var f = c.Record.VatsUIGroupKey;
1668
+ r[f] == null && (r[f] = !0);
1669
+ });
1670
+ var i = [];
1671
+ Object.keys(r).forEach((c) => {
1672
+ var f = {};
1673
+ f.__VatRate = c, i.push(f);
1674
+ }), n.Records.Records = i;
1675
+ const o = s[a];
1676
+ n.Evaluate(o);
1677
+ }
1678
+ }
1679
+ }
1680
+ groupBy(e, t) {
1681
+ return e.reduce((s, n) => {
1682
+ const r = String(n[t]);
1683
+ return (s[r] ||= []).push(n), s;
1684
+ }, {});
1685
+ }
1686
+ }
1687
+ class HelperSessionStorage {
1688
+ static hasKey(e) {
1689
+ return this.getFromSessionStorage(e) != null;
1690
+ }
1691
+ static getFromSessionStorage(e) {
1692
+ return localStorage.getItem(e);
1693
+ }
1694
+ static setToSessionStorage(e, t) {
1695
+ localStorage.setItem(e, JSON.stringify(t));
1696
+ }
1697
+ }
1698
+ const evaluateEdit = (l, e) => {
1699
+ var t = fromEditToTech(l), s = new InvoiceObj(t, e);
1700
+ return s.Evaluate() || console.log("Errors:"), s.GetObject();
1701
+ }, fromEditToTech = (l) => {
1702
+ var e = fromEditToTechRecurzive("Invoice", l.Invoice);
1703
+ return e;
1704
+ }, fromEditToTechRecurzive = (l, e) => {
1705
+ var t = null;
1706
+ return e != null && (Array.isArray(e) ? (t = [], e.forEach((s) => {
1707
+ t.push(fromEditToTechSingle(s));
1708
+ })) : t = fromEditToTechSingle(e)), { table: t };
1709
+ }, fromEditToTechSingle = (l) => {
1710
+ var e = {}, t = Object.keys(l);
1711
+ return t.forEach((s) => {
1712
+ if (s == "_details") {
1713
+ var n = {}, r = Object.keys(l[s]);
1714
+ r.forEach((i) => {
1715
+ n[i] = fromEditToTechRecurzive(i, l[s][i]);
1716
+ }), e._details = n;
1717
+ return;
1718
+ }
1719
+ e[s] = l[s].Value;
1720
+ }), t;
1721
+ }, getClientInfo = () => {
1722
+ var l = HelperSessionStorage.getFromSessionStorage("ClientInfo");
1723
+ return l;
1724
+ }, setClientInfo = (l) => {
1725
+ HelperSessionStorage.setToSessionStorage("ClientInfo", JSON.stringify(l));
1726
+ };
1727
+ export {
1728
+ evaluateEdit,
1729
+ getClientInfo,
1730
+ setClientInfo
1731
+ };