From d89a2a0c60da06d51fd257a0dddb875e3f36d761 Mon Sep 17 00:00:00 2001 From: Adele Smiciene Date: Mon, 6 Jan 2025 10:05:35 +0200 Subject: [PATCH 1/9] extending the Core app with payments --- .../app/src/Document/EDocument.Page.al | 93 +++++++++++++ .../app/src/Document/EDocument.Table.al | 15 +- .../Helpers/EDocumentErrorHelper.Codeunit.al | 14 ++ .../EmptyPaymentHandler.Codeunit.al | 33 +++++ .../IDocumentPaymentHandler.Interface.al | 21 +++ .../Payments/GetPaymentDetails.Codeunit.al | 47 +++++++ .../Payments/PaymentContext.Codeunit.al | 67 +++++++++ .../Payments/PaymentIntegration.Enum.al | 18 +++ .../PaymentIntegrationManagement.Codeunit.al | 130 ++++++++++++++++++ .../Payments/ReceivePayments.Codeunit.al | 54 ++++++++ .../Payments/SendPayment.Codeunit.al | 40 ++++++ .../Payments/SyncPaymentsJob.Codeunit.al | 51 +++++++ .../src/Payments/EDocumentPayment.Table.al | 89 ++++++++++++ .../Payments/EDocumentPaymentProgress.Enum.al | 27 ++++ .../src/Payments/EDocumentPayments.Page.al | 61 ++++++++ .../app/src/Payments/PaymentStatus.Enum.al | 31 +++++ .../EDocumentBackgroundJobs.Codeunit.al | 38 +++++ .../app/src/Service/EDocumentService.Table.al | 45 ++++++ .../app/src/Service/EdocumentService.Page.al | 33 +++++ 19 files changed, 906 insertions(+), 1 deletion(-) create mode 100644 Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al create mode 100644 Apps/W1/EDocument/app/src/Integration/Interfaces/IDocumentPaymentHandler.Interface.al create mode 100644 Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al create mode 100644 Apps/W1/EDocument/app/src/Integration/Payments/PaymentContext.Codeunit.al create mode 100644 Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegration.Enum.al create mode 100644 Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al create mode 100644 Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al create mode 100644 Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al create mode 100644 Apps/W1/EDocument/app/src/Integration/Payments/SyncPaymentsJob.Codeunit.al create mode 100644 Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al create mode 100644 Apps/W1/EDocument/app/src/Payments/EDocumentPaymentProgress.Enum.al create mode 100644 Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al create mode 100644 Apps/W1/EDocument/app/src/Payments/PaymentStatus.Enum.al diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al index d975f90883..20da3c25df 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al @@ -11,6 +11,8 @@ using Microsoft.eServices.EDocument.Integration.Receive; using Microsoft.Bank.Reconciliation; using Microsoft.eServices.EDocument.OrderMatch; using Microsoft.eServices.EDocument.OrderMatch.Copilot; +using Microsoft.eServices.EDocument.Integration.Payments; +using Microsoft.eServices.EDocument.Payments; page 6121 "E-Document" { @@ -119,6 +121,18 @@ page 6121 "E-Document" Importance = Additional; ToolTip = 'Specifies the electronic document posting date.'; } + field("Payment Status"; this.PaymentStatus) + { + Caption = 'Payment Status'; + Visible = false; + Editable = false; + ToolTip = 'Specifies the payment status of the electronic document.'; + } + field("Paid Amount"; Rec."Paid Amount") + { + Visible = false; + ToolTip = 'Specifies the paid amount of the electronic document.'; + } } group(ReceivingCompanyInfo) { @@ -346,6 +360,34 @@ page 6121 "E-Document" end; } } + group(Payments) + { + Caption = 'Payments'; + action(ReceivePayments) + { + Caption = 'Receive Payments'; + ToolTip = 'Receive payments for the electronic document.'; + Image = Payment; + Visible = false; + + trigger OnAction() + begin + this.ReceivePaymentsForEDoc(); + end; + } + action(SendPayments) + { + Caption = 'Send Payment'; + ToolTip = 'Send payment for the electronic document.'; + Image = Payment; + Visible = false; + + trigger OnAction() + begin + this.SendPaymentsForEDoc(); + end; + } + } group(Troubleshoot) { Caption = 'Troubleshoot'; @@ -507,6 +549,13 @@ page 6121 "E-Document" SetIncomingDocActions(); EDocImport.ProcessEDocPendingOrderMatch(Rec); + + if (Rec.Direction = Rec.Direction::Incoming) then + Rec.SetRange("Payment Direction Filter", "E-Document Direction"::Outgoing) + else + Rec.SetRange("Payment Direction Filter", "E-Document Direction"::Incoming); + + this.SetPaymentStatus(); end; local procedure SetStyle() @@ -589,6 +638,49 @@ page 6121 "E-Document" ShowRelink := false; end; + local procedure SetPaymentStatus() + begin + if Rec."Paid Amount" = 0 then + this.PaymentStatus := this.PaymentStatus::"Not Paid" + else + if Rec."Paid Amount" < Rec."Amount Incl. VAT" then + this.PaymentStatus := this.PaymentStatus::"Partially Paid" + else + this.PaymentStatus := this.PaymentStatus::"Paid In Full" + end; + + local procedure ReceivePaymentsForEDoc() + var + EDocService: Record "E-Document Service"; + PaymentContext: Codeunit PaymentContext; + PaymentIntegrationManagement: Codeunit "Payment Integration Management"; + EDocServices: Page "E-Document Services"; + begin + EDocServices.LookupMode(true); + if EDocServices.RunModal() <> Action::LookupOK then + exit; + + EDocServices.GetRecord(EDocService); + this.EDocumentErrorHelper.ClearPaymentErrorMessages(Rec); + PaymentIntegrationManagement.ReceivePayments(Rec, EDocService, PaymentContext); + end; + + local procedure SendPaymentsForEDoc() + var + EDocService: Record "E-Document Service"; + PaymentContext: Codeunit PaymentContext; + PaymentIntegrationManagement: Codeunit "Payment Integration Management"; + EDocServices: Page "E-Document Services"; + begin + EDocServices.LookupMode(true); + if EDocServices.RunModal() <> Action::LookupOK then + exit; + + EDocServices.GetRecord(EDocService); + this.EDocumentErrorHelper.ClearPaymentErrorMessages(Rec); + PaymentIntegrationManagement.SendPayments(Rec, EDocService, PaymentContext); + end; + var EDocumentBackgroundjobs: Codeunit "E-Document Background Jobs"; EDocIntegrationManagement: Codeunit "E-Doc. Integration Management"; @@ -596,6 +688,7 @@ page 6121 "E-Document" EDocumentErrorHelper: Codeunit "E-Document Error Helper"; EDocumentHelper: Codeunit "E-Document Processing"; ErrorsAndWarningsNotification: Notification; + PaymentStatus: Enum "E-Document Payment Progress"; RecordLinkTxt, StyleStatusTxt : Text; ShowRelink, ShowMapToOrder, HasErrorsOrWarnings, HasErrors, IsIncomingDoc, IsProcessed, CopilotVisible : Boolean; EDocHasErrorOrWarningMsg: Label 'Errors or warnings found for E-Document. Please review below in "Error Messages" section.'; diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Table.al b/Apps/W1/EDocument/app/src/Document/EDocument.Table.al index 4ec6ab4122..215e7bceea 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Table.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Table.al @@ -11,6 +11,7 @@ using System.Automation; using System.IO; using System.Reflection; using System.Threading; +using Microsoft.eServices.EDocument.Payments; table 6121 "E-Document" { @@ -182,7 +183,19 @@ table 6121 "E-Document" Caption = 'Receiving Company Id'; ToolTip = 'Specifies the receiving company id, such as PEPPOL id, or other identifiers used in the electronic document exchange.'; } - + field(32; "Paid Amount"; Decimal) + { + Caption = 'Paid Amount'; + Editable = false; + FieldClass = FlowField; + CalcFormula = sum("E-Document Payment".Amount where("E-Document Entry No." = field("Entry No"), Direction = field("Payment Direction Filter"))); + } + field(33; "Payment Direction Filter"; Enum "E-Document Direction") + { + Caption = 'Payment Direction Filter'; + Editable = false; + FieldClass = FlowFilter; + } } keys { diff --git a/Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al b/Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al index b58704193d..9be2abf35a 100644 --- a/Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al @@ -6,6 +6,7 @@ namespace Microsoft.eServices.EDocument; using System.Telemetry; using System.Utilities; +using Microsoft.eServices.EDocument.Payments; codeunit 6115 "E-Document Error Helper" { @@ -105,6 +106,19 @@ codeunit 6115 "E-Document Error Helper" ErrorMessage.LogSimpleMessage(ErrorMessage."Message Type"::Error, Message); end; + /// + /// Use it to clear errors for E-Document related to payments. + /// + /// The E-Document record. + procedure ClearPaymentErrorMessages(EDocument: Record "E-Document") + var + ErrorMessage: Record "Error Message"; + begin + ErrorMessage.SetRange("Context Record ID", EDocument.RecordId()); + ErrorMessage.SetRange("Table Number", Database::"E-Document Payment"); + ErrorMessage.DeleteAll(); + end; + internal procedure GetTelemetryImplErrLbl(): Text begin exit(EDocTelemetryImplErr); diff --git a/Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al new file mode 100644 index 0000000000..f5b48a91cf --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al @@ -0,0 +1,33 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Payments; + +using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Integration.Interfaces; +using Microsoft.eServices.EDocument.Payments; +using System.Utilities; + +/// +/// This codeunit is used to implement the "Document Payment Handler" interface. It is used to provide a default implementation for the "Action Invoker" interface. +/// +codeunit 6105 "Empty Payment Handler" implements IDocumentPaymentHandler +{ + Access = Internal; + InherentEntitlements = X; + InherentPermissions = X; + + procedure Send(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext) + begin + end; + + procedure Receive(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var PaymentsMetadata: Codeunit "Temp Blob List"; PaymentContext: Codeunit PaymentContext) + begin + end; + + procedure GetDetails(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; PaymentContext: Codeunit PaymentContext) + begin + end; + +} \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Integration/Interfaces/IDocumentPaymentHandler.Interface.al b/Apps/W1/EDocument/app/src/Integration/Interfaces/IDocumentPaymentHandler.Interface.al new file mode 100644 index 0000000000..8d18748817 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Interfaces/IDocumentPaymentHandler.Interface.al @@ -0,0 +1,21 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Interfaces; + +using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Integration.Payments; +using System.Utilities; + +/// +/// Interface for sending and receiving paymnet information for E-Documents using E-Document service +/// +interface IDocumentPaymentHandler +{ + procedure Send(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext) + + procedure Receive(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var PaymentsMetadata: Codeunit "Temp Blob List"; PaymentContext: Codeunit PaymentContext) + + procedure GetDetails(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; PaymentContext: Codeunit PaymentContext) +} diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al new file mode 100644 index 0000000000..3dfda82c1d --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al @@ -0,0 +1,47 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Payments; + + +using System.Utilities; +using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Integration.Interfaces; + +codeunit 6107 "Get Payment Details" +{ + Access = Internal; + InherentEntitlements = X; + InherentPermissions = X; + + trigger OnRun() + begin + this.EDocumentService.TestField(Code); + this.IDocumentPaymentHandler.GetDetails(this.EDocument, this.EDocumentService, this.PaymentMetadata, this.PaymentContext); + end; + + procedure SetContext(PaymentContext: Codeunit PaymentContext) + begin + this.PaymentContext := PaymentContext; + end; + + procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) + begin + this.IDocumentPaymentHandler := PaymentHandler; + end; + + procedure SetParameters(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob") + begin + this.EDocument.Copy(EDocument); + this.EDocumentService.Copy(EDocumentService); + this.PaymentMetadata := PaymentMetadata; + end; + + var + EDocument: Record "E-Document"; + EDocumentService: Record "E-Document Service"; + PaymentMetadata: Codeunit "Temp Blob"; + PaymentContext: Codeunit PaymentContext; + IDocumentPaymentHandler: Interface IDocumentPaymentHandler; +} diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentContext.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentContext.Codeunit.al new file mode 100644 index 0000000000..5c4d83c421 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentContext.Codeunit.al @@ -0,0 +1,67 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Payments; + +using Microsoft.eServices.EDocument.Integration; +using Microsoft.eServices.EDocument.Payments; + +codeunit 6104 PaymentContext +{ + /// + /// Get the Http Message State codeunit. + /// + procedure Http(): Codeunit "Http Message State" + begin + exit(this.HttpMessageState); + end; + + /// + /// Retrieves the payment date. + /// + procedure GetDate(): Date + begin + exit(this.Date); + end; + + /// + /// Retrieves the payment amount. + /// + procedure GetAmount(): Decimal + begin + exit(this.Amount); + end; + + /// + /// Sets the payment date and amount. + /// + procedure SetPaymentInformation(Date: Date; Amount: Decimal) + begin + this.Date := Date; + this.Amount := Amount; + end; + + /// + /// Retrieves the payment status. + /// + procedure GetPaymentStatus(): Enum "Payment Status" + begin + exit(this.PaymentStatus); + end; + + /// + /// Sets the payment status. + /// + procedure SetPaymentStatus(NewPaymentStatus: Enum "Payment Status") + begin + this.PaymentStatus := NewPaymentStatus; + end; + + var + HttpMessageState: Codeunit "Http Message State"; + PaymentStatus: Enum "Payment Status"; + Date: Date; + Amount: Decimal; + +} \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegration.Enum.al b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegration.Enum.al new file mode 100644 index 0000000000..d8dd11e960 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegration.Enum.al @@ -0,0 +1,18 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Payments; +using Microsoft.eServices.EDocument.Integration.Interfaces; + +enum 6105 "Payment Integration" implements IDocumentPaymentHandler +{ + Extensible = true; + Access = Public; + + value(0; "No Integration") + { + Caption = 'No Integration'; + Implementation = IDocumentPaymentHandler = "Empty Payment Handler"; + } +} \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al new file mode 100644 index 0000000000..694c2a0daa --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al @@ -0,0 +1,130 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Payments; + +using System.Utilities; +using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Payments; +using Microsoft.eServices.EDocument.Integration.Interfaces; + +codeunit 6117 "Payment Integration Management" +{ + internal procedure ReceivePayments(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext) + var + PaymentMetadata: Codeunit "Temp Blob"; + PaymentsMetadata: Codeunit "Temp Blob List"; + IDocumentPaymentHandler: Interface IDocumentPaymentHandler; + Index: Integer; + begin + IDocumentPaymentHandler := EDocumentService."Payment Integration"; + this.RunReceivePayments(EDocument, EDocumentService, PaymentsMetadata, IDocumentPaymentHandler, PaymentContext); + + if PaymentsMetadata.IsEmpty() then + exit; + + for Index := 1 to PaymentsMetadata.Count() do begin + PaymentsMetadata.Get(Index, PaymentMetadata); + this.ReceivePaymentDetails(EDocument, EDocumentService, PaymentMetadata, IDocumentPaymentHandler); + end; + end; + + internal procedure SendPayments(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext) + var + Payment: Record "E-Document Payment"; + begin + Payment.SetRange("E-Document Entry No.", EDocument."Entry No"); + Payment.SetFilter(Status, '%1|%2', Payment.Status::Created, Payment.Status::"Sending Error"); + + if not Payment.FindSet() then + exit; + + repeat + this.SendPayment(EDocument, EDocumentService, Payment); + until Payment.Next() = 0; + end; + + local procedure RunReceivePayments(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; Payments: Codeunit "Temp Blob List"; IDocumentPaymentHandler: Interface IDocumentPaymentHandler; PaymentContext: Codeunit PaymentContext) + var + ReceivePayments: Codeunit "Receive Payments"; + begin + // Commit needed for "if codeunit run" pattern when catching errors. + Commit(); + + ReceivePayments.SetInstance(IDocumentPaymentHandler); + ReceivePayments.SetService(EDocumentService); + ReceivePayments.SetDocument(EDocument); + ReceivePayments.SetContext(PaymentContext); + ReceivePayments.SetPayments(Payments); + if not ReceivePayments.Run() then + this.EDocumentErrorHelper.LogErrorMessage(EDocument, Database::"E-Document Payment", EDocument.FieldNo("Paid Amount"), StrSubstNo(this.PaymentReceiveErr, GetLastErrorText())); + end; + + local procedure ReceivePaymentDetails(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; IDocumentPaymentHandler: Interface IDocumentPaymentHandler) + var + Payment: Record "E-Document Payment"; + PaymentContext: Codeunit PaymentContext; + begin + PaymentContext.SetPaymentStatus("Payment Status"::Received); + + this.RunGetPaymentDetails(EDocument, EDocumentService, PaymentMetadata, IDocumentPaymentHandler, PaymentContext); + + if (PaymentContext.GetAmount() = 0) or (PaymentContext.GetDate() = 0D) then + exit; + + Payment.Init(); + Payment."E-Document Entry No." := EDocument."Entry No"; + Payment.Direction := Payment.Direction::Incoming; + Payment.Date := PaymentContext.GetDate(); + Payment.Validate(Amount, PaymentContext.GetAmount()); + Payment.Status := PaymentContext.GetPaymentStatus(); + Payment.Insert(); + end; + + local procedure RunGetPaymentDetails(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; IDocumentPaymentHandler: Interface IDocumentPaymentHandler; PaymentContext: Codeunit PaymentContext): Boolean + var + GetPaymentDetails: Codeunit "Get Payment Details"; + begin + // Commit needed for "if codeunit run" pattern when catching errors. + Commit(); + + GetPaymentDetails.SetInstance(IDocumentPaymentHandler); + GetPaymentDetails.SetContext(PaymentContext); + GetPaymentDetails.SetParameters(EDocument, EDocumentService, PaymentMetadata); + if not GetPaymentDetails.Run() then + this.EDocumentErrorHelper.LogErrorMessage(EDocument, Database::"E-Document Payment", EDocument.FieldNo("Paid Amount"), StrSubstNo(this.PaymentReceiveErr, GetLastErrorText())); + end; + + local procedure SendPayment(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; Payment: Record "E-Document Payment") + var + PaymentContext: Codeunit PaymentContext; + begin + PaymentContext.SetPaymentStatus("Payment Status"::Sent); + + this.RunSendPayment(EDocument, EDocumentService, Payment, EDocumentService."Payment Integration", PaymentContext); + + Payment.Status := PaymentContext.GetPaymentStatus(); + Payment.Modify(false); + end; + + local procedure RunSendPayment(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; Payment: Record "E-Document Payment"; IDocumentPaymentHandler: Interface IDocumentPaymentHandler; PaymentContext: Codeunit PaymentContext): Boolean + var + SendPayment: Codeunit "Send Payment"; + begin + // Commit needed for "if codeunit run" pattern when catching errors. + Commit(); + + SendPayment.SetInstance(IDocumentPaymentHandler); + SendPayment.SetDocumentAndService(EDocument, EDocumentService); + SendPayment.SetContext(PaymentContext); + + if not SendPayment.Run() then + this.EDocumentErrorHelper.LogErrorMessage(EDocument, Payment, EDocument.FieldNo("Paid Amount"), StrSubstNo(this.PaymentSendErr, GetLastErrorText())); + end; + + var + EDocumentErrorHelper: Codeunit "E-Document Error Helper"; + PaymentSendErr: Label 'Sending payments for this document failed with error: %1', Comment = '%1 - error message'; + PaymentReceiveErr: Label 'Receiving payments for this document failed with error: %1', Comment = '%1 - error message'; +} diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al new file mode 100644 index 0000000000..b121535af9 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al @@ -0,0 +1,54 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Payments; + +using System.Utilities; +using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Integration.Interfaces; + +codeunit 6106 "Receive Payments" +{ + Access = Internal; + InherentEntitlements = X; + InherentPermissions = X; + + trigger OnRun() + begin + EDocumentService.TestField(Code); + IDocumentPaymentHandler.Receive(this.EDocument, this.EDocumentService, this.PaymentsMetadata, this.PaymentContext); + end; + + procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) + begin + this.IDocumentPaymentHandler := PaymentHandler; + end; + + procedure SetContext(PaymentContext: Codeunit PaymentContext) + begin + this.PaymentContext := PaymentContext; + end; + + procedure SetPayments(PaymentsMetadata: Codeunit "Temp Blob List") + begin + this.PaymentsMetadata := PaymentsMetadata + end; + + procedure SetService(var EDocumentService: Record "E-Document Service") + begin + this.EDocumentService.Copy(EDocumentService); + end; + + procedure SetDocument(var EDocument: Record "E-Document") + begin + this.EDocument.Copy(EDocument); + end; + + var + EDocument: Record "E-Document"; + EDocumentService: Record "E-Document Service"; + PaymentsMetadata: Codeunit "Temp Blob List"; + PaymentContext: Codeunit PaymentContext; + IDocumentPaymentHandler: Interface IDocumentPaymentHandler; +} diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al new file mode 100644 index 0000000000..ee074ed0d3 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al @@ -0,0 +1,40 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Payments; + +using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Integration.Interfaces; +using Microsoft.eServices.EDocument.Payments; + +codeunit 6116 "Send Payment" +{ + trigger OnRun() + begin + this.EDocumentService.TestField(Code); + this.IPaymentHandler.Send(this.EDocument, this.EDocumentService, this.PaymentContext); + end; + + procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) + begin + this.IPaymentHandler := PaymentHandler; + end; + + procedure SetContext(PaymentContext: Codeunit PaymentContext) + begin + this.PaymentContext := PaymentContext; + end; + + procedure SetDocumentAndService(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service") + begin + this.EDocument.Copy(EDocument); + this.EDocumentService.Copy(EDocumentService); + end; + + var + EDocument: Record "E-Document"; + EDocumentService: Record "E-Document Service"; + PaymentContext: Codeunit PaymentContext; + IPaymentHandler: Interface IDocumentPaymentHandler; +} diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/SyncPaymentsJob.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/SyncPaymentsJob.Codeunit.al new file mode 100644 index 0000000000..24ebeb9b07 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Integration/Payments/SyncPaymentsJob.Codeunit.al @@ -0,0 +1,51 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Integration.Payments; + +using System.Threading; +using Microsoft.eServices.EDocument; + +codeunit 6119 "Sync Payments Job" +{ + Access = Internal; + TableNo = "Job Queue Entry"; + + trigger OnRun() + var + EDocument: Record "E-Document"; + EDocumentService: Record "E-Document Service"; + EDocumentServiceStatus: Record "E-Document Service Status"; + begin + EDocumentService.Get(Rec."Record ID to Process"); + if EDocumentService."Payment Integration" = EDocumentService."Payment Integration"::"No Integration" then + exit; + + EDocumentServiceStatus.SetRange("E-Document Service Code", EDocumentService."Code"); + if EDocumentServiceStatus.FindSet() then + repeat + EDocument.Get(EDocumentServiceStatus."E-Document Entry No"); + if EDocument."Direction" = EDocument.Direction::Incoming then + this.SendPayments(EDocument, EDocumentService) + else + this.ReceivePayments(EDocument, EDocumentService); + until EDocumentServiceStatus.Next() = 0; + end; + + local procedure SendPayments(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service") + var + PaymentContext: Codeunit PaymentContext; + PaymentIntegrationManagement: Codeunit "Payment Integration Management"; + begin + PaymentIntegrationManagement.SendPayments(EDocument, EDocumentService, PaymentContext); + end; + + local procedure ReceivePayments(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service") + var + PaymentContext: Codeunit PaymentContext; + PaymentIntegrationManagement: Codeunit "Payment Integration Management"; + begin + PaymentIntegrationManagement.ReceivePayments(EDocument, EDocumentService, PaymentContext); + end; +} \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al new file mode 100644 index 0000000000..98293cc0c5 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al @@ -0,0 +1,89 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Payments; + +using Microsoft.eServices.EDocument; + +table 6101 "E-Document Payment" +{ + Caption = 'E-Document Payment'; + DataClassification = CustomerContent; + DrillDownPageId = "E-Document Payments"; + LookupPageId = "E-Document Payments"; + + fields + { + field(1; "E-Document Entry No."; Integer) + { + Caption = 'E-Document Entry No.'; + TableRelation = "E-Document"."Entry No"; + } + field(2; "Payment No."; Integer) + { + Caption = 'Payment No.'; + AutoIncrement = true; + } + field(20; "Date"; Date) + { + Caption = 'Date'; + } + field(21; Amount; Decimal) + { + Caption = 'Amount'; + DecimalPlaces = 2; + + trigger OnValidate() + begin + this.CalculateVAT(); + end; + } + field(22; "VAT Base"; Decimal) + { + Caption = 'VAT Base'; + DecimalPlaces = 2; + } + field(23; "VAT Amount"; Decimal) + { + Caption = 'VAT Amount'; + DecimalPlaces = 2; + } + field(24; Status; Enum "Payment Status") + { + Caption = 'Status'; + } + field(25; Direction; Enum "E-Document Direction") + { + Caption = 'Direction'; + } + } + keys + { + key(PK; "E-Document Entry No.", "Payment No.") + { + Clustered = true; + } + } + + trigger OnInsert() + begin + if Rec.Status = Rec.Status::" " then + Rec.Status := Rec.Status::Created; + end; + + local procedure CalculateVAT() + var + EDocument: Record "E-Document"; + EDocumentService: Record "E-Document Service"; + EDocLog: Codeunit "E-Document Log"; + begin + EDocument.Get(Rec."E-Document Entry No."); + EDocumentService := EDocLog.GetLastServiceFromLog(EDocument); + if not EDocumentService."Calculate Payment VAT" then + exit; + + Rec."VAT Base" := Rec.Amount / (EDocument."Amount Incl. VAT" / EDocument."Amount Excl. VAT"); + Rec."VAT Amount" := Rec.Amount - Rec."VAT Base"; + end; +} \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPaymentProgress.Enum.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPaymentProgress.Enum.al new file mode 100644 index 0000000000..78185309de --- /dev/null +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPaymentProgress.Enum.al @@ -0,0 +1,27 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Payments; + +enum 6104 "E-Document Payment Progress" +{ + Extensible = false; + + value(0; " ") + { + Caption = ' '; + } + value(1; "Not Paid") + { + Caption = 'Not Paid'; + } + value(2; "Partially Paid") + { + Caption = 'Partially Paid'; + } + value(3; "Paid In Full") + { + Caption = 'Paid In Full'; + } +} diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al new file mode 100644 index 0000000000..55b995ae70 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al @@ -0,0 +1,61 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Payments; + +page 6101 "E-Document Payments" +{ + ApplicationArea = All; + Caption = 'E-Document Payments'; + PageType = List; + SourceTable = "E-Document Payment"; + UsageCategory = Lists; + + layout + { + area(Content) + { + repeater(General) + { + field("Date"; Rec."Date") + { + ApplicationArea = All; + ToolTip = 'Specifies the value of the Date field.'; + } + field(Amount; Rec.Amount) + { + ApplicationArea = All; + ToolTip = 'Specifies the value of the Amount field.'; + } + field("VAT Base"; Rec."VAT Base") + { + ApplicationArea = All; + ToolTip = 'Specifies the value of the VAT Base field.'; + Visible = false; + } + field("VAT Amount"; Rec."VAT Amount") + { + ApplicationArea = All; + ToolTip = 'Specifies the value of the VAT Amount field.'; + Visible = false; + } + field(Status; Rec.Status) + { + ApplicationArea = All; + ToolTip = 'Specifies the value of the Status field.'; + } + field(Direction; Rec.Direction) + { + ApplicationArea = All; + ToolTip = 'Specifies the value of the Direction field.'; + } + } + } + } + + trigger OnNewRecord(BelowxRec: Boolean) + begin + Evaluate(Rec.Direction, Rec.GetFilter("Direction")); + end; +} diff --git a/Apps/W1/EDocument/app/src/Payments/PaymentStatus.Enum.al b/Apps/W1/EDocument/app/src/Payments/PaymentStatus.Enum.al new file mode 100644 index 0000000000..6f84595e90 --- /dev/null +++ b/Apps/W1/EDocument/app/src/Payments/PaymentStatus.Enum.al @@ -0,0 +1,31 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.eServices.EDocument.Payments; + +enum 6103 "Payment Status" +{ + Extensible = false; + + value(0; " ") + { + Caption = ''; + } + value(1; Created) + { + Caption = 'Created'; + } + value(2; Sent) + { + Caption = 'Sent'; + } + value(3; Received) + { + Caption = 'Received'; + } + value(4; "Sending Error") + { + Caption = 'Sending Error'; + } +} diff --git a/Apps/W1/EDocument/app/src/Processing/EDocumentBackgroundJobs.Codeunit.al b/Apps/W1/EDocument/app/src/Processing/EDocumentBackgroundJobs.Codeunit.al index d688b52eec..9bff894411 100644 --- a/Apps/W1/EDocument/app/src/Processing/EDocumentBackgroundJobs.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Processing/EDocumentBackgroundJobs.Codeunit.al @@ -6,6 +6,7 @@ namespace Microsoft.eServices.EDocument; using System.Telemetry; using System.Threading; +using Microsoft.eServices.EDocument.Integration.Payments; codeunit 6133 "E-Document Background Jobs" { @@ -104,6 +105,33 @@ codeunit 6133 "E-Document Background Jobs" Telemetry.LogMessage('0000LC5', EDocumentJobTelemetryLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All, TelemetryDimensions); end; + procedure ScheduleRecurrentPaymentSyncJob(var EDocumentService: Record "E-Document Service") + var + JobQueueEntry: Record "Job Queue Entry"; + begin + if EDocumentService.Code = '' then + exit; + + if not this.IsRecurrentJobScheduledForAService(EDocumentService."Payment Sync Recurrent Job Id") then begin + JobQueueEntry.ScheduleRecurrentJobQueueEntryWithFrequency(JobQueueEntry."Object Type to Run"::Codeunit, Codeunit::"Sync Payments Job", EDocumentService.RecordId, EDocumentService."Payment Sync Min between runs", EDocumentService."Payment Sync Start Time"); + EDocumentService."Payment Sync Recurrent Job Id" := JobQueueEntry.ID; + EDocumentService.Modify(); + + JobQueueEntry."Rerun Delay (sec.)" := 600; + JobQueueEntry."No. of Attempts to Run" := 0; + JobQueueEntry."Job Queue Category Code" := this.JobQueueCategoryTok; + JobQueueEntry.Modify(); + end else begin + JobQueueEntry.Get(EDocumentService."Payment Sync Recurrent Job Id"); + JobQueueEntry."Starting Time" := EDocumentService."Payment Sync Start Time"; + JobQueueEntry."No. of Minutes between Runs" := EDocumentService."Payment Sync Min between runs"; + JobQueueEntry."No. of Attempts to Run" := 0; + JobQueueEntry.Modify(); + if not JobQueueEntry.IsReadyToStart() then + JobQueueEntry.Restart(); + end; + end; + procedure HandleRecurrentBatchJob(var EDocumentService: Record "E-Document Service") begin if (EDocumentService."Use Batch Processing") and (EDocumentService."Batch Mode" = EDocumentService."Batch Mode"::Recurrent) then begin @@ -124,6 +152,16 @@ codeunit 6133 "E-Document Background Jobs" RemoveJob(EDocumentService."Import Recurrent Job Id"); end; + procedure HandleRecurrentPaymentSyncJob(var EDocumentService: Record "E-Document Service") + begin + if EDocumentService."Auto Sync Payments" then begin + EDocumentService.TestField("Payment Sync Start Time"); + EDocumentService.TestField("Payment Sync Min between runs"); + this.ScheduleRecurrentPaymentSyncJob(EDocumentService); + end else + this.RemoveJob(EDocumentService."Payment Sync Recurrent Job Id"); + end; + procedure RemoveJob(JobId: Guid) var JobQueueEntry: Record "Job Queue Entry"; diff --git a/Apps/W1/EDocument/app/src/Service/EDocumentService.Table.al b/Apps/W1/EDocument/app/src/Service/EDocumentService.Table.al index 7f152dd481..9f9b803033 100644 --- a/Apps/W1/EDocument/app/src/Service/EDocumentService.Table.al +++ b/Apps/W1/EDocument/app/src/Service/EDocumentService.Table.al @@ -6,6 +6,7 @@ namespace Microsoft.eServices.EDocument; using Microsoft.Finance.GeneralLedger.Journal; using System.Privacy; +using Microsoft.eServices.EDocument.Integration.Payments; using Microsoft.eServices.EDocument.Integration; using Microsoft.eServices.EDocument.Integration.Action; @@ -251,6 +252,50 @@ table 6103 "E-Document Service" ToolTip = 'Specifies the implementation of actions that can be performed after the document is sent to the service.'; DataClassification = SystemMetadata; } + field(29; "Payment Integration"; Enum "Payment Integration") + { + Caption = 'Payment Integration'; + ToolTip = 'Specifies the integration for receiving payments from the service.'; + DataClassification = SystemMetadata; + } + field(30; "Calculate Payment VAT"; Boolean) + { + Caption = 'Calculate Payment VAT'; + ToolTip = 'Specifies whether the VAT amount should be calculated for the payment.'; + DataClassification = SystemMetadata; + } + field(31; "Auto Sync Payments"; Boolean) + { + Caption = 'Auto Sync Payments'; + ToolTip = 'Specifies whether the payments should be automatically synchronized with the service.'; + DataClassification = SystemMetadata; + + trigger OnValidate() + begin + this.EDocumentBackgroundJobs.HandleRecurrentPaymentSyncJob(Rec); + end; + } + field(32; "Payment Sync Start Time"; Time) + { + Caption = 'Sync Start Time'; + ToolTip = 'Specifies the time when the synchronization should start.'; + DataClassification = SystemMetadata; + NotBlank = true; + InitValue = 0T; + } + field(33; "Payment Sync Min between runs"; Integer) + { + Caption = 'Minutes between runs'; + ToolTip = 'Specifies the time between synchronization runs.'; + DataClassification = SystemMetadata; + InitValue = 1440; + } + field(34; "Payment Sync Recurrent Job Id"; Guid) + { + Caption = 'Sync Recurrent Job Id'; + ToolTip = 'Specifies the ID of the job that is used for the synchronization.'; + DataClassification = SystemMetadata; + } } keys { diff --git a/Apps/W1/EDocument/app/src/Service/EdocumentService.Page.al b/Apps/W1/EDocument/app/src/Service/EdocumentService.Page.al index 76d903cfa8..e6edd726e6 100644 --- a/Apps/W1/EDocument/app/src/Service/EdocumentService.Page.al +++ b/Apps/W1/EDocument/app/src/Service/EdocumentService.Page.al @@ -56,6 +56,16 @@ page 6133 "E-Document Service" { ToolTip = 'Specifies integration code for sent e-document actions.'; } + field("Payment Integration"; Rec."Payment Integration") + { + ToolTip = 'Specifies integration code for the payment tracking functionality.'; + Visible = false; + } + field("Calculate Payment VAT"; Rec."Calculate Payment VAT") + { + ToolTip = 'Specifies if VAT should be calculated for payments.'; + Visible = false; + } field("Use Batch Processing"; Rec."Use Batch Processing") { ToolTip = 'Specifies if service uses batch processing for export.'; @@ -177,6 +187,29 @@ page 6133 "E-Document Service" } } } + group(Payment) + { + Caption = 'Payment Settings'; + Visible = false; + + field("Auto Sync Payments"; Rec."Auto Sync Payments") + { + ToolTip = 'Specifies if payments should be automatically synchronized.'; + } + group(PaymentSyncSettings) + { + ShowCaption = false; + Visible = Rec."Auto Sync Payments"; + field("Payment Sync Start Time"; Rec."Payment Sync Start Time") + { + ToolTip = 'Specifies the start time of payment synchronization job.'; + } + field("Payment Sync Min between runs"; Rec."Payment Sync Min between runs") + { + ToolTip = 'Specifies the number of minutes between payment synchronization jobs.'; + } + } + } part(EDocumentDataExchDef; "E-Doc. Service Data Exch. Sub") { ApplicationArea = All; From be90cbf26c7f626f47b3d62e368c425bcc66d669 Mon Sep 17 00:00:00 2001 From: Adele Smiciene Date: Thu, 9 Jan 2025 10:58:38 +0200 Subject: [PATCH 2/9] remove direction filter, add small fixes --- .../app/src/Document/EDocument.Page.al | 7 +--- .../app/src/Document/EDocument.Table.al | 8 +---- .../Helpers/EDocumentErrorHelper.Codeunit.al | 2 +- .../EmptyPaymentHandler.Codeunit.al | 5 ++- .../IDocumentPaymentHandler.Interface.al | 2 +- .../PaymentIntegrationManagement.Codeunit.al | 3 +- .../Payments/SendPayment.Codeunit.al | 4 +++ .../src/Payments/EDocumentPayment.Table.al | 36 +++++++++++++++---- .../Payments/EDocumentPaymentProgress.Enum.al | 2 +- .../src/Payments/EDocumentPayments.Page.al | 15 ++++---- 10 files changed, 51 insertions(+), 33 deletions(-) diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al index 20da3c25df..d2956e07b0 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al @@ -550,11 +550,6 @@ page 6121 "E-Document" EDocImport.ProcessEDocPendingOrderMatch(Rec); - if (Rec.Direction = Rec.Direction::Incoming) then - Rec.SetRange("Payment Direction Filter", "E-Document Direction"::Outgoing) - else - Rec.SetRange("Payment Direction Filter", "E-Document Direction"::Incoming); - this.SetPaymentStatus(); end; @@ -646,7 +641,7 @@ page 6121 "E-Document" if Rec."Paid Amount" < Rec."Amount Incl. VAT" then this.PaymentStatus := this.PaymentStatus::"Partially Paid" else - this.PaymentStatus := this.PaymentStatus::"Paid In Full" + this.PaymentStatus := this.PaymentStatus::Paid end; local procedure ReceivePaymentsForEDoc() diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Table.al b/Apps/W1/EDocument/app/src/Document/EDocument.Table.al index 215e7bceea..3c3b3c2c1a 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Table.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Table.al @@ -188,13 +188,7 @@ table 6121 "E-Document" Caption = 'Paid Amount'; Editable = false; FieldClass = FlowField; - CalcFormula = sum("E-Document Payment".Amount where("E-Document Entry No." = field("Entry No"), Direction = field("Payment Direction Filter"))); - } - field(33; "Payment Direction Filter"; Enum "E-Document Direction") - { - Caption = 'Payment Direction Filter'; - Editable = false; - FieldClass = FlowFilter; + CalcFormula = sum("E-Document Payment".Amount where("E-Document Entry No." = field("Entry No"))); } } keys diff --git a/Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al b/Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al index 9be2abf35a..21bf573122 100644 --- a/Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Helpers/EDocumentErrorHelper.Codeunit.al @@ -116,7 +116,7 @@ codeunit 6115 "E-Document Error Helper" begin ErrorMessage.SetRange("Context Record ID", EDocument.RecordId()); ErrorMessage.SetRange("Table Number", Database::"E-Document Payment"); - ErrorMessage.DeleteAll(); + ErrorMessage.DeleteAll(false); end; internal procedure GetTelemetryImplErrLbl(): Text diff --git a/Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al index f5b48a91cf..9b29cc294a 100644 --- a/Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al @@ -10,7 +10,7 @@ using Microsoft.eServices.EDocument.Payments; using System.Utilities; /// -/// This codeunit is used to implement the "Document Payment Handler" interface. It is used to provide a default implementation for the "Action Invoker" interface. +/// This codeunit is used to provide a default implementation for the "Document Payment Handler" interface. /// codeunit 6105 "Empty Payment Handler" implements IDocumentPaymentHandler { @@ -20,14 +20,17 @@ codeunit 6105 "Empty Payment Handler" implements IDocumentPaymentHandler procedure Send(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext) begin + // This method serves as a placeholder implementation for the IDocumentPaymentHandler interface. end; procedure Receive(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var PaymentsMetadata: Codeunit "Temp Blob List"; PaymentContext: Codeunit PaymentContext) begin + // This method serves as a placeholder implementation for the IDocumentPaymentHandler interface. end; procedure GetDetails(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; PaymentContext: Codeunit PaymentContext) begin + // This method serves as a placeholder implementation for the IDocumentPaymentHandler interface. end; } \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Integration/Interfaces/IDocumentPaymentHandler.Interface.al b/Apps/W1/EDocument/app/src/Integration/Interfaces/IDocumentPaymentHandler.Interface.al index 8d18748817..c7f9f45a12 100644 --- a/Apps/W1/EDocument/app/src/Integration/Interfaces/IDocumentPaymentHandler.Interface.al +++ b/Apps/W1/EDocument/app/src/Integration/Interfaces/IDocumentPaymentHandler.Interface.al @@ -9,7 +9,7 @@ using Microsoft.eServices.EDocument.Integration.Payments; using System.Utilities; /// -/// Interface for sending and receiving paymnet information for E-Documents using E-Document service +/// Interface for sending and receiving payment information for E-Documents using E-Document service /// interface IDocumentPaymentHandler { diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al index 694c2a0daa..d0f0c487c4 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al @@ -74,8 +74,7 @@ codeunit 6117 "Payment Integration Management" exit; Payment.Init(); - Payment."E-Document Entry No." := EDocument."Entry No"; - Payment.Direction := Payment.Direction::Incoming; + Payment.Validate("E-Document Entry No.", EDocument."Entry No"); Payment.Date := PaymentContext.GetDate(); Payment.Validate(Amount, PaymentContext.GetAmount()); Payment.Status := PaymentContext.GetPaymentStatus(); diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al index ee074ed0d3..ec43b5becb 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al @@ -10,6 +10,10 @@ using Microsoft.eServices.EDocument.Payments; codeunit 6116 "Send Payment" { + Access = Internal; + InherentEntitlements = X; + InherentPermissions = X; + trigger OnRun() begin this.EDocumentService.TestField(Code); diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al index 98293cc0c5..15548e2c01 100644 --- a/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al @@ -19,20 +19,29 @@ table 6101 "E-Document Payment" { Caption = 'E-Document Entry No.'; TableRelation = "E-Document"."Entry No"; + AllowInCustomizations = Always; + + trigger OnValidate() + begin + this.SetPaymentDirection(); + end; } field(2; "Payment No."; Integer) { Caption = 'Payment No.'; AutoIncrement = true; + AllowInCustomizations = Always; } field(20; "Date"; Date) { Caption = 'Date'; + ToolTip = 'Specifies the value of the Date field.'; } field(21; Amount; Decimal) { Caption = 'Amount'; DecimalPlaces = 2; + ToolTip = 'Specifies the value of the Amount field.'; trigger OnValidate() begin @@ -43,21 +52,31 @@ table 6101 "E-Document Payment" { Caption = 'VAT Base'; DecimalPlaces = 2; + Editable = false; + ToolTip = 'Specifies the value of the VAT Base field.'; } field(23; "VAT Amount"; Decimal) { Caption = 'VAT Amount'; DecimalPlaces = 2; + Editable = false; + ToolTip = 'Specifies the value of the VAT Amount field.'; } field(24; Status; Enum "Payment Status") { Caption = 'Status'; + Editable = false; + InitValue = Created; + ToolTip = 'Specifies the value of the Status field.'; } field(25; Direction; Enum "E-Document Direction") { Caption = 'Direction'; + Editable = false; + ToolTip = 'Specifies the value of the Direction field.'; } } + keys { key(PK; "E-Document Entry No.", "Payment No.") @@ -66,12 +85,6 @@ table 6101 "E-Document Payment" } } - trigger OnInsert() - begin - if Rec.Status = Rec.Status::" " then - Rec.Status := Rec.Status::Created; - end; - local procedure CalculateVAT() var EDocument: Record "E-Document"; @@ -86,4 +99,15 @@ table 6101 "E-Document Payment" Rec."VAT Base" := Rec.Amount / (EDocument."Amount Incl. VAT" / EDocument."Amount Excl. VAT"); Rec."VAT Amount" := Rec.Amount - Rec."VAT Base"; end; + + local procedure SetPaymentDirection() + var + EDocument: Record "E-Document"; + begin + EDocument.Get(Rec."E-Document Entry No."); + if EDocument.Direction = EDocument.Direction::Outgoing then + Rec.Direction := Rec.Direction::Incoming + else + Rec.Direction := Rec.Direction::Outgoing; + end; } \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPaymentProgress.Enum.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPaymentProgress.Enum.al index 78185309de..122d29a77f 100644 --- a/Apps/W1/EDocument/app/src/Payments/EDocumentPaymentProgress.Enum.al +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPaymentProgress.Enum.al @@ -20,7 +20,7 @@ enum 6104 "E-Document Payment Progress" { Caption = 'Partially Paid'; } - value(3; "Paid In Full") + value(3; Paid) { Caption = 'Paid In Full'; } diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al index 55b995ae70..bae935dd05 100644 --- a/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al @@ -21,41 +21,40 @@ page 6101 "E-Document Payments" field("Date"; Rec."Date") { ApplicationArea = All; - ToolTip = 'Specifies the value of the Date field.'; + Editable = this.PaymentEditable; } field(Amount; Rec.Amount) { ApplicationArea = All; - ToolTip = 'Specifies the value of the Amount field.'; + Editable = this.PaymentEditable; } field("VAT Base"; Rec."VAT Base") { ApplicationArea = All; - ToolTip = 'Specifies the value of the VAT Base field.'; Visible = false; } field("VAT Amount"; Rec."VAT Amount") { ApplicationArea = All; - ToolTip = 'Specifies the value of the VAT Amount field.'; Visible = false; } field(Status; Rec.Status) { ApplicationArea = All; - ToolTip = 'Specifies the value of the Status field.'; } field(Direction; Rec.Direction) { ApplicationArea = All; - ToolTip = 'Specifies the value of the Direction field.'; } } } } - trigger OnNewRecord(BelowxRec: Boolean) + var + PaymentEditable: Boolean; + + trigger OnAfterGetRecord() begin - Evaluate(Rec.Direction, Rec.GetFilter("Direction")); + this.PaymentEditable := Rec.Status <> Rec.Status::Sent; end; } From 9672d29a370b765677afaff3e04d2e983982f212 Mon Sep 17 00:00:00 2001 From: Adele Smiciene Date: Tue, 14 Jan 2025 12:54:53 +0200 Subject: [PATCH 3/9] add automated tests --- .../src/Payments/EDocumentPayment.Table.al | 12 +- .../test/src/LibraryEDocument.Codeunit.al | 12 + .../src/Mock/EDocPaymentImplState.Codeunit.al | 28 ++ .../EDocPaymentIntegrationMock.Codeunit.al | 34 ++ .../EDocPaymentIntegrationMock.EnumExt.al | 8 + .../src/Payments/EDocPaymentTest.Codeunit.al | 400 ++++++++++++++++++ 6 files changed, 488 insertions(+), 6 deletions(-) create mode 100644 Apps/W1/EDocument/test/src/Mock/EDocPaymentImplState.Codeunit.al create mode 100644 Apps/W1/EDocument/test/src/Mock/EDocPaymentIntegrationMock.Codeunit.al create mode 100644 Apps/W1/EDocument/test/src/Mock/EDocPaymentIntegrationMock.EnumExt.al create mode 100644 Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al index 15548e2c01..0c9ed468a7 100644 --- a/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al @@ -35,13 +35,13 @@ table 6101 "E-Document Payment" field(20; "Date"; Date) { Caption = 'Date'; - ToolTip = 'Specifies the value of the Date field.'; + ToolTip = 'Specifies the date when the payment was made.'; } field(21; Amount; Decimal) { Caption = 'Amount'; DecimalPlaces = 2; - ToolTip = 'Specifies the value of the Amount field.'; + ToolTip = 'Specifies the total payment amount including VAT.'; trigger OnValidate() begin @@ -53,27 +53,27 @@ table 6101 "E-Document Payment" Caption = 'VAT Base'; DecimalPlaces = 2; Editable = false; - ToolTip = 'Specifies the value of the VAT Base field.'; + ToolTip = 'Specifies the net amount used as basis for VAT calculation for this payment transaction.'; } field(23; "VAT Amount"; Decimal) { Caption = 'VAT Amount'; DecimalPlaces = 2; Editable = false; - ToolTip = 'Specifies the value of the VAT Amount field.'; + ToolTip = 'Specifies the calculated tax amount for this payment transaction.'; } field(24; Status; Enum "Payment Status") { Caption = 'Status'; Editable = false; InitValue = Created; - ToolTip = 'Specifies the value of the Status field.'; + ToolTip = 'Specifies the current state of the payment.'; } field(25; Direction; Enum "E-Document Direction") { Caption = 'Direction'; Editable = false; - ToolTip = 'Specifies the value of the Direction field.'; + ToolTip = 'Specifies whether this payment is being received (incoming) or sent (outgoing).'; } } diff --git a/Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al b/Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al index f331edeb50..429e7c2bf1 100644 --- a/Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al +++ b/Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al @@ -759,6 +759,18 @@ codeunit 139629 "Library - E-Document" end; #endif + procedure CreateTestPaymentServiceForEDoc(var EDocService: Record "E-Document Service"; ServiceIntegration: Enum "Service Integration"; PaymentIntegration: Enum "Payment Integration") + begin + if not EDocService.Get('TESTPAYMENT') then begin + EDocService.Init(); + EDocService.Code := 'TESTPAYMENT'; + EDocService."Document Format" := "E-Document Format"::Mock; + EDocService."Service Integration V2" := ServiceIntegration; + EDocService."Payment Integration" := PaymentIntegration; + EDocService.Insert(); + end; + end; + procedure CreateDirectMapping(var EDocMapping: Record "E-Doc. Mapping"; EDocService: Record "E-Document Service"; FindValue: Text; ReplaceValue: Text) begin CreateDirectMapping(EDocMapping, EDocService, FindValue, ReplaceValue, 0, 0); diff --git a/Apps/W1/EDocument/test/src/Mock/EDocPaymentImplState.Codeunit.al b/Apps/W1/EDocument/test/src/Mock/EDocPaymentImplState.Codeunit.al new file mode 100644 index 0000000000..7373225eb2 --- /dev/null +++ b/Apps/W1/EDocument/test/src/Mock/EDocPaymentImplState.Codeunit.al @@ -0,0 +1,28 @@ +codeunit 139503 "E-Doc. Payment Impl. State" +{ + EventSubscriberInstance = Manual; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc Payment Integration Mock", 'OnSendPayment', '', false, false)] + local procedure OnSendPayment(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext) + begin + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc Payment Integration Mock", 'OnReceivePayment', '', false, false)] + local procedure OnReceivePayment(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var PaymentsMetadata: Codeunit "Temp Blob List"; PaymentContext: Codeunit PaymentContext) + var + TempBlob: Codeunit "Temp Blob"; + PaymentText: Text; + OutStream: OutStream; + begin + PaymentText := '{"PaymentId": "123456"}'; + TempBlob.CreateOutStream(OutStream); + OutStream.Write(PaymentText); + PaymentsMetadata.Add(TempBlob); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Doc Payment Integration Mock", 'OnGetPaymentDetails', '', false, false)] + local procedure OnGetPaymentDetails(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; PaymentContext: Codeunit PaymentContext) + begin + PaymentContext.SetPaymentInformation(Today(), 1); + end; +} diff --git a/Apps/W1/EDocument/test/src/Mock/EDocPaymentIntegrationMock.Codeunit.al b/Apps/W1/EDocument/test/src/Mock/EDocPaymentIntegrationMock.Codeunit.al new file mode 100644 index 0000000000..52757ea95a --- /dev/null +++ b/Apps/W1/EDocument/test/src/Mock/EDocPaymentIntegrationMock.Codeunit.al @@ -0,0 +1,34 @@ +codeunit 139502 "E-Doc Payment Integration Mock" implements IDocumentPaymentHandler +{ + Access = Internal; + + procedure Send(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext) + begin + OnSendPayment(EDocument, EDocumentService, PaymentContext); + end; + + procedure Receive(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var PaymentsMetadata: Codeunit "Temp Blob List"; PaymentContext: Codeunit PaymentContext) + begin + OnReceivePayment(EDocument, EDocumentService, PaymentsMetadata, PaymentContext); + end; + + procedure GetDetails(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; PaymentContext: Codeunit PaymentContext) + begin + OnGetPaymentDetails(EDocument, EDocumentService, PaymentMetadata, PaymentContext); + end; + + [IntegrationEvent(false, false)] + procedure OnSendPayment(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentContext: Codeunit PaymentContext) + begin + end; + + [IntegrationEvent(false, false)] + procedure OnReceivePayment(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var PaymentsMetadata: Codeunit "Temp Blob List"; PaymentContext: Codeunit PaymentContext) + begin + end; + + [IntegrationEvent(false, false)] + procedure OnGetPaymentDetails(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; PaymentContext: Codeunit PaymentContext) + begin + end; +} diff --git a/Apps/W1/EDocument/test/src/Mock/EDocPaymentIntegrationMock.EnumExt.al b/Apps/W1/EDocument/test/src/Mock/EDocPaymentIntegrationMock.EnumExt.al new file mode 100644 index 0000000000..d80d5cf13f --- /dev/null +++ b/Apps/W1/EDocument/test/src/Mock/EDocPaymentIntegrationMock.EnumExt.al @@ -0,0 +1,8 @@ +enumextension 139501 "E-Doc Payment Integration Mock" extends "Payment Integration" +{ + value(139500; Mock) + { + Caption = 'Mock'; + Implementation = IDocumentPaymentHandler = "E-Doc Payment Integration Mock"; + } +} diff --git a/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al b/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al new file mode 100644 index 0000000000..c0bdfcd84e --- /dev/null +++ b/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al @@ -0,0 +1,400 @@ +codeunit 139501 "E-Doc. Payment Test" +{ + Subtype = Test; + TestPermissions = Disabled; + + var + Customer: Record "Customer"; + EDocService: Record "E-Document Service"; + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + Vendor: Record Vendor; + Assert: Codeunit "Assert"; + EDocExportMgt: Codeunit "E-Doc. Export"; + EDocImplState: Codeunit "E-Doc. Impl. State"; + EDocLogTest: Codeunit "E-Doc Log Test"; + EDocPaymentImplState: Codeunit "E-Doc. Payment Impl. State"; + LibraryEDoc: Codeunit "Library - E-Document"; + LibraryPurchase: Codeunit "Library - Purchase"; + LibraryRandom: Codeunit "Library - Random"; + LibraryInventory: Codeunit "Library - Inventory"; + PurchOrderTestBuffer: Codeunit "E-Doc. Test Buffer"; + + //Create partial payment + [Test] + procedure CreateOutgoingPartialPaymentTest() + var + EDocument: Record "E-Document"; + EDocServicePage: TestPage "E-Document Service"; + PaymentAmount: Decimal; + i: Integer; + begin + // [FEATURE] [E-Document] + // [SCENARIO] Create partial payment for received E-Document + this.Initialize(); + + // [GIVEN] Create E-Document service setup + this.LibraryEDoc.CreateTestPaymentServiceForEDoc(this.EDocService, Enum::"Service Integration"::Mock, Enum::"Payment Integration"::Mock); + this.EDocService."Calculate Payment VAT" := false; + this.EDocService."Lookup Account Mapping" := false; + this.EDocService."Lookup Item GTIN" := false; + this.EDocService."Lookup Item Reference" := false; + this.EDocService."Resolve Unit Of Measure" := false; + this.EDocService."Validate Line Discount" := false; + this.EDocService."Verify Totals" := false; + this.EDocService."Use Batch Processing" := false; + this.EDocService.Modify(); + BindSubscription(this.EDocImplState); + + // [GIVEN] Create received E-Document + this.LibraryPurchase.CreateVendorWithAddress(this.Vendor); + this.Vendor."Receive E-Document To" := this.Vendor."Receive E-Document To"::"Purchase Invoice"; + this.Vendor.Modify(); + this.LibraryPurchase.CreatePurchHeader(this.PurchaseHeader, this.PurchaseHeader."Document Type"::Invoice, this.Vendor."No."); + + for i := 1 to 3 do begin + this.LibraryPurchase.CreatePurchaseLine(this.PurchaseLine, this.PurchaseHeader, this.PurchaseLine.Type::Item, this.LibraryInventory.CreateItemNo(), this.LibraryRandom.RandInt(100)); + this.PurchaseLine.Validate("Direct Unit Cost", this.LibraryRandom.RandDecInRange(1, 100, 2)); + this.PurchaseLine.Modify(true); + end; + + this.PurchOrderTestBuffer.ClearTempVariables(); + this.PurchOrderTestBuffer.AddPurchaseDocToTemp(this.PurchaseHeader); + + // [WHEN] Running Receive + EDocServicePage.OpenView(); + EDocServicePage.Filter.SetFilter(Code, this.EDocService.Code); + EDocServicePage.Receive.Invoke(); + UnbindSubscription(this.EDocImplState); + + // [THEN] Purchase invoice is created with corresponding values + EDocument.FindLast(); + + // [THEN] Check that Paid Amount for the document is 0 + this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + + // [GIVEN] Create partial payment for E-Document + PaymentAmount := 100; + this.CreateEDocumentPayment(EDocument, PaymentAmount); + + // [THEN] Check that Paid Amount for the document is updated + this.CheckPaidAmountAndPaymentStatus(EDocument, PaymentAmount, Enum::"E-Document Payment Progress"::"Partially Paid"); + + // [THEN] Check that Payments Direction is correct + this.CheckPaymentDirection(EDocument, Enum::"E-Document Direction"::Outgoing); + end; + + //Create full payment + [Test] + procedure CreateOutgoingFullPaymentTest() + var + EDocument: Record "E-Document"; + EDocServicePage: TestPage "E-Document Service"; + i: Integer; + begin + // [FEATURE] [E-Document] + // [SCENARIO] Send payment for received E-Document + this.Initialize(); + + // [GIVEN] Create E-Document service setup + this.LibraryEDoc.CreateTestPaymentServiceForEDoc(this.EDocService, Enum::"Service Integration"::Mock, Enum::"Payment Integration"::Mock); + this.EDocService."Calculate Payment VAT" := false; + this.EDocService."Lookup Account Mapping" := false; + this.EDocService."Lookup Item GTIN" := false; + this.EDocService."Lookup Item Reference" := false; + this.EDocService."Resolve Unit Of Measure" := false; + this.EDocService."Validate Line Discount" := false; + this.EDocService."Verify Totals" := false; + this.EDocService."Use Batch Processing" := false; + this.EDocService.Modify(); + BindSubscription(this.EDocImplState); + + // [GIVEN] Create received E-Document + this.LibraryPurchase.CreateVendorWithAddress(this.Vendor); + this.Vendor."Receive E-Document To" := this.Vendor."Receive E-Document To"::"Purchase Invoice"; + this.Vendor.Modify(); + this.LibraryPurchase.CreatePurchHeader(this.PurchaseHeader, this.PurchaseHeader."Document Type"::Invoice, this.Vendor."No."); + + for i := 1 to 3 do begin + this.LibraryPurchase.CreatePurchaseLine(this.PurchaseLine, this.PurchaseHeader, this.PurchaseLine.Type::Item, this.LibraryInventory.CreateItemNo(), this.LibraryRandom.RandInt(100)); + this.PurchaseLine.Validate("Direct Unit Cost", this.LibraryRandom.RandDecInRange(1, 100, 2)); + this.PurchaseLine.Modify(true); + end; + + this.PurchOrderTestBuffer.ClearTempVariables(); + this.PurchOrderTestBuffer.AddPurchaseDocToTemp(this.PurchaseHeader); + + // [WHEN] Running Receive + EDocServicePage.OpenView(); + EDocServicePage.Filter.SetFilter(Code, this.EDocService.Code); + EDocServicePage.Receive.Invoke(); + UnbindSubscription(this.EDocImplState); + + // [THEN] Purchase invoice is created with corresponding values + EDocument.FindLast(); + + // [THEN] Check that Paid Amount for the document is 0 + this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + + // [GIVEN] Create partial payment for E-Document + this.CreateFullEDocumentPayments(EDocument); + + // [THEN] Check that Paid Amount for the document is updated + this.CheckPaidAmountAndPaymentStatus(EDocument, EDocument."Amount Incl. VAT", Enum::"E-Document Payment Progress"::Paid); + + // [THEN] Check that Payments Direction is correct + this.CheckPaymentDirection(EDocument, Enum::"E-Document Direction"::Outgoing); + end; + + //Create partial payment + [Test] + procedure CreateOutgoingPaymentWithVATCalculationTest() + var + EDocument: Record "E-Document"; + EDocServicePage: TestPage "E-Document Service"; + PaymentAmount: Decimal; + i: Integer; + begin + // [FEATURE] [E-Document] + // [SCENARIO] Create partial payment for received E-Document + this.Initialize(); + + // [GIVEN] Create E-Document service setup and set VAT calculation + this.LibraryEDoc.CreateTestPaymentServiceForEDoc(this.EDocService, Enum::"Service Integration"::Mock, Enum::"Payment Integration"::Mock); + this.EDocService."Calculate Payment VAT" := true; + this.EDocService."Lookup Account Mapping" := false; + this.EDocService."Lookup Item GTIN" := false; + this.EDocService."Lookup Item Reference" := false; + this.EDocService."Resolve Unit Of Measure" := false; + this.EDocService."Validate Line Discount" := false; + this.EDocService."Verify Totals" := false; + this.EDocService."Use Batch Processing" := false; + this.EDocService.Modify(); + BindSubscription(this.EDocImplState); + + // [GIVEN] Create received E-Document + this.LibraryPurchase.CreateVendorWithAddress(this.Vendor); + this.Vendor."Receive E-Document To" := this.Vendor."Receive E-Document To"::"Purchase Invoice"; + this.Vendor.Modify(); + this.LibraryPurchase.CreatePurchHeader(this.PurchaseHeader, this.PurchaseHeader."Document Type"::Invoice, this.Vendor."No."); + + for i := 1 to 3 do begin + this.LibraryPurchase.CreatePurchaseLine(this.PurchaseLine, this.PurchaseHeader, this.PurchaseLine.Type::Item, this.LibraryInventory.CreateItemNo(), this.LibraryRandom.RandInt(100)); + this.PurchaseLine.Validate("Direct Unit Cost", this.LibraryRandom.RandDecInRange(1, 100, 2)); + this.PurchaseLine.Modify(true); + end; + + this.PurchOrderTestBuffer.ClearTempVariables(); + this.PurchOrderTestBuffer.AddPurchaseDocToTemp(this.PurchaseHeader); + + // [WHEN] Running Receive + EDocServicePage.OpenView(); + EDocServicePage.Filter.SetFilter(Code, this.EDocService.Code); + EDocServicePage.Receive.Invoke(); + UnbindSubscription(this.EDocImplState); + + // [THEN] Purchase invoice is created with corresponding values + EDocument.FindLast(); + + // [THEN] Check that Paid Amount for the document is 0 + this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + + // [GIVEN] Create partial payment for E-Document + PaymentAmount := 100; + this.CreateEDocumentPayment(EDocument, PaymentAmount); + + // [THEN] Check that Paid Amount for the document is updated + this.CheckPaidAmountAndPaymentStatus(EDocument, PaymentAmount, Enum::"E-Document Payment Progress"::"Partially Paid"); + + // [THEN] Check that VAT amount is calculated + this.CheckPaymentVATAmount(EDocument); + end; + + //Create incoming partial payment + [Test] + procedure CreateIncomingPartialPaymentTest() + var + EDocument: Record "E-Document"; + PaymentAmount: Decimal; + begin + // [FEATURE] [E-Document] + // [SCENARIO] Receive payment for sent E-Document + this.Initialize(); + + // [GIVEN] Setup E-Document service to send E-Document and receive payment + this.LibraryEDoc.SetupStandardVAT(); + this.LibraryEDoc.SetupStandardSalesScenario(this.Customer, this.EDocService, Enum::"E-Document Format"::"PEPPOL BIS 3.0", Enum::"Service Integration"::Mock); + this.EDocService."Payment Integration" := Enum::"Payment Integration"::Mock; + this.EDocService."Calculate Payment VAT" := false; + this.EDocService.Modify(); + + // [WHEN] Create and post sales invoice to create E-Document + this.LibraryEDoc.PostInvoice(this.Customer); + EDocument.FindLast(); + + // [WHEN] Export EDocument + BindSubscription(this.EDocLogTest); + this.EDocExportMgt.ExportEDocument(EDocument, this.EDocService); + UnbindSubscription(this.EDocLogTest); + + // [THEN] Check that Paid Amount for the document is 0 + this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + + // [WHEN] Receive payment for E-Document + PaymentAmount := 1; + this.CreateEDocumentPayment(EDocument, PaymentAmount); + + // [THEN] Check that Paid Amount for the document is updated + this.CheckPaidAmountAndPaymentStatus(EDocument, PaymentAmount, Enum::"E-Document Payment Progress"::"Partially Paid"); + + // [THEN] Check that Payments Direction is correct + this.CheckPaymentDirection(EDocument, Enum::"E-Document Direction"::Incoming); + end; + + //Receive incoming payment + [HandlerFunctions('EDocumentServiceSelectionHandler')] + [Test] + procedure ReceivePaymentTest() + var + EDocument: Record "E-Document"; + begin + // [FEATURE] [E-Document] + // [SCENARIO] Receive payment for sent E-Document + this.Initialize(); + + // [GIVEN] Setup E-Document service to send E-Document and receive payment + this.LibraryEDoc.SetupStandardVAT(); + this.LibraryEDoc.SetupStandardSalesScenario(this.Customer, this.EDocService, Enum::"E-Document Format"::"PEPPOL BIS 3.0", Enum::"Service Integration"::Mock); + this.EDocService."Payment Integration" := Enum::"Payment Integration"::Mock; + this.EDocService."Calculate Payment VAT" := false; + this.EDocService.Modify(); + + // [WHEN] Create and post sales invoice to create E-Document + this.LibraryEDoc.PostInvoice(this.Customer); + EDocument.FindLast(); + + // [WHEN] Export EDocument + BindSubscription(this.EDocLogTest); + this.EDocExportMgt.ExportEDocument(EDocument, this.EDocService); + UnbindSubscription(this.EDocLogTest); + + // [THEN] Check that Paid Amount for the document is 0 + this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + + // [WHEN] Receive payment for E-Document + this.ReceivePayment(EDocument); + + // [THEN] Check that Paid Amount for the document is updated + this.CheckPaidAmountAndPaymentStatus(EDocument, 1, Enum::"E-Document Payment Progress"::"Partially Paid"); + + // [THEN] Check that Payments Direction is correct + this.CheckPaymentDirection(EDocument, Enum::"E-Document Direction"::Incoming); + end; + + local procedure Initialize() + var + EDocument: Record "E-Document"; + EDocumentPayment: Record "E-Document Payment"; + begin + Clear(this.EDocPaymentImplState); + EDocument.DeleteAll(); + EDocumentPayment.DeleteAll(); + + Clear(this.PurchaseHeader); + this.PurchaseHeader.DeleteAll(); + + Clear(this.EDocService); + end; + + local procedure CreateEDocumentPayment(EDocument: Record "E-Document"; PaymentAmount: Decimal) + begin + this.CreateEDocumentPaymentRecord(EDocument."Entry No", PaymentAmount) + end; + + local procedure CreateFullEDocumentPayments(EDocument: Record "E-Document") + begin + this.CreateEDocumentPaymentRecord(EDocument."Entry No", 100); + this.CreateEDocumentPaymentRecord(EDocument."Entry No", EDocument."Amount Incl. VAT" - 100) + end; + + local procedure CreateEDocumentPaymentRecord(EDocumentEntryNo: Integer; Amount: Decimal) + var + EDocumentPayment: Record "E-Document Payment"; + begin + EDocumentPayment.Init(); + EDocumentPayment.Validate("E-Document Entry No.", EDocumentEntryNo); + EDocumentPayment.Date := Today(); + EDocumentPayment.Validate(Amount, Amount); + EDocumentPayment.Insert(); + end; + + local procedure ReceivePayment(EDocument: Record "E-Document") + var + EDocumentPage: TestPage "E-Document"; + begin + BindSubscription(this.EDocPaymentImplState); + EDocumentPage.OpenView(); + EDocumentPage.GoToRecord(EDocument); + EDocumentPage.ReceivePayments.Invoke(); + UnbindSubscription(this.EDocPaymentImplState); + end; + + local procedure CheckPaidAmountAndPaymentStatus(EDocument: Record "E-Document"; ExpectedPaidAmount: Decimal; ExpectedPaymentStatus: Enum "E-Document Payment Progress") + var + EDocumentPage: TestPage "E-Document"; + PaidAmount: Decimal; + PaymentStatus: Enum "E-Document Payment Progress"; + begin + EDocumentPage.OpenView(); + EDocumentPage.GoToRecord(EDocument); + Evaluate(PaidAmount, EDocumentPage."Paid Amount".Value()); + Evaluate(PaymentStatus, EDocumentPage."Payment Status".Value()); + this.Assert.AreEqual(ExpectedPaidAmount, PaidAmount, 'Paid Amount is not updated.'); + this.Assert.AreEqual(ExpectedPaymentStatus, PaymentStatus, 'Payment Status is not updated.'); + EDocumentPage.Close(); + end; + + local procedure CheckPaymentVATAmount(EDocument: Record "E-Document") + var + EDocumentPage: TestPage "E-Document"; + PaymentsPage: TestPage "E-Document Payments"; + VATBaseAmount: Decimal; + VATAmount: Decimal; + begin + EDocumentPage.OpenView(); + EDocumentPage.GoToRecord(EDocument); + PaymentsPage.Trap(); + EDocumentPage."Paid Amount".Drilldown(); + PaymentsPage.First(); + Evaluate(VATBaseAmount, PaymentsPage."VAT Base".Value()); + Evaluate(VATAmount, PaymentsPage."VAT Amount".Value()); + this.Assert.AreNotEqual(0, VATBaseAmount, 'Payment Base Amount is not calculated.'); + this.Assert.AreNotEqual(0, VATAmount, 'Payment VAT Amount is not calculated.'); + PaymentsPage.Close(); + end; + + local procedure CheckPaymentDirection(EDocument: Record "E-Document"; ExpectedDirection: Enum "E-Document Direction") + var + EDocumentPage: TestPage "E-Document"; + PaymentsPage: TestPage "E-Document Payments"; + Direction: Enum "E-Document Direction"; + begin + EDocumentPage.OpenView(); + EDocumentPage.GoToRecord(EDocument); + PaymentsPage.Trap(); + EDocumentPage."Paid Amount".Drilldown(); + PaymentsPage.First(); + repeat + Evaluate(Direction, PaymentsPage.Direction.Value()); + this.Assert.AreEqual(ExpectedDirection, Direction, 'Payment Direction is not correct.'); + until not PaymentsPage.Next(); + PaymentsPage.Close(); + end; + + [ModalPageHandler] + procedure EDocumentServiceSelectionHandler(var EDocumentServices: TestPage "E-Document Services") + begin + EDocumentServices.GoToRecord(this.EDocService); + EDocumentServices.OK().Invoke(); + end; +} From 8f893803ad3216f696689a662108294a99142718 Mon Sep 17 00:00:00 2001 From: Adele Smiciene Date: Tue, 21 Jan 2025 15:44:20 +0200 Subject: [PATCH 4/9] fixes --- .../EDocument/app/src/Document/EDocument.Page.al | 3 ++- .../Payments/GetPaymentDetails.Codeunit.al | 14 +++++++++++++- .../EmptyPaymentHandler.Codeunit.al | 0 .../Payments/PaymentContext.Codeunit.al | 8 +++++++- .../Payments/PaymentIntegration.Enum.al | 1 + .../PaymentIntegrationManagement.Codeunit.al | 2 +- .../Payments/ReceivePayments.Codeunit.al | 15 +++++++++++++++ .../Integration/Payments/SendPayment.Codeunit.al | 11 +++++++++++ .../app/src/Payments/EDocumentPayments.Page.al | 6 ------ .../app/src/Payments/PaymentStatus.Enum.al | 2 +- .../EDocumentBackgroundJobs.Codeunit.al | 14 ++++++++++---- .../app/src/Service/EDocumentService.Table.al | 4 ++-- .../app/src/Service/EdocumentService.Page.al | 5 ----- 13 files changed, 63 insertions(+), 22 deletions(-) rename Apps/W1/EDocument/app/src/Integration/{Actions => Payments}/Implementations/EmptyPaymentHandler.Codeunit.al (100%) diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al index d2956e07b0..f090394b68 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al @@ -363,6 +363,7 @@ page 6121 "E-Document" group(Payments) { Caption = 'Payments'; + action(ReceivePayments) { Caption = 'Receive Payments'; @@ -641,7 +642,7 @@ page 6121 "E-Document" if Rec."Paid Amount" < Rec."Amount Incl. VAT" then this.PaymentStatus := this.PaymentStatus::"Partially Paid" else - this.PaymentStatus := this.PaymentStatus::Paid + this.PaymentStatus := this.PaymentStatus::Paid; end; local procedure ReceivePaymentsForEDoc() diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al index 3dfda82c1d..750d4664b9 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al @@ -4,7 +4,6 @@ // ------------------------------------------------------------------------------------------------ namespace Microsoft.eServices.EDocument.Integration.Payments; - using System.Utilities; using Microsoft.eServices.EDocument; using Microsoft.eServices.EDocument.Integration.Interfaces; @@ -21,16 +20,29 @@ codeunit 6107 "Get Payment Details" this.IDocumentPaymentHandler.GetDetails(this.EDocument, this.EDocumentService, this.PaymentMetadata, this.PaymentContext); end; + /// + /// Sets the global variable PaymentContext. + /// procedure SetContext(PaymentContext: Codeunit PaymentContext) begin this.PaymentContext := PaymentContext; end; + /// + /// Sets the IPaymentHandler instance. + /// procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) begin this.IDocumentPaymentHandler := PaymentHandler; end; + + /// + /// Sets the parameters for the payment information receiving. + /// + /// Electronic document for which payment is received. + /// Service for receiving payments. + /// TempBlob which contains received payment information. procedure SetParameters(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob") begin this.EDocument.Copy(EDocument); diff --git a/Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/Implementations/EmptyPaymentHandler.Codeunit.al similarity index 100% rename from Apps/W1/EDocument/app/src/Integration/Actions/Implementations/EmptyPaymentHandler.Codeunit.al rename to Apps/W1/EDocument/app/src/Integration/Payments/Implementations/EmptyPaymentHandler.Codeunit.al diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentContext.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentContext.Codeunit.al index 5c4d83c421..ec3cb5cba7 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentContext.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentContext.Codeunit.al @@ -12,6 +12,7 @@ codeunit 6104 PaymentContext /// /// Get the Http Message State codeunit. /// + /// codeunit Http Message State that contains http request and response messages. procedure Http(): Codeunit "Http Message State" begin exit(this.HttpMessageState); @@ -20,6 +21,7 @@ codeunit 6104 PaymentContext /// /// Retrieves the payment date. /// + /// Date when the payment was made. procedure GetDate(): Date begin exit(this.Date); @@ -28,6 +30,7 @@ codeunit 6104 PaymentContext /// /// Retrieves the payment amount. /// + /// Amount of the payment. procedure GetAmount(): Decimal begin exit(this.Amount); @@ -36,6 +39,8 @@ codeunit 6104 PaymentContext /// /// Sets the payment date and amount. /// + /// Date when the payment was made. + /// Amount of the payment. procedure SetPaymentInformation(Date: Date; Amount: Decimal) begin this.Date := Date; @@ -45,6 +50,7 @@ codeunit 6104 PaymentContext /// /// Retrieves the payment status. /// + /// Current payment status. procedure GetPaymentStatus(): Enum "Payment Status" begin exit(this.PaymentStatus); @@ -53,6 +59,7 @@ codeunit 6104 PaymentContext /// /// Sets the payment status. /// + /// New payment status. procedure SetPaymentStatus(NewPaymentStatus: Enum "Payment Status") begin this.PaymentStatus := NewPaymentStatus; @@ -63,5 +70,4 @@ codeunit 6104 PaymentContext PaymentStatus: Enum "Payment Status"; Date: Date; Amount: Decimal; - } \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegration.Enum.al b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegration.Enum.al index d8dd11e960..89c3f23781 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegration.Enum.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegration.Enum.al @@ -3,6 +3,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // ------------------------------------------------------------------------------------------------ namespace Microsoft.eServices.EDocument.Integration.Payments; + using Microsoft.eServices.EDocument.Integration.Interfaces; enum 6105 "Payment Integration" implements IDocumentPaymentHandler diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al index d0f0c487c4..e0e6821980 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/PaymentIntegrationManagement.Codeunit.al @@ -78,7 +78,7 @@ codeunit 6117 "Payment Integration Management" Payment.Date := PaymentContext.GetDate(); Payment.Validate(Amount, PaymentContext.GetAmount()); Payment.Status := PaymentContext.GetPaymentStatus(); - Payment.Insert(); + Payment.Insert(true); end; local procedure RunGetPaymentDetails(EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service"; PaymentMetadata: Codeunit "Temp Blob"; IDocumentPaymentHandler: Interface IDocumentPaymentHandler; PaymentContext: Codeunit PaymentContext): Boolean diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al index b121535af9..9d4d397dda 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al @@ -20,26 +20,41 @@ codeunit 6106 "Receive Payments" IDocumentPaymentHandler.Receive(this.EDocument, this.EDocumentService, this.PaymentsMetadata, this.PaymentContext); end; + /// + /// Sets the IPaymentHandler instance. + /// procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) begin this.IDocumentPaymentHandler := PaymentHandler; end; + /// + /// Sets the global variable PaymentContext. + /// procedure SetContext(PaymentContext: Codeunit PaymentContext) begin this.PaymentContext := PaymentContext; end; + /// + /// Sets the received payments to Temp Blob List. + /// procedure SetPayments(PaymentsMetadata: Codeunit "Temp Blob List") begin this.PaymentsMetadata := PaymentsMetadata end; + /// + /// Sets the E-Document Service used for receiving payments. + /// procedure SetService(var EDocumentService: Record "E-Document Service") begin this.EDocumentService.Copy(EDocumentService); end; + /// + /// Sets the E-Document for which payments are received. + /// procedure SetDocument(var EDocument: Record "E-Document") begin this.EDocument.Copy(EDocument); diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al index ec43b5becb..a7ef7dde6a 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al @@ -20,16 +20,27 @@ codeunit 6116 "Send Payment" this.IPaymentHandler.Send(this.EDocument, this.EDocumentService, this.PaymentContext); end; + /// + /// Sets the IPaymentHandler instance. + /// procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) begin this.IPaymentHandler := PaymentHandler; end; + /// + /// Sets the global variable PaymentContext. + /// procedure SetContext(PaymentContext: Codeunit PaymentContext) begin this.PaymentContext := PaymentContext; end; + /// + /// Sets the parameters for the payment handler. + /// + /// Electronic document for which payments are sent. + /// Service for sending payments. procedure SetDocumentAndService(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service") begin this.EDocument.Copy(EDocument); diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al index bae935dd05..473ec29333 100644 --- a/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al @@ -20,31 +20,25 @@ page 6101 "E-Document Payments" { field("Date"; Rec."Date") { - ApplicationArea = All; Editable = this.PaymentEditable; } field(Amount; Rec.Amount) { - ApplicationArea = All; Editable = this.PaymentEditable; } field("VAT Base"; Rec."VAT Base") { - ApplicationArea = All; Visible = false; } field("VAT Amount"; Rec."VAT Amount") { - ApplicationArea = All; Visible = false; } field(Status; Rec.Status) { - ApplicationArea = All; } field(Direction; Rec.Direction) { - ApplicationArea = All; } } } diff --git a/Apps/W1/EDocument/app/src/Payments/PaymentStatus.Enum.al b/Apps/W1/EDocument/app/src/Payments/PaymentStatus.Enum.al index 6f84595e90..ef7ad64afe 100644 --- a/Apps/W1/EDocument/app/src/Payments/PaymentStatus.Enum.al +++ b/Apps/W1/EDocument/app/src/Payments/PaymentStatus.Enum.al @@ -10,7 +10,7 @@ enum 6103 "Payment Status" value(0; " ") { - Caption = ''; + Caption = ' '; } value(1; Created) { diff --git a/Apps/W1/EDocument/app/src/Processing/EDocumentBackgroundJobs.Codeunit.al b/Apps/W1/EDocument/app/src/Processing/EDocumentBackgroundJobs.Codeunit.al index 9bff894411..33a62d2a04 100644 --- a/Apps/W1/EDocument/app/src/Processing/EDocumentBackgroundJobs.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Processing/EDocumentBackgroundJobs.Codeunit.al @@ -113,20 +113,26 @@ codeunit 6133 "E-Document Background Jobs" exit; if not this.IsRecurrentJobScheduledForAService(EDocumentService."Payment Sync Recurrent Job Id") then begin - JobQueueEntry.ScheduleRecurrentJobQueueEntryWithFrequency(JobQueueEntry."Object Type to Run"::Codeunit, Codeunit::"Sync Payments Job", EDocumentService.RecordId, EDocumentService."Payment Sync Min between runs", EDocumentService."Payment Sync Start Time"); + JobQueueEntry.ScheduleRecurrentJobQueueEntryWithFrequency( + JobQueueEntry."Object Type to Run"::Codeunit, + Codeunit::"Sync Payments Job", + EDocumentService.RecordId, + EDocumentService."Payment Sync Min between runs", + EDocumentService."Payment Sync Start Time"); + EDocumentService."Payment Sync Recurrent Job Id" := JobQueueEntry.ID; - EDocumentService.Modify(); + EDocumentService.Modify(false); JobQueueEntry."Rerun Delay (sec.)" := 600; JobQueueEntry."No. of Attempts to Run" := 0; JobQueueEntry."Job Queue Category Code" := this.JobQueueCategoryTok; - JobQueueEntry.Modify(); + JobQueueEntry.Modify(false); end else begin JobQueueEntry.Get(EDocumentService."Payment Sync Recurrent Job Id"); JobQueueEntry."Starting Time" := EDocumentService."Payment Sync Start Time"; JobQueueEntry."No. of Minutes between Runs" := EDocumentService."Payment Sync Min between runs"; JobQueueEntry."No. of Attempts to Run" := 0; - JobQueueEntry.Modify(); + JobQueueEntry.Modify(false); if not JobQueueEntry.IsReadyToStart() then JobQueueEntry.Restart(); end; diff --git a/Apps/W1/EDocument/app/src/Service/EDocumentService.Table.al b/Apps/W1/EDocument/app/src/Service/EDocumentService.Table.al index 9f9b803033..cd99201a77 100644 --- a/Apps/W1/EDocument/app/src/Service/EDocumentService.Table.al +++ b/Apps/W1/EDocument/app/src/Service/EDocumentService.Table.al @@ -255,7 +255,7 @@ table 6103 "E-Document Service" field(29; "Payment Integration"; Enum "Payment Integration") { Caption = 'Payment Integration'; - ToolTip = 'Specifies the integration for receiving payments from the service.'; + ToolTip = 'Specifies the integration for sending and receiving payments from the service.'; DataClassification = SystemMetadata; } field(30; "Calculate Payment VAT"; Boolean) @@ -283,7 +283,7 @@ table 6103 "E-Document Service" NotBlank = true; InitValue = 0T; } - field(33; "Payment Sync Min between runs"; Integer) + field(33; "Payment Sync Min Between Runs"; Integer) { Caption = 'Minutes between runs'; ToolTip = 'Specifies the time between synchronization runs.'; diff --git a/Apps/W1/EDocument/app/src/Service/EdocumentService.Page.al b/Apps/W1/EDocument/app/src/Service/EdocumentService.Page.al index e6edd726e6..2427643df4 100644 --- a/Apps/W1/EDocument/app/src/Service/EdocumentService.Page.al +++ b/Apps/W1/EDocument/app/src/Service/EdocumentService.Page.al @@ -58,12 +58,10 @@ page 6133 "E-Document Service" } field("Payment Integration"; Rec."Payment Integration") { - ToolTip = 'Specifies integration code for the payment tracking functionality.'; Visible = false; } field("Calculate Payment VAT"; Rec."Calculate Payment VAT") { - ToolTip = 'Specifies if VAT should be calculated for payments.'; Visible = false; } field("Use Batch Processing"; Rec."Use Batch Processing") @@ -194,7 +192,6 @@ page 6133 "E-Document Service" field("Auto Sync Payments"; Rec."Auto Sync Payments") { - ToolTip = 'Specifies if payments should be automatically synchronized.'; } group(PaymentSyncSettings) { @@ -202,11 +199,9 @@ page 6133 "E-Document Service" Visible = Rec."Auto Sync Payments"; field("Payment Sync Start Time"; Rec."Payment Sync Start Time") { - ToolTip = 'Specifies the start time of payment synchronization job.'; } field("Payment Sync Min between runs"; Rec."Payment Sync Min between runs") { - ToolTip = 'Specifies the number of minutes between payment synchronization jobs.'; } } } From 0768d7d93be7819b790d2517d152573cbdbf0ab1 Mon Sep 17 00:00:00 2001 From: Adele Smiciene Date: Tue, 21 Jan 2025 16:38:44 +0200 Subject: [PATCH 5/9] fixes --- .../app/src/Document/EDocument.Page.al | 3 +-- .../app/src/Document/EDocument.Table.al | 1 + .../Payments/GetPaymentDetails.Codeunit.al | 4 +++- .../Payments/ReceivePayments.Codeunit.al | 21 ++++++++++++------- .../Payments/SendPayment.Codeunit.al | 4 +++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al index f090394b68..03029d00a8 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Page.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Page.al @@ -126,12 +126,11 @@ page 6121 "E-Document" Caption = 'Payment Status'; Visible = false; Editable = false; - ToolTip = 'Specifies the payment status of the electronic document.'; + ToolTip = 'Specifies the electronic document payment status.'; } field("Paid Amount"; Rec."Paid Amount") { Visible = false; - ToolTip = 'Specifies the paid amount of the electronic document.'; } } group(ReceivingCompanyInfo) diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Table.al b/Apps/W1/EDocument/app/src/Document/EDocument.Table.al index 3c3b3c2c1a..6853356137 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Table.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Table.al @@ -189,6 +189,7 @@ table 6121 "E-Document" Editable = false; FieldClass = FlowField; CalcFormula = sum("E-Document Payment".Amount where("E-Document Entry No." = field("Entry No"))); + ToolTip = 'Specifies the amount that has already been paid.'; } } keys diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al index 750d4664b9..d7865c146d 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al @@ -23,14 +23,16 @@ codeunit 6107 "Get Payment Details" /// /// Sets the global variable PaymentContext. /// + /// Payment context codeunit. procedure SetContext(PaymentContext: Codeunit PaymentContext) begin this.PaymentContext := PaymentContext; end; /// - /// Sets the IPaymentHandler instance. + /// Sets the IDocumentPaymentHandler instance. /// + /// IDocumentPaymentHandler implementation used for receiving payment details. procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) begin this.IDocumentPaymentHandler := PaymentHandler; diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al index 9d4d397dda..1770e9fc28 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/ReceivePayments.Codeunit.al @@ -16,13 +16,14 @@ codeunit 6106 "Receive Payments" trigger OnRun() begin - EDocumentService.TestField(Code); - IDocumentPaymentHandler.Receive(this.EDocument, this.EDocumentService, this.PaymentsMetadata, this.PaymentContext); + this.EDocumentService.TestField(Code); + this.IDocumentPaymentHandler.Receive(this.EDocument, this.EDocumentService, this.PaymentsMetadata, this.PaymentContext); end; /// - /// Sets the IPaymentHandler instance. - /// + /// Sets the IDocumentPaymentHandler instance. + /// + /// IDocumentPaymentHandler implementation used for receiving payments. procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) begin this.IDocumentPaymentHandler := PaymentHandler; @@ -30,7 +31,8 @@ codeunit 6106 "Receive Payments" /// /// Sets the global variable PaymentContext. - /// + /// + /// Payment context codeunit. procedure SetContext(PaymentContext: Codeunit PaymentContext) begin this.PaymentContext := PaymentContext; @@ -38,7 +40,8 @@ codeunit 6106 "Receive Payments" /// /// Sets the received payments to Temp Blob List. - /// + /// + /// Temp Blob List to save received payments. procedure SetPayments(PaymentsMetadata: Codeunit "Temp Blob List") begin this.PaymentsMetadata := PaymentsMetadata @@ -46,7 +49,8 @@ codeunit 6106 "Receive Payments" /// /// Sets the E-Document Service used for receiving payments. - /// + /// + /// Service for receiving payments. procedure SetService(var EDocumentService: Record "E-Document Service") begin this.EDocumentService.Copy(EDocumentService); @@ -54,7 +58,8 @@ codeunit 6106 "Receive Payments" /// /// Sets the E-Document for which payments are received. - /// + /// + /// E-Document for which payments are received. procedure SetDocument(var EDocument: Record "E-Document") begin this.EDocument.Copy(EDocument); diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al index a7ef7dde6a..a4f3a5e55d 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/SendPayment.Codeunit.al @@ -21,8 +21,9 @@ codeunit 6116 "Send Payment" end; /// - /// Sets the IPaymentHandler instance. + /// Sets the IDocumentPaymentHandler instance. /// + /// IDocumentPaymentHandler implementation used for sending payments. procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler) begin this.IPaymentHandler := PaymentHandler; @@ -31,6 +32,7 @@ codeunit 6116 "Send Payment" /// /// Sets the global variable PaymentContext. /// + /// Payment context codeunit. procedure SetContext(PaymentContext: Codeunit PaymentContext) begin this.PaymentContext := PaymentContext; From 9809c08f1cb37a43c763442dd0ed058c315c3901 Mon Sep 17 00:00:00 2001 From: Adele Smiciene Date: Wed, 22 Jan 2025 11:08:02 +0200 Subject: [PATCH 6/9] modify permission sets --- .../app/Permissions/EDocCoreBasic.PermissionSet.al | 4 +++- .../app/Permissions/EDocCoreEdit.PermissionSet.al | 4 +++- .../app/Permissions/EDocCoreObjects.PermissionSet.al | 12 +++++++++++- .../app/Permissions/EDocCoreRead.PermissionSet.al | 4 +++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Apps/W1/EDocument/app/Permissions/EDocCoreBasic.PermissionSet.al b/Apps/W1/EDocument/app/Permissions/EDocCoreBasic.PermissionSet.al index 149349c3ad..e81a34511d 100644 --- a/Apps/W1/EDocument/app/Permissions/EDocCoreBasic.PermissionSet.al +++ b/Apps/W1/EDocument/app/Permissions/EDocCoreBasic.PermissionSet.al @@ -7,6 +7,7 @@ namespace Microsoft.eServices.EDocument; using Microsoft.eServices.EDocument.IO.Peppol; using Microsoft.EServices.EDocument.OrderMatch; using Microsoft.eServices.EDocument.Service.Participant; +using Microsoft.eServices.EDocument.Payments; permissionset 6103 "E-Doc. Core - Basic" { @@ -29,5 +30,6 @@ permissionset 6103 "E-Doc. Core - Basic" tabledata "E-Doc. Service Supported Type" = im, tabledata "E-Doc. Imported Line" = imd, tabledata "E-Doc. Order Match" = imd, - tabledata "Service Participant" = imd; + tabledata "Service Participant" = imd, + tabledata "E-Document Payment" = imd; } diff --git a/Apps/W1/EDocument/app/Permissions/EDocCoreEdit.PermissionSet.al b/Apps/W1/EDocument/app/Permissions/EDocCoreEdit.PermissionSet.al index 81acc2e21f..59f059e7f1 100644 --- a/Apps/W1/EDocument/app/Permissions/EDocCoreEdit.PermissionSet.al +++ b/Apps/W1/EDocument/app/Permissions/EDocCoreEdit.PermissionSet.al @@ -7,6 +7,7 @@ namespace Microsoft.eServices.EDocument; using Microsoft.eServices.EDocument.IO.Peppol; using Microsoft.EServices.EDocument.OrderMatch; using Microsoft.eServices.EDocument.Service.Participant; +using Microsoft.eServices.EDocument.Payments; permissionset 6102 "E-Doc. Core - Edit" { @@ -29,5 +30,6 @@ permissionset 6102 "E-Doc. Core - Edit" tabledata "E-Doc. Service Supported Type" = IMD, tabledata "E-Doc. Imported Line" = IMD, tabledata "E-Doc. Order Match" = IMD, - tabledata "Service Participant" = IMD; + tabledata "Service Participant" = IMD, + tabledata "E-Document Payment" = IMD; } diff --git a/Apps/W1/EDocument/app/Permissions/EDocCoreObjects.PermissionSet.al b/Apps/W1/EDocument/app/Permissions/EDocCoreObjects.PermissionSet.al index 3000c3ad9d..42292c47c6 100644 --- a/Apps/W1/EDocument/app/Permissions/EDocCoreObjects.PermissionSet.al +++ b/Apps/W1/EDocument/app/Permissions/EDocCoreObjects.PermissionSet.al @@ -5,10 +5,12 @@ namespace Microsoft.eServices.EDocument; using Microsoft.eServices.EDocument.IO; +using Microsoft.eServices.EDocument.Integration.Payments; using Microsoft.eServices.EDocument.IO.Peppol; using Microsoft.EServices.EDocument.OrderMatch; using Microsoft.EServices.EDocument.OrderMatch.Copilot; using Microsoft.eServices.EDocument.Service.Participant; +using Microsoft.eServices.EDocument.Payments; permissionset 6100 "E-Doc. Core - Objects" { Assignable = false; @@ -28,6 +30,7 @@ permissionset 6100 "E-Doc. Core - Objects" table "E-Doc. Imported Line" = X, table "E-Doc. PO Match Prop. Buffer" = X, table "Service Participant" = X, + table "E-Document Payment" = X, codeunit "E-Document Import Job" = X, codeunit "E-Doc. Integration Management" = X, codeunit "E-Doc. Mapping" = X, @@ -69,6 +72,12 @@ permissionset 6100 "E-Doc. Core - Objects" codeunit "E-Doc. PO Copilot Matching" = X, codeunit "E-Doc. Attachment Processor" = X, codeunit "Service Participant" = X, + codeunit "Payment Integration Management" = X, + codeunit "Empty Payment Handler" = X, + codeunit "Send Payment" = X, + codeunit "Receive Payments" = X, + codeunit "Get Payment Details" = X, + codeunit "Sync Payments Job" = X, page "E-Doc. Changes Part" = X, page "E-Doc. Changes Preview" = X, page "E-Document Activities" = X, @@ -91,5 +100,6 @@ permissionset 6100 "E-Doc. Core - Objects" page "E-Doc. PO Copilot Prop" = X, page "E-Doc. PO Match Prop. Sub" = X, page "E-Doc. Order Match Act." = X, - page "Service Participants" = X; + page "Service Participants" = X, + page "E-Document Payments" = X; } diff --git a/Apps/W1/EDocument/app/Permissions/EDocCoreRead.PermissionSet.al b/Apps/W1/EDocument/app/Permissions/EDocCoreRead.PermissionSet.al index 30362c9850..6b14fa6ff3 100644 --- a/Apps/W1/EDocument/app/Permissions/EDocCoreRead.PermissionSet.al +++ b/Apps/W1/EDocument/app/Permissions/EDocCoreRead.PermissionSet.al @@ -7,6 +7,7 @@ namespace Microsoft.eServices.EDocument; using Microsoft.eServices.EDocument.IO.Peppol; using Microsoft.EServices.EDocument.OrderMatch; using Microsoft.eServices.EDocument.Service.Participant; +using Microsoft.eServices.EDocument.Payments; permissionset 6101 "E-Doc. Core - Read" { @@ -26,5 +27,6 @@ permissionset 6101 "E-Doc. Core - Read" tabledata "E-Doc. Service Supported Type" = R, tabledata "E-Doc. Imported Line" = R, tabledata "E-Doc. Order Match" = R, - tabledata "Service Participant" = R; + tabledata "Service Participant" = R, + tabledata "E-Document Payment" = R; } \ No newline at end of file From ac0892d530c5b0ad27fd649aa03dd4999dcf2d9d Mon Sep 17 00:00:00 2001 From: Grasiele Matuleviciute Date: Wed, 22 Jan 2025 13:11:00 +0200 Subject: [PATCH 7/9] Format fixes --- Apps/W1/EDocument/app/src/Document/EDocument.Table.al | 1 + .../Integration/Payments/GetPaymentDetails.Codeunit.al | 1 - .../Implementations/EmptyPaymentHandler.Codeunit.al | 1 - .../EDocument/app/src/Payments/EDocumentPayment.Table.al | 2 +- .../EDocument/app/src/Payments/EDocumentPayments.Page.al | 2 +- Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al | 2 +- .../test/src/Payments/EDocPaymentTest.Codeunit.al | 8 ++++---- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Apps/W1/EDocument/app/src/Document/EDocument.Table.al b/Apps/W1/EDocument/app/src/Document/EDocument.Table.al index 3c3b3c2c1a..b3a0967142 100644 --- a/Apps/W1/EDocument/app/src/Document/EDocument.Table.al +++ b/Apps/W1/EDocument/app/src/Document/EDocument.Table.al @@ -191,6 +191,7 @@ table 6121 "E-Document" CalcFormula = sum("E-Document Payment".Amount where("E-Document Entry No." = field("Entry No"))); } } + keys { key(Key1; "Entry No") diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al index 750d4664b9..19a5b02d22 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/GetPaymentDetails.Codeunit.al @@ -36,7 +36,6 @@ codeunit 6107 "Get Payment Details" this.IDocumentPaymentHandler := PaymentHandler; end; - /// /// Sets the parameters for the payment information receiving. /// diff --git a/Apps/W1/EDocument/app/src/Integration/Payments/Implementations/EmptyPaymentHandler.Codeunit.al b/Apps/W1/EDocument/app/src/Integration/Payments/Implementations/EmptyPaymentHandler.Codeunit.al index 9b29cc294a..8ca1839684 100644 --- a/Apps/W1/EDocument/app/src/Integration/Payments/Implementations/EmptyPaymentHandler.Codeunit.al +++ b/Apps/W1/EDocument/app/src/Integration/Payments/Implementations/EmptyPaymentHandler.Codeunit.al @@ -32,5 +32,4 @@ codeunit 6105 "Empty Payment Handler" implements IDocumentPaymentHandler begin // This method serves as a placeholder implementation for the IDocumentPaymentHandler interface. end; - } \ No newline at end of file diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al index 0c9ed468a7..3e3573d1a8 100644 --- a/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPayment.Table.al @@ -32,7 +32,7 @@ table 6101 "E-Document Payment" AutoIncrement = true; AllowInCustomizations = Always; } - field(20; "Date"; Date) + field(20; Date; Date) { Caption = 'Date'; ToolTip = 'Specifies the date when the payment was made.'; diff --git a/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al b/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al index 473ec29333..6953951c15 100644 --- a/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al +++ b/Apps/W1/EDocument/app/src/Payments/EDocumentPayments.Page.al @@ -18,7 +18,7 @@ page 6101 "E-Document Payments" { repeater(General) { - field("Date"; Rec."Date") + field(Date; Rec.Date) { Editable = this.PaymentEditable; } diff --git a/Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al b/Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al index 429e7c2bf1..32dfade4d7 100644 --- a/Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al +++ b/Apps/W1/EDocument/test/src/LibraryEDocument.Codeunit.al @@ -767,7 +767,7 @@ codeunit 139629 "Library - E-Document" EDocService."Document Format" := "E-Document Format"::Mock; EDocService."Service Integration V2" := ServiceIntegration; EDocService."Payment Integration" := PaymentIntegration; - EDocService.Insert(); + EDocService.Insert(true); end; end; diff --git a/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al b/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al index c0bdfcd84e..bfc3ebdcd4 100644 --- a/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al +++ b/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al @@ -297,11 +297,11 @@ codeunit 139501 "E-Doc. Payment Test" EDocumentPayment: Record "E-Document Payment"; begin Clear(this.EDocPaymentImplState); - EDocument.DeleteAll(); - EDocumentPayment.DeleteAll(); + EDocument.DeleteAll(false); + EDocumentPayment.DeleteAll(false); Clear(this.PurchaseHeader); - this.PurchaseHeader.DeleteAll(); + this.PurchaseHeader.DeleteAll(false); Clear(this.EDocService); end; @@ -325,7 +325,7 @@ codeunit 139501 "E-Doc. Payment Test" EDocumentPayment.Validate("E-Document Entry No.", EDocumentEntryNo); EDocumentPayment.Date := Today(); EDocumentPayment.Validate(Amount, Amount); - EDocumentPayment.Insert(); + EDocumentPayment.Insert(true); end; local procedure ReceivePayment(EDocument: Record "E-Document") From 89e251c3f27c794bc34625c3c540bc2cb91d1b8e Mon Sep 17 00:00:00 2001 From: Adele Smiciene Date: Wed, 22 Jan 2025 15:49:33 +0200 Subject: [PATCH 8/9] change automated tests --- .../src/Payments/EDocPaymentTest.Codeunit.al | 118 +++++++----------- 1 file changed, 42 insertions(+), 76 deletions(-) diff --git a/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al b/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al index c0bdfcd84e..77ebc282f5 100644 --- a/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al +++ b/Apps/W1/EDocument/test/src/Payments/EDocPaymentTest.Codeunit.al @@ -35,15 +35,7 @@ codeunit 139501 "E-Doc. Payment Test" // [GIVEN] Create E-Document service setup this.LibraryEDoc.CreateTestPaymentServiceForEDoc(this.EDocService, Enum::"Service Integration"::Mock, Enum::"Payment Integration"::Mock); - this.EDocService."Calculate Payment VAT" := false; - this.EDocService."Lookup Account Mapping" := false; - this.EDocService."Lookup Item GTIN" := false; - this.EDocService."Lookup Item Reference" := false; - this.EDocService."Resolve Unit Of Measure" := false; - this.EDocService."Validate Line Discount" := false; - this.EDocService."Verify Totals" := false; - this.EDocService."Use Batch Processing" := false; - this.EDocService.Modify(); + this.SetDefaultEDocServiceValues(this.EDocService, false); BindSubscription(this.EDocImplState); // [GIVEN] Create received E-Document @@ -71,14 +63,14 @@ codeunit 139501 "E-Doc. Payment Test" EDocument.FindLast(); // [THEN] Check that Paid Amount for the document is 0 - this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + this.CheckPaidAmount(EDocument, 0); // [GIVEN] Create partial payment for E-Document PaymentAmount := 100; this.CreateEDocumentPayment(EDocument, PaymentAmount); // [THEN] Check that Paid Amount for the document is updated - this.CheckPaidAmountAndPaymentStatus(EDocument, PaymentAmount, Enum::"E-Document Payment Progress"::"Partially Paid"); + this.CheckPaidAmount(EDocument, PaymentAmount); // [THEN] Check that Payments Direction is correct this.CheckPaymentDirection(EDocument, Enum::"E-Document Direction"::Outgoing); @@ -98,15 +90,7 @@ codeunit 139501 "E-Doc. Payment Test" // [GIVEN] Create E-Document service setup this.LibraryEDoc.CreateTestPaymentServiceForEDoc(this.EDocService, Enum::"Service Integration"::Mock, Enum::"Payment Integration"::Mock); - this.EDocService."Calculate Payment VAT" := false; - this.EDocService."Lookup Account Mapping" := false; - this.EDocService."Lookup Item GTIN" := false; - this.EDocService."Lookup Item Reference" := false; - this.EDocService."Resolve Unit Of Measure" := false; - this.EDocService."Validate Line Discount" := false; - this.EDocService."Verify Totals" := false; - this.EDocService."Use Batch Processing" := false; - this.EDocService.Modify(); + this.SetDefaultEDocServiceValues(this.EDocService, false); BindSubscription(this.EDocImplState); // [GIVEN] Create received E-Document @@ -134,13 +118,13 @@ codeunit 139501 "E-Doc. Payment Test" EDocument.FindLast(); // [THEN] Check that Paid Amount for the document is 0 - this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + this.CheckPaidAmount(EDocument, 0); // [GIVEN] Create partial payment for E-Document this.CreateFullEDocumentPayments(EDocument); // [THEN] Check that Paid Amount for the document is updated - this.CheckPaidAmountAndPaymentStatus(EDocument, EDocument."Amount Incl. VAT", Enum::"E-Document Payment Progress"::Paid); + this.CheckPaidAmount(EDocument, EDocument."Amount Incl. VAT"); // [THEN] Check that Payments Direction is correct this.CheckPaymentDirection(EDocument, Enum::"E-Document Direction"::Outgoing); @@ -161,15 +145,7 @@ codeunit 139501 "E-Doc. Payment Test" // [GIVEN] Create E-Document service setup and set VAT calculation this.LibraryEDoc.CreateTestPaymentServiceForEDoc(this.EDocService, Enum::"Service Integration"::Mock, Enum::"Payment Integration"::Mock); - this.EDocService."Calculate Payment VAT" := true; - this.EDocService."Lookup Account Mapping" := false; - this.EDocService."Lookup Item GTIN" := false; - this.EDocService."Lookup Item Reference" := false; - this.EDocService."Resolve Unit Of Measure" := false; - this.EDocService."Validate Line Discount" := false; - this.EDocService."Verify Totals" := false; - this.EDocService."Use Batch Processing" := false; - this.EDocService.Modify(); + this.SetDefaultEDocServiceValues(this.EDocService, true); BindSubscription(this.EDocImplState); // [GIVEN] Create received E-Document @@ -197,14 +173,14 @@ codeunit 139501 "E-Doc. Payment Test" EDocument.FindLast(); // [THEN] Check that Paid Amount for the document is 0 - this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + this.CheckPaidAmount(EDocument, 0); // [GIVEN] Create partial payment for E-Document PaymentAmount := 100; this.CreateEDocumentPayment(EDocument, PaymentAmount); // [THEN] Check that Paid Amount for the document is updated - this.CheckPaidAmountAndPaymentStatus(EDocument, PaymentAmount, Enum::"E-Document Payment Progress"::"Partially Paid"); + this.CheckPaidAmount(EDocument, PaymentAmount); // [THEN] Check that VAT amount is calculated this.CheckPaymentVATAmount(EDocument); @@ -238,14 +214,14 @@ codeunit 139501 "E-Doc. Payment Test" UnbindSubscription(this.EDocLogTest); // [THEN] Check that Paid Amount for the document is 0 - this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + this.CheckPaidAmount(EDocument, 0); // [WHEN] Receive payment for E-Document PaymentAmount := 1; this.CreateEDocumentPayment(EDocument, PaymentAmount); // [THEN] Check that Paid Amount for the document is updated - this.CheckPaidAmountAndPaymentStatus(EDocument, PaymentAmount, Enum::"E-Document Payment Progress"::"Partially Paid"); + this.CheckPaidAmount(EDocument, PaymentAmount); // [THEN] Check that Payments Direction is correct this.CheckPaymentDirection(EDocument, Enum::"E-Document Direction"::Incoming); @@ -279,13 +255,13 @@ codeunit 139501 "E-Doc. Payment Test" UnbindSubscription(this.EDocLogTest); // [THEN] Check that Paid Amount for the document is 0 - this.CheckPaidAmountAndPaymentStatus(EDocument, 0, Enum::"E-Document Payment Progress"::"Not Paid"); + this.CheckPaidAmount(EDocument, 0); // [WHEN] Receive payment for E-Document this.ReceivePayment(EDocument); // [THEN] Check that Paid Amount for the document is updated - this.CheckPaidAmountAndPaymentStatus(EDocument, 1, Enum::"E-Document Payment Progress"::"Partially Paid"); + this.CheckPaidAmount(EDocument, 1); // [THEN] Check that Payments Direction is correct this.CheckPaymentDirection(EDocument, Enum::"E-Document Direction"::Incoming); @@ -306,6 +282,19 @@ codeunit 139501 "E-Doc. Payment Test" Clear(this.EDocService); end; + local procedure SetDefaultEDocServiceValues(var EDocService: Record "E-Document Service"; CalculateVAT: Boolean) + begin + EDocService."Lookup Account Mapping" := false; + EDocService."Lookup Item GTIN" := false; + EDocService."Lookup Item Reference" := false; + EDocService."Resolve Unit Of Measure" := false; + EDocService."Validate Line Discount" := false; + EDocService."Verify Totals" := false; + EDocService."Use Batch Processing" := false; + EDocService."Calculate Payment VAT" := CalculateVAT; + EDocService.Modify(false); + end; + local procedure CreateEDocumentPayment(EDocument: Record "E-Document"; PaymentAmount: Decimal) begin this.CreateEDocumentPaymentRecord(EDocument."Entry No", PaymentAmount) @@ -339,56 +328,33 @@ codeunit 139501 "E-Doc. Payment Test" UnbindSubscription(this.EDocPaymentImplState); end; - local procedure CheckPaidAmountAndPaymentStatus(EDocument: Record "E-Document"; ExpectedPaidAmount: Decimal; ExpectedPaymentStatus: Enum "E-Document Payment Progress") - var - EDocumentPage: TestPage "E-Document"; - PaidAmount: Decimal; - PaymentStatus: Enum "E-Document Payment Progress"; + local procedure CheckPaidAmount(EDocument: Record "E-Document"; ExpectedPaidAmount: Decimal) begin - EDocumentPage.OpenView(); - EDocumentPage.GoToRecord(EDocument); - Evaluate(PaidAmount, EDocumentPage."Paid Amount".Value()); - Evaluate(PaymentStatus, EDocumentPage."Payment Status".Value()); - this.Assert.AreEqual(ExpectedPaidAmount, PaidAmount, 'Paid Amount is not updated.'); - this.Assert.AreEqual(ExpectedPaymentStatus, PaymentStatus, 'Payment Status is not updated.'); - EDocumentPage.Close(); + EDocument.CalcFields("Paid Amount"); + this.Assert.AreEqual(ExpectedPaidAmount, EDocument."Paid Amount", 'Paid Amount is not updated.'); end; local procedure CheckPaymentVATAmount(EDocument: Record "E-Document") var - EDocumentPage: TestPage "E-Document"; - PaymentsPage: TestPage "E-Document Payments"; - VATBaseAmount: Decimal; - VATAmount: Decimal; + EDocumentPayment: Record "E-Document Payment"; begin - EDocumentPage.OpenView(); - EDocumentPage.GoToRecord(EDocument); - PaymentsPage.Trap(); - EDocumentPage."Paid Amount".Drilldown(); - PaymentsPage.First(); - Evaluate(VATBaseAmount, PaymentsPage."VAT Base".Value()); - Evaluate(VATAmount, PaymentsPage."VAT Amount".Value()); - this.Assert.AreNotEqual(0, VATBaseAmount, 'Payment Base Amount is not calculated.'); - this.Assert.AreNotEqual(0, VATAmount, 'Payment VAT Amount is not calculated.'); - PaymentsPage.Close(); + EDocumentPayment.SetRange("E-Document Entry No.", EDocument."Entry No"); + if EDocumentPayment.FindSet() then + repeat + this.Assert.AreNotEqual(0, EDocumentPayment."VAT Base", 'Payment Base Amount is not calculated.'); + this.Assert.AreNotEqual(0, EDocumentPayment."VAT Amount", 'Payment VAT Amount is not calculated.'); + until EDocumentPayment.Next() = 0; end; local procedure CheckPaymentDirection(EDocument: Record "E-Document"; ExpectedDirection: Enum "E-Document Direction") var - EDocumentPage: TestPage "E-Document"; - PaymentsPage: TestPage "E-Document Payments"; - Direction: Enum "E-Document Direction"; + EDocumentPayment: Record "E-Document Payment"; begin - EDocumentPage.OpenView(); - EDocumentPage.GoToRecord(EDocument); - PaymentsPage.Trap(); - EDocumentPage."Paid Amount".Drilldown(); - PaymentsPage.First(); - repeat - Evaluate(Direction, PaymentsPage.Direction.Value()); - this.Assert.AreEqual(ExpectedDirection, Direction, 'Payment Direction is not correct.'); - until not PaymentsPage.Next(); - PaymentsPage.Close(); + EDocumentPayment.SetRange("E-Document Entry No.", EDocument."Entry No"); + if EDocumentPayment.FindSet() then + repeat + this.Assert.AreEqual(ExpectedDirection, EDocumentPayment.Direction, 'Payment Direction is not correct.'); + until EDocumentPayment.Next() = 0; end; [ModalPageHandler] From d6774b8881aa04fe7466b4b38bb63764d0b75638 Mon Sep 17 00:00:00 2001 From: Grasiele Matuleviciute Date: Wed, 22 Jan 2025 17:05:25 +0200 Subject: [PATCH 9/9] Removed workspace --- .../edocument_workspace.code-workspace | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 Apps/W1/EDocument/edocument_workspace.code-workspace diff --git a/Apps/W1/EDocument/edocument_workspace.code-workspace b/Apps/W1/EDocument/edocument_workspace.code-workspace deleted file mode 100644 index 35fb4f1ea3..0000000000 --- a/Apps/W1/EDocument/edocument_workspace.code-workspace +++ /dev/null @@ -1,24 +0,0 @@ -{ - "settings": { - "al.enableCodeAnalysis": true, - "al.codeAnalyzers": [ - "${CodeCop}", - "${UICop}", - "${AppSourceCop}" - ] - }, - "folders": [ - { - "name": "app", - "path": "app" - }, - { - "name": "test", - "path": "test" - }, - { - "name": "demo data", - "path": "demo data" - } - ] -} \ No newline at end of file