' SummaryPage2_AccountPaymentArrangement_ArrangementSummary
Option Explicit On
Option Strict On

' #################################################################
' Account Payment Arrangement Summary page

' Version: 2.01 (10/07/2018)

' Usage: Account Payment Arrangement wizard
' #################################################################

' Objects
Private mAccount As finAccount
Private mAccountPayArrangementAdd As finAccountPayArrangementAdd

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
  mAccountPayArrangementAdd = DirectCast(source, finAccountPayArrangementAdd)
  mAccount = mAccountPayArrangementAdd.Account

  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

  ' Assume Success
  Ok = True

  ' Initialise
  sb = finBL.CreateHtmlSummaryPage2StringBuilder()

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

  If mAccount.IsNew Then
    ' No Account loaded
    sb.SectionColumnsAddQuickBlock("Summary", "{{info|Please select an Account.}}")
  ElseIf mAccount.Status <> isefinAccountStatus.Open Then
    ' Invalid Account Status
    sb.SectionColumnsAddQuickBlock("Summary", "{{info|Please select an 'Open' Account.}}")
  Else
    ' Begin Section
    sb.SectionColumnsBegin()

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

    ' Summary
    sb.BlockBegin("Current Summary", "", isefinSummaryPageBlockHeadingStyle.Main, False)
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_FinancialStatus(ScriptInfo, mAccount, , , , , , , , , False))
    sb.BlockEnd()

    ' Changes
    Select Case mAccount.AccountClass
      Case isefinAccountClass.LoanFR, isefinAccountClass.LoanFT
        sb.BlockBegin("Changes")
        If mAccountPayArrangementAdd.Calculation.IsCalculationRequired Then
          sb.Append("{{info|Click 'Calculate' to display updated information.|True}}")
        Else
          sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_PaymentArrangement_Changes(ScriptInfo, mAccountPayArrangementAdd))
        End If
        sb.BlockEnd()
    End Select
    
    ' End Column 1
    sb.ColumnEnd()

    ' Begin Column 2
    sb.ColumnBegin("50%")

    ' Payment Schedule
    Select Case mAccount.AccountClass
      Case isefinAccountClass.LoanFR, isefinAccountClass.LoanFT
        sb.BlockBegin("Payment Schedule")
        If mAccountPayArrangementAdd.Calculation.IsCalculationRequired Then
          sb.Append("{{info|Click 'Calculate' to display updated information.|True}}")
        Else
          sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_PaymentArrangement_Schedule(ScriptInfo, mAccountPayArrangementAdd))
        End If
        sb.BlockEnd()

      Case isefinAccountClass.LoanRC
        sb.BlockBegin("Payment Schedule")
        If mAccountPayArrangementAdd.Calculation.IsCalculationRequired Then
          sb.Append("{{info|Click 'Calculate' to display updated information.|True}}")
        Else
          sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_PaymentArrangement_Schedule(ScriptInfo, mAccountPayArrangementAdd))
        End If
        sb.BlockEnd()
    End Select

    ' 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