' SummaryPage2_BankingInterfaceSummary_Monoova
Option Explicit On
Option Strict On

' #################################################################
' Monoova Banking Interface Summary Page Script
'
' (c) Copyright Intersoft Systems Limited 2024
'
' Version: 1.01 (19/11/2024)
'
' Usage: Various forms
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  08/07/2024  ISS      J032289   Created
'          29/07/2024  ISS      J032652   Added PayTo
'    1.01  19/11/2024  ISS      J034741   Incorrect button shown for PayTo Agreement
' #################################################################

' Constants
'#const "IncludeFeeInformation",Boolean,True,"Show Fee information?"

' Constants
Private IncludeFeeInformation As Boolean = True

' Special Constants
Const TestMode As Boolean = False

' Properties
Private ServiceLogs As ISServiceLogs

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 ISBankInterfaceResponse

  ' Assume Success
  Main = True

  ' Get Constants
  With ScriptInfo.Constants
    IncludeFeeInformation = .GetBoolean("IncludeFeeInformation", IncludeFeeInformation)
  End With

  ' Get Service Logs
  Try
    Main = finBL.BankingInterface.GetServiceLogs(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 the Banking Interface.")
    ElseIf ServiceLogs(0).RequestStatus <> iseAuditLogStatus.Success Then
      Main = False
      finBL.Error.ErrorBegin("Invalid Service Log. Initial Request was not successful.")
    Else
      Response = DirectCast(ServiceLogs(0).ExResponse, ISBankInterfaceResponse)
    End If
  End If

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

End Function

Private Function CreatePage(response As ISBankInterfaceResponse,
                            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 serviceLogs(0).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("#663399", "#F0F0F0", "", "#F2F2F2")
    .HtmlHeaderInsertServiceReportTheme("#663399", "#2AB5C5", "", "#F2F2F2")

    ' 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

  ' Body
  Select Case response.GetType()
    Case GetType(ISBankInterfaceResponse_Monoova_GetmAccountDetails)
      Me.CreatePage_mAccountDetails(DirectCast(response, ISBankInterfaceResponse_Monoova_GetmAccountDetails), HtmlSummaryPage2StringBuilder)

    Case GetType(ISBankInterfaceResponse_Monoova_PayToCreatePaymentAgreement)
      Me.CreatePage_PayToCreatePaymentAgreement(DirectCast(response, ISBankInterfaceResponse_Monoova_PayToCreatePaymentAgreement), HtmlSummaryPage2StringBuilder)
      
    Case GetType(ISBankInterfaceResponse_Monoova_PayToCreatePaymentInstruction)
      Me.CreatePage_PayToCreatePaymentInstruction(DirectCast(response, ISBankInterfaceResponse_Monoova_PayToCreatePaymentInstruction), HtmlSummaryPage2StringBuilder)

    Case GetType(ISBankInterfaceResponse_Monoova_ProcessTransaction)
      Me.CreatePage_ProcessTransaction(DirectCast(response, ISBankInterfaceResponse_Monoova_ProcessTransaction), HtmlSummaryPage2StringBuilder)
      
    Case GetType(ISBankInterfaceResponse_Monoova_ValidateBsb)
      Me.CreatePage_ValidateBsb(DirectCast(response, ISBankInterfaceResponse_Monoova_ValidateBsb), HtmlSummaryPage2StringBuilder)
      
    Case Else
      Success = False
      finBL.Error.ErrorBeginFormat("Unexpected Response Type '{0}'.", TypeName(response))
  End Select

  ' Disclaimer
  HtmlSummaryPage2StringBuilder.AppendLine("<hr>")
  HtmlSummaryPage2StringBuilder.AppendLine("{{disclaimer|finPOWER Connect version " & finBL.VersionMajorMinorBuild & " using " & response.ServiceName & " service.}}")

  ' Finalise HTML
  HtmlSummaryPage2StringBuilder.HtmlFinalise()

  ' Resolve Templates
  html = HtmlSummaryPage2StringBuilder.ToString(True)

  Return Success

End Function

Private Sub CreatePage_mAccountDetails(response As ISBankInterfaceResponse_Monoova_GetmAccountDetails,
                                       htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  With HtmlSummaryPage2StringBuilder
    .AppendH1(String.Format("Account '{0}'", response.Request_GetmAccountDetails.AccountNumber))
    .AppendH2(response.ServiceName)
  
    .SummaryTablesAppend(Me.Monoova_mAccountDetails_Request(response))
    .SummaryTablesAppend(Me.Monoova_mAccountDetails(response))
  End With
 
End Sub

Private Sub CreatePage_PayToCreatePaymentAgreement(response As ISBankInterfaceResponse_Monoova_PayToCreatePaymentAgreement,
                                                   htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Agreement As ISBankInterfaceResponse_Monoova_PayToGetPaymentAgreementDetails
  Dim IsCancelling As Boolean
  Dim Response_Monoova_PayToAmendPaymentAgreementStatus As ISBankInterfaceResponse_Monoova_PayToAmendPaymentAgreementStatus
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects
  Dim SummaryTables As ISSummaryTables

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))

  ' Get Related Service Log for List of Agreements
  IsCancelling = False
  For Each ServiceLog In ServiceLogs
    If ServiceLog.RequestStatus = iseAuditLogStatus.Success Then
      Select Case ServiceLog.ExResponse.GetType()
        Case GetType(ISBankInterfaceResponse_Monoova_PayToCreatePaymentAgreement)
          ' Ignore Create
          
        Case GetType(ISBankInterfaceResponse_Monoova_PayToAmendPaymentAgreementBilateral)
          ' Ignore Amendments
          
        Case GetType( ISBankInterfaceResponse_Monoova_PayToAmendPaymentAgreementUnilateral)
          ' Ignore Amendments

        Case GetType(ISBankInterfaceResponse_Monoova_PayToGetPaymentAgreement)
          Agreement = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Monoova_PayToGetPaymentAgreement).Data
        
        Case GetType(ISBankInterfaceResponse_Monoova_PayToAmendPaymentAgreementStatus)
          ' Status Change - check for cancelling
          Response_Monoova_PayToAmendPaymentAgreementStatus = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Monoova_PayToAmendPaymentAgreementStatus)
          If Response_Monoova_PayToAmendPaymentAgreementStatus.Request_PayToAmendPaymentAgreementStatus.Status= iseBankInterface_Monoova_PayToAgreementPayloadStatus.Cancel Then
            IsCancelling = True
          End If
         
      End Select
    End If
  Next

  With HtmlSummaryPage2StringBuilder
    If Not String.IsNullOrEmpty(response.Request_PayToCreatePaymentAgreement.PayerDetails.UltimatePayer) Then
      .AppendH1(response.Request_PayToCreatePaymentAgreement.PayerDetails.UltimatePayer)
    Else
      .AppendH1(response.Request_PayToCreatePaymentAgreement.PayerDetails.Payer)
    End If
    .AppendH2(String.Format("PayTo Payment Agreement - {0}", response.ServiceName))

    .SummaryTablesAppend(Me.Monoova_PayToCreateAgreement_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Monoova_PayToPaymentAgreement(response, Agreement, 2, IsCancelling, Response_Monoova_PayToAmendPaymentAgreementStatus, ServiceLogSourceObjects.Account.pk))
        
    ' History
    SummaryTables = Me.Monoova_History()
    If finBL.CurrentUser.IsAdministrator Then
      ' Add Force Delete option?
      Select Case ServiceLogs(0).ResponseStatus
        Case iseServiceLogResponseStatus.Complete, iseServiceLogResponseStatus.NotApplicable
          ' Only show if last Request is a failed Agreeement
          ' TODO 
          If ServiceLog.RequestStatus = iseAuditLogStatus.Failed AndAlso ServiceLogs(ServiceLogs.Count - 1).ProductId = ISBankInterfaceResponse_Monoova_PayToCreatePaymentAgreement.PRODUCT_ID Then
            SummaryTables.ItemByIndex(0).Actions.AddApplicationShortcutUrl("ForceDelete", "Force Delete", String.Format("App://Global?Type=BankingInterface.Monoova.DeleteReceivableContact&ServiceLogPk={0}&force=true", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          End If
      End Select
    End If  
    .SummaryTablesAppend(SummaryTables)
 End With

End Sub

Private Sub CreatePage_PayToCreatePaymentInstruction(response As ISBankInterfaceResponse_Monoova_PayToCreatePaymentInstruction,
                                                     htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Name As String
  Dim Request_PayToCreatePaymentInstruction As ISBankInterfaceRequest_Monoova_PayToCreatePaymentInstruction
  Dim Response_PayToGetPaymentInstruction As ISBankInterfaceResponse_Monoova_PayToGetPaymentInstruction
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects
  Dim SummaryTables As ISSummaryTables

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))

  ' Get Related Service Log for List of Agreements
  For Each ServiceLog In ServiceLogs
    If ServiceLog.RequestStatus = iseAuditLogStatus.Success Then
      Select Case ServiceLog.ExResponse.GetType()
        Case GetType(ISBankInterfaceResponse_Monoova_PayToCreatePaymentInstruction)
          Request_PayToCreatePaymentInstruction = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Monoova_PayToCreatePaymentInstruction).Request_PayToCreatePaymentInstruction

        Case GetType(ISBankInterfaceResponse_Monoova_PayToGetPaymentInstruction)
          Response_PayToGetPaymentInstruction = DirectCast(servicelog.ExResponse, ISBankInterfaceResponse_Monoova_PayToGetPaymentInstruction)
          
      End Select
    End If
  Next

  ' Get Name
  If ServiceLogSourceObjects.BankTransactionView IsNot Nothing Then
    Name = ServiceLogSourceObjects.BankTransactionView.AccountTransactions(0).AccountName
  End If
  
  With HtmlSummaryPage2StringBuilder
    .AppendH1(Name)
    .AppendH2(String.Format("PayTo Payment Instruction - {0}", response.ServiceName))

    .SummaryTablesAppend(Me.Monoova_PayToCreatePayment_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Monoova_PayToPayment(Request_PayToCreatePaymentInstruction, Response_PayToGetPaymentInstruction, 2))
    
    ' History
    SummaryTables = Me.Monoova_History()
    .SummaryTablesAppend(SummaryTables)
 End With

End Sub

Private Sub CreatePage_ProcessTransaction(response As ISBankInterfaceResponse_Monoova_ProcessTransaction,
                                          htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Name As String
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))
  
  ' Get Name
  If ServiceLogSourceObjects.BankTransactionView Is Nothing Then
    Name = Response.Request_ProcessTransaction.UniqueReference
  Else
    Name = ServiceLogSourceObjects.BankTransactionView.AccountTransactions(0).AccountName
  End If
                                          
  With HtmlSummaryPage2StringBuilder
    .AppendH1(Name)
    .AppendH2(String.Format("{0} ({1}) - {2}", finBL.Runtime.TextUtilities.SplitWordsAtCapitals(response.ProductId), response.Request_ProcessTransaction.PaymentType, response.ServiceName))
    
    .SummaryTablesAppend(Me.Monoova_ProcessTransaction_Request(response, serviceLogSourceObjects))
    .SummaryTablesAppend(Me.Monoova_ProcessTransaction_Status(response, serviceLogSourceObjects))
    .SummaryTablesAppend(Me.Monoova_History())
  End With
 
End Sub

Private Sub CreatePage_ValidateBsb(response As ISBankInterfaceResponse_Monoova_ValidateBsb,
                                   htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  With HtmlSummaryPage2StringBuilder
    .AppendH1(String.Format("Validate BSB '{0}'", response.Request_ValidateBsb.BsbNumber))
    .AppendH2(response.ServiceName)
  
    .SummaryTablesAppend(Me.Monoova_ValidateBsb_Request(response))
    .SummaryTablesAppend(Me.Monoova_ValidateBsb(response))
  End With
 
End Sub

Private Function Monoova_History() 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

Private Function Monoova_mAccountDetails(response As ISBankInterfaceResponse_Monoova_GetmAccountDetails) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Response", 2,,, TestMode)
  With SummaryTable
    .AddRowCaptionText("Account Number:", Response.Data.AccountNumber)

    .Rows.AddSectionHeading3("Company")
    .AddRowCaptionText("Name:", Response.Data.Name)
    .AddRowCaptionText("ABN:", Response.Data.Abn)

    .Rows.AddSectionHeading3("Contact")
    .AddRowCaptionText("Name:", Response.Data.ContactName)
    .AddRowCaptionTextPhoneNumber("Phone:", Response.Data.ContactNumber)
    .AddRowCaptionTextEmailAddress("Email:", Response.Data.Email)
    .AddRowCaptionAddressDetailsPhysical("Address", Response.Data.AddressDetails, True)

    .Rows.AddSectionHeading3("Bank Account")
    .AddRowCaptionText("BSB:", Response.Data.Bsb)
    .AddRowCaptionText("Account Number:", Response.Data.BankAccountNumber)
    .AddRowCaptionText("Title:", Response.Data.BankAccountTitle)

    .Rows.AddSectionHeading3("Miscellaneous")
    .AddRowCaptionText("Fee Account:", Response.Data.FeeAccountNumber)
    .AddRowCaptionBooleanYesNo("Allow Duplicates?:", Response.Data.AllowDuplicates,True)

    .Rows.AddSectionHeading3("Financial")
    .AddRowCaptionCurrency("Balance:", Response.Data.Financials.ActualBalance, True, True)
    .AddRowCaptionCurrency("Uncleared Funds:", Response.Data.Financials.UnclearedFunds, True, True)
    .AddRowCaptionCurrency("Available Balance:", Response.Data.Financials.AvailableBalance, True, True, iseSummaryTableRowClass.NormalBold)
    .AddRowCaptionCurrency("Fee Account Balance:", Response.Data.Financials.FeeAccountActualBalance, True, True)

    .Rows.AddSectionHeading3("Credit Limit")
    .AddRowCaptionCurrency("Credit Limit:", Response.Data.Financials.CreditLimit, True, True)
    
    .Rows.AddSectionHeading3("NPP")
    .AddRowCaptionCurrency("NPP Balance:", Response.Data.Financials.NppBalance, True, True)
    .AddRowCaptionCurrency("NPP Payout Limit:", Response.Data.Financials.NppPayoutLimit, True, True)
  End With
  SummaryTables.Add("Response", SummaryTable)

Return SummaryTables

End Function

 Private Function Monoova_mAccountDetails_Request(response As ISBankInterfaceResponse_Monoova_GetmAccountDetails) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2,,, TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If response.Request_GetmAccountDetails.BankAccountPk <> 0 Then
      .AddRowCaptionCodeDescription("Bank Account:", response.Request_GetmAccountDetails.BankAccountPk, finBL.BankAccounts, False)
    End If  
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Monoova_PayToCreateAgreement_Request(response As ISBankInterfaceResponse_Monoova_PayToCreatePaymentAgreement,
                                                      serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()
  
  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If serviceLogSourceObjects.AccountLog IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("AccountLog", CStr(serviceLogSourceObjects.AccountLog.Pk), "Banking Interface Summary")
      End With
    ElseIf serviceLogSourceObjects.Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", serviceLogSourceObjects.Account.AccountId, "Payments")
      End With
    End If
    
    .AddRowCaptionText("Description:", response.Request_PayToCreatePaymentAgreement.PaymentDetails.Description)
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Monoova_PayToCreatePayment_Request(response As ISBankInterfaceResponse_Monoova_PayToCreatePaymentInstruction,
                                                    serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Bank Transaction:", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString(), serviceLogSourceObjects.BankTransactionView.ElementTypeText)
        .Cells(1).HyperlinkSetFormShow("BankTransactionView", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString())
      End With
      If serviceLogSourceObjects.BankTransactionView.AccountTransactions IsNot Nothing AndAlso serviceLogSourceObjects.BankTransactionView.AccountTransactions.Count <> 0 Then
        With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account.AccountId, serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account.Name)
          .Cells(1).HyperlinkSetFormShow("Accounts", serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account.AccountId, "Payments")
        End With
      End If
    End If
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Monoova_PayToPayment(request_PayToCreatePaymentInstruction As ISBankInterfaceRequest_Monoova_PayToCreatePaymentInstruction,
                                      response_PayToGetPaymentInstruction As ISBankInterfaceResponse_Monoova_PayToGetPaymentInstruction,
                             Optional headingLevel As Integer = 2) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("PayTo Payment Instruction Details", "PayToPayment", headingLevel,,, TestMode)
  With SummaryTable
    .AddRowCaptionText("Payment Id:", request_PayToCreatePaymentInstruction.PaymentInitiationUid, True)
    .AddRowCaptionText("Agreement Id:", request_PayToCreatePaymentInstruction.PaymentAgreementUid, True)
    .AddRowCaptionCurrency("Amount:", request_PayToCreatePaymentInstruction.PaymentDetails.Amount, True, True)
    .AddRowCaptionTick("Is Last Payment:", request_PayToCreatePaymentInstruction.PaymentDetails.IsLastPayment, False, False)
    .AddRowCaptionText("Lodgement Reference:", request_PayToCreatePaymentInstruction.PaymentDetails.LodgementReference)
  
    If response_PayToGetPaymentInstruction IsNot Nothing Then
      Select Case response_PayToGetPaymentInstruction.Data.PaymentInitiationStatus
        Case iseBankInterface_Monoova_PayToPaymentStatus.Undefined
          .AddRowCaptionText("Status:", response_PayToGetPaymentInstruction.Data.PaymentInitiationStatusRaw, False)
        Case Else
          .AddRowCaptionText("Status:", response_PayToGetPaymentInstruction.Data.PaymentInitiationStatusText, False) 
      End Select
      .AddRowCaptionText("Status Description", response_PayToGetPaymentInstruction.Data.PaymentInitiationStatusDescription, False)
      Select Case response_PayToGetPaymentInstruction.Data.StatusReasonCode
        Case iseBankInterface_Monoova_PayToPaymentRejectionReasonCode.Undefined
          .AddRowCaptionText("Status:", response_PayToGetPaymentInstruction.Data.StatusReasonCodeRaw, False)
        Case Else
          .AddRowCaptionText("Status:", response_PayToGetPaymentInstruction.Data.StatusReasonCodeText, False) 
      End Select
      .AddRowCaptionText("Status Description", response_PayToGetPaymentInstruction.Data.StatusReasonDescription, False)
    End If
  End With
  SummaryTables.Add("PayToPayment", SummaryTable)

Return SummaryTables

End Function

Private Function Monoova_PayToPaymentAgreement(response As ISBankInterfaceResponse_Monoova_PayToCreatePaymentAgreement,
                                               agreement As ISBankInterfaceResponse_Monoova_PayToGetPaymentAgreementDetails,
                                      Optional headingLevel As Integer = 2,
                                      Optional isCancelling As Boolean = False,
                                      Optional response_Monoova_PayToAmendPaymentAgreementStatus As ISBankInterfaceResponse_Monoova_PayToAmendPaymentAgreementStatus = Nothing,
                                      Optional accountPk As Integer = 0) As ISSummaryTables

  Dim PendingAction As ISBankInterfaceResponse_Monoova_PayToGetPaymentAgreementPendingAction
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("PayTo Payment Agreement Details", "PayToAgreement", headingLevel,,, TestMode)
  With SummaryTable
    If agreement Is Nothing Then
      .AddRowCaptionText("Payment Agreement Id:", response.Request_PayToCreatePaymentAgreement.PaymentAgreementUid)
      .AddRowCaptionUtcDateTimeWithTimeZone("Created:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
      .AddRowCaptionText("Description:", response.Request_PayToCreatePaymentAgreement.PaymentDetails.Description)
      .AddRowCaptionText("Short Description:", response.Request_PayToCreatePaymentAgreement.PaymentDetails.ShortDescription, False)
      .AddRowCaptionText("Purpose:", response.Request_PayToCreatePaymentAgreement.PaymentDetails.PurposeText)
      .AddRowCaptionDateTime("Response By:", response.Request_PayToCreatePaymentAgreement.PaymentDetails.RespondByTime, False)
      .AddRowCaptionDate("Start Date:", response.Request_PayToCreatePaymentAgreement.PaymentDetails.StartDate, False)
      .AddRowCaptionDate("End Date:", response.Request_PayToCreatePaymentAgreement.PaymentDetails.EndDate, False)
      .AddRowCaptionTick("Automatic Renewal:", response.Request_PayToCreatePaymentAgreement.PaymentDetails.AutomaticRenewal, False, True)
      
      ' Actions
      With .Actions
        ' Refresh
        .AddApplicationShortcutUrl("Update", "Update", String.Format("App://Global?Type=BankingInterface.PayTo.UpdateAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
      End With
    Else
      .AddRowCaptionText("Payment Agreement Id:", agreement.PaymentAgreementUid)
      .AddRowCaptionText("MMS Id:", agreement.MmsId)
      With .Rows.AddCaptionText("Status:", agreement.PaymentAgreementStatusText)
        .BackgroundColour = agreement.StateHtmlColour
      End With
      If len(agreement.StatusReasonDescription) <> 0 Then
        With .Rows.AddCaptionText("State Reason:", agreement.StatusReasonDescription)
          .BackgroundColour = agreement.StateHtmlColour
        End With
      End If
        
      .AddRowCaptionUtcDateTimeWithTimeZone("Created:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
      .AddRowCaptionText("Description:", agreement.PaymentDetails.Description)
      .AddRowCaptionText("Short Description:", agreement.PaymentDetails.ShortDescription, False)
      If agreement.PaymentDetails.Purpose = iseBankInterface_Monoova_PayToAgreementPurpose.Undefined Then
        .AddRowCaptionText("Purpose:", agreement.PaymentDetails.PurposeRaw)
      Else
        .AddRowCaptionText("Purpose:", agreement.PaymentDetails.PurposeText)
      End If
      .AddRowCaptionDateTime("Response By:", agreement.PaymentDetails.RespondByTime, False)
      .AddRowCaptionDate("Start Date:", agreement.PaymentDetails.StartDate, False)
      .AddRowCaptionDate("End Date:", agreement.PaymentDetails.EndDate, False)
      .AddRowCaptionTick("Automatic Renewal:", agreement.PaymentDetails.AutomaticRenewal, False, True)
     
      ' Actions
      With .Actions
        Select Case agreement.PaymentAgreementStatus
          Case iseBankInterface_Monoova_PayToAgreementStatus.Active
            ' Refresh
            .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.PayTo.RefreshAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
  
            ' Amend
            If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Amend") Then
              .AddApplicationShortcutUrl("Amend", "Amend", String.Format("App://Global?Type=BankingInterface.PayTo.AmendAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
            End If
            
            If isCancelling Then
              ' Alert if Cancelling
              SummaryTable.TextBefore = "{{alert|Agreement is being CANCELLED. Please Refresh to update the Agreement State.|true}}"
            Else  
              ' Suspend
              If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Suspend") Then
                .AddApplicationShortcutUrl("Pause", "Pause", String.Format("App://Global?Type=BankingInterface.PayTo.SuspendAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
              End If
              ' Cancel
              If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Cancel") Then
                .AddApplicationShortcutUrl("Cancel", "Cancel", String.Format("App://Global?Type=BankingInterface.PayTo.CancelAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
              End If
            End If  

          Case iseBankInterface_Monoova_PayToAgreementStatus.Cancelled, iseBankInterface_Monoova_PayToAgreementStatus.Expired
            ' Refresh
            .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.PayTo.RefreshAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
            
          Case iseBankInterface_Monoova_PayToAgreementStatus.Created, iseBankInterface_Monoova_PayToAgreementStatus.InProgress
            ' Update
            .AddApplicationShortcutUrl("Update", "Update", String.Format("App://Global?Type=BankingInterface.PayTo.UpdateAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
            
          Case iseBankInterface_Monoova_PayToAgreementStatus.Paused
            ' Refresh
            .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.PayTo.RefreshAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
            
            ' Reactivate
            If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Reactivate") Then
              .AddApplicationShortcutUrl("Resume", "Resume", String.Format("App://Global?Type=BankingInterface.PayTo.ReactivateAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
            End If            
            ' Cancel
            If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Cancel") Then
              .AddApplicationShortcutUrl("Cancel", "Cancel", String.Format("App://Global?Type=BankingInterface.PayTo.CancelAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
            End If

        Case iseBankInterface_Monoova_PayToAgreementStatus.Rejected
          ' Nothing to do
        End Select
      End With
    End If
  End With
  SummaryTables.Add("PayToAgreement", SummaryTable)
  
  ' Terms
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Terms", "PayToTerms",headingLevel+1,,, TestMode)
  With SummaryTable
    If agreement Is Nothing Then
      .AddRowCaptionText("Type:", response.Request_PayToCreatePaymentAgreement.PaymentTerms.AgreementTypeText)
      .AddRowCaptionText("Frequency:", response.Request_PayToCreatePaymentAgreement.PaymentTerms.FrequencyText)
      .AddRowCaptionInteger("Number Of Transactions Permitted:", response.Request_PayToCreatePaymentAgreement.PaymentTerms.NumberOfTransactionsPermitted,, False)
      .AddRowCaptionCurrency("Amount:", response.Request_PayToCreatePaymentAgreement.PaymentTerms.Amount,, False)
      .AddRowCaptionCurrency("Maximum Amount:", response.Request_PayToCreatePaymentAgreement.PaymentTerms.MaximumAmount,, False)     
    Else
      .AddRowCaptionText("Type:", agreement.PaymentTerms.AgreementTypeText)
      .AddRowCaptionText("Frequency:", agreement.PaymentTerms.FrequencyText)
      .AddRowCaptionInteger("Number Of Transactions Permitted:", agreement.PaymentTerms.NumberOfTransactionsPermitted.GetValueOrDefault(),, False)
      .AddRowCaptionCurrency("Amount:", agreement.PaymentTerms.Amount.GetValueOrDefault(),, False)
      .AddRowCaptionCurrency("Maximum Amount:", agreement.PaymentTerms.MaximumAmount.GetValueOrDefault(),, False)
    End If
  End With
  SummaryTables.Add("PayToTerms", SummaryTable)

  ' Payer
  If agreement IsNot Nothing Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Payer", "Payer", headingLevel+1,,, TestMode)
    With SummaryTable
      .AddRowCaptionText("Payer:", agreement.PayerDetails.Payer, False)
      If agreement.PayerDetails.PayerType = iseBankInterface_Monoova_PayToPayeePayerType.Undefined Then
        .AddRowCaptionText("Type:", agreement.PayerDetails.PayerTypeRaw, False)
      Else
        .AddRowCaptionText("Type:", agreement.PayerDetails.PayerTypeText, False)
      End If
      .AddRowCaptionText("Ultimate Payer:", agreement.PayerDetails.UltimatePayer, False)
      .AddRowCaptionText("Payer Party Reference:", agreement.PayerDetails.PayerPartyReference, False)
      .AddRowCaptionText("Account Type:", agreement.PayerDetails.PayerAccountTypeText, False)
      Select Case agreement.PayerDetails.PayerAccountType
        Case iseBankInterface_Monoova_PayToPayIdType.BankAccount
          If Len(agreement.PayerDetails.LinkedBsbRaw) > 3 Then
            .AddRowCaptionText("Linked BSB:", String.Format("{0}-{1}",  Left(agreement.PayerDetails.LinkedBsbRaw, 3), Mid(agreement.PayerDetails.LinkedBsbRaw, 4), False))
          Else
            .AddRowCaptionText("Linked BSB:", agreement.PayerDetails.LinkedBsbRaw, False)
          End If
          .AddRowCaptionText("Linked Account:", agreement.PayerDetails.LinkedAccountRaw, False)
        Case Else
          .AddRowCaptionText("Account Value:", agreement.PayerDetails.PayerAccountValue, False)
      End Select      
    End With
    SummaryTables.Add("Payer", SummaryTable)
  End If

  ' Payee
  If agreement IsNot Nothing Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Payee", "Payee", headingLevel+1,,, TestMode)
    With SummaryTable
      .AddRowCaptionText("Account Name:", agreement.PayeeDetails.PayeeAccountName, False)
      If agreement.PayeeDetails.PayeeType = iseBankInterface_Monoova_PayToPayeePayerType.Undefined Then
        .AddRowCaptionText("Type:", agreement.PayeeDetails.PayeeTypeRaw, False)
      Else
        .AddRowCaptionText("Type:", agreement.PayeeDetails.PayeeTypeText, False)
      End If
      .AddRowCaptionText("Ultimate Payee:", agreement.PayeeDetails.UltimatePayee, False)
      .AddRowCaptionText("Account Type:", agreement.PayeeDetails.PayeeAccountTypeText, False)
      Select Case agreement.PayeeDetails.PayeeAccountType
        Case iseBankInterface_Monoova_PayToPayIdType.BankAccount
          If Len(agreement.PayeeDetails.PayeeLinkedBsbRaw) > 3 Then
            .AddRowCaptionText("Linked BSB:", String.Format("{0}-{1}",  Left(agreement.PayeeDetails.PayeeLinkedBsbRaw, 3), Mid(agreement.PayeeDetails.PayeeLinkedBsbRaw, 4), False))
          Else
            .AddRowCaptionText("Linked BSB:", agreement.PayeeDetails.PayeeLinkedBsbRaw, False)
          End If
          .AddRowCaptionText("Linked Account:", agreement.PayeeDetails.PayeeLinkedAccountRaw, False)
        Case Else
          .AddRowCaptionText("Account Value:", agreement.PayeeDetails.PayeeAccountValue, False)
      End Select
    End With
    SummaryTables.Add("Payee", SummaryTable)
  End If  

  ' Pending Actions
  If agreement IsNot Nothing AndAlso agreement.PendingActions IsNot Nothing AndAlso agreement.PendingActions.Count <> 0  Then
    SummaryTable = SummaryTables.CreateSummaryTableTabular("Pending Actions", "PendingActions", headingLevel+1, TestMode)
    With SummaryTable
      ' Columns
      With .Columns
        .AddText("Id")
        .AddText("Type")
        .AddBoolean("Bilateral Agreement?")
        .AddText("Status")
      End With
  
      ' Rows
      With .Rows
        For Each PendingAction In agreement.PendingActions
          With .Add
            With .Cells
              .AddText(PendingAction.ActionId)
              If PendingAction.ActionType = iseBankInterface_Monoova_PayToAgreementPendingActionType.Undefined Then
                .AddText(PendingAction.ActionTypeRaw)
              Else
                .AddText(PendingAction.ActionTypeText)
              End If
              .AddTick(PendingAction.Bilateral, False, True)
              If PendingAction.Status = iseBankInterface_Monoova_PayToAgreementPendingActionStatus.Undefined Then
                .AddText(PendingAction.StatusRaw)
              Else
                .AddText(PendingAction.StatusText)
              End If
            End With
          End With
        Next
      End With
    End With
    SummaryTables.Add("PendingActions", SummaryTable)
  End If

  Return SummaryTables

End Function

Private Function Monoova_ProcessTransaction_Request(response As ISBankInterfaceResponse_Monoova_ProcessTransaction,
                                                    serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim Account As finAccount
  Dim BankAccount As finBankAccountRO
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Information
  If finBL.BankAccounts.ExistsPk(response.Request_ProcessTransaction.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_ProcessTransaction.BankAccountPk)
  Else
    BankAccount = Nothing
  End If
  If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
    Account = serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account
  Else
    Account = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    .AddRowCaptionText("Monoova ID:", response.Data.TransactionId, True)
    .AddRowCaptionText("Reference:", response.Request_ProcessTransaction.UniqueReference)
    .AddRowCaptionCodeDescription("Bank Account:", BankAccount.Pk, finBL.BankAccounts, False)
    If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Bank Transaction:", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString(), serviceLogSourceObjects.BankTransactionView.ElementTypeText)
        .Cells(1).HyperlinkSetFormShow("BankTransactionView", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString())
      End With
    End If
  End With
  SummaryTables.Add("Request", SummaryTable)

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Transaction", "Transaction", 3, , , TestMode)
  With SummaryTable
    .AddRowCaptionText("Type:", response.Request_ProcessTransaction.PaymentType)
    If Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", Account.AccountId, Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", Account.AccountId)
      End With
    End If
    '.AddRowCaptionText("Description:", response.Request_ProcessTransaction.Description)
    
    Select Case response.Request_ProcessTransaction.PaymentSource
      Case iseBankInterface_Monoova_TransactionPaymentSource.DirectDebit
        'TODO: Apply masking
        .AddRowCaptionText("BSB:", response.Request_ProcessTransaction.PaymentSource_DirectDebit.BsbNumber)
        .AddRowCaptionText("Account Number:", response.Request_ProcessTransaction.PaymentSource_DirectDebit.AccountNumber)
        .AddRowCaptionText("Account Name:", response.Request_ProcessTransaction.PaymentSource_DirectDebit.AccountName)
        .AddRowCaptionText("Reference:", response.Request_ProcessTransaction.PaymentSource_DirectDebit.LodgementReference)
        .AddRowCaptionCurrency("Amount:", response.Request_ProcessTransaction.Disbursements.TotalAmount, True, True)
        
      Case iseBankInterface_Monoova_TransactionPaymentSource.mAccount
        If response.Request_ProcessTransaction.Disbursements.Count = 1 Then
          Select Case response.Request_ProcessTransaction.Disbursements(0).DisbursementMethod
            Case iseBankInterface_Monoova_TransactionDisbursementMethod.NppCreditBankAccount
              .AddRowCaptionText("Remitter Name:", response.Request_ProcessTransaction.Disbursements(0).DisbursementMethod_NppBankAccount.RemitterName)
              .AddRowCaptionText("BSB:", response.Request_ProcessTransaction.Disbursements(0).DisbursementMethod_NppBankAccount.BsbNumber)
              .AddRowCaptionText("Account Number:", response.Request_ProcessTransaction.Disbursements(0).DisbursementMethod_NppBankAccount.AccountNumber)
              .AddRowCaptionText("Account Name:", response.Request_ProcessTransaction.Disbursements(0).DisbursementMethod_NppBankAccount.AccountName)
              
            Case Else
              'TODO:
          End Select    
          .AddRowCaptionCurrency("Amount:", response.Request_ProcessTransaction.Disbursements.TotalAmount, True, True)
        Else
          'TODO:
        End If  
    End Select

    ' Fees
    If IncludeFeeInformation Then
      .AddRowCaptionText("Monoova Fee:", Format(response.Data.FeeAmountIncludingGst,finBL.Runtime.Locale.CurrencyFormat(True,3)))
    End If  
  End With
  SummaryTables.Add("Transaction", SummaryTable)

  Return SummaryTables

End Function

Private Function Monoova_ProcessTransaction_Status(response As ISBankInterfaceResponse_Monoova_ProcessTransaction,
                                                   serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim BankTransactionView As finBankTransactionView
  Dim LatestTransactionStatus As ISBankInterfaceResponse_Monoova_GetTransactionStatus
  Dim ServiceLog As ISServiceLog
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Information
  If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
    BankTransactionView = serviceLogSourceObjects.BankTransactionView
  Else
    BankTransactionView = Nothing
  End If

  ' Get latest Transaction Status
  For Each ServiceLog In ServiceLogs
    If ServiceLog.RequestStatus = iseAuditLogStatus.Success Then
      Select Case ServiceLog.ExResponse.GetType()
        Case GetType(ISBankInterfaceResponse_Monoova_GetTransactionStatus)
          LatestTransactionStatus = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Monoova_GetTransactionStatus)
      End Select
    End If      
  Next  

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Status", "Status", 2, , , TestMode)
  With SummaryTable
    If BankTransactionView Is Nothing Then
      .AddRowCaptionText("Status:", serviceLogs(0).ResponseStatusText)
    Else
      With .Rows.AddCaptionText("Status:", BankTransactionView.BankInterfaceStatusText)
        Select Case BankTransactionView.BankInterfaceStatus
          Case isefinBankTransactionBankInterfaceStatus.Aborted
            .BackgroundColour = "gold"
          Case isefinBankTransactionBankInterfaceStatus.Failed, isefinBankTransactionBankInterfaceStatus.SendFailed
            .BackgroundColour = "pink"
          Case isefinBankTransactionBankInterfaceStatus.Pending, isefinBankTransactionBankInterfaceStatus.Queued
            .BackgroundColour = "orange"
          Case isefinBankTransactionBankInterfaceStatus.Success
            .BackgroundColour = "lightgreen"
        End Select
      End With
      .AddRowCaptionText("Reference:", BankTransactionView.BankInterfaceReference)
    End If  

    If LatestTransactionStatus IsNot Nothing Then
      Select Case LatestTransactionStatus.Data.Status
        Case iseBankInterface_Monoova_TransactionStatus.Complete
          .AddRowCaptionDate("Date Completed:", LatestTransactionStatus.Data.CompletedDate, True)
          .AddRowCaptionDate("Date Cleared:", LatestTransactionStatus.Data.FundsClearedDate, False)
          
        Case iseBankInterface_Monoova_TransactionStatus.Dishonoured
          .AddRowCaptionDate("Dishonour Date:", LatestTransactionStatus.Data.DishonouredDate)
          If Len(LatestTransactionStatus.Data.DishonouredReason) = 0 Then
            .AddRowCaptionText("Dishonour Reason:", LatestTransactionStatus.Data.StatusDescription)
          Else
            .AddRowCaptionText("Dishonour Reason:", LatestTransactionStatus.Data.StatusDescription & vbNewline & LatestTransactionStatus.Data.DishonouredReason)
          End If

        Case iseBankInterface_Monoova_TransactionStatus.Pending
          
        Case iseBankInterface_Monoova_TransactionStatus.Rejected

        Case iseBankInterface_Monoova_TransactionStatus.WaitingOnClearedFunds
          .AddRowCaptionDate("Expected Clearance:", LatestTransactionStatus.Data.ExpectedClearanceDateForFunds)
      End Select    
    End If  

    ' Actions
    With .actions
      If BankTransactionView IsNot Nothing AndAlso BankTransactionView.CanSendViaBankInterface Then
        .AddApplicationShortcutUrl("Resend", "Resend", String.Format("App://Global?Type=BankingInterface.Send&BankTransactionPk={0}", bankTransactionView.BankTransactionPk), True).ShowInWebInterfaces = True
      End If

      If ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.InProgress Then
        If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.Requests.Update") Then
          .AddApplicationShortcutUrl("UpdateStatus", "Update Status", String.Format("App://Global?Type=BankingInterface.UpdateStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
        End If
      End If
    End With
  End With
  SummaryTables.Add("Status", SummaryTable)

  Return SummaryTables

End Function

Private Function Monoova_ValidateBsb(response As ISBankInterfaceResponse_Monoova_ValidateBsb) As ISSummaryTables

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

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Response", 2,,, TestMode)
  With SummaryTable
    ' Branch Information
    .AddRowCaptionText("BSB:", Response.Data.Bsb)
    .AddRowCaptionText("Bank Code:", Response.Data.BankCode)
    .AddRowCaptionAddressDetailsPhysical("Address", Response.Data.AddressDetails, True)

    ' Warnings
    Warnings = ""
    If Response.Data.Closed Then
      Warnings &= "{{warning|Branch Closed.|true}}"
    End If
    .TextAfter = Warnings
  End With
  SummaryTables.Add("Response", SummaryTable)

  Return SummaryTables

End Function

 Private Function Monoova_ValidateBsb_Request(response As ISBankInterfaceResponse_Monoova_ValidateBsb) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2,,, TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If response.Request_ValidateBsb.BankAccountPk <> 0 Then
      .AddRowCaptionCodeDescription("Bank Account:", response.Request_ValidateBsb.BankAccountPk, finBL.BankAccounts, False)
    End If  
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function
