Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E-Document Core] - Extending the Core app with payments #27972

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand All @@ -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;
}
88 changes: 88 additions & 0 deletions Apps/W1/EDocument/app/src/Document/EDocument.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand Down Expand Up @@ -119,6 +121,17 @@ 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 electronic document payment status.';
}
field("Paid Amount"; Rec."Paid Amount")
{
Visible = false;
}
}
group(ReceivingCompanyInfo)
{
Expand Down Expand Up @@ -346,6 +359,35 @@ 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';
Expand Down Expand Up @@ -507,6 +549,8 @@ page 6121 "E-Document"
SetIncomingDocActions();

EDocImport.ProcessEDocPendingOrderMatch(Rec);

this.SetPaymentStatus();
end;

local procedure SetStyle()
Expand Down Expand Up @@ -589,13 +633,57 @@ 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;
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";
EDocImport: Codeunit "E-Doc. Import";
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.';
Expand Down
11 changes: 10 additions & 1 deletion Apps/W1/EDocument/app/src/Document/EDocument.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand Down Expand Up @@ -182,8 +183,16 @@ 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")));
ToolTip = 'Specifies the amount that has already been paid.';
}
}

keys
{
key(Key1; "Entry No")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand Down Expand Up @@ -105,6 +106,19 @@ codeunit 6115 "E-Document Error Helper"
ErrorMessage.LogSimpleMessage(ErrorMessage."Message Type"::Error, Message);
end;

/// <summary>
/// Use it to clear errors for E-Document related to payments.
/// </summary>
/// <param name="EDocument">The E-Document record.</param>
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(false);
end;

internal procedure GetTelemetryImplErrLbl(): Text
begin
exit(EDocTelemetryImplErr);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Interface for sending and receiving payment information for E-Documents using E-Document service
/// </summary>
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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// ------------------------------------------------------------------------------------------------
// 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;

/// <summary>
/// Sets the global variable PaymentContext.
/// </summary>
/// <param name="PaymentContext">Payment context codeunit.</param>
procedure SetContext(PaymentContext: Codeunit PaymentContext)
begin
this.PaymentContext := PaymentContext;
end;

/// <summary>
/// Sets the IDocumentPaymentHandler instance.
/// </summary>
/// <param name="PaymentHandler">IDocumentPaymentHandler implementation used for receiving payment details.</param>
procedure SetInstance(PaymentHandler: Interface IDocumentPaymentHandler)
begin
this.IDocumentPaymentHandler := PaymentHandler;
end;

/// <summary>
/// Sets the parameters for the payment information receiving.
/// </summary>
/// <param name="EDocument">Electronic document for which payment is received.</param>
/// <param name="EDocumentService">Service for receiving payments.</param>
/// <param name="PaymentMetadata">TempBlob which contains received payment information.</param>
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// ------------------------------------------------------------------------------------------------
// 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;

/// <summary>
/// This codeunit is used to provide a default implementation for the "Document Payment Handler" interface.
/// </summary>
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
// 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;
}
Loading
Loading