' SummaryPage2_PPSRUpdate_ItemSummary
Option Explicit On
Option Strict On

' #################################################################
' PPSRNZ Update Summary Page

' Version: 2.01 (16/03/2021)

' Usage: PPSRNZ Update wizard
' #################################################################

'#Const "ShowItemReference",Boolean,False,"Show Reference column in Security Items table."

' Constants
Private ShowItemReference As Boolean = False

' Properties
Dim mPPSRNZUpdate As finSecurityRegistryPPSRNZ_Update
Dim mSecurityStmt As finSecurityStmt
Dim mIndex As Integer

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

  ' Assume Success
  Main = True

  ' Initialise  
  mIndex = eventArgs.GetInteger("Index")

  ' Get Source
  If source IsNot Nothing Then
    Select Case source.GetType()
      Case GetType(finSecurityRegistryPPSRNZ_Update)
        mPPSRNZUpdate = DirectCast(source, finSecurityRegistryPPSRNZ_Update)

      Case Else
        mSecurityStmt = DirectCast(source, finSecurityStmt)
    End Select
  End If    
  
  ' Get Constants
  With ScriptInfo.Constants
    ShowItemReference = .GetBoolean("ShowItemReference", ShowItemReference)
  End With

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

End Function

Private Function CreatePage(ByRef html As String) As Boolean

  Dim Ok As Boolean
  Dim sb As finHtmlSummaryPage2StringBuilder
  Dim Warnings As finWarnings

  ' Assume Success
  Ok = True

  ' Initialise
  sb = finBL.CreateHtmlSummaryPage2StringBuilder()

  ' Initialise HTML
  With sb
    .Initialise(ScriptInfo)
    .HtmlHeaderBegin("", isefinSummaryPageStyle.Blocks)
    .HtmlHeaderEnd()
  End With

  ' Get Security Statement
  If mSecurityStmt Is Nothing AndAlso mPPSRNZUpdate IsNot Nothing Then
    mSecurityStmt = mPPSRNZUpdate(mIndex).SecurityStmt
  End If  

  If mSecurityStmt IsNot Nothing Then
    ' Security Statement
    ' Begin Section
    sb.SectionColumnsBegin()

    ' Begin Column 1
    sb.ColumnBegin("60%")

    ' Summary
    sb.BlockBegin("Summary", "", isefinSummaryPageBlockHeadingStyle.Main, False)
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.SecurityStmt_Summary(ScriptInfo, mSecurityStmt, Me.ScriptInfo.FormKey <> "SecurityStmts", ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
    sb.BlockEnd()

    ' PPSR
    sb.BlockBegin("PPSR")
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.SecurityStmt_PPSRSummary(ScriptInfo, mSecurityStmt, ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
    sb.BlockEnd()

    ' Security Items
    If finBL.Settings.SecurityStmtInsuranceBrokerTerminology Then
      sb.BlockBegin("Policies")
    Else
      sb.BlockBegin("Security Items")
    End If
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.SecurityStmt_SecurityItems(ScriptInfo, mSecurityStmt, ShowItemReference, False, False, False, False, True, 20, ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
    sb.BlockEnd()

    ' End Column 1
    sb.ColumnEnd()

    ' Begin Column 2
    sb.ColumnBegin("40%", "25em", "50em")

    ' Warnings
    Warnings = mSecurityStmt.GetWarnings()
    sb.BlockBegin("Warnings", "", If(Warnings.Count = 0, isefinSummaryPageBlockHeadingStyle.Normal, isefinSummaryPageBlockHeadingStyle.Warning))
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.WarningsSummary(ScriptInfo, Warnings))
    sb.BlockEnd()

    ' Accounts
    If mSecurityStmt.Accounts.Count <> 0 Then
      sb.BlockBegin("Accounts")
      sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.SecurityStmt_Accounts(ScriptInfo, mSecurityStmt, 20, ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
      sb.BlockEnd()
    End If

    ' Clients
    If mSecurityStmt.Clients.Count <> 0 Then
      sb.BlockBegin("Clients")
      sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.SecurityStmt_Clients(ScriptInfo, mSecurityStmt, 20, ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
      sb.BlockEnd()
    End If

    ' End Column 2
    sb.ColumnEnd()

    ' End Section
    sb.SectionColumnsEnd()
  End If

  ' Finalise HTML
  sb.HtmlFinalise()

  ' Resolve Templates
  html = sb.ToString(True)

  Return Ok

End Function