' SummaryPage2_AccountAcceptDecline_AccountSummary
Option Explicit On
Option Strict On

' #################################################################
' Account Accept or Decline Summary page
'
' Version: 2.01 (04/11/2021)
'
' Usage: Account Accept or Decline wizard
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    2.00  13/03/2014  ISS
'    2.01  04/11/2021  ISS      J027713   Updated obsoleted functions
' #################################################################

'#Const "BankReferenceLength",Integer,0,"Length of Bank Reference. Will left pad with zeros if necessary, 0=no padding."
'#const "ShowClientAddressInSummary",Boolean,False,"Show the Main Client's postal address in the Summary Block."
'#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 "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."
'#const "ShowCreditLimitBlock",Boolean,True,"Show Credit Limits Block."
'#const "ShowMinimumPaymentsDueBlock",Boolean,True,"Show Minimum Payments Due Block."
'#const "ShowInterestBlock",Boolean,True,"Show Interest Block."

' Constants
Private BankReferenceLength As Integer = 0
Private ShowClientAddressInSummary As Boolean = False
Private ShowClientCity As Boolean = True
Private ShowClientAddressFull As Boolean = False
Private ShowClientDateOfBirth As Boolean = False
Private ShowClientPassword As Boolean = True
Private ShowCreditLimitBlock As Boolean = True
Private ShowMinimumPaymentsDueBlock As Boolean = True
Private ShowInterestBlock As Boolean = True

' Objects
Private mAccount As finAccount
Private mAccountAcceptDecline As finAccountAcceptDecline

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

  ' Get Constants
  With ScriptInfo.Constants
    BankReferenceLength = .GetInteger("BankReferenceLength", BankReferenceLength)
    ShowClientAddressInSummary = .GetBoolean("ShowClientAddressInSummary", ShowClientAddressInSummary)
    ShowClientCity = .GetBoolean("ShowClientCity", ShowClientCity)
    ShowClientAddressFull = .GetBoolean("ShowClientAddressFull", ShowClientAddressFull)
    ShowClientDateOfBirth = .GetBoolean("ShowClientDateOfBirth", ShowClientDateOfBirth)
    ShowClientPassword = .GetBoolean("ShowClientPassword", ShowClientPassword)
    ShowCreditLimitBlock = .GetBoolean("ShowCreditLimitBlock", ShowCreditLimitBlock)
    ShowMinimumPaymentsDueBlock = .GetBoolean("ShowMinimumPaymentsDueBlock", ShowMinimumPaymentsDueBlock)
    ShowInterestBlock = .GetBoolean("ShowInterestBlock", ShowInterestBlock)
  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

  ' 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.Quote Then
    ' Invalid Account Status
    sb.SectionColumnsAddQuickBlock("Summary", "{{info|Please select a 'Quote' Account.}}")
  Else
    ' Begin Section
    sb.SectionColumnsBegin()

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

    ' Summary
    sb.BlockBegin("Summary", "", isefinSummaryPageBlockHeadingStyle.Main, False)
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_Summary(ScriptInfo, mAccount, False, ShowClientAddressInSummary, BankReferenceLength))
    sb.BlockEnd()

    ' Clients
    sb.BlockBegin("Clients", "", If(mAccount.Clients.HasClientWithAlertMessage(), isefinSummaryPageBlockHeadingStyle.Warning, isefinSummaryPageBlockHeadingStyle.Normal))
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_Clients(ScriptInfo, mAccount, ShowClientCity, ShowClientAddressFull, ShowClientDateOfBirth, ShowClientPassword, True, True, True, 20, False))
    sb.BlockEnd()

    ' Financial Summary
    sb.BlockBegin("Summary")
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_FinancialSummary(ScriptInfo, mAccount,,, False, False))
    sb.BlockEnd()

    ' End Column
    sb.ColumnEnd()

    ' Begin Column 2
    sb.ColumnBegin("")

    ' Term and Payments/ Financial
    Select Case mAccount.AccountClass
      Case isefinAccountClass.Disbursement
        ' Financial Details block
        sb.BlockBegin("Financial Details")
        sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_FinancialDetails(ScriptInfo, mAccount,, False))
        sb.BlockEnd()

      Case isefinAccountClass.LoanFR, isefinAccountClass.LoanFT
        ' Term & Payments block
        sb.BlockBegin("Term & Payments")
        sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_TermAndPayments(ScriptInfo, mAccount,, False))
        sb.BlockEnd()

      Case isefinAccountClass.LoanRC
        ' Financial Details block
        sb.BlockBegin("Financial Details")
        sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_FinancialDetails(ScriptInfo, mAccount,, False))
        sb.BlockEnd()

        ' Minimum Payments block
        If ShowMinimumPaymentsDueBlock Then
          sb.BlockBegin("Minimum Payments")
          sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_MinimumPaymentsSummary2(ScriptInfo, mAccount,,,,,, False))
          sb.BlockEnd()
        End If
    End Select

    ' Interest block
    If ShowInterestBlock AndAlso mAccount.SupportsInterest Then
      sb.BlockBegin("Interest")
      sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_Interest2(ScriptInfo, mAccount,,,,,,, False))
      sb.BlockEnd()
    End If

    ' Credit Limits
    If mAccount.AccountType.CreditLimitCount > 0 Then
      sb.BlockBegin("Credit Limits")
      sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.Account_CreditLimits(ScriptInfo, mAccount, 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