' SummaryPage2_ClientEmployments_EmploymentSummary
Option Explicit On
Option Strict On

' #################################################################
' Client Employment Summary

' Version: 2.00 (01/12/2015)

' Usage: Clients form, Employments page
' #################################################################

'#Const "ShowMap",Boolean,False,"Show a map of the Contact Address."

' Constants
Private ShowMap As Boolean = True

' Objects
Private mClient As finClient
Private mClientEmployment As finClientEmployment

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 Index As Integer

  ' Assume Success
  Main = True

  ' Initialise
  mClient = DirectCast(source, finClient)
  Index = eventArgs.GetInteger("Index")
  If Index >= 0 AndAlso Index < mClient.Employments.Count Then
    mClientEmployment = mClient.Employments(Index)
  Else
    Main = False
    finBL.Error.ErrorBegin("Invalid Employment index.")
  End If

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

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

End Function

Private Function CreatePage(ByRef html As String) As Boolean

  Dim Ok As Boolean
  Dim sb As finHtmlSummaryPage2StringBuilder

  ' Assume Success
  Ok = True

  ' Initialise
  sb = finBL.CreateHtmlSummaryPage2StringBuilder()

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

  ' Begin Section
  sb.SectionColumnsBegin()

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

  ' Summary Block
  sb.BlockBegin("Summary", "", isefinSummaryPageBlockHeadingStyle.Main, False)
  sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.ClientEmployment_Summary(ScriptInfo, mClientEmployment))
  sb.BlockEnd()

  ' Linked Client Summary Block
  If mClientEmployment.LinkedClientPk <> 0 Then
    sb.BlockBegin("Linked Client Summary")
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Client_Summary(ScriptInfo, mClientEmployment.LinkedClient))
    sb.BlockEnd()
  End If

  ' End Column 1
  sb.ColumnEnd()

  ' Begin Column 2
  sb.ColumnBegin()

  ' External User Block
  Select Case mClientEmployment.Client.SpecialType
    Case isefinClientSpecialType.ExternalParty
      sb.BlockBegin("External User")
      sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.ClientEmployment_ExternalUser(ScriptInfo, mClientEmployment))
      sb.BlockEnd()
  End Select

  ' Linked Client Addresses Block
  If mClientEmployment.LinkedClientPk <> 0 Then
    sb.BlockBegin("Linked Client Addresses")
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Client_Addresses(ScriptInfo, mClientEmployment.LinkedClient))
    sb.BlockEnd()
  End If

  ' Address Map
  If ShowMap Then
    If mClientEmployment.LinkedClientPk <> 0 Then
      If mClientEmployment.LinkedClient.ContactAddresses.GetCurrentPhysicalAddressContactAddress() IsNot Nothing Then
        sb.BlockBegin("Linked Client Map")
        sb.Append(finBL.SummaryPageStandardBlocks.Client_Map(ScriptInfo, mClientEmployment.LinkedClient, , mClientEmployment.LinkedClient.ContactAddresses.GetCurrentPhysicalAddressContactAddress().ToAddressDetails(True)))
        sb.BlockEnd()
      End If
    End If
  End If

  ' End Column 2
  sb.ColumnEnd()

  ' End Section
  sb.SectionColumnsEnd()

  ' Finalise HTML
  sb.HtmlFinalise()

  ' Resolve Templates
  html = sb.ToString(True)

  Return Ok

End Function