1+ // ------------------------------------------------------------------------------------------------
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ // Licensed under the MIT License. See License.txt in the project root for license information.
4+ // ------------------------------------------------------------------------------------------------
5+
6+ namespace Microsoft. DemoData. Finance;
7+
8+ using Microsoft. Finance. GeneralLedger. Setup;
9+ using Microsoft. DemoTool. Helpers;
10+ using Microsoft. Finance. GeneralLedger. Account;
11+ using Microsoft. Foundation. Enums;
12+ using Microsoft. Finance. Currency;
13+
14+ codeunit 5627 "Create Add. Reporting Currency"
15+ {
16+ InherentEntitlements = X;
17+ InherentPermissions = X;
18+ Permissions =
19+ tabledata "General Ledger Setup" = rm,
20+ tabledata Currency = rm;
21+
22+ trigger OnRun()
23+ begin
24+ ConfigureAdditionalReportingCurrency() ;
25+ GenerateGLAccountsForReportingCurrency() ;
26+ UpdateCurrencyResidualAccounts() ;
27+ end ;
28+
29+ procedure ConfigureAdditionalReportingCurrency()
30+ var
31+ GeneralLedgerSetup: Record "General Ledger Setup";
32+ CreateCurrency: Codeunit "Create Currency";
33+ ACYCode: Code [10 ];
34+ begin
35+ GeneralLedgerSetup. Get() ;
36+ ACYCode := GeneralLedgerSetup. "LCY Code" = CreateCurrency. EUR() ? CreateCurrency. USD() : CreateCurrency. EUR() ;
37+ GeneralLedgerSetup. "Additional Reporting Currency" := ACYCode;
38+ GeneralLedgerSetup. Modify ( true) ;
39+ end ;
40+
41+ procedure GenerateGLAccountsForReportingCurrency()
42+ var
43+ GLAccountCategory: Record "G/L Account Category";
44+ SubCategory: Text [80 ];
45+ begin
46+ ContosoGLAccount. AddAccountForLocalization( ResidualFXGainsName() , ' 9335' ) ;
47+ ContosoGLAccount. AddAccountForLocalization( ResidualFXLossesName() , ' 9345' ) ;
48+
49+ SubCategory := Format( GLAccountCategory. "Account Category"::Income, 80 ) ;
50+ ContosoGLAccount. InsertGLAccount( ResidualFXGains() , ResidualFXGainsName() , Enum ::"G/L Account Income/Balance"::"Income Statement", Enum ::"G/L Account Category"::Income, SubCategory, Enum ::"G/L Account Type"::Posting, ' ' , ' ' , 0 , ' ' , Enum ::"General Posting Type"::" ", ' ' , ' ' , false, false, false) ;
51+
52+ SubCategory := Format( GLAccountCategory. "Account Category"::Expense, 80 ) ;
53+ ContosoGLAccount. InsertGLAccount( ResidualFXLosses() , ResidualFXLossesName() , Enum ::"G/L Account Income/Balance"::"Income Statement", Enum ::"G/L Account Category"::Expense, SubCategory, Enum ::"G/L Account Type"::Posting, ' ' , ' ' , 0 , ' ' , Enum ::"General Posting Type"::" ", ' ' , ' ' , false, false, false) ;
54+ end ;
55+
56+ procedure UpdateCurrencyResidualAccounts()
57+ var
58+ Currency: Record "Currency";
59+ CreateGLAccount: Codeunit "Create G/L Account";
60+ CreateCurrency: Codeunit "Create Currency";
61+ begin
62+ Currency. SetFilter( Code , ' %1|%2' , CreateCurrency. EUR() , CreateCurrency. USD()) ;
63+ if Currency. FindSet( true) then begin
64+ repeat
65+ Currency. Validate( "Residual Gains Account", ResidualFXGains()) ;
66+ Currency. Validate( "Residual Losses Account", ResidualFXLosses()) ;
67+ Currency. Modify ( true) ;
68+ until Currency. Next() = 0 ;
69+ end ;
70+ end ;
71+
72+ procedure ResidualFXGains() : Code [20 ]
73+ begin
74+ exit ( ContosoGLAccount. GetAccountNo( ResidualFXGainsName())) ;
75+ end ;
76+
77+ procedure ResidualFXGainsName() : Text [100 ]
78+ begin
79+ exit ( ResidualFXGainsLbl) ;
80+ end ;
81+
82+ procedure ResidualFXLosses() : Code [20 ]
83+ begin
84+ exit ( ContosoGLAccount. GetAccountNo( ResidualFXLossesName())) ;
85+ end ;
86+
87+ procedure ResidualFXLossesName() : Text [100 ]
88+ begin
89+ exit ( ResidualFXLossesLbl) ;
90+ end ;
91+
92+ var
93+ ContosoGLAccount: Codeunit "Contoso GL Account";
94+ ResidualFXGainsLbl: Label ' Residual FX Gains' , MaxLength = 100 ;
95+ ResidualFXLossesLbl: Label ' Residual FX Losses' , MaxLength = 100 ;
96+ }
0 commit comments