' SummaryPage2_CreditEnquiryReport_RealAML
Option Explicit On
Option Strict On

' #################################################################
' RealAML Credit Enquiry Report Summary Page Script
'
' Version: 1.09 (30/05/2023)
'
' Usage: Credit Enquiry and Log forms
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  18/06/2021  ISS                Created
'    1.01  05/08/2021  ISS      J027008   Updated to v1.1.1
'    1.02  24/09/2021  ISS      J027266   Updated to v1.3.0
'    1.03  06/10/2021  ISS      J027509   Updated to v1.4.0
'    1.04  28/06/2022  ISS      J028902   Updated to v1.6.2
'    1.05  30/06/2022  ISS      J027154   IgnoreBlanks option added to ClientWarnings
'    1.06  26/08/2022  ISS      J028902   Layout change to accomodate new fields
'    1.07  20/10/2022  ISS      J029859   Added Verification face and identification document images 
'    1.08  02/11/2022  ISS      J029875   Updated to v1.8.1 
'    1.09  30/05/2023  ISS      J031146   Removed reference to obsoleted property
' #################################################################

'#Const "OutOfDateWarningDays",Integer,30,"Number of days before warning the Enquiry is out-of-date."
'#Const "ShowPortalUrl",Boolean,True,"Show link to Aply portal to review Verifications."

' Constants
Private OutOfDateWarningDays As Integer = 30

' Special Constants
Const TestMode As Boolean = False

' Properties
Private AccountAppApplicant As finAccountAppApplicant
Private AccountAppLog As finAccountAppLog
Private Client As finClient
Private ClientLog As finClientLog

Public Function Main(source As Object,
                     eventId As String,
                     eventArgs As ISKeyValueList,
                     ByRef handled As Boolean,
                     ByRef returnValues As ISKeyValueList,
                     ByRef text As String) As Boolean

  Dim Response As ISCreditEnquiryResponse
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogs As ISServiceLogs

  ' Assume Success
  Main = True

  ' Get Constants
  With ScriptInfo.Constants
    OutOfDateWarningDays = .GetInteger("OutOfDateWarningDays", OutOfDateWarningDays)
  End With

  ' Get Service Logs
  Try
    Main = finBL.CreditBureau.GetCreditEnquiryServiceLogs(CInt(source), ServiceLogs)
  Catch ex As Exception
    Main = False
    finBL.Error.ErrorBeginFromException(ex)
  End Try
  If Main Then
    If ServiceLogs.Count = 0 Then
      Main = False
      finBL.Error.ErrorBegin("Invalid Service Log for a Credit Enquiry.")
    ElseIf ServiceLogs(0).RequestStatus <> iseAuditLogStatus.Success Then
      Main = False
      finBL.Error.ErrorBegin("Invalid Service Log. Initial Request was not successful.")
    Else
      ServiceLog = ServiceLogs(0)
      Response = DirectCast(ServiceLogs(0).ExResponse, ISCreditEnquiryResponse)
    End If
  End If

  ' Handle Events
  If Main Then
    Select Case eventId
      Case ""
        ' Main event, i.e., return main page content
        Main = Me.CreatePage(ServiceLogs, ServiceLog, Response, text)
    End Select
  End If

End Function

' AddCaption / AddRow Helpers
Private Sub AddCaptionSuccessFail(cells As ISSummaryTableCells, value As iseCreditBureau_RealAML_Result, valueRaw As String)

  Select Case value
    Case iseCreditBureau_RealAML_Result.Fail
      cells.AddCaptionWiki("{{icon|Outcome_Failed}}")
    Case iseCreditBureau_RealAML_Result.NotApplicable
      cells.AddCaptionWiki("{{icon|Outcome_Unknown}}").Tooltip = "Not Applicable"
    Case iseCreditBureau_RealAML_Result.NotPresent
      cells.AddCaptionWiki("").Tooltip = "Not Present"
    Case iseCreditBureau_RealAML_Result.Partial
      cells.AddCaptionWiki("{{icon|Outcome_Refer}}").Tooltip = "Partial"
    Case iseCreditBureau_RealAML_Result.Pass
      cells.AddCaptionWiki("{{icon|Outcome_Success}}")
    Case iseCreditBureau_RealAML_Result.Undefined
      cells.AddCaptionWiki(finBL.Runtime.TextUtilities.ProperCase(valueRaw))
  End Select

End Sub

' Bank Match results section
Private Function RealAML_VerificationResults_BankMatch(response_VerificationResultData As ISCreditEnquiryResponse_RealAML_VerificationResultData) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("BankMatch Result", "BankMatchResults", 2, 30, , TestMode)
  With SummaryTable
    .WidthHtml = "50%"

    .Rows.AddText("Overall Result", iseSummaryTableCellClass.Highlight2)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Overall Result:", response_VerificationResultData.BankMatch.OverallResult, response_VerificationResultData.BankMatch.OverallResultText)

    .Rows.AddText("Bank", iseSummaryTableCellClass.Highlight2)
    .AddRowCaptionText("Name:", response_VerificationResultData.BankMatch.BankName, False)
  End With
  SummaryTables.Add("BankMatchResults", SummaryTable)

  ' Return
  Return SummaryTables

End Function

' Create Page
Private Function CreatePage(serviceLogs As ISServiceLogs,
                            serviceLog As ISServiceLog,
                            response As ISCreditEnquiryResponse,
                            ByRef html As String) As Boolean

 Dim HtmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise ByRef
  html = ""

  ' Initialise
  HtmlSummaryPage2StringBuilder = finBL.CreateHtmlSummaryPage2StringBuilder()

  ' Initialise HTML
  With HtmlSummaryPage2StringBuilder
    ' Display test watermark
    If serviceLog.TestMode Then .Watermark = "Test Mode"

    ' Note: Embed images (will also embed CSS) since we want to be able to easily produce a PDF document
    .Initialise(ScriptInfo, False, True)

    ' Begin HTML Header
    .HtmlHeaderBegin(String.Format("{0} {1}", response.ServiceName, serviceLogs(0).ProductId), isefinSummaryPageStyle.ServiceReport)

    ' Theme
    .HtmlHeaderInsertServiceReportTheme("#43B79A", "#F2F2F2", "", "#F8F8F8")

    ' Intersoft PDF Options (including style tweaks)
    .HtmlHeaderInsertPdfGenerationHints("A4", "Portrait", 880, "1.5cm", "1.5cm", "1cm", "1cm", "font-size:0.9em")

    ' Finalise HTML Header
    .HtmlHeaderEnd()
  End With
  
  Select Case response.GetType()
    Case GetType(ISCreditEnquiryResponse_RealAML_Verify)
      Me.CreatePage_RealAML_Verify(serviceLogs, DirectCast(response, ISCreditEnquiryResponse_RealAML_Verify), HtmlSummaryPage2StringBuilder)

    Case GetType(ISCreditEnquiryResponse_RealAML_InstantVerify)
      Me.CreatePage_RealAML_InstantVerify(serviceLogs, DirectCast(response, ISCreditEnquiryResponse_RealAML_InstantVerify), HtmlSummaryPage2StringBuilder)

    Case Else
      Success = False
      finBL.Error.ErrorBeginFormat("Unexpected Response Type '{0}'.", TypeName(response))
  End Select

  ' Disclaimer
  HtmlSummaryPage2StringBuilder.AppendLine("<hr>")
  HtmlSummaryPage2StringBuilder.AppendLine("{{disclaimer|This report was produced by finPOWER Connect version " & finBL.VersionMajorMinorBuild & " using information retrieved from the " & response.ServiceName & " service on " & finBL.FormatDateTime(response.EnquiryDate, True, True, True) &"}}")

  ' Finalise HTML
  HtmlSummaryPage2StringBuilder.HtmlFinalise()

  ' Resolve Templates
  html = HtmlSummaryPage2StringBuilder.ToString(True)

  Return Success

End Function

' Customer Data action (Verify)
Private Function RealAML_VerificationResults_Verify(serviceLogs As ISServiceLogs,
                                                    serviceLogReportPk As Integer,
                                                    response_Verify As ISCreditEnquiryResponse_RealAML_Verify,
                                                    response_VerificationResult As ISCreditEnquiryResponse_RealAML_VerificationResult,
                                                    response_VerificationResultReport As ISCreditEnquiryResponse_RealAML_VerificationResultReport) As ISSummaryTables

  Dim ServiceLogPk As Integer
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()
  ServiceLogPk = serviceLogs(0).Pk
  
  If response_VerificationResult IsNot Nothing Then
    ' Warnings
    Warnings = ""
    If Len(response_VerificationResult.FirstName) <> 0 AndAlso Len(response_Verify.Request_Verify.FirstName) <> 0 Then
      If StrComp(response_VerificationResult.FirstName, response_Verify.Request_Verify.FirstName, CompareMethod.Text) <> 0 Then
        Warnings &= "{{warning|First Name does not match Request.}}"
      End If
    End If
    If Len(response_VerificationResult.LastName) <> 0 AndAlso Len(response_Verify.Request_Verify.LastName) <> 0 Then
      If StrComp(response_VerificationResult.LastName, response_Verify.Request_Verify.LastName, CompareMethod.Text) <> 0 Then
        Warnings &= "{{warning|Last Name does not match Request.}}"
      End If
    End If

    ' Client/ Applicant Warnings
    Warnings &= Me.GetClientWarnings(
      response_VerificationResult.Data.FirstName,
      response_VerificationResult.Data.MiddleNames,
      response_VerificationResult.Data.LastName,
      response_VerificationResult.Data.DateOfBirth,
      response_VerificationResult.Data.Address.ToAddressDetails(),
      False)

    ' Verification Data
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Customer Data Supplied", "CustomerData", 2, 30, , TestMode)
    With SummaryTable
      .WidthHtml = "100%"
      .MaxWidthHtml = "650px"

      .AddRowCaptionText("Name:", response_VerificationResult.FullName)
      .AddRowCaptionDate("Date of Birth:", response_VerificationResult.DateOfBirth, , finBL.Runtime.DateUtilities.AgeAsText(response_VerificationResult.DateOfBirth))
      If response_VerificationResult.Data.Address.ToAddressDetails().HasValue() Then
        .AddRowCaptionAddressDetailsPhysical("Address:", response_VerificationResult.Data.Address.ToAddressDetails(), False)
      End If

      ' Identification Types
      If response_VerificationResult.Data.HasNationalId OrElse response_VerificationResult.Data.HasNationalIdSecondary OrElse response_VerificationResult.Data.HasNationalIdTertiary Then
        .Rows.AddSectionHeading3(response_VerificationResult.Data.NationalIdHeading)  
      End If  
      If response_VerificationResult.Data.HasNationalId Then
        .AddRowCaptionText( response_VerificationResult.Data.NationalIdDescription & ":", response_VerificationResult.Data.NationalId, False)
      End If
      If response_VerificationResult.Data.HasNationalIdSecondary Then
        .AddRowCaptionText(response_VerificationResult.Data.NationalIdSecondaryDescription & ":", response_VerificationResult.Data.NationalIdSecondary, False)
      End If  
      If response_VerificationResult.Data.HasNationalIdTertiary Then
        .AddRowCaptionText(response_VerificationResult.Data.NationalIdTertiaryDescription & ":", response_VerificationResult.Data.NationalIdTertiary, False)
      End If  
      
      ' Warnings
      .TextAfter = Warnings

      ' Add Actions
      If response_VerificationResultReport Is Nothing Then
        ' Get Document?
        If response_VerificationResult.Data.IsCompleted OrElse response_VerificationResult.Data.IsCancelled Then
          If Len(response_VerificationResult.Data.ReportPdfUrl) <> 0 Then
            .Actions.AddApplicationShortcutUrl("GetDocument", "Get Report", String.Format("app://global?type=CreditEnquiry.GetDocuments&serviceLogPk={0}", serviceLogPk), True).ShowInWebInterfaces = True
          End If
        End If
      Else
       ' View Document
       .Actions.AddApplicationShortcutUrl("OpenDocument", "View Report", String.Format("app://global?type=CreditEnquiry.OpenDocument&serviceLogPk={0}", serviceLogReportPk), True).ShowInWebInterfaces = True

        If AccountAppApplicant IsNot Nothing AndAlso AccountAppLog IsNot Nothing Then
          If Len(AccountAppLog.DocumentFileName) = 0 Then
            .Actions.AddApplicationShortcutUrl("SaveDocument", "Save Report", String.Format("app://global?type=CreditEnquiry.SaveDocument&serviceLogPk={0}", serviceLogReportPk), True).ShowInWebInterfaces = True
          End If
        ElseIf Client IsNot Nothing AndAlso ClientLog IsNot Nothing Then
          If Len(ClientLog.DocumentFileName) = 0 Then
            .Actions.AddApplicationShortcutUrl("SaveDocument", "Save Report", String.Format("app://global?type=CreditEnquiry.SaveDocument&serviceLogPk={0}", serviceLogReportPk), True).ShowInWebInterfaces = True
          End If
        End If
      End If
    End With
    SummaryTables.Add("CustomerData", SummaryTable)
  End If

  ' Return
  Return SummaryTables

End Function

' Customer Data section (InstantVerify)
Private Function RealAML_VerificationResults_InstantVerify(serviceLogPk As Integer,
                                                           serviceLogReportPk As Integer,
                                                           response_InstantVerify As ISCreditEnquiryResponse_RealAML_InstantVerify,
                                                           response_VerificationResult As ISCreditEnquiryResponse_RealAML_VerificationResult,
                                                           response_VerificationResultReport As ISCreditEnquiryResponse_RealAML_VerificationResultReport) As ISSummaryTables

  Dim DateOfBirth As Date
  Dim FullName As String
  Dim ResponseData As ISCreditEnquiryResponse_RealAML_VerificationResultData
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If response_VerificationResult IsNot Nothing Then
    ' Warnings
    Warnings = ""
    If Len(response_VerificationResult.FirstName) <> 0 AndAlso Len(response_InstantVerify.Request_InstantVerify.FirstName) <> 0 Then
      If StrComp(response_VerificationResult.FirstName, response_InstantVerify.Request_InstantVerify.FirstName, CompareMethod.Text) <> 0 Then
        Warnings &= "{{warning|First Name does not match Request.}}"
      End If
    End If
    If Len(response_VerificationResult.LastName) <> 0 AndAlso Len(response_InstantVerify.Request_InstantVerify.LastName) <> 0 Then
      If StrComp(response_VerificationResult.LastName, response_InstantVerify.Request_InstantVerify.LastName, CompareMethod.Text) <> 0 Then
        Warnings &= "{{warning|Last Name does not match Request.}}"
      End If
    End If

    ResponseData = response_VerificationResult.Data
    FullName = response_VerificationResult.FullName
    DateOfBirth = response_VerificationResult.DateOfBirth
  Else
    ' Warnings
    Warnings = ""
    If Len(response_InstantVerify.FirstName) <> 0 AndAlso Len(response_InstantVerify.Request_InstantVerify.FirstName) <> 0 Then
      If StrComp(response_InstantVerify.FirstName, response_InstantVerify.Request_InstantVerify.FirstName, CompareMethod.Text) <> 0 Then
        Warnings &= "{{warning|First Name does not match Request.}}"
      End If
    End If
    If Len(response_InstantVerify.LastName) <> 0 AndAlso Len(response_InstantVerify.Request_InstantVerify.LastName) <> 0 Then
      If StrComp(response_InstantVerify.LastName, response_InstantVerify.Request_InstantVerify.LastName, CompareMethod.Text) <> 0 Then
        Warnings &= "{{warning|Last Name does not match Request.}}"
      End If
    End If

    ResponseData = response_InstantVerify.Data
    FullName = response_InstantVerify.FullName
    DateOfBirth = response_InstantVerify.DateOfBirth
  End If

  If ResponseData IsNot Nothing Then
    ' Client/ Applicant Warnings
    Warnings &= Me.GetClientWarnings(
      ResponseData.FirstName,
      ResponseData.MiddleNames,
      ResponseData.LastName,
      ResponseData.DateOfBirth,
      ResponseData.Address.ToAddressDetails(),
      False)

    ' Verification Data
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Customer Data Suppplied", "CustomerData", 2, 30, , TestMode)
    With SummaryTable
      .AddRowCaptionText("Name:", FullName)
      .AddRowCaptionDate("Date of Birth:", DateOfBirth, , finBL.Runtime.DateUtilities.AgeAsText(DateOfBirth))
      If ResponseData.Address.ToAddressDetails().HasValue() Then
        .AddRowCaptionAddressDetailsPhysical("Address:", ResponseData.Address.ToAddressDetails(), False)
      End If
 
      ' Identification Types
      If ResponseData.HasNationalId OrElse ResponseData.HasNationalIdSecondary OrElse ResponseData.HasNationalIdTertiary Then
        .Rows.AddSectionHeading3(ResponseData.NationalIdHeading)  
      End If  
      If ResponseData.HasNationalId Then
        .AddRowCaptionText( ResponseData.NationalIdDescription & ":", ResponseData.NationalId, False)
      End If
      If ResponseData.HasNationalIdSecondary Then
        .AddRowCaptionText(ResponseData.NationalIdSecondaryDescription & ":", ResponseData.NationalIdSecondary, False)
      End If  
      If ResponseData.HasNationalIdTertiary Then
        .AddRowCaptionText(ResponseData.NationalIdTertiaryDescription & ":", ResponseData.NationalIdTertiary, False)
      End If  
 
      ' Warnings
      .TextAfter = Warnings

      ' Add Actions
      If response_VerificationResultReport Is Nothing Then
        ' Get Document?
        If ResponseData.IsCompleted OrElse ResponseData.IsCancelled Then
          If Len(ResponseData.ReportPdfUrl) <> 0 Then
            .Actions.AddApplicationShortcutUrl("GetDocument", "Get Report", String.Format("app://global?type=CreditEnquiry.GetDocuments&serviceLogPk={0}", serviceLogPk), True).ShowInWebInterfaces = True
          End If
        End If
      Else
       ' View Document
       .Actions.AddApplicationShortcutUrl("OpenDocument", "View Report", String.Format("app://global?type=CreditEnquiry.OpenDocument&serviceLogPk={0}", serviceLogReportPk), True).ShowInWebInterfaces = True

        If AccountAppApplicant IsNot Nothing AndAlso AccountAppLog IsNot Nothing Then
          If Len(AccountAppLog.DocumentFileName) = 0 Then
            .Actions.AddApplicationShortcutUrl("SaveDocument", "Save Report", String.Format("app://global?type=CreditEnquiry.SaveDocument&serviceLogPk={0}", serviceLogReportPk), True).ShowInWebInterfaces = True
          End If
        ElseIf Client IsNot Nothing AndAlso ClientLog IsNot Nothing Then
          If Len(ClientLog.DocumentFileName) = 0 Then
            .Actions.AddApplicationShortcutUrl("SaveDocument", "Save Report", String.Format("app://global?type=CreditEnquiry.SaveDocument&serviceLogPk={0}", serviceLogReportPk), True).ShowInWebInterfaces = True
          End If
        End If
      End If
    End With
    SummaryTables.Add("CustomerData", SummaryTable)
  End If

  ' Return
  Return SummaryTables

End Function

' Data checkers for Alerts section
Public Sub CheckEnquiryDate(enquiryDate As Date,
                            Warnings As finWarnings)
  Dim Days As Integer

  Days = CInt(DateDiff(DateInterval.Day, enquiryDate, finBL.TimeZoneFunctions.GetCurrentLocalDateTime()))
  If Days > OutOfDateWarningDays Then
    Warnings.AddWarning(String.Format("This is an OLD Report, data is from {0} days ago.", Days),,, isefinWarningLevel.Critical)
  End If

End Sub

' Face Match results section
Private Function RealAML_VerificationResults_FaceMatch(serviceLogs As ISServiceLogs,
                                                       response_VerificationResultData As ISCreditEnquiryResponse_RealAML_VerificationResultData,
                                                       enquiryDate As Date) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim ImageIndex As Integer
    
  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()
  
  SummaryTable = SummaryTables.CreateSummaryTableInformation("FaceMatch", "FaceMatch", 2, 30, , TestMode)
  With SummaryTable
    .WidthHtml = "100%"
    .MaxWidthHtml = "650px"
    
    ' Face Image (Right Hand Side)
    ImageIndex = finBL.CreditBureau.Service_RealAML.GetDownloadedFile(serviceLogs, "face.image")
    If ImageIndex <> -1 Then
      .TextRight = "{{ServiceLogImage MaxWidth='270px' ServiceLogPk='" & CStr(serviceLogs(ImageIndex).Pk) & "'}}"
    End If 

    .Rows.AddSectionHeading3("FaceMatch Result")  
    Me.AddRowCaptionSuccessFail(SummaryTable, "Overall Result:", response_VerificationResultData.FaceMatch.OverallResult, response_VerificationResultData.FaceMatch.OverallResultText)
    .AddRowCaptionDateTimeWithTimeZone("Completed Date and Time:", response_VerificationResultData.FacematchCompletedAt, finBL.Settings.TimeZoneId)

    .Rows.AddSectionHeading3("FaceMatch Primary Checks")  
    Me.AddRowCaptionSuccessFail(SummaryTable, "Face Comparison Check:", response_VerificationResultData.FaceMatch.FaceComparisonResult, response_VerificationResultData.FaceMatch.FaceComparisonResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Passive Liveness Check:", response_VerificationResultData.FaceMatch.PhotoLivelinessResult, response_VerificationResultData.FaceMatch.PhotoLivelinessResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Data Comparison Check:", response_VerificationResultData.FaceMatch.DataComparisonResult, response_VerificationResultData.FaceMatch.DataComparisonResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Identity Document Check:", response_VerificationResultData.FaceMatch.IdentityDocumentResult, response_VerificationResultData.FaceMatch.IdentityDocumentResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Anti-Tamper Check:", response_VerificationResultData.FaceMatch.AntiTamperResult, response_VerificationResultData.FaceMatch.AntiTamperResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Document Not-Expired Check:", response_VerificationResultData.FaceMatch.DocumentExpiryResult, response_VerificationResultData.FaceMatch.DocumentExpiryResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Screen Replay Attack:", response_VerificationResultData.FaceMatch.DocumentExpiryResult, response_VerificationResultData.FaceMatch.IdDocLivelinessResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Duplicate Liveness Photo (beta):", response_VerificationResultData.FaceMatch.DocumentExpiryResult, response_VerificationResultData.FaceMatch.AgencyDuplicateResultText)

    .Rows.AddSectionHeading3("FaceMatch Secondary Checks")  
    If response_VerificationResultData.FaceMatch.PortraitsComparisonResult <> iseCreditBureau_RealAML_FaceMatchResult.Undefined Then
      ' Deprecated by RealAML in Version 1.6.3
      Me.AddRowCaptionSuccessFail(SummaryTable, "Portrait Image Comparison:", response_VerificationResultData.FaceMatch.PortraitsComparisonResult, response_VerificationResultData.FaceMatch.PortraitsComparisonResultText)
    End If   
    Me.AddRowCaptionSuccessFail(SummaryTable, "Machine-Readable Zone Check:", response_VerificationResultData.FaceMatch.MrzResult, response_VerificationResultData.FaceMatch.MrzResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Liveness Photo Age:", response_VerificationResultData.FaceMatch.PortraitAgeResult, response_VerificationResultData.FaceMatch.PortraitAgeResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Public Figure Check:", response_VerificationResultData.FaceMatch.PublicFigureResult, response_VerificationResultData.FaceMatch.PublicFigureResultText)
    .AddRowCaptionText("Matched Public Figures:", response_VerificationResultData.FaceMatch.MatchedPublicFiguresToCsv, False)
  End With
  SummaryTables.Add("FaceMatch", SummaryTable)
  
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Scanned OCR Data", "ScannedOcrData", 3, 30, , TestMode)
  With SummaryTable
    .WidthHtml = "100%"
    .MaxWidthHtml = "650px"

    ' ID Document Images
    .TextRight = ""
    ImageIndex = finBL.CreditBureau.Service_RealAML.GetDownloadedFile(serviceLogs, "IdDocument.FrontImage")
    If ImageIndex <> -1 Then
      .TextRight &= "{{ServiceLogImage MaxWidth='270px' ServiceLogPk='" & CStr(serviceLogs(ImageIndex).Pk) & "'}}"
    End If  
    ImageIndex = finBL.CreditBureau.Service_RealAML.GetDownloadedFile(serviceLogs, "IdDocument.BackImage")
    If ImageIndex <> -1 Then
      .TextRight &= "{{ServiceLogImage MaxWidth='270px' ServiceLogPk='" & CStr(serviceLogs(ImageIndex).Pk) & "'}}"
    End If  

    .AddRowCaptionText("Identification Document:", response_VerificationResultData.FaceMatch.OcrData.NationalIdHeading)  
    .AddRowCaptionText("Full Name:", response_VerificationResultData.FaceMatch.OcrData.FullName)
    .AddRowCaptionDate("Date of Birth:", response_VerificationResultData.FaceMatch.OcrData.BirthDate, , finBL.Runtime.DateUtilities.AgeAsText(response_VerificationResultData.FaceMatch.OcrData.BirthDate))
    If response_VerificationResultData.FaceMatch.OcrData.Address.ToAddressDetails.HasValue() Then
      .AddRowCaptionAddressDetailsPhysical("Address:", response_VerificationResultData.FaceMatch.OcrData.Address.ToAddressDetails, False)
    End If
    If response_VerificationResultData.FaceMatch.OcrData.HasNationalId Then
      .AddRowCaptionText( response_VerificationResultData.FaceMatch.OcrData.NationalIdDescription & ":", response_VerificationResultData.FaceMatch.OcrData.NationalId, False)
    End If
    If response_VerificationResultData.FaceMatch.OcrData.HasNationalIdSecondary Then
      .AddRowCaptionText(response_VerificationResultData.FaceMatch.OcrData.NationalIdSecondaryDescription & ":", response_VerificationResultData.FaceMatch.OcrData.NationalIdSecondary, False)
    End If  
    If response_VerificationResultData.FaceMatch.OcrData.HasNationalIdTertiary Then
      .AddRowCaptionText(response_VerificationResultData.FaceMatch.OcrData.NationalIdTertiaryDescription & ":", response_VerificationResultData.FaceMatch.OcrData.NationalIdTertiary, False)
    End If  

    .AddRowCaptionDate("Issued:", response_VerificationResultData.FaceMatch.OcrData.IssueDate, False)
    If response_VerificationResultData.FaceMatch.OcrData.ExpiryDate <> Nothing Then
      If response_VerificationResultData.FaceMatch.OcrData.ExpiryDate < enquiryDate Then
        .AddRowCaptionDate("Expiry:", response_VerificationResultData.FaceMatch.OcrData.ExpiryDate, , "**!!Expired!!**")
      Else
        .AddRowCaptionDate("Expiry:", response_VerificationResultData.FaceMatch.OcrData.ExpiryDate, , "")
      End If
    End If

    If response_VerificationResultData.FaceMatch.OcrData.Address.HasData Then
      .AddRowCaptionText("Country:", response_VerificationResultData.FaceMatch.OcrData.Address.Country)
    End If
    
    ' Client/ Applicant Warnings
    If response_VerificationResultData.FaceMatch.OcrData.HasDataValues Then
      .TextAfter = Me.GetClientWarnings(
        response_VerificationResultData.FaceMatch.OcrData.FirstName,
        response_VerificationResultData.FaceMatch.OcrData.MiddleNames,
        response_VerificationResultData.FaceMatch.OcrData.LastName,
        response_VerificationResultData.FaceMatch.OcrData.BirthDate,
        response_VerificationResultData.FaceMatch.OcrData.Address.ToAddressDetails,
        True)
    Else
      .TextAfter = "{{warning|OCR data is not available.|true}}"
    End If

    .Rows.AddSectionHeading3("Liveness Stats")  
    .AddRowCaptionText("Quality:", response_VerificationResultData.FaceMatch.LivenessQuality)
    .AddRowCaptionText("Probability:", response_VerificationResultData.FaceMatch.LivenessProbability)
  End With
  SummaryTables.Add("ScannedOcrData", SummaryTable)
  
  ' Return
  Return SummaryTables

End Function

' Headings section
Private Function RealAML_InstantVerify_EnquiryDetails(serviceLogs As ISServiceLogs,
                                                      response_InstantVerify As ISCreditEnquiryResponse_RealAML_InstantVerify,
                                                      response_VerificationResult As ISCreditEnquiryResponse_RealAML_VerificationResult,
                                                      response_VerificationResultReport As ISCreditEnquiryResponse_RealAML_VerificationResultReport) As ISSummaryTables

  Dim Days As Integer
  Dim ResponseData As ISCreditEnquiryResponse_RealAML_VerificationResultData
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If response_VerificationResult IsNot Nothing Then
    ResponseData = response_VerificationResult.Data
  Else
    ResponseData = response_InstantVerify.Data
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "EnquiryDetails", , , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Issue Date and Time:", response_InstantVerify.EnquiryUtcDate, finBL.Settings.TimeZoneId)
    If ResponseData IsNot Nothing Then
      .AddRowCaptionUtcDateTimeWithTimeZone("Completed Date and Time:", ResponseData.CompletedAt, finBL.Settings.TimeZoneId)
    End If
    .AddRowCaptionText("Reference:", serviceLogs(0).RequestReference)

    If Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Client:", client.ClientId, client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", client.ClientId)
      End With
    ElseIf AccountAppApplicant IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Applicant:", AccountAppApplicant.AccountApp.AccountAppId, AccountAppApplicant.Name)
        .Cells(1).HyperlinkSetFormShow("AccountApps", AccountAppApplicant.AccountApp.AccountAppId, "Applicants")
      End With
    ElseIf Len(response_InstantVerify.Request.ClientId) <> 0 Then
      .AddRowCaptionWiki("Client:", String.Format("**{0} !!Not Found!!**", response_InstantVerify.Request.ClientId))
    End If

    .AddRowCaptionText("Signature Key:", ResponseData.SignatureKey) ' "RealAML Reference" ?
    .AddRowCaptionText("Phone:", ResponseData.PhoneFormatted, False)
    .AddRowCaptionText("Email:", ResponseData.Email, False)
    .AddRowCaptionText("Verification Type:", ResponseData.VerificationTypeText, True)

    ' Website URL Link
    If Len(ResponseData.Url) <> 0 Then
      If ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.InProgress Then
        .Rows.AddCaptionText("Verification Link:", ResponseData.Url).Cells(1).HyperlinkSetExternal(ResponseData.Url)
      End If
    End If
    
    ' IP Addresses
    .AddRowCaptionText("IP Address(es):", ResponseData.UniqueIpAddressesResolved)

    If ResponseData.IsCompleted Then
      .AddRowCaptionDateTime("QuickID completed at:", ResponseData.QuickIdCompletedAt)
      .AddRowCaptionDateTime("FaceMatch completed at:", ResponseData.FacematchCompletedAt)
    ElseIf ResponseData.IsCancelled Then
      ' Ignore
    Else
      .AddRowCaptionBooleanYesNo("Completed:", ResponseData.IsCompleted, True)

      If ResponseData.QuickIdIsCompleted.HasValue() Then
        .AddRowCaptionBooleanYesNo("QuickID Completed:", ResponseData.QuickIdIsCompleted.GetValueOrDefault(), True)
      End If
      If ResponseData.FaceMatchIsCompleted.HasValue() Then
        .AddRowCaptionBooleanYesNo("FaceMatch Completed:", ResponseData.FaceMatchIsCompleted.GetValueOrDefault(), True)
      End If
    End If

    ' Add Actions
    If ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.InProgress Then
      With .Actions
        .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("app://global?type=CreditEnquiry.GetReport&serviceLogPk={0}&NotifyAction=CreditEnquiry.Refresh", serviceLogs(0).Pk), True).ShowInWebInterfaces = True
        .AddApplicationShortcutUrl("Resend", "Resend", String.Format("app://global?type=CreditEnquiry.Resend&serviceLogPk={0}&NotifyAction=CreditEnquiry.Refresh", serviceLogs(0).Pk), True).ShowInWebInterfaces = True
      End With
    End If

    ' Warnings
    Warnings = ""

    ' Out of date
    Days = CInt(DateDiff(DateInterval.Day, response_InstantVerify.EnquiryUtcDate, finBL.TimeZoneFunctions.GetCurrentUtcDateTime()))
    If Days > OutOfDateWarningDays Then
       Warnings &= "{{Warning|This Report is " & CStr(Days) & " days old.}}"
    End If

    .TextAfter = Warnings
  End With
  SummaryTables.Add("EnquiryDetails", SummaryTable)

  Return SummaryTables

End Function

' History section
Private Function RealAML_History(serviceLogs As ISServiceLogs) As ISSummaryTables

  Dim ServiceLog As ISServiceLog
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableTabular("History", "History", 2, TestMode)
  With SummaryTable
    ' Columns
    With .Columns
      .AddText("Service Log")
      .AddDate("Date")
      .AddText("User")
      .AddText("Type")
      .AddText("Status")
    End With

    ' Rows
    With .Rows
      For Each ServiceLog In serviceLogs
        With .Add
          If Len(ServiceLog.ExStatusHtmlColour) <> 0 Then
            .BackgroundColour = ServiceLog.ExStatusHtmlColour
            If finBL.Runtime.ColourUtilities.HtmlColourIsDark(ServiceLog.ExStatusHtmlColour) Then .ForegroundColour = "white"
          End If
          With .Cells
            .AddText(CStr(ServiceLog.Pk)).HyperlinkSetFormShow("ServiceLog", CStr(ServiceLog.Pk))
            .AddDateTime(ServiceLog.CreatedDate,, True)
            .AddCodeDescription(ServiceLog.CreatedUserPk, finBL.Users)
            .AddText(ServiceLog.ProductId)
            .AddText(ServiceLog.ExStatus).Tooltip = ServiceLog.ExStatusTooltip
          End With
        End With
      Next
    End With
  End With
  SummaryTables.Add("History", SummaryTable)

  Return SummaryTables

End Function

' PEP results section
Private Function RealAML_VerificationResults_Pep(response_VerificationResultData As ISCreditEnquiryResponse_RealAML_VerificationResultData) As ISSummaryTables

  Dim Link As String
  Dim Links As String
  Dim PepHit As ISCreditEnquiryResponse_RealAML_VerificationResultPepHit
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableTabular("PEP Result", "PEP", 2, TestMode)
  With SummaryTable
    ' Result
    Select Case response_VerificationResultData.Results.PepResult
      Case iseCreditBureau_RealAML_PepResult.Potential
        .TextBefore = "{{warning|There are potential PEP matches.}}"
      Case iseCreditBureau_RealAML_PepResult.Match
        .TextBefore = "{{warning|There are PEP matches.|true}}"
      Case iseCreditBureau_RealAML_PepResult.NoMatch
        If response_VerificationResultData.PepHits.Count = 0 Then
          .TextBefore = "{{info|There are no Potential PEP matches.|true}}"
        End If
    End Select

    ' Add PEP Hits table
    If response_VerificationResultData.PepHits.Count <> 0 Then
      ' Columns
      With .Columns
        .AddText("Name")
        .AddText("Title")
        .AddText("Country")
        .AddText("Risk Types")
        .AddDate("Date of Birth")
        .AddText("Images and Links")
      End With

      ' Rows
      With .Rows
        For Each PepHit In response_VerificationResultData.PepHits
          Links = ""
          For Each Link In PepHit.Links
            If Len(Links) <> 0 Then Links &= vbNewLine
            Links &= String.Format("[[{0}|{1}]]", finBL.CreateApplicationShortcutExternal(Link).ToUrlString(True), Link)
          Next

          With .Add.Cells
            .AddText(PepHit.Name)
            .AddText(PepHit.Title)
            .AddText(PepHit.Country)
            .AddText(PepHit.RiskTypes)
            .AddDate(PepHit.BirthDate)
            .AddWiki(Links)
          End With
        Next
      End With
    End If
  End With
  SummaryTables.Add("PEP", SummaryTable)

  ' Return
  Return SummaryTables

End Function

' QuickID results section
Private Function RealAML_VerificationResults_QuickId(response_VerificationResultData As ISCreditEnquiryResponse_RealAML_VerificationResultData) As ISSummaryTables

  Dim Source As ISCreditEnquiryResponse_RealAML_VerificationResultSource
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' QuickID Results
  SummaryTable = SummaryTables.CreateSummaryTableInformation("QuickID Result", "QuickIdResults", 2, 30 , , TestMode)
  With SummaryTable
    .WidthHtml = "50%"
    Me.AddRowCaptionSuccessFail(SummaryTable, "Overall Result:", response_VerificationResultData.Results.QuickIdOverallResult, response_VerificationResultData.Results.QuickIdOverallResultText)
    .AddRowCaptionDateTimeWithTimeZone("Completed Date and Time:", response_VerificationResultData.QuickIdCompletedAt, finBL.Settings.TimeZoneId)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Name Check:", response_VerificationResultData.Results.QuickIdNameResult, response_VerificationResultData.Results.QuickIdNameResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Date of Birth Check:", response_VerificationResultData.Results.QuickIdBirthDateResult, response_VerificationResultData.Results.QuickIdBirthDateResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "Address Check:", response_VerificationResultData.Results.QuickIdAddressResult, response_VerificationResultData.Results.QuickIdAddressResultText)
    Me.AddRowCaptionSuccessFail(SummaryTable, "PEP Check:", response_VerificationResultData.Results.PepResult, response_VerificationResultData.Results.PepResultText)
  End With
  SummaryTables.Add("QuickIdResults", SummaryTable)

  ' Quick Id Sources
  SummaryTable = SummaryTables.CreateSummaryTableTabular("Sources", "Sources", 3, TestMode)
  With SummaryTable
    ' Columns
    With .Columns
      .AddText("Source")
      .AddText("Name", 18, iseSummaryTableCellTextAlign.Center)
      .AddText("Date of Birth", 18, iseSummaryTableCellTextAlign.Center)
      .AddText("Address", 18, iseSummaryTableCellTextAlign.Center)
    End With

    ' Rows
    With .Rows
      For Each Source In response_VerificationResultData.QuickIdResultSources
        With .Add
          .Cells.AddText(Source.Label)
          Me.AddCaptionSuccessFail(.Cells, Source.Name, Source.NameText)
          Me.AddCaptionSuccessFail(.Cells, Source.BirthDate, Source.BirthDateText)
          Me.AddCaptionSuccessFail(.Cells, Source.Address, Source.AddressText)
        End With
      Next
    End With
  End With
  SummaryTables.Add("Sources", SummaryTable)

  ' Return
  Return SummaryTables

End Function

Private Sub AddRowCaptionSuccessFail(summaryTable As ISSummaryTable, caption As String, value As Boolean?)

  If value.HasValue() Then
    Select Case value
      Case True
        summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Success}}")
      Case Else
        summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Failed}}")
    End Select
  End If

End Sub

Private Sub AddRowCaptionSuccessFail(summaryTable As ISSummaryTable, caption As String, value As iseCreditBureau_RealAML_BankMatchResult, valueRaw As String)

  Select Case value
    Case iseCreditBureau_RealAML_BankMatchResult.Fail
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Failed}} FAIL")
    Case iseCreditBureau_RealAML_BankMatchResult.Pass
      summaryTable.AddRowCaptionText(caption,"{{icon|Outcome_Success}}")
    Case iseCreditBureau_RealAML_BankMatchResult.Undefined
      If Len(valueRaw) = 0 Then
        summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Unknown}}",,,,,"No Result")
      Else
        summaryTable.AddRowCaptionText(caption, finBL.Runtime.TextUtilities.ProperCase(valueRaw))
      End If  
  End Select

End Sub

Private Sub AddRowCaptionSuccessFail(summaryTable As ISSummaryTable, caption As String, value As iseCreditBureau_RealAML_FaceMatchResult, valueRaw As String)

  Select Case value
    Case iseCreditBureau_RealAML_FaceMatchResult.Fail
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Failed}} FAIL")
    Case iseCreditBureau_RealAML_FaceMatchResult.Review
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Refer}} Review")
    Case iseCreditBureau_RealAML_FaceMatchResult.Pass
      summaryTable.AddRowCaptionText(caption,"{{icon|Outcome_Success}}")
    Case iseCreditBureau_RealAML_FaceMatchResult.Undefined
      If Len(valueRaw) = 0 Then
        summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Unknown}}",,,,,"No Result")
      Else
        summaryTable.AddRowCaptionText(caption, finBL.Runtime.TextUtilities.ProperCase(valueRaw))
      End If  
  End Select

End Sub

Private Sub AddRowCaptionSuccessFail(summaryTable As ISSummaryTable, caption As String, value As iseCreditBureau_RealAML_PepResult, valueRaw As String)

  Select Case value
    Case iseCreditBureau_RealAML_PepResult.Match
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Failed}} Match")
    Case iseCreditBureau_RealAML_PepResult.NoMatch
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Success}} No Match")
    Case iseCreditBureau_RealAML_PepResult.NotApplicable
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Unknown}} Not Applicable")
    Case iseCreditBureau_RealAML_PepResult.Potential
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Refer}} Potential")
    Case iseCreditBureau_RealAML_PepResult.Undefined
      If Len(valueRaw) = 0 Then
        summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Unknown}}",,,,,"No Result")
      Else
        summaryTable.AddRowCaptionText(caption, finBL.Runtime.TextUtilities.ProperCase(valueRaw))
      End If  
  End Select

End Sub

Private Sub AddRowCaptionSuccessFail(summaryTable As ISSummaryTable, caption As String, value As iseCreditBureau_RealAML_Result, valueRaw As String)

  Select Case value
    Case iseCreditBureau_RealAML_Result.Fail
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Failed}} FAIL")
    Case iseCreditBureau_RealAML_Result.NotApplicable
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Unknown}} Not Applicable")
    Case iseCreditBureau_RealAML_Result.NotPresent
      summaryTable.AddRowCaptionText(caption, "Not Present")
    Case iseCreditBureau_RealAML_Result.Partial
      summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Refer}} Partial")
    Case iseCreditBureau_RealAML_Result.Pass
      summaryTable.AddRowCaptionText(caption,"{{icon|Outcome_Success}}")
    Case iseCreditBureau_RealAML_Result.Undefined
      If Len(valueRaw) = 0 Then
        summaryTable.AddRowCaptionText(caption, "{{icon|Outcome_Unknown}}",,,,,"No Result")
      Else
        summaryTable.AddRowCaptionText(caption, finBL.Runtime.TextUtilities.ProperCase(valueRaw))
      End If  
  End Select

End Sub

Public Sub CheckRealAMLFaceMatchResult(valueToCheck As iseCreditBureau_RealAML_FaceMatchResult,
                                       textValue As String,
                                       ByRef Warnings As finWarnings)
  Select Case valueToCheck
    Case iseCreditBureau_RealAML_FaceMatchResult.Pass
      ' All OK
    Case iseCreditBureau_RealAML_FaceMatchResult.Review
      Warnings.AddWarning(String.Format("The FaceMatch Result is '{0}'.", textValue),,, isefinWarningLevel.High, "#FaceMatch")
    Case iseCreditBureau_RealAML_FaceMatchResult.Undefined
      Warnings.AddWarning("FaceMatch Result not returned.",,, isefinWarningLevel.High, "#FaceMatch")
    Case Else
      Warnings.AddWarning(String.Format("The FaceMatch Result is '{0}'.", textValue),,, isefinWarningLevel.Critical, "#FaceMatch")
  End Select

End Sub

Public Sub CheckRealAMLPepResult(valueToCheck As iseCreditBureau_RealAML_PepResult,
                                 ByRef Warnings As finWarnings)
  Select Case valueToCheck
    Case iseCreditBureau_RealAML_PepResult.Potential
      Warnings.AddWarning("There are potential PEP matches.",,, isefinWarningLevel.High, "#PEP")
    Case iseCreditBureau_RealAML_PepResult.Match
      Warnings.AddWarning("There are PEP matches.",,, isefinWarningLevel.Critical, "#PEP")
  End Select

End Sub

Public Sub CheckRealAMLResult(valueToCheck As iseCreditBureau_RealAML_Result,
                              textValue As String,
                              ByRef Warnings As finWarnings)
  Select Case valueToCheck
    Case iseCreditBureau_RealAML_Result.NotApplicable
      ' Ignore
    Case iseCreditBureau_RealAML_Result.Pass
      ' OK
    Case Else
      Warnings.AddWarning(String.Format("The Overall Result is '{0}'.", textValue),,, isefinWarningLevel.Critical)
  End Select

End Sub

Public Sub CheckResponseStatus(valueToCheck As iseServiceLogResponseStatus,
                               ByRef Warnings As finWarnings)
  Select Case valueToCheck
    Case iseServiceLogResponseStatus.Deleted
      Warnings.AddWarning("Request deleted.",,, isefinWarningLevel.Critical)
    Case iseServiceLogResponseStatus.Failed
      Warnings.AddWarning("Request failed.",,, isefinWarningLevel.Critical)
    Case iseServiceLogResponseStatus.InProgress
      Warnings.AddWarning("Report not yet complete.",,, isefinWarningLevel.High)
  End Select

End Sub

Private Sub CreatePage_RealAML_InstantVerify(serviceLogs As ISServiceLogs,
                                             response_InstantVerify As ISCreditEnquiryResponse_RealAML_InstantVerify,
                                             htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim i As Integer
  Dim Response_VerificationResult As ISCreditEnquiryResponse_RealAML_VerificationResult
  Dim Response_VerificationResultReport As ISCreditEnquiryResponse_RealAML_VerificationResultReport
  Dim ServiceLog_VerifyReportPK As Integer
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account Application or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  With ServiceLogSourceObjects
    If .Load(ServiceLogs(0)) Then
      AccountAppApplicant = .AccountAppApplicant
      AccountAppLog = .AccountAppLog
      Client = .Client
      ClientLog = .ClientLog
    End If
  End With

  ' Get Responses
  For i = serviceLogs.Count - 1 To 0 Step -1
    If serviceLogs(i).RequestStatus = iseAuditLogStatus.Success Then
      Select Case serviceLogs(i).ExResponse.GetType()
        Case GetType(ISCreditEnquiryResponse_RealAML_VerificationResult)
          If Response_VerificationResult Is Nothing Then
            Response_VerificationResult = DirectCast(serviceLogs(i).ExResponse, ISCreditEnquiryResponse_RealAML_VerificationResult)
          End If

        Case GetType(ISCreditEnquiryResponse_RealAML_VerificationResultReport)
          If Response_VerificationResultReport Is Nothing Then
            ServiceLog_VerifyReportPK = serviceLogs(i).Pk
            Response_VerificationResultReport = DirectCast(serviceLogs(i).ExResponse, ISCreditEnquiryResponse_RealAML_VerificationResultReport)
          End If
      End Select
    End If
  Next

  With htmlSummaryPage2StringBuilder
    ' Heading
    .AppendH1(response_InstantVerify.Request_InstantVerify.FullName)
    .AppendH2(String.Format("{0} - {1}", serviceLogs(0).ProductId, response_InstantVerify.ServiceName))

    .SummaryTablesAppend(Me.RealAML_InstantVerify_EnquiryDetails(serviceLogs, response_InstantVerify, Response_VerificationResult, Response_VerificationResultReport))
    .SummaryTablesAppend(Me.RealAML_InstantVerify_Alerts(serviceLogs, response_InstantVerify, Response_VerificationResult))
    .SummaryTablesAppend(Me.RealAML_VerificationResults_InstantVerify(serviceLogs(0).Pk, ServiceLog_VerifyReportPK, response_InstantVerify, Response_VerificationResult, Response_VerificationResultReport))

    If Response_VerificationResult IsNot Nothing Then
      If Response_VerificationResult.HasQuickIdResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_QuickId(Response_VerificationResult.Data))
      End If

      If Response_VerificationResult.HasFaceMatchResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_FaceMatch(serviceLogs, Response_VerificationResult.Data, response_InstantVerify.EnquiryDate))
      End If

      If Response_VerificationResult.HasBankMatchResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_BankMatch(Response_VerificationResult.Data))
      End If

      If Response_VerificationResult.HasPepResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_Pep(Response_VerificationResult.Data))
      End If

      If Not Response_VerificationResult.Data.IsCompleted Then
        .SummaryTablesAppend(Me.RealAML_History(serviceLogs))
      End If
    ElseIf response_InstantVerify IsNot Nothing Then
      If response_InstantVerify.HasQuickIdResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_QuickId(response_InstantVerify.Data))
      End If

      If response_InstantVerify.HasFaceMatchResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_FaceMatch(serviceLogs, response_InstantVerify.Data, response_InstantVerify.EnquiryDate))
      End If

      If response_InstantVerify.HasBankMatchResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_BankMatch(Response_VerificationResult.Data))
      End If

      If response_InstantVerify.HasPepResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_Pep(response_InstantVerify.Data))
      End If

      If Not response_InstantVerify.Data.IsCompleted Then
        .SummaryTablesAppend(Me.RealAML_History(serviceLogs))
      End If
    Else
      .SummaryTablesAppend(Me.RealAML_History(serviceLogs))
    End If
  End With

End Sub

Private Sub CreatePage_RealAML_Verify(serviceLogs As ISServiceLogs,
                                      response_Verify As ISCreditEnquiryResponse_RealAML_Verify,
                                      htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim i As Integer
  Dim Response_VerificationResult As ISCreditEnquiryResponse_RealAML_VerificationResult
  Dim Response_VerificationResultReport As ISCreditEnquiryResponse_RealAML_VerificationResultReport
  Dim ServiceLog_VerifyReportPK As Integer
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account Application or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  With ServiceLogSourceObjects
    If .Load(ServiceLogs(0)) Then
      AccountAppApplicant = .AccountAppApplicant
      AccountAppLog = .AccountAppLog
      Client = .Client
      ClientLog = .ClientLog
    End If
  End With

  ' Get Responses
  For i = serviceLogs.Count - 1 To 0 Step -1
    If serviceLogs(i).RequestStatus = iseAuditLogStatus.Success Then
      Select Case serviceLogs(i).ExResponse.GetType()
        Case GetType(ISCreditEnquiryResponse_RealAML_VerificationResult)
          If Response_VerificationResult Is Nothing Then
            Response_VerificationResult = DirectCast(serviceLogs(i).ExResponse, ISCreditEnquiryResponse_RealAML_VerificationResult)
          End If

        Case GetType(ISCreditEnquiryResponse_RealAML_VerificationResultReport)
          If Response_VerificationResultReport Is Nothing Then
            ServiceLog_VerifyReportPK = serviceLogs(i).Pk
            Response_VerificationResultReport = DirectCast(serviceLogs(i).ExResponse, ISCreditEnquiryResponse_RealAML_VerificationResultReport)
          End If
      End Select
    End If
  Next
  
  With htmlSummaryPage2StringBuilder
    ' Heading
    .AppendH1(response_Verify.Request_Verify.FullName)
    .AppendH2(String.Format("{0} - {1}", serviceLogs(0).ProductId, response_Verify.ServiceName))

    .SummaryTablesAppend(Me.RealAML_Verify_EnquiryDetails(serviceLogs, response_Verify, Response_VerificationResult, Response_VerificationResultReport))
    .SummaryTablesAppend(Me.RealAML_Verify_Alerts(serviceLogs, response_Verify, Response_VerificationResult, Response_VerificationResultReport))
    If Response_VerificationResult IsNot Nothing Then
      .SummaryTablesAppend(Me.RealAML_VerificationResults_Verify(serviceLogs, ServiceLog_VerifyReportPK, response_Verify, Response_VerificationResult, Response_VerificationResultReport))'

      If Response_VerificationResult.HasQuickIdResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_QuickId(Response_VerificationResult.Data))
      End If

      If Response_VerificationResult.HasFaceMatchResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_FaceMatch(serviceLogs, Response_VerificationResult.Data, Response_VerificationResult.EnquiryDate))
      End If

      If Response_VerificationResult.HasBankMatchResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_BankMatch(Response_VerificationResult.Data))
      End If

      If Response_VerificationResult.HasPepResult Then
        .SummaryTablesAppend(Me.RealAML_VerificationResults_Pep(Response_VerificationResult.Data))
      End If

      If Not response_VerificationResult.Data.IsCompleted Then
        .SummaryTablesAppend(Me.RealAML_History(serviceLogs))
      End If
    Else
      .SummaryTablesAppend(Me.RealAML_History(serviceLogs))
    End If
  End With
End Sub

Private Function GetClientWarnings(firstName As String,
                                   middleNames As String,
                                   lastName As String,
                                   dateOfBirth As Date,
                                   addressDetails As ISAddressDetails,
                                   ignoreBlanks As Boolean) As String

  Dim  AddressDetailsClient As ISAddressDetails

  ' Initialise
  GetClientWarnings = ""

  ' If Suburb and City the same clear Suburb for better matching
  If addressDetails IsNot Nothing AndAlso StrComp(addressDetails.Suburb, addressDetails.City, CompareMethod.Text) = 0 Then
    addressDetails.Suburb = ""
  End If

  ' Client/ Applicant Warnings
  If Client IsNot Nothing Then
    ' Client
    If (Not ignoreBlanks OrElse Len(firstName) > 0) AndAlso StrComp(firstName, Client.FirstName, CompareMethod.Text) <> 0 Then
      GetClientWarnings &= "{{warning|" & String.Format("First Name does not match Client - '{0}'.", Client.FirstName) & "}}"
    End If
    If Len(middleNames) <> 0 AndAlso Len(Client.MiddleNames) <> 0 Then
      If StrComp(middleNames, Client.MiddleNames, CompareMethod.Text) <> 0 Then
        GetClientWarnings &= "{{warning|" & String.Format("Middle Name does not match Client - '{0}'.", Client.MiddleNames) & "}}"
      End If
    End If
    If (Not ignoreBlanks OrElse Len(lastName) > 0) AndAlso StrComp(lastName, Client.LastName, CompareMethod.Text) <> 0 Then
      GetClientWarnings &= "{{warning|" & String.Format("Last Name does not match Client - '{0}'.", Client.LastName) & "}}"
    End If
    If (Not ignoreBlanks OrElse (dateOfBirth <> Nothing)) Then
      If dateOfBirth = Nothing Then
        GetClientWarnings &= "{{warning|Date of Birth not specified.}}"
      ElseIf Client.DateOfBirth = Nothing Then
        GetClientWarnings &= "{{info|Client's Date of Birth not found.}}"
      ElseIf dateOfBirth <> Client.DateOfBirth Then
        GetClientWarnings &= "{{warning|" & String.Format("Date of Birth does not match Client - {0}.", finBL.FormatDateLong(Client.DateOfBirth)) & "}}"
      End If
    End If

    AddressDetailsClient = Client.ContactAddresses.GetCurrentAddress().ToAddressDetails()
    With AddressDetailsClient
      .Instructions = ""
      .Addressee = ""
      .OrganisationName = ""
      .StreetUnit = ""
      .StreetNumber = ""
      .StreetName = ""
      .StreetType = ""
      .StreetDirection = ""
      .PostalId = ""

      ' If Suburb and City the same clear Suburb for better matching
      If StrComp(.Suburb, .City, CompareMethod.Text) = 0 Then
        .Suburb = ""
      End If
    End With
    If Not addressDetails.HasValue Then
      GetClientWarnings &= "{{info|Address not found.}}"
    ElseIf AddressDetailsClient.HasValue Then
      If Not addressDetails.CompareTo(AddressDetailsClient, True) Then
        addressDetails.Suburb = ""
        AddressDetailsClient.Suburb = ""

        If addressDetails.CompareTo(AddressDetailsClient, True) Then
          GetClientWarnings &= "{{info|Partial Address match - check Suburb.}}"
        Else
          GetClientWarnings &= "{{warning|Address does not match Client.}}"
        End If
      End If
    End If
  ElseIf AccountAppApplicant IsNot Nothing Then
    ' TODO ****
    ' Applicant
    If StrComp(firstName, AccountAppApplicant.FirstName, CompareMethod.Text) <> 0 Then
      If ignoreBlanks AndAlso Len(AccountAppApplicant.FirstName) = 0 Then
         ' Do Nothing
      Else
        GetClientWarnings &= "{{warning|" & String.Format("First Name does not match Applicant - '{0}'.", AccountAppApplicant.FirstName) & "}}"
      End If
    End If

    If (Not ignoreBlanks OrElse Len(AccountAppApplicant.FirstName) > 0) AndAlso StrComp(firstName, AccountAppApplicant.FirstName, CompareMethod.Text) <> 0 Then
      GetClientWarnings &= "{{warning|" & String.Format("First Name does not match Applicant - '{0}'.", AccountAppApplicant.FirstName) & "}}"
    End If
    If Len(middleNames) <> 0 AndAlso Len(AccountAppApplicant.MiddleNames) <> 0 Then
      If StrComp(middleNames, AccountAppApplicant.MiddleNames, CompareMethod.Text) <> 0 Then
        GetClientWarnings &= "{{warning|" & String.Format("Middle Name does not match Applicant - '{0}'.", AccountAppApplicant.MiddleNames) & "}}"
      End If
    End If
    If (Not ignoreBlanks OrElse Len(AccountAppApplicant.LastName) > 0) AndAlso StrComp(lastName, AccountAppApplicant.LastName, CompareMethod.Text) <> 0 Then
      GetClientWarnings &= "{{warning|" & String.Format("Last Name does not match Applicant - '{0}'.", AccountAppApplicant.LastName) & "}}"
    End If
    If (Not ignoreBlanks OrElse (dateOfBirth <> Nothing)) Then
      If dateOfBirth = Nothing Then
        GetClientWarnings &= "{{warning|Date of Birth not specified.}}"
      ElseIf AccountAppApplicant.DateOfBirth = Nothing Then
        GetClientWarnings &= "{{info|Applicant's Date of Birth not found.}}"
      ElseIf dateOfBirth <> AccountAppApplicant.DateOfBirth Then
        GetClientWarnings &= "{{warning|" & String.Format("Date of Birth does not match Applicant - {0}.", finBL.FormatDateLong(AccountAppApplicant.DateOfBirth)) & "}}"
      End If
    End If

    AddressDetailsClient = AccountAppApplicant.AddressPostal()
    With AddressDetailsClient
      .Instructions = ""
      .Addressee = ""
      .OrganisationName = ""
      .StreetUnit = ""
      .StreetNumber = ""
      .StreetName = ""
      .StreetType = ""
      .StreetDirection = ""
      .PostalId = ""

      ' If Suburb and City the same clear Suburb for better matching
      If StrComp(.Suburb, .City, CompareMethod.Text) = 0 Then
        .Suburb = ""
      End If
    End With
    If Not addressDetails.HasValue() Then
      GetClientWarnings &= "{{info|Address not found.}}"
    ElseIf AddressDetailsClient.HasValue() Then
      If Not addressDetails.CompareTo(AddressDetailsClient, True) Then
        addressDetails.Suburb = ""
        AddressDetailsClient.Suburb = ""

        If addressDetails.CompareTo(AddressDetailsClient, True) Then
          GetClientWarnings &= "{{info|Partial Address match - check Suburb.}}"
        Else
          GetClientWarnings &= "{{warning|Address does not match Client.}}"
        End If
      End If
    End If
  End If

End Function

Public Function RealAML_InstantVerify_Alerts(serviceLogs As ISServiceLogs,
                                             response_InstantVerify As ISCreditEnquiryResponse_RealAML_InstantVerify,
                                             response_VerificationResult As ISCreditEnquiryResponse_RealAML_VerificationResult) As ISSummaryTables
                                            
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As finWarnings

  ' Create Objects
  SummaryTables = finBL.CreateSummaryTables ()
  Warnings = finBL.CreateWarnings

  ' Status
  CheckResponseStatus(ServiceLogs(0).ResponseStatus, Warnings)

  If response_InstantVerify.Status = "Completed" Then
    ' Out of Date
    CheckEnquiryDate(response_InstantVerify.EnquiryDate, Warnings)
  End If

  If response_VerificationResult IsNot Nothing AndAlso response_VerificationResult.Data IsNot Nothing Then
    ' Overall Result
    If response_VerificationResult.Data.HasQuickIdResult Then
      CheckRealAMLResult(response_VerificationResult.Data.Results.QuickIdOverallResult, response_VerificationResult.Data.Results.QuickIdOverallResultText, Warnings)
    End If

    ' FaceMatch Result
    If response_VerificationResult.Data.HasFaceMatchResult Then
      CheckRealAMLFaceMatchResult(response_VerificationResult.Data.FaceMatch.OverallResult, response_VerificationResult.Data.FaceMatch.OverallResultText, Warnings)
    End If

    ' PEP Alerts
    If response_VerificationResult.Data.HasPepResult Then
      CheckRealAMLPepResult(response_VerificationResult.Data.Results.PepResult, Warnings)
    End If
  End If

  ' Add Alerts
  If Warnings.Count <> 0 Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Alerts", "Alerts", 2)
    SummaryTable.TextAfter = Warnings.GetHtmlTemplateText()
    SummaryTables.Add("Alerts", SummaryTable)
  End If

  Return SummaryTables

End Function

Public Function RealAML_Verify_Alerts(serviceLogs As ISServiceLogs,
                                      response_Verify As ISCreditEnquiryResponse_RealAML_Verify,
                                      response_VerificationResult As ISCreditEnquiryResponse_RealAML_VerificationResult,
                                      response_VerificationResultReport As ISCreditEnquiryResponse_RealAML_VerificationResultReport) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As finWarnings

  ' Create Objects
  SummaryTables = finBL.CreateSummaryTables ()
  Warnings = finBL.CreateWarnings

  ' Status
  CheckResponseStatus(ServiceLogs(0).ResponseStatus, Warnings)

  If response_VerificationResult IsNot Nothing Then
    ' Out of Date
    CheckEnquiryDate(response_VerificationResult.EnquiryDate, Warnings)

    ' Overall Result
    If response_VerificationResult.HasQuickIdResult Then
      If response_VerificationResult.Data.IsCompleted Then
        CheckRealAMLResult(response_VerificationResult.Data.Results.QuickIdOverallResult, response_VerificationResult.Data.Results.QuickIdOverallResultText, Warnings)
      End If
    End If

    ' FaceMatch Result
    If response_VerificationResult.HasFaceMatchResult Then
      CheckRealAMLFaceMatchResult(response_VerificationResult.Data.FaceMatch.OverallResult, response_VerificationResult.Data.FaceMatch.OverallResultText, Warnings)
    End If

    ' PEP Alerts
    If response_VerificationResult.HasPepResult Then
      CheckRealAMLPepResult(response_VerificationResult.Data.Results.PepResult, Warnings)
    End If
  End If

  ' Add Alerts
  If Warnings.Count <> 0 Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Alerts", "Alerts", 2)
    SummaryTable.TextAfter = Warnings.GetHtmlTemplateText()
    SummaryTables.Add("Alerts", SummaryTable)
  End If

  Return SummaryTables

End Function

Private Function RealAML_Verify_EnquiryDetails(serviceLogs As ISServiceLogs,
                                               response_Verify As ISCreditEnquiryResponse_RealAML_Verify,
                                               response_VerificationResult As ISCreditEnquiryResponse_RealAML_VerificationResult,
                                               response_VerificationResultReport As ISCreditEnquiryResponse_RealAML_VerificationResultReport) As ISSummaryTables

  Dim Days As Integer
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "EnquiryDetails", , 30, , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Issue Date and Time:", response_Verify.EnquiryUtcDate, finBL.Settings.TimeZoneId)
    If response_VerificationResult IsNot Nothing Then
      .AddRowCaptionUtcDateTimeWithTimeZone("Completed Date and Time:", response_VerificationResult.Data.CompletedAt, finBL.Settings.TimeZoneId)
    End If
    .AddRowCaptionText("Reference:", serviceLogs(0).RequestReference)

    If Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Client:", client.ClientId, client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", client.ClientId)
      End With
    ElseIf AccountAppApplicant IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Applicant:", AccountAppApplicant.AccountApp.AccountAppId, AccountAppApplicant.Name)
        .Cells(1).HyperlinkSetFormShow("AccountApps", AccountAppApplicant.AccountApp.AccountAppId, "Applicants")
      End With
    ElseIf Len(response_Verify.Request.ClientId) <> 0 Then
      .AddRowCaptionWiki("Client:", String.Format("**{0} !!Not Found!!**", response_Verify.Request.ClientId))
    End If

    .AddRowCaptionText("RealAML Reference:", response_Verify.Data.SignatureKey)
    .AddRowCaptionText("Phone:", response_Verify.Data.PhoneFormatted, False)
    .AddRowCaptionText("Email:", response_Verify.data.Email, False)
    .AddRowCaptionText("Verification Type:", response_Verify.Data.VerificationTypeText, True)

    ' Website URL Link
    If Len(response_Verify.Data.Url) <> 0 Then
      If ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.InProgress Then
        .Rows.AddCaptionText("Verification Link:", response_Verify.Data.Url).Cells(1).HyperlinkSetExternal(response_Verify.Data.Url)
      End If
    End If

    If response_VerificationResult Is Nothing Then
      .AddRowCaptionBooleanYesNo("Completed:",  False)
    Else
      If response_VerificationResult.Data.IsCompleted Then
        ' Ignore
      ElseIf response_VerificationResult.Data.IsCancelled Then
        ' Ignore
      Else
        .AddRowCaptionBooleanYesNo("Completed:", response_VerificationResult.Data.IsCompleted, True)

        If response_VerificationResult.Data.QuickIdIsCompleted.HasValue() Then
          .AddRowCaptionBooleanYesNo("QuickID Completed:", response_VerificationResult.Data.QuickIdIsCompleted.GetValueOrDefault(), True)
        End If
        If response_VerificationResult.Data.FaceMatchIsCompleted.HasValue() Then
          .AddRowCaptionBooleanYesNo("FaceMatch Completed:", response_VerificationResult.Data.FaceMatchIsCompleted.GetValueOrDefault(), True)
        End If
      End If
    End If
    
    ' IP Addresses
    If response_VerificationResult IsNot Nothing Then
      .AddRowCaptionText("IP Address(es):", response_VerificationResult.Data.UniqueIpAddressesResolved)
    End If

    ' Add Actions
    If ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.InProgress Then
      With .Actions
        .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("app://global?type=ServiceLog.Refresh&serviceLogPk={0}&NotifyAction=CreditEnquiry.Refresh", serviceLogs(0).Pk), True).ShowInWebInterfaces = True
        .AddApplicationShortcutUrl("UpdateStatus", "Update Status", String.Format("app://global?type=CreditEnquiry.GetReport&serviceLogPk={0}&NotifyAction=CreditEnquiry.Refresh", serviceLogs(0).Pk), True).ShowInWebInterfaces = True
        .AddApplicationShortcutUrl("Resend", "Resend", String.Format("app://global?type=CreditEnquiry.Resend&serviceLogPk={0}&NotifyAction=CreditEnquiry.Refresh", serviceLogs(0).Pk), True).ShowInWebInterfaces = True
      End With
    End If

    ' Warnings
    Warnings = ""

    ' Out of date
    Days = CInt(DateDiff(DateInterval.Day, response_Verify.EnquiryUtcDate, finBL.TimeZoneFunctions.GetCurrentUtcDateTime()))
    If Days > OutOfDateWarningDays Then
       Warnings &= "{{Warning|This Report is " & CStr(Days) & " days old.}}"
    End If

    .TextAfter = Warnings
  End With
  SummaryTables.Add("EnquiryDetails", SummaryTable)

  Return SummaryTables

End Function