forked from microsoft/ALAppExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEDocument.Page.al
612 lines (575 loc) · 23.7 KB
/
EDocument.Page.al
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
// ------------------------------------------------------------------------------------------------
// 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;
using System.Telemetry;
using System.Utilities;
using Microsoft.eServices.EDocument.Integration.Send;
using Microsoft.eServices.EDocument.Integration.Receive;
using Microsoft.Bank.Reconciliation;
using Microsoft.eServices.EDocument.OrderMatch;
using Microsoft.eServices.EDocument.OrderMatch.Copilot;
page 6121 "E-Document"
{
ApplicationArea = Basic, Suite;
PageType = Card;
SourceTable = "E-Document";
InsertAllowed = false;
DeleteAllowed = false;
ModifyAllowed = false;
RefreshOnActivate = true;
layout
{
area(content)
{
group(General)
{
field(Record; RecordLinkTxt)
{
Caption = 'Document';
Editable = false;
ToolTip = 'Specifies the record, document, journal line, or ledger entry, that is linked to the electronic document.';
trigger OnDrillDown()
begin
Rec.ShowRecord();
CurrPage.Update();
end;
}
field("Electronic Document Status"; Rec.Status)
{
Editable = false;
Caption = 'Document Status';
ToolTip = 'Specifies the status of the electronic document.';
StyleExpr = StyleStatusTxt;
}
field(Direction; Rec.Direction)
{
Importance = Additional;
ToolTip = 'Specifies the direction of the electronic document.';
}
field("Workflow Code"; Rec."Workflow Code")
{
Editable = false;
Importance = Additional;
ToolTip = 'Specifies the Workflow used on the electronic document.';
}
field("Incoming E-Document No."; Rec."Incoming E-Document No.")
{
Importance = Additional;
ToolTip = 'Specifies the electronic document number.';
}
field("Document Type"; Rec."Document Type")
{
Importance = Additional;
ToolTip = 'Specifies the electronic document type.';
}
field("Document No."; Rec."Document No.")
{
Importance = Additional;
ToolTip = 'Specifies the document number of the electronic document.';
}
field("Document Date"; Rec."Document Date")
{
ToolTip = 'Specifies the document date of the electronic document.';
Importance = Additional;
}
field("Due Date"; Rec."Due Date")
{
Importance = Additional;
ToolTip = 'Specifies the due date of the electronic document.';
}
field("Order No."; Rec."Order No.")
{
Editable = false;
ToolTip = 'Specifies the related order number of the electronic document.';
Importance = Additional;
}
field("Amount Excl. VAT"; Rec."Amount Excl. VAT")
{
Importance = Additional;
ToolTip = 'Specifies the total amount of the electronic document excluding VAT.';
}
field("Amount Incl. VAT"; Rec."Amount Incl. VAT")
{
ToolTip = 'Specifies the total amount of the electronic document including VAT.';
Importance = Additional;
}
field("Currency Code"; Rec."Currency Code")
{
Importance = Additional;
ToolTip = 'Specifies the electronic document currency code.';
}
field("Bill-to/Pay-to No."; Rec."Bill-to/Pay-to No.")
{
Editable = false;
Importance = Additional;
ToolTip = 'Specifies the customer/vendor of the electronic document.';
}
field("Bill-to/Pay-to Name"; Rec."Bill-to/Pay-to Name")
{
ToolTip = 'Specifies the customer/vendor name of the electronic document.';
}
field("Posting Date"; Rec."Posting Date")
{
Importance = Additional;
ToolTip = 'Specifies the electronic document posting date.';
}
}
group(ReceivingCompanyInfo)
{
Caption = 'Receiving Company Information';
Visible = false;
field("Receiving Company VAT Reg. No."; Rec."Receiving Company VAT Reg. No.")
{
Caption = 'VAT Registration No.';
Editable = false;
ToolTip = 'Specifies the receiving company VAT number.';
}
field("Receiving Company GLN"; Rec."Receiving Company GLN")
{
Caption = 'GLN';
Editable = false;
Importance = Additional;
ToolTip = 'Specifies the receiving company GLN.';
}
field("Receiving Company Name"; Rec."Receiving Company Name")
{
Caption = 'Name';
Editable = false;
ToolTip = 'Specifies the receiving company name.';
}
field("Receiving Company Address"; Rec."Receiving Company Address")
{
Caption = 'Address';
Editable = false;
Importance = Additional;
ToolTip = 'Specifies the receiving company address.';
}
}
part(EInvoicePreview; "E-Invoice Lines")
{
Caption = 'E-Invoice Lines';
SubPageLink = "E-Document Entry No." = field("Entry No");
ShowFilter = false;
Visible = IsIncomingDoc and ShowPreview;
}
part(EdocoumentServiceStatus; "E-Document Service Status")
{
Caption = 'Service Status';
SubPageLink = "E-Document Entry No" = field("Entry No");
ShowFilter = false;
}
#if not CLEAN24
group(EDocServiceStatus)
{
Visible = false;
Enabled = false;
ObsoleteTag = '24.0';
ObsoleteReason = 'Part inside group moved out';
ObsoleteState = Pending;
}
#endif
part(ErrorMessagesPart; "Error Messages Part")
{
Visible = HasErrorsOrWarnings;
ShowFilter = false;
UpdatePropagation = Both;
}
#if not CLEAN24
group("Errors and Warnings")
{
Visible = false;
Enabled = false;
ObsoleteTag = '24.0';
ObsoleteReason = 'Part inside group moved out';
ObsoleteState = Pending;
}
#endif
}
}
actions
{
area(Processing)
{
group(Outgoing)
{
Caption = 'Outgoing';
action(Send)
{
Caption = 'Send Document';
ToolTip = 'Starts the document export.';
Image = SendElectronicDocument;
Visible = not IsIncomingDoc;
trigger OnAction()
begin
SendEDocument();
end;
}
action(Recreate)
{
Caption = 'Recreate Document';
ToolTip = 'Recreates the electronic document';
Image = CreateDocument;
Visible = not IsIncomingDoc;
trigger OnAction()
var
EDocService: Record "E-Document Service";
EDocExport: Codeunit "E-Doc. Export";
EDocServices: Page "E-Document Services";
begin
EDocServices.LookupMode := true;
if EDocServices.RunModal() = Action::LookupOK then begin
EDocServices.GetRecord(EDocService);
EDocumentErrorHelper.ClearErrorMessages(Rec);
EDocExport.Recreate(Rec, EDocService);
end
end;
}
action(GetApproval)
{
Caption = 'Get Approval';
ToolTip = 'Gets if the electronic document is approved or rejected';
Image = Approval;
Visible = not IsIncomingDoc;
trigger OnAction()
var
EDocService: Record "E-Document Service";
ActionContext: Codeunit ActionContext;
EDocServices: Page "E-Document Services";
begin
EDocServices.LookupMode := true;
if EDocServices.RunModal() = Action::LookupOK then begin
EDocServices.GetRecord(EDocService);
EDocumentErrorHelper.ClearErrorMessages(Rec);
EDocIntegrationManagement.GetApprovalStatus(Rec, EDocService, ActionContext);
end
end;
}
action(Cancel)
{
Caption = 'Cancel EDocument';
ToolTip = 'Cancels the electronic document';
Image = Cancel;
Visible = not IsIncomingDoc;
trigger OnAction()
var
EDocService: Record "E-Document Service";
ActionContext: Codeunit ActionContext;
EDocServices: Page "E-Document Services";
begin
EDocServices.LookupMode := true;
if EDocServices.RunModal() = Action::LookupOK then begin
EDocServices.GetRecord(EDocService);
EDocumentErrorHelper.ClearErrorMessages(Rec);
EDocIntegrationManagement.GetCancellationStatus(Rec, EDocService, ActionContext);
end
end;
}
}
group(Incoming)
{
Caption = 'Incoming';
action(GetBasicInfo)
{
Caption = 'Get Basic Info';
ToolTip = 'Gets the electronic document basic info.';
Image = GetOrder;
Visible = false;
trigger OnAction()
begin
EDocImport.GetBasicInfo(Rec);
end;
}
action(CreateDocument)
{
Caption = 'Reprocess Document';
ToolTip = 'Reprocess the electronic file to a purchase document.';
Image = CreateXMLFile;
Visible = IsIncomingDoc and (not IsProcessed);
trigger OnAction()
begin
EDocImport.ProcessDocument(Rec, false);
if EDocumentErrorHelper.HasErrors(Rec) then
Message(DocNotCreatedMsg, Rec."Document Type");
end;
}
action(CreateJournal)
{
Caption = 'Reprocess Journal Line';
ToolTip = 'Reprocess the electronic file to a journal line.';
Image = Journal;
Visible = IsIncomingDoc and (not IsProcessed);
trigger OnAction()
begin
EDocImport.ProcessDocument(Rec, true);
if EDocumentErrorHelper.HasErrors(Rec) then
Message(DocNotCreatedMsg, Rec."Document Type");
end;
}
#if not CLEAN24
action(UpdateOrder)
{
Caption = 'Update Order';
ToolTip = 'Updates related order.';
Image = UpdateDescription;
Visible = false;
Enabled = false;
ObsoleteTag = '24.0';
ObsoleteReason = 'Update order changed to "Receive E-Document To" on Vendor';
ObsoleteState = Pending;
trigger OnAction()
begin
exit;
end;
}
#endif
action(MatchToOrder)
{
Caption = 'Match Purchase Order';
ToolTip = 'Match E-document lines to Purchase Order.';
Image = Reconcile;
Visible = ShowMapToOrder;
trigger OnAction()
var
EDocOrderMatch: Codeunit "E-Doc. Line Matching";
begin
EDocOrderMatch.RunMatching(Rec);
end;
}
}
group(Troubleshoot)
{
Caption = 'Troubleshoot';
action(ImportManually)
{
Caption = 'Replace Source Document';
ToolTip = 'Import and replace the electronic document.';
Image = UpdateXML;
Visible = IsIncomingDoc and (not IsProcessed);
trigger OnAction()
begin
EDocImport.UploadDocument(Rec);
CurrPage.Update();
end;
}
action(TextToAccountMapping)
{
Caption = 'Map Text to Account';
Image = MapAccounts;
RunObject = Page "Text-to-Account Mapping Wksh.";
ToolTip = 'Create a mapping of text on electronic documents to identical text on specific debit, credit, and balancing accounts in the general ledger or on bank accounts so that the resulting document or journal lines are prefilled with the specified information.';
Visible = IsIncomingDoc and HasErrors and (not ShowRelink);
}
action(LinkOrder)
{
Caption = 'Update Purchase Order Link';
ToolTip = 'Updated Purchase Order link for E-Document to different Purchase Order.';
Image = LinkAccount;
Visible = IsIncomingDoc and ShowRelink and (not IsProcessed);
trigger OnAction()
begin
EDocImport.UpdatePurchaseOrderLink(Rec);
end;
}
}
}
area(Navigation)
{
action(EDocumentLog)
{
Caption = 'Logs';
ToolTip = 'Shows all logs for the E-Document.';
Image = Log;
RunObject = Page "E-Document Logs";
RunPageLink = "E-Doc. Entry No" = field("Entry No");
RunPageMode = View;
}
}
area(Promoted)
{
group(Category_Process)
{
actionref(MatchToOrderCE_Promoted; MatchToOrderCopilotEnabled) { }
actionref(MatchToOrder_Promoted; MatchToOrder) { }
actionref(LinkOrder_Promoted; LinkOrder) { }
actionref(CreateDocument_Promoted; CreateDocument) { }
actionref(CreateJournal_Promoted; CreateJournal) { }
actionref(ImportManually_Promoted; ImportManually) { }
actionref(TextToAccountMapping_Promoted; TextToAccountMapping) { }
actionref(Send_Promoted; Send) { }
actionref(Recreate_Promoted; Recreate) { }
actionref(Cancel_promoteed; Cancel) { }
actionref(Approval_promoteed; GetApproval) { }
}
group(Category_Troubleshoot)
{
Caption = 'Troubleshoot';
Visible = false;
}
#if not CLEAN24
group(Out)
{
Caption = 'Outgoing';
Visible = false;
ObsoleteTag = '24.0';
ObsoleteReason = 'Actionrefs moved to process category';
ObsoleteState = Pending;
}
group(In)
{
Caption = 'Incoming';
Visible = false;
ObsoleteTag = '24.0';
ObsoleteReason = 'Actionrefs moved to process category';
ObsoleteState = Pending;
actionref(GetBasicInfo_Promoted; GetBasicInfo)
{
ObsoleteTag = '24.0';
ObsoleteReason = 'Actionref removed';
ObsoleteState = Pending;
}
group(CreateDoc)
{
Visible = false;
ShowAs = SplitButton;
ObsoleteTag = '24.0';
ObsoleteReason = 'CreateDoc group removed';
ObsoleteState = Pending;
actionref(UpdateOrder_Promoted; UpdateOrder)
{
Visible = false;
ObsoleteTag = '24.0';
ObsoleteReason = 'Update order changed to "Receive E-Document To" on Vendor';
ObsoleteState = Pending;
}
}
}
#endif
}
area(Prompting)
{
action(MatchToOrderCopilotEnabled)
{
Caption = 'Match Purchase Order With Copilot';
ToolTip = 'Match E-document lines to Purchase Order.';
Image = SparkleFilled;
Visible = ShowMapToOrder and CopilotVisible;
trigger OnAction()
var
EDocOrderMatch: Codeunit "E-Doc. Line Matching";
begin
EDocOrderMatch.RunMatching(Rec, true);
end;
}
}
}
trigger OnOpenPage()
var
EDocPOMatching: Codeunit "E-Doc. PO Copilot Matching";
begin
ShowMapToOrder := false;
HasErrorsOrWarnings := false;
HasErrors := false;
IsProcessed := false;
CopilotVisible := EDocPOMatching.IsCopilotVisible();
end;
trigger OnAfterGetRecord()
begin
IsProcessed := Rec.Status = Rec.Status::Processed;
IsIncomingDoc := Rec.Direction = Rec.Direction::Incoming;
ShowPreview := (Rec."Document Type" = Rec."Document Type"::"Purchase Invoice") or (Rec."Document Type" = Rec."Document Type"::"Purchase Credit Memo");
RecordLinkTxt := EDocumentHelper.GetRecordLinkText(Rec);
HasErrorsOrWarnings := (EDocumentErrorHelper.ErrorMessageCount(Rec) + EDocumentErrorHelper.WarningMessageCount(Rec)) > 0;
HasErrors := EDocumentErrorHelper.ErrorMessageCount(Rec) > 0;
if HasErrorsOrWarnings then
ShowErrorsAndWarnings()
else
ClearErrorsAndWarnings();
SetStyle();
ResetActionVisiability();
SetIncomingDocActions();
EDocImport.ProcessEDocPendingOrderMatch(Rec);
end;
local procedure SetStyle()
begin
case Rec.Status of
Rec.Status::Error:
StyleStatusTxt := 'Unfavorable';
Rec.Status::Processed:
StyleStatusTxt := 'Favorable';
else
StyleStatusTxt := 'None';
end;
end;
local procedure ShowErrorsAndWarnings()
var
ErrorMessage: Record "Error Message";
TempErrorMessage: Record "Error Message" temporary;
begin
ErrorMessage.SetRange("Context Record ID", Rec.RecordId);
ErrorMessage.CopyToTemp(TempErrorMessage);
CurrPage.ErrorMessagesPart.Page.SetRecords(TempErrorMessage);
CurrPage.ErrorMessagesPart.Page.Update(false);
ErrorsAndWarningsNotification.Message(EDocHasErrorOrWarningMsg);
ErrorsAndWarningsNotification.Send();
end;
local procedure ClearErrorsAndWarnings()
var
TempErrorMessage: Record "Error Message" temporary;
begin
CurrPage.ErrorMessagesPart.Page.SetRecords(TempErrorMessage);
CurrPage.ErrorMessagesPart.Page.Update(false);
end;
local procedure SendEDocument()
var
EDocService: Record "E-Document Service";
SendContext: Codeunit SendContext;
EDocServices: Page "E-Document Services";
IsAsync: Boolean;
begin
EDocServices.LookupMode(true);
if EDocServices.RunModal() <> Action::LookupOK then
exit;
EDocServices.GetRecord(EDocService);
EDocumentErrorHelper.ClearErrorMessages(Rec);
if not EDocIntegrationManagement.Send(Rec, EDocService, SendContext, IsAsync) then
exit;
if IsAsync then
EDocumentBackgroundjobs.ScheduleGetResponseJob();
end;
local procedure SetIncomingDocActions()
var
EDocService: Record "E-Document Service";
EDocServiceStatus2: Record "E-Document Service Status";
EDocLog: Codeunit "E-Document Log";
FeatureTelemetry: Codeunit "Feature Telemetry";
EDocPOCopilotMatching: Codeunit "E-Doc. PO Copilot Matching";
begin
if not IsIncomingDoc then
exit;
EDocService := EDocLog.GetLastServiceFromLog(Rec);
if (Rec."Document Type" = Enum::"E-Document Type"::"Purchase Order") and (Rec.Status <> Rec.Status::Processed) then begin
EDocServiceStatus2.Get(Rec."Entry No", EDocService.Code);
ShowMapToOrder := EDocServiceStatus2.Status = Enum::"E-Document Service Status"::"Order Linked";
ShowRelink := true;
FeatureTelemetry.LogUptake('0000MMK', EDocPOCopilotMatching.FeatureName(), Enum::"Feature Uptake Status"::Discovered);
end;
end;
local procedure ResetActionVisiability()
begin
ShowMapToOrder := false;
ShowRelink := false;
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;
RecordLinkTxt, StyleStatusTxt : Text;
ShowRelink, ShowMapToOrder, HasErrorsOrWarnings, HasErrors, IsIncomingDoc, IsProcessed, CopilotVisible, ShowPreview : Boolean;
EDocHasErrorOrWarningMsg: Label 'Errors or warnings found for E-Document. Please review below in "Error Messages" section.';
DocNotCreatedMsg: Label 'Failed to create new %1 from E-Document. Please review errors below.', Comment = '%1 - E-Document Document Type';
}