-
Notifications
You must be signed in to change notification settings - Fork 0
/
PowerDimensionCzar.cs
148 lines (125 loc) · 4.72 KB
/
PowerDimensionCzar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/// <summary>
/// Created and maintained By Jalal Derakhshani
/// 2021
/// </summary>
class PowerDimensionCzar
{
}
private str GenerateExcludingString(Set _values = null)
{
str result;
container baseCon;
baseCon = conDel(_values.pack(), 1, 3);
result = strReplace(con2Str(baseCon), ",", ",!");
result = "!" + result;
return result;
}
public static Set GetAllDimensionAttributeTitles(Set _exclude = new Set(Types::String))
{
DimensionAttribute dimensionAttribute;
Set result = new Set(Types::String) ;
;
while
select Name from dimensionAttribute group by dimensionAttribute.Name where !(dimensionAttribute.Name like "SystemGeneratedAttribute*")
{
if(!_exclude.in(dimensionAttribute.Name))
result.add(dimensionAttribute.Name);
}
return result;
}
public static DimensionDefault GetDefaultDimensionFromAttrs(container _dimAttrs, boolean _excludeOtherAttrs = true)
{
int currPair;
Query q;
QueryRun qr;
QueryBuildDataSource qbds, qbdsExclude;
DefaultDimensionView result;
PowerDimensionCzar dimCzar = new PowerDimensionCzar();
Set attrs = new Set(Types::String);
int attrPairsCount = conLen(_dimAttrs) / 2;
int attrIdx;
;
q = new Query();
for(currPair = 1; currPair <= attrPairsCount; currPair++)
{
switch(currPair)
{
case 1:
qbds = q.addDataSource(tableNum(DefaultDimensionView));
attrIdx = 1;
break;
default:
qbds = qbds.addDataSource(tableNum(DefaultDimensionView));
qbds.joinMode(JoinMode::InnerJoin);
qbds.relations(false);
qbds.addLink(fieldNum(DefaultDimensionView, DefaultDimension), fieldNum(DefaultDimensionView, DefaultDimension));
}
qbds.addRange(fieldNum(DefaultDimensionView, Name)).value(conPeek(_dimAttrs, attrIdx));
qbds.addRange(fieldNum(DefaultDimensionView, DisplayValue)).value(conPeek(_dimAttrs, attrIdx + 1));
attrs.add(conPeek(_dimAttrs, attrIdx));
attrIdx += 2;
}
qbdsExclude = qbds.addDataSource(tableNum(DefaultDimensionView));
qbdsExclude.joinMode(JoinMode::NoExistsJoin);
qbdsExclude.relations(false);
qbdsExclude.addLink(fieldNum(DefaultDimensionView, DefaultDimension), fieldNum(DefaultDimensionView, DefaultDimension));
qbdsExclude.addRange(fieldNum(DefaultDimensionView, Name)).value(dimCzar.GenerateExcludingString(attrs));
qr = new QueryRun(q);
while(qr.next())
{
result = qr.get(tableNum(DefaultDimensionView));
if(result.DefaultDimension)
return result.DefaultDimension;
}
return 0;
}
public static DimensionDefault findDefaultDimension(container _dimAttrs, boolean _excludeOtherAttrs = true)
{
return PowerDimensionCzar::GetDefaultDimensionFromAttrs(_dimAttrs, _excludeOtherAttrs);
}
public static DimensionDefault findOrCreateDefaultDimension(container _dimAttrs, boolean _excludeOtherAttrs = true)
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
DimensionAttributeValue dimensionAttributeValue;
DimensionDefault existsAlready = PowerDimensionCzar::findDefaultDimension(_dimAttrs);
int currPair;
Set attrs = new Set(Types::String);
int attrPairsCount = conLen(_dimAttrs) / 2;
int attrIdx;
;
if (existsAlready)
{
return existsAlready;
}
for (currPair = 1; currPair <= attrPairsCount; currPair++)
{
if (currPair == 1)
{
attrIdx = 1;
}
dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(conPeek(_dimAttrs, attrIdx), conPeek(_dimAttrs, attrIdx+1), false, true);
valueSetStorage.addItem(dimensionAttributeValue);
attrs.add(conPeek(_dimAttrs, attrIdx));
attrIdx += 2;
}
result = valueSetStorage.save();
return result;
}
public static DimensionDefault GetLedgerDimensionFromOffsetAcc(int _offsetAccount)
{
container dimensions;
RecId dimRes;
;
try
{
dimensions = [_offsetAccount, _offsetAccount, 0];
dimRes = AxdDimensionUtil::getLedgerAccountId(dimensions);
}
catch
{
Global::exceptionTextFallThrough();
}
return dimRes;
}