Table 4596 SOA KPI Summary

Sales Order Agent, Microsoft.Agent.SalesOrderAgent

src/Apps/W1/SalesOrderAgent/app/src/RoleCenter/SOAKPISummary.Table.al179 lines, Copyright (c) Microsoft Corporation. MIT

// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------#pragma warning disable AS0007namespace Microsoft.Agent.SalesOrderAgent;using System.Agents;table 4596 "SOA KPI Summary"{    DataClassification = CustomerContent;    Access = Internal;    InherentEntitlements = RIMDX;    InherentPermissions = RIMDX;    ReplicateData = false;    Caption = 'Sales Order Agent';    Permissions = tabledata "SOA Setup" = r, tabledata "Agent Task" = r, tabledata "Agent Task Message" = r;    fields    {        field(1; "User Security ID"; Guid)        {            Caption = 'User Security ID';            ToolTip = 'Specifies the security identifier (SID) of the agent for whom the KPIs are tracked.';            DataClassification = EndUserPseudonymousIdentifiers;        }        field(2; "Received Emails"; Integer)        {            Caption = 'Received emails';            ToolTip = 'Specifies the total number of emails that the agent has received.';            DataClassification = CustomerContent;        }        field(3; "Total Emails"; Integer)        {            Caption = 'Total emails';            ToolTip = 'Specifies the total number of emails that the agent has received or created.';            DataClassification = CustomerContent;        }        field(4; "Total Quotes Created"; Integer)        {            Caption = 'Quotes created';            ToolTip = 'Specifies the total number of quotes that the agent has created. Both active and inactive quotes are included.';            DataClassification = CustomerContent;        }        field(5; "Total Orders Created"; Integer)        {            Caption = 'Orders created';            ToolTip = 'Specifies the total number of orders that the agent has created. Both active and inactive orders are included.';            DataClassification = CustomerContent;        }        field(6; "Total Amount Orders"; Decimal)        {            Caption = 'Amount inc. Tax of orders';            ToolTip = 'Specifies the total amount including tax of all orders that the agent has created. Both active and inactive orders are included.';            AutoFormatType = 1;            AutoFormatExpression = '';            DataClassification = CustomerContent;        }        field(20; "Last Updated DateTime"; DateTime)        {            Caption = 'Updated at';            ToolTip = 'Specifies the date and time when the KPI was last updated.';            DataClassification = CustomerContent;        }    }    keys    {        key(Key1; "User Security ID")        {            Clustered = true;        }    }    internal procedure GetSafe(AgentSecurityID: Guid)    begin        if IsNullGuid(AgentSecurityID) then            exit;        Rec.ReadIsolation := IsolationLevel::ReadCommitted;        if not Rec.Get(AgentSecurityID) then begin            Rec.Init();            Rec."User Security ID" := AgentSecurityID;            Rec.Insert();        end;    end;    internal procedure UpdateEntryKPIs(var SOAKPIEntry: Record "SOA KPI Entry"; PreviousAmount: Decimal; InsertedRecord: Boolean; AgentSecurityID: Guid)    begin        Rec.GetSafe(AgentSecurityID);        case SOAKPIEntry."Record Type" of            SOAKPIEntry."Record Type"::"Sales Order":                begin                    if InsertedRecord then begin                        Rec."Total Orders Created" += 1;                        Rec."Total Amount Orders" += SOAKPIEntry."Amount Including Tax";                        Rec.Modify();                        exit;                    end;                    if SOAKPIEntry."Amount Including Tax" > PreviousAmount then begin                        Rec."Total Amount Orders" += SOAKPIEntry."Amount Including Tax" - PreviousAmount;                        Rec.Modify();                    end;                    exit;                end;            SOAKPIEntry."Record Type"::"Sales Quote":                if InsertedRecord then begin                    Rec."Total Quotes Created" += 1;                    Rec.Modify();                    exit;                end;        end;    end;    internal procedure UpdateEmailKPIs(AgentSecurityID: Guid)    begin        UpdateEmailKPIs(AgentSecurityID, true);    end;    internal procedure UpdateEmailKPIs(AgentSecurityID: Guid; UseRefreshInterval: Boolean)    var        SOASetup: Record "SOA Setup";        AgentTask: Record "Agent Task";        AgentTaskMessage: Record "Agent Task Message";        BlankUpdatedDateTime: DateTime;        UpdateDateTime: DateTime;    begin        if IsNullGuid(AgentSecurityID) then            exit;        SOASetup.SetRange("User Security ID", AgentSecurityID);        if SOASetup.IsEmpty() then            exit;        Clear(BlankUpdatedDateTime);        Rec.GetSafe(AgentSecurityID);        if UseRefreshInterval then            if Rec."Last Updated DateTime" <> BlankUpdatedDateTime then                if CurrentDateTime() - Rec."Last Updated DateTime" < RefreshKPIsInterval() then                    exit;        UpdateDateTime := CurrentDateTime();        AgentTask.SetLoadFields(ID);        AgentTask.SetRange("Agent User Security ID", AgentSecurityID);        AgentTask.ReadIsolation := IsolationLevel::ReadCommitted;        AgentTaskMessage.ReadIsolation := IsolationLevel::ReadCommitted;        if AgentTask.FindSet() then            repeat                AgentTaskMessage.SetRange("Task ID", AgentTask.ID);                AgentTaskMessage.SetRange(Type);                if Rec."Last Updated DateTime" <> BlankUpdatedDateTime then                    AgentTaskMessage.SetFilter(SystemCreatedAt, '>=%1', Rec."Last Updated DateTime");                Rec."Total Emails" += AgentTaskMessage.Count();                AgentTaskMessage.SetRange(Type, AgentTaskMessage.Type::Input);                Rec."Received Emails" += AgentTaskMessage.Count();            until AgentTask.Next() = 0;        Rec."Last Updated DateTime" := UpdateDateTime;        Rec.Modify();    end;    local procedure RefreshKPIsInterval(): Integer    begin        if Rec."Received Emails" < 50 then            exit(1000); // 1 second        if Rec."Received Emails" < 100 then            exit(60000); // 1 minute        exit(300000); // 5 minutes    end;}