diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index a2f67418bc9..aae6e797946 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1100,7 +1100,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/APAC/Tests/VAT/NonDedVATCurrency.Codeunit.al b/src/Layers/APAC/Tests/VAT/NonDedVATCurrency.Codeunit.al index ad4edd9eb55..8ca233bc056 100644 --- a/src/Layers/APAC/Tests/VAT/NonDedVATCurrency.Codeunit.al +++ b/src/Layers/APAC/Tests/VAT/NonDedVATCurrency.Codeunit.al @@ -20,6 +20,9 @@ codeunit 134286 "Non. Ded. VAT Currency" LibraryUtility: Codeunit "Library - Utility"; Assert: Codeunit Assert; isInitialized: Boolean; + GLEntriesSourceCurrNotBalancedErr: Label 'G/L Entries source currency amounts must be balanced'; + NoSourceCurrGLEntriesErr: Label 'No G/L Entries with the expected source currency were created'; + GLEntrySourceCurrAmountErr: Label 'G/L Entry source currency amount for account %1 is not as expected', Comment = '%1 = G/L Account No.'; [Test] procedure BasicPurchInvWithACY() @@ -242,6 +245,56 @@ codeunit 134286 "Non. Ded. VAT Currency" VerifyGLEntriesBalanced(DocumentNo, PostingDate); end; + [Test] + procedure PostFCYPurchInvWithPartialNonDedVATAndSourceCurrConsistency() + var + PurchHeader: Record "Purchase Header"; + PurchLine: Record "Purchase Line"; + VATPostingSetup: Record "VAT Posting Setup"; + CurrencyCode: Code[10]; + DocNo: Code[20]; + begin + // [SCENARIO 640619] Posting a foreign currency Purchase Invoice with partial Non-Deductible VAT does not cause a G/L Entry consistency error when "Check Source Curr. Consistency" is enabled in General Ledger Setup. + Initialize(); + + // [GIVEN] "Check Source Curr. Consistency" is enabled in General Ledger Setup + EnableCheckSourceCurrConsistency(); + + // [GIVEN] Normal VAT Posting Setup with "VAT %" = 20 and partial "Non-Deductible VAT %" = 50, with a dedicated Non-Deductible Purchase VAT Account + LibraryERM.CreateVATPostingSetupWithAccounts(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT", 20); + LibraryNonDeductibleVAT.SetAllowNonDeductibleVATForVATPostingSetup(VATPostingSetup); + VATPostingSetup.Validate("Non-Deductible VAT %", 50); + VATPostingSetup.Validate("Non-Ded. Purchase VAT Account", LibraryERM.CreateGLAccountNo()); + VATPostingSetup.Modify(true); + + // [GIVEN] Currency "C" with exchange rate that differs from LCY + CurrencyCode := LibraryERM.CreateCurrencyWithExchangeRate(WorkDate(), 100, 130); + + // [GIVEN] Purchase Invoice in currency "C" with Normal VAT and partial Non-Deductible VAT + LibraryPurchase.CreatePurchHeader( + PurchHeader, PurchHeader."Document Type"::Invoice, + LibraryPurchase.CreateVendorWithVATBusPostingGroup(VATPostingSetup."VAT Bus. Posting Group")); + PurchHeader.Validate("Currency Code", CurrencyCode); + PurchHeader.Modify(true); + LibraryPurchase.CreatePurchaseLine( + PurchLine, PurchHeader, PurchLine.Type::Item, + LibraryInventory.CreateItemWithVATProdPostingGroup(VATPostingSetup."VAT Prod. Posting Group"), 1); + PurchLine.Validate("Direct Unit Cost", 100); + PurchLine.Modify(true); + + // [WHEN] Post the Purchase Invoice (must not raise a source currency consistency error) + DocNo := LibraryPurchase.PostPurchaseDocument(PurchHeader, true, true); + + // [THEN] G/L Entries are balanced in LCY and in source currency + VerifyGLEntriesBalanced(DocNo, PurchHeader."Posting Date"); + VerifyGLEntriesSourceCurrencyBalanced(DocNo, PurchHeader."Posting Date", CurrencyCode); + + // [THEN] The deductible VAT G/L entry carries the deductible half of the 20 source-currency VAT amount (100 base * 20% VAT * (100% - 50% Non-Deductible)) + VerifyGLEntrySourceCurrencyAmountForAccount(DocNo, PurchHeader."Posting Date", CurrencyCode, VATPostingSetup."Purchase VAT Account", 10); + // [THEN] The non-deductible VAT G/L entry carries the non-deductible half of the 20 source-currency VAT amount (100 base * 20% VAT * 50% Non-Deductible) + VerifyGLEntrySourceCurrencyAmountForAccount(DocNo, PurchHeader."Posting Date", CurrencyCode, VATPostingSetup."Non-Ded. Purchase VAT Account", 10); + end; + local procedure Initialize() var LibraryERMCountryData: Codeunit "Library - ERM Country Data"; @@ -382,4 +435,38 @@ codeunit 134286 "Non. Ded. VAT Currency" Assert.AreEqual(GLEntry."Debit Amount", GLEntry."Credit Amount", 'G/L Entries LCY must be balanced'); Assert.AreEqual(GLEntry."Add.-Currency Debit Amount", GLEntry."Add.-Currency Credit Amount", 'G/L Entries ACY must be balanced'); end; + + local procedure VerifyGLEntriesSourceCurrencyBalanced(DocumentNo: Code[20]; PostingDate: Date; CurrencyCode: Code[10]) + var + GLEntry: Record "G/L Entry"; + begin + GLEntry.SetRange("Document No.", DocumentNo); + GLEntry.SetRange("Posting Date", PostingDate); + GLEntry.SetRange("Source Currency Code", CurrencyCode); + Assert.IsFalse(GLEntry.IsEmpty(), NoSourceCurrGLEntriesErr); + GLEntry.CalcSums("Source Currency Amount"); + Assert.AreEqual(0, GLEntry."Source Currency Amount", GLEntriesSourceCurrNotBalancedErr); + end; + + local procedure VerifyGLEntrySourceCurrencyAmountForAccount(DocumentNo: Code[20]; PostingDate: Date; CurrencyCode: Code[10]; GLAccountNo: Code[20]; ExpectedSourceCurrencyAmount: Decimal) + var + GLEntry: Record "G/L Entry"; + begin + GLEntry.SetRange("Document No.", DocumentNo); + GLEntry.SetRange("Posting Date", PostingDate); + GLEntry.SetRange("Source Currency Code", CurrencyCode); + GLEntry.SetRange("G/L Account No.", GLAccountNo); + Assert.IsFalse(GLEntry.IsEmpty(), NoSourceCurrGLEntriesErr); + GLEntry.CalcSums("Source Currency Amount"); + Assert.AreEqual(ExpectedSourceCurrencyAmount, GLEntry."Source Currency Amount", StrSubstNo(GLEntrySourceCurrAmountErr, GLAccountNo)); + end; + + local procedure EnableCheckSourceCurrConsistency() + var + GeneralLedgerSetup: Record "General Ledger Setup"; + begin + GeneralLedgerSetup.Get(); + GeneralLedgerSetup.Validate("Check Source Curr. Consistency", true); + GeneralLedgerSetup.Modify(true); + end; } \ No newline at end of file diff --git a/src/Layers/BE/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/BE/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index be02d4b70d8..c27c4fbf2ff 100644 --- a/src/Layers/BE/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/BE/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1020,7 +1020,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 783a8e0c532..bb1f72cf26d 100644 --- a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1033,7 +1033,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 01754337de9..a649f4d28cc 100644 --- a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1073,7 +1073,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 0363b151994..1de213bf909 100644 --- a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1016,7 +1016,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/FR/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/FR/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 11b607b5349..0ecca10c2d8 100644 --- a/src/Layers/FR/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/FR/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1024,7 +1024,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 6a460f13990..9f4747cbf0e 100644 --- a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1218,7 +1218,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index ca0847da745..89843870b65 100644 --- a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1099,7 +1099,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 29b0a108ffa..f4af4dd3507 100644 --- a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1022,7 +1022,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 780850855a0..50c2fce539c 100644 --- a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1292,7 +1292,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index ee49175df46..8791cffbc71 100644 --- a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -1014,7 +1014,7 @@ codeunit 12 "Gen. Jnl.-Post Line" CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), VATPostingParameters."Deductible VAT Amount", VATPostingParameters."Deductible VAT Amount ACY", true, - GenJnlLine."Source Curr. VAT Amount") + GenJnlLine."Source Curr. VAT Amount" - CalcAmountSrcCurr(GenJnlLine, VATPostingParameters."Non-Deductible VAT Amount")) else CreateGLEntry( GenJnlLine, VATPostingSetup.GetPurchAccount(VATPostingParameters."Unrealized VAT"), diff --git a/src/Layers/W1/Tests/VAT/NonDedVATCurrency.Codeunit.al b/src/Layers/W1/Tests/VAT/NonDedVATCurrency.Codeunit.al index 2f6e3275a99..72f1cb99af5 100644 --- a/src/Layers/W1/Tests/VAT/NonDedVATCurrency.Codeunit.al +++ b/src/Layers/W1/Tests/VAT/NonDedVATCurrency.Codeunit.al @@ -20,6 +20,9 @@ codeunit 134286 "Non. Ded. VAT Currency" LibraryUtility: Codeunit "Library - Utility"; Assert: Codeunit Assert; isInitialized: Boolean; + GLEntriesSourceCurrNotBalancedErr: Label 'G/L Entries source currency amounts must be balanced'; + NoSourceCurrGLEntriesErr: Label 'No G/L Entries with the expected source currency were created'; + GLEntrySourceCurrAmountErr: Label 'G/L Entry source currency amount for account %1 is not as expected', Comment = '%1 = G/L Account No.'; [Test] procedure BasicPurchInvWithACY() @@ -242,6 +245,56 @@ codeunit 134286 "Non. Ded. VAT Currency" VerifyGLEntriesBalanced(DocumentNo, PostingDate); end; + [Test] + procedure PostFCYPurchInvWithPartialNonDedVATAndSourceCurrConsistency() + var + PurchHeader: Record "Purchase Header"; + PurchLine: Record "Purchase Line"; + VATPostingSetup: Record "VAT Posting Setup"; + CurrencyCode: Code[10]; + DocNo: Code[20]; + begin + // [SCENARIO 640619] Posting a foreign currency Purchase Invoice with partial Non-Deductible VAT does not cause a G/L Entry consistency error when "Check Source Curr. Consistency" is enabled in General Ledger Setup. + Initialize(); + + // [GIVEN] "Check Source Curr. Consistency" is enabled in General Ledger Setup + EnableCheckSourceCurrConsistency(); + + // [GIVEN] Normal VAT Posting Setup with "VAT %" = 20 and partial "Non-Deductible VAT %" = 50, with a dedicated Non-Deductible Purchase VAT Account + LibraryERM.CreateVATPostingSetupWithAccounts(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT", 20); + LibraryNonDeductibleVAT.SetAllowNonDeductibleVATForVATPostingSetup(VATPostingSetup); + VATPostingSetup.Validate("Non-Deductible VAT %", 50); + VATPostingSetup.Validate("Non-Ded. Purchase VAT Account", LibraryERM.CreateGLAccountNo()); + VATPostingSetup.Modify(true); + + // [GIVEN] Currency "C" with exchange rate that differs from LCY + CurrencyCode := LibraryERM.CreateCurrencyWithExchangeRate(WorkDate(), 100, 130); + + // [GIVEN] Purchase Invoice in currency "C" with Normal VAT and partial Non-Deductible VAT + LibraryPurchase.CreatePurchHeader( + PurchHeader, PurchHeader."Document Type"::Invoice, + LibraryPurchase.CreateVendorWithVATBusPostingGroup(VATPostingSetup."VAT Bus. Posting Group")); + PurchHeader.Validate("Currency Code", CurrencyCode); + PurchHeader.Modify(true); + LibraryPurchase.CreatePurchaseLine( + PurchLine, PurchHeader, PurchLine.Type::Item, + LibraryInventory.CreateItemWithVATProdPostingGroup(VATPostingSetup."VAT Prod. Posting Group"), 1); + PurchLine.Validate("Direct Unit Cost", 100); + PurchLine.Modify(true); + + // [WHEN] Post the Purchase Invoice (must not raise a source currency consistency error) + DocNo := LibraryPurchase.PostPurchaseDocument(PurchHeader, true, true); + + // [THEN] G/L Entries are balanced in LCY and in source currency + VerifyGLEntriesBalanced(DocNo, PurchHeader."Posting Date"); + VerifyGLEntriesSourceCurrencyBalanced(DocNo, PurchHeader."Posting Date", CurrencyCode); + + // [THEN] The deductible VAT G/L entry carries the deductible half of the 20 source-currency VAT amount (100 base * 20% VAT * (100% - 50% Non-Deductible)) + VerifyGLEntrySourceCurrencyAmountForAccount(DocNo, PurchHeader."Posting Date", CurrencyCode, VATPostingSetup."Purchase VAT Account", 10); + // [THEN] The non-deductible VAT G/L entry carries the non-deductible half of the 20 source-currency VAT amount (100 base * 20% VAT * 50% Non-Deductible) + VerifyGLEntrySourceCurrencyAmountForAccount(DocNo, PurchHeader."Posting Date", CurrencyCode, VATPostingSetup."Non-Ded. Purchase VAT Account", 10); + end; + local procedure Initialize() var LibraryERMCountryData: Codeunit "Library - ERM Country Data"; @@ -367,4 +420,38 @@ codeunit 134286 "Non. Ded. VAT Currency" Assert.AreEqual(GLEntry."Debit Amount", GLEntry."Credit Amount", 'G/L Entries LCY must be balanced'); Assert.AreEqual(GLEntry."Add.-Currency Debit Amount", GLEntry."Add.-Currency Credit Amount", 'G/L Entries ACY must be balanced'); end; + + local procedure VerifyGLEntriesSourceCurrencyBalanced(DocumentNo: Code[20]; PostingDate: Date; CurrencyCode: Code[10]) + var + GLEntry: Record "G/L Entry"; + begin + GLEntry.SetRange("Document No.", DocumentNo); + GLEntry.SetRange("Posting Date", PostingDate); + GLEntry.SetRange("Source Currency Code", CurrencyCode); + Assert.IsFalse(GLEntry.IsEmpty(), NoSourceCurrGLEntriesErr); + GLEntry.CalcSums("Source Currency Amount"); + Assert.AreEqual(0, GLEntry."Source Currency Amount", GLEntriesSourceCurrNotBalancedErr); + end; + + local procedure VerifyGLEntrySourceCurrencyAmountForAccount(DocumentNo: Code[20]; PostingDate: Date; CurrencyCode: Code[10]; GLAccountNo: Code[20]; ExpectedSourceCurrencyAmount: Decimal) + var + GLEntry: Record "G/L Entry"; + begin + GLEntry.SetRange("Document No.", DocumentNo); + GLEntry.SetRange("Posting Date", PostingDate); + GLEntry.SetRange("Source Currency Code", CurrencyCode); + GLEntry.SetRange("G/L Account No.", GLAccountNo); + Assert.IsFalse(GLEntry.IsEmpty(), NoSourceCurrGLEntriesErr); + GLEntry.CalcSums("Source Currency Amount"); + Assert.AreEqual(ExpectedSourceCurrencyAmount, GLEntry."Source Currency Amount", StrSubstNo(GLEntrySourceCurrAmountErr, GLAccountNo)); + end; + + local procedure EnableCheckSourceCurrConsistency() + var + GeneralLedgerSetup: Record "General Ledger Setup"; + begin + GeneralLedgerSetup.Get(); + GeneralLedgerSetup.Validate("Check Source Curr. Consistency", true); + GeneralLedgerSetup.Modify(true); + end; } \ No newline at end of file