' SummaryPage2_WorkflowTypeItem_WorkflowTypeItemSummary
Option Explicit On
Option Strict On

' #################################################################
' Workflow Type Item Details

' Add the following text to KB articles related to this script:
' Note: This summary page is not currently accessible for customisation.
'
' Version: 2.22 (14/08/2023)

' Usage: Workflow Types form
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    2.20  22/04/2021  ISS                Updated
'    2.21  01/05/2023  ISS      J030842   'Allocate to User' can now clear an allocation
'    2.22  14/08/2023  ISS      J030450   Remove warning about no outcome for HTML Widget items
' #################################################################

' Constants

' Objects
Private mWorkflowTypeItem As finWorkflowTypeItem

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
  mWorkflowTypeItem = DirectCast(source, finWorkflowTypeItem)

  ' 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 Include As Boolean
  Dim sb As finHtmlSummaryPage2StringBuilder
  Dim strTemp As String
  Dim Success As Boolean  

  ' Assume Success
  Success = 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
  sb.BlockBegin("Summary", "", isefinSummaryPageBlockHeadingStyle.Main, False)
  sb.SummaryTablesAppend(WorkflowTypeItem_Summary())
  sb.BlockEnd()

  ' End Column 1
  sb.ColumnEnd()

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

  ' Outcomes
  Select Case mWorkflowTypeItem.ItemType
    Case isefinWorkflowItemType.DecisionCard, isefinWorkflowItemType.BankAccountEnquiryReview, isefinWorkflowItemType.HtmlWidget, isefinWorkflowItemType.HtmlWidgetScript, isefinWorkflowItemType.ItemGroup, isefinWorkflowItemType.Question, isefinWorkflowItemType.Test
      Include = True
    Case isefinWorkflowItemType.PageSet
      ' Page Sets can optionally define Outcomes
      Include = (mWorkflowTypeItem.OutcomeItems.Count <> 0)
  End Select
  If Include Then
    sb.BlockBegin("Outcomes")
    sb.SummaryTablesAppend(WorkflowTypeItem_Outcomes())
    sb.BlockEnd()
  End If

  ' Actions
  Select Case mWorkflowTypeItem.ItemType
    Case isefinWorkflowItemType.DecisionCard, isefinWorkflowItemType.BankAccountEnquiryReview, isefinWorkflowItemType.ItemGroup, isefinWorkflowItemType.Question, isefinWorkflowItemType.Test
      strTemp = "for 'Success' outcomes"
    Case Else
      strTemp = ""
  End Select
  sb.BlockBegin("Actions", strTemp)
  sb.SummaryTablesAppend(WorkflowTypeItem_Actions())
  sb.BlockEnd()

  ' End Column 2
  sb.ColumnEnd()

  ' End Section
  sb.SectionColumnsEnd()

  ' Finalise HTML
  sb.HtmlFinalise()

  ' Resolve Templates
  html = sb.ToString(True)

  Return Success

End Function

Private Function WorkflowTypeItem_Actions() As ISSummaryTables

  Dim SummaryTableMain As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTableMain = finBL.CreateSummaryTable()
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  With SummaryTableMain
    ' Initialise
    .TableClass = iseSummaryTableClass.Information
    .Caption = ""
    .Columns.AddText(16)
    .Columns.AddText()

    With .Rows
      ' Flag Colour
      If mWorkflowTypeItem.FlagColourUpdate Then
        .AddSectionHeading2("Update Flag Colour")

        If Len(mWorkflowTypeItem.FlagColour) = 0 Then
          .AddCaptionText("Flag Colour:", "Clear Flag")
        Else
          .AddCaptionText("Flag Colour:", "{{icon|Flag[" & mWorkflowTypeItem.FlagColour & "]|" & mWorkflowTypeItem.FlagColour & "}}")
        End If
      End If

      ' Monitor Categories
      If mWorkflowTypeItem.MonitorCategoryAUpdate OrElse mWorkflowTypeItem.MonitorCategoryBUpdate OrElse mWorkflowTypeItem.MonitorCategoryCUpdate Then
        .AddSectionHeading2("Update Monitor Categories")

        If mWorkflowTypeItem.MonitorCategoryAUpdate Then
          If mWorkflowTypeItem.MonitorCategoryAPk = 0 Then
            .AddCaptionWiki(String.Format("{0}:", finBL.Settings.MonitorCategoryADescriptionResolved), "--(Clear)--")
          Else
            .AddCaptionCodeDescription(String.Format("{0}:", finBL.Settings.MonitorCategoryADescriptionResolved), mWorkflowTypeItem.MonitorCategoryAPk, finBL.MonitorCategories)
          End If
        End If
        If mWorkflowTypeItem.MonitorCategoryBUpdate Then
          If mWorkflowTypeItem.MonitorCategoryBPk = 0 Then
            .AddCaptionWiki(String.Format("{0}:", finBL.Settings.MonitorCategoryBDescriptionResolved), "--(Clear)--")
          Else
            .AddCaptionCodeDescription(String.Format("{0}:", finBL.Settings.MonitorCategoryBDescriptionResolved), mWorkflowTypeItem.MonitorCategoryBPk, finBL.MonitorCategories)
          End If
        End If
        If mWorkflowTypeItem.MonitorCategoryCUpdate Then
          If mWorkflowTypeItem.MonitorCategoryCPk = 0 Then
            .AddCaptionWiki(String.Format("{0}:", finBL.Settings.MonitorCategoryCDescriptionResolved), "--(Clear)--")
          Else
            .AddCaptionCodeDescription(String.Format("{0}:", finBL.Settings.MonitorCategoryCDescriptionResolved), mWorkflowTypeItem.MonitorCategoryCPk, finBL.MonitorCategories)
          End If
        End If
      End If

      ' Account Application
      If mWorkflowTypeItem.AccountAppStatusSubUpdate Then
        .AddSectionHeading2("Update Account Application")

        If mWorkflowTypeItem.AccountAppStatusSubUpdate Then
          If Len(mWorkflowTypeItem.AccountAppStatusSub) = 0 Then
            .AddCaptionWiki("Sub-Status:", "--(Clear)--")
          Else
            .AddCaptionText("Sub-Status:", mWorkflowTypeItem.AccountAppStatusSub)
          End If
        End If
      End If
    End With

    ' Warnings
    If .Rows.Count = 0 Then
      Warnings &= "{{info|No actions will be taken upon completing this item.}}"
    End If
    .TextAfter = Warnings
  End With

  ' Add Summary Tables
  SummaryTables.Add("Main", SummaryTableMain)

  Return SummaryTables

End Function

Private Function WorkflowTypeItem_Outcomes() As ISSummaryTables

  Dim CountActionNone As Integer
  Dim CountCloseWorkflow As Integer
  Dim ShowAction As Boolean
  Dim ShowDescription As Boolean
  Dim ShowHidden As Boolean
  Dim ShowSuccess As Boolean
  Dim SummaryTableMain As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String
  Dim WorkflowItemOutcomeItem As finWorkflowItemOutcomeItem

  ' Initialise
  SummaryTableMain = finBL.CreateSummaryTable()
  SummaryTables = finBL.CreateSummaryTables()

  ' Determine Columns to include
  For Each WorkflowItemOutcomeItem In mWorkflowTypeItem.OutcomeItems
    With WorkflowItemOutcomeItem
      If .Action <> isefinWorkflowItemOutcomeAction.None Then
        ShowAction = True
      End If
      If Len(.OutcomeDescription) <> 0 Then
        ShowDescription = True
      End If
      If .Hidden Then ShowHidden = True
      If .Success Then ShowSuccess = True
    End With
  Next

  ' Main
  With SummaryTableMain
    If mWorkflowTypeItem.OutcomeItems.Count = 0 Then
      Warnings &= "{{warning|No outcomes defined.}}"
    Else
      ' Initialise
      .TableClass = iseSummaryTableClass.TabularData
      .AutoStripe = True
      .Caption = ""

      ' Columns
      With .Columns
        .AddText("Outcome")
        If ShowDescription Then .AddText("Description")
        If ShowSuccess Then .AddText("Success", 1)
        If ShowHidden Then .AddText("Hidden", 1)
        If ShowAction Then .AddText("Action")
      End With

      For Each WorkflowItemOutcomeItem In mWorkflowTypeItem.OutcomeItems
        With .Rows.Add().Cells
          .AddText(WorkflowItemOutcomeItem.Outcome)
          If ShowDescription Then .AddText(WorkflowItemOutcomeItem.OutcomeDescription)
          If ShowSuccess Then .AddTick(WorkflowItemOutcomeItem.Success, False, True)
          If ShowHidden Then .AddTick(WorkflowItemOutcomeItem.Hidden, False, True)
          If ShowAction Then .AddWiki(WorkflowItemOutcomeItem.ActionDescription(True))
        End With

        ' Statistics used for Warnings
        Select Case WorkflowItemOutcomeItem.Action
          Case isefinWorkflowItemOutcomeAction.None
            CountActionNone += 1
          Case isefinWorkflowItemOutcomeAction.CancelWorkflow, isefinWorkflowItemOutcomeAction.CloseWorkflow
            CountCloseWorkflow += 1
        End Select
      Next
    End If

    ' Warnings
    If mWorkflowTypeItem.OutcomeItems.Count <> 0 Then
      Select Case mWorkflowTypeItem.ItemType
        Case isefinWorkflowItemType.BankAccountEnquiryReview
          Warnings &= "{{info|Depending on the outcome of the Decision Card or the User selection, **Pass**, **Fail** or **Refer** outcomes will be used.}}"

        Case isefinWorkflowItemType.DecisionCard
          Warnings &= "{{info|Depending on the outcome of the Decision Card, **Pass**, **Fail** or **Refer** outcomes will be used.}}"

        Case isefinWorkflowItemType.Test
          Warnings &= "{{info|If the test conditions pass then outcome **True** will be used, if they fail, outcome **False** will be used.}}"
      End Select
      
      Select Case mWorkflowTypeItem.ItemType
        Case isefinWorkflowItemType.HtmlWidget, isefinWorkflowItemType.HtmlWidgetScript
          ' It is perfectly valid for an HTML Widget to have no outcome action
          
        Case Else
          If CountActionNone = mWorkflowTypeItem.OutcomeItems.Count Then
            Warnings &= "{{warning|No outcomes perform an action.}}"
          ElseIf CountCloseWorkflow + CountActionNone = mWorkflowTypeItem.OutcomeItems.Count AndAlso CountActionNone <> 0 Then
            Warnings &= "{{warning|No outcomes perform an action other than to close the Workflow.}}"
          End If
      End Select
    End If
    .TextAfter = Warnings
  End With

  ' Add Summary Tables
  SummaryTables.Add("Main", SummaryTableMain)

  Return SummaryTables

End Function

Private Function WorkflowTypeItem_Summary() As ISSummaryTables

  Dim DecisionCard As finDecisionCardRO
  Dim Document As finDocumentRO
  Dim i As Integer
  Dim strTemp As String
  Dim SummaryTableMain As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTableMain = finBL.CreateSummaryTable()
  SummaryTables = finBL.CreateSummaryTables()

  ' Main
  With SummaryTableMain
    ' Initialise
    .TableClass = iseSummaryTableClass.Information
    .Caption = ""
    .Columns.AddText(16).NoBreakChars = 20
    .Columns.AddText()

    With .Rows
      ' General
      .AddCaptionText("Description:", mWorkflowTypeItem.Description, iseSummaryTableCellClass.Highlight2)
      If Len(mWorkflowTypeItem.ItemId) <> 0 Then
        .AddCaptionText("Code:", mWorkflowTypeItem.ItemId)
      End If
      .AddCaptionText("Type:", mWorkflowTypeItem.ItemTypeText, iseSummaryTableCellClass.Highlight1)
      If mWorkflowTypeItem.Hidden Then
        .AddCaptionTick("Hidden:", mWorkflowTypeItem.Hidden)
      End If
      If mWorkflowTypeItem.HiddenWhenComplete Then
        .AddCaptionTick("Hidden Complete:", mWorkflowTypeItem.HiddenWhenComplete)
      End If
      .AddCaptionTick("Allow N/A:", mWorkflowTypeItem.AllowNotApplicable)
      Select Case mWorkflowTypeItem.ItemType
        Case isefinWorkflowItemType.CheckListItem, isefinWorkflowItemType.Review
        Case isefinWorkflowItemType.ItemGroup, isefinWorkflowItemType.Question
          If mWorkflowTypeItem.Automatic Then
            .AddCaptionWiki("Automatic:", "{{tick}} --use 'BeforeItemAction' event to specify outcome--")
          End If

        Case Else
          If mWorkflowTypeItem.Automatic Then
            .AddCaptionWiki("Automatic:", "{{tick}} --no user intervention required--")
          End If
      End Select

      ' Repeat
      Select Case mWorkflowTypeItem.WorkflowType.TargetObjectType
        Case isefinWorkflowTargetObjectType.Account
          ' -------
          ' Account
          ' -------
          If mWorkflowTypeItem.GenerateItemPerClient Then
            .AddSectionHeading2("Repeat For Each Account Client")
            .AddCaptionText("Account Roles:", mWorkflowTypeItem.GenerateItemPerClientAccountRoles)
            .AddCaptionText("Signatory:", mWorkflowTypeItem.GenerateItemPerClientAccountSignatoryText)
            .AddCaptionText("Send Mail:", mWorkflowTypeItem.GenerateItemPerClientSendDocumentsText)
            If finBL.Settings.AddOns.SecurityRegister Then
              .AddCaptionText("Security Debtor:", mWorkflowTypeItem.GenerateItemPerClientSecurityPartyText)
            End If
            .AddCaptionTick("Group Consecutive:", mWorkflowTypeItem.GenerateItemPerClientGroupConsecutive, True)
          End If

        Case isefinWorkflowTargetObjectType.AccountApp
          ' -------------------
          ' Account Application
          ' -------------------
          If mWorkflowTypeItem.GenerateItemPerClient Then
            .AddSectionHeading2("Repeat For Each Applicant")
            .AddCaptionText("Account Roles:", mWorkflowTypeItem.GenerateItemPerClientAccountRoles)
            .AddCaptionText("Applicant Used:", mWorkflowTypeItem.GenerateItemPerClientApplicantUsedText)
            .AddCaptionTick("Group Consecutive:", mWorkflowTypeItem.GenerateItemPerClientGroupConsecutive, True)
          End If
      End Select

      ' Notes Entry
      Select Case mWorkflowTypeItem.ItemType
        Case isefinWorkflowItemType.BankAccountEnquiry, isefinWorkflowItemType.BankAccountEnquiryReview,
             isefinWorkflowItemType.CreditEnquiry,
             isefinWorkflowItemType.DecisionCard,
             isefinWorkflowItemType.Log,
             isefinWorkflowItemType.OutgoingCommunication,
             isefinWorkflowItemType.PaymentArrangement,
             isefinWorkflowItemType.SecurityEnquiry, isefinWorkflowItemType.SecurityRegisterSearch,
             isefinWorkflowItemType.WebMail
            
        Case Else
          If mWorkflowTypeItem.StatusNotesEntryMethod <> isefinWorkflowItemStatusNotesEntryMethod.None Then
            .AddSectionHeading2("Action Notes")
            .AddCaptionText("Notes Entry:", mWorkflowTypeItem.StatusNotesEntryMethodText)
          End If
      End Select

      ' Type-Specific
      Select Case mWorkflowTypeItem.ItemType
        Case isefinWorkflowItemType.AllocateToUser
          ' Allocate To User
          .AddSectionHeading2("Allocate To User")
          If mWorkflowTypeItem.AllocateToSupervisor Then
            .AddCaptionText("Allocate To:", "Current Workflow User's Supervisor")
          ElseIf mWorkflowTypeItem.UserPk = 0 Then
            .AddCaptionText("Allocate To:", "Allocated User will be cleared")
          Else
            .AddCaptionCodeDescription("Allocate To:", mWorkflowTypeItem.UserPk, finBL.Users)
          End If
          If Len(mWorkflowTypeItem.Period) <> 0 Then
            .AddCaptionText("Recall Period:", mWorkflowTypeItem.PeriodDescription)
          End If

        Case isefinWorkflowItemType.BankAccountEnquiry
          ' Bank Account Enquiry
          .AddSectionHeading2("Bank Account Enquiry")
          .AddCaptionText("Service:", mWorkflowTypeItem.ServiceId)
          .AddCaptionText("Document:", mWorkflowTypeItem.BankAccountEnquiryDocumentTypeText)

        Case isefinWorkflowItemType.BankAccountEnquiryReview
          ' Bank Account Enquiry Review
          .AddSectionHeading2("Bank Account Enquiry Review")
          .AddCaptionCodeDescription("Decision Card:", mWorkflowTypeItem.DecisionCardPk, finBL.DecisionCards)

          If finBL.DecisionCards.ExistsPk(mWorkflowTypeItem.DecisionCardPk) Then
            DecisionCard = finBL.DecisionCards.ItemByPk(mWorkflowTypeItem.DecisionCardPk)
            Select Case mWorkflowTypeItem.WorkflowType.TargetObjectType
              Case isefinWorkflowTargetObjectType.Account
                If DecisionCard.DecisionSource = isefinDecisionCardSource.Client Then
                  If mWorkflowTypeItem.GenerateItemPerClient Then
                    .AddCaptionWiki("Decision On:", "**Each Account Client** --(based on the repeat section)--")
                  Else
                    .AddCaptionText("Decision On:", "Main Account Client")
                  End If
                End If

              Case Else
                finBL.DebugPrint("Workflow Type Item, Decision Card: Unknown Target Object Type.")
            End Select
          End If

          .AddCaptionTick("Prevent Action if no Report:", mWorkflowTypeItem.BankAccountEnquiryReviewPreventActionIfNotAvailable)

        Case isefinWorkflowItemType.CreditEnquiry
          ' Credit Enquiry
          .AddSectionHeading2("Credit Enquiry")
          .AddCaptionText("Service:", mWorkflowTypeItem.ServiceId)
          If mWorkflowTypeItem.ServiceAlwaysUseIndividual Then
            .AddCheckBox("Always perform an 'Individual' Enquiry for 'Organisation' type Clients?", mWorkflowTypeItem.ServiceAlwaysUseIndividual)
          End If

        Case isefinWorkflowItemType.DecisionCard
          ' Decision Card
          .AddSectionHeading2("Decision Card")
          .AddCaptionCodeDescription("Decision Card:", mWorkflowTypeItem.DecisionCardPk, finBL.DecisionCards)

          If finBL.DecisionCards.ExistsPk(mWorkflowTypeItem.DecisionCardPk) Then
            DecisionCard = finBL.DecisionCards.ItemByPk(mWorkflowTypeItem.DecisionCardPk)
            Select Case mWorkflowTypeItem.WorkflowType.TargetObjectType
              Case isefinWorkflowTargetObjectType.Account
                If DecisionCard.DecisionSource = isefinDecisionCardSource.Account Then
                  .AddCaptionText("Decision On:", "Account")
                Else
                  If mWorkflowTypeItem.GenerateItemPerClient Then
                    .AddCaptionWiki("Decision On:", "**Each Account Client** --(based on the repeat section)--")
                  Else
                    .AddCaptionText("Decision On:", "Main Account Client")
                  End If
                End If

              Case Else
                finBL.DebugPrint("Workflow Type Item, Decision Card: Unknown Target Object Type.")
            End Select
          End If

        Case isefinWorkflowItemType.Document
          ' Document
          .AddSectionHeading2("Document")
          .AddCaptionCodeDescription("Document:", mWorkflowTypeItem.DocumentPk, finBL.Documents)
          If mWorkflowTypeItem.DocumentPublishImmediately Then
            .AddCaptionWiki("Publish Immediately:", "{{tick}} --(when actioned directly by a User)--")
          Else
            .AddCaptionWiki("Publish Immediately:", "{{cross}} --(will be manually published, e.g., via Documents Publish wizard)--")
          End If
          .AddCheckBox("Customise Document's Parameters?", mWorkflowTypeItem.ItemParametersCustomise)

          If mWorkflowTypeItem.GenerateItemPerClient Then
            ' Not Applicable
          ElseIf finBL.Documents.ExistsPk(mWorkflowTypeItem.DocumentPk) Then
            Document = finBL.Documents.ItemByPk(mWorkflowTypeItem.DocumentPk)
            Select Case mWorkflowTypeItem.WorkflowType.TargetObjectType
              Case isefinWorkflowTargetObjectType.Account, isefinWorkflowTargetObjectType.AccountApp
                ' -------------------------------
                ' Account and Account Application
                ' -------------------------------
                Select Case Document.FileType
                  Case iseDocumentFileType.Email, iseDocumentFileType.Sms
                    If mWorkflowTypeItem.WorkflowType.TargetObjectType = isefinWorkflowTargetObjectType.Account Then
                      .AddCaptionText("Required Clients:", mWorkflowTypeItem.DocumentClientsText)
                    Else
                      .AddCaptionText("Required Applicants:", mWorkflowTypeItem.DocumentClientsText)
                    End If
                End Select

                If finBL.Settings.AddOns.Branch OrElse finBL.Settings.AddOns.ExternalParty Then
                  strTemp = ""
                  If mWorkflowTypeItem.DocumentSendToBranch Then
                    If Len(strTemp) <> 0 Then strTemp &= ", "
                    strTemp &= "**Branch**"
                  End If
                  If finBL.Settings.AddOns.ExternalParty Then
                    If mWorkflowTypeItem.DocumentSendToBroker Then
                      If Len(strTemp) <> 0 Then strTemp &= ", "
                      strTemp &= "**Broker**"
                    End If
                    If mWorkflowTypeItem.WorkflowType.Version <> isefinWorkflowTypeVersion.Version1 AndAlso mWorkflowTypeItem.DocumentSendToBrokerEmployee Then
                      If Len(strTemp) <> 0 Then strTemp &= ", "
                      strTemp &= "**Broker Employee**"
                    End If
                    If mWorkflowTypeItem.DocumentSendToDealer Then
                      If Len(strTemp) <> 0 Then strTemp &= ", "
                      strTemp &= "**Dealer**"
                    End If
                    If mWorkflowTypeItem.WorkflowType.Version <> isefinWorkflowTypeVersion.Version1 AndAlso mWorkflowTypeItem.DocumentSendToDealerEmployee Then
                      If Len(strTemp) <> 0 Then strTemp &= ", "
                      strTemp &= "**Dealer Employee**"
                    End If
                  End If
                  If Len(strTemp) <> 0 Then
                    .AddCaptionWiki("Send Also To:", strTemp)
                  End If
                End If

                Select Case Document.FileType
                  Case iseDocumentFileType.Email
                    ' Email
                    .AddSectionHeading2("Email")
                    .AddCaptionText("Target:", mWorkflowTypeItem.EmailMessageTargetText)
                    .AddCaptionTick("HTML Format:", mWorkflowTypeItem.EmailHtml, True)

                  Case iseDocumentFileType.SMS
                    ' SMS
                    If Len(mWorkflowTypeItem.TemplateMessage) <> 0 Then
                      .AddSectionHeading2("SMS")
                      .AddText(mWorkflowTypeItem.TemplateMessage)
                    End If
                End Select
            End Select
          End If

          If mWorkflowTypeItem.ItemParametersCustomise Then
            .AddSectionHeading2("Document Parameters")
            .AddText(finBL.Utilities.KeyValueListToText(mWorkflowTypeItem.ItemParameters, False, False))
          End If
          
        Case isefinWorkflowItemType.HtmlWidget
          ' HTML Widget
          .AddSectionHeading2("HTML Widget")
          .AddCaptionText ("HTML Widget:", mWorkflowTypeItem.HtmlWidgetId)
          .AddCheckBox("Customise HTML Widget's Parameters?", mWorkflowTypeItem.HtmlWidgetCustomise)

          If mWorkflowTypeItem.HtmlWidgetCustomise Then
            .AddSectionHeading2("HTML Widget Parameters")
            .AddText(finBL.Utilities.KeyValueListToText(mWorkflowTypeItem.HtmlWidgetParameters, False, False))
          End If

        Case isefinWorkflowItemType.HtmlWidgetScript
          ' HTML Widget Script
          .AddSectionHeading2("HTML Widget")
          .AddCaptionCodeDescription("Script:", mWorkflowTypeItem.HtmlWidgetScriptId, finBL.Scripts)
          .AddCheckBox("Customise HTML Widget's Parameters?", mWorkflowTypeItem.HtmlWidgetCustomise)

          If mWorkflowTypeItem.HtmlWidgetCustomise Then
            .AddSectionHeading2("HTML Widget Parameters")
            .AddText(finBL.Utilities.KeyValueListToText(mWorkflowTypeItem.HtmlWidgetParameters, False, False))
          End If

        Case isefinWorkflowItemType.ItemGroup
          ' Item Group
          .AddSectionHeading2("Item Group")
          .AddCaptionTick("Complete Items In Order:", mWorkflowTypeItem.ItemGroupSequential, True)
          If mWorkflowTypeItem.ItemGroupSequential Then
            .AddCaptionTick("N/A In Order:", mWorkflowTypeItem.ItemGroupNaSequential, True)
          End If
          If mWorkflowTypeItem.WorkflowType.Version <> isefinWorkflowTypeVersion.Version1 Then
            .AddCaptionTick("Items Clear Recall Date:", mWorkflowTypeItem.GroupItemsClearRecallDate, True)
          End If

        Case isefinWorkflowItemType.Log
          ' Log
          .AddSectionHeading2("Log")

        Case isefinWorkflowItemType.PageSet
          ' Page Set
          .AddSectionHeading2("Page Set")
          .AddCaptionCodeDescription("Page Set:", mWorkflowTypeItem.PageSetPk, finBL.PageSets)

        Case isefinWorkflowItemType.Review
          ' Review
          .AddSectionHeading2("Review")
          .AddCaptionText("Period:", mWorkflowTypeItem.PeriodDescription)
          If finBL.Utilities.DateCycleGetCycle(mWorkflowTypeItem.Period) = isefinDateCycle.Day Then
            .AddCaptionTick("Working Days:", mWorkflowTypeItem.PeriodWorkingDays, True)
            If mWorkflowTypeItem.PeriodWorkingDays Then
              .AddCaptionText("Calendar:", mWorkflowTypeItem.PeriodWorkingDaysCalendarTypeText)
            End If
          End If
          .AddCaptionText("Wait From:", mWorkflowTypeItem.WaitPeriodBaseText)


        Case isefinWorkflowItemType.SecurityEnquiry
          ' Security Enquiry
          .AddSectionHeading2("Security Enquiry")
          .AddCaptionText("Service:", mWorkflowTypeItem.ServiceId)

        Case isefinWorkflowItemType.Test
          ' Test
          .AddSectionHeading2("Test")
          strTemp = mWorkflowTypeItem.TestDescription(False)
          .AddText(strTemp)
          If Len(strTemp) = 0 Then
            Warnings &= "{{warning|No Test conditions defined.}}"
          End If

        Case isefinWorkflowItemType.Wait
          ' Wait
          .AddSectionHeading2("Wait")
          .AddCaptionText("Period:", mWorkflowTypeItem.PeriodDescription)
          If finBL.Utilities.DateCycleGetCycle(mWorkflowTypeItem.Period) = isefinDateCycle.Day Then
            .AddCaptionTick("Working Days:", mWorkflowTypeItem.PeriodWorkingDays, True)
            If mWorkflowTypeItem.PeriodWorkingDays Then
              .AddCaptionText("Calendar:", mWorkflowTypeItem.PeriodWorkingDaysCalendarTypeText)
            End If
          End If
          .AddCaptionText("Wait From:", mWorkflowTypeItem.WaitPeriodBaseText)
          
        Case isefinWorkflowItemType.WebMail
          ' Web Mail
          .AddSectionHeading2("Send Web Mail")
      End Select

      ' Log-Specific
      Select Case mWorkflowTypeItem.ItemType
        Case isefinWorkflowItemType.Document, isefinWorkflowItemType.Log, isefinWorkflowItemType.OutgoingCommunication, isefinWorkflowItemType.WebMail
          If Len(mWorkflowTypeItem.LogSubject) <> 0 Then .AddCaptionText("Subject:", mWorkflowTypeItem.LogSubject)
          If Len(mWorkflowTypeItem.LogNotes) <> 0 Then .AddCaptionText("Notes:", mWorkflowTypeItem.LogNotes)
          If mWorkflowTypeItem.LogSeverityPk <> 0 Then
            .AddCaptionCodeDescription("Log Severity:", mWorkflowTypeItem.LogSeverityPk, finBL.LogSeverities)
          End If
          If Len(mWorkflowTypeItem.LogActionPeriod) <> 0 Then .AddCaptionText("Log Action Period:", mWorkflowTypeItem.LogActionPeriodDescription)
          If mWorkflowTypeItem.LogDelegateAction <> isefinWorkflowItemLogDelegateAction.None Then
            .AddCaptionText("Delegate To:", mWorkflowTypeItem.LogDelegateActionText)
            Select Case mWorkflowTypeItem.LogDelegateAction
              Case isefinWorkflowItemLogDelegateAction.Role
                .AddCaptionCodeDescription("Role:", mWorkflowTypeItem.LogDelegateToRolePk, finBL.Roles)
              Case isefinWorkflowItemLogDelegateAction.User
                .AddCaptionCodeDescription("User:", mWorkflowTypeItem.LogDelegateToUserPk, finBL.Users)
            End Select
          End If
      End Select

      ' Permissions
      If Len(mWorkflowTypeItem.PermissionKeyAction) <> 0 OrElse Len(mWorkflowTypeItem.PermissionKeyReset) <> 0 Then
        .AddSectionHeading2("Permission")
        If Len(mWorkflowTypeItem.PermissionKeyAction) <> 0 Then
          .AddCaptionText("Action:", mWorkflowTypeItem.PermissionKeyAction)
        End If
        If Len(mWorkflowTypeItem.PermissionKeyReset) <> 0 Then
          .AddCaptionText("Reset:", mWorkflowTypeItem.PermissionKeyReset)
        End If
        If Len(mWorkflowTypeItem.PermissionKeySkip) <> 0 Then
          .AddCaptionText("Skip:", mWorkflowTypeItem.PermissionKeySkip)
        End If
      End If
    End With

    ' Warnings
    i = mWorkflowTypeItem.Parent.IndexOf(mWorkflowTypeItem)
    Select Case mWorkflowTypeItem.ItemType
      Case isefinWorkflowItemType.CheckListItem
        If mWorkflowTypeItem.GroupWithPrevious OrElse (i < mWorkflowTypeItem.Parent.Count - 1 AndAlso mWorkflowTypeItem.Parent.Item(i + 1).GroupWithPrevious) Then
          Warnings &= "{{info|Checking this will skip all other grouped items.}}"
        End If
      Case Else
        If mWorkflowTypeItem.GroupWithPrevious AndAlso i <> 0 Then
          Warnings &= "{{info|Will only occur if the previous item could not be actioned.}}"
        End If
    End Select
    If Not mWorkflowTypeItem.IsValid(strTemp) Then
      Warnings &= "{{warning|" & strTemp & "}}"
    End If
    .TextAfter = Warnings
  End With

  ' Add Summary Tables
  SummaryTables.Add("Main", SummaryTableMain)

  Return SummaryTables

End Function