@@ -4,6 +4,8 @@ using System.Integration;
4
4
using Microsoft. Finance. GeneralLedger. Journal;
5
5
using Microsoft. Finance. Dimension;
6
6
using Microsoft. Finance. GeneralLedger. Account;
7
+ using Microsoft. Finance. Analysis. StatisticalAccount;
8
+ using Microsoft. Finance. GeneralLedger. Setup;
7
9
8
10
codeunit 4017 "GP Account Migrator"
9
11
{
@@ -45,7 +47,6 @@ codeunit 4017 "GP Account Migrator"
45
47
local procedure OnMigrateAccountTransactions( var Sender: Codeunit "GL Acc. Data Migration Facade"; RecordIdToMigrate: RecordId )
46
48
var
47
49
GPAccount: Record "GP Account";
48
- GLAccount: Record "G/L Account";
49
50
GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
50
51
begin
51
52
if RecordIdToMigrate. TableNo() <> Database ::"GP Account" then
@@ -59,9 +60,6 @@ codeunit 4017 "GP Account Migrator"
59
60
60
61
GPAccount. Get( RecordIdToMigrate) ;
61
62
62
- if not GLAccount. Get( GPAccount. AcctNum) then
63
- exit ;
64
-
65
63
GenerateGLTransactionBatches( GPAccount) ;
66
64
end ;
67
65
@@ -81,6 +79,9 @@ codeunit 4017 "GP Account Migrator"
81
79
82
80
GPAccount. Get( RecordIdToMigrate) ;
83
81
82
+ if GPAccount. AccountType <> 1 then
83
+ exit ;
84
+
84
85
if not GLAccount. Get( GPAccount. AcctNum) then
85
86
exit ;
86
87
@@ -120,7 +121,6 @@ codeunit 4017 "GP Account Migrator"
120
121
local procedure OnCreateOpeningBalanceTrx( var Sender: Codeunit "GL Acc. Data Migration Facade"; RecordIdToMigrate: RecordId )
121
122
var
122
123
GPAccount: Record "GP Account";
123
- GLAccount: Record "G/L Account";
124
124
GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
125
125
begin
126
126
if RecordIdToMigrate. TableNo() <> Database ::"GP Account" then
@@ -136,14 +136,22 @@ codeunit 4017 "GP Account Migrator"
136
136
if GPAccount. IncomeBalance then
137
137
exit ;
138
138
139
- if not GLAccount. Get( GPAccount. AcctNum) then
140
- exit ;
141
-
142
139
CreateBeginningBalance( GPAccount) ;
143
140
end ;
144
141
145
142
procedure CreateBeginningBalance( GPAccount: Record "GP Account")
143
+ begin
144
+ case GPAccount. AccountType of
145
+ 1 :
146
+ CreateGLAccountBeginningBalanceImp( GPAccount) ;
147
+ 2 :
148
+ CreateStatisticalAccountBeginningBalanceImp( GPAccount) ;
149
+ end ;
150
+ end ;
151
+
152
+ local procedure CreateGLAccountBeginningBalanceImp( GPAccount: Record "GP Account")
146
153
var
154
+ GLAccount: Record "G/L Account";
147
155
GPGL10111: Record "GP GL10111";
148
156
GenJournalLine: Record "Gen. Journal Line";
149
157
GPFiscalPeriods: Record "GP Fiscal Periods";
@@ -162,6 +170,9 @@ codeunit 4017 "GP Account Migrator"
162
170
ACTNUMBR_8: Code [20 ];
163
171
DimSetID: Integer ;
164
172
begin
173
+ if not GLAccount. Get( GPAccount. AcctNum) then
174
+ exit ;
175
+
165
176
InitialYear := GPCompanyAdditionalSettings. GetInitialYear() ;
166
177
if InitialYear = 0 then
167
178
exit ;
@@ -176,7 +187,7 @@ codeunit 4017 "GP Account Migrator"
176
187
if BeginningBalance = 0 then
177
188
exit ;
178
189
179
- PostingGroupCode := PostingGroupCodeTxt + format ( InitialYear) + ' BB' ;
190
+ PostingGroupCode := PostingGroupCodeTxt + Format ( InitialYear) + ' BB' ;
180
191
if GPFiscalPeriods. Get( 0 , InitialYear) then begin
181
192
DataMigrationFacadeHelper. CreateGeneralJournalBatchIfNeeded( CopyStr( PostingGroupCode, 1 , 10 ) , ' ' , ' ' ) ;
182
193
DataMigrationFacadeHelper. CreateGeneralJournalLine(
@@ -212,7 +223,100 @@ codeunit 4017 "GP Account Migrator"
212
223
end ;
213
224
end ;
214
225
226
+ local procedure CreateStatisticalAccountBeginningBalanceImp( GPAccount: Record "GP Account")
227
+ var
228
+ GPGL00100: Record "GP GL00100";
229
+ GPGL10111: Record "GP GL10111";
230
+ GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
231
+ GPFiscalPeriods: Record "GP Fiscal Periods";
232
+ StatisticalAccJournalBatch: Record "Statistical Acc. Journal Batch";
233
+ StatisticalAccJournalLine: Record "Statistical Acc. Journal Line";
234
+ StatisticalAccJournalLineCurrent: Record "Statistical Acc. Journal Line";
235
+ InitialYear: Integer ;
236
+ BeginningBalance: Decimal ;
237
+ DocumentNo: Code [20 ];
238
+ LineNum: Integer ;
239
+ ACTNUMBR_1: Code [20 ];
240
+ ACTNUMBR_2: Code [20 ];
241
+ ACTNUMBR_3: Code [20 ];
242
+ ACTNUMBR_4: Code [20 ];
243
+ ACTNUMBR_5: Code [20 ];
244
+ ACTNUMBR_6: Code [20 ];
245
+ ACTNUMBR_7: Code [20 ];
246
+ ACTNUMBR_8: Code [20 ];
247
+ DimSetID: Integer ;
248
+ begin
249
+ InitialYear := GPCompanyAdditionalSettings. GetInitialYear() ;
250
+ if InitialYear = 0 then
251
+ exit ;
252
+
253
+ if not GPGL00100. Get( GPAccount. AcctIndex) then
254
+ exit ;
255
+
256
+ if GPGL00100. Clear_Balance then
257
+ exit ;
258
+
259
+ GPGL10111. SetRange( ACTINDX, GPAccount. AcctIndex) ;
260
+ GPGL10111. SetRange( PERIODID, 0 ) ;
261
+ GPGL10111. SetRange( YEAR1, InitialYear) ;
262
+ if not GPGL10111. FindFirst() then
263
+ exit ;
264
+
265
+ BeginningBalance := GPGL10111. PERDBLNC;
266
+ if BeginningBalance = 0 then
267
+ exit ;
268
+
269
+ DocumentNo := PostingGroupCodeTxt + Format( InitialYear) + ' BB' ;
270
+ if GPFiscalPeriods. Get( 0 , InitialYear) then begin
271
+ if not StatisticalAccJournalBatch. Get( ' ' , DocumentNo) then begin
272
+ StatisticalAccJournalBatch. Validate( Name, DocumentNo) ;
273
+ StatisticalAccJournalBatch. Insert( true) ;
274
+ end ;
275
+
276
+ StatisticalAccJournalLineCurrent. SetRange( "Journal Batch Name", StatisticalAccJournalBatch. Name) ;
277
+ if StatisticalAccJournalLineCurrent. FindLast() then
278
+ LineNum := StatisticalAccJournalLineCurrent. "Line No." + 10000
279
+ else
280
+ LineNum := 10000 ;
281
+
282
+ StatisticalAccJournalLine. Validate( "Journal Batch Name", DocumentNo) ;
283
+ StatisticalAccJournalLine. Validate( "Line No.", LineNum) ;
284
+ StatisticalAccJournalLine. Validate( "Document No.", DocumentNo) ;
285
+ StatisticalAccJournalLine. Validate( Description, CopyStr( BeginningBalanceTrxTxt, 1 , MaxStrLen( StatisticalAccJournalLine. Description))) ;
286
+ StatisticalAccJournalLine. Validate( "Statistical Account No.", CopyStr( GPAccount. AcctNum, 1 , MaxStrLen( StatisticalAccJournalLine. "Statistical Account No."))) ;
287
+ StatisticalAccJournalLine. Validate( "Posting Date", GPFiscalPeriods. PERIODDT) ;
288
+ StatisticalAccJournalLine. Validate( Amount, BeginningBalance) ;
289
+ StatisticalAccJournalLine. Insert() ;
290
+
291
+ ACTNUMBR_1 := GPGL10111. ACTNUMBR_1;
292
+ ACTNUMBR_2 := GPGL10111. ACTNUMBR_2;
293
+ ACTNUMBR_3 := GPGL10111. ACTNUMBR_3;
294
+ ACTNUMBR_4 := GPGL10111. ACTNUMBR_4;
295
+ ACTNUMBR_5 := GPGL10111. ACTNUMBR_5;
296
+ ACTNUMBR_6 := GPGL10111. ACTNUMBR_6;
297
+ ACTNUMBR_7 := GPGL10111. ACTNUMBR_7;
298
+ ACTNUMBR_8 := GPGL10111. ACTNUMBR_8;
299
+
300
+ if AreAllSegmentNumbersEmpty( ACTNUMBR_1, ACTNUMBR_2, ACTNUMBR_3, ACTNUMBR_4, ACTNUMBR_5, ACTNUMBR_6, ACTNUMBR_7, ACTNUMBR_8) then
301
+ GetSegmentNumbersFromGPAccountIndex( GPGL10111. ACTINDX, ACTNUMBR_1, ACTNUMBR_2, ACTNUMBR_3, ACTNUMBR_4, ACTNUMBR_5, ACTNUMBR_6, ACTNUMBR_7, ACTNUMBR_8) ;
302
+
303
+ DimSetID := CreateDimSet( ACTNUMBR_1, ACTNUMBR_2, ACTNUMBR_3, ACTNUMBR_4, ACTNUMBR_5, ACTNUMBR_6, ACTNUMBR_7, ACTNUMBR_8) ;
304
+ StatisticalAccJournalLine. Validate( "Dimension Set ID", DimSetID) ;
305
+ StatisticalAccJournalLine. Modify ( true) ;
306
+ end ;
307
+ end ;
308
+
215
309
procedure MigrateAccountDetails( GPAccount: Record "GP Account"; var GLAccDataMigrationFacade: Codeunit "GL Acc. Data Migration Facade")
310
+ begin
311
+ case GPAccount. AccountType of
312
+ 1 :
313
+ MigrateGLAccountDetailsImp( GPAccount, GLAccDataMigrationFacade) ;
314
+ 2 :
315
+ MigrateStatisticalAccountDetailsImp( GPAccount) ;
316
+ end ;
317
+ end ;
318
+
319
+ local procedure MigrateGLAccountDetailsImp( GPAccount: Record "GP Account"; var GLAccDataMigrationFacade: Codeunit "GL Acc. Data Migration Facade")
216
320
var
217
321
HelperFunctions: Codeunit "Helper Functions";
218
322
DataMigrationErrorLogging: Codeunit "Data Migration Error Logging";
@@ -232,36 +336,74 @@ codeunit 4017 "GP Account Migrator"
232
336
GLAccDataMigrationFacade. ModifyGLAccount( true) ;
233
337
end ;
234
338
235
- procedure GenerateGLTransactionBatches( GPAccount: Record "GP Account") ;
339
+ local procedure MigrateStatisticalAccountDetailsImp( GPAccount: Record "GP Account")
340
+ var
341
+ StatisticalAccount: Record "Statistical Account";
342
+ GeneralLedgerSetup: Record "General Ledger Setup";
343
+ DataMigrationErrorLogging: Codeunit "Data Migration Error Logging";
344
+ AccountNum: Code [20 ];
345
+ begin
346
+ AccountNum := CopyStr( GPAccount. AcctNum. Trim() , 1 , MaxStrLen( StatisticalAccount. "No.")) ;
347
+
348
+ if StatisticalAccount. Get( AccountNum) then
349
+ exit ;
350
+
351
+ DataMigrationErrorLogging. SetLastRecordUnderProcessing( Format( GPAccount. RecordId )) ;
352
+
353
+ StatisticalAccount. "No." := AccountNum;
354
+ StatisticalAccount. Name := CopyStr( GPAccount. Name, 1 , MaxStrLen( StatisticalAccount. Name)) ;
355
+
356
+ if GeneralLedgerSetup. Get() then begin
357
+ StatisticalAccount. "Global Dimension 1 Code" := GeneralLedgerSetup. "Global Dimension 1 Code";
358
+ StatisticalAccount. "Global Dimension 2 Code" := GeneralLedgerSetup. "Global Dimension 2 Code";
359
+ end ;
360
+
361
+ StatisticalAccount. Insert( true) ;
362
+ end ;
363
+
364
+ procedure GenerateGLTransactionBatches( GPAccount: Record "GP Account")
365
+ begin
366
+ case GPAccount. AccountType of
367
+ 1 :
368
+ GenerateGLAccountTransactionsImp( GPAccount) ;
369
+ 2 :
370
+ GenerateStatisticalAccountTransactionsImp( GPAccount) ;
371
+ end ;
372
+ end ;
373
+
374
+ local procedure GenerateGLAccountTransactionsImp( GPAccount: Record "GP Account")
236
375
var
237
376
GPGLTransactions: Record "GP GLTransactions";
238
377
GenJournalLine: Record "Gen. Journal Line";
239
378
GPFiscalPeriods: Record "GP Fiscal Periods";
379
+ GLAccount: Record "G/L Account";
240
380
GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
241
381
DataMigrationFacadeHelper: Codeunit "Data Migration Facade Helper";
242
- PostingGroupCode : Code [10 ];
382
+ DocumentNo : Code [10 ];
243
383
DimSetID: Integer ;
244
384
InitialYear: Integer ;
245
385
begin
386
+ if not GLAccount. Get( GPAccount. AcctNum) then
387
+ exit ;
388
+
246
389
InitialYear := GPCompanyAdditionalSettings. GetInitialYear() ;
247
390
248
- GPGLTransactions. Reset() ;
249
391
GPGLTransactions. SetCurrentKey( YEAR1, PERIODID, ACTINDX) ;
250
- GPGLTransactions. SetFilter ( ACTINDX, ' = %1 ' , GPAccount. AcctIndex) ;
392
+ GPGLTransactions. SetRange ( ACTINDX, GPAccount. AcctIndex) ;
251
393
252
394
if InitialYear > 0 then
253
395
GPGLTransactions. SetFilter( YEAR1, ' >= %1' , InitialYear) ;
254
396
255
397
if GPGLTransactions. FindSet() then
256
398
repeat
257
- PostingGroupCode := PostingGroupCodeTxt + format ( GPGLTransactions. YEAR1) + ' -' + format ( GPGLTransactions. PERIODID) ;
399
+ DocumentNo := PostingGroupCodeTxt + Format ( GPGLTransactions. YEAR1) + ' -' + Format ( GPGLTransactions. PERIODID) ;
258
400
259
401
if GPFiscalPeriods. Get( GPGLTransactions. PERIODID, GPGLTransactions. YEAR1) then begin
260
- DataMigrationFacadeHelper. CreateGeneralJournalBatchIfNeeded( CopyStr( PostingGroupCode , 1 , 10 ) , ' ' , ' ' ) ;
402
+ DataMigrationFacadeHelper. CreateGeneralJournalBatchIfNeeded( CopyStr( DocumentNo , 1 , 10 ) , ' ' , ' ' ) ;
261
403
DataMigrationFacadeHelper. CreateGeneralJournalLine(
262
404
GenJournalLine,
263
- PostingGroupCode ,
264
- PostingGroupCode ,
405
+ DocumentNo ,
406
+ DocumentNo ,
265
407
CopyStr( DescriptionTrxTxt, 1 , 50 ) ,
266
408
GenJournalLine. "Account Type"::"G/L Account",
267
409
CopyStr( GPAccount. AcctNum, 1 , 20 ) ,
@@ -279,6 +421,62 @@ codeunit 4017 "GP Account Migrator"
279
421
until GPGLTransactions. Next() = 0 ;
280
422
end ;
281
423
424
+ local procedure GenerateStatisticalAccountTransactionsImp( GPAccount: Record "GP Account")
425
+ var
426
+ GPGLTransactions: Record "GP GLTransactions";
427
+ GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
428
+ GPFiscalPeriods: Record "GP Fiscal Periods";
429
+ StatisticalAccount: Record "Statistical Account";
430
+ StatisticalAccJournalBatch: Record "Statistical Acc. Journal Batch";
431
+ StatisticalAccJournalLine: Record "Statistical Acc. Journal Line";
432
+ StatisticalAccJournalLineCurrent: Record "Statistical Acc. Journal Line";
433
+ InitialYear: Integer ;
434
+ DocumentNo: Code [10 ];
435
+ LineNum: Integer ;
436
+ DimSetID: Integer ;
437
+ begin
438
+ if not StatisticalAccount. Get( GPAccount. AcctNum) then
439
+ exit ;
440
+
441
+ InitialYear := GPCompanyAdditionalSettings. GetInitialYear() ;
442
+
443
+ GPGLTransactions. SetCurrentKey( YEAR1, PERIODID, ACTINDX) ;
444
+ GPGLTransactions. SetRange( ACTINDX, GPAccount. AcctIndex) ;
445
+
446
+ if InitialYear > 0 then
447
+ GPGLTransactions. SetFilter( YEAR1, ' >= %1' , InitialYear) ;
448
+
449
+ if GPGLTransactions. FindSet() then
450
+ repeat
451
+ DocumentNo := PostingGroupCodeTxt + Format( GPGLTransactions. YEAR1) + ' -' + Format( GPGLTransactions. PERIODID) ;
452
+ if GPFiscalPeriods. Get( GPGLTransactions. PERIODID, GPGLTransactions. YEAR1) then begin
453
+ if not StatisticalAccJournalBatch. Get( ' ' , DocumentNo) then begin
454
+ StatisticalAccJournalBatch. Validate( Name, DocumentNo) ;
455
+ StatisticalAccJournalBatch. Insert( true) ;
456
+ end ;
457
+
458
+ StatisticalAccJournalLineCurrent. SetRange( "Journal Batch Name", StatisticalAccJournalBatch. Name) ;
459
+ if StatisticalAccJournalLineCurrent. FindLast() then
460
+ LineNum := StatisticalAccJournalLineCurrent. "Line No." + 10000
461
+ else
462
+ LineNum := 10000 ;
463
+
464
+ StatisticalAccJournalLine. Validate( "Journal Batch Name", DocumentNo) ;
465
+ StatisticalAccJournalLine. Validate( "Line No.", LineNum) ;
466
+ StatisticalAccJournalLine. Validate( "Document No.", DocumentNo) ;
467
+ StatisticalAccJournalLine. Validate( Description, CopyStr( DescriptionTrxTxt, 1 , MaxStrLen( StatisticalAccJournalLine. Description))) ;
468
+ StatisticalAccJournalLine. Validate( "Statistical Account No.", CopyStr( GPAccount. AcctNum, 1 , MaxStrLen( StatisticalAccJournalLine. "Statistical Account No."))) ;
469
+ StatisticalAccJournalLine. Validate( "Posting Date", GPFiscalPeriods. PERIODDT) ;
470
+ StatisticalAccJournalLine. Validate( Amount, GPGLTransactions. PERDBLNC) ;
471
+ StatisticalAccJournalLine. Insert() ;
472
+
473
+ DimSetID := CreateDimSet( GPGLTransactions. ACTNUMBR_1, GPGLTransactions. ACTNUMBR_2, GPGLTransactions. ACTNUMBR_3, GPGLTransactions. ACTNUMBR_4, GPGLTransactions. ACTNUMBR_5, GPGLTransactions. ACTNUMBR_6, GPGLTransactions. ACTNUMBR_7, GPGLTransactions. ACTNUMBR_8) ;
474
+ StatisticalAccJournalLine. Validate( "Dimension Set ID", DimSetID) ;
475
+ StatisticalAccJournalLine. Modify ( true) ;
476
+ end ;
477
+ until GPGLTransactions. Next() = 0 ;
478
+ end ;
479
+
282
480
local procedure CreateDimSet( ACTNUMBR_1: Code [20 ]; ACTNUMBR_2: Code [20 ]; ACTNUMBR_3: Code [20 ]; ACTNUMBR_4: Code [20 ]; ACTNUMBR_5: Code [20 ]; ACTNUMBR_6: Code [20 ]; ACTNUMBR_7: Code [20 ]; ACTNUMBR_8: Code [20 ]) : Integer
283
481
var
284
482
TempDimensionSetEntry: Record "Dimension Set Entry" temporary ;
0 commit comments