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.
- package/Evaluator/ExpresionLogicService.ts +669 -0
- package/Evaluator/Parser/AddLeadZerosParse.ts +70 -0
- package/Evaluator/Parser/AppearParse.ts +67 -0
- package/Evaluator/Parser/BaseParse.ts +93 -0
- package/Evaluator/Parser/CalcDateParse.ts +73 -0
- package/Evaluator/Parser/CheckParse.ts +99 -0
- package/Evaluator/Parser/CommaParser.ts +17 -0
- package/Evaluator/Parser/ConcatParse.ts +34 -0
- package/Evaluator/Parser/CountParse.ts +26 -0
- package/Evaluator/Parser/EmptyParse.ts +41 -0
- package/Evaluator/Parser/ExistParse.ts +69 -0
- package/Evaluator/Parser/IfParse.ts +388 -0
- package/Evaluator/Parser/IfStategment.ts +345 -0
- package/Evaluator/Parser/InDetailParse.ts +109 -0
- package/Evaluator/Parser/InListParse.ts +57 -0
- package/Evaluator/Parser/LiteralValueParse.ts +36 -0
- package/Evaluator/Parser/LogicalOperatorParse.ts +16 -0
- package/Evaluator/Parser/OnlyExpressionParse.ts +137 -0
- package/Evaluator/Parser/OperatorParse.ts +17 -0
- package/Evaluator/Parser/StartsParse.ts +36 -0
- package/Evaluator/Parser/SubstrParse.ts +110 -0
- package/Evaluator/Parser/SumParse.ts +15 -0
- package/Evaluator/Parser/ToNullParser.ts +0 -0
- package/Evaluator/Parser/TrimParse.ts +30 -0
- package/Evaluator/Parser/UpperLoverParse.ts +41 -0
- package/Evaluator/Parser/ValueFromObjParse.ts +37 -0
- package/Evaluator/Parser/ValueParse.ts +61 -0
- package/HelperSessionStorage.ts +13 -0
- package/Interfaces/SchemaStruct.ts +28 -0
- package/Library/jsonrpc-2.0.js +869 -0
- package/Structure/InvoiceObj.ts +691 -0
- package/Structure/RecordArray.ts +145 -0
- package/Structure/RecordSingle.ts +1076 -0
- package/Structure/TableLevel.ts +248 -0
- package/dist/Evaluator/ExpresionLogicService.js +505 -0
- package/dist/Evaluator/Parser/AddLeadZerosParse.js +55 -0
- package/dist/Evaluator/Parser/AppearParse.js +48 -0
- package/dist/Evaluator/Parser/BaseParse.js +89 -0
- package/dist/Evaluator/Parser/CalcDateParse.js +54 -0
- package/dist/Evaluator/Parser/CheckParse.js +80 -0
- package/dist/Evaluator/Parser/CommaParser.js +13 -0
- package/dist/Evaluator/Parser/ConcatParse.js +29 -0
- package/dist/Evaluator/Parser/CountParse.js +23 -0
- package/dist/Evaluator/Parser/EmptyParse.js +35 -0
- package/dist/Evaluator/Parser/ExistParse.js +57 -0
- package/dist/Evaluator/Parser/IfParse.js +296 -0
- package/dist/Evaluator/Parser/IfStategment.js +287 -0
- package/dist/Evaluator/Parser/InDetailParse.js +79 -0
- package/dist/Evaluator/Parser/InListParse.js +40 -0
- package/dist/Evaluator/Parser/LiteralValueParse.js +26 -0
- package/dist/Evaluator/Parser/LogicalOperatorParse.js +13 -0
- package/dist/Evaluator/Parser/OnlyExpressionParse.js +106 -0
- package/dist/Evaluator/Parser/OperatorParse.js +13 -0
- package/dist/Evaluator/Parser/StartsParse.js +30 -0
- package/dist/Evaluator/Parser/SubstrParse.js +83 -0
- package/dist/Evaluator/Parser/SumParse.js +13 -0
- package/dist/Evaluator/Parser/ToNullParser.js +1 -0
- package/dist/Evaluator/Parser/TrimParse.js +25 -0
- package/dist/Evaluator/Parser/UpperLoverParse.js +32 -0
- package/dist/Evaluator/Parser/ValueFromObjParse.js +29 -0
- package/dist/Evaluator/Parser/ValueParse.js +59 -0
- package/dist/HelperSessionStorage.js +12 -0
- package/dist/Interfaces/SchemaStruct.js +2 -0
- package/dist/Structure/InvoiceObj.js +610 -0
- package/dist/Structure/RecordArray.js +102 -0
- package/dist/Structure/RecordSingle.js +950 -0
- package/dist/Structure/TableLevel.js +162 -0
- package/dist/index.js +19 -0
- package/index.ts +20 -0
- package/package.json +20 -0
- package/tsconfig.json +103 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CalcDateParse = void 0;
|
|
4
|
+
const BaseParse_1 = require("./BaseParse");
|
|
5
|
+
const OnlyExpressionParse_1 = require("./OnlyExpressionParse");
|
|
6
|
+
class CalcDateParse extends BaseParse_1.BaseParse {
|
|
7
|
+
constructor(valueExpression, funname) {
|
|
8
|
+
super(valueExpression, funname);
|
|
9
|
+
this.value = "";
|
|
10
|
+
this.offset = "";
|
|
11
|
+
var split = this.Expression.split(",");
|
|
12
|
+
if (split.length == 2) {
|
|
13
|
+
this.value = split[0];
|
|
14
|
+
this.offset = split[1];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
Evaluate(obj, critm, record, item) {
|
|
18
|
+
if (this.value == "" || this.offset == "") {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
var valueEval = new OnlyExpressionParse_1.OnlyExpressionParse(this.value);
|
|
22
|
+
var valueE = valueEval.Evaluate(obj, critm, record, item);
|
|
23
|
+
var offsetEval = new OnlyExpressionParse_1.OnlyExpressionParse(this.offset);
|
|
24
|
+
var offsetE = offsetEval.Evaluate(obj, critm, record, item);
|
|
25
|
+
var datetimeValue = null;
|
|
26
|
+
var offsetInt = null;
|
|
27
|
+
if (valueE.constructor.name == "Date") {
|
|
28
|
+
datetimeValue = valueE;
|
|
29
|
+
}
|
|
30
|
+
else if (typeof valueE == "string") {
|
|
31
|
+
datetimeValue = new Date(valueE);
|
|
32
|
+
}
|
|
33
|
+
if (typeof offsetE == "number") {
|
|
34
|
+
offsetInt = offsetE;
|
|
35
|
+
}
|
|
36
|
+
else if (typeof offsetE == "string") {
|
|
37
|
+
offsetInt = parseInt(offsetE);
|
|
38
|
+
}
|
|
39
|
+
if (offsetInt != null && datetimeValue != null) {
|
|
40
|
+
datetimeValue.setDate(datetimeValue.getDate() + offsetInt);
|
|
41
|
+
if (item.TypeDDD == "Date") {
|
|
42
|
+
return BaseParse_1.BaseParse.getIsoDate(datetimeValue);
|
|
43
|
+
}
|
|
44
|
+
else if (item.TypeDDD == "DateTime") {
|
|
45
|
+
return BaseParse_1.BaseParse.getIsoDateTime(datetimeValue);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
debugger;
|
|
50
|
+
}
|
|
51
|
+
return this.Expression;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.CalcDateParse = CalcDateParse;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheckParse = void 0;
|
|
4
|
+
const InvoiceObj_1 = require("../../Structure/InvoiceObj");
|
|
5
|
+
const BaseParse_1 = require("./BaseParse");
|
|
6
|
+
class CheckParse extends BaseParse_1.BaseParse {
|
|
7
|
+
constructor(valueExpression, funname) {
|
|
8
|
+
super(valueExpression, funname);
|
|
9
|
+
this.Detail = "";
|
|
10
|
+
this.Exp = "";
|
|
11
|
+
this.Parameter = "";
|
|
12
|
+
var split = this.Expression.split(",");
|
|
13
|
+
if (split.length == 2) {
|
|
14
|
+
var split = this.Expression.split(",");
|
|
15
|
+
if (split.length != 3) {
|
|
16
|
+
throw "Check have more or less parameters that 3";
|
|
17
|
+
}
|
|
18
|
+
this.Detail = split[0];
|
|
19
|
+
this.Exp = split[1];
|
|
20
|
+
this.Parameter = split[2];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
Evaluate(obj, critm, record, item) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
var list = [];
|
|
26
|
+
if (InvoiceObj_1.InvoiceObj.isMultiple(this.Detail)) {
|
|
27
|
+
/*var tableLevels = obj.(Detail);
|
|
28
|
+
if (tableLevels == null||tableLevels.Count==0)
|
|
29
|
+
{
|
|
30
|
+
throw new Exception($"Can't find level {Detail}");
|
|
31
|
+
}
|
|
32
|
+
foreach(var tab in tableLevels)
|
|
33
|
+
{
|
|
34
|
+
var array = tab.Records as RecordLevelArray;
|
|
35
|
+
foreach(var rec in array.Records)
|
|
36
|
+
{
|
|
37
|
+
list.Add(rec);
|
|
38
|
+
}
|
|
39
|
+
} */
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
var tableLevel = obj.FindTableLevel(this.Detail);
|
|
43
|
+
if (tableLevel == null) {
|
|
44
|
+
throw "Can't find level {Detail}";
|
|
45
|
+
}
|
|
46
|
+
if (tableLevel.Record != null) {
|
|
47
|
+
throw "Table level isn't detail!";
|
|
48
|
+
}
|
|
49
|
+
if (tableLevel.Records == null) {
|
|
50
|
+
throw "Table level doesn't have records!";
|
|
51
|
+
}
|
|
52
|
+
var array = tableLevel.Records.Records;
|
|
53
|
+
for (var i = 0; i < array.length; i++) {
|
|
54
|
+
list.push(array[i]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
var trueCounter = 0;
|
|
58
|
+
for (var i = 0; i < list.length; i++) {
|
|
59
|
+
/*var result = ExpressionLogic.ParseExpressionAndReturnValue("IF("+this.Exp+",true,false)", obj, item, rec, 0);
|
|
60
|
+
if(result=="true")
|
|
61
|
+
{
|
|
62
|
+
trueCounter++;
|
|
63
|
+
if(this.Parameter?.toLocaleLowerCase() =="one")
|
|
64
|
+
{
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}TODO*/
|
|
68
|
+
}
|
|
69
|
+
if (((_a = this.Parameter) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) == "one") {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
else if (((_b = this.Parameter) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase()) == "all") {
|
|
73
|
+
return trueCounter == list.length;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw "Check prameter isn't valid!Valid:One,All.Provided:" + this.Parameter;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.CheckParse = CheckParse;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommaParser = void 0;
|
|
4
|
+
const BaseParse_1 = require("./BaseParse");
|
|
5
|
+
class CommaParser extends BaseParse_1.BaseParse {
|
|
6
|
+
constructor(valueExpression, funname) {
|
|
7
|
+
super(valueExpression, funname);
|
|
8
|
+
}
|
|
9
|
+
Evaluate(obj, critm, record, item) {
|
|
10
|
+
return this.Expression;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.CommaParser = CommaParser;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConcatParse = void 0;
|
|
4
|
+
const BaseParse_1 = require("./BaseParse");
|
|
5
|
+
const CommaParser_1 = require("./CommaParser");
|
|
6
|
+
const ExpresionLogicService_1 = require("../ExpresionLogicService");
|
|
7
|
+
class ConcatParse extends BaseParse_1.BaseParse {
|
|
8
|
+
constructor(valueExpression, funname) {
|
|
9
|
+
var _a;
|
|
10
|
+
super(valueExpression, funname);
|
|
11
|
+
this.sections = [];
|
|
12
|
+
this.sections = (_a = ExpresionLogicService_1.ExpresionLogicService.GetExpressions(this.Expression, this)) !== null && _a !== void 0 ? _a : [];
|
|
13
|
+
}
|
|
14
|
+
Evaluate(obj, critm, record, item) {
|
|
15
|
+
var builder = "";
|
|
16
|
+
for (var i = 0; i < this.sections.length; i++) {
|
|
17
|
+
let section = this.sections[i];
|
|
18
|
+
if (section instanceof CommaParser_1.CommaParser) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
var value = section.Evaluate(obj, critm, record, item);
|
|
22
|
+
if (value != null) {
|
|
23
|
+
builder += value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return builder;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ConcatParse = ConcatParse;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CountParse = void 0;
|
|
4
|
+
const BaseParse_1 = require("./BaseParse");
|
|
5
|
+
class CountParse extends BaseParse_1.BaseParse {
|
|
6
|
+
constructor(valueExpression, funname) {
|
|
7
|
+
super(valueExpression, funname);
|
|
8
|
+
this.Table = ";";
|
|
9
|
+
this.Table = this.Expression;
|
|
10
|
+
}
|
|
11
|
+
Evaluate(obj, critm, record, item) {
|
|
12
|
+
var _a;
|
|
13
|
+
if (this.Table == "") {
|
|
14
|
+
throw "Function count don't have defined table!";
|
|
15
|
+
}
|
|
16
|
+
var tableLevel = obj.FindTableLevel(this.Table);
|
|
17
|
+
if (tableLevel == null) {
|
|
18
|
+
return -1;
|
|
19
|
+
}
|
|
20
|
+
return (_a = tableLevel.Records) === null || _a === void 0 ? void 0 : _a.Records.length;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.CountParse = CountParse;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmptyParse = void 0;
|
|
4
|
+
const BaseParse_1 = require("./BaseParse");
|
|
5
|
+
const OnlyExpressionParse_1 = require("./OnlyExpressionParse");
|
|
6
|
+
const ExpresionLogicService_1 = require("../ExpresionLogicService");
|
|
7
|
+
class EmptyParse extends BaseParse_1.BaseParse {
|
|
8
|
+
constructor(valueExpression, funname) {
|
|
9
|
+
super(valueExpression, funname);
|
|
10
|
+
this.valueExp = null;
|
|
11
|
+
var dd = ExpresionLogicService_1.ExpresionLogicService.GetExpressions(this.Expression, this);
|
|
12
|
+
if (dd == null) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (dd.length == 1 && dd[0] instanceof OnlyExpressionParse_1.OnlyExpressionParse) {
|
|
16
|
+
this.valueExp = dd[0];
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw "Expression '" + this.Expression + "' isn't ValueFromObjParse";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
Evaluate(obj, critm, record, item) {
|
|
23
|
+
var _a;
|
|
24
|
+
var value = (_a = this.valueExp) === null || _a === void 0 ? void 0 : _a.Evaluate(obj, critm, record, item);
|
|
25
|
+
if (value == null) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (typeof value == "string") {
|
|
29
|
+
var v = value;
|
|
30
|
+
return v == "" || v.trim() == "";
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.EmptyParse = EmptyParse;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExistParser = void 0;
|
|
4
|
+
const BaseParse_1 = require("./BaseParse");
|
|
5
|
+
class ExistParser extends BaseParse_1.BaseParse {
|
|
6
|
+
constructor(valueExpression, funname) {
|
|
7
|
+
var _a;
|
|
8
|
+
super(valueExpression, funname);
|
|
9
|
+
this.Table = "";
|
|
10
|
+
this.FieldName = "";
|
|
11
|
+
this.Negate = false;
|
|
12
|
+
if (funname.toLowerCase() == "notexists(") {
|
|
13
|
+
this.Negate = true;
|
|
14
|
+
}
|
|
15
|
+
var split = this.Expression.split(".");
|
|
16
|
+
if (split.length != 2) {
|
|
17
|
+
}
|
|
18
|
+
this.Table = split[0];
|
|
19
|
+
this.FieldName = split[1];
|
|
20
|
+
if ((_a = this.Table) === null || _a === void 0 ? void 0 : _a.startsWith("!")) {
|
|
21
|
+
this.Table = this.Table.substring(1);
|
|
22
|
+
this.Negate = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
Evaluate(obj, critm, record, item) {
|
|
26
|
+
var _a;
|
|
27
|
+
if (this.Table == null) {
|
|
28
|
+
throw "No table";
|
|
29
|
+
}
|
|
30
|
+
var tableLevel = obj.FindTableLevel(this.Table);
|
|
31
|
+
if (tableLevel == null) {
|
|
32
|
+
throw "Table level " + this.Table + " don't exist in object!";
|
|
33
|
+
}
|
|
34
|
+
let exist = false;
|
|
35
|
+
;
|
|
36
|
+
if (tableLevel == obj.rootLevel) {
|
|
37
|
+
var rec = tableLevel.Record;
|
|
38
|
+
exist = (rec === null || rec === void 0 ? void 0 : rec.Record.Record[this.FieldName]) != null;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
var records = tableLevel.Records;
|
|
42
|
+
if (records == null) {
|
|
43
|
+
throw "Table level " + this.Table + " don't have active records!";
|
|
44
|
+
}
|
|
45
|
+
var index = records.Records.indexOf(critm);
|
|
46
|
+
if (index == -1) {
|
|
47
|
+
throw "Table level " + this.Table + " not the same as record!" + ((_a = critm === null || critm === void 0 ? void 0 : critm.Parent) === null || _a === void 0 ? void 0 : _a.Tablename);
|
|
48
|
+
}
|
|
49
|
+
exist = records.Records[index].Record[this.FieldName] != null;
|
|
50
|
+
}
|
|
51
|
+
if (this.Negate) {
|
|
52
|
+
exist = !exist;
|
|
53
|
+
}
|
|
54
|
+
return exist;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.ExistParser = ExistParser;
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IfParse = void 0;
|
|
4
|
+
const BaseParse_1 = require("./BaseParse");
|
|
5
|
+
const CommaParser_1 = require("./CommaParser");
|
|
6
|
+
const LogicalOperatorParse_1 = require("./LogicalOperatorParse");
|
|
7
|
+
const OperatorParse_1 = require("./OperatorParse");
|
|
8
|
+
const ExpresionLogicService_1 = require("../ExpresionLogicService");
|
|
9
|
+
class IfParse extends BaseParse_1.BaseParse {
|
|
10
|
+
constructor(valueExpression, funname) {
|
|
11
|
+
super(valueExpression, funname);
|
|
12
|
+
this.conditionParse = [];
|
|
13
|
+
this.conditionTrueParse = [];
|
|
14
|
+
this.conditionFalseParse = [];
|
|
15
|
+
var dd = ExpresionLogicService_1.ExpresionLogicService.GetExpressions(this.Expression, this);
|
|
16
|
+
if (dd == null) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
var current = [];
|
|
20
|
+
for (let i = 0; i < dd.length; i++) {
|
|
21
|
+
current = this.logic(current, dd[i]);
|
|
22
|
+
}
|
|
23
|
+
this.logic(current, null);
|
|
24
|
+
if (this.conditionParse.length == 0 || this.conditionTrueParse.length == 0 || this.conditionFalseParse.length == 0) {
|
|
25
|
+
throw "Can't parse if stategment " + valueExpression + "!";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
Evaluate(obj, critm, record, item) {
|
|
29
|
+
var candidates = this.conditionParse.filter(x => x instanceof LogicalOperatorParse_1.LogicalOperatorParser);
|
|
30
|
+
var finishResult = false;
|
|
31
|
+
if (candidates.length == 0) {
|
|
32
|
+
finishResult = this.validateExpression(obj, critm, record, item, this.conditionParse);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
let condition = [];
|
|
36
|
+
let result = [];
|
|
37
|
+
for (let i = 0; i < this.conditionParse.length; i++) {
|
|
38
|
+
let c = this.conditionParse[i];
|
|
39
|
+
if (c instanceof LogicalOperatorParse_1.LogicalOperatorParser) {
|
|
40
|
+
var res = this.validateExpression(obj, critm, record, item, result);
|
|
41
|
+
result = [];
|
|
42
|
+
condition.push(res);
|
|
43
|
+
condition.push(c.Expression);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (result.length > 0) {
|
|
48
|
+
var res = this.validateExpression(obj, critm, record, item, result);
|
|
49
|
+
condition.push(res);
|
|
50
|
+
}
|
|
51
|
+
finishResult = condition[0];
|
|
52
|
+
for (var i = 1; i < condition.length; i += 2) {
|
|
53
|
+
var c = condition[i];
|
|
54
|
+
switch (c) {
|
|
55
|
+
case "&&":
|
|
56
|
+
{
|
|
57
|
+
finishResult = finishResult && condition[i + 1];
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case "||":
|
|
61
|
+
{
|
|
62
|
+
finishResult = finishResult || condition[i + 1];
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finish: if (finishResult == true) {
|
|
69
|
+
return ExpresionLogicService_1.ExpresionLogicService.ConcatValues(this.conditionTrueParse, obj, critm, record, item);
|
|
70
|
+
}
|
|
71
|
+
return ExpresionLogicService_1.ExpresionLogicService.ConcatValues(this.conditionFalseParse, obj, critm, record, item);
|
|
72
|
+
}
|
|
73
|
+
logic(list, c) {
|
|
74
|
+
if (c == null || c instanceof CommaParser_1.CommaParser) {
|
|
75
|
+
if (this.conditionParse.length == 0) {
|
|
76
|
+
this.conditionParse = list;
|
|
77
|
+
}
|
|
78
|
+
else if (this.conditionTrueParse.length == 0) {
|
|
79
|
+
this.conditionTrueParse = list;
|
|
80
|
+
}
|
|
81
|
+
else if (this.conditionFalseParse.length == 0) {
|
|
82
|
+
this.conditionFalseParse = list;
|
|
83
|
+
}
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
list.push(c);
|
|
87
|
+
return list;
|
|
88
|
+
}
|
|
89
|
+
validateExpression(obj, critm, record, item, oneCondition) {
|
|
90
|
+
let result = null;
|
|
91
|
+
var candidates = oneCondition.filter(x => x instanceof OperatorParse_1.OperatorParser);
|
|
92
|
+
if (candidates.length == 0) {
|
|
93
|
+
if (oneCondition.length == 1) {
|
|
94
|
+
var evaluated = oneCondition[0].Evaluate(obj, critm, record, item);
|
|
95
|
+
if (typeof evaluated == "boolean") {
|
|
96
|
+
result = evaluated;
|
|
97
|
+
//goto evaluatedCond;
|
|
98
|
+
}
|
|
99
|
+
/*if (evaluated == null&&(obj.currentInvoiceMode==InvoiceObj.InvoiceMode.GetInit|| obj.currentInvoiceMode == InvoiceObj.InvoiceMode.GetInitNFE))
|
|
100
|
+
{
|
|
101
|
+
result = false; goto evaluatedCond;
|
|
102
|
+
}*/
|
|
103
|
+
if (evaluated == null && item.TypeNET == "bool") {
|
|
104
|
+
result = false; //goto evaluatedCond;
|
|
105
|
+
}
|
|
106
|
+
if (typeof evaluated == "string") {
|
|
107
|
+
var temp = evaluated;
|
|
108
|
+
if (temp.trim().toLowerCase() == "false") {
|
|
109
|
+
result = false;
|
|
110
|
+
//goto evaluatedCond;
|
|
111
|
+
}
|
|
112
|
+
if (temp.trim().toLowerCase() == "true") {
|
|
113
|
+
result = true;
|
|
114
|
+
//goto evaluatedCond;
|
|
115
|
+
}
|
|
116
|
+
//goto evaluatedCond;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
let leftSideL = [];
|
|
122
|
+
let rightSideL = [];
|
|
123
|
+
var current = leftSideL;
|
|
124
|
+
for (let i = 0; i < oneCondition.length; i++) {
|
|
125
|
+
if (oneCondition[i] instanceof OperatorParse_1.OperatorParser) {
|
|
126
|
+
current = rightSideL;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
current.push(oneCondition[i]);
|
|
130
|
+
}
|
|
131
|
+
var leftEval = ExpresionLogicService_1.ExpresionLogicService.ConcatValues(leftSideL, obj, critm, record, item);
|
|
132
|
+
var rightEval = ExpresionLogicService_1.ExpresionLogicService.ConcatValues(rightSideL, obj, critm, record, item);
|
|
133
|
+
if (leftEval == null || rightEval == null) {
|
|
134
|
+
switch (candidates[0].Expression) {
|
|
135
|
+
case "=":
|
|
136
|
+
case "==":
|
|
137
|
+
{
|
|
138
|
+
result = leftEval == rightEval;
|
|
139
|
+
return this.evaluateCondition(result);
|
|
140
|
+
}
|
|
141
|
+
case "!=":
|
|
142
|
+
case "<>":
|
|
143
|
+
{
|
|
144
|
+
result = leftEval != rightEval;
|
|
145
|
+
return this.evaluateCondition(result);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (typeof leftEval == "number" && typeof rightEval == "number") {
|
|
150
|
+
var leftSide = leftEval;
|
|
151
|
+
var rightSide = rightEval;
|
|
152
|
+
switch (candidates[0].Expression) {
|
|
153
|
+
case ">=":
|
|
154
|
+
{
|
|
155
|
+
result = leftSide >= rightSide;
|
|
156
|
+
return this.evaluateCondition(result);
|
|
157
|
+
}
|
|
158
|
+
case "<=":
|
|
159
|
+
{
|
|
160
|
+
result = leftSide <= rightSide;
|
|
161
|
+
return this.evaluateCondition(result);
|
|
162
|
+
}
|
|
163
|
+
case "!=":
|
|
164
|
+
case "<>":
|
|
165
|
+
{
|
|
166
|
+
result = leftSide != rightSide;
|
|
167
|
+
return this.evaluateCondition(result);
|
|
168
|
+
}
|
|
169
|
+
case "<":
|
|
170
|
+
{
|
|
171
|
+
result = leftSide < rightSide;
|
|
172
|
+
return this.evaluateCondition(result);
|
|
173
|
+
}
|
|
174
|
+
case ">":
|
|
175
|
+
{
|
|
176
|
+
result = leftSide > rightSide;
|
|
177
|
+
return this.evaluateCondition(result);
|
|
178
|
+
}
|
|
179
|
+
case "==":
|
|
180
|
+
case "=":
|
|
181
|
+
{
|
|
182
|
+
result = leftSide == rightSide;
|
|
183
|
+
return this.evaluateCondition(result);
|
|
184
|
+
}
|
|
185
|
+
default:
|
|
186
|
+
{
|
|
187
|
+
throw "Operator " + candidates[0].Expression + " not supported on condition decimal and decimal";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (typeof leftEval == "string" && typeof rightEval == "string") {
|
|
192
|
+
if ((leftEval.toLowerCase() == "false" || leftEval.toLowerCase() == "true") &&
|
|
193
|
+
(rightEval.toLowerCase() == "false" || rightEval.toLowerCase() == "true")) {
|
|
194
|
+
let lSide = Boolean(leftEval);
|
|
195
|
+
let rside = Boolean(rightEval);
|
|
196
|
+
switch (candidates[0].Expression) {
|
|
197
|
+
case "!=":
|
|
198
|
+
case "<>":
|
|
199
|
+
{
|
|
200
|
+
result = lSide != rside;
|
|
201
|
+
return this.evaluateCondition(result);
|
|
202
|
+
}
|
|
203
|
+
case "==":
|
|
204
|
+
case "=":
|
|
205
|
+
{
|
|
206
|
+
result = lSide == rside;
|
|
207
|
+
return this.evaluateCondition(result);
|
|
208
|
+
}
|
|
209
|
+
default:
|
|
210
|
+
{
|
|
211
|
+
throw "Operator " + candidates[0].Expression + " not supported on condition bool and bool";
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
result = this.StringCompare(leftEval, rightEval, candidates[0].Expression);
|
|
216
|
+
return this.evaluateCondition(result);
|
|
217
|
+
}
|
|
218
|
+
if (leftEval instanceof Date && typeof rightEval == "string") {
|
|
219
|
+
var leftSideD = BaseParse_1.BaseParse.getIsoDateTime(leftEval);
|
|
220
|
+
result = this.StringCompare(leftSideD, rightEval, candidates[0].Expression);
|
|
221
|
+
return this.evaluateCondition(result);
|
|
222
|
+
}
|
|
223
|
+
if (typeof leftEval == "string" && rightEval instanceof Date) {
|
|
224
|
+
var rightSideD = BaseParse_1.BaseParse.getIsoDateTime(rightEval);
|
|
225
|
+
result = this.StringCompare(leftEval, rightSideD, candidates[0].Expression);
|
|
226
|
+
return this.evaluateCondition(result);
|
|
227
|
+
}
|
|
228
|
+
if (leftEval instanceof Date && rightEval instanceof Date) {
|
|
229
|
+
switch (candidates[0].Expression) {
|
|
230
|
+
case ">=":
|
|
231
|
+
{
|
|
232
|
+
result = leftEval >= rightEval;
|
|
233
|
+
return this.evaluateCondition(result);
|
|
234
|
+
}
|
|
235
|
+
case "<=":
|
|
236
|
+
{
|
|
237
|
+
result = leftEval <= rightEval;
|
|
238
|
+
return this.evaluateCondition(result);
|
|
239
|
+
}
|
|
240
|
+
case "!=":
|
|
241
|
+
case "<>":
|
|
242
|
+
{
|
|
243
|
+
result = leftEval != rightEval;
|
|
244
|
+
return this.evaluateCondition(result);
|
|
245
|
+
}
|
|
246
|
+
case "<":
|
|
247
|
+
{
|
|
248
|
+
result = leftEval < rightEval;
|
|
249
|
+
return this.evaluateCondition(result);
|
|
250
|
+
}
|
|
251
|
+
case ">":
|
|
252
|
+
{
|
|
253
|
+
result = leftEval > rightEval;
|
|
254
|
+
return this.evaluateCondition(result);
|
|
255
|
+
}
|
|
256
|
+
case "==":
|
|
257
|
+
case "=":
|
|
258
|
+
{
|
|
259
|
+
result = leftEval == rightEval;
|
|
260
|
+
return this.evaluateCondition(result);
|
|
261
|
+
}
|
|
262
|
+
default:
|
|
263
|
+
{
|
|
264
|
+
throw "Operator " + candidates[0].Expression + " not supported on condition string";
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return this.evaluateCondition(result);
|
|
270
|
+
}
|
|
271
|
+
evaluateCondition(result) {
|
|
272
|
+
if (result == null) {
|
|
273
|
+
throw "Can't eval " + this.Expression + "!";
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
StringCompare(leftSide, rightSide, oper) {
|
|
278
|
+
switch (oper) {
|
|
279
|
+
case "!=":
|
|
280
|
+
case "<>":
|
|
281
|
+
{
|
|
282
|
+
return leftSide != rightSide;
|
|
283
|
+
}
|
|
284
|
+
case "==":
|
|
285
|
+
case "=":
|
|
286
|
+
{
|
|
287
|
+
return leftSide == rightSide;
|
|
288
|
+
}
|
|
289
|
+
default:
|
|
290
|
+
{
|
|
291
|
+
throw "Operator " + oper + " not supported on condition string";
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.IfParse = IfParse;
|