Page 43 Sales Invoice
src/Layers/W1/BaseApp/Sales/Document/SalesInvoice.Page.al2,250 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.Sales.Document;using Microsoft.Bank.Setup;using Microsoft.CRM.Contact;using Microsoft.CRM.Outlook;using Microsoft.EServices.EDocument;using Microsoft.Finance.Currency;using Microsoft.Finance.Dimension;using Microsoft.Finance.GeneralLedger.Setup;using Microsoft.Finance.VAT.Calculation;using Microsoft.Foundation.Address;using Microsoft.Foundation.Attachment;using Microsoft.Foundation.Enums;using Microsoft.Foundation.Reporting;using Microsoft.Intercompany;using Microsoft.Intercompany.Journal;using Microsoft.Intercompany.Outbox;using Microsoft.Inventory.Item;using Microsoft.Inventory.Location;using Microsoft.Projects.Resources.Resource;using Microsoft.Purchases.Document;using Microsoft.Sales.Comment;using Microsoft.Sales.Customer;using Microsoft.Sales.History;using Microsoft.Sales.Posting;using Microsoft.Sales.Pricing;using Microsoft.Sales.Setup;using Microsoft.Utilities;using System.Automation;using System.Environment;using System.Environment.Configuration;using System.Privacy;using System.Security.User;using System.Threading;/// <summary>/// Displays and manages a single sales invoice document for direct customer billing./// </summary>page 43 "Sales Invoice"{ Caption = 'Sales Invoice'; PageType = Document; RefreshOnActivate = true; SourceTable = "Sales Header"; SourceTableView = where("Document Type" = filter(Invoice)); AdditionalSearchTerms = 'Sales Bill, Sales Receipt, Commerce Invoice, Client Invoice, Sales Slip, Sales Transaction Invoice'; AboutTitle = 'About sales invoice details'; AboutText = 'You can update and add to the sales invoice until you post it. If you leave the invoice without posting, you can return to it later from the list of ongoing invoices.'; layout { area(content) { group(General) { Caption = 'General'; field("No."; Rec."No.") { ApplicationArea = All; Importance = Standard; ToolTip = 'Specifies the number of the involved entry or record, according to the specified number series.'; Visible = DocNoVisible; trigger OnAssistEdit() begin if Rec.AssistEdit(xRec) then CurrPage.Update(); end; } field("Sell-to Customer No."; Rec."Sell-to Customer No.") { ApplicationArea = Basic, Suite; Caption = 'Customer No.'; Importance = Additional; NotBlank = true; ToolTip = 'Specifies the number of the customer who will receive the products and be billed by default.'; trigger OnValidate() begin IsSalesLinesEditable := Rec.SalesLinesEditable(); Rec.SelltoCustomerNoOnAfterValidate(Rec, xRec); CurrPage.Update(); end; } field("Sell-to Customer Name"; Rec."Sell-to Customer Name") { ApplicationArea = Basic, Suite; Caption = 'Customer Name'; Importance = Promoted; NotBlank = true; ShowMandatory = true; AboutTitle = 'Who you are selling to'; AboutText = 'This can be an existing customer, or you can register a new from here. Customers can have special prices and discounts that are automatically used when you enter the sales lines.'; ToolTip = 'Specifies the name of the customer who will receive the products and be billed by default.'; trigger OnAfterLookup(Selected: RecordRef) var Customer: Record Customer; begin Selected.SetTable(Customer); if Rec."Sell-to Customer No." <> Customer."No." then begin Rec.Validate("Sell-to Customer No.", Customer."No."); if Rec."Sell-to Customer No." <> Customer."No." then error(''); IsSalesLinesEditable := Rec.SalesLinesEditable(); CurrPage.Update(); end; end; trigger OnValidate() begin Rec.SelltoCustomerNoOnAfterValidate(Rec, xRec); CurrPage.Update(); end; } field("Sell-to Customer Name 2"; Rec."Sell-to Customer Name 2") { ApplicationArea = Basic, Suite; Caption = 'Customer Name 2'; QuickEntry = false; Visible = false; } field("Registration Number"; Rec."Registration Number") { ApplicationArea = VAT; Editable = false; Importance = Additional; Visible = false; } field("Posting Description"; Rec."Posting Description") { ApplicationArea = Suite; Visible = false; } group("Sell-to") { Caption = 'Sell-to'; field("Sell-to Address"; Rec."Sell-to Address") { ApplicationArea = Basic, Suite; Caption = 'Address'; Importance = Additional; QuickEntry = false; } field("Sell-to Address 2"; Rec."Sell-to Address 2") { ApplicationArea = Basic, Suite; Caption = 'Address 2'; Importance = Additional; QuickEntry = false; } field("Sell-to City"; Rec."Sell-to City") { ApplicationArea = Basic, Suite; Caption = 'City'; Importance = Additional; QuickEntry = false; } group(Control60) { ShowCaption = false; Visible = IsSellToCountyVisible; field("Sell-to County"; Rec."Sell-to County") { ApplicationArea = Basic, Suite; CaptionClass = '5,1,' + Rec."Sell-to Country/Region Code"; Importance = Additional; QuickEntry = false; } } field("Sell-to Post Code"; Rec."Sell-to Post Code") { ApplicationArea = Basic, Suite; Caption = 'Post Code'; Importance = Additional; QuickEntry = false; ToolTip = 'Specifies the postal code.'; } field("Sell-to Country/Region Code"; Rec."Sell-to Country/Region Code") { ApplicationArea = Basic, Suite; Caption = 'Country/Region Code'; Importance = Additional; QuickEntry = false; ToolTip = 'Specifies the country or region of the address.'; trigger OnValidate() begin IsSellToCountyVisible := FormatAddress.UseCounty(Rec."Sell-to Country/Region Code"); end; } field("Sell-to Contact No."; Rec."Sell-to Contact No.") { ApplicationArea = Basic, Suite; Caption = 'Contact No.'; Importance = Additional; trigger OnLookup(var Text: Text): Boolean begin if not Rec.SelltoContactLookup() then exit(false); Text := Rec."Sell-to Contact No."; CurrPage.Update(); exit(true); end; trigger OnValidate() begin if ApplicationAreaMgmtFacade.IsAdvancedEnabled() then if Rec.GetFilter("Sell-to Contact No.") = xRec."Sell-to Contact No." then if Rec."Sell-to Contact No." <> xRec."Sell-to Contact No." then Rec.SetRange("Sell-to Contact No."); if Rec."Sell-to Contact No." <> xRec."Sell-to Contact No." then CurrPage.Update(); end; } field(SellToPhoneNo; SellToContact."Phone No.") { ApplicationArea = Basic, Suite; Caption = 'Phone No.'; Importance = Additional; Editable = false; ExtendedDatatype = PhoneNo; ToolTip = 'Specifies the telephone number of the contact person that the sales document will be sent to.'; } field(SellToMobilePhoneNo; SellToContact."Mobile Phone No.") { ApplicationArea = Basic, Suite; Caption = 'Mobile Phone No.'; Importance = Additional; Editable = false; ExtendedDatatype = PhoneNo; ToolTip = 'Specifies the mobile telephone number of the contact person that the sales document will be sent to.'; } field(SellToEmail; SellToContact."E-Mail") { ApplicationArea = Basic, Suite; Caption = 'Email'; Importance = Additional; Editable = false; ExtendedDatatype = EMail; ToolTip = 'Specifies the email address of the contact person that the sales document will be sent to.'; } } field("Sell-to Contact"; Rec."Sell-to Contact") { ApplicationArea = Basic, Suite; Caption = 'Contact'; Editable = Rec."Sell-to Customer No." <> ''; ToolTip = 'Specifies the name of the person to contact at the customer.'; } field("Your Reference"; Rec."Your Reference") { ApplicationArea = Basic, Suite; Importance = Additional; ToolTip = 'Specifies the customer''s reference. The contents will be printed on sales documents.'; } field("Document Date"; Rec."Document Date") { ApplicationArea = Basic, Suite; Importance = Promoted; } field("Posting Date"; Rec."Posting Date") { ApplicationArea = Basic, Suite; Importance = Promoted; trigger OnValidate() begin SaveInvoiceDiscountAmount(); end; } field("VAT Reporting Date"; Rec."VAT Reporting Date") { ApplicationArea = VAT; Importance = Promoted; Editable = VATDateEnabled; Visible = VATDateEnabled; } field("Due Date"; Rec."Due Date") { ApplicationArea = Basic, Suite; Importance = Promoted; } field("Incoming Document Entry No."; Rec."Incoming Document Entry No.") { ApplicationArea = Basic, Suite; Importance = Additional; Visible = false; } field("External Document No."; Rec."External Document No.") { ApplicationArea = Basic, Suite; Importance = Additional; ShowMandatory = ExternalDocNoMandatory; } field("Salesperson Code"; Rec."Salesperson Code") { ApplicationArea = Suite; Importance = Additional; trigger OnValidate() begin SalespersonCodeOnAfterValidate(); end; } field("Campaign No."; Rec."Campaign No.") { ApplicationArea = RelationshipMgmt; Importance = Additional; ToolTip = 'Specifies the number of the campaign that the document is linked to.'; trigger OnValidate() begin if Rec."Campaign No." <> xRec."Campaign No." then CurrPage.Update(); end; } field("Responsibility Center"; Rec."Responsibility Center") { AccessByPermission = TableData "Responsibility Center" = R; ApplicationArea = Basic, Suite; Importance = Additional; } field("Assigned User ID"; Rec."Assigned User ID") { ApplicationArea = Basic, Suite; Importance = Additional; } field(Status; Rec.Status) { ApplicationArea = Suite; Importance = Promoted; StyleExpr = StatusStyleTxt; AboutTitle = 'Check the invoice status here'; AboutText = 'You can only edit an open invoice. When status is Released, it means the invoice is up for next stage in processing, such as reserving the products being sold. Use Reopen if you must edit a released invoice.'; } field("Job Queue Status"; Rec."Job Queue Status") { ApplicationArea = All; Importance = Additional; ToolTip = 'Specifies the status of a job queue entry or task that handles the posting of sales invoices.'; 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; } group("Work Description") { Caption = 'Work Description'; field(WorkDescription; WorkDescription) { ApplicationArea = Basic, Suite; Importance = Additional; MultiLine = true; ShowCaption = false; ToolTip = 'Specifies the products or service being offered'; trigger OnValidate() begin Rec.SetWorkDescription(WorkDescription); end; } } } part(SalesLines; "Sales Invoice Subform") { ApplicationArea = Basic, Suite; Editable = IsSalesLinesEditable; Enabled = IsSalesLinesEditable; SubPageLink = "Document No." = field("No."); UpdatePropagation = Both; } group("Invoice Details") { Caption = 'Invoice Details'; field("Currency Code"; Rec."Currency Code") { ApplicationArea = Suite; Importance = Promoted; trigger OnAssistEdit() begin Clear(ChangeExchangeRate); if Rec."Posting Date" <> 0D then ChangeExchangeRate.SetParameter(Rec."Currency Code", Rec."Currency Factor", Rec."Posting Date") else ChangeExchangeRate.SetParameter(Rec."Currency Code", Rec."Currency Factor", WorkDate()); if ChangeExchangeRate.RunModal() = ACTION::OK then begin Rec.Validate("Currency Factor", ChangeExchangeRate.GetParameter()); SaveInvoiceDiscountAmount(); end; Clear(ChangeExchangeRate); end; trigger OnValidate() begin CurrPage.Update(); end; } field("Company Bank Account Code"; Rec."Company Bank Account Code") { ApplicationArea = Suite; Importance = Promoted; } field("Shipment Date"; Rec."Shipment Date") { ApplicationArea = Basic, Suite; Importance = Promoted; } group(Control58) { ShowCaption = false; Visible = ShowQuoteNo; field("Quote No."; Rec."Quote No.") { ApplicationArea = All; } } field("Prices Including VAT"; Rec."Prices Including VAT") { ApplicationArea = VAT; trigger OnValidate() begin CurrPage.SalesLines.Page.ForceTotalsCalculation(); CurrPage.Update(); end; } field("VAT Country/Region Code"; Rec."VAT Country/Region Code") { ApplicationArea = VAT; Importance = Additional; } field("VAT Registration No."; Rec."VAT Registration No.") { ApplicationArea = VAT; Importance = Additional; } field("Gen. Bus. Posting Group"; Rec."Gen. Bus. Posting Group") { ApplicationArea = Basic, Suite; Importance = Additional; } field("VAT Bus. Posting Group"; Rec."VAT Bus. Posting Group") { ApplicationArea = Basic, Suite; trigger OnValidate() begin CurrPage.Update(); end; } field("Customer Posting Group"; Rec."Customer Posting Group") { ApplicationArea = Basic, Suite; Editable = IsPostingGroupEditable; Importance = Additional; } field("Payment Terms Code"; Rec."Payment Terms Code") { ApplicationArea = Basic, Suite; Importance = Promoted; } field("Payment Method Code"; Rec."Payment Method Code") { ApplicationArea = Basic, Suite; Importance = Additional; Visible = IsPaymentMethodCodeVisible; trigger OnValidate() begin UpdatePaymentService(); end; } field("Reason Code"; Rec."Reason Code") { ApplicationArea = Basic, Suite; Importance = Additional; Visible = false; } field("EU 3-Party Trade"; Rec."EU 3-Party Trade") { ApplicationArea = BasicEU; } group(Control174) { ShowCaption = false; Visible = PaymentServiceVisible; field(SelectedPayments; Rec.GetSelectedPaymentServicesText()) { ApplicationArea = All; Caption = 'Payment Service'; Editable = false; Enabled = PaymentServiceEnabled; MultiLine = true; ToolTip = 'Specifies the online payment service, such as PayPal, that customers can use to pay the sales document.'; trigger OnAssistEdit() begin Rec.ChangePaymentServiceSetting(); end; } } field("Shortcut Dimension 1 Code"; Rec."Shortcut Dimension 1 Code") { ApplicationArea = Dimensions; trigger OnValidate() begin CurrPage.Update(); end; } field("Shortcut Dimension 2 Code"; Rec."Shortcut Dimension 2 Code") { ApplicationArea = Dimensions; trigger OnValidate() begin CurrPage.Update(); end; } field("Payment Discount %"; Rec."Payment Discount %") { ApplicationArea = Basic, Suite; ToolTip = 'Specifies the payment discount percentage granted if the customer pays on or before the date entered in the Pmt. Discount Date field.'; } field("Pmt. Discount Date"; Rec."Pmt. Discount Date") { ApplicationArea = Basic, Suite; Importance = Additional; } field("Journal Templ. Name"; Rec."Journal Templ. Name") { ApplicationArea = BasicBE; Visible = IsJournalTemplNameVisible; } field("Direct Debit Mandate ID"; Rec."Direct Debit Mandate ID") { ApplicationArea = Basic, Suite; } field("Location Code"; Rec."Location Code") { ApplicationArea = Location; Importance = Additional; } } group("Shipping and Billing") { Caption = 'Shipping and Billing'; Enabled = Rec."Sell-to Customer No." <> ''; group(Control34) { ShowCaption = false; group(Control200) { ShowCaption = false; field(ShippingOptions; ShipToOptions) { ApplicationArea = Basic, Suite; Caption = 'Ship-to'; ToolTip = 'Specifies the address that the products on the sales document are shipped to. Default (Sell-to Address): The same as the customer''s sell-to address. Alternate Ship-to Address: One of the customer''s alternate ship-to addresses. Custom Address: Any ship-to address that you specify in the fields below.'; trigger OnValidate() var ShipToAddress: Record "Ship-to Address"; ShipToAddressList: Page "Ship-to Address List"; IsHandled: Boolean; begin IsHandled := false; OnBeforeValidateShipToOptions(Rec, ShipToOptions.AsInteger(), IsHandled); if not IsHandled then case ShipToOptions of ShipToOptions::"Default (Sell-to Address)": begin Rec.Validate("Ship-to Code", ''); Rec.CopySellToAddressToShipToAddress(); end; ShipToOptions::"Alternate Shipping Address": begin ShipToAddress.SetRange("Customer No.", Rec."Sell-to Customer No."); ShipToAddressList.LookupMode := true; ShipToAddressList.SetTableView(ShipToAddress); if ShipToAddressList.RunModal() = ACTION::LookupOK then begin ShipToAddressList.GetRecord(ShipToAddress); Rec.Validate("Ship-to Code", ShipToAddress.Code); IsShipToCountyVisible := FormatAddress.UseCounty(ShipToAddress."Country/Region Code"); end else ShipToOptions := ShipToOptions::"Custom Address"; end; ShipToOptions::"Custom Address": begin Rec.Validate("Ship-to Code", ''); IsShipToCountyVisible := FormatAddress.UseCounty(Rec."Ship-to Country/Region Code"); end; end; OnAfterValidateShipToOptions(Rec, ShipToOptions.AsInteger()); end; } group(Control202) { ShowCaption = false; Visible = not (ShipToOptions = ShipToOptions::"Default (Sell-to Address)"); field("Ship-to Code"; Rec."Ship-to Code") { ApplicationArea = Basic, Suite; Caption = 'Code'; Editable = ShipToOptions = ShipToOptions::"Alternate Shipping Address"; Importance = Promoted; ToolTip = 'Specifies the code for another shipment address than the customer''s own address, which is entered by default.'; trigger OnValidate() var ShipToAddress: Record "Ship-to Address"; begin if (xRec."Ship-to Code" <> '') and (Rec."Ship-to Code" = '') then Error(EmptyShipToCodeErr); if Rec."Ship-to Code" <> '' then begin ShipToAddress.Get(Rec."Sell-to Customer No.", Rec."Ship-to Code"); IsShipToCountyVisible := FormatAddress.UseCounty(ShipToAddress."Country/Region Code"); end else IsShipToCountyVisible := false; end; } field("Ship-to Name"; Rec."Ship-to Name") { ApplicationArea = Basic, Suite; Caption = 'Name'; Editable = ShipToOptions = ShipToOptions::"Custom Address"; ToolTip = 'Specifies the name that products on the sales document will be shipped to.'; } field("Ship-to Name 2"; Rec."Ship-to Name 2") { ApplicationArea = Basic, Suite; Caption = 'Name 2'; Editable = ShipToOptions = ShipToOptions::"Custom Address"; Importance = Additional; QuickEntry = false; Visible = false; } field("Ship-to Address"; Rec."Ship-to Address") { ApplicationArea = Basic, Suite; Caption = 'Address'; Editable = ShipToOptions = ShipToOptions::"Custom Address"; QuickEntry = false; } field("Ship-to Address 2"; Rec."Ship-to Address 2") { ApplicationArea = Basic, Suite; Caption = 'Address 2'; Editable = ShipToOptions = ShipToOptions::"Custom Address"; QuickEntry = false; } field("Ship-to City"; Rec."Ship-to City") { ApplicationArea = Basic, Suite; Caption = 'City'; Editable = ShipToOptions = ShipToOptions::"Custom Address"; QuickEntry = false; } group(Control82) { ShowCaption = false; Visible = IsShipToCountyVisible; field("Ship-to County"; Rec."Ship-to County") { ApplicationArea = Basic, Suite; CaptionClass = '5,1,' + Rec."Ship-to Country/Region Code"; Editable = ShipToOptions = ShipToOptions::"Custom Address"; QuickEntry = false; } } field("Ship-to Post Code"; Rec."Ship-to Post Code") { ApplicationArea = Basic, Suite; Caption = 'Post Code'; Editable = ShipToOptions = ShipToOptions::"Custom Address"; QuickEntry = false; ToolTip = 'Specifies the postal code.'; } field("Ship-to Country/Region Code"; Rec."Ship-to Country/Region Code") { ApplicationArea = Basic, Suite; Caption = 'Country/Region'; Editable = ShipToOptions = ShipToOptions::"Custom Address"; Importance = Additional; QuickEntry = false; ToolTip = 'Specifies the customer''s country/region.'; trigger OnValidate() begin IsShipToCountyVisible := FormatAddress.UseCounty(Rec."Ship-to Country/Region Code"); end; } } field("Ship-to Phone No."; Rec."Ship-to Phone No.") { ApplicationArea = Basic, Suite; Caption = 'Phone No.'; } field("Ship-to Contact"; Rec."Ship-to Contact") { ApplicationArea = Basic, Suite; Caption = 'Contact'; ToolTip = 'Specifies the name of the contact person at the address that products on the sales document will be shipped to.'; } } group("Shipment Method") { Caption = 'Shipment Method'; field("Shipment Method Code"; Rec."Shipment Method Code") { ApplicationArea = Basic, Suite; Caption = 'Code'; Importance = Additional; ToolTip = 'Specifies how items on the sales document are shipped to the customer.'; } field("Shipping Agent Code"; Rec."Shipping Agent Code") { ApplicationArea = Suite; Caption = 'Agent'; Importance = Additional; ToolTip = 'Specifies which shipping agent is used to transport the items on the sales document to the customer.'; } field("Shipping Agent Service Code"; Rec."Shipping Agent Service Code") { ApplicationArea = Suite; Caption = 'Agent service'; Importance = Additional; ToolTip = 'Specifies which shipping agent service is used to transport the items on the sales document to the customer.'; } field("Package Tracking No."; Rec."Package Tracking No.") { ApplicationArea = Suite; Importance = Additional; } } } group(Control203) { ShowCaption = false; field(BillToOptions; BillToOptions) { ApplicationArea = Basic, Suite; Caption = 'Bill-to'; ToolTip = 'Specifies the customer that the sales invoice will be sent to. Default (Customer): The same as the customer on the sales invoice. Another Customer: Any customer that you specify in the fields below.'; trigger OnValidate() begin if BillToOptions = BillToOptions::"Default (Customer)" then begin Rec.Validate("Bill-to Customer No.", Rec."Sell-to Customer No."); Rec.RecallModifyAddressNotification(Rec.GetModifyBillToCustomerAddressNotificationId()); end; Rec.CopySellToAddressToBillToAddress(); end; } group(Control205) { ShowCaption = false; Visible = not (BillToOptions = BillToOptions::"Default (Customer)"); field("Bill-to Name"; Rec."Bill-to Name") { ApplicationArea = Basic, Suite; Caption = 'Name'; Editable = ((BillToOptions = BillToOptions::"Another Customer") or ((BillToOptions = BillToOptions::"Custom Address") and not ShouldSearchForCustByName)); Enabled = ((BillToOptions = BillToOptions::"Another Customer") or ((BillToOptions = BillToOptions::"Custom Address") and not ShouldSearchForCustByName)); Importance = Promoted; NotBlank = true; ToolTip = 'Specifies the customer to whom you will send the sales invoice, when different from the customer that you are selling to.'; trigger OnValidate() begin if not ((BillToOptions = BillToOptions::"Custom Address") and not ShouldSearchForCustByName) then begin if Rec.GetFilter("Bill-to Customer No.") = xRec."Bill-to Customer No." then if Rec."Bill-to Customer No." <> xRec."Bill-to Customer No." then Rec.SetRange("Bill-to Customer No."); CurrPage.Update(); end; end; trigger OnLookup(var Text: Text): Boolean var Customer: Record Customer; begin OnBeforeLookupBillToName(Customer, Rec); if Customer.SelectCustomer(Customer) then begin xRec := Rec; Rec."Bill-to Name" := Customer.Name; Rec.Validate("Bill-to Customer No.", Customer."No."); end; if not ((BillToOptions = BillToOptions::"Custom Address") and not ShouldSearchForCustByName) then begin if Rec.GetFilter("Bill-to Customer No.") = xRec."Bill-to Customer No." then if Rec."Bill-to Customer No." <> xRec."Bill-to Customer No." then Rec.SetRange("Bill-to Customer No."); CurrPage.Update(); end; end; } field("Bill-to Name 2"; Rec."Bill-to Name 2") { ApplicationArea = Basic, Suite; Caption = 'Name 2'; Editable = (BillToOptions = BillToOptions::"Another Customer"); Enabled = (BillToOptions = BillToOptions::"Another Customer"); Importance = Additional; QuickEntry = false; Visible = false; } field("Bill-to Address"; Rec."Bill-to Address") { ApplicationArea = Basic, Suite; Caption = 'Address'; Editable = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Enabled = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Importance = Additional; QuickEntry = false; } field("Bill-to Address 2"; Rec."Bill-to Address 2") { ApplicationArea = Basic, Suite; Caption = 'Address 2'; Editable = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Enabled = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Importance = Additional; QuickEntry = false; } field("Bill-to City"; Rec."Bill-to City") { ApplicationArea = Basic, Suite; Caption = 'City'; Editable = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Enabled = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Importance = Additional; QuickEntry = false; } group(Control85) { ShowCaption = false; Visible = IsBillToCountyVisible; field("Bill-to County"; Rec."Bill-to County") { ApplicationArea = Basic, Suite; CaptionClass = '5,1,' + Rec."Bill-to Country/Region Code"; Editable = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Enabled = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Importance = Additional; QuickEntry = false; } } field("Bill-to Post Code"; Rec."Bill-to Post Code") { ApplicationArea = Basic, Suite; Caption = 'Post Code'; Editable = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Enabled = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Importance = Additional; QuickEntry = false; ToolTip = 'Specifies the postal code.'; } field("Bill-to Country/Region Code"; Rec."Bill-to Country/Region Code") { ApplicationArea = Basic, Suite; Caption = 'Country/Region'; Editable = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Enabled = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Importance = Additional; QuickEntry = false; ToolTip = 'Specifies the country or region of the address.'; trigger OnValidate() begin IsBillToCountyVisible := FormatAddress.UseCounty(Rec."Bill-to Country/Region Code"); end; } field("Bill-to Contact No."; Rec."Bill-to Contact No.") { ApplicationArea = Basic, Suite; Caption = 'Contact No.'; Editable = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Enabled = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Importance = Additional; } field("Bill-to Contact"; Rec."Bill-to Contact") { ApplicationArea = Basic, Suite; Caption = 'Contact'; Editable = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); Enabled = (BillToOptions = BillToOptions::"Custom Address") or (Rec."Bill-to Customer No." <> Rec."Sell-to Customer No."); ToolTip = 'Specifies the name of the person you should contact at the customer you are sending the invoice to.'; } field(BillToContactPhoneNo; BillToContact."Phone No.") { ApplicationArea = Basic, Suite; Caption = 'Phone No.'; Editable = false; Importance = Additional; ExtendedDatatype = PhoneNo; ToolTip = 'Specifies the telephone number of the person you should contact at the customer you are sending the invoice to.'; } field(BillToContactMobilePhoneNo; BillToContact."Mobile Phone No.") { ApplicationArea = Basic, Suite; Caption = 'Mobile Phone No.'; Editable = false; Importance = Additional; ExtendedDatatype = PhoneNo; ToolTip = 'Specifies the mobile telephone number of the person you should contact at the customer you are sending the invoice to.'; } field(BillToContactEmail; BillToContact."E-Mail") { ApplicationArea = Basic, Suite; Caption = 'Email'; Editable = false; Importance = Additional; ExtendedDatatype = EMail; ToolTip = 'Specifies the email address of the person you should contact at the customer you are sending the invoice to.'; } } } } group("Foreign Trade") { Caption = 'Foreign Trade'; field("Transaction Specification"; Rec."Transaction Specification") { ApplicationArea = BasicEU; } field("Transaction Type"; Rec."Transaction Type") { ApplicationArea = BasicEU; } field("Transport Method"; Rec."Transport Method") { ApplicationArea = BasicEU; } field("Exit Point"; Rec."Exit Point") { ApplicationArea = BasicEU; } field("Area"; Rec.Area) { ApplicationArea = BasicEU; } field("Language Code"; Rec."Language Code") { ApplicationArea = Basic, Suite; Visible = false; } field("Format Region"; Rec."Format Region") { ApplicationArea = Basic, Suite; Visible = false; } } } area(factboxes) { part(SalesDocCheckFactbox; "Sales Doc. Check Factbox") { ApplicationArea = All; Caption = 'Document Check'; Visible = SalesDocCheckFactboxVisible; SubPageLink = "No." = field("No."), "Document Type" = field("Document Type"); } part("Attached Documents List"; "Doc. Attachment List Factbox") { ApplicationArea = All; Caption = 'Documents'; UpdatePropagation = Both; SubPageLink = "Table ID" = const(Database::"Sales Header"), "No." = field("No."), "Document Type" = field("Document Type"); } part(Control31; "Pending Approval FactBox") { ApplicationArea = All; SubPageLink = "Table ID" = const(36), "Document Type" = field("Document Type"), "Document No." = field("No."), Status = const(Open); Visible = OpenApprovalEntriesExistForCurrUser; } part(Control1903720907; "Sales Hist. Sell-to FactBox") { ApplicationArea = Basic, Suite; SubPageLink = "No." = field("Sell-to Customer No."), "Date Filter" = field("Date Filter"); Visible = false; } part(Control1907234507; "Sales Hist. Bill-to FactBox") { ApplicationArea = Basic, Suite; SubPageLink = "No." = field("Bill-to Customer No."), "Date Filter" = field("Date Filter"); Visible = false; } part(Control1902018507; "Customer Statistics FactBox") { ApplicationArea = Basic, Suite; SubPageLink = "No." = field("Bill-to Customer No."), "Date Filter" = field("Date Filter"); } part(Control1900316107; "Customer Details FactBox") { ApplicationArea = Basic, Suite; SubPageLink = "No." = field("Sell-to Customer No."), "Date Filter" = field("Date Filter"); } part(Control1906127307; "Sales Line FactBox") { ApplicationArea = Basic, Suite; Provider = SalesLines; SubPageLink = "Document Type" = field("Document Type"), "Document No." = field("Document No."), "Line No." = field("Line No."); Visible = false; } part(Control1901314507; "Item Invoicing FactBox") { ApplicationArea = Basic, Suite; Provider = SalesLines; SubPageLink = "No." = field("No."); } part(IncomingDocAttachFactBox; "Incoming Doc. Attach. FactBox") { ApplicationArea = Basic, Suite; ShowFilter = false; Visible = false; } part(ApprovalFactBox; "Approval FactBox") { ApplicationArea = Basic, Suite; Visible = false; } part(Control1907012907; "Resource Details FactBox") { ApplicationArea = Basic, Suite; Provider = SalesLines; SubPageLink = "No." = field("No."); Visible = false; } part(WorkflowStatus; "Workflow Status FactBox") { ApplicationArea = All; Editable = false; Enabled = false; ShowFilter = false; Visible = ShowWorkflowStatus; } systempart(Control1900383207; Links) { ApplicationArea = RecordLinks; Visible = false; } systempart(Control1905767507; Notes) { ApplicationArea = Notes; } } } actions { area(navigation) { group("&Invoice") { Caption = '&Invoice'; Image = Invoice; action(SalesStatistics) { ApplicationArea = Basic, Suite; Caption = 'Statistics'; Enabled = Rec."No." <> ''; Image = Statistics; ShortCutKey = 'F7'; Visible = true; ToolTip = 'View statistical information, such as the value of posted entries, for the record.'; RunObject = Page "Sales Statistics"; RunPageOnRec = true; } action(CustomerStatistics) { ApplicationArea = Basic, Suite; Caption = 'Customer Statistics'; Enabled = IsCustomerOrContactNotEmpty; Image = Statistics; RunObject = Page "Customer Statistics"; RunPageLink = "No." = field("Sell-to Customer No."), "Date Filter" = field("Date Filter"); ToolTip = 'View statistical information, such as the value of posted entries, for the sell-to customer on the sales document.'; } action("Co&mments") { ApplicationArea = Comments; Caption = 'Co&mments'; Image = ViewComments; RunObject = Page "Sales Comment Sheet"; RunPageLink = "Document Type" = field("Document Type"), "No." = field("No."), "Document Line No." = const(0); ToolTip = 'View or add comments for the record.'; } action(Approvals) { AccessByPermission = TableData "Approval Entry" = R; ApplicationArea = Suite; Caption = 'Approvals'; Image = Approvals; ToolTip = 'View a list of the records that are waiting to be approved. For example, you can see who requested the record to be approved, when it was sent, and when it is due to be approved.'; trigger OnAction() var ApprovalsMgmt: Codeunit "Approvals Mgmt."; begin ApprovalsMgmt.OpenApprovalsSales(Rec); end; } action(Function_CustomerCard) { ApplicationArea = Basic, Suite; Caption = 'Customer'; Enabled = IsCustomerOrContactNotEmpty; Image = Customer; RunObject = Page "Customer Card"; RunPageLink = "No." = field("Sell-to Customer No."), "Date Filter" = field("Date Filter"); ShortCutKey = 'Shift+F7'; ToolTip = 'View or edit detailed information about the customer on the sales document.'; } action(Dimensions) { AccessByPermission = TableData Dimension = R; ApplicationArea = Dimensions; Caption = 'Dimensions'; Enabled = Rec."No." <> ''; 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.ShowDocDim(); CurrPage.SaveRecord(); end; } action(DocAttach) { ApplicationArea = All; 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(History) { Caption = 'History'; action(PageInteractionLogEntries) { ApplicationArea = Suite; Caption = 'Interaction Log E&ntries'; Image = InteractionLog; ShortCutKey = 'Ctrl+F7'; ToolTip = 'View a list of interaction log entries related to this document.'; trigger OnAction() begin Rec.ShowInteractionLogEntries(); end; } } } area(processing) { group(Approval) { Caption = 'Approval'; action(Approve) { ApplicationArea = All; Caption = 'Approve'; Image = Approve; ToolTip = 'Approve the requested changes.'; Visible = OpenApprovalEntriesExistForCurrUser; trigger OnAction() begin ApprovalsMgmt.ApproveRecordApprovalRequest(Rec.RecordId); end; } action(Reject) { ApplicationArea = All; Caption = 'Reject'; Image = Reject; ToolTip = 'Reject the approval request.'; Visible = OpenApprovalEntriesExistForCurrUser; trigger OnAction() begin ApprovalsMgmt.RejectRecordApprovalRequest(Rec.RecordId); end; } action(Delegate) { ApplicationArea = All; Caption = 'Delegate'; Image = Delegate; ToolTip = 'Delegate the approval to a substitute approver.'; Visible = OpenApprovalEntriesExistForCurrUser; trigger OnAction() begin ApprovalsMgmt.DelegateRecordApprovalRequest(Rec.RecordId); end; } action(Comment) { ApplicationArea = All; Caption = 'Comments'; Image = ViewComments; ToolTip = 'View or add comments for the record.'; Visible = OpenApprovalEntriesExistForCurrUser; trigger OnAction() var ApprovalsMgmt: Codeunit "Approvals Mgmt."; begin ApprovalsMgmt.GetApprovalComment(Rec); end; } } group(Action9) { Caption = 'Release'; Image = ReleaseDoc; action(Release) { ApplicationArea = Suite; Caption = 'Re&lease'; Enabled = IsCustomerOrContactNotEmpty and (Rec.Status <> Rec.Status::Released); Image = ReleaseDoc; ShortCutKey = 'Ctrl+F9'; ToolTip = 'Release the document to the next stage of processing. You must reopen the document before you can make changes to it.'; trigger OnAction() var ReleaseSalesDoc: Codeunit "Release Sales Document"; begin ReleaseSalesDoc.PerformManualRelease(Rec); CurrPage.SalesLines.PAGE.ClearTotalSalesHeader(); end; } action(Reopen) { ApplicationArea = Suite; Caption = 'Re&open'; Enabled = Rec.Status <> Rec.Status::Open; Image = ReOpen; ToolTip = 'Reopen the document to change it after it has been approved. Approved documents have the Released status and must be opened before they can be changed.'; trigger OnAction() var ReleaseSalesDoc: Codeunit "Release Sales Document"; begin ReleaseSalesDoc.PerformManualReopen(Rec); CurrPage.SalesLines.PAGE.ClearTotalSalesHeader(); end; } action("Reject IC Sales Invoice") { ApplicationArea = Intercompany; Caption = 'Reject IC Sales Invoice'; Enabled = RejectICSalesInvoiceEnabled; Image = Cancel; ToolTip = 'Deletes the invoice and sends the rejection to the company that created it.'; trigger OnAction() var ICInboxOutboxMgt: Codeunit ICInboxOutboxMgt; begin if not ICInboxOutboxMgt.IsSalesHeaderFromIncomingIC(Rec) then exit; if Confirm(SureToRejectMsg) then ICInboxOutboxMgt.RejectAcceptedSalesHeader(Rec); end; } } group("F&unctions") { Caption = 'F&unctions'; Image = "Action"; action(CreatePurchaseInvoice) { ApplicationArea = Basic, Suite; Caption = 'Create Purchase Invoice'; Image = NewPurchaseInvoice; //The property 'PromotedCategory' can only be set if the property 'Promoted' is set to 'true' //PromotedCategory = Category7; //The property 'PromotedIsBig' can only be set if the property 'Promoted' is set to 'true' //PromotedIsBig = true; ToolTip = 'Create a new purchase invoice to buy all the items that are required by the sales document, even if some of the items are already available.'; trigger OnAction() var SelectedSalesLine: Record "Sales Line"; PurchDocFromSalesDoc: Codeunit "Purch. Doc. From Sales Doc."; begin CurrPage.SalesLines.PAGE.SetSelectionFilter(SelectedSalesLine); PurchDocFromSalesDoc.CreatePurchaseInvoice(Rec, SelectedSalesLine); end; } action(GetRecurringSalesLines) { ApplicationArea = Suite; Caption = 'Get Recurring Sales Lines'; Ellipsis = true; Enabled = IsCustomerOrContactNotEmpty; Image = CustomerCode; ToolTip = 'Insert sales document lines that you have set up for the customer as recurring. Recurring sales lines could be for a monthly replenishment order or a fixed freight expense.'; trigger OnAction() var StdCustSalesCode: Record "Standard Customer Sales Code"; begin StdCustSalesCode.InsertSalesLines(Rec); end; } action(CalculateInvoiceDiscount) { AccessByPermission = TableData "Cust. Invoice Disc." = R; ApplicationArea = Basic, Suite; Caption = 'Calculate &Invoice Discount'; Enabled = IsCustomerOrContactNotEmpty; Image = CalculateInvoiceDiscount; ToolTip = 'Calculate the invoice discount for the entire sales document when all sales invoice lines are entered.'; trigger OnAction() begin ApproveCalcInvDisc(); SalesCalcDiscountByType.ResetRecalculateInvoiceDisc(Rec); end; } action(CopyDocument) { ApplicationArea = Suite; Caption = 'Copy Document'; Ellipsis = true; Enabled = Rec."No." <> ''; Image = CopyDocument; ToolTip = 'Copy document lines and header information from another sales document to this document. You can copy a posted sales invoice into a new sales invoice to quickly create a similar document.'; trigger OnAction() begin Rec.CopyDocument(); if Rec.Get(Rec."Document Type", Rec."No.") then; CurrPage.SalesLines.Page.ForceTotalsCalculation(); CurrPage.Update(); end; } action("Move Negative Lines") { ApplicationArea = Basic, Suite; Caption = 'Move Negative Lines'; Ellipsis = true; Image = MoveNegativeLines; ToolTip = 'Prepare to create a replacement sales order in a sales return process.'; trigger OnAction() begin Clear(MoveNegSalesLines); MoveNegSalesLines.SetSalesHeader(Rec); MoveNegSalesLines.RunModal(); MoveNegSalesLines.ShowDocument(); end; } group("Incoming Document") { 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.NewAttachmentFromSalesDocument(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("Request Approval") { Caption = 'Request Approval'; action(SendApprovalRequest) { ApplicationArea = Basic, Suite; Caption = 'Send A&pproval Request'; Enabled = not OpenApprovalEntriesExist and CanRequestApprovalForFlow; Image = SendApprovalRequest; ToolTip = 'Request approval of the document.'; trigger OnAction() begin if ApprovalsMgmt.CheckSalesApprovalPossible(Rec) then ApprovalsMgmt.OnSendSalesDocForApproval(Rec); end; } action(CancelApprovalRequest) { ApplicationArea = Basic, Suite; Caption = 'Cancel Approval Re&quest'; Enabled = CanCancelApprovalForRecord or CanCancelApprovalForFlow; Image = CancelApprovalRequest; ToolTip = 'Cancel the approval request.'; trigger OnAction() var WorkflowWebhookMgt: Codeunit "Workflow Webhook Management"; begin ApprovalsMgmt.OnCancelSalesApprovalRequest(Rec); WorkflowWebhookMgt.FindAndCancel(Rec.RecordId); end; } group(Flow) { Caption = 'Power Automate'; Image = Flow; customaction(CreateFlowFromTemplate) { ApplicationArea = Basic, Suite; Caption = 'Create approval flow'; ToolTip = 'Create a new flow in Power Automate from a list of relevant flow templates.'; Visible = IsSaaS and IsPowerAutomatePrivacyNoticeApproved; CustomActionType = FlowTemplateGallery; FlowTemplateCategoryName = 'd365bc_approval_salesInvoice'; } } } group("P&osting") { Caption = 'P&osting'; Image = Post; action(Post) { ApplicationArea = Basic, Suite; Caption = 'P&ost'; Image = PostOrder; ShortCutKey = 'F9'; AboutTitle = 'When all is set, you post'; AboutText = 'After entering the sales lines and other information, you post the invoice to make it count. After posting, the sales invoice is moved to the Posted Sales Invoices list.'; ToolTip = 'Finalize the document or journal by posting the amounts and quantities to the related accounts in your company books.'; trigger OnAction() begin PostDocument(CODEUNIT::"Sales-Post (Yes/No)", Enum::"Navigate After Posting"::"Posted Document"); end; } action(PostAndNew) { ApplicationArea = Basic, Suite; Caption = 'Post and New'; Ellipsis = true; Image = PostOrder; ShortCutKey = 'Alt+F9'; ToolTip = 'Post the sales document and create a new, empty one.'; trigger OnAction() begin PostDocument(CODEUNIT::"Sales-Post (Yes/No)", Enum::"Navigate After Posting"::"New Document"); end; } action(PostAndSend) { ApplicationArea = Basic, Suite; Caption = 'Post and &Send'; Ellipsis = true; Image = PostSendTo; ToolTip = 'Finalize and prepare to send the document according to the customer''s sending profile, such as attached to an email. The Send document to window opens first so you can confirm or select a sending profile.'; trigger OnAction() begin PostDocument(CODEUNIT::"Sales-Post and Send", Enum::"Navigate After Posting"::"Do Nothing"); 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() begin ShowPreview(); end; } action(DraftInvoice) { ApplicationArea = Basic, Suite; Caption = 'Draft Invoice'; Ellipsis = true; Image = ViewPostedOrder; //The property 'PromotedCategory' can only be set if the property 'Promoted' is set to 'true' //PromotedCategory = Category5; ToolTip = 'View or print the sales invoice as a draft before you perform the actual posting.'; trigger OnAction() var DocumentPrint: Codeunit "Document-Print"; begin DocumentPrint.PrintSalesHeader(Rec); end; } action(ProformaInvoice) { ApplicationArea = Basic, Suite; Caption = 'Pro Forma Invoice'; Ellipsis = true; Image = ViewPostedOrder; //The property 'PromotedCategory' can only be set if the property 'Promoted' is set to 'true' //PromotedCategory = Category5; ToolTip = 'View or print the pro forma sales invoice.'; trigger OnAction() var DocumentPrint: Codeunit "Document-Print"; begin DocumentPrint.PrintProformaSalesInvoice(Rec); end; } action("Test Report") { ApplicationArea = Basic, Suite; Caption = 'Test Report'; Ellipsis = true; Image = TestReport; //The property 'PromotedCategory' can only be set if the property 'Promoted' is set to 'true' //PromotedCategory = Category5; 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() begin ReportPrint.PrintSalesHeader(Rec); 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.'; trigger OnAction() begin Rec.CancelBackgroundPosting(); end; } action(PrintToAttachment) { ApplicationArea = Basic, Suite; Caption = 'Attach as PDF'; Ellipsis = true; Image = PrintAttachment; ToolTip = 'Create a PDF file and attach it to the document.'; trigger OnAction() var SalesHeader: Record "Sales Header"; DocumentPrint: Codeunit "Document-Print"; begin SalesHeader := Rec; SalesHeader.SetRecFilter(); DocumentPrint.PrintSalesInvoiceToDocumentAttachment(SalesHeader, DocumentPrint.GetSalesInvoicePrintToAttachmentOption(Rec)); end; } } } area(Promoted) { group(Category_Process) { Caption = 'Process', Comment = 'Generated from the PromotedActionCategories property index 1.'; group(Category_Category5) { Caption = 'Posting', Comment = 'Generated from the PromotedActionCategories property index 4.'; ShowAs = SplitButton; actionref(Post_Promoted; Post) { } actionref(PostAndSend_Promoted; PostAndSend) { } actionref(Preview_Promoted; Preview) { } actionref(PostAndNew_Promoted; PostAndNew) { } } group(Category_Category8) { Caption = 'Release', Comment = 'Generated from the PromotedActionCategories property index 7.'; ShowAs = SplitButton; actionref(Release_Promoted; Release) { } actionref(Reopen_Promoted; Reopen) { } } } group(Category_Category6) { Caption = 'Prepare', Comment = 'Generated from the PromotedActionCategories property index 5.'; actionref(CopyDocument_Promoted; CopyDocument) { } actionref(GetRecurringSalesLines_Promoted; GetRecurringSalesLines) { } group("Category_Incoming Document") { Caption = 'Incoming Document'; actionref(IncomingDocAttachFile_Promoted; IncomingDocAttachFile) { } actionref(IncomingDocCard_Promoted; IncomingDocCard) { } actionref(SelectIncomingDoc_Promoted; SelectIncomingDoc) { } actionref(RemoveIncomingDoc_Promoted; RemoveIncomingDoc) { } } actionref(CalculateInvoiceDiscount_Promoted; CalculateInvoiceDiscount) { } actionref("Move Negative Lines_Promoted"; "Move Negative Lines") { } } group(Category_PrintSend) { Caption = 'Print/Send'; actionref(DraftInvoice_Promoted; DraftInvoice) { } actionref(ProformaInvoice_Promoted; ProformaInvoice) { } } group(Category_Category4) { Caption = 'Approve', Comment = 'Generated from the PromotedActionCategories property index 3.'; actionref(Approve_Promoted; Approve) { } actionref(Reject_Promoted; Reject) { } actionref(Comment_Promoted; Comment) { } actionref(Delegate_Promoted; Delegate) { } } group(Category_Category9) { Caption = 'Request Approval', Comment = 'Generated from the PromotedActionCategories property index 8.'; actionref(SendApprovalRequest_Promoted; SendApprovalRequest) { } actionref(CancelApprovalRequest_Promoted; CancelApprovalRequest) { } } group(Category_Category7) { Caption = 'Invoice', Comment = 'Generated from the PromotedActionCategories property index 6.'; actionref(Dimensions_Promoted; Dimensions) { } actionref(SalesStatistics_Promoted; SalesStatistics) { } actionref("Co&mments_Promoted"; "Co&mments") { } actionref(DocAttach_Promoted; DocAttach) { } actionref(Approvals_Promoted; Approvals) { } separator(Navigate_Separator) { } actionref(Function_CustomerCard_Promoted; Function_CustomerCard) { } } group(Category_Category10) { Caption = 'View', Comment = 'Generated from the PromotedActionCategories property index 9.'; } group(Category_Category11) { Caption = 'Navigate', Comment = 'Generated from the PromotedActionCategories property index 10.'; } group(Category_Report) { Caption = 'Report', Comment = 'Generated from the PromotedActionCategories property index 2.'; } } } trigger OnAfterGetCurrRecord() begin CurrPage.IncomingDocAttachFactBox.PAGE.LoadDataFromRecord(Rec); CurrPage.ApprovalFactBox.PAGE.UpdateApprovalEntriesFromSourceRecord(Rec.RecordId); ShowWorkflowStatus := CurrPage.WorkflowStatus.PAGE.SetFilterOnWorkflowRecord(Rec.RecordId); StatusStyleTxt := Rec.GetStatusStyleText(); UpdatePaymentService(); SetControlAppearance(); end; trigger OnAfterGetRecord() var ICInboxOutboxMgt: Codeunit ICInboxOutboxMgt; begin RejectICSalesInvoiceEnabled := ICInboxOutboxMgt.IsSalesHeaderFromIncomingIC(Rec); WorkDescription := Rec.GetWorkDescription(); UpdateShipToBillToGroupVisibility(); SellToContact.GetOrClear(Rec."Sell-to Contact No."); BillToContact.GetOrClear(Rec."Bill-to Contact No."); CurrPage.IncomingDocAttachFactBox.Page.SetCurrentRecordID(Rec.RecordId); OnAfterOnAfterGetRecord(Rec); end; trigger OnDeleteRecord(): Boolean var IsHandled: Boolean; Result: Boolean; begin CurrPage.SaveRecord(); OnBeforeOnDeleteRecord(Rec, Result, IsHandled); if IsHandled then exit(Result) else exit(Rec.ConfirmDeletion()); end; trigger OnInit() begin JobQueuesUsed := SalesSetup.JobQueueActive(); SetExtDocNoMandatoryCondition(); IsPowerAutomatePrivacyNoticeApproved := PrivacyNotice.GetPrivacyNoticeApprovalState(FlowServiceManagement.GetPowerAutomatePrivacyNoticeId()) = "Privacy Notice Approval State"::Agreed; end; trigger OnInsertRecord(BelowxRec: Boolean): Boolean begin if DocNoVisible then Rec.CheckCreditMaxBeforeInsert(); if (Rec."Sell-to Customer No." = '') and (Rec.GetFilter("Sell-to Customer No.") <> '') then CurrPage.Update(false); end; trigger OnNewRecord(BelowxRec: Boolean) begin xRec.Init(); Rec."Responsibility Center" := UserMgt.GetSalesFilter(); if (not DocNoVisible) and (Rec."No." = '') then Rec.SetSellToCustomerFromFilter(); Rec.SetDefaultPaymentServices(); UpdateShipToBillToGroupVisibility(); end; trigger OnOpenPage() var PaymentServiceSetup: Record "Payment Service Setup"; OfficeMgt: Codeunit "Office Management"; EnvironmentInfo: Codeunit "Environment Information"; ICInboxOutboxMgt: Codeunit ICInboxOutboxMgt; VATReportingDateMgt: Codeunit "VAT Reporting Date Mgt"; begin Rec.SetSecurityFilterOnRespCenter(); Rec.SetRange("Date Filter", 0D, WorkDate()); ActivateFields(); SetDocNoVisible(); if Rec."No." = '' then if OfficeMgt.CheckForExistingInvoice(Rec."Sell-to Customer No.") then Error(''); // Cancel invoice creation IsSaaS := EnvironmentInfo.IsSaaS(); if (Rec."No." <> '') and (Rec."Sell-to Customer No." = '') then DocumentIsPosted := (not Rec.Get(Rec."Document Type", Rec."No.")); PaymentServiceVisible := PaymentServiceSetup.IsPaymentServiceVisible(); CheckShowBackgrValidationNotification(); RejectICSalesInvoiceEnabled := ICInboxOutboxMgt.IsSalesHeaderFromIncomingIC(Rec); VATDateEnabled := VATReportingDateMgt.IsVATDateEnabled(); end; trigger OnQueryClosePage(CloseAction: Action): Boolean var Result: Boolean; IsHandled: Boolean; begin IsHandled := false; OnBeforeOnQueryClosePage(Rec, DocumentIsPosted, CloseAction, Result, IsHandled); if IsHandled then exit(Result); if not (SkipConfirmationDialogOnClosing or DocumentIsPosted) then exit(Rec.ConfirmCloseUnposted()); end; var SellToContact: Record Contact; BillToContact: Record Contact; SalesSetup: Record "Sales & Receivables Setup"; GLSetup: Record "General Ledger Setup"; MoveNegSalesLines: Report "Move Negative Sales Lines"; ApplicationAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade"; ReportPrint: Codeunit "Test Report-Print"; UserMgt: Codeunit "User Setup Management"; SalesCalcDiscountByType: Codeunit "Sales - Calc Discount By Type"; ApprovalsMgmt: Codeunit "Approvals Mgmt."; LinesInstructionMgt: Codeunit "Lines Instruction Mgt."; CustomerMgt: Codeunit "Customer Mgt."; FormatAddress: Codeunit "Format Address"; PrivacyNotice: Codeunit "Privacy Notice"; FlowServiceManagement: Codeunit "Flow Service Management"; ChangeExchangeRate: Page "Change Exchange Rate"; WorkDescription: Text; StatusStyleTxt: Text; HasIncomingDocument: Boolean; DocNoVisible: Boolean; ExternalDocNoMandatory: Boolean; OpenApprovalEntriesExistForCurrUser: Boolean; IsPowerAutomatePrivacyNoticeApproved: Boolean; OpenApprovalEntriesExist: Boolean; ShowWorkflowStatus: Boolean; PaymentServiceVisible: Boolean; PaymentServiceEnabled: Boolean; SureToRejectMsg: Label 'Rejecting this order will remove it from your company and send it back to the partner company.\\Do you want to continue?'; OpenPostedSalesInvQst: Label 'The invoice is posted as number %1 and moved to the Posted Sales Invoices window.\\Do you want to open the posted invoice?', Comment = '%1 = posted document number'; IsCustomerOrContactNotEmpty: Boolean; ShowQuoteNo: Boolean; JobQueuesUsed: Boolean; CanCancelApprovalForRecord: Boolean; EmptyShipToCodeErr: Label 'The Code field can only be empty if you select Custom Address in the Ship-to field.'; IsSaaS: Boolean; IsBillToCountyVisible: Boolean; IsSellToCountyVisible: Boolean; IsShipToCountyVisible: Boolean; SalesDocCheckFactboxVisible: Boolean; IsJournalTemplNameVisible: Boolean; IsPaymentMethodCodeVisible: Boolean; IsSalesLinesEditable: Boolean; ShouldSearchForCustByName: Boolean; CanRequestApprovalForFlow: Boolean; CanCancelApprovalForFlow: Boolean; RejectICSalesInvoiceEnabled: Boolean; VATDateEnabled: Boolean; protected var ShipToOptions: Enum "Sales Ship-to Options"; BillToOptions: Enum "Sales Bill-to Options"; DocumentIsPosted: Boolean; SkipConfirmationDialogOnClosing: Boolean; IsPostingGroupEditable: Boolean; local procedure ActivateFields() begin IsBillToCountyVisible := FormatAddress.UseCounty(Rec."Bill-to Country/Region Code"); IsSellToCountyVisible := FormatAddress.UseCounty(Rec."Sell-to Country/Region Code"); IsShipToCountyVisible := FormatAddress.UseCounty(Rec."Ship-to Country/Region Code"); GLSetup.Get(); IsJournalTemplNameVisible := GLSetup."Journal Templ. Name Mandatory"; IsPaymentMethodCodeVisible := not GLSetup."Hide Payment Method Code"; IsSalesLinesEditable := Rec.SalesLinesEditable(); end; /// <summary> /// Calls the document posting procedure with the specified posting codeunit and navigation option. /// </summary> /// <param name="PostingCodeunitID">The ID of the posting codeunit to execute.</param> /// <param name="Navigate">The navigation option after posting.</param> procedure CallPostDocument(PostingCodeunitID: Integer; Navigate: Enum "Navigate After Posting") begin PostDocument(PostingCodeunitID, Navigate); end; local procedure PostDocument(PostingCodeunitID: Integer; Navigate: Enum "Navigate After Posting") var SalesHeader: Record "Sales Header"; SalesInvoiceHeader: Record "Sales Invoice Header"; OfficeMgt: Codeunit "Office Management"; InstructionMgt: Codeunit "Instruction Mgt."; PageManagement: Codeunit "Page Management"; PreAssignedNo: Code[20]; xLastPostingNo: Code[20]; IsScheduledPosting: Boolean; IsHandled: Boolean; begin LinesInstructionMgt.SalesCheckAllLinesHaveQuantityAssigned(Rec); PreAssignedNo := Rec."No."; xLastPostingNo := Rec."Last Posting No."; Rec.SendToPosting(PostingCodeunitID); IsScheduledPosting := Rec."Job Queue Status" = Rec."Job Queue Status"::"Scheduled for Posting"; DocumentIsPosted := (not SalesHeader.Get(Rec."Document Type", Rec."No.")) or IsScheduledPosting; OnPostOnAfterSetDocumentIsPosted(SalesHeader, IsScheduledPosting, DocumentIsPosted); if IsScheduledPosting then CurrPage.Close(); CurrPage.Update(false); IsHandled := false; OnPostDocumentBeforeNavigateAfterPosting(Rec, PostingCodeunitID, Navigate, DocumentIsPosted, IsHandled); if IsHandled then exit; if PostingCodeunitID <> CODEUNIT::"Sales-Post (Yes/No)" then exit; if OfficeMgt.IsAvailable() then begin if (Rec."Last Posting No." <> '') and (Rec."Last Posting No." <> xLastPostingNo) then SalesInvoiceHeader.SetRange("No.", Rec."Last Posting No.") else begin SalesInvoiceHeader.SetCurrentKey("Pre-Assigned No."); SalesInvoiceHeader.SetRange("Pre-Assigned No.", PreAssignedNo); end; if SalesInvoiceHeader.FindFirst() then PageManagement.PageRun(SalesInvoiceHeader); end else case Navigate of Enum::"Navigate After Posting"::"Posted Document": if InstructionMgt.IsEnabled(InstructionMgt.ShowPostedConfirmationMessageCode()) then ShowPostedConfirmationMessage(PreAssignedNo, xLastPostingNo); Enum::"Navigate After Posting"::"New Document": if DocumentIsPosted then begin SalesHeader.Init(); SalesHeader.Validate("Document Type", SalesHeader."Document Type"::Invoice); OnPostOnBeforeSalesHeaderInsert(SalesHeader); SalesHeader.Insert(true); PAGE.Run(PAGE::"Sales Invoice", SalesHeader); end; else OnPostDocumentOnElseCaseNavigateAfterPosting(SalesHeader, PostingCodeunitID, Navigate); end; end; local procedure ApproveCalcInvDisc() begin Rec.TestStatusOpen(); CurrPage.SalesLines.PAGE.ApproveCalcInvDisc(); end; local procedure SaveInvoiceDiscountAmount() var DocumentTotals: Codeunit "Document Totals"; begin CurrPage.SaveRecord(); DocumentTotals.SalesRedistributeInvoiceDiscountAmountsOnDocument(Rec); CurrPage.Update(false); end; local procedure ShowPostedConfirmationMessage(PreAssignedNo: Code[20]; xLastPostingNo: Code[20]) var SalesInvoiceHeader: Record "Sales Invoice Header"; InstructionMgt: Codeunit "Instruction Mgt."; ICFeedback: Codeunit "IC Feedback"; begin if (Rec."Last Posting No." <> '') and (Rec."Last Posting No." <> xLastPostingNo) then SalesInvoiceHeader.SetRange("No.", Rec."Last Posting No.") else begin SalesInvoiceHeader.SetCurrentKey("Pre-Assigned No."); SalesInvoiceHeader.SetRange("Pre-Assigned No.", PreAssignedNo); end; if SalesInvoiceHeader.FindFirst() then begin ICFeedback.ShowIntercompanyMessage(Rec, Enum::"IC Transaction Document Type"::Invoice, SalesInvoiceHeader."No."); if InstructionMgt.ShowConfirm(StrSubstNo(OpenPostedSalesInvQst, SalesInvoiceHeader."No."), InstructionMgt.ShowPostedConfirmationMessageCode()) then InstructionMgt.ShowPostedDocument(SalesInvoiceHeader, Page::"Sales Invoice"); end; end; local procedure SalespersonCodeOnAfterValidate() begin CurrPage.SalesLines.PAGE.UpdatePage(true); end; local procedure SetDocNoVisible() var DocumentNoVisibility: Codeunit DocumentNoVisibility; DocType: Option Quote,"Order",Invoice,"Credit Memo","Blanket Order","Return Order",Reminder,FinChMemo; begin DocNoVisible := DocumentNoVisibility.SalesDocumentNoIsVisible(DocType::Invoice, Rec."No."); end; local procedure SetExtDocNoMandatoryCondition() begin SalesSetup.GetRecordOnce(); ExternalDocNoMandatory := SalesSetup."Ext. Doc. No. Mandatory"; end; local procedure ShowPreview() var SalesPostYesNo: Codeunit "Sales-Post (Yes/No)"; begin OnBeforeShowPreview(Rec); SalesPostYesNo.Preview(Rec); end; local procedure SetControlAppearance() var ApprovalsMgmt: Codeunit "Approvals Mgmt."; DocumentErrorsMgt: Codeunit "Document Errors Mgt."; WorkflowWebhookMgt: Codeunit "Workflow Webhook Management"; begin HasIncomingDocument := Rec."Incoming Document Entry No." <> 0; ShowQuoteNo := Rec."Quote No." <> ''; SetExtDocNoMandatoryCondition(); SetPostingGroupEditable(); OpenApprovalEntriesExistForCurrUser := ApprovalsMgmt.HasOpenApprovalEntriesForCurrentUser(Rec.RecordId); OpenApprovalEntriesExist := ApprovalsMgmt.HasOpenApprovalEntries(Rec.RecordId); CanCancelApprovalForRecord := ApprovalsMgmt.CanCancelApprovalForRecord(Rec.RecordId); IsCustomerOrContactNotEmpty := (Rec."Sell-to Customer No." <> '') or (Rec."Sell-to Contact No." <> ''); IsSalesLinesEditable := Rec.SalesLinesEditable(); SalesDocCheckFactboxVisible := DocumentErrorsMgt.BackgroundValidationEnabled(); WorkflowWebhookMgt.GetCanRequestAndCanCancel(Rec.RecordId, CanRequestApprovalForFlow, CanCancelApprovalForFlow); ShouldSearchForCustByName := Rec.ShouldSearchForCustomerByName(Rec."Sell-to Customer No."); end; /// <summary> /// Runs a background check for document errors. /// </summary> procedure RunBackgroundCheck() begin CurrPage.SalesDocCheckFactbox.Page.CheckErrorsInBackground(Rec); end; local procedure CheckShowBackgrValidationNotification() var DocumentErrorsMgt: Codeunit "Document Errors Mgt."; begin if DocumentErrorsMgt.CheckShowEnableBackgrValidationNotification() then SetControlAppearance(); end; /// <summary> /// Sets whether to skip the confirmation dialog when closing the page. /// </summary> /// <param name="Skip">Whether to skip the confirmation dialog.</param> procedure SetSkipConfirmationDialogOnClosing(Skip: Boolean) begin SkipConfirmationDialogOnClosing := Skip; end; protected procedure UpdatePaymentService() var PaymentServiceSetup: Record "Payment Service Setup"; begin PaymentServiceEnabled := PaymentServiceSetup.CanChangePaymentService(Rec); end; /// <summary> /// Sets whether the posting group field should be editable based on customer settings. /// </summary> procedure SetPostingGroupEditable() var BillToCustomer: Record Customer; begin if BillToCustomer.Get(Rec."Bill-to Customer No.") then IsPostingGroupEditable := BillToCustomer."Allow Multiple Posting Groups"; end; local procedure UpdateShipToBillToGroupVisibility() begin CustomerMgt.CalculateShipBillToOptions(ShipToOptions, BillToOptions, Rec); end; [IntegrationEvent(true, false)] local procedure OnAfterOnAfterGetRecord(var SalesHeader: Record "Sales Header") begin end; [IntegrationEvent(false, false)] local procedure OnBeforeShowPreview(var SalesHeader: Record "Sales Header") begin end; [IntegrationEvent(false, false)] local procedure OnPostOnAfterSetDocumentIsPosted(SalesHeader: Record "Sales Header"; var IsScheduledPosting: Boolean; var DocumentIsPosted: Boolean) begin end; [IntegrationEvent(false, false)] local procedure OnPostOnBeforeSalesHeaderInsert(var SalesHeader: Record "Sales Header") begin end; [IntegrationEvent(false, false)] local procedure OnBeforeValidateShipToOptions(var SalesHeader: Record "Sales Header"; ShipToOptions: Option; var IsHandled: Boolean) begin end; [IntegrationEvent(false, false)] local procedure OnAfterValidateShipToOptions(var SalesHeader: Record "Sales Header"; ShipToOptions: Option) begin end; [IntegrationEvent(true, false)] local procedure OnPostDocumentBeforeNavigateAfterPosting(var SalesHeader: Record "Sales Header"; var PostingCodeunitID: Integer; var Navigate: Enum "Navigate After Posting"; DocumentIsPosted: Boolean; var IsHandled: Boolean) begin end; [IntegrationEvent(true, false)] local procedure OnBeforeOnDeleteRecord(var SalesHeader: Record "Sales Header"; var Result: Boolean; var IsHandled: Boolean); begin end; [IntegrationEvent(true, false)] local procedure OnBeforeOnQueryClosePage(var SalesHeader: Record "Sales Header"; DocumentIsPosted: Boolean; CloseAction: Action; var Result: Boolean; var IsHandled: Boolean) begin end; [IntegrationEvent(false, false)] local procedure OnBeforeLookupBillToName(var Customer: Record Customer; SalesHeader: Record "Sales Header") begin end; [IntegrationEvent(true, false)] local procedure OnPostDocumentOnElseCaseNavigateAfterPosting(var SalesHeader: Record "Sales Header"; PostingCodeunitID: Integer; Navigate: Enum "Navigate After Posting") begin end;}