PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Gedemin/Transaction/gdv_AvailAnalytics_unit.pas

http://gedemin.googlecode.com/
Pascal | 195 lines | 164 code | 28 blank | 3 comment | 10 complexity | 9fa7c75149cceacc2f12f6d6fac16ed0 MD5 | raw file
  1unit gdv_AvailAnalytics_unit;
  2
  3interface
  4
  5uses
  6  contnrs, at_classes, classes, AcctUtils, AcctStrings;
  7  
  8type
  9  TgdvAnalytics = class
 10  private
 11    FFieldName: string;
 12    FCaption: string;
 13    FField: TatRelationField;
 14    FListField: TatRelationField;
 15    FAdditional: string;
 16    FTotal: boolean;
 17    procedure SetCaption(const Value: string);
 18    procedure SetField(const Value: TatRelationField);
 19    procedure SetFieldName(const Value: string);
 20    procedure SetAdditional(const Value: string);
 21    procedure SetTotal(const Value: boolean);
 22    procedure SetListField(const Value: TatRelationField);
 23  public
 24    procedure SetListFieldByFieldName(const Value: string); overload;
 25
 26    property FieldName: string read FFieldName write SetFieldName;
 27    property Caption: string read FCaption write SetCaption;
 28    property Field: TatRelationField read FField write SetField;
 29    property ListField: TatRelationField read FListField write SetListField;
 30    property Additional: string read FAdditional write SetAdditional;
 31    property Total: boolean read FTotal write SetTotal;
 32  end;
 33
 34  TgdvAvailAnalytics = class(TObjectList)
 35  private
 36    function GetAnalytics(Index: Integer): TgdvAnalytics;
 37  public
 38    procedure Refresh; virtual;
 39    procedure AddAnalytics(FieldName, Caption: string; Field: TatRelationField;
 40      Additional: string);
 41    function IndexOfByFieldName(FieldName: string): Integer;
 42
 43    property Analytics[Index: Integer]: TgdvAnalytics read GetAnalytics; default;
 44  end;
 45
 46  TgdvAnalyticsList = class(TList)
 47  private
 48    function GetAnalytics(Index: Integer): TgdvAnalytics;
 49  public
 50    property Analytics[Index: Integer]: TgdvAnalytics read GetAnalytics; default;
 51  end;
 52
 53implementation
 54
 55{ TgdvAvailAnalytics }
 56
 57procedure TgdvAvailAnalytics.AddAnalytics(FieldName, Caption: string;
 58  Field: TatRelationField; Additional: string);
 59var
 60  A: TgdvAnalytics;
 61begin
 62  A := TgdvAnalytics.Create;
 63  A.Field := Field;
 64  A.FieldName := FieldName;
 65  A.Caption := Caption;
 66  A.Additional := Additional;
 67  Add(A);
 68end;
 69
 70function TgdvAvailAnalytics.GetAnalytics(Index: Integer): TgdvAnalytics;
 71begin
 72  Result := TgdvAnalytics(Items[Index]);
 73end;
 74
 75function TgdvAvailAnalytics.IndexOfByFieldName(FieldName: string): Integer;
 76var
 77  I: Integer;
 78begin
 79  Result := -1;
 80  for I := 0 to Count - 1 do
 81  begin
 82    if Analytics[I].FieldName = FieldName then
 83    begin
 84      Result := I;
 85      Exit;
 86    end;
 87  end;
 88end;
 89
 90procedure TgdvAvailAnalytics.Refresh;
 91var
 92  L: TList;
 93  A: TgdvAnalytics;
 94  I: Integer;
 95  F: TatRelationField;
 96begin
 97  Clear;
 98  L := TList.Create;
 99  try
100    GetAnalyticsFields(L);
101    for I := 0 to L.Count -1 do
102    begin
103      A := TgdvAnalytics.Create;
104      A.Field := TatRelationField(L[I]);
105      Add(A);
106    end;
107  finally
108    L.Free;
109  end;
110
111  F := atDatabase.FindRelationField(AC_ENTRY, ENTRYDATE);
112  if F <> nil then
113  begin
114    A := TgdvAnalytics.Create;
115    A.Field := F;
116    if A.Field.LName = ENTRYDATE then
117      A.Caption := '????';
118    Add(A);
119  end;
120
121  AddAnalytics(MONTH, '?????', nil, '1');
122  AddAnalytics('QUARTER', '???????', nil, '4');
123  AddAnalytics('YEAR', '???', nil, '3');
124  F := atDatabase.FindRelationField(AC_ENTRY, 'ACCOUNTKEY');
125  if F <> nil then
126  begin
127    AddAnalytics('ACCOUNTKEY', '????? ? ????????', F, '')
128  end;
129  
130  F := atDatabase.FindRelationField(AC_ENTRY, 'CURRKEY');
131  if F <> nil then
132  begin
133    AddAnalytics('CURRKEY', '??????', F, '')
134  end;
135
136  F := atDatabase.FindRelationField(AC_ENTRY, 'COMPANYKEY');
137  if F <> nil then
138  begin
139    AddAnalytics('COMPANYKEY', '??????? ????????', F, '');
140  end;
141end;
142
143{ TgdvAnalytics }
144
145procedure TgdvAnalytics.SetAdditional(const Value: string);
146begin
147  FAdditional := Value;
148end;
149
150procedure TgdvAnalytics.SetCaption(const Value: string);
151begin
152  FCaption := Value;
153end;
154
155procedure TgdvAnalytics.SetField(const Value: TatRelationField);
156begin
157  FField := Value;
158  if Value <> nil then
159  begin
160    FFieldName := Value.FieldName;
161    FCaption := Value.LName;
162  end;
163end;
164
165procedure TgdvAnalytics.SetFieldName(const Value: string);
166begin
167  FFieldName := Value;
168end;
169
170procedure TgdvAnalytics.SetListFieldByFieldName(const Value: string);
171begin
172  if Assigned(FField) and (Value <> '') then
173    ListField := FField.References.RelationFields.ByFieldName(Value)
174  else
175    ListField := nil;
176end;
177
178procedure TgdvAnalytics.SetListField(const Value: TatRelationField);
179begin
180  FListField := Value;
181end;
182
183procedure TgdvAnalytics.SetTotal(const Value: boolean);
184begin
185  FTotal := Value;
186end;
187
188{ TgdvAnalyticsList }
189
190function TgdvAnalyticsList.GetAnalytics(Index: Integer): TgdvAnalytics;
191begin
192  Result := TgdvAnalytics(Items[Index]);
193end;
194
195end.