' SummaryPage2_AccountApp_Status
Option Explicit On
Option Strict On

' #################################################################
' Account Application Status

' Version: 1.01 (14/05/2021)

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

' Constants

' Objects
Private mAccountApp As finAccountApp

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
    mAccountApp = finBL.CreateAccountApp()
    mAccountApp.Load(CStr(source))

    ' Check not filtered out
    If finBL.CurrentUserInformation.IsAccountAppFilteredOut(mAccountApp.AccountAppId) Then
      Throw New ApplicationException(finBL.Error.Message)
    End If
  Else
    mAccountApp = DirectCast(source, finAccountApp)
  End If

  ' Get Constants
  With ScriptInfo.Constants
  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 WorkflowIncompleteCount As Integer

  ' Assume Success
  Ok = True

  ' Initialise
  sb = finBL.CreateHtmlSummaryPage2StringBuilder()

  ' Initialise HTML
  With sb
    .Initialise(ScriptInfo)
    .HtmlHeaderBegin(String.Format("{0}: {1}", mAccountApp.AccountAppId, mAccountApp.Name), 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.AccountApp_StatusSummary(ScriptInfo, mAccountApp))
  sb.BlockEnd()

  ' Workflows
  If finBL.Settings.AddOns.Workflow Then
    mAccountApp.GetIncompleteWorkflowsCount(WorkflowIncompleteCount)
    sb.BlockBegin("Workflows", "", If(WorkflowIncompleteCount = 0, isefinSummaryPageBlockHeadingStyle.Normal, isefinSummaryPageBlockHeadingStyle.WarningLow))
    If WorkflowIncompleteCount = 0 Then
      sb.AppendLine("{{info|No current Workflows.}}")
    Else
      sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.AccountApp_Workflows(ScriptInfo, mAccountApp, False, True, False, , ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
    End If
    sb.BlockEnd()
  End If

  ' End Column 1
  sb.ColumnEnd()

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

  ' Monitoring
  If finBL.Settings.MonitorCategoriesUsed Then
    sb.BlockBegin("Monitoring", "", If(mAccountApp.MonitorCategoryAPk = 0 AndAlso mAccountApp.MonitorCategoryBPk = 0 AndAlso mAccountApp.MonitorCategoryCPk = 0, isefinSummaryPageBlockHeadingStyle.Normal, isefinSummaryPageBlockHeadingStyle.Warning))
    sb.SummaryTablesAppend(finBL.SummaryPageStandardBlocks.AccountApp_Monitoring(ScriptInfo, mAccountApp, False, ScriptInfo.FormRecordMode = iseFormRecordMode.Loaded))
    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