Skip to content

Commit 711c59c

Browse files
GP Unit accounts migrated as BC Statistical accounts (#26498)
This PR enhances the GP migration by migrating Unit accounts as BC Statistical accounts. - Updated the Account migrator to include Unit accounts, and handle them separately from the G/L Account related code. - Statistical Account posting logic. - Added count of unposted Statistical account batches to the Failed Batches tile. - Added unit tests. Fixes #26487 Fixes [AB#537203](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/537203) --------- Co-authored-by: jaymckinney <[email protected]>
1 parent 57a627f commit 711c59c

9 files changed

+531
-197
lines changed

Apps/W1/HybridGP/app/app.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@
2828
"id": "c526b3e9-b8ca-4683-81ba-fcd5f6b1472a",
2929
"name": "Sales and Inventory Forecast",
3030
"publisher": "Microsoft",
31-
"version": "25.0.0.0"
32-
}
31+
"version": "25.0.0.0"
32+
},
33+
{
34+
"id": "ea130081-c669-460f-a5f4-5dde14f03131",
35+
"name": "Statistical Accounts",
36+
"publisher": "Microsoft",
37+
"version": "25.0.0.0"
38+
}
3339
],
3440
"screenshots": [
3541

Apps/W1/HybridGP/app/src/Migration/Accounts/GPAccountMigrator.codeunit.al

+215-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ using System.Integration;
44
using Microsoft.Finance.GeneralLedger.Journal;
55
using Microsoft.Finance.Dimension;
66
using Microsoft.Finance.GeneralLedger.Account;
7+
using Microsoft.Finance.Analysis.StatisticalAccount;
8+
using Microsoft.Finance.GeneralLedger.Setup;
79

810
codeunit 4017 "GP Account Migrator"
911
{
@@ -45,7 +47,6 @@ codeunit 4017 "GP Account Migrator"
4547
local procedure OnMigrateAccountTransactions(var Sender: Codeunit "GL Acc. Data Migration Facade"; RecordIdToMigrate: RecordId)
4648
var
4749
GPAccount: Record "GP Account";
48-
GLAccount: Record "G/L Account";
4950
GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
5051
begin
5152
if RecordIdToMigrate.TableNo() <> Database::"GP Account" then
@@ -59,9 +60,6 @@ codeunit 4017 "GP Account Migrator"
5960

6061
GPAccount.Get(RecordIdToMigrate);
6162

62-
if not GLAccount.Get(GPAccount.AcctNum) then
63-
exit;
64-
6563
GenerateGLTransactionBatches(GPAccount);
6664
end;
6765

@@ -81,6 +79,9 @@ codeunit 4017 "GP Account Migrator"
8179

8280
GPAccount.Get(RecordIdToMigrate);
8381

82+
if GPAccount.AccountType <> 1 then
83+
exit;
84+
8485
if not GLAccount.Get(GPAccount.AcctNum) then
8586
exit;
8687

@@ -120,7 +121,6 @@ codeunit 4017 "GP Account Migrator"
120121
local procedure OnCreateOpeningBalanceTrx(var Sender: Codeunit "GL Acc. Data Migration Facade"; RecordIdToMigrate: RecordId)
121122
var
122123
GPAccount: Record "GP Account";
123-
GLAccount: Record "G/L Account";
124124
GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
125125
begin
126126
if RecordIdToMigrate.TableNo() <> Database::"GP Account" then
@@ -136,14 +136,22 @@ codeunit 4017 "GP Account Migrator"
136136
if GPAccount.IncomeBalance then
137137
exit;
138138

139-
if not GLAccount.Get(GPAccount.AcctNum) then
140-
exit;
141-
142139
CreateBeginningBalance(GPAccount);
143140
end;
144141

145142
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")
146153
var
154+
GLAccount: Record "G/L Account";
147155
GPGL10111: Record "GP GL10111";
148156
GenJournalLine: Record "Gen. Journal Line";
149157
GPFiscalPeriods: Record "GP Fiscal Periods";
@@ -162,6 +170,9 @@ codeunit 4017 "GP Account Migrator"
162170
ACTNUMBR_8: Code[20];
163171
DimSetID: Integer;
164172
begin
173+
if not GLAccount.Get(GPAccount.AcctNum) then
174+
exit;
175+
165176
InitialYear := GPCompanyAdditionalSettings.GetInitialYear();
166177
if InitialYear = 0 then
167178
exit;
@@ -176,7 +187,7 @@ codeunit 4017 "GP Account Migrator"
176187
if BeginningBalance = 0 then
177188
exit;
178189

179-
PostingGroupCode := PostingGroupCodeTxt + format(InitialYear) + 'BB';
190+
PostingGroupCode := PostingGroupCodeTxt + Format(InitialYear) + 'BB';
180191
if GPFiscalPeriods.Get(0, InitialYear) then begin
181192
DataMigrationFacadeHelper.CreateGeneralJournalBatchIfNeeded(CopyStr(PostingGroupCode, 1, 10), '', '');
182193
DataMigrationFacadeHelper.CreateGeneralJournalLine(
@@ -212,7 +223,100 @@ codeunit 4017 "GP Account Migrator"
212223
end;
213224
end;
214225

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+
215309
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")
216320
var
217321
HelperFunctions: Codeunit "Helper Functions";
218322
DataMigrationErrorLogging: Codeunit "Data Migration Error Logging";
@@ -232,36 +336,74 @@ codeunit 4017 "GP Account Migrator"
232336
GLAccDataMigrationFacade.ModifyGLAccount(true);
233337
end;
234338

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")
236375
var
237376
GPGLTransactions: Record "GP GLTransactions";
238377
GenJournalLine: Record "Gen. Journal Line";
239378
GPFiscalPeriods: Record "GP Fiscal Periods";
379+
GLAccount: Record "G/L Account";
240380
GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
241381
DataMigrationFacadeHelper: Codeunit "Data Migration Facade Helper";
242-
PostingGroupCode: Code[10];
382+
DocumentNo: Code[10];
243383
DimSetID: Integer;
244384
InitialYear: Integer;
245385
begin
386+
if not GLAccount.Get(GPAccount.AcctNum) then
387+
exit;
388+
246389
InitialYear := GPCompanyAdditionalSettings.GetInitialYear();
247390

248-
GPGLTransactions.Reset();
249391
GPGLTransactions.SetCurrentKey(YEAR1, PERIODID, ACTINDX);
250-
GPGLTransactions.SetFilter(ACTINDX, '= %1', GPAccount.AcctIndex);
392+
GPGLTransactions.SetRange(ACTINDX, GPAccount.AcctIndex);
251393

252394
if InitialYear > 0 then
253395
GPGLTransactions.SetFilter(YEAR1, '>= %1', InitialYear);
254396

255397
if GPGLTransactions.FindSet() then
256398
repeat
257-
PostingGroupCode := PostingGroupCodeTxt + format(GPGLTransactions.YEAR1) + '-' + format(GPGLTransactions.PERIODID);
399+
DocumentNo := PostingGroupCodeTxt + Format(GPGLTransactions.YEAR1) + '-' + Format(GPGLTransactions.PERIODID);
258400

259401
if GPFiscalPeriods.Get(GPGLTransactions.PERIODID, GPGLTransactions.YEAR1) then begin
260-
DataMigrationFacadeHelper.CreateGeneralJournalBatchIfNeeded(CopyStr(PostingGroupCode, 1, 10), '', '');
402+
DataMigrationFacadeHelper.CreateGeneralJournalBatchIfNeeded(CopyStr(DocumentNo, 1, 10), '', '');
261403
DataMigrationFacadeHelper.CreateGeneralJournalLine(
262404
GenJournalLine,
263-
PostingGroupCode,
264-
PostingGroupCode,
405+
DocumentNo,
406+
DocumentNo,
265407
CopyStr(DescriptionTrxTxt, 1, 50),
266408
GenJournalLine."Account Type"::"G/L Account",
267409
CopyStr(GPAccount.AcctNum, 1, 20),
@@ -279,6 +421,62 @@ codeunit 4017 "GP Account Migrator"
279421
until GPGLTransactions.Next() = 0;
280422
end;
281423

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+
282480
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
283481
var
284482
TempDimensionSetEntry: Record "Dimension Set Entry" temporary;
Binary file not shown.

Apps/W1/HybridGP/app/src/Migration/GPTables/GPPopulateCombinedTables.Codeunit.al

+4-5
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ codeunit 40125 "GP Populate Combined Tables"
5656
GPAccount: Record "GP Account";
5757
AccountDescription: Text;
5858
begin
59-
GPGL00100.SetRange(ACCTTYPE, 1);
60-
// Only want to bring in Posting Accounts, no unit accounts allowed
59+
GPGL00100.SetFilter(ACCTTYPE, '1|2');
60+
// Only Posting and Unit accounts
61+
6162
if not GPGL00100.FindSet() then
6263
exit;
6364

@@ -73,7 +74,7 @@ codeunit 40125 "GP Populate Combined Tables"
7374
if AccountDescription = '' then
7475
AccountDescription := GPGL00100.ACTDESCR;
7576

76-
CLEAR(GPAccount);
77+
Clear(GPAccount);
7778
#pragma warning disable AA0139
7879
GPAccount.AcctNum := GPGL00100.MNACSGMT.Trim();
7980
#pragma warning restore AA0139
@@ -138,7 +139,6 @@ codeunit 40125 "GP Populate Combined Tables"
138139
CurrentKey := 1;
139140
GPGL10110.SetFilter(PERDBLNC, '<>0');
140141
GPGL10110.SetFilter(PERIODID, '>0');
141-
GPGL10110.SetRange(GL00100ACCTYPE1Exist, true);
142142
GPGL10110.SetCurrentKey(YEAR1, PERIODID, ACTNUMBR_1, ACTNUMBR_2, ACTNUMBR_3, ACTNUMBR_4, ACTNUMBR_5, ACTNUMBR_6, ACTNUMBR_7, ACTNUMBR_8);
143143
if GPGL10110.FindSet() then
144144
repeat
@@ -201,7 +201,6 @@ codeunit 40125 "GP Populate Combined Tables"
201201

202202
GPGL10111.SetFilter(PERDBLNC, '<>0');
203203
GPGL10111.SetFilter(PERIODID, '>0');
204-
GPGL10111.SetRange(GL00100ACCTYPE1Exist, true);
205204
GPGL10111.SetCurrentKey(YEAR1, PERIODID, ACTNUMBR_1, ACTNUMBR_2, ACTNUMBR_3, ACTNUMBR_4, ACTNUMBR_5, ACTNUMBR_6, ACTNUMBR_7, ACTNUMBR_8);
206205
if GPGL10111.FindSet() then
207206
repeat

0 commit comments

Comments
 (0)