Page 254 Purchase Journal

Base Application, Microsoft.Finance.GeneralLedger.Journal

src/Layers/W1/BaseApp/Finance/GeneralLedger/Journal/PurchaseJournal.Page.al1,880 lines, Copyright (c) Microsoft Corporation. MIT

// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.Finance.GeneralLedger.Journal;using Microsoft.EServices.EDocument;using Microsoft.Finance.AllocationAccount;using Microsoft.Finance.Currency;using Microsoft.Finance.Dimension;using Microsoft.Finance.GeneralLedger.Posting;using Microsoft.Finance.GeneralLedger.Setup;using Microsoft.Finance.ReceivablesPayables;using Microsoft.Finance.VAT.Calculation;using Microsoft.Foundation.Reporting;using Microsoft.Purchases.Setup;using Microsoft.Utilities;using System.Automation;using System.Environment;using System.Environment.Configuration;using System.Integration;using System.Threading;/// <summary>/// Purchase journal page for entering purchase transactions and vendor-related general journal entries./// Provides specialized interface for purchase postings with vendor account focus and simplified data entry./// </summary>/// <remarks>/// Specialized purchase journal with vendor-focused transaction entry interface./// Features dual view modes: simple view (vendor-focused) and detailed view (full general journal functionality)./// Key capabilities: Vendor payment processing, purchase invoice corrections, vendor adjustments, VAT handling./// Integration: Direct posting to vendor ledger entries, automatic account validation, dimension processing./// </remarks>page 254 "Purchase Journal"{    // // This page has two view modes based on global variable 'IsSimplePage' as :-    // // Show more coloums action (IsSimplePage = FALSE)    // // - Default page layout before simple view was introduced.    // // Show less coloums action (IsSimplePage = TRUE)    // // Hide amount, account type coloums and set default account type to Vendor.    // // Show a new column named document amount where user will enter amount for the line    // // By DEFAULT this page opens up in simple page layout.    ApplicationArea = Basic, Suite;    AutoSplitKey = true;    Caption = 'Purchase Journals';    DataCaptionExpression = Rec.DataCaption();    DelayedInsert = true;    PageType = Worksheet;    AboutTitle = 'About Purchase Journals';    AboutText = 'Record and post purchase-related transactions such as invoices, payments, and credit memos, including amounts, accounts, VAT, and dimensions, to update vendor balances and the general ledger.';    SaveValues = true;    SourceTable = "Gen. Journal Line";    UsageCategory = Tasks;    layout    {        area(content)        {            group(Control2)            {                ShowCaption = false;                field(CurrentJnlBatchName; CurrentJnlBatchName)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Batch Name';                    Lookup = true;                    ToolTip = 'Specifies the name of the journal batch, a personalized journal layout, that the journal is based on.';                    trigger OnLookup(var Text: Text): Boolean                    begin                        CurrPage.SaveRecord();                        GenJnlManagement.LookupName(CurrentJnlBatchName, Rec);                        GenJnlManagement.SetLastViewedJournalBatchName(PAGE::"Purchase Journal", CurrentJnlBatchName);                        SetControlAppearanceFromBatch();                        CurrPage.Update(false);                    end;                    trigger OnValidate()                    begin                        GenJnlManagement.CheckName(CurrentJnlBatchName, Rec);                        CurrentJnlBatchNameOnAfterVali();                        GenJnlManagement.SetLastViewedJournalBatchName(PAGE::"Purchase Journal", CurrentJnlBatchName);                    end;                }                field(GenJnlBatchApprovalStatus; GenJnlBatchApprovalStatus)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Approval Status';                    Editable = false;                    Visible = EnabledGenJnlBatchWorkflowsExist;                    ToolTip = 'Specifies the approval status for general journal batch.';                }            }            repeater(Control1)            {                ShowCaption = false;                field("Posting Date"; Rec."Posting Date")                {                    ApplicationArea = Basic, Suite;                }                field("VAT Reporting Date"; Rec."VAT Reporting Date")                {                    ApplicationArea = VAT;                    Editable = VATDateEnabled;                    Visible = VATDateEnabled;                }                field("Document Date"; Rec."Document Date")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Invoice Received Date"; Rec."Invoice Received Date")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Document Type"; Rec."Document Type")                {                    ApplicationArea = Basic, Suite;                    trigger OnValidate()                    begin                        if xRec."Document Type" <> Rec."Document Type" then                            if (Rec."Document Type" = Rec."Document Type"::Payment) or (Rec."Document Type" = Rec."Document Type"::"Credit Memo") then                                Rec.Validate(Amount, Abs(Rec.Amount))                            else                                if Rec.Amount > 0 then                                    Rec.Validate(Amount, -1 * Rec.Amount)                    end;                }                field("Document No."; Rec."Document No.")                {                    ApplicationArea = Basic, Suite;                    ShowMandatory = true;                }                field("Incoming Document Entry No."; Rec."Incoming Document Entry No.")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                    trigger OnAssistEdit()                    begin                        if Rec."Incoming Document Entry No." > 0 then                            HyperLink(Rec.GetIncomingDocumentURL());                    end;                }                field("External Document No."; Rec."External Document No.")                {                    ApplicationArea = Basic, Suite;                }                field("Account Type"; Rec."Account Type")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                    trigger OnValidate()                    begin                        GenJnlManagement.GetAccounts(Rec, AccName, BalAccName);                        EnableApplyEntriesAction();                        CurrPage.SaveRecord();                    end;                }                field("Account No."; Rec."Account No.")                {                    ApplicationArea = Basic, Suite;                    trigger OnValidate()                    begin                        GenJnlManagement.GetAccounts(Rec, AccName, BalAccName);                        Rec.ShowShortcutDimCode(ShortcutDimCode);                        CurrPage.SaveRecord();                        CurrPage.Update(false);                    end;                }                field("<Vendor Name>"; GetVendorName())                {                    ApplicationArea = Basic, Suite;                    Caption = 'Vendor Name';                    Editable = false;                    ToolTip = 'Specifies the name of the vendor.';                }                field("Spend Request No."; Rec."Spend Request No.")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field(GenJnlLineApprovalStatus; GenJnlLineApprovalStatus)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Approval Status';                    Editable = false;                    Visible = EnabledGenJnlLineWorkflowsExist;                    ToolTip = 'Specifies the approval status for general journal line.';                }                field(Description; Rec.Description)                {                    ApplicationArea = Basic, Suite;                }                field("Salespers./Purch. Code"; Rec."Salespers./Purch. Code")                {                    ApplicationArea = Suite;                    Visible = false;                }                field("Campaign No."; Rec."Campaign No.")                {                    ApplicationArea = RelationshipMgmt;                    Visible = false;                }                field("Currency Code"; Rec."Currency Code")                {                    ApplicationArea = Suite;                    AssistEdit = true;                    Visible = false;                    trigger OnAssistEdit()                    begin                        ChangeExchangeRate.SetParameter(Rec."Currency Code", Rec."Currency Factor", Rec."Posting Date");                        if ChangeExchangeRate.RunModal() = ACTION::OK then                            Rec.Validate("Currency Factor", ChangeExchangeRate.GetParameter());                        Clear(ChangeExchangeRate);                    end;                }                field("Gen. Posting Type"; Rec."Gen. Posting Type")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                    trigger OnValidate()                    begin                        CurrPage.SaveRecord();                    end;                }                field("Gen. Bus. Posting Group"; Rec."Gen. Bus. Posting Group")                {                    ApplicationArea = Basic, Suite;                    ToolTip = 'Specifies the vendor''s trade type to link transactions made for this vendor with the appropriate general ledger account according to the general posting setup.';                    Visible = not IsSimplePage;                }                field("Gen. Prod. Posting Group"; Rec."Gen. Prod. Posting Group")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                }                field("VAT Bus. Posting Group"; Rec."VAT Bus. Posting Group")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("VAT Prod. Posting Group"; Rec."VAT Prod. Posting Group")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Posting Group"; Rec."Posting Group")                {                    ApplicationArea = Basic, Suite;                    Editable = IsPostingGroupEditable;                    Visible = IsPostingGroupEditable;                }                field(DocumentAmount; DocumentAmount)                {                    ApplicationArea = Basic, Suite;                    AutoFormatExpression = Rec."Currency Code";                    AutoFormatType = 1;                    Caption = 'Document Amount';                    ToolTip = 'Specifies the total amount (including VAT) that the journal line consists of.';                    trigger OnValidate()                    begin                        // Document amount can not be less than 0                        if DocumentAmount < 0 then                            Error(NegativeDocAmountErr);                        if (Rec."Document Type" = Rec."Document Type"::Payment) or                           (Rec."Document Type" = Rec."Document Type"::"Credit Memo")                        then                            Rec.Validate(Amount, DocumentAmount)                        else                            Rec.Validate(Amount, DocumentAmount * -1);                        CurrPage.SaveRecord();                    end;                }                field(Amount; Rec.Amount)                {                    ApplicationArea = Basic, Suite;                    Visible = AmountVisible;                    trigger OnValidate()                    begin                        DocumentAmount := Abs(Rec.Amount);                        CurrPage.SaveRecord();                    end;                }                field("Amount (LCY)"; Rec."Amount (LCY)")                {                    ApplicationArea = Basic, Suite;                    ToolTip = 'Specifies the total amount in local currency (including VAT) that the journal line consists of.';                    Visible = AmountVisible;                }                field("Debit Amount"; Rec."Debit Amount")                {                    ApplicationArea = Basic, Suite;                    Visible = DebitCreditVisible;                    trigger OnValidate()                    begin                        DocumentAmount := Abs(Rec."Debit Amount");                    end;                }                field("Credit Amount"; Rec."Credit Amount")                {                    ApplicationArea = Basic, Suite;                    Visible = DebitCreditVisible;                    trigger OnValidate()                    begin                        DocumentAmount := Abs(Rec."Credit Amount");                    end;                }                field("Tax Liable"; Rec."Tax Liable")                {                    ApplicationArea = SalesTax;                    Visible = false;                }                field("Tax Area Code"; Rec."Tax Area Code")                {                    ApplicationArea = SalesTax;                    Visible = false;                }                field("Tax Group Code"; Rec."Tax Group Code")                {                    ApplicationArea = SalesTax;                    Visible = false;                }                field("Use Tax"; Rec."Use Tax")                {                    ApplicationArea = SalesTax;                    Visible = false;                }                field("VAT Amount"; Rec."VAT Amount")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("VAT Difference"; Rec."VAT Difference")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Bal. VAT Amount"; Rec."Bal. VAT Amount")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Bal. VAT Difference"; Rec."Bal. VAT Difference")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Bal. Account Type"; Rec."Bal. Account Type")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                    trigger OnValidate()                    begin                        EnableApplyEntriesAction();                    end;                }                field("Bal. Account No."; Rec."Bal. Account No.")                {                    ApplicationArea = Basic, Suite;                    trigger OnValidate()                    begin                        GenJnlManagement.GetAccounts(Rec, AccName, BalAccName);                        Rec.ShowShortcutDimCode(ShortcutDimCode);                        CurrPage.SaveRecord();                    end;                }                field("Bal. Gen. Posting Type"; Rec."Bal. Gen. Posting Type")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                    trigger OnValidate()                    begin                        CurrPage.SaveRecord();                    end;                }                field("Bal. Gen. Bus. Posting Group"; Rec."Bal. Gen. Bus. Posting Group")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                    trigger OnValidate()                    begin                        CurrPage.SaveRecord();                    end;                }                field("Bal. Gen. Prod. Posting Group"; Rec."Bal. Gen. Prod. Posting Group")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                }                field("Bal. VAT Bus. Posting Group"; Rec."Bal. VAT Bus. Posting Group")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Bal. VAT Prod. Posting Group"; Rec."Bal. VAT Prod. Posting Group")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Deferral Code"; Rec."Deferral Code")                {                    ApplicationArea = Suite;                    Visible = not IsSimplePage;                    trigger OnAssistEdit()                    begin                        CurrPage.SaveRecord();                        Commit();                        Rec.ShowDeferralSchedule();                    end;                }                field("Allocation Account No."; Rec."Selected Alloc. Account No.")                {                    ApplicationArea = All;                    Caption = 'Allocation Account No.';                    Visible = UseAllocationAccountNumber;                    trigger OnValidate()                    var                        GenJournalAllocAccMgt: Codeunit "Gen. Journal Alloc. Acc. Mgt.";                    begin                        GenJournalAllocAccMgt.VerifySelectedAllocationAccountNo(Rec);                    end;                }                field("Bill-to/Pay-to No."; Rec."Bill-to/Pay-to No.")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Ship-to/Order Address Code"; Rec."Ship-to/Order Address Code")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Sales/Purch. (LCY)"; Rec."Sales/Purch. (LCY)")                {                    ApplicationArea = Basic, Suite;                    ToolTip = 'Specifies the line''s net amount (the amount excluding VAT) if you are using this journal line for an invoice.';                    Visible = false;                }                field("Inv. Discount (LCY)"; Rec."Inv. Discount (LCY)")                {                    ApplicationArea = Basic, Suite;                    ToolTip = 'Specifies the amount of the invoice discount if you are using this journal line for an invoice.';                    Visible = false;                }                field("Payment Terms Code"; Rec."Payment Terms Code")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Due Date"; Rec."Due Date")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Pmt. Discount Date"; Rec."Pmt. Discount Date")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Payment Discount %"; Rec."Payment Discount %")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("Applies-to Doc. Type"; Rec."Applies-to Doc. Type")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                }                field("Applies-to Doc. No."; Rec."Applies-to Doc. No.")                {                    ApplicationArea = Basic, Suite;                    Visible = not IsSimplePage;                }                field("Applies-to ID"; Rec."Applies-to ID")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field("On Hold"; Rec."On Hold")                {                    ApplicationArea = Basic, Suite;                }                field("Reason Code"; Rec."Reason Code")                {                    ApplicationArea = Basic, Suite;                    Visible = false;                }                field(Correction; Rec.Correction)                {                    ApplicationArea = Basic, Suite;                }                field(Comment; Rec.Comment)                {                    ApplicationArea = Comments;                    Visible = false;                }                field("Job Queue Status"; Rec."Job Queue Status")                {                    ApplicationArea = All;                    Importance = Additional;                    Visible = JobQueuesUsed;                    trigger OnDrillDown()                    var                        JobQueueEntry: Record "Job Queue Entry";                    begin                        if Rec."Job Queue Status" = Rec."Job Queue Status"::" " then                            exit;                        JobQueueEntry.ShowStatusMsg(Rec."Job Queue Entry ID");                    end;                }                field("Shortcut Dimension 1 Code"; Rec."Shortcut Dimension 1 Code")                {                    ApplicationArea = Dimensions;                    Visible = DimVisible1;                    trigger OnValidate()                    begin                        CurrPage.SaveRecord();                    end;                }                field("Shortcut Dimension 2 Code"; Rec."Shortcut Dimension 2 Code")                {                    ApplicationArea = Dimensions;                    Visible = DimVisible2;                    trigger OnValidate()                    begin                        CurrPage.SaveRecord();                    end;                }                field(ShortcutDimCode3; ShortcutDimCode[3])                {                    ApplicationArea = Dimensions;                    CaptionClass = '1,2,3';                    TableRelation = "Dimension Value".Code where("Global Dimension No." = const(3),                                                                  "Dimension Value Type" = const(Standard),                                                                  Blocked = const(false));                    Visible = DimVisible3;                    trigger OnValidate()                    begin                        Rec.ValidateShortcutDimCode(3, ShortcutDimCode[3]);                        OnAfterValidateShortcutDimCode(Rec, ShortcutDimCode, 3);                    end;                }                field(ShortcutDimCode4; ShortcutDimCode[4])                {                    ApplicationArea = Dimensions;                    CaptionClass = '1,2,4';                    TableRelation = "Dimension Value".Code where("Global Dimension No." = const(4),                                                                  "Dimension Value Type" = const(Standard),                                                                  Blocked = const(false));                    Visible = DimVisible4;                    trigger OnValidate()                    begin                        Rec.ValidateShortcutDimCode(4, ShortcutDimCode[4]);                        OnAfterValidateShortcutDimCode(Rec, ShortcutDimCode, 4);                    end;                }                field(ShortcutDimCode5; ShortcutDimCode[5])                {                    ApplicationArea = Dimensions;                    CaptionClass = '1,2,5';                    TableRelation = "Dimension Value".Code where("Global Dimension No." = const(5),                                                                  "Dimension Value Type" = const(Standard),                                                                  Blocked = const(false));                    Visible = DimVisible5;                    trigger OnValidate()                    begin                        Rec.ValidateShortcutDimCode(5, ShortcutDimCode[5]);                        OnAfterValidateShortcutDimCode(Rec, ShortcutDimCode, 5);                    end;                }                field(ShortcutDimCode6; ShortcutDimCode[6])                {                    ApplicationArea = Dimensions;                    CaptionClass = '1,2,6';                    TableRelation = "Dimension Value".Code where("Global Dimension No." = const(6),                                                                  "Dimension Value Type" = const(Standard),                                                                  Blocked = const(false));                    Visible = DimVisible6;                    trigger OnValidate()                    begin                        Rec.ValidateShortcutDimCode(6, ShortcutDimCode[6]);                        OnAfterValidateShortcutDimCode(Rec, ShortcutDimCode, 6);                    end;                }                field(ShortcutDimCode7; ShortcutDimCode[7])                {                    ApplicationArea = Dimensions;                    CaptionClass = '1,2,7';                    TableRelation = "Dimension Value".Code where("Global Dimension No." = const(7),                                                                  "Dimension Value Type" = const(Standard),                                                                  Blocked = const(false));                    Visible = DimVisible7;                    trigger OnValidate()                    begin                        Rec.ValidateShortcutDimCode(7, ShortcutDimCode[7]);                        OnAfterValidateShortcutDimCode(Rec, ShortcutDimCode, 7);                    end;                }                field(ShortcutDimCode8; ShortcutDimCode[8])                {                    ApplicationArea = Dimensions;                    CaptionClass = '1,2,8';                    TableRelation = "Dimension Value".Code where("Global Dimension No." = const(8),                                                                  "Dimension Value Type" = const(Standard),                                                                  Blocked = const(false));                    Visible = DimVisible8;                    trigger OnValidate()                    begin                        Rec.ValidateShortcutDimCode(8, ShortcutDimCode[8]);                        OnAfterValidateShortcutDimCode(Rec, ShortcutDimCode, 8);                    end;                }            }            group(Control28)            {                ShowCaption = false;                fixed(Control1902205001)                {                    ShowCaption = false;                    group("Number of Lines")                    {                        Caption = 'Number of Lines';                        field(NumberOfJournalRecords; NumberOfRecords)                        {                            ApplicationArea = All;                            AutoFormatType = 1;                            ShowCaption = false;                            Editable = false;                            ToolTip = 'Specifies the number of lines in the current journal batch.';                        }                    }                    group("Account Name")                    {                        Caption = 'Account Name';                        Visible = false;                        field(AccName; AccName)                        {                            ApplicationArea = Basic, Suite;                            Editable = false;                            ShowCaption = false;                            ToolTip = 'Specifies the name of the account.';                        }                    }                    group("Bal. Account Name")                    {                        Caption = 'Bal. Account Name';                        Visible = false;                        field(BalAccName; BalAccName)                        {                            ApplicationArea = Basic, Suite;                            Caption = 'Bal. Account Name';                            Editable = false;                            ToolTip = 'Specifies the name of the balancing account that has been entered on the journal line.';                        }                    }                    group(Control1903866901)                    {                        Caption = 'Balance';                        field(Balance; Balance)                        {                            ApplicationArea = All;                            AutoFormatType = 1;                            AutoFormatExpression = '';                            Caption = 'Balance';                            Editable = false;                            ToolTip = 'Specifies the balance that has accumulated in the purchase journal on the line where the cursor is.';                            Visible = BalanceVisible;                        }                    }                    group("Total Balance")                    {                        Caption = 'Total Balance';                        field(TotalBalance; TotalBalance)                        {                            ApplicationArea = All;                            AutoFormatType = 1;                            AutoFormatExpression = '';                            Caption = 'Total Balance';                            Editable = false;                            ToolTip = 'Specifies the total balance in the purchase journal.';                            Visible = TotalBalanceVisible;                        }                    }                }            }        }        area(factboxes)        {            part(JournalErrorsFactBox; "Journal Errors FactBox")            {                ApplicationArea = Basic, Suite;                Visible = BackgroundErrorCheck;                SubPageLink = "Journal Template Name" = field("Journal Template Name"),                              "Journal Batch Name" = field("Journal Batch Name"),                              "Line No." = field("Line No.");            }            part(JournalLineDetails; "Journal Line Details FactBox")            {                ApplicationArea = Basic, Suite;                SubPageLink = "Journal Template Name" = field("Journal Template Name"),                              "Journal Batch Name" = field("Journal Batch Name"),                              "Line No." = field("Line No.");            }            part(Control1900919607; "Dimension Set Entries FactBox")            {                ApplicationArea = Basic, Suite;                SubPageLink = "Dimension Set ID" = field("Dimension Set ID");            }            part(IncomingDocAttachFactBox; "Incoming Doc. Attach. FactBox")            {                ApplicationArea = Basic, Suite;                ShowFilter = false;            }            part(WorkflowStatusBatch; "Workflow Status FactBox")            {                ApplicationArea = Suite;                Caption = 'Batch Workflows';                Editable = false;                Enabled = false;                ShowFilter = false;                Visible = ShowWorkflowStatusOnBatch;            }            part(WorkflowStatusLine; "Workflow Status FactBox")            {                ApplicationArea = Suite;                Caption = 'Line Workflows';                Editable = false;                Enabled = false;                ShowFilter = false;                Visible = ShowWorkflowStatusOnLine;            }            systempart(Control1900383207; Links)            {                ApplicationArea = RecordLinks;                Visible = false;            }            systempart(Control1905767507; Notes)            {                ApplicationArea = Notes;                Visible = false;            }        }    }    actions    {        area(navigation)        {            group("&Line")            {                Caption = '&Line';                Image = Line;                action(Dimensions)                {                    AccessByPermission = TableData Dimension = R;                    ApplicationArea = Dimensions;                    Caption = 'Dimensions';                    Image = Dimensions;                    ShortCutKey = 'Alt+D';                    ToolTip = 'View or edit dimensions, such as area, project, or department, that you can assign to sales and purchase documents to distribute costs and analyze transaction history.';                    trigger OnAction()                    begin                        Rec.ShowDimensions();                        CurrPage.SaveRecord();                    end;                }            }            group("A&ccount")            {                Caption = 'A&ccount';                Image = ChartOfAccounts;                action(Card)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Card';                    Image = EditLines;                    RunObject = Codeunit "Gen. Jnl.-Show Card";                    ShortCutKey = 'Shift+F7';                    ToolTip = 'View or change detailed information about the record on the document or journal line.';                }                action("Ledger E&ntries")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Ledger E&ntries';                    Image = GLRegisters;                    RunObject = Codeunit "Gen. Jnl.-Show Entries";                    ShortCutKey = 'Ctrl+F7';                    ToolTip = 'View the history of transactions that have been posted for the selected record.';                }            }        }        area(processing)        {            group("F&unctions")            {                Caption = 'F&unctions';                Image = "Action";                action("Renumber Document Numbers")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Renumber Document Numbers';                    Image = EditLines;                    ToolTip = 'Resort the numbers in the Document No. column to avoid posting errors because the document numbers are not in sequence. Entry applications and line groupings are preserved.';                    trigger OnAction()                    begin                        Rec.RenumberDocumentNo();                    end;                }                action("Apply Entries")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Apply Entries';                    Ellipsis = true;                    Enabled = ApplyEntriesActionEnabled;                    Image = ApplyEntries;                    RunObject = Codeunit "Gen. Jnl.-Apply";                    ShortCutKey = 'Shift+F11';                    ToolTip = 'Apply the payment amount on a journal line to a sales or purchase document that was already posted for a customer or vendor. This updates the amount on the posted document, and the document can either be partially paid, or closed as paid or refunded.';                }                action("Insert Conv. LCY Rndg. Lines")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Insert Conv. LCY Rndg. Lines';                    Image = InsertCurrency;                    RunObject = Codeunit "Adjust Gen. Journal Balance";                    ToolTip = 'Insert a rounding correction line in the journal. This rounding correction line will balance in LCY when amounts in the foreign currency also balance. You can then post the journal.';                }                action(DeferralSchedule)                {                    ApplicationArea = Suite;                    Caption = 'Deferral Schedule';                    Image = PaymentPeriod;                    ToolTip = 'View or edit the deferral schedule that governs how expenses or revenue are deferred to different accounting periods when the journal line is posted.';                    trigger OnAction()                    begin                        Rec.ShowDeferralSchedule();                    end;                }                group(IncomingDocument)                {                    Caption = 'Incoming Document';                    Image = Documents;                    action(IncomingDocCard)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'View Incoming Document';                        Enabled = HasIncomingDocument;                        Image = ViewOrder;                        ToolTip = 'View any incoming document records and file attachments that exist for the entry or document.';                        trigger OnAction()                        var                            IncomingDocument: Record "Incoming Document";                        begin                            IncomingDocument.ShowCardFromEntryNo(Rec."Incoming Document Entry No.");                        end;                    }                    action(SelectIncomingDoc)                    {                        AccessByPermission = TableData "Incoming Document" = R;                        ApplicationArea = Basic, Suite;                        Caption = 'Select Incoming Document';                        Image = SelectLineToApply;                        ToolTip = 'Select an incoming document record and file attachment that you want to link to the entry or document.';                        trigger OnAction()                        var                            IncomingDocument: Record "Incoming Document";                        begin                            Rec.Validate("Incoming Document Entry No.", IncomingDocument.SelectIncomingDocument(Rec."Incoming Document Entry No.", Rec.RecordId));                        end;                    }                    action(IncomingDocAttachFile)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'Create Incoming Document from File';                        Ellipsis = true;                        Enabled = not HasIncomingDocument;                        Image = Attach;                        ToolTip = 'Create an incoming document record by selecting a file to attach, and then link the incoming document record to the entry or document.';                        trigger OnAction()                        var                            IncomingDocumentAttachment: Record "Incoming Document Attachment";                        begin                            IncomingDocumentAttachment.NewAttachmentFromGenJnlLine(Rec);                        end;                    }                    action(RemoveIncomingDoc)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'Remove Incoming Document';                        Enabled = HasIncomingDocument;                        Image = RemoveLine;                        ToolTip = 'Remove any incoming document records and file attachments.';                        trigger OnAction()                        var                            IncomingDocument: Record "Incoming Document";                        begin                            if IncomingDocument.Get(Rec."Incoming Document Entry No.") then                                IncomingDocument.RemoveLinkToRelatedRecord();                            Rec."Incoming Document Entry No." := 0;                            Rec.Modify(true);                        end;                    }                }            }            group("P&osting")            {                Caption = 'P&osting';                Image = Post;                action(Reconcile)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Reconcile';                    Image = Reconcile;                    ShortCutKey = 'Ctrl+F11';                    ToolTip = 'View the balances on bank accounts that are marked for reconciliation, usually liquid accounts.';                    trigger OnAction()                    var                        GLReconciliation: Page Reconciliation;                    begin                        GLReconciliation.SetGenJnlLine(Rec);                        GLReconciliation.Run();                    end;                }                action("Test Report")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Test Report';                    Ellipsis = true;                    Image = TestReport;                    ToolTip = 'View a test report so that you can find and correct any errors before you perform the actual posting of the journal or document.';                    trigger OnAction()                    var                        TestReportPrint: Codeunit "Test Report-Print";                    begin                        TestReportPrint.PrintGenJnlLine(Rec);                    end;                }                action(Post)                {                    ApplicationArea = Basic, Suite;                    Caption = 'P&ost';                    Image = PostOrder;                    ShortCutKey = 'F9';                    ToolTip = 'Finalize the document or journal by posting the amounts and quantities to the related accounts in your company books.';                    trigger OnAction()                    begin                        Rec.SendToPosting(Codeunit::"Gen. Jnl.-Post");                        CurrentJnlBatchName := Rec.GetRangeMax("Journal Batch Name");                        SetJobQueueVisibility();                        CurrPage.Update(false);                    end;                }                action(Preview)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Preview Posting';                    Image = ViewPostedOrder;                    ShortCutKey = 'Ctrl+Alt+F9';                    ToolTip = 'Review the different types of entries that will be created when you post the document or journal.';                    trigger OnAction()                    var                        GenJnlPost: Codeunit "Gen. Jnl.-Post";                    begin                        GenJnlPost.Preview(Rec);                    end;                }                action("Post and &Print")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Post and &Print';                    Image = PostPrint;                    ShortCutKey = 'Shift+F9';                    ToolTip = 'Finalize and prepare to print the document or journal. The values and quantities are posted to the related accounts. A report request window where you can specify what to include on the print-out.';                    trigger OnAction()                    begin                        Rec.SendToPosting(Codeunit::"Gen. Jnl.-Post+Print");                        CurrentJnlBatchName := Rec.GetRangeMax("Journal Batch Name");                        SetJobQueueVisibility();                        CurrPage.Update(false);                    end;                }                action("Remove From Job Queue")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Remove From Job Queue';                    Image = RemoveLine;                    ToolTip = 'Remove the scheduled processing of this record from the job queue.';                    Visible = JobQueueVisible;                    trigger OnAction()                    begin                        Rec.CancelBackgroundPosting();                        SetJobQueueVisibility();                        CurrPage.Update(false);                    end;                }                action(RedistributeAccAllocations)                {                    ApplicationArea = All;                    Caption = 'Redistribute Account Allocations';                    Image = EditList;#pragma warning disable AA0219                    ToolTip = 'Use this action to redistribute the account allocations for this line.';#pragma warning restore AA0219                    trigger OnAction()                    var                        AllocAccManualOverride: Page "Redistribute Acc. Allocations";                    begin                        if (Rec."Account Type" <> Rec."Account Type"::"Allocation Account") and (Rec."Bal. Account Type" <> Rec."Bal. Account Type"::"Allocation Account") and (Rec."Selected Alloc. Account No." = '') then                            Error(ActionOnlyAllowedForAllocationAccountsErr);                        AllocAccManualOverride.SetParentSystemId(Rec.SystemId);                        AllocAccManualOverride.SetParentTableId(Database::"Gen. Journal Line");                        AllocAccManualOverride.RunModal();                    end;                }                action(ReplaceAllocationAccountWithLines)                {                    ApplicationArea = All;                    Caption = 'Generate lines from Allocation Account Line';                    Image = CreateLinesFromJob;#pragma warning disable AA0219                    ToolTip = 'Use this action to replace the Allocation Account line with the actual lines that would be generated from the line itself.';#pragma warning restore AA0219                    trigger OnAction()                    var                        BackupRec: Record "Gen. Journal Line";                        GenJournalAllocAccMgt: Codeunit "Gen. Journal Alloc. Acc. Mgt.";                    begin                        if (Rec."Account Type" <> Rec."Account Type"::"Allocation Account") and (Rec."Bal. Account Type" <> Rec."Bal. Account Type"::"Allocation Account") and (Rec."Selected Alloc. Account No." = '') then                            Error(ActionOnlyAllowedForAllocationAccountsErr);                        BackupRec.Copy(Rec);                        BackupRec.SetRecFilter();                        GenJournalAllocAccMgt.CreateLines(BackupRec);                        Rec.Delete();                        CurrPage.Update(false);                    end;                }            }            group("Page")            {                Caption = 'Page';                action(EditInExcel)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Edit in Excel';                    Image = Excel;                    ToolTip = 'Send the data in the journal to an Excel file for analysis or editing.';                    Visible = IsSaaSExcelAddinEnabled;                    AccessByPermission = System "Allow Action Export To Excel" = X;                    trigger OnAction()                    var                        ODataUtility: Codeunit ODataUtility;                    begin                        ODataUtility.EditJournalWorksheetInExcel(CurrPage.Caption, CurrPage.ObjectId(false), Rec."Journal Batch Name", Rec."Journal Template Name");                    end;                }                action(ClassicView)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Show more columns';                    Image = SetupColumns;                    ToolTip = 'Adds additional fields to the journal for a full view of the journal data.';                    Visible = IsSimplePage;                    trigger OnAction()                    begin                        // set journal preference for this page to be NOT simple mode (classic mode)                        CurrPage.Close();                        GenJnlManagement.SetJournalSimplePageModePreference(false, PAGE::"Purchase Journal");                        GenJnlManagement.SetLastViewedJournalBatchName(PAGE::"Purchase Journal", CurrentJnlBatchName);                        PAGE.Run(PAGE::"Purchase Journal");                    end;                }                action(SimpleView)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Show fewer columns';                    Image = SetupList;                    ToolTip = 'Hides many of the less used fields from the journal for better productivity. The fields are still there but not shown.';                    Visible = not IsSimplePage;                    trigger OnAction()                    begin                        // set journal preference for this page to be simple mode                        CheckOnChangeToSimpleView();                        CurrPage.Close();                        GenJnlManagement.SetJournalSimplePageModePreference(true, PAGE::"Purchase Journal");                        GenJnlManagement.SetLastViewedJournalBatchName(PAGE::"Purchase Journal", CurrentJnlBatchName);                        PAGE.Run(PAGE::"Purchase Journal");                    end;                }                group(Errors)                {                    Image = ErrorLog;                    Visible = BackgroundErrorCheck;                    action(ShowLinesWithErrors)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'Show Lines with Issues';                        Image = Error;                        Visible = BackgroundErrorCheck;                        Enabled = not ShowAllLinesEnabled;                        ToolTip = 'View a list of journal lines that have issues before you post the journal.';                        trigger OnAction()                        begin                            Rec.SwitchLinesWithErrorsFilter(ShowAllLinesEnabled);                        end;                    }                    action(ShowAllLines)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'Show All Lines';                        Image = ExpandAll;                        Visible = BackgroundErrorCheck;                        Enabled = ShowAllLinesEnabled;                        ToolTip = 'View all journal lines, including lines with and without issues.';                        trigger OnAction()                        begin                            Rec.SwitchLinesWithErrorsFilter(ShowAllLinesEnabled);                        end;                    }                }            }            group("Request Approval")            {                Caption = 'Request Approval';                group(SendApprovalRequest)                {                    Caption = 'Send Approval Request';                    Image = SendApprovalRequest;                    action(SendApprovalRequestJournalBatch)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'Journal Batch';                        Enabled = not OpenApprovalEntriesOnBatchOrAnyJnlLineExist and CanRequestFlowApprovalForBatchAndAllLines and EnabledGenJnlBatchWorkflowsExist;                        Image = SendApprovalRequest;                        ToolTip = 'Send all journal lines for approval, also those that you may not see because of filters.';                        trigger OnAction()                        var                            ApprovalsMgmt: Codeunit "Approvals Mgmt.";                        begin                            ApprovalsMgmt.TrySendJournalBatchApprovalRequest(Rec);                            SetControlAppearanceFromBatch();                            SetControlAppearance();                        end;                    }                    action(SendApprovalRequestJournalLine)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'Selected Journal Lines';                        Enabled = not OpenApprovalEntriesOnBatchOrCurrJnlLineExist and CanRequestFlowApprovalForBatchAndCurrentLine and EnabledGenJnlLineWorkflowsExist;                        Image = SendApprovalRequest;                        ToolTip = 'Send selected journal lines for approval.';                        trigger OnAction()                        var                            [SecurityFiltering(SecurityFilter::Filtered)]                            GenJournalLine: Record "Gen. Journal Line";                            ApprovalsMgmt: Codeunit "Approvals Mgmt.";                        begin                            GetCurrentlySelectedLines(GenJournalLine);                            ApprovalsMgmt.SendJournalLinesApprovalRequests(GenJournalLine);                            SetControlAppearanceFromBatch();                        end;                    }                }                group(CancelApprovalRequest)                {                    Caption = 'Cancel Approval Request';                    Image = Cancel;                    action(CancelApprovalRequestJournalBatch)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'Journal Batch';                        Enabled = CanCancelApprovalForJnlBatch or CanCancelFlowApprovalForBatch;                        Image = CancelApprovalRequest;                        ToolTip = 'Cancel sending all journal lines for approval, also those that you may not see because of filters.';                        trigger OnAction()                        var                            ApprovalsMgmt: Codeunit "Approvals Mgmt.";                        begin                            ApprovalsMgmt.TryCancelJournalBatchApprovalRequest(Rec);                            SetControlAppearance();                            SetControlAppearanceFromBatch();                        end;                    }                    action(CancelApprovalRequestJournalLine)                    {                        ApplicationArea = Basic, Suite;                        Caption = 'Selected Journal Lines';                        Enabled = CanCancelApprovalForJnlLine or CanCancelFlowApprovalForLine;                        Image = CancelApprovalRequest;                        ToolTip = 'Cancel sending selected journal lines for approval.';                        trigger OnAction()                        var                            [SecurityFiltering(SecurityFilter::Filtered)]                            GenJournalLine: Record "Gen. Journal Line";                            ApprovalsMgmt: Codeunit "Approvals Mgmt.";                        begin                            GetCurrentlySelectedLines(GenJournalLine);                            ApprovalsMgmt.TryCancelJournalLineApprovalRequests(GenJournalLine);                        end;                    }                }            }            group(Approval)            {                Caption = 'Approval';                action(Approve)                {                    ApplicationArea = All;                    Caption = 'Approve';                    Image = Approve;                    ToolTip = 'Approve the requested changes.';                    Visible = OpenApprovalEntriesExistForCurrUser;                    trigger OnAction()                    var                        ApprovalsMgmt: Codeunit "Approvals Mgmt.";                    begin                        ApprovalsMgmt.ApproveGenJournalLineRequest(Rec);                    end;                }                action(Reject)                {                    ApplicationArea = All;                    Caption = 'Reject';                    Image = Reject;                    ToolTip = 'Reject the approval request.';                    Visible = OpenApprovalEntriesExistForCurrUser;                    trigger OnAction()                    var                        ApprovalsMgmt: Codeunit "Approvals Mgmt.";                    begin                        ApprovalsMgmt.RejectGenJournalLineRequest(Rec);                    end;                }                action(Delegate)                {                    ApplicationArea = All;                    Caption = 'Delegate';                    Image = Delegate;                    ToolTip = 'Delegate the approval to a substitute approver.';                    Visible = OpenApprovalEntriesExistForCurrUser;                    trigger OnAction()                    var                        ApprovalsMgmt: Codeunit "Approvals Mgmt.";                    begin                        ApprovalsMgmt.DelegateGenJournalLineRequest(Rec);                    end;                }                action(Comments)                {                    ApplicationArea = All;                    Caption = 'Comments';                    Image = ViewComments;                    ToolTip = 'View or add comments for the record.';                    Visible = OpenApprovalEntriesExistForCurrUser or ApprovalEntriesExistSentByCurrentUser;                    trigger OnAction()                    var                        GenJournalBatch: Record "Gen. Journal Batch";                        ApprovalsMgmt: Codeunit "Approvals Mgmt.";                    begin                        if OpenApprovalEntriesOnJnlLineExist then                            ApprovalsMgmt.GetApprovalComment(Rec)                        else                            if OpenApprovalEntriesOnJnlBatchExist then                                if GenJournalBatch.Get(Rec."Journal Template Name", Rec."Journal Batch Name") then                                    ApprovalsMgmt.GetApprovalComment(GenJournalBatch);                    end;                }            }        }        area(Promoted)        {            group(Category_Process)            {                Caption = 'Process', Comment = 'Generated from the PromotedActionCategories property index 1.';                group(Category_Category5)                {                    Caption = 'Post/Print', Comment = 'Generated from the PromotedActionCategories property index 4.';                    ShowAs = SplitButton;                    actionref(Post_Promoted; Post)                    {                    }                    actionref(Preview_Promoted; Preview)                    {                    }                    actionref("Post and &Print_Promoted"; "Post and &Print")                    {                    }                    actionref("Test Report_Promoted"; "Test Report")                    {                    }                }                actionref("Renumber Document Numbers_Promoted"; "Renumber Document Numbers")                {                }                actionref(Reconcile_Promoted; Reconcile)                {                }                actionref("Apply Entries_Promoted"; "Apply Entries")                {                }            }            group(Category_Category8)            {                Caption = 'Approve', Comment = 'Generated from the PromotedActionCategories property index 7.';                actionref(Approve_Promoted; Approve)                {                }                actionref(Reject_Promoted; Reject)                {                }                actionref(Comments_Promoted; Comments)                {                }                actionref(Delegate_Promoted; Delegate)                {                }            }            group("Category_Request Approval")            {                Caption = 'Request Approval';                group("Category_Send Approval Request")                {                    Caption = 'Send Approval Request';                    actionref(SendApprovalRequestJournalBatch_Promoted; SendApprovalRequestJournalBatch)                    {                    }                    actionref(SendApprovalRequestJournalLine_Promoted; SendApprovalRequestJournalLine)                    {                    }                }                group("Category_Cancel Approval Request")                {                    Caption = 'Cancel Approval Request';                    actionref(CancelApprovalRequestJournalBatch_Promoted; CancelApprovalRequestJournalBatch)                    {                    }                    actionref(CancelApprovalRequestJournalLine_Promoted; CancelApprovalRequestJournalLine)                    {                    }                }            }            group(Category_Category6)            {                Caption = 'Line', Comment = 'Generated from the PromotedActionCategories property index 5.';                actionref(Dimensions_Promoted; Dimensions)                {                }            }            group(Category_Category7)            {                Caption = 'Account', Comment = 'Generated from the PromotedActionCategories property index 6.';            }            group("Category_Incoming Document")            {                Caption = 'Incoming Document';                actionref(IncomingDocAttachFile_Promoted; IncomingDocAttachFile)                {                }                actionref(SelectIncomingDoc_Promoted; SelectIncomingDoc)                {                }                actionref(RemoveIncomingDoc_Promoted; RemoveIncomingDoc)                {                }                actionref(IncomingDocCard_Promoted; IncomingDocCard)                {                }            }            group(Category_Category4)            {                Caption = 'Page', Comment = 'Generated from the PromotedActionCategories property index 3.';                actionref(SimpleView_Promoted; SimpleView)                {                }                actionref(ClassicView_Promoted; ClassicView)                {                }                actionref(EditInExcel_Promoted; EditInExcel)                {                }                actionref(ShowLinesWithErrors_Promoted; ShowLinesWithErrors)                {                }                actionref(ShowAllLines_Promoted; ShowAllLines)                {                }            }            group(Category_Report)            {                Caption = 'Report', Comment = 'Generated from the PromotedActionCategories property index 2.';            }        }    }    trigger OnAfterGetCurrRecord()    begin        HasIncomingDocument := Rec."Incoming Document Entry No." <> 0;        GenJnlManagement.GetAccounts(Rec, AccName, BalAccName);        UpdateBalance();        EnableApplyEntriesAction();        SetControlAppearance();        SetApprovalStateForBatch();        CurrPage.IncomingDocAttachFactBox.PAGE.LoadDataFromRecord(Rec);        SetJobQueueVisibility();        ApprovalMgmt.GetGenJnlBatchApprovalStatus(Rec, GenJnlBatchApprovalStatus, EnabledGenJnlBatchWorkflowsExist);    end;    trigger OnAfterGetRecord()    begin        Rec.ShowShortcutDimCode(ShortcutDimCode);        DocumentAmount := Abs(Rec.Amount);        GenJnlManagement.GetAccounts(Rec, AccName, BalAccName);        CurrPage.IncomingDocAttachFactBox.PAGE.SetCurrentRecordID(Rec.RecordId());        ApprovalMgmt.GetGenJnlLineApprovalStatus(Rec, GenJnlLineApprovalStatus, EnabledGenJnlLineWorkflowsExist);    end;    trigger OnInit()    begin        TotalBalanceVisible := true;        BalanceVisible := true;        AmountVisible := true;        // Get simple / classic mode for this page except when called from a webservices (SOAP or ODATA)        if ClientTypeManagement.GetCurrentClientType() in [CLIENTTYPE::SOAP, CLIENTTYPE::OData, CLIENTTYPE::ODataV4]        then            IsSimplePage := false        else            IsSimplePage := GenJnlManagement.GetJournalSimplePageModePreference(PAGE::"Purchase Journal");        GeneralLedgerSetup.GetRecordOnce();        PurchasesPayablesSetup.GetRecordOnce();        SetJobQueueVisibility();    end;    trigger OnInsertRecord(BelowxRec: Boolean): Boolean    begin        CurrPage.IncomingDocAttachFactBox.PAGE.SetCurrentRecordID(Rec.RecordId);    end;    trigger OnNewRecord(BelowxRec: Boolean)    begin        UpdateBalance();        EnableApplyEntriesAction();        Rec.SetUpNewLine(xRec, Balance, BelowxRec);        Clear(DocumentAmount);        // Setting account type to Vendor and doc type to invoice on new line when in simple page mode        if IsSimplePage then begin            Rec.Validate("Account Type", Rec."Account Type"::Vendor);            Rec.Validate("Document Type", Rec."Document Type"::Invoice);        end;        Clear(ShortcutDimCode);        Clear(GenJnlLineApprovalStatus);    end;    trigger OnOpenPage()    var        AllocationAccountMgt: Codeunit "Allocation Account Mgt.";        ServerSetting: Codeunit "Server Setting";        VATReportingDateMgt: Codeunit "VAT Reporting Date Mgt";        LastGenJnlBatch: Code[10];    begin        IsSaaSExcelAddinEnabled := ServerSetting.GetIsSaasExcelAddinEnabled();        VATDateEnabled := VATReportingDateMgt.IsVATDateEnabled();        UseAllocationAccountNumber := AllocationAccountMgt.UseAllocationAccountNoField();        if ClientTypeManagement.GetCurrentClientType() = CLIENTTYPE::ODataV4 then            exit;        SetControlVisibility();        SetDimensionsVisibility();        BalAccName := '';        if OpenJournalFromBatch() then            exit;        SelectTemplate();        LastGenJnlBatch := GenJnlManagement.GetLastViewedJournalBatchName(PAGE::"Purchase Journal");        if LastGenJnlBatch <> '' then            CurrentJnlBatchName := LastGenJnlBatch;        GenJnlManagement.OpenJnl(CurrentJnlBatchName, Rec);        OnOpenPageOnAfterOpenJnl(CurrentJnlBatchName);        SetControlAppearanceFromBatch();    end;    trigger OnModifyRecord(): Boolean    begin        ApprovalMgmt.CleanGenJournalApprovalStatus(Rec, GenJnlBatchApprovalStatus, GenJnlLineApprovalStatus);    end;    var        GeneralLedgerSetup: Record "General Ledger Setup";        PurchasesPayablesSetup: Record "Purchases & Payables Setup";        GenJnlManagement: Codeunit GenJnlManagement;        ClientTypeManagement: Codeunit "Client Type Management";        JournalErrorsMgt: Codeunit "Journal Errors Mgt.";        BackgroundErrorHandlingMgt: Codeunit "Background Error Handling Mgt.";        ApprovalMgmt: Codeunit "Approvals Mgmt.";        ChangeExchangeRate: Page "Change Exchange Rate";        GenJnlBatchApprovalStatus: Text[20];        GenJnlLineApprovalStatus: Text[20];        Balance: Decimal;        TotalBalance: Decimal;        NumberOfRecords: Integer;        ShowBalance: Boolean;        ShowTotalBalance: Boolean;        HasIncomingDocument: Boolean;        ApplyEntriesActionEnabled: Boolean;        BalanceVisible: Boolean;        TotalBalanceVisible: Boolean;        IsPostingGroupEditable: Boolean;        AmountVisible: Boolean;        DebitCreditVisible: Boolean;        IsSaaSExcelAddinEnabled: Boolean;        NegativeDocAmountErr: Label 'You must specify a positive amount as the document amount. If the journal line is for a document type that has a negative amount, the amount will be tracked correctly.';        ActionOnlyAllowedForAllocationAccountsErr: Label 'This action is only available for lines that have Allocation Account set as Account Type or Balancing Account Type.';        UseAllocationAccountNumber: Boolean;        JobQueuesUsed: Boolean;        JobQueueVisible: Boolean;        BackgroundErrorCheck: Boolean;        ShowAllLinesEnabled: Boolean;        VATDateEnabled: Boolean;        OpenApprovalEntriesOnBatchOrAnyJnlLineExist: Boolean;        ShowWorkflowStatusOnBatch: Boolean;        ShowWorkflowStatusOnLine: Boolean;        EnabledGenJnlLineWorkflowsExist: Boolean;        EnabledGenJnlBatchWorkflowsExist: Boolean;        CanRequestFlowApprovalForBatchAndAllLines: Boolean;        CanRequestFlowApprovalForBatchAndCurrentLine: Boolean;        OpenApprovalEntriesOnBatchOrCurrJnlLineExist: Boolean;        OpenApprovalEntriesOnJnlBatchExist: Boolean;        CanRequestFlowApprovalForBatch: Boolean;        CanCancelApprovalForJnlBatch: Boolean;        CanCancelFlowApprovalForBatch: Boolean;        CanCancelApprovalForJnlLine: Boolean;        CanCancelFlowApprovalForLine: Boolean;        OpenApprovalEntriesExistForCurrUser: Boolean;        ApprovalEntriesExistSentByCurrentUser: Boolean;        OpenApprovalEntriesOnJnlLineExist: Boolean;    protected var        ShortcutDimCode: array[8] of Code[20];        AccName: Text[100];        BalAccName: Text[100];        DimVisible1: Boolean;        DimVisible2: Boolean;        DimVisible3: Boolean;        DimVisible4: Boolean;        DimVisible5: Boolean;        DimVisible6: Boolean;        DimVisible7: Boolean;        DimVisible8: Boolean;        IsSimplePage: Boolean;        CurrentJnlBatchName: Code[10];        DocumentAmount: Decimal;    local procedure UpdateBalance()    begin        GenJnlManagement.CalcBalance(          Rec, xRec, Balance, TotalBalance, ShowBalance, ShowTotalBalance);        BalanceVisible := ShowBalance;        TotalBalanceVisible := ShowTotalBalance;        if ShowTotalBalance then            NumberOfRecords := Rec.Count();    end;    local procedure GetVendorName(): Text[100]    begin        if (Rec."Account Type" = Rec."Account Type"::Vendor) and (AccName <> '') then            exit(AccName);        exit('');    end;    local procedure EnableApplyEntriesAction()    begin        ApplyEntriesActionEnabled :=          (Rec."Account Type" in [Rec."Account Type"::Customer, Rec."Account Type"::Vendor]) or          (Rec."Bal. Account Type" in [Rec."Bal. Account Type"::Customer, Rec."Bal. Account Type"::Vendor]);    end;    local procedure CurrentJnlBatchNameOnAfterVali()    begin        CurrPage.SaveRecord();        GenJnlManagement.SetName(CurrentJnlBatchName, Rec);        SetControlAppearanceFromBatch();        CurrPage.Update(false);    end;    local procedure SetControlVisibility()    begin        // Hide amount when open in simple page mode.        if IsSimplePage then begin            AmountVisible := false;            DebitCreditVisible := false;        end else begin            GeneralLedgerSetup.GetRecordOnce();            AmountVisible := not (GeneralLedgerSetup."Show Amounts" = GeneralLedgerSetup."Show Amounts"::"Debit/Credit Only");            DebitCreditVisible := not (GeneralLedgerSetup."Show Amounts" = GeneralLedgerSetup."Show Amounts"::"Amount Only");        end;        PurchasesPayablesSetup.GetRecordOnce();        IsPostingGroupEditable := PurchasesPayablesSetup."Allow Multiple Posting Groups";    end;    local procedure SetDimensionsVisibility()    var        DimensionManagement: Codeunit DimensionManagement;    begin        DimVisible1 := false;        DimVisible2 := false;        DimVisible3 := false;        DimVisible4 := false;        DimVisible5 := false;        DimVisible6 := false;        DimVisible7 := false;        DimVisible8 := false;        if not IsSimplePage then            DimensionManagement.UseShortcutDims(              DimVisible1, DimVisible2, DimVisible3, DimVisible4, DimVisible5, DimVisible6, DimVisible7, DimVisible8);        Clear(DimensionManagement);    end;    local procedure CheckOnChangeToSimpleView()    var        GenJournalLineCheck: Record "Gen. Journal Line";    begin        GenJournalLineCheck.Copy(Rec);        GenJournalLineCheck.SetFilter("Account Type", '<>%1', GenJournalLineCheck."Account Type"::Vendor);        if GenJournalLineCheck.FindFirst() then            GenJournalLineCheck.TestField("Account Type", GenJournalLineCheck."Account Type"::Vendor);    end;    local procedure SetControlAppearanceFromBatch()    begin        SetApprovalStateForBatch();        BackgroundErrorCheck := BackgroundErrorHandlingMgt.BackgroundValidationFeatureEnabled();        ShowAllLinesEnabled := true;        Rec.SwitchLinesWithErrorsFilter(ShowAllLinesEnabled);        JournalErrorsMgt.SetFullBatchCheck(true);    end;    local procedure SetApprovalStateForBatch()    var        GenJournalBatch: Record "Gen. Journal Batch";    begin        if ClientTypeManagement.GetCurrentClientType() = CLIENTTYPE::ODataV4 then            exit;        if not GenJournalBatch.Get(Rec.GetRangeMax("Journal Template Name"), CurrentJnlBatchName) then            exit;        ShowWorkflowStatusOnBatch := CurrPage.WorkflowStatusBatch.PAGE.SetFilterOnWorkflowRecord(GenJournalBatch.RecordId);        SetApprovalStateForBatch(GenJournalBatch, Rec, OpenApprovalEntriesExistForCurrUser, OpenApprovalEntriesOnJnlBatchExist, OpenApprovalEntriesOnBatchOrAnyJnlLineExist, CanCancelApprovalForJnlBatch, CanRequestFlowApprovalForBatch, CanCancelFlowApprovalForBatch, CanRequestFlowApprovalForBatchAndAllLines, ApprovalEntriesExistSentByCurrentUser, EnabledGenJnlBatchWorkflowsExist, EnabledGenJnlLineWorkflowsExist);    end;    local procedure OpenJournalFromBatch() Result: Boolean    var        IsHandled: Boolean;    begin        IsHandled := false;        OnBeforeOpenJournalFromBatch(Rec, Result, IsHandled);        if IsHandled then            exit(Result);        if Rec.IsOpenedFromBatch() then begin            CurrentJnlBatchName := Rec."Journal Batch Name";            GenJnlManagement.OpenJnl(CurrentJnlBatchName, Rec);            SetControlAppearanceFromBatch();            exit(true);        end;    end;    /// <summary>    /// Sets the current journal batch name for the purchase journal page.    /// Used to control which batch is currently active and displayed in the purchase journal.    /// </summary>    /// <param name="NewCurrentJnlBatchName">The journal batch name to set as current.</param>    procedure SetCurrentJnlBatchName(NewCurrentJnlBatchName: Code[10])    begin        CurrentJnlBatchName := NewCurrentJnlBatchName;    end;    /// <summary>    /// Gets the current journal batch name for the purchase journal page.    /// Returns the name of the journal batch currently active and displayed.    /// </summary>    /// <returns>The current journal batch name code.</returns>    procedure GetCurrentJnlBatchName(): Code[10]    begin        exit(CurrentJnlBatchName);    end;    local procedure SelectTemplate()    var        JnlSelected: Boolean;        IsHandled: Boolean;    begin        IsHandled := false;        OnBeforeSelectTemplate(Rec, GenJnlManagement, IsHandled);        if IsHandled then            exit;        GenJnlManagement.TemplateSelection(PAGE::"Purchase Journal", Enum::"Gen. Journal Template Type"::Purchases, false, Rec, JnlSelected);        if not JnlSelected then            Error('');    end;    local procedure GetCurrentlySelectedLines(var GenJournalLine: Record "Gen. Journal Line"): Boolean    begin        CurrPage.SetSelectionFilter(GenJournalLine);        exit(GenJournalLine.FindSet());    end;    local procedure SetControlAppearance()    begin        SetApprovalState(Rec.RecordId, OpenApprovalEntriesOnJnlBatchExist, CanRequestFlowApprovalForBatch, CanCancelFlowApprovalForLine, OpenApprovalEntriesExistForCurrUser, OpenApprovalEntriesOnJnlLineExist, OpenApprovalEntriesOnBatchOrCurrJnlLineExist, CanCancelApprovalForJnlLine, CanRequestFlowApprovalForBatchAndCurrentLine);        ShowWorkflowStatusOnLine := CurrPage.WorkflowStatusLine.PAGE.SetFilterOnWorkflowRecord(Rec.RecordId);    end;    internal procedure SetApprovalState(RecordId: RecordId; OpenApprovalEntriesOnJournalBatchExist: Boolean; LocalCanRequestFlowApprovalForBatch: Boolean; var LocalCanCancelFlowApprovalForLine: Boolean; var OpenApprovalEntriesExistForCurrentUser: Boolean; var OpenApprovalEntriesOnJournalLineExist: Boolean; var OpenApprovalEntriesOnBatchOrCurrentJournalLineExist: Boolean; var CanCancelApprovalForJournalLine: Boolean; var LocalCanRequestFlowApprovalForBatchAndCurrentLine: Boolean)    var        ApprovalsMgmt: Codeunit "Approvals Mgmt.";        WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";        CanRequestFlowApprovalForLine: Boolean;    begin        OpenApprovalEntriesExistForCurrentUser := OpenApprovalEntriesExistForCurrentUser or ApprovalsMgmt.HasOpenApprovalEntriesForCurrentUser(RecordId);        OpenApprovalEntriesOnJournalLineExist := ApprovalsMgmt.HasOpenApprovalEntries(RecordId);        OpenApprovalEntriesOnBatchOrCurrentJournalLineExist := OpenApprovalEntriesOnJournalBatchExist or OpenApprovalEntriesOnJournalLineExist;        CanCancelApprovalForJournalLine := ApprovalsMgmt.CanCancelApprovalForRecord(RecordId);        WorkflowWebhookManagement.GetCanRequestAndCanCancel(RecordId, CanRequestFlowApprovalForLine, LocalCanCancelFlowApprovalForLine);        LocalCanRequestFlowApprovalForBatchAndCurrentLine := LocalCanRequestFlowApprovalForBatch and CanRequestFlowApprovalForLine;    end;    internal procedure SetApprovalStateForBatch(GenJournalBatch: Record "Gen. Journal Batch"; GenJournalLine: Record "Gen. Journal Line"; var OpenApprovalEntriesExistForCurrentUser: Boolean; var OpenApprovalEntriesOnJournalBatchExist: Boolean; var OpenApprovalEntriesOnBatchOrAnyJournalLineExist: Boolean; var CanCancelApprovalForJournalBatch: Boolean; var LocalCanRequestFlowApprovalForBatch: Boolean; var LocalCanCancelFlowApprovalForBatch: Boolean; var LocalCanRequestFlowApprovalForBatchAndAllLines: Boolean; var LocalApprovalEntriesExistSentByCurrentUser: Boolean; var EnabledGeneralJournalBatchWorkflowsExist: Boolean; var EnabledGeneralJournalLineWorkflowsExist: Boolean)    var        ApprovalsMgmt: Codeunit "Approvals Mgmt.";        WorkflowWebhookManagement: Codeunit "Workflow Webhook Management";        WorkflowEventHandling: Codeunit "Workflow Event Handling";        WorkflowManagement: Codeunit "Workflow Management";        CanRequestFlowApprovalForAllLines: Boolean;    begin        OpenApprovalEntriesExistForCurrentUser := OpenApprovalEntriesExistForCurrentUser or ApprovalsMgmt.HasOpenApprovalEntriesForCurrentUser(GenJournalBatch.RecordId);        OpenApprovalEntriesOnJournalBatchExist := ApprovalsMgmt.HasOpenApprovalEntries(GenJournalBatch.RecordId);        OpenApprovalEntriesOnBatchOrAnyJournalLineExist := OpenApprovalEntriesOnJournalBatchExist or ApprovalsMgmt.HasAnyOpenJournalLineApprovalEntries(GenJournalLine."Journal Template Name", GenJournalLine."Journal Batch Name");        CanCancelApprovalForJournalBatch := ApprovalsMgmt.CanCancelApprovalForRecord(GenJournalBatch.RecordId);        WorkflowWebhookManagement.GetCanRequestAndCanCancelJournalBatch(GenJournalBatch, LocalCanRequestFlowApprovalForBatch, LocalCanCancelFlowApprovalForBatch, CanRequestFlowApprovalForAllLines);        LocalCanRequestFlowApprovalForBatchAndAllLines := LocalCanRequestFlowApprovalForBatch and CanRequestFlowApprovalForAllLines;        LocalApprovalEntriesExistSentByCurrentUser := ApprovalsMgmt.HasApprovalEntriesSentByCurrentUser(GenJournalBatch.RecordId) or ApprovalsMgmt.HasApprovalEntriesSentByCurrentUser(Rec.RecordId);        EnabledGeneralJournalLineWorkflowsExist := WorkflowManagement.EnabledWorkflowExist(DATABASE::"Gen. Journal Line", WorkflowEventHandling.RunWorkflowOnSendGeneralJournalLineForApprovalCode());        EnabledGeneralJournalBatchWorkflowsExist := WorkflowManagement.EnabledWorkflowExist(DATABASE::"Gen. Journal Batch", WorkflowEventHandling.RunWorkflowOnSendGeneralJournalBatchForApprovalCode());    end;    local procedure SetJobQueueVisibility()    begin        JobQueueVisible := Rec."Job Queue Status" = Rec."Job Queue Status"::"Scheduled for Posting";        JobQueuesUsed := GeneralLedgerSetup.JobQueueActive();    end;    /// <summary>    /// Integration event that occurs after validating shortcut dimension codes in the purchase journal.    /// Allows custom processing of dimension validation for purchase journal entries.    /// </summary>    /// <param name="GenJournalLine">The journal line being validated for dimension codes.</param>    /// <param name="ShortcutDimCode">Array of shortcut dimension codes being validated.</param>    /// <param name="DimIndex">Index of the dimension code being validated (1-8).</param>    [IntegrationEvent(false, false)]    local procedure OnAfterValidateShortcutDimCode(var GenJournalLine: Record "Gen. Journal Line"; var ShortcutDimCode: array[8] of Code[20]; DimIndex: Integer)    begin    end;    /// <summary>    /// Integration event that occurs before opening a journal from a batch in the purchase journal.    /// Allows custom handling of journal opening operations and result override.    /// </summary>    /// <param name="GenJournalLine">The journal line context for opening the journal.</param>    /// <param name="Result">Boolean result that can be modified to override the opening operation.</param>    /// <param name="IsHandled">Set to true to skip standard journal opening processing.</param>    [IntegrationEvent(true, false)]    local procedure OnBeforeOpenJournalFromBatch(var GenJournalLine: Record "Gen. Journal Line"; var Result: Boolean; var IsHandled: Boolean)    begin    end;    /// <summary>    /// Integration event that occurs before selecting a journal template in the purchase journal.    /// Allows custom template selection logic and override of standard template selection.    /// </summary>    /// <param name="GenJournalLine">The journal line providing context for template selection.</param>    /// <param name="GenJnlManagement">General journal management codeunit for template operations.</param>    /// <param name="IsHandled">Set to true to skip standard template selection processing.</param>    [IntegrationEvent(true, false)]    local procedure OnBeforeSelectTemplate(var GenJournalLine: Record "Gen. Journal Line"; var GenJnlManagement: Codeunit GenJnlManagement; var IsHandled: Boolean)    begin    end;    /// <summary>    /// Integration event that occurs after opening the journal during page opening for the purchase journal.    /// Allows custom processing after journal initialization and batch selection.    /// </summary>    /// <param name="CurrentJnlBatchName">The current journal batch name after opening the journal.</param>    [IntegrationEvent(true, false)]    local procedure OnOpenPageOnAfterOpenJnl(var CurrentJnlBatchName: Code[10])    begin    end;}