' SummaryPage2_AccountArchive_ArchiveSummary
Option Explicit On
Option Strict On

' #################################################################
' Account Archive Summary
'
' Version: 2.01 (14/05/2021)
'
' Usage: Client form, Accounts page and Account Archive View form
' #################################################################

'#const "ShowClientCity",Boolean,True,"Show the City (or suburb) in the Clients block."
'#const "ShowClientAddressFull",Boolean,True,"Show the full Address in the Clients block."
'#const "ShowClientContactMethods",Boolean,False,"Show Client Contact Methods in the Clients block."
'#const "ContactMethodIds",String,"","A range of Contact Methods to include or a blank String to include all uncategories Contact Methods."
'#const "ShowClientDateOfBirth",Boolean,False,"Show the Client's date of birth in the Clients block."
'#const "ShowClientPassword",Boolean,True,"Show the Client's Password popup in the Clients block."

' Constants
Private ShowClientCity As Boolean = True
Private ShowClientAddressFull As Boolean = False
Private ShowClientContactMethods As Boolean = False
Private ContactMethodIds As String = ""
Private ShowClientDateOfBirth As Boolean = False
Private ShowClientPassword As Boolean = True

' Objects
Private mAccountArchiveView As finAccountArchiveView

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
  If TypeOf source Is String Then
	mAccountArchiveView = finBL.CreateAccountArchiveView()
    mAccountArchiveView.LoadAccountId(CStr(source))

    ' Check not filtered out
    ' NOTE: Not necessary since this is done in the business layer
  Else
    mAccountArchiveView = DirectCast(source, finAccountArchiveView)
  End If

  ' Get Constants
  With ScriptInfo.Constants
    ShowClientCity = .GetBoolean("ShowClientCity", ShowClientCity)
    ShowClientAddressFull = .GetBoolean("ShowClientAddressFull", ShowClientAddressFull)
    ShowClientContactMethods = .GetBoolean("ShowClientContactMethods", ShowClientContactMethods)
    ContactMethodIds = .GetString("ContactMethodIds", ContactMethodIds)
    ShowClientDateOfBirth = .GetBoolean("ShowClientDateOfBirth", ShowClientDateOfBirth)
    ShowClientPassword = .GetBoolean("ShowClientPassword", ShowClientPassword)
  End With

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

End Function

' The createpage in the scripts file
Private Function CreatePage(ByRef html As String) As Boolean

  Dim Account As finAccount
  Dim sb As finHtmlSummaryPage2StringBuilder
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise  
  Account = mAccountArchiveView.CreateAccount()
  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
  sb.BlockBegin("Summary", "", isefinSummaryPageBlockHeadingStyle.Main, False)
  sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.AccountArchiveView_Summary(ScriptInfo, mAccountArchiveView))
  sb.BlockEnd()

  ' Account Details
  sb.BlockBegin("Account Details")
  sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.AccountArchiveView_AccountDetails(ScriptInfo, mAccountArchiveView))
  sb.BlockEnd()

  ' Clients
  sb.BlockBegin("Clients")
  sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_Clients2(ScriptInfo, Account, ShowClientCity, ShowClientAddressFull, ShowClientContactMethods, ContactMethodIds, ShowClientDateOfBirth, ShowClientPassword, True, True, True, 20, ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
  sb.BlockEnd()

  ' User Data
  If mAccountArchiveView.UserData.Count <> 0 Then
    sb.BlockBegin("Other Information")
    sb.SummaryTablesAppend(finBL.Utilities.KeyValueListToSummaryTables(mAccountArchiveView.UserData, True))
    sb.BlockEnd()
  End If

  ' End Column 1
  sb.ColumnEnd()

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

  ' Original Financial Summary
  sb.BlockBegin("Original Financial Summary")
  If mAccountArchiveView.HasOriginalCalc Then
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_FinancialSummary(ScriptInfo, Account, mAccountArchiveView.OriginalCalc, mAccountArchiveView.OriginalSummary, False))
  Else
    sb.AppendLine("{{info|Financial details are not available.}}")
  End If
  sb.BlockEnd()

  ' Term and Payment
  Select Case mAccountArchiveView.AccountClass
    Case  isefinAccountClass.LoanFR,isefinAccountClass.LoanFT,isefinAccountClass.LoanRC
      sb.BlockBegin("Original Term & Payments")
      If mAccountArchiveView.HasOriginalCalc Then
        sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_TermAndPayments(ScriptInfo, Account))
      Else
        sb.AppendLine("{{info|Financial details are not available.}}")
      End If
      sb.BlockEnd()
  End Select

  ' Final Financial Summary
  Select Case mAccountArchiveView.ArchiveType
    Case isefinAccountArchiveType.Closed
      sb.BlockBegin("Final Financial Summary")
      If mAccountArchiveView.HasCurrentCalc Then
        sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_FinancialSummary(ScriptInfo, Account, mAccountArchiveView.CurrentCalc, mAccountArchiveView.CurrentSummary, False))
      Else
        sb.AppendLine("{{info|Financial details are not available.}}")
      End If
      sb.BlockEnd()
  End Select

  ' End Column 2
  sb.ColumnEnd()

  ' End Section
  sb.SectionColumnsEnd()

  ' Finalise HTML
  sb.HtmlFinalise()

  ' Resolve Templates
  html = sb.ToString(True)

  Return Success

End Function