Page 5934 Service Invoice Subform

Base Application, Microsoft.Service.Document

src/Layers/W1/BaseApp/Service/Document/ServiceInvoiceSubform.Page.al749 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.Service.Document;using Microsoft.Finance.Dimension;using Microsoft.Foundation.Attachment;using Microsoft.Foundation.ExtendedText;using Microsoft.Inventory.Availability;using Microsoft.Inventory.Item;using Microsoft.Inventory.Item.Catalog;using Microsoft.Inventory.Location;using Microsoft.Pricing.Calculation;using Microsoft.Sales.Pricing;using Microsoft.Utilities;page 5934 "Service Invoice Subform"{    AutoSplitKey = true;    Caption = 'Lines';    DelayedInsert = true;    LinksAllowed = false;    MultipleNewLines = true;    PageType = ListPart;    SourceTable = "Service Line";    SourceTableView = where("Document Type" = filter(Invoice));    layout    {        area(content)        {            repeater(Control1)            {                ShowCaption = false;                field(Type; Rec.Type)                {                    ApplicationArea = Service;                    trigger OnValidate()                    begin                        NoOnAfterValidate();                    end;                }                field("No."; Rec."No.")                {                    ApplicationArea = Service;                    trigger OnValidate()                    var                        Item: Record "Item";                    begin                        Rec.ShowShortcutDimCode(ShortcutDimCode);                        NoOnAfterValidate();                        if Rec."Variant Code" = '' then                            VariantCodeMandatory := Item.IsVariantMandatory(Rec.Type = Rec.Type::Item, Rec."No.");                    end;                }                field("Item Reference No."; Rec."Item Reference No.")                {                    AccessByPermission = tabledata "Item Reference" = R;                    ApplicationArea = Service, ItemReferences;                    QuickEntry = false;                    Visible = ItemReferenceVisible;                    trigger OnLookup(var Text: Text): Boolean                    var                        ServItemReferenceMgt: Codeunit "Serv. Item Reference Mgt.";                    begin                        ServItemReferenceMgt.ServiceReferenceNoLookup(Rec);                        NoOnAfterValidate();                        CurrPage.Update();                    end;                }                field("Variant Code"; Rec."Variant Code")                {                    ApplicationArea = Planning;                    Visible = false;                    ShowMandatory = VariantCodeMandatory;                    trigger OnValidate()                    var                        Item: Record "Item";                    begin                        if Rec."Variant Code" = '' then                            VariantCodeMandatory := Item.IsVariantMandatory(Rec.Type = Rec.Type::Item, Rec."No.");                    end;                }                field(Nonstock; Rec.Nonstock)                {                    ApplicationArea = Service;                    Visible = false;                }                field("Gen. Bus. Posting Group"; Rec."Gen. Bus. Posting Group")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Gen. Prod. Posting Group"; Rec."Gen. Prod. Posting Group")                {                    ApplicationArea = Service;                    Visible = false;                }                field("VAT Bus. Posting Group"; Rec."VAT Bus. Posting Group")                {                    ApplicationArea = Service;                    Visible = false;                }                field("VAT Prod. Posting Group"; Rec."VAT Prod. Posting Group")                {                    ApplicationArea = Service;                    Visible = false;                }                field(Description; Rec.Description)                {                    ApplicationArea = Service;                }                field("Description 2"; Rec."Description 2")                {                    ApplicationArea = Service;                    Importance = Additional;                    Visible = false;                }                field("Return Reason Code"; Rec."Return Reason Code")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Location Code"; Rec."Location Code")                {                    ApplicationArea = Location;                }                field("Bin Code"; Rec."Bin Code")                {                    ApplicationArea = Warehouse;                    Visible = false;                }                field(Quantity; Rec.Quantity)                {                    ApplicationArea = Service;                    BlankZero = true;                    trigger OnValidate()                    begin                        QuantityOnAfterValidate();                    end;                }                field("Unit of Measure Code"; Rec."Unit of Measure Code")                {                    ApplicationArea = Service;                    trigger OnValidate()                    begin                        UnitofMeasureCodeOnAfterValidate();                    end;                }                field("Unit of Measure"; Rec."Unit of Measure")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Unit Cost (LCY)"; Rec."Unit Cost (LCY)")                {                    ApplicationArea = Service;                    ToolTip = 'Specifies the cost, in LCY, of one unit of the item or resource on the line.';                    Visible = false;                }                field("Unit Price"; Rec."Unit Price")                {                    ApplicationArea = Service;                    BlankZero = true;                }                field("Tax Liable"; Rec."Tax Liable")                {                    ApplicationArea = SalesTax;                    Editable = false;                    Visible = false;                }                field("Tax Area Code"; Rec."Tax Area Code")                {                    ApplicationArea = SalesTax;                    Visible = false;                }                field("Tax Group Code"; Rec."Tax Group Code")                {                    ApplicationArea = SalesTax;                    ShowMandatory = Rec."Tax Area Code" <> '';                }                field("Line Discount %"; Rec."Line Discount %")                {                    ApplicationArea = Service;                    BlankZero = true;                }                field("Line Amount"; Rec."Line Amount")                {                    ApplicationArea = Service;                    BlankZero = true;                }                field("Line Discount Amount"; Rec."Line Discount Amount")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Allow Invoice Disc."; Rec."Allow Invoice Disc.")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Inv. Discount Amount"; Rec."Inv. Discount Amount")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Serv. Price Adjmt. Gr. Code"; Rec."Serv. Price Adjmt. Gr. Code")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Contract No."; Rec."Contract No.")                {                    ApplicationArea = Service;                }                field("Service Item No."; Rec."Service Item No.")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Service Item Serial No."; Rec."Service Item Serial No.")                {                    ApplicationArea = Service;                    ToolTip = 'Specifies the serial number of the service item to which this service line is linked.';                    Visible = false;                }                field("Appl.-to Service Entry"; Rec."Appl.-to Service Entry")                {                    ApplicationArea = Service;                    Visible = true;                }                field("Work Type Code"; Rec."Work Type Code")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Appl.-to Item Entry"; Rec."Appl.-to Item Entry")                {                    ApplicationArea = Service;                    Visible = false;                }                field("Shortcut Dimension 1 Code"; Rec."Shortcut Dimension 1 Code")                {                    ApplicationArea = Dimensions;                    Visible = DimVisible1;                }                field("Shortcut Dimension 2 Code"; Rec."Shortcut Dimension 2 Code")                {                    ApplicationArea = Dimensions;                    Visible = DimVisible2;                }                field("ShortcutDimCode[3]"; 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]);                    end;                }                field("ShortcutDimCode[4]"; 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]);                    end;                }                field("ShortcutDimCode[5]"; 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]);                    end;                }                field("ShortcutDimCode[6]"; 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]);                    end;                }                field("ShortcutDimCode[7]"; 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]);                    end;                }                field("ShortcutDimCode[8]"; 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]);                    end;                }            }        }    }    actions    {        area(processing)        {            action(SelectMultiItems)            {                AccessByPermission = TableData Item = R;                ApplicationArea = Service;                Caption = 'Select items';                Ellipsis = true;                Image = NewItem;                ToolTip = 'Add two or more items from the full list of available items.';                trigger OnAction()                begin                    Rec.SelectMultipleItems();                end;            }            group("F&unctions")            {                Caption = 'F&unctions';                Image = "Action";                action("Get &Price")                {                    ApplicationArea = Service;                    Caption = 'Get &Price';                    Ellipsis = true;                    Image = Price;                    ToolTip = 'Insert the lowest possible price in the Unit Price field according to any special price that you have set up.';                    trigger OnAction()                    begin                        Rec.PickPrice();                    end;                }                action("Get Li&ne Discount")                {                    AccessByPermission = TableData "Sales Line Discount" = R;                    ApplicationArea = Service;                    Caption = 'Get Li&ne Discount';                    Ellipsis = true;                    Image = LineDiscount;                    ToolTip = 'Insert the best possible discount in the Line Discount field according to any special discounts that you have set up.';                    Visible = not ExtendedPriceEnabled;                    trigger OnAction()                    begin                        Rec.PickDiscount();                    end;                }                action(GetLineDiscount)                {                    AccessByPermission = TableData "Sales Discount Access" = R;                    ApplicationArea = Service;                    Caption = 'Get Li&ne Discount';                    Ellipsis = true;                    Image = LineDiscount;                    Visible = ExtendedPriceEnabled;                    ToolTip = 'Insert the best possible discount in the Line Discount field according to any special discounts that you have set up.';                    trigger OnAction()                    begin                        Rec.PickDiscount();                    end;                }                action("Insert &Ext. Texts")                {                    AccessByPermission = TableData "Extended Text Header" = R;                    ApplicationArea = Service;                    Caption = 'Insert &Ext. Texts';                    Image = Text;                    ToolTip = 'Insert the extended item description that is set up for the item that is being processed on the line.';                    trigger OnAction()                    begin                        InsertExtendedText(true);                    end;                }                action(GetShipmentLines)                {                    ApplicationArea = Service;                    Caption = 'Get &Shipment Lines';                    Ellipsis = true;                    Image = Shipment;                    ToolTip = 'Select multiple shipments to the same customer because you want to combine them on one invoice.';                    trigger OnAction()                    begin                        GetShipment();                    end;                }            }            group("&Line")            {                Caption = '&Line';                Image = Line;                group("Item Availability by")                {                    Caption = 'Item Availability by';                    Image = ItemAvailability;                    action("Event")                    {                        ApplicationArea = Service;                        Caption = 'Event';                        Image = "Event";                        ToolTip = 'View how the actual and the projected available balance of an item will develop over time according to supply and demand events.';                        trigger OnAction()                        begin                            ServAvailabilityMgt.ShowItemAvailabilityFromServLine(Rec, "Item Availability Type"::"Event");                        end;                    }                    action(Period)                    {                        ApplicationArea = Service;                        Caption = 'Period';                        Image = Period;                        ToolTip = 'View the projected quantity of the item over time according to time periods, such as day, week, or month.';                        trigger OnAction()                        begin                            ServAvailabilityMgt.ShowItemAvailabilityFromServLine(Rec, "Item Availability Type"::Period);                        end;                    }                    action(Variant)                    {                        ApplicationArea = Planning;                        Caption = 'Variant';                        Image = ItemVariant;                        ToolTip = 'View or edit the item''s variants. Instead of setting up each color of an item as a separate item, you can set up the various colors as variants of the item.';                        trigger OnAction()                        begin                            ServAvailabilityMgt.ShowItemAvailabilityFromServLine(Rec, "Item Availability Type"::Variant);                        end;                    }                    action(Location)                    {                        AccessByPermission = TableData Location = R;                        ApplicationArea = Service;                        Caption = 'Location';                        Image = Warehouse;                        ToolTip = 'View the actual and projected quantity of the item per location.';                        trigger OnAction()                        begin                            ServAvailabilityMgt.ShowItemAvailabilityFromServLine(Rec, "Item Availability Type"::Location);                        end;                    }                    action(Lot)                    {                        ApplicationArea = ItemTracking;                        Caption = 'Lot';                        Image = LotInfo;                        RunObject = Page "Item Availability by Lot No.";                        RunPageLink = "No." = field("No."),                            "Location Filter" = field("Location Code"),                            "Variant Filter" = field("Variant Code");                        ToolTip = 'View the current and projected quantity of the item in each lot.';                    }                    action("BOM Level")                    {                        ApplicationArea = Service;                        Caption = 'BOM Level';                        Image = BOMLevel;                        ToolTip = 'View availability figures for items on bills of materials that show how many units of a parent item you can make based on the availability of child items.';                        trigger OnAction()                        begin                            ServAvailabilityMgt.ShowItemAvailabilityFromServLine(Rec, "Item Availability Type"::BOM);                        end;                    }                }                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();                    end;                }                action("Item &Tracking Lines")                {                    ApplicationArea = ItemTracking;                    Caption = 'Item &Tracking Lines';                    Image = ItemTrackingLines;                    ShortCutKey = 'Ctrl+Alt+I';                    ToolTip = 'View or edit serial, lot and package numbers that are assigned to the item on the document or journal line.';                    trigger OnAction()                    begin                        Rec.OpenItemTrackingLines();                    end;                }                action(DocAttach)                {                    ApplicationArea = Service;                    Caption = 'Attachments';                    Image = Attach;                    ToolTip = 'Add a file as an attachment. You can attach images as well as documents.';                    trigger OnAction()                    var                        DocumentAttachmentDetails: Page "Document Attachment Details";                        RecRef: RecordRef;                    begin                        RecRef.GetTable(Rec);                        DocumentAttachmentDetails.OpenForRecRef(RecRef);                        DocumentAttachmentDetails.RunModal();                    end;                }            }            group(Errors)            {                Caption = 'Issues';                Image = ErrorLog;                Visible = BackgroundErrorCheck;                ShowAs = SplitButton;                action(ShowLinesWithErrors)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Show Lines with Issues';                    Image = Error;                    Visible = BackgroundErrorCheck;                    Enabled = not ShowAllLinesEnabled;                    ToolTip = 'View a list of service lines that have issues before you post the document.';                    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 service lines, including lines with and without issues.';                    trigger OnAction()                    begin                        Rec.SwitchLinesWithErrorsFilter(ShowAllLinesEnabled);                    end;                }            }        }    }    trigger OnAfterGetRecord()    var        Item: Record Item;    begin        Rec.ShowShortcutDimCode(ShortcutDimCode);        if Rec."Variant Code" = '' then            VariantCodeMandatory := Item.IsVariantMandatory(Rec.Type = Rec.Type::Item, Rec."No.");    end;    trigger OnDeleteRecord(): Boolean    var        ServiceLineReserve: Codeunit "Service Line-Reserve";    begin        if (Rec.Quantity <> 0) and Rec.ItemExists(Rec."No.") then begin            Commit();            if not ServiceLineReserve.DeleteLineConfirm(Rec) then                exit(false);            ServiceLineReserve.DeleteLine(Rec);        end;    end;    trigger OnNewRecord(BelowxRec: Boolean)    begin        Rec.Type := xRec.Type;        Clear(ShortcutDimCode);    end;    trigger OnOpenPage()    var        PriceCalculationMgt: Codeunit "Price Calculation Mgt.";        DocumentErrorsMgt: Codeunit "Document Errors Mgt.";    begin        ExtendedPriceEnabled := PriceCalculationMgt.IsExtendedPriceCalculationEnabled();        BackgroundErrorCheck := DocumentErrorsMgt.BackgroundValidationEnabled();        SetDimensionsVisibility();        SetItemReferenceVisibility();    end;    var        ServHeader: Record "Service Header";        ServAvailabilityMgt: Codeunit "Serv. Availability Mgt.";        ExtendedPriceEnabled: Boolean;        BackgroundErrorCheck: Boolean;        ItemReferenceVisible: Boolean;        ShowAllLinesEnabled: Boolean;        VariantCodeMandatory: Boolean;        ServiceContractErr: Label 'This service invoice was created from the service contract. If you want to get shipment lines, you must create another service invoice.';    protected var        ShortcutDimCode: array[8] of Code[20];        DimVisible1: Boolean;        DimVisible2: Boolean;        DimVisible3: Boolean;        DimVisible4: Boolean;        DimVisible5: Boolean;        DimVisible6: Boolean;        DimVisible7: Boolean;        DimVisible8: Boolean;    procedure ApproveCalcInvDisc()    begin        CODEUNIT.Run(CODEUNIT::"Service-Disc. (Yes/No)", Rec);    end;    procedure GetShipment()    begin        ServHeader.Get(Rec."Document Type", Rec."Document No.");        if ServHeader."Contract No." <> '' then            Error(ServiceContractErr);        CODEUNIT.Run(CODEUNIT::"Service-Get Shipment", Rec);    end;    procedure InsertExtendedText(Unconditionally: Boolean)    var        ServiceTransferExtText: Codeunit "Service Transfer Ext. Text";    begin        OnBeforeInsertExtendedText(Rec);        if ServiceTransferExtText.ServCheckIfAnyExtText(Rec, Unconditionally) then begin            CurrPage.SaveRecord();            ServiceTransferExtText.InsertServExtText(Rec);        end;        if ServiceTransferExtText.MakeUpdate() then            UpdateForm(true);    end;    local procedure SetItemReferenceVisibility()    var        ItemReference: Record "Item Reference";    begin        ItemReferenceVisible := not ItemReference.IsEmpty();    end;    procedure UpdateForm(SetSaveRecord: Boolean)    begin        CurrPage.Update(SetSaveRecord);    end;    protected procedure NoOnAfterValidate()    begin        InsertExtendedText(false);    end;    protected procedure QuantityOnAfterValidate()    begin        if Rec.Reserve = Rec.Reserve::Always then begin            CurrPage.SaveRecord();            Rec.AutoReserve();        end;    end;    protected procedure UnitofMeasureCodeOnAfterValidate()    begin        if Rec.Reserve = Rec.Reserve::Always then begin            CurrPage.SaveRecord();            Rec.AutoReserve();        end;    end;    local procedure SetDimensionsVisibility()    var        DimMgt: Codeunit DimensionManagement;    begin        DimVisible1 := false;        DimVisible2 := false;        DimVisible3 := false;        DimVisible4 := false;        DimVisible5 := false;        DimVisible6 := false;        DimVisible7 := false;        DimVisible8 := false;        DimMgt.UseShortcutDims(          DimVisible1, DimVisible2, DimVisible3, DimVisible4, DimVisible5, DimVisible6, DimVisible7, DimVisible8);        Clear(DimMgt);    end;    [IntegrationEvent(false, false)]    local procedure OnBeforeInsertExtendedText(var ServiceLine: Record "Service Line")    begin    end;}