' SummaryPage2_AccountPayment_PaymentSummary
Option Explicit On
Option Strict On

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

' Version: 2.02 (11/06/2018)

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

' Objects
Private mAccount As finAccount
Private mAccountPayment As finAccountPayment

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
  mAccountPayment = DirectCast(source, finAccountPayment)
  mAccount = mAccountPayment.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("100%")

    ' Summary
    sb.BlockBegin("Summary", "", isefinSummaryPageBlockHeadingStyle.Main, False)
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.AccountPayment_Summary(ScriptInfo, mAccountPayment, False))
    sb.BlockEnd()

    ' Credit Limits
    If mAccount.AccountType.CreditLimitCount > 0 Then
      sb.BlockBegin("Credit Limits")
      sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_CreditLimits_ForTransaction(ScriptInfo, mAccount, mAccountpayment.PaymentDate, "Payment", mAccountPayment.PaymentValueResolved, , , "Fees", mAccountPayment.PaymentFeeValueResolved,False), "", "")
      sb.BlockEnd()
    End If

    ' End Column 1
    sb.ColumnEnd()

    ' End Section
    sb.SectionColumnsEnd()
  End If

  ' Finalise HTML
  sb.HtmlFinalise()

  ' Resolve Templates
  html = sb.ToString(True)

  Return Ok

End Function