' SummaryPage2_SecurityEnquiryReport_CentrixNZ
Option Explicit On
Option Strict On

' #################################################################
' Centrix NZ Wheels Security Report Summary Page Script
'
' Version: 2.02 (09/12/2016)
'
' Usage: Security Enquiry form and Log forms
' #################################################################

'#Const "OutOfDateWarningDays",Integer,30,"Number of days before warning the Enquiry is out-of-date."

' Constants
Private OutOfDateWarningDays As Integer = 30

' Special Constants
Const TestMode As Boolean = False

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 i As Integer
  Dim Response As ISSecurityEnquiryResponse
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogs As ISServiceLogs

  ' Assume Success
  Main = True

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

  ' Get Security Enquiry Service Logs (ignoring any errors)
  If Main Then
    Try
      Main = finBL.SecurityEnquiry.GetSecurityEnquiryServiceLogs(CInt(source), ServiceLogs)
    Catch ex As Exception
      finBL.Error.ErrorBeginFromException(ex)
      Return False
    End Try
  End If

  If Main Then
    If ServiceLogs.Count = 0 Then
      ' Error
      Main = False
      finBL.Error.ErrorBegin("Invalid Service Log for a Security Enquiry.")
    Else
      For i = ServiceLogs.Count - 1 To 0 Step - 1
        If ServiceLogs(i).RequestStatus = iseAuditLogStatus.Success Then
          ServiceLog = ServiceLogs(i)
          Response = DirectCast(ServiceLogs(i).ExResponse, ISSecurityEnquiryResponse)
          Exit For
        End If
      Next
      If Response Is Nothing Then
        ' Error
        Main = False
        finBL.Error.ErrorBegin("Invalid Service Log for a Security Enquiry.")
      End If
    End If
  End If

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

End Function

Private Function CreatePage(serviceLog As ISServiceLog,
                            response As ISSecurityEnquiryResponse,
                            ByRef html As String) As Boolean

  Dim HtmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' 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, response.ProductId), isefinSummaryPageStyle.ServiceReport)

    ' Theme
    .HtmlHeaderInsertServiceReportTheme("#FF6400", "#FFE7D5", "", "#FFF7F0")

    ' 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

  ' VedaScore Apply
  Select Case TypeName(response)
    Case "ISSecurityEnquiryResponse_CentrixNZ_ConfirmOwner"
      Me.CreatePage_CentrixNZConfirmOwner(ServiceLog, Response, HtmlSummaryPage2StringBuilder)
    Case "ISSecurityEnquiryResponse_CentrixNZ_WheelsSearch"
      Me.CreatePage_CentrixNZWheels(ServiceLog, Response, HtmlSummaryPage2StringBuilder)
  End Select

  ' Disclaimer
  HtmlSummaryPage2StringBuilder.Append("<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

Private Sub CreatePage_CentrixNZConfirmOwner(serviceLog As ISServiceLog,
                                             response As ISSecurityEnquiryResponse,
                                             sb As finHtmlSummaryPage2StringBuilder)

  Dim CentrixResponse As ISSecurityEnquiryResponse_CentrixNZ_ConfirmOwner
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finbl.CreateSummaryTables()
  CentrixResponse = DirectCast(response, ISSecurityEnquiryResponse_CentrixNZ_ConfirmOwner)

  With sb
    ' Heading
    .AppendH1("Centrix Confirm Owner")
    .SummaryTablesAppend(Me.CentrixNZConfirmOwner_InformationProvided(CentrixResponse))
    .SummaryTablesAppend(Me.CentrixNZConfirmOwner_Result(CentrixResponse))
    If CentrixResponse.NztaMessages.Count <> 0 Then
      .SummaryTablesAppend(Me.CentrixNZ_NztaMessgages(CentrixResponse.NztaMessages))
    End If

  End With

End Sub

Private Sub CreatePage_CentrixNZWheels(serviceLog As ISServiceLog,
                                       response As ISSecurityEnquiryResponse,
                                       sb As finHtmlSummaryPage2StringBuilder)

  Dim CentrixResponse As ISSecurityEnquiryResponse_CentrixNZ_WheelsSearch
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finbl.CreateSummaryTables()
  CentrixResponse = DirectCast(response, ISSecurityEnquiryResponse_CentrixNZ_WheelsSearch)

  With sb
    ' Heading
    .AppendH1(CentrixResponse.VehicleDetails.VehicleDescription)
    .AppendH2(String.Format("{0} - {1}", CentrixResponse.ProductId, CentrixResponse.ServiceName))

    .SummaryTablesAppend(Me.CentrixNZWheels_InformationProvided(CentrixResponse))
    .SummaryTablesAppend(Me.CentrixNZWheels_VehicleDescription(CentrixResponse.VehicleDetails))
    .SummaryTablesAppend(Me.CentrixNZWheels_Alerts(CentrixResponse))
    If CentrixResponse.NztaMessages.Count <> 0 Then
      .SummaryTablesAppend(Me.CentrixNZ_NztaMessgages(CentrixResponse.NztaMessages))
    End If

    .SummaryTablesAppend(Me.CentrixNZWheels_CurrentRegisteredParties(CentrixResponse.RegisteredParties))
    .SummaryTablesAppend(Me.CentrixNZWheels_VehicleDetails(CentrixResponse.VehicleDetails, CentrixResponse.RegistrationDetails))
    .SummaryTablesAppend(Me.CentrixNZWheels_RegistrationDetails(CentrixResponse.RegistrationDetails))
    .SummaryTablesAppend(Me.CentrixNZWheels_PlateHistory(CentrixResponse.PlateIssuedList))
    .SummaryTablesAppend(Me.CentrixNZWheels_OdometerHistory(CentrixResponse.OdometerReadings))
    ' NOTE : this is different to the other methods as we want to have a different background colour for each financial interest.
    If CentrixResponse.FinancialInterests.HasData Then
      Me.CentrixNZWheels_FinancialInterests(sb, CentrixResponse.FinancialInterests)
    End If
    If CentrixResponse.FuelSafeDetails.HasData Then
      .SummaryTablesAppend(Me.CentrixNZWheels_FuelSafeDetails(CentrixResponse.FuelSafeDetails))
    End If
    ' NOTE : this is different to the other methods as we want to have a different background colour for each vehicle variant.
    If CentrixResponse.VehicleVariantList.HasData Then
      .SummaryTablesAppend(Me.CentrixNZWheels_VehicleVariants(CentrixResponse.ValuationVehicleVariant, CentrixResponse.VehicleVariantList, CentrixResponse.RegistrationDetails.LatestOdometer, CentrixResponse.RegistrationDetails.OdometerUnit))
    End If

    ' Court Fines
    .SummaryTablesAppend(Me.CentrixNZWheels_CourtFines(CentrixResponse.FinesDataList))
  End With

End Sub

Private Function CentrixNZConfirmOwner_InformationProvided(centrixResponse As ISSecurityEnquiryResponse_CentrixNZ_ConfirmOwner) As ISSummaryTables

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

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "InformationProvided",, 16, 40, TestMode)
  With SummaryTable
    Days = CInt(DateDiff(DateInterval.Day, centrixResponse.EnquiryUtcDate, finBL.TimeZoneFunctions.GetCurrentUtcDateTime()))
    If Days > OutOfDateWarningDays Then
      If centrixResponse.EnquiryDate = centrixResponse.EnquiryNZDate Then
        With .Rows.Add.Cells
          .AddCaption("Enquiry Date:")
          .AddWiki("**" & finBL.FormatDateTime(centrixResponse.EnquiryNZDate, True) & " --This Report is " & CStr(Days) & " days old.--**").CellClass = iseSummaryTableCellClass.WarningBold
        End With
      Else
        With .Rows.Add.Cells
          .AddCaption("Enquiry Date:")
          .AddWiki("**" & finBL.FormatDateTime(centrixResponse.EnquiryNZDate, True) & " (all dates shown in NZ time) --This Report is " & CStr(Days) & " days old.--**").CellClass = iseSummaryTableCellClass.WarningBold
        End With
      End If
    Else
      If centrixResponse.EnquiryDate = centrixResponse.EnquiryNZDate Then
        .AddRowCaptionDateTime("Enquiry Date:", centrixResponse.EnquiryNZDate)
      Else
        .AddRowCaptionDateTime("Enquiry Date:", centrixResponse.EnquiryNZDate,, "(all dates shown in NZ time)")
      End If
    End If
    .AddRowCaptionText("Enquiry Number:", centrixResponse.EnquiryNumber, True)
    If Len(centrixResponse.SearchVehicle.PlateNumber) = 0 Then
      .AddRowCaptionWiki("Plate Number:", "**Plate Number not supplied**")
    Else
      .AddRowCaptionWiki("Plate Number:", String.Format("**++{0}++**", centrixResponse.SearchVehicle.PlateNumber))
    End If
    If Len(centrixResponse.SearchVehicle.Vin) = 0 Then
      .AddRowCaptionWiki("VIN:", "**VIN not supplied**")
    Else
      .AddRowCaptionWiki("VIN:", String.Format("**++{0}++**", centrixResponse.SearchVehicle.Vin))
    End If

    .AddRowCaptionText("Surname:", centrixResponse.Surname, False)
    .AddRowCaptionText("First Name:", centrixResponse.FirstName, False)
    .AddRowCaptionDate("Date of Birth:", centrixResponse.DateOfBirth, False)
    .AddRowCaptionText("Drivers Licence:", centrixResponse.DriversLicence, False)
    .AddRowCaptionText("Company Name:", centrixResponse.CompanyName, False)

    ' Disclaimer
    .TextAfter = "{{disclaimer|" & centrixResponse.ReportDisclaimer & "}}"
  End With
  SummaryTables.Add("InformationProvided", SummaryTable)

  Return SummaryTables

End Function

Private Function CentrixNZConfirmOwner_Result(centrixResponse As ISSecurityEnquiryResponse_CentrixNZ_ConfirmOwner) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Owner", "Owner", 2, 16, 40, TestMode)
  With SummaryTable
    If centrixResponse.Match Then
      .AddRowCaptionWiki("Match:", "**++Matched++**")
    Else
      .AddRowCaptionWiki("Match:", "**!!Not Matched!!**")
    End If
    .AddRowCaptionText("Message:", centrixResponse.ResponseMessage, False)
  End With
  SummaryTables.Add("NAME", SummaryTable)

  Return SummaryTables

End Function

Private Function CentrixNZWheels_Alerts(centrixResponse As ISSecurityEnquiryResponse_CentrixNZ_WheelsSearch) As ISSummaryTables

  Dim Days As Integer
  Dim Warnings As finWarnings
  Dim StatusMessage As ISSecurityEnquiryResponse_CentrixNZ_StatusMessage
  Dim strTemp As String
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Warnings
  Warnings = finBL.CreateWarnings()

  ' Build Warning Lists
  With centrixResponse
    ' Out of Date
    Days = CInt(DateDiff(DateInterval.Day, .EnquiryUtcDate, finBL.TimeZoneFunctions.GetCurrentUtcDateTime()))
    If Days > OutOfDateWarningDays Then
      Warnings.AddWarning(String.Format("This is an OLD Report, data is from {0} days ago.", Days),,, isefinWarningLevel.Critical)
    End If

    ' Status Messages
    For Each StatusMessage In .StatusMessages
      strTemp = String.Format("{0}: {1}", StatusMessage.Code, StatusMessage.Text)
      Select UCase(StatusMessage.Type)
        Case "DEBUG"
          If TestMode Then Warnings.AddWarning(strTemp,,, isefinWarningLevel.High)
        Case "ERROR"
          Warnings.AddWarning(strTemp,,, isefinWarningLevel.Critical)
        Case "INFORMATION"
          Warnings.AddWarning(strTemp,,, isefinWarningLevel.High)
        Case "WARNING"
          Warnings.AddWarning(strTemp,,, isefinWarningLevel.High)
      End Select
    Next

    ' NZTA Messages
    If .NztaMessages.Count <> 0 Then
      Warnings.AddWarning("NZTA Messages.",,, isefinWarningLevel.Critical, "#NztaMessages")
    End If

    ' Stolen
    If .VehicleDetails.HasData Then
      If .VehicleDetails.ReportedStolen Then
        Warnings.AddWarning("Vehicle Reported Stolen.",,, isefinWarningLevel.Critical, "#VehicleDetails")
      End If
    End If

    ' Reliable Odometer
    If .OdometerReadings.HasData Then
      If .OdometerReadings(0).ReliableOdometer Then
        Warnings.AddWarning("Reliable Odometer.",,, isefinWarningLevel.Low, "#OdometerHistory")
      Else
        Warnings.AddWarning("Unreliable Odometer.",,, isefinWarningLevel.Critical, "#OdometerHistory")
      End If
    End If

    ' Registration
    If .RegistrationDetails.HasData Then
      Select Case UCase(.RegistrationDetails.RegistrationStatusCode)
        Case "A"
          Warnings.AddWarning("Vehicle Currently Registered.",,, isefinWarningLevel.Low, "#RegistrationDetails")
        Case "C"
          Warnings.AddWarning("Vehicle Registration Cancelled.",,, isefinWarningLevel.Critical, "#RegistrationDetails")
        Case "L"
          Warnings.AddWarning("Vehicle Registration Lapsed.",,, isefinWarningLevel.Critical, "#RegistrationDetails")
         Case Else
          Warnings.AddWarning(String.Format("Unknown Vehicle Registration Status ().", .RegistrationDetails.RegistrationStatus),,, isefinWarningLevel.Critical, "#RegistrationDetails")
      End Select
    End If

    ' Financial Interests
    If .FinancialInterests.HasData Then
      If .FinancialInterests.NumberOfRegisteredFinancialInterests > 0 Then
        Warnings.AddWarning(String.Format("{0} Financial Interests Recorded.", .FinancialInterests.NumberOfRegisteredFinancialInterests),,, isefinWarningLevel.Critical, "#FinancialInterests")
      End If
    Else
      Warnings.AddWarning("PPSR Search not included. This Motor Vehicle may have Financial Interests recorded in the PPSR.",,, isefinWarningLevel.High)
    End If

    ' Fuel Safety Details
    If .FuelSafeDetails.HasData Then
      If Not .FuelSafeDetails.IsSuccess Then
        Warnings.AddWarning("Fuel Safe Details error.",,, isefinWarningLevel.Critical, "#FuelSafeDetails")
      End If
    End If

    ' Court Fines
    If .FinesDataList.HasData Then
      If .FinesDataList.HasOutstandingFines Then
        Warnings.AddWarning("Outstanding Court Fines Recorded.",,, isefinWarningLevel.Critical, "#CourtFines")
      End If
    End If

    ' Market Data
    If .VehicleVariantList.HasData Then
      Warnings.AddWarning("Market Valuation found.",,, isefinWarningLevel.Low, "#MarketValuation")
    End If
  End With

  ' 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 CentrixNZWheels_CourtFines(finesDataList As ISSecurityEnquiryResponse_CentrixNZ_FinesDataList) As ISSummaryTables

  Dim FinesData As ISSecurityEnquiryResponse_CentrixNZ_FinesData
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If finesDataList.HasData Then
    ' Disclaimer
    SummaryTables.AddSummaryTableBlank("Disclaimer", "", "{{disclaimer|" & finesDataList.Disclaimer & "}}", "Disclaimer")

    If finesDataList.Count <> 0 Then
      ' Main
      SummaryTable = SummaryTables.CreateSummaryTableTabular("", "CourtFines",, TestMode)
      With SummaryTable
        ' Columns
        With .Columns
          .AddText("Outstanding")
          .AddText("Message")
          .AddText("Outstanding Amount")
          .AddDate("As At Date")
          .AddText("Status")
          .AddText("External Reference")
          .AddText("Request Timestamp")
        End With

        For Each FinesData In finesDataList
          With .Rows.Add().Cells
            .AddText(CStr(IIf(FinesData.HasOutstandingFines, "True", "False")))
            .AddText(FinesData.FinesMessage)
            .AddCurrency(FinesData.OutstandingFinesAmount)
            .AddDate(FinesData.AsAtDate)
            If FinesData.StatusCode = FinesData.StatusCodeDescription Then
              .AddText(FinesData.StatusCodeDescription)
            Else
              .AddText(FinesData.StatusCode & ": " & FinesData.StatusCodeDescription)
            End If
            .AddText(FinesData.ExternalTxnReference)
            .AddDate(FinesData.RequestTimestamp)
          End With
        Next
      End With
      SummaryTables.Add("CourtFines", SummaryTable)
    End If
  End If

  Return SummaryTables

End Function

Private Function CentrixNZWheels_CurrentRegisteredParties(registeredParties As ISSecurityEnquiryResponse_CentrixNZ_RegisteredParties) As ISSummaryTables

  Dim RegisteredParty As ISSecurityEnquiryResponse_CentrixNZ_RegisteredParty
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If Not registeredParties.HasData OrElse registeredParties.Count = 0 Then
    SummaryTables.AddSummaryTableBlank("RegisteredParties", "Current Registered Parties", "No Current Registered Parties found.", "RegisteredParties", 2)
  Else
    ' Main
    SummaryTable = SummaryTables.CreateSummaryTableTabular("Current Registered Parties", "RegisteredParties", 2, TestMode)
    With SummaryTable
      ' Columns
      With .Columns
        .AddDate("Acquisition Date")
        .AddText("Name")
        .AddText("Physical Address")
        .AddText("Mailing Address")
      End With

      With .Rows
        For Each RegisteredParty In registeredParties
          With .Add().Cells
            .AddDate(RegisteredParty.AcquisitionDate)
            .AddText(RegisteredParty.PartyName)
            .AddAddressPlainText(RegisteredParty.PhysicalAddress)
            .AddAddressPlainText(RegisteredParty.MailingAddress)
          End With
        Next
      End With
    End With
    SummaryTables.Add("RegisteredParties", SummaryTable)
  End If

  Return SummaryTables

End Function

Private Sub CentrixNZWheels_FinancialInterests(sb As finHtmlSummaryPage2StringBuilder,
                                               financialInterests As ISSecurityEnquiryResponse_CentrixNZ_FinancialInterests)

  Dim CollateralItem As ISSecurityEnquiryResponse_CentrixNZ_CollateralItem
  Dim Debtor As ISSecurityEnquiryResponse_CentrixNZ_Debtor
  Dim i As Integer
  Dim Interest As ISSecurityEnquiryResponse_CentrixNZ_Interest
  Dim SecuredParty As ISSecurityEnquiryResponse_CentrixNZ_SecuredParty
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Financial Interests", "FinancialInterests", 2, 16, 40, TestMode)
  With SummaryTable
    ' Disclaimer
    .TextBefore = "{{disclaimer|" & financialInterests.Disclaimer & "}}"

    .AddRowCaptionDateTime("PPSR Search Date:", financialInterests.PPSRSearchDate)
    .AddRowCaptionText("Search Status:", financialInterests.PPSRSearchStatus)
  End With
  SummaryTables.Add("FinancialInterests", SummaryTable)
  sb.SummaryTablesAppend(SummaryTables)

  i = 0
  For Each Interest In financialInterests.Interests
    ' Initialise
    SummaryTables = finBL.CreateSummaryTables()

    i += 1

    ' Interest
    SummaryTable = SummaryTables.CreateSummaryTableInformation(interest.RegistrationNumber, interest.RegistrationNumber, 3, 16, 40, TestMode)
    With SummaryTable
      .AddRowCaptionText("Registration Number:", interest.RegistrationNumber)
      .AddRowCaptionDateTime("Registration Date:", interest.RegistrationDate)
      .AddRowCaptionText("Status:", interest.Status)
      .AddRowCaptionDateTime("Expiry Date:", interest.ExpiryDate)
    End With
    SummaryTables.Add(String.Format("Interest_{0}", i), SummaryTable)

    ' Collateral
    If Interest.CollateralItems.Count <> 0 Then
      SummaryTable = SummaryTables.CreateSummaryTableTabular("Collateral Items", "CollateralItems", 3, TestMode)
      With SummaryTable
        ' Columns
        With .Columns
          .AddText("Collateral")
          .AddText("Plate Number")
          .AddText("VIN")
          .AddText("Chassis")
        End With

        For Each CollateralItem In Interest.CollateralItems
          With .Rows.Add().Cells
            .AddText(CollateralItem.CollateralDescription)
            .AddText(CollateralItem.PlateNumber)
            .AddText(CollateralItem.Vin)
            .AddText(CollateralItem.Chassis)
          End With
        Next
      End With
      SummaryTables.Add(String.Format("Interest_{0} Collateral", i), SummaryTable)
    End If

    ' Secured Parties
    If Interest.SecuredParties.Count <> 0 Then
      SummaryTable = SummaryTables.CreateSummaryTableTabular("Secured Parties", "SecuredParties", 3, TestMode)
      With SummaryTable
        ' Columns
        With .Columns
          .AddText("Name")
          .AddText("Address")
          .AddText("Mailing Address")
          .AddText("Phone")
          .AddText("Fax")
          .AddText("Email")
        End With

        For Each SecuredParty In Interest.SecuredParties
          With .Rows.Add().Cells
            .AddText(SecuredParty.Name)
            .AddAddressPlainText(SecuredParty.CurrentAddress)
            .AddAddressPlainText(SecuredParty.MailingAddress)
            .AddText(SecuredParty.Phone)
            .AddText(SecuredParty.Fax)
            If Len(SecuredParty.Email) <> 0 Then
              With .Add(SecuredParty.Email)
                .HyperlinkSetEmailAddress(SecuredParty.Email)
              End With
            Else
              .AddText(SecuredParty.Email)
            End If
          End With
        Next
      End With
      SummaryTables.Add(String.Format("Interest_{0} SecuredParties", i), SummaryTable)
    End If

    ' Debtors
    If Interest.Debtors.Count <> 0 Then
      SummaryTable = SummaryTables.CreateSummaryTableTabular("Debtors", "Debtors", 3, TestMode)
      With SummaryTable
        ' Columns
        With .Columns
          .AddText("Name")
          .AddText("Address")
          .AddText("Mailing Address")
          .AddText("Phone")
          .AddText("Fax")
          .AddText("Email")
        End With

        For Each Debtor In Interest.Debtors
          With .Rows.Add().Cells
            .AddText(Debtor.Name)
            .AddAddressPlainText(Debtor.CurrentAddress)
            .AddAddressPlainText(Debtor.MailingAddress)
            .AddText(Debtor.Phone)
            .AddText(Debtor.Fax)
            If Len(Debtor.Email) <> 0 Then
              With .Add(Debtor.Email)
                .HyperlinkSetEmailAddress(Debtor.Email)
              End With
            Else
              .AddText(Debtor.Email)
            End If
          End With
        Next
      End With
      SummaryTables.Add(String.Format("Interest_{0} Debtors", i), SummaryTable)
    End If

    If i Mod 2 <> 0 Then
      sb.Append("<div style='background-color:#eeffee'>")
      sb.SummaryTablesAppend(SummaryTables)
      sb.Append("</div>")
    Else
      ' Div added as a test. This bg color was originaly set as the bg for all summary tables in the function then overwriten by this if == true statement.
      sb.Append("<div style='background-color:#F8F8F8'>")
      sb.SummaryTablesAppend(SummaryTables)
      sb.Append("</div>")
    End If
  Next

End Sub

Private Function CentrixNZWheels_FuelSafeDetails(fuelSafetyDetails As ISSecurityEnquiryResponse_CentrixNZ_FuelSafeDetails) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Fuel Safe Details", "FuelSafeDetails", 2, 16, 40, TestMode)
  With SummaryTable
    If Not fuelSafetyDetails.IsSuccess Then
      .AddRowCaptionWiki("Success:", "**!!No!!**")
    End If
    .AddRowCaptionText("Source:", fuelSafetyDetails.Source)
    .AddRowCaptionText("Response:", fuelSafetyDetails.ResponseDescription)

    If fuelSafetyDetails.IsSuccess Then
      .Rows.AddText("Fuel Economy", iseSummaryTableCellClass.CaptionBold)
      .AddRowCaptionText("Fuel Stars:", String.Format("{0} out of {1}", fuelSafetyDetails.FuelStars, fuelSafetyDetails.FuelStarsMaximum))
      .AddRowCaptionText("Consumption:", fuelSafetyDetails.FuelConsumption & " litres per 100km")
      If fuelSafetyDetails.YearlyCostIsNumeric Then
        .AddRowCaptionCurrency("Annual Cost:", fuelSafetyDetails.YearlyCost)
      Else
        .AddRowCaptionText("Annual Cost:", fuelSafetyDetails.YearlyCostRaw)
      End If

      .Rows.AddText("Environmental", iseSummaryTableCellClass.CaptionBold)
      .AddRowCaptionText("Pollutant Stars:", String.Format("{0} out of {1}", fuelSafetyDetails.PollutantStars, fuelSafetyDetails.PollutantStarsMaximum))
      .AddRowCaptionText("CO2 Stars:", String.Format("{0} out of {1}", fuelSafetyDetails.Co2Stars, fuelSafetyDetails.Co2StarsMaximum))

      .Rows.AddText("Driver Safety", iseSummaryTableCellClass.CaptionBold)
      .AddRowCaptionText("Safety Stars:", String.Format("{0} out of {1}", fuelSafetyDetails.DriverSafetyStars, fuelSafetyDetails.DriverSafetyStarsMaximum))
      .AddRowCaptionText("Test Source:", fuelSafetyDetails.DriverSafetyTestSource, True)
      .AddRowCaptionText("Test Description:", fuelSafetyDetails.DriverSafetyTest, True)
    End If
  End With
  SummaryTables.Add("FuelSafeDetails", SummaryTable)

  Return SummaryTables

End Function

Private Function CentrixNZWheels_InformationProvided(centrixResponse As ISSecurityEnquiryResponse_CentrixNZ_WheelsSearch) As ISSummaryTables

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

    ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "InformationProvided", 3, 16, 40, TestMode)
  With SummaryTable
    Days = CInt(DateDiff(DateInterval.Day, centrixResponse.EnquiryUtcDate, finBL.TimeZoneFunctions.GetCurrentUtcDateTime()))
    If Days > OutOfDateWarningDays Then
      If centrixResponse.EnquiryDate = centrixResponse.EnquiryNZDate Then
        With .Rows.Add.Cells
          .AddCaption("Enquiry Date:")
          .AddWiki("**" & finBL.FormatDateTime(centrixResponse.EnquiryNZDate, True) & " --This Report is " & CStr(Days) & " days old.--**").CellClass = iseSummaryTableCellClass.WarningBold
        End With
      Else
        With .Rows.Add.Cells
          .AddCaption("Enquiry Date:")
          .AddWiki("**" & finBL.FormatDateTime(centrixResponse.EnquiryNZDate, True) & " (all dates shown in NZ time) --This Report is " & CStr(Days) & " days old.--**").CellClass = iseSummaryTableCellClass.WarningBold
        End With
      End If
    Else    
      If centrixResponse.EnquiryDate = centrixResponse.EnquiryNZDate Then
        .AddRowCaptionDateTime("Enquiry Date:", CentrixResponse.EnquiryNZDate)
      Else
        .AddRowCaptionDateTime("Enquiry Date:", CentrixResponse.EnquiryNZDate,, "(all dates shown in NZ time)")
      End If
    End If
    .AddRowCaptionText("Enquiry Number:", centrixResponse.EnquiryNumber, True)
    If Len(centrixResponse.SearchVehicle.PlateNumber) = 0 Then
      .AddRowCaptionWiki("Plate Number:", "**Plate Number not supplied**")
    Else
      .AddRowCaptionWiki("Plate Number:", String.Format("**++{0}++**", centrixResponse.SearchVehicle.PlateNumber))
    End If
    If Len(centrixResponse.SearchVehicle.Vin) = 0 Then
      .AddRowCaptionWiki("VIN:", "**VIN not supplied**")
    Else
      .AddRowCaptionWiki("VIN:", String.Format("**++{0}++**", centrixResponse.SearchVehicle.Vin))
    End If

    ' Disclaimer
    .TextAfter = "{{disclaimer|" & centrixResponse.ReportDisclaimer & "}}"
  End With
  SummaryTables.Add("InformationProvider", SummaryTable)

  Return SummaryTables

End Function

Private Function CentrixNZ_NztaMessgages(nztaMessages As ISSecurityEnquiryResponse_CentrixNZ_NztaMessages) As ISSummaryTables

  Dim NztaMessage As ISSecurityEnquiryResponse_CentrixNZ_NztaMessage
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  SummaryTable = SummaryTables.CreateSummaryTableTabular("NZTA Messages", "NztaMessages", 2, TestMode)
  With SummaryTable
    ' Columns
    With .Columns
      .AddText("Type")
      .AddText("Origin")
      .AddText("Code")
      .AddText("Message")
    End With

    For Each NztaMessage In nztaMessages
      With .Rows.Add().Cells
        Select Case UCase(NztaMessage.Type)
          Case "Confirm"
            .AddWiki("{{Info|Confirm}}")
          Case "ERROR"
            .AddWiki("{{Error|Error}}")
          Case "FATAL"
            .AddWiki("{{Error|Fatal}}")
          Case "INFORMATION"
            .AddWiki("{{Info|Information}}")
          Case "WARNING"
            .AddWiki("{{Warning|Warning}}")
          Case Else
            .AddText(NztaMessage.Type)
        End Select
        .AddText(NztaMessage.Origin)
        .AddText(NztaMessage.Code)
        .AddText(NztaMessage.Message)
      End With
    Next
  End With
  SummaryTables.Add("NztaMessages", SummaryTable)

  Return SummaryTables

End Function

Private Function CentrixNZWheels_OdometerHistory(odometerReadings As ISSecurityEnquiryResponse_CentrixNZ_OdometerReadings) As ISSummaryTables

  Dim OdometerReading As ISSecurityEnquiryResponse_CentrixNZ_OdometerReading
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If odometerReadings.Count = 0 Then
    SummaryTables.AddSummaryTableBlank("OdometerHistory", "Odometer History", "No Odometer History found.", "OdometerHistory", 2)
  Else
    ' Main
    SummaryTable = SummaryTables.CreateSummaryTableTabular("Odometer History", "OdometerHistory", 2, TestMode)
    With SummaryTable
      ' Columns
      With .Columns
        .AddDate("Date")
        .AddInteger("Reading")
        .AddText("Source")
        .AddText("Reliable")
      End With

      For Each OdometerReading In odometerReadings
        With .Rows.Add().Cells
          .AddDate(OdometerReading.ReadingDate)
          .AddInteger(OdometerReading.Reading)
          .AddText(OdometerReading.Source)
          If OdometerReading.ReliableOdometer Then
            .AddText("Yes")
          Else
            .AddText("NO")
          End If
        End With
      Next
    End With
    SummaryTables.Add("OdoneterHistory", SummaryTable)
  End If

  Return SummaryTables

End Function

Private Function CentrixNZWheels_PlateHistory(plateIssuedList As ISSecurityEnquiryResponse_CentrixNZ_PlateIssuedList) As ISSummaryTables

  Dim PlateIssued As ISSecurityEnquiryResponse_CentrixNZ_PlateIssued
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If plateIssuedList.Count = 0 Then
    SummaryTables.AddSummaryTableBlank("PlateHistory", "Plate History", "No Plate History found.", "PlateHistory", 2)
  Else
    ' Main
    SummaryTable = SummaryTables.CreateSummaryTableTabular("Plate History", "PlateHistory", 2, TestMode)
    With SummaryTable
      ' Columns
      With .Columns
        .AddDate("Date Issued")
        .AddText("Plate Number")
      End With

      For Each PlateIssued In plateIssuedList
        With .Rows.Add().Cells
          .AddDate(PlateIssued.DateIssued)
          .AddText(PlateIssued.PlateNumber)
        End With
      Next
    End With
    SummaryTables.Add("PlateHistory", SummaryTable)
  End If


  Return SummaryTables

End Function

Private Function CentrixNZWheels_VehicleDescription(vehicleDetails As ISSecurityEnquiryResponse_CentrixNZ_VehicleDetails) As ISSummaryTables

  Dim VehicleYear As String
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

    ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Vehicle Description", "VehicleDescription", 2, 16, 40, TestMode)
  With SummaryTable
    ' Year
    If vehicleDetails.VehicleYear <> 0 Then
      VehicleYear = CStr(vehicleDetails.VehicleYear)
    Else
      VehicleYear = ""
    End If

    .AddRowCaptionText("Plate Number:", vehicleDetails.PlateNumber, True)
    .AddRowCaptionText("VIN:", vehicleDetails.Vin, True)
    .AddRowCaptionText("Vehicle Year:", VehicleYear, True)
    .AddRowCaptionText("Make:", vehicleDetails.Make, True)
    .AddRowCaptionText("Model:", vehicleDetails.Model, True)
    .AddRowCaptionText("Sub-model:", vehicleDetails.SubModel)
    .AddRowCaptionText("Body Style:", vehicleDetails.BodyStyle)
  End With
  SummaryTables.Add("VehicleDescription", SummaryTable)

  Return SummaryTables

End Function

Private Function CentrixNZWheels_RegistrationDetails(registrationDetails As ISSecurityEnquiryResponse_CentrixNZ_RegistrationDetails) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

    ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Left
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Registration Details", "RegistrationDetails", 2, 26, 40, TestMode)
  With SummaryTable
    .Align = "Left"

    .AddRowCaptionDate("First Registered in NZ:", registrationDetails.DateFirstRegisteredInNZ, True)
    .AddRowCaptionDate("Licence Expiry Date:", registrationDetails.LicenceExpiryDate, True)
    .AddRowCaptionDateTime("Licence Issue Date/Time:", registrationDetails.LicenceIssueDate, True)
    .AddRowCaptionText("Cause of Latest Registration:", registrationDetails.CauseOfLatestRegistration, True)
    .AddRowCaptionDate("Date of Last Registration:", registrationDetails.DateOfLastRegistration, True)
    .AddRowCaptionInteger("Latest Odometer:", registrationDetails.LatestOdometer, True, True)
    .AddRowCaptionDate("Date of Odometer Reading:", registrationDetails.DateOfOdometerReading, True)
    .AddRowCaptionText("Odometer Source:", registrationDetails.OdometerSource, True)
    .AddRowCaptionText("Odometer Unit:", registrationDetails.OdometerUnit, True)
  End With
  SummaryTables.Add("RegistrationDetails1", SummaryTable)

  ' Right
  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "RegistrationDetails2", 2, 26, 40, TestMode)
  With SummaryTable
    .Align = "Left"

    Select Case UCase(registrationDetails.RegistrationStatusCode)
      Case "A"
        .AddRowCaptionWiki("Registration Status:", String.Format("**++{0}++**", registrationDetails.RegistrationStatus), True)
      Case Else
        .AddRowCaptionWiki("Registration Status:", String.Format("**!!{0}!!**", registrationDetails.RegistrationStatus), True)
    End Select
    .AddRowCaptionText("Plate Type:", registrationDetails.PlateType, True)
    .AddRowCaptionText("Licence Type:", registrationDetails.LicenceType, True)
    .AddRowCaptionText("Continuous Licence:", If(registrationDetails.ContinuousLicence, "Yes", "No"), True)
    .AddRowCaptionText("Usage:", registrationDetails.Usage, True)
    .AddRowCaptionText("Subject to COF:", If(registrationDetails.SubjectToCof, "Yes", "No"), True)
    .AddRowCaptionText("Subject to RUC:", If(registrationDetails.SubjectToRuc, "Yes", "No"), True)
    .AddRowCaptionText("Subject to WOF:", If(registrationDetails.SubjectToWof, "Yes", "No"), True)
  End With
  SummaryTables.Add("RegistrationDetails2", SummaryTable)

'  ' Main
'  SummaryTable = SummaryTables.CreateSummaryTableInformation("Registration Details", "RegistrationDetails", 2, 16, 40, TestMode)
'  With SummaryTable
'    .Columns(1).WidthChars = 40
'    .Columns(1).NoBreakChars = 50
'    .Columns.AddText(16).NoBreakChars = 40
'    .Columns.AddText(40)
'
'    With .Rows.Add()
'      .Cells.AddCaption("Date First Registered in NZ:")
'      .Cells.AddDate(registrationDetails.DateFirstRegisteredInNZ, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Registration Status:")
'      Select Case UCase(registrationDetails.RegistrationStatusCode)
'        Case "A"
'          .Cells.AddWiki(String.Format("**++{0}++**", registrationDetails.RegistrationStatus))
'        Case Else
'          .Cells.AddWiki(String.Format("**!!{0}!!**", registrationDetails.RegistrationStatus))
'      End Select
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Licence Expiry Date:")
'      .Cells.AddDate(registrationDetails.LicenceExpiryDate, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Plate Type:")
'      .Cells.AddText(registrationDetails.PlateType).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Licence Issue Date/ Time:")
'      .Cells.AddDateTime(registrationDetails.LicenceIssueDate, True, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Licence Type:")
'      .Cells.AddText(registrationDetails.LicenceType).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Cause of Latest Registration:")
'      .Cells.AddText(registrationDetails.CauseOfLatestRegistration).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Continuous Licence:")
'      If registrationDetails.ContinuousLicence Then
'        .Cells.AddText("Yes").CellClass = iseSummaryTableCellClass.NormalBold
'      Else
'        .Cells.AddText("No").CellClass = iseSummaryTableCellClass.NormalBold
'      End If
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Date of Last Registration:")
'      .Cells.AddDate(registrationDetails.DateOfLastRegistration, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Usage:")
'      .Cells.AddText(registrationDetails.Usage).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Latest Odometer:")
'      .Cells.AddInteger(registrationDetails.LatestOdometer, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Subject to COF:")
'      If registrationDetails.SubjectToCof Then
'        .Cells.AddText("Yes").CellClass = iseSummaryTableCellClass.NormalBold
'      Else
'        .Cells.AddText("No").CellClass = iseSummaryTableCellClass.NormalBold
'      End If
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Date of Odometer Reading:")
'      .Cells.AddDate(registrationDetails.DateOfOdometerReading, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Subject to RUC:")
'      If registrationDetails.SubjectToRuc Then
'        .Cells.AddText("Yes").CellClass = iseSummaryTableCellClass.NormalBold
'      Else
'        .Cells.AddText("No").CellClass = iseSummaryTableCellClass.NormalBold
'      End If
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Odometer Source:")
'      .Cells.AddText(registrationDetails.OdometerSource).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Subject to WOF:")
'      If registrationDetails.SubjectToWof Then
'        .Cells.AddText("Yes").CellClass = iseSummaryTableCellClass.NormalBold
'      Else
'        .Cells.AddText("No").CellClass = iseSummaryTableCellClass.NormalBold
'      End If
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Odometer Unit:")
'      .Cells.AddText(registrationDetails.OdometerUnit).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddText("")
'      .Cells.AddText("")
'    End With
'  End With
'  SummaryTables.Add("RegistrationDetails", SummaryTable)

  Return SummaryTables

End Function

Private Function CentrixNZWheels_VehicleDetails(vehicleDetails As ISSecurityEnquiryResponse_CentrixNZ_VehicleDetails,
                                                registrationDetails As ISSecurityEnquiryResponse_CentrixNZ_RegistrationDetails) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

    ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Left
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Vehicle Details", "VehicleDetails", 2, 16, 40, TestMode)
  With SummaryTable
    .Align = "Left"

    .AddRowCaptionText("Vehicle Type:", vehicleDetails.VehicleType, True)
    .AddRowCaptionText("Chassis Number:", vehicleDetails.ChassisNumber, True)
    .AddRowCaptionText("Colour:", vehicleDetails.Colour, True)
    .AddRowCaptionText("Gross Vehicle Mass:", vehicleDetails.GrossVehicleMass & " kg", True)
    .AddRowCaptionText("Fuel Type:", vehicleDetails.FuelType, True)
    If registrationDetails.SubjectToWof
      If vehicleDetails.PassLastWof Then
        .AddRowCaptionWiki("Last WOF Inspection:", String.Format("**++{0} (Pass)++**", finBL.FormatDate(vehicleDetails.LastWofInspectionDate, True)), True)
      Else
        .AddRowCaptionWiki("Last WOF Inspection:", String.Format("**!!{0} (Failed)!!**", finBL.FormatDate(vehicleDetails.LastWofInspectionDate, True)), True)
      End If
    ElseIf registrationDetails.SubjectToCof Then
      Select Case vehicleDetails.PassLastCof
        Case iseTriState.False
          .AddRowCaptionWiki("Last COF Inspection:", String.Format("**!!{0} (Failed)!!**", finBL.FormatDate(vehicleDetails.LastCofInspectionDate, True)), True)
        Case iseTriState.None
          .AddRowCaptionText("Last COF Inspection:", "", True)
        Case iseTriState.True
          .AddRowCaptionText("Last COF Inspection:", String.Format("**++{0} (Pass)++**", finBL.FormatDate(vehicleDetails.LastCofInspectionDate, True)), True)
      End Select
    Else
      .AddRowCaptionText("", "", True)
    End If
    If registrationDetails.SubjectToWof
      .AddRowCaptionDate("WOF Expiry Date:", vehicleDetails.ExpiryDateOfLastWof, True)
    ElseIf registrationDetails.SubjectToCof Then
      .AddRowCaptionDate("COF Expiry Date:", vehicleDetails.ExpiryDateOfLastCof, True)
    Else
      .AddRowCaptionText("", "", True)
    End If
  End With
  SummaryTables.Add("VehicleDetails", SummaryTable)

  ' Right
  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "VehicleDetails2",,,, TestMode)
  With SummaryTable
    .Align = "Left"

    .AddRowCaptionText("Engine Number:", vehicleDetails.EngineNumber, True)
    .AddRowCaptionInteger("CC Rating:", vehicleDetails.CcRating, True)
    .AddRowCaptionText("Country of Origin:", vehicleDetails.CountryOfOrigin, True)
    .AddRowCaptionText("Previous Country:", vehicleDetails.PreviousCountryOfRegistration, True)
    .AddRowCaptionText("Assembly Type:", vehicleDetails.AssemblyType, True)
    .AddRowCaptionInteger("No. of Seats:", vehicleDetails.NumberOfSeats, True)
    If vehicleDetails.ReportedStolen Then
      .AddRowCaptionWiki("Reported Stolen:", "**!!Yes!!**", True)
    Else
      .AddRowCaptionWiki("Reported Stolen:", "**++No++**", True)
    End If
  End With
  SummaryTables.Add("VehicleDetails2", SummaryTable)


'  ' Main
'  SummaryTable = SummaryTables.CreateSummaryTableInformation("Vehicle Details", "Vehicle Details", 2, 16, 40, TestMode)
'  With SummaryTable
'    .Columns(1).WidthChars = 40
'    .Columns(1).NoBreakChars = 50
'    .Columns.AddText(16).NoBreakChars = 40
'    .Columns.AddText(40)
'
'    With .Rows.Add()
'      .Cells.AddCaption("Vehicle Type:")
'      .Cells.AddText(vehicleDetails.VehicleType).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Engine Number:")
'      .Cells.AddText(vehicleDetails.EngineNumber).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Chassis Number:")
'      .Cells.AddText(vehicleDetails.ChassisNumber).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("CC Rating:")
'      .Cells.AddInteger(vehicleDetails.CcRating, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Colour:")
'      .Cells.AddText(vehicleDetails.Colour).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Country of Origin:")
'      .Cells.AddText(vehicleDetails.CountryOfOrigin).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Gross Vehicle Mass:")
'      .Cells.AddText(vehicleDetails.GrossVehicleMass & " kg").CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Previous Country:")
'      .Cells.AddText(vehicleDetails.PreviousCountryOfRegistration).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      .Cells.AddCaption("Fuel Type:")
'      .Cells.AddText(vehicleDetails.FuelType).CellClass = iseSummaryTableCellClass.NormalBold
'      .Cells.AddCaption("Assembly Type:")
'      .Cells.AddText(vehicleDetails.AssemblyType).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      If registrationDetails.SubjectToWof
'        .Cells.AddCaption("Last WOF Inspection:")
'        If vehicleDetails.PassLastWof Then
'          .Cells.AddWiki(String.Format("**++{0} (Pass)++**", finBL.FormatDate(vehicleDetails.LastWofInspectionDate, True)))
'        Else
'          .Cells.AddWiki(String.Format("**!!{0} (Failed)!!**", finBL.FormatDate(vehicleDetails.LastWofInspectionDate, True)))
'        End If
'      ElseIf registrationDetails.SubjectToCof Then
'        .Cells.AddCaption("Last COF Inspection:")
'        Select Case vehicleDetails.PassLastCof
'          Case iseTriState.False
'            .Cells.AddWiki(String.Format("**!!{0} (Failed)!!**", finBL.FormatDate(vehicleDetails.LastCofInspectionDate, True)))
'          Case iseTriState.None
'            .Cells.AddText("")
'          Case iseTriState.True
'            .Cells.AddWiki(String.Format("**++{0} (Pass)++**", finBL.FormatDate(vehicleDetails.LastCofInspectionDate, True)))
'        End Select
'      Else
'        .Cells.AddCaption("")
'        .Cells.AddText("")
'      End If
'      .Cells.AddCaption("No. of Seats:")
'      .Cells.AddInteger(vehicleDetails.NumberOfSeats, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'    End With
'    With .Rows.Add()
'      If registrationDetails.SubjectToWof
'        .Cells.AddCaption("Expiry Date of Last WOF:")
'        .Cells.AddDate(vehicleDetails.ExpiryDateOfLastWof, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'      ElseIf registrationDetails.SubjectToCof Then
'        .Cells.AddCaption("Expiry Date of Last COF:")
'        .Cells.AddDate(vehicleDetails.ExpiryDateOfLastCof, True, iseSummaryTableCellTextAlign.Left).CellClass = iseSummaryTableCellClass.NormalBold
'      Else
'        .Cells.AddCaption("")
'        .Cells.AddText("")
'      End If
'      .Cells.AddCaption("Reported Stolen:")
'      If vehicleDetails.ReportedStolen Then
'        .Cells.AddWiki("**!!Yes!!**")
'      Else
'        .Cells.AddWiki("**++No++**")
'      End If
'    End With
'  End With
'  SummaryTables.Add("VehicleDetails", SummaryTable)

  Return SummaryTables

End Function

Private Function CentrixNZWheels_VehicleVariants(vehicleVariantValuationData As ISSecurityEnquiryResponse_CentrixNZ_VehicleVariant,
                                                 vehicleVariantList As ISSecurityEnquiryResponse_CentrixNZ_VehicleVariantList,
                                                 odometerReading As Integer,
                                                 odometerUnit As String) As ISSummaryTables

  Dim CellClass As iseSummaryTableCellClass
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim VehicleVariant As ISSecurityEnquiryResponse_CentrixNZ_VehicleVariant

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If Not vehicleVariantList.HasData Then
    SummaryTables.AddSummaryTableBlank("MarketValuation", "Market Valuation", "No Market Valuation found.", "MarketValuation", 2)
  Else
    If vehicleVariantValuationData IsNot Nothing Then
      ' Main
      SummaryTable = SummaryTables.CreateSummaryTableInformation("Market Valuation", "MarketValuation", 2, 16, 40, TestMode)
      With SummaryTable
        ' Disclaimer
        .TextBefore = "{{disclaimer|" & vehicleVariantList.DisclaimerShort &"}}"

        ' Rows
        .AddRowCaptionText("Valuation Id:", CStr(vehicleVariantValuationData.ValuationData.ValuationId))
        .AddRowCaptionText("Vehicle:", vehicleVariantValuationData.VehicleDescription)
        .AddRowCaptionText("Description:", vehicleVariantValuationData.Description)
        .AddRowCaptionText("Type:", vehicleVariantValuationData.VehicleTypeDescription)
        .AddRowCaptionText("Odometer:", String.Format("{0} {1}", Format(odometerReading, "#,##0"), odometerUnit))
        .AddRowCaptionCurrency("Good Condition Retail:", vehicleVariantValuationData.GoodRetail, True)
      End With
      SummaryTables.Add("MarketValuation", SummaryTable)

      ' Valuation
      SummaryTable = SummaryTables.CreateSummaryTableTabular("Valuation", "Valuation", 3, TestMode)
      With SummaryTable
        ' Columns
        With .Columns
          .AddText("Valuation")
          .AddCurrency("As New")
          .AddCurrency("Very Good")
          .AddCurrency("Good")
          .AddCurrency("Average")
          .AddCurrency("Fair")
          .AddCurrency("Poor")
        End With

        With .Rows.Add().Cells
          .AddText("Private")
          .AddCurrency(vehicleVariantValuationData.ValuationData.PrivatePriceAsNew)
          .AddCurrency(vehicleVariantValuationData.ValuationData.PrivatePriceVeryGood)
          .AddCurrency(vehicleVariantValuationData.ValuationData.PrivatePriceGood)
          .AddCurrency(vehicleVariantValuationData.ValuationData.PrivatePriceAverage)
          .AddCurrency(vehicleVariantValuationData.ValuationData.PrivatePriceFair)
          .AddCurrency(vehicleVariantValuationData.ValuationData.PrivatePricePoor)
        End With

        With .Rows.Add().Cells
          .AddText("Trade In")
          .AddCurrency(vehicleVariantValuationData.ValuationData.TradeInPriceAsNew)
          .AddCurrency(vehicleVariantValuationData.ValuationData.TradeInPriceVeryGood)
          .AddCurrency(vehicleVariantValuationData.ValuationData.TradeInPriceGood)
          .AddCurrency(vehicleVariantValuationData.ValuationData.TradeInPriceAverage)
          .AddCurrency(vehicleVariantValuationData.ValuationData.TradeInPriceFair)
          .AddCurrency(vehicleVariantValuationData.ValuationData.TradeInPricePoor)
        End With
      End With
      SummaryTables.Add("Valuation", SummaryTable)

    End If

    ' Without Valuation Data
    ' Variants
    If vehicleVariantList.Count = 0 Then
      SummaryTables.AddSummaryTableBlank("Variants", "Variants", "No Variants information found.", "Variants", 2)
    Else
      If vehicleVariantValuationData IsNot Nothing Then
        SummaryTable = SummaryTables.CreateSummaryTableTabular("Variants", "Variants", 3, TestMode)
      Else
        SummaryTable = SummaryTables.CreateSummaryTableTabular("Variants", "Variants", 2, TestMode)
      End If
      With SummaryTable
        ' Columns
        With .Columns
          .AddText("Redbook Code")
          .AddText("Type")
          .AddText("Description")
          .AddText("Body")
          .AddText("Make")
          .AddText("Model")
          .AddText("Manufacture Date")
          .AddCurrency("Good Condition Retail")
        End With

        With .Rows
          For Each VehicleVariant In vehicleVariantList
            If VehicleVariant.ValuationData.HasData Then
              CellClass = iseSummaryTableCellClass.NormalBold
            Else
              CellClass = iseSummaryTableCellClass.Normal
            End If
            With .Add().Cells
              .AddText(VehicleVariant.RedbookCode).CellClass = CellClass
              .AddText(VehicleVariant.VehicleTypeDescription).CellClass = CellClass
              .AddText(VehicleVariant.MakeDescription).CellClass = CellClass
              .AddText(VehicleVariant.BodyStyle).CellClass = CellClass
              .AddText(VehicleVariant.FamilyDescription).CellClass = CellClass
              .AddText(VehicleVariant.Description).CellClass = CellClass
              If VehicleVariant.Month = 0 Then
                .AddText(CStr(VehicleVariant.Year)).CellClass = CellClass
              Else
                .AddText(String.Format("{0}/{1}", VehicleVariant.Month, VehicleVariant.Year)).CellClass = CellClass
              End If
              .Addcurrency(VehicleVariant.GoodRetail).CellClass = CellClass
            End With
          Next
        End With

        ' Disclaimer
        .TextAfter = "{{disclaimer|" & vehicleVariantList.Disclaimer &"}}"
      End With
      SummaryTables.Add("Variants", SummaryTable)
    End If
  End If

  Return SummaryTables

End Function