Codeunit 1325 Cancel PstdPurchInv (Yes/No)
src/Layers/W1/BaseApp/Purchases/History/CancelPstdPurchInvYesNo.Codeunit.al69 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.Purchases.History;using Microsoft.Utilities;codeunit 1325 "Cancel PstdPurchInv (Yes/No)"{ Permissions = TableData "Purch. Inv. Header" = rm, TableData "Purch. Cr. Memo Hdr." = rm; TableNo = "Purch. Inv. Header"; trigger OnRun() begin CancelInvoice(Rec); end; var CancelPostedInvoiceFromOrderQst: Label 'This invoice was posted from a purchase order. To cancel it, a purchase credit memo will be created and posted. The quantities from the original purchase order will be restored, provided the purchase order still exists.\ \Do you want to continue?'; CancelPostedInvoiceQst: Label 'The posted purchase invoice will be canceled, and a purchase credit memo will be created and posted.\ \Do you want to continue?'; OpenPostedCreditMemoQst: Label 'A credit memo was successfully created. Do you want to open the posted credit memo?'; procedure CancelInvoice(var PurchInvHeader: Record "Purch. Inv. Header"): Boolean var PurchCrMemoHdr: Record "Purch. Cr. Memo Hdr."; CancelledDocument: Record "Cancelled Document"; CorrectPostedPurchInvoice: Codeunit "Correct Posted Purch. Invoice"; IsHandled: Boolean; begin IsHandled := false; OnCancelInvoiceOnBeforeTestCorrectInvoiceIsAllowed(PurchInvHeader, IsHandled); if not IsHandled then CorrectPostedPurchInvoice.TestCorrectInvoiceIsAllowed(PurchInvHeader, true); if Confirm(GetCancelPostedInvoiceQst(PurchInvHeader)) then if CorrectPostedPurchInvoice.CancelPostedInvoice(PurchInvHeader) then if Confirm(OpenPostedCreditMemoQst) then begin CancelledDocument.FindPurchCancelledInvoice(PurchInvHeader."No."); PurchCrMemoHdr.Get(CancelledDocument."Cancelled By Doc. No."); IsHandled := false; OnBeforeShowPostedPurchaseCreditMemo(PurchCrMemoHdr, IsHandled); if not IsHandled then PAGE.Run(PAGE::"Posted Purchase Credit Memo", PurchCrMemoHdr); exit(true); end; exit(false); end; local procedure GetCancelPostedInvoiceQst(PurchInvHeader: Record "Purch. Inv. Header"): Text begin if PurchInvHeader."Order No." <> '' then exit(CancelPostedInvoiceFromOrderQst); exit(CancelPostedInvoiceQst); end; [IntegrationEvent(false, false)] local procedure OnBeforeShowPostedPurchaseCreditMemo(var PurchCrMemoHdr: Record "Purch. Cr. Memo Hdr."; var IsHandled: Boolean) begin end; [IntegrationEvent(false, false)] local procedure OnCancelInvoiceOnBeforeTestCorrectInvoiceIsAllowed(var PurchInvHeader: Record "Purch. Inv. Header"; var IsHandled: Boolean) begin end;}