diff --git a/src/Apps/W1/EDocument/App/src/Extensions/EDocPurchInvLine.TableExt.al b/src/Apps/W1/EDocument/App/src/Extensions/EDocPurchInvLine.TableExt.al new file mode 100644 index 0000000000..e035b87668 --- /dev/null +++ b/src/Apps/W1/EDocument/App/src/Extensions/EDocPurchInvLine.TableExt.al @@ -0,0 +1,37 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ +namespace Microsoft.Purchases.History; + +tableextension 6130 "E-Doc. Purch. Inv. Line" extends "Purch. Inv. Line" +{ + fields + { + field(6101; "Search Similarity Score"; Decimal) + { + AutoFormatExpression = ''; + AutoFormatType = 1; + Caption = 'Search Similarity Score'; + Editable = false; + DataClassification = SystemMetadata; + } + + } + + keys + { + key(KeySearch; "Search Similarity Score") + { + } + } + + internal procedure GetStyle() Result: Text + begin + if Rec."Search Similarity Score" < 0.5 then + exit('Unfavorable'); + + exit('None'); + end; + +} diff --git a/src/Apps/W1/EDocument/App/src/Processing/Import/PrepareDraft/PreparePurchaseEDocDraft.Codeunit.al b/src/Apps/W1/EDocument/App/src/Processing/Import/PrepareDraft/PreparePurchaseEDocDraft.Codeunit.al index 7997ca6d44..96defac7d4 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/Import/PrepareDraft/PreparePurchaseEDocDraft.Codeunit.al +++ b/src/Apps/W1/EDocument/App/src/Processing/Import/PrepareDraft/PreparePurchaseEDocDraft.Codeunit.al @@ -5,7 +5,7 @@ namespace Microsoft.eServices.EDocument.Processing.Import; using Microsoft.eServices.EDocument; -using Microsoft.eServices.EDocument.Processing.AI; +// using Microsoft.eServices.EDocument.Processing.AI; using Microsoft.eServices.EDocument.Processing.Import.Purchase; using Microsoft.eServices.EDocument.Processing.Interfaces; using Microsoft.Foundation.UOM; @@ -74,7 +74,7 @@ codeunit 6125 "Prepare Purchase E-Doc. Draft" implements IProcessStructuredData until EDocumentPurchaseLine.Next() = 0; // Apply all Copilot-powered matching techniques to the lines - CopilotLineMatching(EDocument."Entry No"); + // CopilotLineMatching(EDocument."Entry No"); end; // Log telemetry and activity sessions @@ -112,43 +112,43 @@ codeunit 6125 "Prepare Purchase E-Doc. Draft" implements IProcessStructuredData ActivityLog.Log(); end; - local procedure CopilotLineMatching(EDocumentEntryNo: Integer) - var - EDocumentPurchaseLine: Record "E-Document Purchase Line"; - begin - EDocumentPurchaseLine.SetLoadFields("E-Document Entry No.", "[BC] Purchase Type No.", "[BC] Deferral Code"); - EDocumentPurchaseLine.ReadIsolation(IsolationLevel::ReadCommitted); - - // Step 1: Apply historical pattern matching - EDocumentPurchaseLine.SetRange("E-Document Entry No.", EDocumentEntryNo); - EDocumentPurchaseLine.SetRange("[BC] Purchase Type No.", ''); - EDocumentPurchaseLine.SetRange("[BC] Item Reference No.", ''); - - if not EDocumentPurchaseLine.IsEmpty() then begin - Commit(); - Codeunit.Run(Codeunit::"E-Doc. Historical Matching", EDocumentPurchaseLine); - end; - - // Step 2: Apply line-to-account matching for remaining lines with no purchase type - Clear(EDocumentPurchaseLine); - EDocumentPurchaseLine.SetRange("E-Document Entry No.", EDocumentEntryNo); - EDocumentPurchaseLine.SetRange("[BC] Purchase Type No.", ''); - EDocumentPurchaseLine.SetRange("[BC] Item Reference No.", ''); - if not EDocumentPurchaseLine.IsEmpty() then begin - Commit(); - Codeunit.Run(Codeunit::"E-Doc. GL Account Matching", EDocumentPurchaseLine); - end; - - // Step 3: Apply deferral matching for lines with a purchase type but no deferral code - Clear(EDocumentPurchaseLine); - EDocumentPurchaseLine.SetRange("E-Document Entry No.", EDocumentEntryNo); - EDocumentPurchaseLine.SetRange("[BC] Deferral Code", ''); - EDocumentPurchaseLine.SetRange("[BC] Item Reference No.", ''); - if not EDocumentPurchaseLine.IsEmpty() then begin - Commit(); - if Codeunit.Run(Codeunit::"E-Doc. Deferral Matching", EDocumentPurchaseLine) then; - end; - end; + // local procedure CopilotLineMatching(EDocumentEntryNo: Integer) + // var + // EDocumentPurchaseLine: Record "E-Document Purchase Line"; + // begin + // EDocumentPurchaseLine.SetLoadFields("E-Document Entry No.", "[BC] Purchase Type No.", "[BC] Deferral Code"); + // EDocumentPurchaseLine.ReadIsolation(IsolationLevel::ReadCommitted); + + // // Step 1: Apply historical pattern matching + // EDocumentPurchaseLine.SetRange("E-Document Entry No.", EDocumentEntryNo); + // EDocumentPurchaseLine.SetRange("[BC] Purchase Type No.", ''); + // EDocumentPurchaseLine.SetRange("[BC] Item Reference No.", ''); + + // if not EDocumentPurchaseLine.IsEmpty() then begin + // Commit(); + // Codeunit.Run(Codeunit::"E-Doc. Historical Matching", EDocumentPurchaseLine); + // end; + + // // Step 2: Apply line-to-account matching for remaining lines with no purchase type + // Clear(EDocumentPurchaseLine); + // EDocumentPurchaseLine.SetRange("E-Document Entry No.", EDocumentEntryNo); + // EDocumentPurchaseLine.SetRange("[BC] Purchase Type No.", ''); + // EDocumentPurchaseLine.SetRange("[BC] Item Reference No.", ''); + // if not EDocumentPurchaseLine.IsEmpty() then begin + // Commit(); + // Codeunit.Run(Codeunit::"E-Doc. GL Account Matching", EDocumentPurchaseLine); + // end; + + // // Step 3: Apply deferral matching for lines with a purchase type but no deferral code + // Clear(EDocumentPurchaseLine); + // EDocumentPurchaseLine.SetRange("E-Document Entry No.", EDocumentEntryNo); + // EDocumentPurchaseLine.SetRange("[BC] Deferral Code", ''); + // EDocumentPurchaseLine.SetRange("[BC] Item Reference No.", ''); + // if not EDocumentPurchaseLine.IsEmpty() then begin + // Commit(); + // if Codeunit.Run(Codeunit::"E-Doc. Deferral Matching", EDocumentPurchaseLine) then; + // end; + // end; procedure OpenDraftPage(var EDocument: Record "E-Document") var diff --git a/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/EDocPurchaseDraftSubform.Page.al b/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/EDocPurchaseDraftSubform.Page.al index 3b770f226a..41f18bc607 100644 --- a/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/EDocPurchaseDraftSubform.Page.al +++ b/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/EDocPurchaseDraftSubform.Page.al @@ -5,6 +5,7 @@ namespace Microsoft.eServices.EDocument.Processing.Import.Purchase; using Microsoft.eServices.EDocument; +using Microsoft.eServices.EDocument.Processing.AI; using Microsoft.eServices.EDocument.Processing.Import; using Microsoft.Finance.Dimension; using Microsoft.Purchases.Document; @@ -168,6 +169,55 @@ page 6183 "E-Doc. Purchase Draft Subform" { Caption = '&Line'; Image = Line; + group("Classify") + { + Caption = 'Classify'; + action(ChooseFromHistory) + { + ApplicationArea = All; + Caption = 'Classify line from history'; + ToolTip = 'Choose values from similar lines on previously posted invoices.'; + Image = History; + + trigger OnAction() + var + TempPurchInvLine: Record "Purch. Inv. Line" temporary; + EDocPurchSearchHistory: Page "E-Doc Purch. Search History"; + begin + EDocPurchSearchHistory.SetDescription(Rec.Description); + EDocPurchSearchHistory.LookupMode := true; + if EDocPurchSearchHistory.RunModal() <> Action::LookupOK then + exit; + EDocPurchSearchHistory.GetRecord(TempPurchInvLine); + + if TempPurchInvLine."No." = '' then + exit; + + Rec."[BC] Purchase Type No." := TempPurchInvLine."No."; + Rec."[BC] Purchase Line Type" := TempPurchInvLine.Type; + Rec.Modify(); + CurrPage.Update(); + end; + } + action(SuggestGLAccount) + { + ApplicationArea = All; + Caption = 'Suggest G/L accounts'; + ToolTip = 'Suggests a G/L account based on the line description.'; + Image = SuggestLines; + + trigger OnAction() + begin + EDocumentPurchaseLine.SetRange("E-Document Entry No.", Rec."E-Document Entry No."); + EDocumentPurchaseLine.SetRange("[BC] Purchase Type No.", ''); + EDocumentPurchaseLine.SetRange("[BC] Item Reference No.", ''); + if not EDocumentPurchaseLine.IsEmpty() then + Codeunit.Run(Codeunit::"E-Doc. GL Account Matching", EDocumentPurchaseLine); + + CurrPage.Update(); + end; + } + } group("Order Matching") { Caption = 'Order matching'; diff --git a/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchSearchHistory.Page.al b/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchSearchHistory.Page.al new file mode 100644 index 0000000000..1b35d4d6ec --- /dev/null +++ b/src/Apps/W1/EDocument/App/src/Processing/Import/Purchase/History/EDocPurchSearchHistory.Page.al @@ -0,0 +1,128 @@ +// ------------------------------------------------------------------------------------------------ +// 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.Processing.Import.Purchase; + +using Microsoft.Purchases.History; +using System.Search; + +page 6157 "E-Doc Purch. Search History" +{ + PageType = List; + ApplicationArea = All; + SourceTableTemporary = true; + SourceTable = "Purch. Inv. Line"; + SourceTableView = sorting("Search Similarity Score") order(descending); + Editable = false; + Extensible = false; + InsertAllowed = false; + DeleteAllowed = false; + + layout + { + area(Content) + { + group(SearchFields) + { + ShowCaption = false; + field(DescriptionText; DescriptionText) + { + ApplicationArea = All; + Caption = 'Description'; + ToolTip = 'Specifies the description of the e-document purchase line history record.'; + Editable = true; + + trigger OnValidate() + begin + SearchAndFillPart(); + end; + + } + } + repeater(Lines) + { + Editable = false; + field("Document No."; Rec."Document No.") + { + ToolTip = 'Specifies the document number of the purchase invoice line.'; + } + field(Type; Rec.Type) + { + ToolTip = 'Specifies the type of the purchase invoice line.'; + } + field("No."; Rec."No.") + { + ToolTip = 'Specifies the number of the purchase invoice line.'; + } + field(Description; Rec.Description) + { + ToolTip = 'Specifies the description of the purchase invoice line.'; + } + field("Unit of Measure"; Rec."Unit of Measure") + { + ToolTip = 'Specifies the unit of measure of the purchase invoice line.'; + } + field("Direct Unit Cost"; Rec."Direct Unit Cost") + { + ToolTip = 'Specifies the direct unit cost of the purchase invoice line.'; + } + field(Amount; Rec.Amount) + { + ToolTip = 'Specifies the amount of the purchase invoice line.'; + } + field("Search Similarity Score"; Rec."Search Similarity Score") + { + ToolTip = 'Specifies the similarity score of the e-document purchase line search result.'; + StyleExpr = StyleTxt; + } + } + } + } + + var + DescriptionText: Text; + StyleTxt: Text; + + trigger OnAfterGetRecord() + begin + StyleTxt := Rec.GetStyle(); + end; + + trigger OnOpenPage() + begin + if DescriptionText <> '' then + SearchAndFillPart(); + end; + + internal procedure SetDescription(Text: Text) + begin + DescriptionText := Text; + end; + + local procedure SearchAndFillPart() + var + TempPurchInvLine: Record "Purch. Inv. Line" temporary; + PurchInvLine: Record "Purch. Inv. Line"; + TempResultTable: Record "Data Similarity Result" temporary; + SemanticDataSearch: Codeunit "Semantic Data Search"; + RecordRef: RecordRef; + begin + RecordRef.GetTable(PurchInvLine); + SemanticDataSearch.SetSearchTarget(RecordRef); + if not SemanticDataSearch.FindSimilar(DescriptionText, TempResultTable) then + exit; + + TempPurchInvLine.DeleteAll(); + if TempResultTable.FindSet() then + repeat + PurchInvLine.GetBySystemId(TempResultTable."System ID"); + TempPurchInvLine := PurchInvLine; + TempPurchInvLine."Search Similarity Score" := TempResultTable.Similarity; + Rec := TempPurchInvLine; + if Rec.Insert() then; + until TempResultTable.Next() = 0; + + end; + +} \ No newline at end of file