Skip to content

Commit fed9d31

Browse files
committed
Two step processing for E-Documents on sales side
1 parent 581fc25 commit fed9d31

File tree

8 files changed

+152
-5
lines changed

8 files changed

+152
-5
lines changed

Apps/W1/EDocument/app/src/Document/EDocument.Page.al

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ page 6121 "E-Document"
523523
StyleStatusTxt := 'Unfavorable';
524524
Rec.Status::Processed:
525525
StyleStatusTxt := 'Favorable';
526+
Rec.Status::Exported:
527+
StyleStatusTxt := 'Ambiguous';
526528
else
527529
StyleStatusTxt := 'None';
528530
end;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ------------------------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License. See License.txt in the project root for license information.
4+
// ------------------------------------------------------------------------------------------------
5+
namespace Microsoft.eServices.EDocument;
6+
7+
/// <summary>
8+
/// E-Document Exported Status
9+
/// </summary>
10+
codeunit 6185 "E-Doc Exported Status" implements IEDocumentStatus
11+
{
12+
procedure GetEDocumentStatus(): Enum "E-Document Status"
13+
begin
14+
exit(Enum::"E-Document Status"::Exported);
15+
end;
16+
}

Apps/W1/EDocument/app/src/Document/Status/EDocumentServiceStatus.Enum.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum 6106 "E-Document Service Status" implements IEDocumentStatus
1414
value(1; "Exported")
1515
{
1616
Caption = 'Exported';
17-
Implementation = IEDocumentStatus = "E-Doc Processed Status";
17+
Implementation = IEDocumentStatus = "E-Doc Exported Status";
1818
}
1919
value(2; "Sending Error")
2020
{

Apps/W1/EDocument/app/src/Document/Status/EDocumentStatus.Enum.al

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ enum 6108 "E-Document Status"
1111
value(0; "In Progress") { Caption = 'In progress'; }
1212
value(1; "Processed") { Caption = 'Processed'; }
1313
value(2; "Error") { Caption = 'Error'; }
14+
value(3; "Exported") { Caption = 'Exported'; }
1415
}

Apps/W1/EDocument/app/src/Processing/EDocumentProcessing.Codeunit.al

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ codeunit 6108 "E-Document Processing"
6565
#endif
6666
IEDocumentStatus: Interface IEDocumentStatus;
6767
InProgress: Boolean;
68+
Exported: Boolean;
6869
#if not CLEAN26
6970
IsHandled: Boolean;
7071
#endif
@@ -89,15 +90,22 @@ codeunit 6108 "E-Document Processing"
8990
end;
9091
EDocument.Status::"In Progress":
9192
InProgress := true;
93+
EDocument.Status::Exported:
94+
Exported := true;
9295
end;
9396

9497
until EDocumentServiceStatus.Next() = 0;
9598

9699
// If one service is in progress, then the whole E-Document is in progress
97-
if InProgress then
98-
EDocument.Validate(Status, EDocument.Status::"In Progress")
99-
else
100-
EDocument.Validate(Status, EDocument.Status::Processed);
100+
// If no service is in progress and at least one status is exported, then the whole E-Document is exported
101+
case true of
102+
InProgress:
103+
EDocument.Validate(Status, EDocument.Status::"In Progress");
104+
Exported:
105+
EDocument.Validate(Status, EDocument.Status::Exported);
106+
else
107+
EDocument.Validate(Status, EDocument.Status::Processed);
108+
end;
101109
EDocument.Modify(true);
102110
end;
103111

Apps/W1/EDocument/app/src/Processing/Import/Purchase/EDocumentPurchaseDraft.Page.al

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ page 6181 "E-Document Purchase Draft"
428428
StyleStatusTxt := 'Unfavorable';
429429
Rec.Status::Processed:
430430
StyleStatusTxt := 'Favorable';
431+
Rec.Status::Exported:
432+
StyleStatusTxt := 'Ambiguous';
431433
else
432434
StyleStatusTxt := 'None';
433435
end;

Apps/W1/EDocument/app/src/Workflow/EDocumentWorkFlowProcessing.Codeunit.al

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,37 @@ codeunit 6135 "E-Document WorkFlow Processing"
110110
Telemetry.LogMessage('0000LBW', EDocTelemetryProcessingEndScopeLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All);
111111
end;
112112

113+
internal procedure ExportEDocument(var EDocument: Record "E-Document"; WorkflowStepInstance: Record "Workflow Step Instance")
114+
var
115+
WorkflowStepArgument: Record "Workflow Step Argument";
116+
EDocumentService: Record "E-Document Service";
117+
begin
118+
if not ValidateFlowStep(EDocument, WorkflowStepArgument, WorkflowStepInstance) then
119+
exit;
120+
EDocumentService.Get(WorkflowStepArgument."E-Document Service");
121+
ExportEDocument(EDocument, EDocumentService);
122+
end;
123+
124+
internal procedure ExportEDocument(var EDocument: Record "E-Document"; EDocumentService: Record "E-Document Service")
125+
var
126+
Telemetry: Codeunit Telemetry;
127+
EDocumentHelper: Codeunit "E-Document Processing";
128+
FeatureTelemetry: Codeunit "Feature Telemetry";
129+
TelemetryDimensions: Dictionary of [Text, Text];
130+
begin
131+
FeatureTelemetry.LogUptake('0000KZ0', EDocumentHelper.GetEDocTok(), Enum::"Feature Uptake Status"::Used);
132+
EDocumentHelper.GetTelemetryDimensions(EDocumentService, EDocument, TelemetryDimensions);
133+
Telemetry.LogMessage('0000LB6', EDocTelemetryProcessingStartScopeLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All, TelemetryDimensions);
134+
135+
if IsEdocServiceUsingBatch(EDocumentService) then
136+
DoBatchExport(EDocument, EDocumentService)
137+
else
138+
DoExport(EDocument, EDocumentService);
139+
140+
FeatureTelemetry.LogUsage('0000KZ1', EDocumentHelper.GetEDocTok(), 'E-Document has been exported.');
141+
Telemetry.LogMessage('0000LB7', EDocTelemetryProcessingEndScopeLbl, Verbosity::Normal, DataClassification::OrganizationIdentifiableInformation, TelemetryScope::All);
142+
end;
143+
113144
internal procedure HandleNextEvent(var EDocument: Record "E-Document")
114145
var
115146
WorkflowManagement: Codeunit "Workflow Management";
@@ -190,6 +221,52 @@ codeunit 6135 "E-Document WorkFlow Processing"
190221
end;
191222
end;
192223

224+
local procedure DoBatchExport(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service")
225+
var
226+
TempEDocMappingLogs: Record "E-Doc. Mapping Log" temporary;
227+
EDocExport: Codeunit "E-Doc. Export";
228+
EDocIntMgt: Codeunit "E-Doc. Integration Management";
229+
EDocumentLog: Codeunit "E-Document Log";
230+
EDocumentBackgroundjobs: Codeunit "E-Document Background Jobs";
231+
EDocumentErrorHelper: Codeunit "E-Document Error Helper";
232+
TempBlob: Codeunit "Temp Blob";
233+
EDocServiceStatus: Enum "E-Document Service Status";
234+
BeforeExportEDocErrorCount: Dictionary of [Integer, Integer];
235+
IsAsync, IsHandled, AnyErrors : Boolean;
236+
ErrorCount: Integer;
237+
begin
238+
EDocServiceStatus := Enum::"E-Document Service Status"::"Pending Batch";
239+
EDocumentLog.InsertLog(EDocument, EDocumentService, Enum::"E-Document Service Status"::"Pending Batch");
240+
EDocumentProcessing.ModifyServiceStatus(EDocument, EDocumentService, EDocServiceStatus);
241+
EDocumentProcessing.ModifyEDocumentStatus(EDocument);
242+
243+
if EDocumentService."Batch Mode" = EDocumentService."Batch Mode"::Recurrent then
244+
exit;
245+
if EDocumentService."Batch Mode" = EDocumentService."Batch Mode"::Threshold then begin
246+
if not IsThresholdBatchCriteriaMet(EDocumentService, EDocument) then
247+
exit;
248+
end else begin
249+
OnBatchSendWithCustomBatchMode(EDocument, EDocumentService, IsHandled);
250+
if not IsHandled then
251+
Error(NotSupportedBatchModeErr, EDocumentService."Batch Mode");
252+
exit;
253+
end;
254+
255+
EDocExport.ExportEDocumentBatch(EDocument, EDocumentService, TempEDocMappingLogs, TempBlob, BeforeExportEDocErrorCount);
256+
257+
AnyErrors := false;
258+
EDocument.FindSet();
259+
repeat
260+
BeforeExportEDocErrorCount.Get(EDocument."Entry No", ErrorCount);
261+
if (EDocumentErrorHelper.ErrorMessageCount(EDocument) > ErrorCount) then
262+
AnyErrors := true;
263+
until EDocument.Next() = 0;
264+
265+
InsertLogsForThresholdBatch(EDocument, EDocumentService, TempEDocMappingLogs, TempBlob, AnyErrors);
266+
if not AnyErrors then
267+
HandleNextEvent(EDocument);
268+
end;
269+
193270
local procedure InsertLogsForThresholdBatch(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service"; var TempEDocMappingLogs: Record "E-Doc. Mapping Log" temporary; var TempBlob: Codeunit "Temp Blob"; Error: Boolean)
194271
var
195272
EDocMappingLog: Record "E-Doc. Mapping Log";
@@ -246,6 +323,14 @@ codeunit 6135 "E-Document WorkFlow Processing"
246323
HandleNextEvent(EDocument);
247324
end;
248325

326+
local procedure DoExport(var EDocument: Record "E-Document"; var EDocumentService: Record "E-Document Service")
327+
var
328+
EDocExport: Codeunit "E-Doc. Export";
329+
begin
330+
if EDocExport.ExportEDocument(EDocument, EDocumentService) then
331+
HandleNextEvent(EDocument);
332+
end;
333+
249334
local procedure ValidateFlowStep(var EDocument: Record "E-Document"; var WorkflowStepArgument: Record "Workflow Step Argument"; WorkflowStepInstance: Record "Workflow Step Instance"): Boolean
250335
var
251336
EDocErrorHelper: Codeunit "E-Document Error Helper";

Apps/W1/EDocument/app/src/Workflow/EDocumentWorkFlowSetup.Codeunit.al

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ codeunit 6139 "E-Document Workflow Setup"
3636
Workflow.Modify();
3737
end;
3838

39+
internal procedure InsertInitForSingleServiceTemplate()
40+
var
41+
Workflow: Record Workflow;
42+
WorkflowSetup: Codeunit "Workflow Setup";
43+
begin
44+
WorkflowSetup.InsertWorkflowTemplate(Workflow, EDocInitForSingleServiceTemplateWfCodeTxt, EDocInitForSingleServiceTemplateWfDescriptionTxt, EDocCategoryTxt);
45+
Workflow.Validate(Template, false);
46+
Workflow.Modify();
47+
InsertB2GWorkflowDetails(Workflow);
48+
Workflow.Validate(Template, true);
49+
Workflow.Modify();
50+
end;
51+
3952
internal procedure EDocReceived(): Code[128]
4053
begin
4154
exit('EDOCRECEIVED');
@@ -51,6 +64,11 @@ codeunit 6139 "E-Document Workflow Setup"
5164
exit('EDOCSendEDOCRESPONSE');
5265
end;
5366

67+
procedure EDocInitEDocResponseCode(): Code[128];
68+
begin
69+
exit('EDOCInitEDOCRESPONSE');
70+
end;
71+
5472
procedure EDocCreated(): code[128];
5573
begin
5674
exit('EDOCCREATEDEVENT')
@@ -78,6 +96,7 @@ codeunit 6139 "E-Document Workflow Setup"
7896
WorkflowResponseHandling: Codeunit "Workflow Response Handling";
7997
begin
8098
WorkflowResponseHandling.AddResponseToLibrary(EDocSendEDocResponseCode(), Database::"E-Document", 'Send E-Document using setup: %1', 'GROUP 50100');
99+
WorkflowResponseHandling.AddResponseToLibrary(EDocInitEDocResponseCode(), Database::"E-Document", 'Init E-Document using setup: %1', 'GROUP 50100');
81100
WorkflowResponseHandling.AddResponseToLibrary(EDocImport(), Database::"E-Document", 'Import E-Document using setup: %1', 'GROUP 50100');
82101
end;
83102

@@ -86,6 +105,7 @@ codeunit 6139 "E-Document Workflow Setup"
86105
begin
87106
case WorkflowResponse."Function Name" of
88107
EDocSendEDocResponseCode(),
108+
EDocInitEDocResponseCode(),
89109
EDocImport():
90110
Result := (CopyStr(StrSubstNo(WorkflowResponse.Description, WorkflowStepArgument."E-Document Service"), 1, 250));
91111
end;
@@ -102,6 +122,11 @@ codeunit 6139 "E-Document Workflow Setup"
102122
WorkflowResponseHandling.AddResponsePredecessor(EDocSendEDocResponseCode(), EDocCreated());
103123
WorkflowResponseHandling.AddResponsePredecessor(EDocSendEDocResponseCode(), EDocStatusChanged());
104124
end;
125+
EDocInitEDocResponseCode():
126+
begin
127+
WorkflowResponseHandling.AddResponsePredecessor(EDocInitEDocResponseCode(), EDocCreated());
128+
WorkflowResponseHandling.AddResponsePredecessor(EDocInitEDocResponseCode(), EDocStatusChanged());
129+
end;
105130
end;
106131
end;
107132

@@ -118,6 +143,11 @@ codeunit 6139 "E-Document Workflow Setup"
118143
EDocWorkflowProcessing.SendEDocument(Variant, ResponseWorkflowStepInstance);
119144
ResponseExecuted := true;
120145
end;
146+
EDocInitEDocResponseCode():
147+
begin
148+
EDocWorkflowProcessing.ExportEDocument(Variant, ResponseWorkflowStepInstance);
149+
ResponseExecuted := true;
150+
end;
121151
end;
122152
end;
123153

@@ -126,6 +156,7 @@ codeunit 6139 "E-Document Workflow Setup"
126156
begin
127157
InsertSendToSingleServiceTemplate();
128158
InsertSendToMultiServiceTemplate();
159+
InsertInitForSingleServiceTemplate();
129160
end;
130161

131162
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Workflow Setup", OnAddWorkflowCategoriesToLibrary, '', false, false)]
@@ -160,6 +191,8 @@ codeunit 6139 "E-Document Workflow Setup"
160191
EDocCategoryTxt: Label 'EDOC', Locked = true;
161192
EDocSendToSingleServiceTemplateWfCodeTxt: Label 'EDOCTOS', Locked = true;
162193
EDocSendToMultiServicesTemplateWfCodeTxt: Label 'EDOCTOM', Locked = true;
194+
EDocInitForSingleServiceTemplateWfCodeTxt: Label 'EDOCINIT', Locked = true;
163195
EDocSendToSingleServiceTemplateWfDescriptionTxt: Label 'Send to one service';
164196
EDocSendToMultiServicesTemplateWfDescriptionTxt: Label 'Send to multiple services';
197+
EDocInitForSingleServiceTemplateWfDescriptionTxt: Label 'Init for one service';
165198
}

0 commit comments

Comments
 (0)