Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Loading