' SummaryPage2_AccountApp_AccountSummary
Option Explicit On
Option Strict On

' #################################################################
' Account Application Account Details

' Version: 1.03 (26/04/2016)

' Usage: Account Applications form, Quotes page
' #################################################################

'#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,False,"Show Interest Block."
'#const "ShowWarningBankTransactions",Boolean,False,"Show warnings related to Bank Transactions, eg Cash payments not lodged, Direct Debits still to be processed."
'#const "LastPaymentDaysMaximum",Integer,120,"Maximum Days for warning since last Reversed Payment."

' 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 = False
Private ShowWarningBankTransactions As Boolean = False
Private LastPaymentDaysMaximum As Integer = 120

' Parameters
Private mIncludeShowTempObjectButton As Boolean = True

' Objects
Private mAccount As finAccount
Private mAccountApp As finAccountApp
Private mAccountAppCalculation As finAccountAppCalculation

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
  mAccountApp = DirectCast(source, finAccountApp)

  ' Get Parameters
  mAccount = DirectCast(eventArgs.GetObject("Account"), finAccount)
  mAccountAppCalculation = DirectCast(eventArgs.GetObject("AccountAppCalculation"), finAccountAppCalculation)
  mIncludeShowTempObjectButton = eventArgs.GetBoolean("IncludeShowTempObjectButton", mIncludeShowTempObjectButton)

  ' 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)
    ShowWarningBankTransactions = .GetBoolean("ShowWarningBankTransactions", ShowWarningBankTransactions)
    LastPaymentDaysMaximum = .GetInteger("LastPaymentDaysMaximum", LastPaymentDaysMaximum)
  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
  Dim Warnings As finWarnings

  ' 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("50%")

  ' Summary
  If Not mAccount.IsNew Then
    sb.BlockBegin("Summary", "(Actual Account)", isefinSummaryPageBlockHeadingStyle.Main)
  ElseIf Not mAccountAppCalculation Is Nothing Then
    sb.BlockBegin("Summary", "", isefinSummaryPageBlockHeadingStyle.Main)
  ElseIf mAccountAppCalculation.UserInvalid Then
    sb.BlockBegin("Summary", String.Format("({0})", mAccountAppCalculation.NameResolved), isefinSummaryPageBlockHeadingStyle.Warning)
  Else
    sb.BlockBegin("Summary", String.Format("({0})", mAccountAppCalculation.NameResolved), isefinSummaryPageBlockHeadingStyle.Main)
  End If
  sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.AccountApp_AccountSummary(ScriptInfo, mAccountApp, mAccountAppCalculation, mAccount, mIncludeShowTempObjectButton))
  sb.BlockEnd()

  ' End Column 1
  sb.ColumnEnd()

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

  ' Warnings
  Warnings = mAccount.GetWarnings()
  If Warnings.Count <> 0 Then
    sb.BlockBegin("Warnings", "", If(Warnings.Count = 0, isefinSummaryPageBlockHeadingStyle.Normal, isefinSummaryPageBlockHeadingStyle.Warning))
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.WarningsSummary(ScriptInfo, Warnings))
    sb.BlockEnd()
  End If

  ' 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, ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
  sb.BlockEnd()

  ' Security
  If finBL.Settings.AddOns.SecurityRegister AndAlso mAccount.SecurityStmt.SecurityItems.Count <> 0 Then
    sb.BlockBegin("Security")
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.SecurityStmt_SecurityItems(ScriptInfo, mAccount.SecurityStmt, True, True, True, True, True, True, 0, False))
    sb.BlockEnd()
  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