Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1076,13 +1076,15 @@ codeunit 10692 "Generate SAF-T 1.3 File"
CustLedgEntry: Record "Cust. Ledger Entry";
VendLedgEntry: Record "Vendor Ledger Entry";
BankAccLedgEntry: Record "Bank Account Ledger Entry";
GeneralLedgerSetup: Record "General Ledger Setup";
begin
CurrencyCode := '';
ExchangeRate := 0;
EntryAmount := 0;
EntryAmountLCY := 0;
if not SAFTExportHeader."Export Currency Information" then
exit;
GeneralLedgerSetup.Get();

if GLEntry."Source Type" in [GLEntry."Source Type"::Customer, GLEntry."Source Type"::" "] then begin
CustLedgEntry.SetRange("Transaction No.", GLEntry."Transaction No.");
Expand All @@ -1091,6 +1093,8 @@ codeunit 10692 "Generate SAF-T 1.3 File"
exit;
if CustLedgEntry."Currency Code" = '' then
exit;
if CustLedgEntry."Currency Code" = GeneralLedgerSetup."LCY Code" then
exit;
CustLedgEntry.CalcFields(Amount, "Amount (LCY)");
if CustLedgEntry.Amount = 0 then
exit;
Expand All @@ -1109,6 +1113,8 @@ codeunit 10692 "Generate SAF-T 1.3 File"
exit;
if VendLedgEntry."Currency Code" = '' then
exit;
if VendLedgEntry."Currency Code" = GeneralLedgerSetup."LCY Code" then
exit;
VendLedgEntry.CalcFields(Amount, "Amount (LCY)");
if VendLedgEntry.Amount = 0 then
exit;
Expand All @@ -1127,6 +1133,8 @@ codeunit 10692 "Generate SAF-T 1.3 File"
exit;
if BankAccLedgEntry."Currency Code" = '' then
exit;
if BankAccLedgEntry."Currency Code" = GeneralLedgerSetup."LCY Code" then
exit;
if BankAccLedgEntry.Amount = 0 then
exit;
CurrencyCode := BankAccLedgEntry."Currency Code";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,13 +1070,15 @@ codeunit 10673 "Generate SAF-T File"
CustLedgEntry: Record "Cust. Ledger Entry";
VendLedgEntry: Record "Vendor Ledger Entry";
BankAccLedgEntry: Record "Bank Account Ledger Entry";
GeneralLedgerSetup: Record "General Ledger Setup";
begin
CurrencyCode := '';
ExchangeRate := 0;
EntryAmount := 0;
EntryAmountLCY := 0;
if not SAFTExportHeader."Export Currency Information" then
exit;
GeneralLedgerSetup.Get();

if GLEntry."Source Type" in [GLEntry."Source Type"::Customer, GLEntry."Source Type"::" "] then begin
CustLedgEntry.SetRange("Transaction No.", GLEntry."Transaction No.");
Expand All @@ -1085,6 +1087,8 @@ codeunit 10673 "Generate SAF-T File"
exit;
if CustLedgEntry."Currency Code" = '' then
exit;
if CustLedgEntry."Currency Code" = GeneralLedgerSetup."LCY Code" then
exit;
CustLedgEntry.CalcFields(Amount, "Amount (LCY)");
if CustLedgEntry.Amount = 0 then
exit;
Expand All @@ -1103,6 +1107,8 @@ codeunit 10673 "Generate SAF-T File"
exit;
if VendLedgEntry."Currency Code" = '' then
exit;
if VendLedgEntry."Currency Code" = GeneralLedgerSetup."LCY Code" then
exit;
VendLedgEntry.CalcFields(Amount, "Amount (LCY)");
if VendLedgEntry.Amount = 0 then
exit;
Expand All @@ -1121,6 +1127,8 @@ codeunit 10673 "Generate SAF-T File"
exit;
if BankAccLedgEntry."Currency Code" = '' then
exit;
if BankAccLedgEntry."Currency Code" = GeneralLedgerSetup."LCY Code" then
exit;
if BankAccLedgEntry.Amount = 0 then
exit;
CurrencyCode := BankAccLedgEntry."Currency Code";
Expand Down
195 changes: 195 additions & 0 deletions Apps/NO/NorwegianSAFT/test/src/SAFTXMLTests.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,201 @@ codeunit 148103 "SAF-T XML Tests"
Abs(GenJournalLine."Amount (LCY)"), GenJournalLine."Currency Factor");
end;

[Test]
[HandlerFunctions('ConfirmYesHandler')]
procedure VendLCYCurrencyCodeNotExportedInCurrencyBlock()
var
SAFTMappingRange: Record "SAF-T Mapping Range";
SAFTExportHeader: Record "SAF-T Export Header";
SAFTExportLine: Record "SAF-T Export Line";
TempXMLBuffer: Record "XML Buffer" temporary;
TempChildXMLBuffer: Record "XML Buffer" temporary;
GLAccount: Record "G/L Account";
Vendor: Record Vendor;
GeneralLedgerSetup: Record "General Ledger Setup";
GLEntry: Record "G/L Entry";
DocNo: Code[20];
GLEntryNo: Integer;
TransactionNo: Integer;
AmountLCY: Decimal;
begin
// [FEATURE] [Currency] [Purchase]
// [SCENARIO 26554] No currency information is exported for a vendor ledger entry when currency code equals the company LCY code
// and "Export Currency Information" option is enabled in the SAF-T export card

Initialize();

SAFTTestHelper.SetupSAFT(SAFTMappingRange, SAFTMappingType::"Four Digit Standard Account", 10);
SAFTTestHelper.MatchGLAccountsFourDigit(SAFTMappingRange.Code);
SAFTTestHelper.CreateSAFTExportHeader(SAFTExportHeader, SAFTMappingRange.Code);
GeneralLedgerSetup.Get();

DocNo := LibraryUtility.GenerateGUID();
GLAccount.SetRange("Income/Balance", GLAccount."Income/Balance"::"Balance Sheet");
GLAccount.FindFirst();
Vendor.FindFirst();
SAFTTestHelper.IncludesNoSourceCodeToTheFirstSAFTSourceCode();

// [GIVEN] G/L entry for a vendor with "Transaction No." = "Y" and Amount = 100 (Amount LCY)
AmountLCY := LibraryRandom.RandDec(100, 2);
TransactionNo := GetLastUsedTransactionNo() + 1;
GLEntryNo :=
SAFTTestHelper.MockGLEntry(
SAFTExportHeader."Ending Date", DocNo, GLAccount."No.",
TransactionNo, 0, GLEntry."Gen. Posting Type"::Purchase, '',
'', GLEntry."Source Type"::Vendor, Vendor."No.", '', AmountLCY, 0);

// [GIVEN] Vendor ledger entry with "Currency Code" equal to the company LCY code
SAFTTestHelper.MockVendLedgEntry(
GLEntryNo, SAFTExportHeader."Starting Date", Vendor."No.", TransactionNo,
GeneralLedgerSetup."LCY Code", AmountLCY, AmountLCY, AmountLCY, 1, "Gen. Journal Document Type"::Invoice);

// [WHEN] Export G/L entries to the XML file
LibraryVariableStorage.Enqueue(GenerateSAFTFileImmediatelyQst);
SAFTTestHelper.RunSAFTExport(SAFTExportHeader);
SAFTExportLine.SetRange("Master Data", false);
SAFTTestHelper.FindSAFTExportLine(SAFTExportLine, SAFTExportHeader.ID);
SAFTTestHelper.LoadXMLBufferFromSAFTExportLine(TempXMLBuffer, SAFTExportLine);

// [THEN] The DebitAmount node has only "n1:Amount" and no currency information
Assert.IsTrue(
TempXMLBuffer.FindNodesByXPath(
TempXMLBuffer, '/n1:AuditFile/n1:GeneralLedgerEntries/n1:Journal/n1:Transaction/n1:Line/n1:DebitAmount'),
'No G/L entries exported.');
VerifyChildElementsCount(TempChildXMLBuffer, TempXMLBuffer, 1);
SAFTTestHelper.AssertCurrentElementValue(TempChildXMLBuffer, 'n1:Amount', SAFTTestHelper.FormatAmount(AmountLCY));
end;

[Test]
[HandlerFunctions('ConfirmYesHandler')]
procedure CustLCYCurrencyCodeNotExportedInCurrencyBlock()
var
SAFTMappingRange: Record "SAF-T Mapping Range";
SAFTExportHeader: Record "SAF-T Export Header";
SAFTExportLine: Record "SAF-T Export Line";
TempXMLBuffer: Record "XML Buffer" temporary;
TempChildXMLBuffer: Record "XML Buffer" temporary;
GLAccount: Record "G/L Account";
Customer: Record Customer;
GeneralLedgerSetup: Record "General Ledger Setup";
GLEntry: Record "G/L Entry";
DocNo: Code[20];
GLEntryNo: Integer;
TransactionNo: Integer;
AmountLCY: Decimal;
begin
// [FEATURE] [Currency] [Sales]
// [SCENARIO 26554] No currency information is exported for a customer ledger entry when currency code equals the company LCY code
// and "Export Currency Information" option is enabled in the SAF-T export card

Initialize();

SAFTTestHelper.SetupSAFT(SAFTMappingRange, SAFTMappingType::"Four Digit Standard Account", 10);
SAFTTestHelper.MatchGLAccountsFourDigit(SAFTMappingRange.Code);
SAFTTestHelper.CreateSAFTExportHeader(SAFTExportHeader, SAFTMappingRange.Code);
GeneralLedgerSetup.Get();

DocNo := LibraryUtility.GenerateGUID();
GLAccount.SetRange("Income/Balance", GLAccount."Income/Balance"::"Balance Sheet");
GLAccount.FindFirst();
Customer.FindFirst();
SAFTTestHelper.IncludesNoSourceCodeToTheFirstSAFTSourceCode();

// [GIVEN] G/L entry for a customer with "Transaction No." = "Y" and Amount = 100 (Amount LCY)
AmountLCY := LibraryRandom.RandDec(100, 2);
TransactionNo := GetLastUsedTransactionNo() + 1;
GLEntryNo :=
SAFTTestHelper.MockGLEntry(
SAFTExportHeader."Ending Date", DocNo, GLAccount."No.",
TransactionNo, 0, GLEntry."Gen. Posting Type"::Sale, '',
'', GLEntry."Source Type"::Customer, Customer."No.", '', AmountLCY, 0);

// [GIVEN] Customer ledger entry with "Currency Code" equal to the company LCY code
SAFTTestHelper.MockCustLedgEntry(
GLEntryNo, SAFTExportHeader."Starting Date", Customer."No.", TransactionNo,
GeneralLedgerSetup."LCY Code", AmountLCY, AmountLCY, AmountLCY, 1, "Gen. Journal Document Type"::Invoice);

// [WHEN] Export G/L entries to the XML file
LibraryVariableStorage.Enqueue(GenerateSAFTFileImmediatelyQst);
SAFTTestHelper.RunSAFTExport(SAFTExportHeader);
SAFTExportLine.SetRange("Master Data", false);
SAFTTestHelper.FindSAFTExportLine(SAFTExportLine, SAFTExportHeader.ID);
SAFTTestHelper.LoadXMLBufferFromSAFTExportLine(TempXMLBuffer, SAFTExportLine);

// [THEN] The DebitAmount node has only "n1:Amount" and no currency information
Assert.IsTrue(
TempXMLBuffer.FindNodesByXPath(
TempXMLBuffer, '/n1:AuditFile/n1:GeneralLedgerEntries/n1:Journal/n1:Transaction/n1:Line/n1:DebitAmount'),
'No G/L entries exported.');
VerifyChildElementsCount(TempChildXMLBuffer, TempXMLBuffer, 1);
SAFTTestHelper.AssertCurrentElementValue(TempChildXMLBuffer, 'n1:Amount', SAFTTestHelper.FormatAmount(AmountLCY));
end;

[Test]
[HandlerFunctions('ConfirmYesHandler')]
procedure BankLCYCurrencyCodeNotExportedInCurrencyBlock()
var
SAFTMappingRange: Record "SAF-T Mapping Range";
SAFTExportHeader: Record "SAF-T Export Header";
SAFTExportLine: Record "SAF-T Export Line";
TempXMLBuffer: Record "XML Buffer" temporary;
TempChildXMLBuffer: Record "XML Buffer" temporary;
BankAccount: Record "Bank Account";
GLAccount: Record "G/L Account";
GeneralLedgerSetup: Record "General Ledger Setup";
GLEntry: Record "G/L Entry";
DocNo: Code[20];
GLEntryNo: Integer;
TransactionNo: Integer;
AmountLCY: Decimal;
begin
// [FEATURE] [Currency] [Bank]
// [SCENARIO 26554] No currency information is exported for a bank account ledger entry when currency code equals the company LCY code
// and "Export Currency Information" option is enabled in the SAF-T export card

Initialize();

SAFTTestHelper.SetupSAFT(SAFTMappingRange, SAFTMappingType::"Four Digit Standard Account", 10);
SAFTTestHelper.MatchGLAccountsFourDigit(SAFTMappingRange.Code);
SAFTTestHelper.CreateSAFTExportHeader(SAFTExportHeader, SAFTMappingRange.Code);
GeneralLedgerSetup.Get();

DocNo := LibraryUtility.GenerateGUID();
GLAccount.SetRange("Income/Balance", GLAccount."Income/Balance"::"Balance Sheet");
GLAccount.FindFirst();
BankAccount.FindFirst();
SAFTTestHelper.IncludesNoSourceCodeToTheFirstSAFTSourceCode();

// [GIVEN] G/L entry for a bank account with "Transaction No." = "Y" and Amount = 100 (Amount LCY)
AmountLCY := LibraryRandom.RandDec(100, 2);
TransactionNo := GetLastUsedTransactionNo() + 1;
GLEntryNo :=
SAFTTestHelper.MockGLEntry(
SAFTExportHeader."Ending Date", DocNo, GLAccount."No.",
TransactionNo, 0, GLEntry."Gen. Posting Type"::Sale, '',
'', GLEntry."Source Type"::"Bank Account", BankAccount."No.", '', AmountLCY, 0);

// [GIVEN] Bank account ledger entry with "Currency Code" equal to the company LCY code
SAFTTestHelper.MockBankLedgEntry(
GLEntryNo, SAFTExportHeader."Starting Date", BankAccount."No.", TransactionNo,
GeneralLedgerSetup."LCY Code", AmountLCY, AmountLCY, "Gen. Journal Document Type"::Invoice);

// [WHEN] Export G/L entries to the XML file
LibraryVariableStorage.Enqueue(GenerateSAFTFileImmediatelyQst);
SAFTTestHelper.RunSAFTExport(SAFTExportHeader);
SAFTExportLine.SetRange("Master Data", false);
SAFTTestHelper.FindSAFTExportLine(SAFTExportLine, SAFTExportHeader.ID);
SAFTTestHelper.LoadXMLBufferFromSAFTExportLine(TempXMLBuffer, SAFTExportLine);

// [THEN] The DebitAmount node has only "n1:Amount" and no currency information
Assert.IsTrue(
TempXMLBuffer.FindNodesByXPath(
TempXMLBuffer, '/n1:AuditFile/n1:GeneralLedgerEntries/n1:Journal/n1:Transaction/n1:Line/n1:DebitAmount'),
'No G/L entries exported.');
VerifyChildElementsCount(TempChildXMLBuffer, TempXMLBuffer, 1);
SAFTTestHelper.AssertCurrentElementValue(TempChildXMLBuffer, 'n1:Amount', SAFTTestHelper.FormatAmount(AmountLCY));
end;

local procedure Initialize()
begin
LibraryTestInitialize.OnTestInitialize(CODEUNIT::"SAF-T XML Tests");
Expand Down
Loading
Loading