diff --git a/src/Apps/CZ/FixedAssetLocalization/app/Src/Reports/CalculateDepreciationCZF.Report.al b/src/Apps/CZ/FixedAssetLocalization/app/Src/Reports/CalculateDepreciationCZF.Report.al index 90ac9d0fd4..9963999188 100644 --- a/src/Apps/CZ/FixedAssetLocalization/app/Src/Reports/CalculateDepreciationCZF.Report.al +++ b/src/Apps/CZ/FixedAssetLocalization/app/Src/Reports/CalculateDepreciationCZF.Report.al @@ -16,7 +16,7 @@ report 31240 "Calculate Depreciation CZF" { AdditionalSearchTerms = 'write down fixed asset'; ApplicationArea = FixedAssets; - Caption = 'Calculate Depreciation'; + Caption = 'Calculate Depreciation CZ'; ProcessingOnly = true; UsageCategory = Tasks; @@ -118,6 +118,7 @@ report 31240 "Calculate Depreciation CZF" end; if TempFAJournalLine.FindSet() then repeat + InsertBonusDepreciationFAJnlLine(); FAJournalLine.Init(); FAJournalLine."Line No." := 0; FAJournalSetup.SetFAJnlTrailCodes(FAJournalLine); @@ -157,6 +158,7 @@ report 31240 "Calculate Depreciation CZF" end; if TempGenJournalLine.FindSet() then repeat + InsertBonusDepreciationGenJnlLine(); GenJournalLine.Init(); GenJournalLine."Line No." := 0; FAJournalSetup.SetGenJnlTrailCodes(GenJournalLine); @@ -371,6 +373,8 @@ report 31240 "Calculate Depreciation CZF" CalculateDepreciation: Codeunit "Calculate Depreciation"; FAInsertGLAccount: Codeunit "FA Insert G/L Account"; SuppUpdtSourceHandlerCZF: Codeunit "Supp. Updt. Source Handler CZF"; + FADeprBookBonusDepreciationApplied: Dictionary of [RecordId, Boolean]; + FADeprBookBonusDepreciationAmount: Dictionary of [RecordId, Decimal]; WindowDialog: Dialog; DeprAmount: Decimal; Custom1Amount: Decimal; @@ -422,6 +426,129 @@ report 31240 "Calculate Depreciation CZF" exit(StrSubstNo(PostingDescription, FANo, StrSubstNo('%1/%2', Date2DMY(PeriodDate, 3), Date2DMY(PeriodDate, 2)))); end; + local procedure InsertBonusDepreciationFAJnlLine() + var + FADepreciationBook: Record "FA Depreciation Book"; + BonusDepreciationAmount: Decimal; + begin + if not FASetup.BonusDepreciationCorrectlySetupCZF() then + exit; + + FADepreciationBook.SetLoadFields("Use Bonus Depreciation", "Depreciation Starting Date", "Bonus Depreciation %"); + if not FADepreciationBook.Get(TempFAJournalLine."FA No.", DeprBookCode) then + exit; + + if not FADepreciationBook."Use Bonus Depreciation" then + exit; + + if not FADepreciationBook.EligibleForBonusDepreciation(FASetup) then + exit; + + if GetBonusDepreciationApplied(FADepreciationBook) then + exit; + + // Implementation for inserting bonus depreciation line + FAJournalLine.Init(); + FAJournalLine."Line No." := 0; + FAJournalSetup.SetFAJnlTrailCodes(FAJournalLine); + LineNo := LineNo + 1; + if GuiAllowed() then + WindowDialog.Update(3, LineNo); + FAJournalLine."Posting Date" := PostingDate; + FAJournalLine."FA Posting Date" := DeprUntilDate; + if FAJournalLine."Posting Date" = FAJournalLine."FA Posting Date" then + FAJournalLine."Posting Date" := 0D; + FAJournalLine."FA Posting Type" := "FA Journal Line FA Posting Type"::"Bonus Depreciation"; + FAJournalLine.Validate("FA No.", TempFAJournalLine."FA No."); + FAJournalLine."Document No." := DocumentNo2; + FAJournalLine."Posting No. Series" := NoSeries; + FAJournalLine.Description := BuildDescription(TempFAJournalLine."FA No.", PostingDate); + FAJournalLine.Validate("Depreciation Book Code", DeprBookCode); + BonusDepreciationAmount := GetBonusDepreciationAmount(FADepreciationBook); + FAJournalLine.Validate(Amount, BonusDepreciationAmount); + FAJournalLine."FA Error Entry No." := TempFAJournalLine."FA Error Entry No."; + FAJnlNextLineNo := FAJnlNextLineNo + 10000; + FAJournalLine."Line No." := FAJnlNextLineNo; + FAJournalLine.Insert(true); + FAJnlLineCreatedCount += 1; + end; + + local procedure GetBonusDepreciationApplied(FADepreciationBook: Record "FA Depreciation Book"): Boolean + var + BonusDepreciationApplied: Boolean; + begin + if not FADeprBookBonusDepreciationApplied.ContainsKey(FADepreciationBook.RecordId) then begin + BonusDepreciationApplied := FADepreciationBook.BonusDepreciationAppliedCZF(); + FADeprBookBonusDepreciationApplied.Add(FADepreciationBook.RecordId, BonusDepreciationApplied); + exit(BonusDepreciationApplied) + end; + + exit(FADeprBookBonusDepreciationApplied.Get(FADepreciationBook.RecordId)); + end; + + local procedure GetBonusDepreciationAmount(FADepreciationBook: Record "FA Depreciation Book"): Decimal + var + BonusDepreciationAmount: Decimal; + begin + if FADeprBookBonusDepreciationAmount.ContainsKey(FADepreciationBook.RecordId) then + exit(-FADeprBookBonusDepreciationAmount.Get(FADepreciationBook.RecordId)); + + BonusDepreciationAmount := -FADepreciationBook.BonusDepreciationAmountCZF(); + FADeprBookBonusDepreciationAmount.Add(FADepreciationBook.RecordId, -BonusDepreciationAmount); + exit(BonusDepreciationAmount) + end; + + local procedure InsertBonusDepreciationGenJnlLine() + var + FADepreciationBook: Record "FA Depreciation Book"; + BonusDepreciationAmount: Decimal; + begin + if not FASetup.BonusDepreciationCorrectlySetupCZF() then + exit; + + FADepreciationBook.SetLoadFields("Use Bonus Depreciation", "Depreciation Starting Date", "Bonus Depreciation %"); + if not FADepreciationBook.Get(TempGenJournalLine."Account No.", DeprBookCode) then + exit; + + if not FADepreciationBook."Use Bonus Depreciation" then + exit; + + if not FADepreciationBook.EligibleForBonusDepreciation(FASetup) then + exit; + + if GetBonusDepreciationApplied(FADepreciationBook) then + exit; + + // Implementation for inserting bonus depreciation line + GenJournalLine.Init(); + GenJournalLine."Line No." := 0; + FAJournalSetup.SetGenJnlTrailCodes(GenJournalLine); + LineNo := LineNo + 1; + if GuiAllowed() then + WindowDialog.Update(3, LineNo); + GenJournalLine."Posting Date" := PostingDate; + GenJournalLine."VAT Reporting Date" := PostingDate; + GenJournalLine."FA Posting Date" := DeprUntilDate; + if GenJournalLine."Posting Date" = GenJournalLine."FA Posting Date" then + GenJournalLine."FA Posting Date" := 0D; + GenJournalLine."FA Posting Type" := "Gen. Journal Line FA Posting Type"::"Bonus Depreciation"; + GenJournalLine."Account Type" := GenJournalLine."Account Type"::"Fixed Asset"; + GenJournalLine.Validate("Account No.", TempGenJournalLine."Account No."); + GenJournalLine."Document No." := DocumentNo2; + GenJournalLine."Posting No. Series" := NoSeries; + GenJournalLine.Description := BuildDescription(TempGenJournalLine."Account No.", PostingDate); + GenJournalLine.Validate("Depreciation Book Code", DeprBookCode); + BonusDepreciationAmount := GetBonusDepreciationAmount(FADepreciationBook); + GenJournalLine.Validate(Amount, BonusDepreciationAmount); + GenJournalLine."FA Error Entry No." := TempGenJournalLine."FA Error Entry No."; + GenJnlNextLineNo := GenJnlNextLineNo + 1000; + GenJournalLine."Line No." := GenJnlNextLineNo; + GenJournalLine.Insert(true); + GenJnlLineCreatedCount += 1; + if BalAccount then + FAInsertGLAccount.GetBalAcc(GenJournalLine, GenJnlNextLineNo); + end; + [IntegrationEvent(false, false)] local procedure OnAfterCalculateDepreciation(FANo: Code[20]; var TempGenJournalLine: Record "Gen. Journal Line" temporary; var TempFAJournalLine: Record "FA Journal Line" temporary; var DeprAmount: Decimal; var NumberOfDays: Integer; DeprBookCode: Code[10]; DeprUntilDate: Date; EntryAmounts: array[4] of Decimal; DaysInPeriod: Integer) begin diff --git a/src/Apps/CZ/FixedAssetLocalization/app/Src/TableExtensions/FADepreciationBookCZF.TableExt.al b/src/Apps/CZ/FixedAssetLocalization/app/Src/TableExtensions/FADepreciationBookCZF.TableExt.al index 003e86dc63..6e99150475 100644 --- a/src/Apps/CZ/FixedAssetLocalization/app/Src/TableExtensions/FADepreciationBookCZF.TableExt.al +++ b/src/Apps/CZ/FixedAssetLocalization/app/Src/TableExtensions/FADepreciationBookCZF.TableExt.al @@ -4,8 +4,10 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.FixedAssets; +using Microsoft.Finance.GeneralLedger.Setup; using Microsoft.FixedAssets.Depreciation; using Microsoft.FixedAssets.FixedAsset; +using Microsoft.FixedAssets.Ledger; using Microsoft.FixedAssets.Setup; tableextension 31247 "FA Depreciation Book CZF" extends "FA Depreciation Book" @@ -174,6 +176,28 @@ tableextension 31247 "FA Depreciation Book CZF" extends "FA Depreciation Book" FASubclass.TableCaption(), FASubclass.Code); end; + internal procedure BonusDepreciationAppliedCZF(): Boolean + var + FALedgerEntry: Record "FA Ledger Entry"; + begin + FALedgerEntry.ReadIsolation(IsolationLevel::ReadCommitted); + FALedgerEntry.SetCurrentKey("FA No.", "Depreciation Book Code", "FA Posting Category", "FA Posting Type"); + FALedgerEntry.SetRange("FA No.", Rec."FA No."); + FALedgerEntry.SetRange("Depreciation Book Code", Rec."Depreciation Book Code"); + FALedgerEntry.SetRange("FA Posting Category", FALedgerEntry."FA Posting Category"::" "); + FALedgerEntry.SetRange("FA Posting Type", "FA Ledger Entry FA Posting Type"::"Bonus Depreciation"); + exit(not FALedgerEntry.IsEmpty()); + end; + + internal procedure BonusDepreciationAmountCZF(): Decimal + var + GeneralLedgerSetup: Record "General Ledger Setup"; + begin + GeneralLedgerSetup.Get(); + Rec.CalcFields("Acquisition Cost"); + exit(Round(Rec."Acquisition Cost" * Rec."Bonus Depreciation %" * 0.01, GeneralLedgerSetup."Amount Rounding Precision")); + end; + [IntegrationEvent(true, false)] local procedure OnBeforeCheckDefaultFAPostingGroupCZF(var IsHandled: Boolean) begin diff --git a/src/Apps/CZ/FixedAssetLocalization/app/Src/TableExtensions/FASetupCZF.TableExt.al b/src/Apps/CZ/FixedAssetLocalization/app/Src/TableExtensions/FASetupCZF.TableExt.al index 031c47a9e1..28cb4712f4 100644 --- a/src/Apps/CZ/FixedAssetLocalization/app/Src/TableExtensions/FASetupCZF.TableExt.al +++ b/src/Apps/CZ/FixedAssetLocalization/app/Src/TableExtensions/FASetupCZF.TableExt.al @@ -62,4 +62,9 @@ tableextension 31249 "FA Setup CZF" extends "FA Setup" DataClassification = CustomerContent; } } + + internal procedure BonusDepreciationCorrectlySetupCZF(): Boolean + begin + exit((Rec."Bonus Depreciation %" > 0) and (Rec."Bonus Depr. Effective Date" <> 0D)); + end; }