<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2023-09-26T02:34:38.0000000">
    <CreatedUserId>ADMIN</CreatedUserId>
    <CreatedUtcDate>2022-09-29T01:23:36.6700000</CreatedUtcDate>
    <UpdatedUserId>ADMIN</UpdatedUserId>
    <UpdatedUtcDate>2023-09-26T02:34:22.0500000</UpdatedUtcDate>
    <ScriptId>DAP</ScriptId>
    <Description>Disbursement Account Payments</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Bookmarks />
    <Category />
    <Code>' HtmlWidget_AccountDisbursementPayments
Option Explicit On
Option Strict On

' #################################################################
' Disbursement Account Payment wizard
'
' Version: 1.04 (26/09/2023)
'
' Usage: System-defined HTML Widget
'
' NOTE: Uses Web Services Background Processes
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  12/11/2021  ISS      J024136   Created
'    1.01  08/12/2021  ISS      J027840   Spelling Correction
'    1.02  29/09/2022  ISS      J029737   Implemented widget.UI.BuildBackgroundProcessProgress
'    1.03  18/08/2023  ISS      J031825   Added support for AccountId Parameter
'    1.04  26/09/2023  ISS      J032081   Implemented 'finBL.HtmlWidgetUtilities.HasPermissionToViewFormKey(FORM_KEY)' validation functionality
' #################################################################

' Constants
Private Const FORM_KEY As String = "AccountDisbursementPayments"

' Common Parameters
Private mAccountId As String

' Objects
Private mCombinedParameters As ISKeyValueList
Private mParameters As ISKeyValueList
Private mStartupParameters As ISKeyValueList

Public Function Main(eventId As String, parametersJson As String, startUpParametersJson As String, hostingContext As isefinHtmlWidgetHostingContext, requestInfo As finScriptRequestInfo, ByRef returnValue As String) As Boolean

  ' Assume Success
  Main = True

  ' Get Parameters
  mParameters = finBL.CreateKeyValueList()
  mParameters.FromSimpleJsonString(parametersJson)
  mStartupParameters = finBL.CreateKeyValueList()
  mStartupParameters.FromSimpleJsonString(startUpParametersJson)

  ' Get Combined Parameters (Startup Parameters updated with event Parameters)
  mCombinedParameters = mStartupParameters.Clone()
  mCombinedParameters.UpdateFromKeyValueList(mParameters, True)

  ' Get Common Parameters
  With mCombinedParameters
    mAccountId = .GetString("AccountId")
  End With
  
  ' Handle Events
  Select Case eventId
    Case ""
      ' Main event, i.e., return initial HTML content (excluding html and body tags)
      returnValue = ScriptInfo.TemplateText

    Case "CancelBackgroundProcess"
      ' Cancel a Process
      Main = CancelBackgroundProcess(returnValue)

    Case "Finish"
      ' Finish wizard
      Main = Finish(parametersJson, requestInfo, returnValue)

    Case "GetCurrentProcesses"
      ' Get Current Processes
      Main = GetCurrentProcesses(returnValue)

    Case "GetBackgroundProcessStatus"
      ' Get Background Process Status
      Main = GetBackgroundProcessStatus(returnValue)

    Case "GetUpdateItemPreview"
      ' Get the HTML Summary Page for the active row on the grid
      returnValue = GetUpdateItemPreview()

    Case "GetInitialisationInfo"
      ' Get Initialisation Information required for this wizard
      Main = GetInitialisationInfo(returnValue)

    Case "GetUpdateItems"
      ' Get Update Items
      Main = GetUpdateItems(parametersJson, returnValue)

    Case Else
      finBL.Error.ErrorBeginFormat("Unhandled event '{0}'.", eventId)
      Main = False
  End Select

End Function

''' &lt;summary&gt;
'''  Request that a Background Process is Cancelled.
''' &lt;/summary&gt;
Private Function CancelBackgroundProcess(ByRef returnValue As String) As Boolean

  Dim ProcessId As String
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Get Parameters
  ProcessId = mCombinedParameters.GetString("ProcessId")

  ' Request Cancel
  Success = finBL.HtmlWidgetUtilities.CancelBackgroundProcess(processId)

  Return Success

End Function

''' &lt;summary&gt;
'''  Create a finAccountDisbursementPayments object.
''' &lt;/summary&gt;
Private Function CreateAccountDisbursementPayments(parameters As WizardFinishParameters,
                                                   ByRef accountDisbursementPayments As finAccountDisbursementPayments) As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise
  accountDisbursementPayments = finBL.CreateAccountDisbursementPayments()

  ' Update
  With accountDisbursementPayments
    ' Update
    If Success AndAlso parameters IsNot Nothing Then
      ' General
      .PaymentDate = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(parameters.PaymentDate)
      .IncludeTransactionsToDate = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(parameters.IncludeTransactionsToDate)

      ' Ranges
      .RangeAccountManagers = parameters.RangeAccountManagers
      .RangeAccounts = parameters.RangeAccounts
      .RangeAccountTypes = parameters.RangeAccountTypes
      .RangeBranches = parameters.RangeBranches
      .RangeDepartments = parameters.RangeDepartments
      .RangeEntities = parameters.RangeEntities
      .RangeProductTypes = parameters.RangeProductTypes
      .RangeSourceAccounts = parameters.RangeSourceAccounts
    End If
  End With

  Return Success

End Function

''' &lt;summary&gt;
'''  Finish, i.e., Queue Background Process.
''' &lt;/summary&gt;
''' &lt;param name="parametersJson"&gt;
'''  A JSON formatted WizardFinishParameters object.
''' &lt;/param&gt;
Private Function Finish(parametersJson As String,
                        requestInfo As finScriptRequestInfo,
                        ByRef returnValue As String) As Boolean

  Dim AccountDisbursementPayment As finAccountDisbursementPayment
  Dim AccountDisbursementPayments As finAccountDisbursementPayments
  Dim ProcessId As String
  Dim Success As Boolean
  Dim WizardFinishParameters As WizardFinishParameters

  ' Assume Success
  Success = True

  ' Validate

  ' Parse Parameters
  Success = GetWizardFinishParameters(parametersJson, WizardFinishParameters)

  ' Get finAccountDisbursementPayments Object and refresh
  If Success Then
    If CreateAccountDisbursementPayments(WizardFinishParameters, AccountDisbursementPayments) Then
      Success = AccountDisbursementPayments.Refresh()
    Else
      Success = False
    End If
  End If

  ' Update Included Items
  If Success Then
    For Each AccountDisbursementPayment In AccountDisbursementPayments
      With AccountDisbursementPayment
        .Include = HasIdentifier(AccountDisbursementPayment, WizardFinishParameters)
      End With
    Next

    ' Validate
    If AccountDisbursementPayments.CountIncluded = 0 Then
      Success = False
      finBL.Error.ErrorBegin("You must select at least one Disbursement Account Payment to process.")
    ElseIf AccountDisbursementPayments.CountIncluded() &lt;&gt; WizardFinishParameters.SelectedItemIdentifierList.Count() Then
      Success = False
      finBL.Error.ErrorBegin("Record mismatch. The collection may have changed since it was originally loaded. Please refresh the results and try again.")
    End If
  End If

  ' Queue Background Process
  If Success Then
    Success = finBL.HtmlWidgetUtilities.QueueBackgroundProcess_AccountDisbursementPayments(AccountDisbursementPayments, ProcessId)
  End If

  ' Finalise
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(New WizardFinishDetails(ProcessId), returnValue)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Background Process Status.
''' &lt;/summary&gt;
Private Function GetBackgroundProcessStatus(ByRef returnValue As String) As Boolean

  Dim LastEventId As String
  Dim ProcessId As String
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Get Parameters
  With mCombinedParameters
    LastEventId = .GetString("LastEventId")
    ProcessId = .GetString("ProcessId")
  End With

  ' Get Background Processes Status including Events
  Success = finBL.HtmlWidgetUtilities.GetBackgroundProcessStatusIncludingEventsJson(processId, lastEventId, returnValue)

  Return Success

End Function

''' &lt;summary&gt;
'''  Get current and recent Background Processes that for this User (these  are also returned in GetInitialisationInfo).
''' &lt;/summary&gt;
Private Function GetCurrentProcesses(ByRef returnValue As String) As Boolean

  Dim ProcessStatuses As List(Of finHtmlWidgetUtilities.JsonProcessStatusInformation)
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Get current and recent Background Processes that for this User
  Success = finBL.HtmlWidgetUtilities.GetBackgroundProcessesJson_AccountDisbursementPayments(True, ProcessStatuses)

  ' Response
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(ProcessStatuses, returnValue)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get the HTML Summary Page for the active row on the grid.
''' &lt;/summary&gt;
Private Function GetUpdateItemPreview() As String

  Dim AccountDisbursementPayment As finAccountDisbursementPayment
  Dim AccountDisbursementPayments As finAccountDisbursementPayments
  Dim AccountId As String
  Dim Found As Boolean
  Dim Html As String
  Dim Identifier As String
  Dim ParametersJson As String
  Dim Success As Boolean
  Dim WizardFinishParameters As WizardFinishParameters

  ' Assume Success
  Success = True

  ' Get Parameters
  With mCombinedParameters
    AccountId = .GetString("AccountId")
    ParametersJson = .GetString("ParametersJson")
    Identifier = .GetString("Identifier")
  End With

  ' Get Finish Parameters
  Success = GetWizardFinishParameters(ParametersJson, WizardFinishParameters)

  ' Restrict Results to this Account
  If Success Then
    WizardFinishParameters.RangeAccounts = AccountId
    If CreateAccountDisbursementPayments(WizardFinishParameters, AccountDisbursementPayments) Then
      AccountDisbursementPayments.Refresh()
    Else
      Success = False
    End If
  End If

  ' Get Summary
  If Success Then
    For Each AccountDisbursementPayment In AccountDisbursementPayments
      If StrComp(AccountDisbursementPayment.GetHtmlWidgetIdentifier(), Identifier) = 0 Then
        Found = True
        Html = finBL.SummaryPageFunctions.AccountDisbursementPaymentSummary(False, AccountDisbursementPayment, finBL.HtmlWidgetUtilities.CreateScriptContextData(ScriptInfo, FORM_KEY))
        Exit For
      End If
    Next
  End If

  ' Found?
  If Success AndAlso Not Found Then
    Html = finBL.GetHtmlErrorMessage("Failed to retrieve Disbursement Account Payment Summary.", "This may be due to the Disbursement Account Payment having already been processed.")
  End If

  ' Error
  If Not Success Then
    Html = finBL.GetHtmlErrorMessage(finBL.Error.Message(True, False, True))
  End If

  Return Html

End Function

''' &lt;summary&gt;
'''  Get Initialisation Information required for this wizard.
''' &lt;/summary&gt;
Private Function GetInitialisationInfo(ByRef returnValue As String) As Boolean

  Dim Account As finAccount
  Dim AccountDisbursementPayments As finAccountDisbursementPayments
  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim ProcessStatuses As List(Of finHtmlWidgetUtilities.JsonProcessStatusInformation)
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise  

  ' Validate
  Success = finBL.HtmlWidgetUtilities.HasPermissionToViewFormKey(FORM_KEY)

  ' Validate Account
  If Success AndAlso Len(mAccountId) &lt;&gt; 0 Then
    Account = finBL.CreateAccount()    
    If Account.Load(mAccountId) Then
      If Account.AccountClass &lt;&gt; isefinAccountClass.Disbursement Then
        Success = False
        finBL.Error.ErrorBegin("Account is not a Disbursement Account.")
      ElseIf Account.Status &lt;&gt; isefinAccountStatus.Open Then
        Success = False
        finBL.Error.ErrorBegin("Account is not 'Open'.")
      End If
    Else 
      Success = False
    End If
  End If
  
  ' Get finAccountDisbursementPayments Object
  If Success Then
    Success = CreateAccountDisbursementPayments(Nothing, AccountDisbursementPayments)
  End If

  ' Get Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' Record
      .AccountId = mAccountId
      .PaymentDate = finBL.HtmlWidgetUtilities.GetJsonUtcDateFromDatabaseDate(AccountDisbursementPayments.PaymentDate)
      .IncludeTransactionsToDate = finBL.HtmlWidgetUtilities.GetJsonUtcDateFromDatabaseDate(AccountDisbursementPayments.IncludeTransactionsToDate)

      ' Lists

      ' Configuration

      ' Advanced Sections
      .ShowBranches = mCombinedParameters.GetString("ShowBranches") : If Len(.ShowBranches) = 0 Then .ShowBranches = "Advanced"
      .ShowEntities = mCombinedParameters.GetString("ShowEntities") : If Len(.ShowEntities) = 0 Then .ShowEntities = "Advanced"
      .ShowAccountManagers = mCombinedParameters.GetString("ShowAccountManagers") : If Len(.ShowAccountManagers) = 0 Then .ShowAccountManagers = "Advanced"
      .ShowAccounts = mCombinedParameters.GetString("ShowAccounts") : If Len(.ShowAccounts) = 0 Then .ShowAccounts = "Advanced"
      .ShowAccountTypes = mCombinedParameters.GetString("ShowAccountTypes") : If Len(.ShowAccountTypes) = 0 Then .ShowAccountTypes = "Advanced"
      .ShowDepartments = mCombinedParameters.GetString("ShowDepartments") : If Len(.ShowDepartments) = 0 Then .ShowDepartments = "Advanced"
      .ShowProductTypes = mCombinedParameters.GetString("ShowProductTypes") : If Len(.ShowProductTypes) = 0 Then .ShowProductTypes = "Advanced"
      .ShowSourceAccounts = mCombinedParameters.GetString("ShowSourceAccounts") : If Len(.ShowSourceAccounts) = 0 Then .ShowSourceAccounts = "Advanced"

      ' Override advanced if an Account has been specified
      If Len(mAccountId) &lt;&gt; 0 Then
        .ShowBranches = "False"
        .ShowEntities = "False"
        .ShowAccountManagers = "False"
        .ShowAccounts = "True"
        .ShowAccountTypes = "False"
        .ShowDepartments = "False"
        .ShowProductTypes = "False"
        .ShowSourceAccounts = "False"
      End If
      
      ' Licence
      If Not finBL.Settings.AddOns.Branch Then .ShowBranches = "False"
      If Not finBL.Settings.AddOns.Entity Then .ShowEntities = "False"

      ' Has Advanced?
      .PageGeneralHasAdvanced = (.ShowEntities = "Advanced" OrElse .ShowBranches = "Advanced" OrElse .ShowAccountManagers = "Advanced" OrElse .ShowAccounts = "Advanced" OrElse .ShowAccountTypes = "Advanced" OrElse .ShowDepartments = "Advanced" OrElse .ShowProductTypes = "Advanced" OrElse .ShowSourceAccounts = "Advanced")

      ' Heading
      If (.ShowEntities = "Advanced" AndAlso .ShowBranches = "Advanced" AndAlso .ShowAccountManagers = "Advanced" AndAlso .ShowAccounts = "Advanced" AndAlso .ShowAccountTypes = "Advanced" AndAlso .ShowDepartments = "Advanced" AndAlso .ShowProductTypes = "Advanced" AndAlso .ShowSourceAccounts = "Advanced") Then
        ' All Advanced
        .ShowRangesHeading = "Advanced"
      Else If (.ShowEntities = "False" AndAlso .ShowBranches = "False" AndAlso .ShowAccountManagers = "False" AndAlso .ShowAccounts = "False" AndAlso .ShowAccountTypes = "False" AndAlso .ShowDepartments = "False" AndAlso .ShowProductTypes = "False" AndAlso .ShowSourceAccounts = "False") Then
        ' All Hidden
        .ShowRangesHeading = "False"
      Else If (.ShowEntities &lt;&gt; "True" AndAlso .ShowBranches &lt;&gt; "True" AndAlso .ShowAccountManagers &lt;&gt; "True" AndAlso .ShowAccounts &lt;&gt; "True" AndAlso .ShowAccountTypes &lt;&gt; "True" AndAlso .ShowDepartments &lt;&gt; "True" AndAlso .ShowProductTypes &lt;&gt; "True" AndAlso .ShowSourceAccounts &lt;&gt; "True") AndAlso (.ShowEntities = "Advanced" OrElse .ShowBranches = "Advanced" OrElse .ShowAccountManagers = "Advanced" OrElse .ShowAccounts = "Advanced" OrElse .ShowAccountTypes = "Advanced" OrElse .ShowDepartments = "Advanced" OrElse .ShowProductTypes = "Advanced" OrElse .ShowSourceAccounts = "Advanced") Then
        ' Some Advanced
        .ShowRangesHeading = "Advanced"
      Else
        ' Some always displayed
        .ShowRangesHeading = "True"
      End If

      ' Configuration
      .ReadOnly = finBL.Database.IsReadOnly

      ' Form Heading
      .FormHeading = ScriptInfo.ScriptCaption
      If Len(.FormHeading) = 0 Then .FormHeading = "Disbursement Account Payments"
    End With
  End If

  ' Get current and recent Background Processes that for this User
  If Success Then
    If finBL.HtmlWidgetUtilities.GetBackgroundProcessesJson_AccountDisbursementPayments(True, ProcessStatuses) Then
      FormInitialisationInfo.CurrentProcesses = ProcessStatuses
    Else
      Success = False
    End If
  End If

  ' Serialise
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(FormInitialisationInfo, returnValue)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Wizard Finish Parameters.
''' &lt;/summary&gt;
Private Function GetWizardFinishParameters(parametersJson As String,
                                           ByRef wizardFinishParameters As WizardFinishParameters) As Boolean

  Dim obj As Object
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise ByRef Parameters
  wizardFinishParameters = Nothing

  ' Deserialise
  If finBL.Runtime.WebUtilities.DeserialiseJsonStringToObject(parametersJson, GetType(WizardFinishParameters), obj) Then
    wizardFinishParameters = DirectCast(obj, WizardFinishParameters)
  Else
    Success = False
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Update Items.
''' &lt;/summary&gt;
Private Function GetUpdateItems(parametersJson As String,
                                ByRef returnValue As String) As Boolean

  Dim AccountDisbursementPayment As finAccountDisbursementPayment
  Dim AccountDisbursementPayments As finAccountDisbursementPayments
  Dim Success As Boolean
  Dim UpdateItems As List(Of UpdateItem)
  Dim WizardFinishParameters As WizardFinishParameters

  ' Assume Success
  Success = True

  ' Initialise
  UpdateItems = New List(Of UpdateItem)

  ' Parse Parameters
  Success = GetWizardFinishParameters(parametersJson, WizardFinishParameters)

  ' Get Account Disbursement Payments Object and refresh
  If Success Then
    If CreateAccountDisbursementPayments(WizardFinishParameters, AccountDisbursementPayments) Then
      Success = AccountDisbursementPayments.Refresh()
    Else
      Success = False
    End If
  End If

  ' Add to Collection
  If Success Then
    For Each AccountDisbursementPayment In AccountDisbursementPayments
      UpdateItems.Add(New UpdateItem(AccountDisbursementPayment))
    Next
  End If

  ' Finalise
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(UpdateItems, returnValue)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Returns True if the specified identifier exists in the collection.
''' &lt;/summary&gt;
Private Function HasIdentifier(accountDisbursementPayment As finAccountDisbursementPayment,
                               wizardFinishParameters As WizardFinishParameters) As Boolean
  Dim Identifier As String
  Dim s As String

  ' Get Identifier
  Identifier = accountDisbursementPayment.GetHtmlWidgetIdentifier()

  ' Find Identifier
  For Each s In wizardFinishParameters.SelectedItemIdentifierList
    If StrComp(s, Identifier) = 0 Then
      Return True
    End If
  Next

  Return False

End Function

''' &lt;summary&gt;
'''  Wizard Initialisation Information.
''' &lt;/summary&gt;
Public Class FormInitialisationInfo

  ' Current Processes
  Public CurrentProcesses As New List(Of finHtmlWidgetUtilities.JsonProcessStatusInformation)

  ' Record
  Public AccountId As String
  Public PaymentDate As Date
  Public IncludeTransactionsToDate As Date

  ' Lists

  ' Advanced
  Public PageGeneralHasAdvanced As Boolean
  Public ShowBranches As String
  Public ShowEntities As String
  Public ShowRangesHeading As String
  Public ShowAccountManagers As String
  Public ShowAccounts As String
  Public ShowAccountTypes As String
  Public ShowDepartments As String
  Public ShowProductTypes As String
  Public ShowSourceAccounts As String

  ' Configuration
  Public FormHeading As String
  Public [ReadOnly] As Boolean

End Class



''' &lt;summary&gt;
'''  Update Item.
''' &lt;/summary&gt;
Public Class UpdateItem

  Public AccountId As String
  Public AccountName As String
  Public CanInclude As Boolean
  Public ChequeReference As String
  Public Fee As Decimal
  Public Icon As String
  Public Identifier As String
  Public Include As Boolean
  Public Incoming As Decimal
  Public Outgoing As Decimal
  Public ValueNet As Decimal
  Public Warnings As String

  Public Sub New(accountDisbursementPayment As finAccountDisbursementPayment)

    ' Build Object
    With accountDisbursementPayment
      Me.AccountId = .AccountId
      Me.AccountName = .AccountName
      Me.CanInclude = .CanInclude(Me.Warnings)
      Me.ChequeReference = .ChequeReference
      Me.Fee = .Fee

      If Me.CanInclude Then
        Me.Icon = "Blank"
      Else
        Me.Icon = "Warning"
      End If

      Me.Identifier = .GetHtmlWidgetIdentifier()
      Me.Include = .Include

      If .Value &lt; 0 Then
        Me.Outgoing = -.Value
        Me.Incoming = 0
      ElseIf .Value &gt; 0 Then
        Me.Outgoing = 0
        Me.Incoming = .Value
      Else
        Me.Outgoing = 0
        Me.Incoming = 0
      End If
      Me.ValueNet = .ValueNet
    End With

  End Sub

End Class



''' &lt;summary&gt;
'''  Finish details.
''' &lt;/summary&gt;
Public Class WizardFinishDetails

  Public ProcessId As String

  Public Sub New(processId As String)

    Me.ProcessId = processId

  End Sub

End Class



''' &lt;summary&gt;
'''  Wizard Finish Parameters.
''' &lt;/summary&gt;
Public Class WizardFinishParameters

  ' General
  Public IncludeTransactionsToDate As Date
  Public PaymentDate As Date

  ' Ranges
  Public RangeAccountManagers As String
  Public RangeAccounts As String
  Public RangeAccountTypes As String
  Public RangeBranches As String
  Public RangeDepartments As String
  Public RangeEntities As String
  Public RangeProductTypes As String
  Public RangeSourceAccounts As String

  ' Selected Items
  Public SelectedItemIdentifierList As New List(Of String)

End Class</Code>
    <Language>VisualBasic</Language>
    <Notes>System defined HTML Widget.

Used as a finPOWER Connect Cloud compatible version of the form "AccountDisbursementPayments".</Notes>
    <PermissionKeyExecute />
    <ReferenceLinq>false</ReferenceLinq>
    <RunWithoutPrompts>false</RunWithoutPrompts>
    <TemplateText>&lt;div id="frmMain" class="is-widget-content" style="visibility:hidden"&gt;

  &lt;!-- Form Header --&gt;
  &lt;header&gt;
    &lt;div class="header"&gt;&lt;/div&gt;
    &lt;div class="summary"&gt;&lt;/div&gt;
    &lt;!-- Tabs --&gt;
    &lt;div id="tabWizard" class="is-tabs"&gt;
      &lt;ul&gt;
        &lt;li tabId="CurrentProcesses" tooltipText="Drilldown to view the status of current and recent Disbursement Account Payments you have processed."&gt;Recent Disbursement Account Payments&lt;/li&gt;
        &lt;li tabId="General" tooltipText="Enter selection criteria."&gt;Payment Options&lt;/li&gt;
        &lt;li tabId="UpdateItems" tooltipText="Select the Disbursement Accounts to pay."&gt;Accounts&lt;/li&gt;
        &lt;li tabId="Progress" tooltipText="Processing progress."&gt;Progress&lt;/li&gt;
      &lt;ul&gt;
    &lt;/div&gt;
  &lt;/header&gt;

  &lt;!-- Pages --&gt;
  &lt;div class="is-widget-form-body"&gt;
    &lt;!-- Current Processes --&gt;
    &lt;div id="pageCurrentProcesses"&gt;
      &lt;div id="gridCurrentProcesses"&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;!-- General --&gt;
    &lt;div id="pageGeneral"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:6em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblPaymentDate"&gt;Enter Date to make Payments on&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="datePaymentDate"&gt;Payment:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="datePaymentDate" /&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblTransactionDate"&gt;Include Transactions dated on or before&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="dateIncludeTransactionsToDate"&gt;To Date:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="dateIncludeTransactionsToDate" /&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr advancedId="Ranges"&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblRanges"&gt;Enter Ranges to filter information&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr advancedId="Accounts"&gt;
          &lt;th&gt;&lt;label for="txtRangeAccounts"&gt;Accounts:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRangeAccounts" lookupCaption="Accounts" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr advancedId="AccountManagers"&gt;
          &lt;th&gt;&lt;label for="txtRangeAccountManagers"&gt;Account&amp;nbsp;Managers:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRangeAccountManagers" lookupCaption="Account Managers" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr advancedId="AccountTypes"&gt;
          &lt;th&gt;&lt;label for="txtRangeAccountTypes"&gt;Account&amp;nbsp;Types:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRangeAccountTypes" lookupCaption="Account Types" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr advancedId="Branches"&gt;
          &lt;th&gt;&lt;label for="txtRangeBranches"&gt;Branches:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRangeBranches" lookupCaption="Branches" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr advancedId="Departments"&gt;
          &lt;th&gt;&lt;label for="txtRangeDepartments"&gt;Departments:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRangeDepartments" lookupCaption="Departments" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr advancedId="Entities"&gt;
          &lt;th&gt;&lt;label for="txtRangeEntities"&gt;Entities:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRangeEntities" lookupCaption="Entities" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr advancedId="ProductTypes"&gt;
          &lt;th&gt;&lt;label for="txtRangeProductTypes"&gt;Product&amp;nbsp;Types:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRangeProductTypes" lookupCaption="Product Types" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr advancedId="SourceAccounts"&gt;
          &lt;th&gt;&lt;label for="txtRangeSourceAccounts"&gt;Source&amp;nbsp;Accounts:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRangeSourceAccounts" lookupCaption="Source Accounts" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;

    &lt;!-- Update Items --&gt;
    &lt;div id="pageUpdateItems"&gt;
      &lt;div class="is-dock-fill is-split-container split5050"&gt;
        &lt;div class="panel"&gt;
          &lt;div id="gridUpdateItems"&gt;&lt;/div&gt;
          &lt;div id="divTransactionsSummary" class="is-info-text info" style="position:absolute; bottom:2px; right:2px; line-height:19px; font-size:15px; margin:0"&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="panel"&gt;
          &lt;div id="wbUpdateItemSummary" class="is-dock-fill"&gt;&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;

    &lt;!-- Progress --&gt;
    &lt;div id="pageProgress" style="display:flex"&gt;
      &lt;div id="divProgress" class="progress-events"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;!-- Form Footer --&gt;
  &lt;footer&gt;
    &lt;button id="cmdHistory" class="is-button" style="float:left"&gt;Recent&lt;/button&gt;
    &lt;button id="cmdAdvanced" class="is-button" style="float:left" title="Show/hide advanced options"&gt;Advanced&lt;/button&gt;

    &lt;button id="cmdCancel" class="is-button"&gt;Cancel&lt;/button&gt;
    &lt;button id="cmdBack" class="is-button"&gt;&amp;lt; Back&lt;/button&gt;
    &lt;button id="cmdNext" class="is-button"&gt;Next &amp;gt;&lt;/button&gt;
    &lt;button id="cmdFinish" class="is-button ok"&gt;Finish&lt;/button&gt;
  &lt;/footer&gt;
&lt;/div&gt;

&lt;script&gt;
// Properties
var mRecord;
var mRecord_BackgroundProcessStatus;
var mRecord_CurrentProcesses;

var mDisbursementAccountPayments;

// Controls
var C = {
  //   Current Processes
  gridCurrentProcesses: null,

  //   General
  lblPaymentDate: null,
  datePaymentDate: null,

  lblTransactionDate: null,
  dateIncludeTransactionsToDate: null,

  lblRanges: null,
  txtRangeAccountManagers: null,
  txtRangeAccounts: null,
  txtRangeAccountTypes: null,
  txtRangeBranches: null,
  txtRangeDepartments: null,
  txtRangeEntities: null,
  txtRangeProductTypes: null,
  txtRangeSourceAccounts: null,

  //   Update Items
  gridUpdateItems: null,
  divTransactionsSummary: null,
  wbUpdateItemSummary: null,

  //   Progress
  divProgress: null,
}

// Form
var frmMain;
var tabWizard;

// Wizard Buttons
var cmdCancel;
var cmdBack;
var cmdNext;
var cmdFinish;

var cmdHistory;
var cmdAdvanced;

// Other
var mAdvancedVisible = false;
var mComplete = false;
var mFromRecent = false;
var mMonitoringExisting = false;
var mProcessId;

// ==========
// Initialise
// ==========
$(function () {
  // Mobile optimisations
  $(window).resize(Form_Resize);

  // Controls
  //   General
  C.lblPaymentDate = widget.UI.Label("lblPaymentDate", {});
  C.datePaymentDate = widget.UI.DateBox("datePaymentDate", {
    allowBlank: false,
  });

  C.lblTransactionDate = widget.UI.Label("lblTransactionDate", {});
  C.dateIncludeTransactionsToDate = widget.UI.DateBox("dateIncludeTransactionsToDate", {
    allowBlank: false,
  });

  C.lblRanges = widget.UI.Label("lblRanges", {});

  //   Update Items
  C.divTransactionsSummary = $("#divTransactionsSummary");
  C.wbUpdateItemSummary = widget.UI.PreviewPane("wbUpdateItemSummary", {
    formActionHandler: Widget_NotificationHandler,
  });

  //   Progress
  C.divProgress = $("#divProgress");

  // Ranges
  for(var k in C) {
    if (k.startsWith("txtRange")) {
      C[k] = widget.UI.TextBox(k, {
        maxLength: 255,
        onButtonClick: txtRange_ButtonClick,
      });
      var buttons = [];

      // Lookup button
      buttons.push({id: "Lookup", icon: "Find", tooltipText: "Lookup"});

      // Define buttons
      C[k].ButtonsDefine(buttons);
    }
  }

  // Grids
  C.gridCurrentProcesses = widget.UI.Grid("gridCurrentProcesses", {
    docked: true,
    stickyHeader: true,
    rowNumbering: true,

    onInitialiseRow: gridCurrentProcesses_InitialiseRow,
    onRowDrilldown: gridCurrentProcesses_RowDrilldown,
  });

  C.gridUpdateItems = widget.UI.Grid("gridUpdateItems", {
    allowCellSelect: false,
    allowMultiRowSelect: true,
    docked: true,
    showRowSelectors: true,
    stickyHeader: true,
    rowNumbering: true,

    onAction: gridUpdateItems_Action,
    onAfterRowActivate: gridUpdateItems_AfterRowActivate,
    onBeforeCellUpdate: gridUpdateItems_BeforeCellUpdate,
    onInitialiseRow: gridUpdateItems_InitialiseRow,
    onRowDrilldown: gridUpdateItems_RowDrilldown,
  });

  // Create Widget form
  // NOTE: Hide by default for a cleaner startup
  frmMain = new widget.UI.Form("frmMain", { visible: false });

  // Create Tabs
  tabWizard = new widget.UI.Tabs("tabWizard", { style: "wizard" });

  // Handle Wizard Buttons
  cmdCancel = $("#cmdCancel");
  cmdBack = $("#cmdBack");
  cmdNext = $("#cmdNext");
  cmdFinish = $("#cmdFinish");
  cmdCancel.click(tabWizard_Cancel);
  cmdBack.click(function() { tabWizard_Move(-1); });
  cmdNext.click(function() { tabWizard_Move(1); });
  cmdFinish.click(function() { Form_ExecuteAction("Finish"); });

  cmdHistory = $("#cmdHistory");
  cmdHistory.click(function() { Form_ExecuteAction("Recent"); });

  cmdAdvanced = $("#cmdAdvanced");
  cmdAdvanced.click(AdvancedToggle);

  // Handle Notifications
  widget.DisableCloseButton();
  widget.ActionNotificationHandle(Widget_NotificationHandler);

  // Reset
  Form_Reset();
});

// ==========
// Reset Form
// ==========
function Form_Reset() {
  // Defaults

  // Set Tab
  tabWizard.SelectedTabId("General");

  // Resize
  Form_Resize();

  // Load Record (i.e., initialise wizard)
  Record_Load();
}

// ===========
// Load Record
// ===========
function Record_Load() {
  // Initialise
  mRecord = null;
  mRecord_BackgroundProcessStatus = null;
  mRecord_CurrentProcesses = null;
  mDisbursementAccountPayments = null;

  // Hide content
  frmMain.Visible(false);

  // Block UI
  widget.UI.Block("Initialising, please wait...");

  // Load Initialisation details
  widget.GetString("GetInitialisationInfo", {},
    // Success
    function (data) {
      mRecord = JSON.parse(data);
      mRecord_CurrentProcesses = mRecord.CurrentProcesses;

      // Give Collections ability to lookup by code

      // Load Fields
      Fields_Load();

      // Notify if there are Current Processes
      var countCurrent = 0;
      for (var i = 0; i &lt; mRecord_CurrentProcesses.length; i++) {
        switch (mRecord_CurrentProcesses[i].Status) {
          case "Pending":
          case "InProgress":
          case "InProgressCancelRequested":
            countCurrent += 1;
        }
      }
      if (countCurrent != 0) {
        tabWizard_Move(-1);
        widget.UI.MsgBoxInfo("There are existing Disbursement Account Payments that you have run that are not yet complete.\n\nReview and optionally monitor these or use the 'Next &gt;' button to run a new instance of Disbursement Account Payments.", { heading: "Disbursement Account Payments Still Running", icon: "MonitorCategory"} );
      }
    },

    // Fail
    function (message) {
      widget.UI.MsgBoxAlert("fail: " + message);
      Fields_Load();
    }
  );
}

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // Current Processes
    // NOTE: Bind here since this is the first page
    gridCurrentProcesses_Refresh();

    // General
    C.txtRangeAccounts.Text(mRecord.AccountId);
    C.datePaymentDate.Value(mRecord.PaymentDate);
    C.dateIncludeTransactionsToDate.Value(mRecord.IncludeTransactionsToDate);
  }

  // Unblock UI
  widget.UI.Unblock();

  // Update fields
  Fields_Update();

  // Update Controls

  // Refresh Tab
  tabWizard_Refresh();
}

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // General
  // Not used by this HTML Widget
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Heading
  if (mRecord) {
    widget.SetHeading(mRecord.FormHeading);
  }

  // Information Lists

  // Lists
  if (mRecord) {
  }

  // Controls
  if (mRecord) {
    if (mRecord.AccountId) {
      C.lblRanges.Text("Disbursement Account Payments for Account");
      C.txtRangeAccounts.Caption("Account:");
      C.txtRangeAccounts.ReadOnly(true);
      C.txtRangeAccounts.ButtonsDefine([]);
    }

    // Initialise Advanced
    AdvancedInitialise();
  }

  // Auto-format
  tabWizard.AutoFormatPage();

  // Update Buttons
  tabWizard_UpdateButtons();

  // Read-Only?
  if (mRecord &amp;&amp; mRecord.ReadOnly) frmMain.FormReadOnly(C, true);

  // Show content
  frmMain.Visible(mRecord != null);

  // Resize Tab
  tabWizard_Resize();
}

// ===========
// Resize Form
// ===========
function Form_Resize() {
  // General

  // Tab
  tabWizard_Resize();
}

// ==============
// Wizard Buttons
// ==============
function tabWizard_Cancel() {
  // Executing?
  if (mComplete) {
    tabWizard_Cancel_Post();
  }
  else if (mRecord_BackgroundProcessStatus &amp;&amp; !mMonitoringExisting) {
    widget.UI.MsgBoxConfirm("Disbursement Account Payments is still running.\n\nThis will continue to run and you can re-open this form at any time to check on its status.\n\n\Close this form?", {}, tabWizard_Cancel_Post);
  }
  else {
    tabWizard_Cancel_Post();
  }
}

function tabWizard_Cancel_Post() {
  if (widget.CanClose()) {
    widget.Close();
  }
  else {
    widget.Reset();
  }
}

function tabWizard_UpdateButtons() {
  // Back and Next Buttons?
  var tabIndex = tabWizard.SelectedTabIndex();
  cmdBack.prop("disabled", tabIndex &lt;= 1);
  cmdNext.prop("disabled", tabIndex &gt;= tabWizard.TabCount() - 2);

  // Finish Button
  cmdFinish.prop("disabled", tabWizard.SelectedTabId() != "UpdateItems" || (mRecord &amp;&amp; mRecord.ReadOnly));

  // Page Exceptions
  if (mRecord_BackgroundProcessStatus) {
    cmdNext.prop("disabled", tabIndex &gt;= tabWizard.TabCount() - 1);
    cmdBack.prop("disabled", true);
    cmdHistory.prop("disabled", true);

    switch(mRecord_BackgroundProcessStatus.Status) {
      case "Pending":
      case "InProgress":
        cmdFinish.text("Stop");
        cmdFinish.prop("disabled", false);
        cmdFinish.addClass("negative");
        break;

      default:
        cmdFinish.text("Process");
        cmdFinish.prop("disabled", true);
        cmdFinish.removeClass("negative");
    }
  }
  else {
    cmdFinish.text("Process");
    cmdHistory.prop("disabled", false);
  }

  // Only show Advanced button on relevant pages
  if (mRecord) {
    cmdAdvanced.hide()
    switch (tabWizard.SelectedTabId()) {
      case "General":
        if (mRecord.PageGeneralHasAdvanced) cmdAdvanced.show();
        break;
    }
  }
  else {
    cmdAdvanced.hide();
  }

  // Recent Page exceptions
  if (mFromRecent) {
    cmdHistory.prop("disabled", false);

    cmdBack.prop("disabled", true);
    cmdNext.prop("disabled", true);
    cmdFinish.prop("disabled", true);
  }

  if (mComplete) {
    // Complete, i.e., Finish now closes the wizard
    cmdFinish.text("Close");
    cmdFinish.prop("disabled", false);

    // Allow viewing recent list
    cmdHistory.prop("disabled", false);
  }
}

// ==========
// Resize Tab
// ==========
function tabWizard_Resize() {
  switch (tabWizard.SelectedTabId()) {
    case "General":
      // General
      for(var k in C) {
        if (k.startsWith("txtRange")) {
          C[k].WidthResizeFromParent();
        }
      }
      break;

    default:
      break;
  }
}

// ===========
// Wizard Move
// ===========
function tabWizard_Move(direction) {
  var Ok;

  // Validate
  if (direction &gt; 0) {
    tabWizard_Validate(function () { tabWizard_MovePost(direction); });
  }
  else {
    // Can always move backwards
    tabWizard_MovePost(direction);
  }
}

function tabWizard_MovePost(direction) {
  var Ok = true;

  // Find Next Tab to Move To
  if (Ok) {
    var found = false;
    var newTab = tabWizard.SelectedTabIndex();

    do {
      newTab += direction;

      switch (tabWizard.GetTabIdByIndex(newTab)) {
        default:
          found = true;
          break;
      }

      // Found?
      if (found) {
        break;
      }
      else if (newTab == tabWizard.TabCount() - 1) {
        // Just in case!
        widget.UI.MsgBoxAlert("tabWizard_MovePost: Tab not handled!");
        break;
      }
    }
    while (true);

    // Refresh the New Tab
    tabWizard_Refresh(newTab);
  }
}

// ===========
// Refresh Tab
// ===========
function tabWizard_Refresh(newTab) {
  // Moving forward onto tab, so Load information
  if (newTab &gt;= tabWizard.SelectedTabIndex()) {
    switch (tabWizard.GetTabIdByIndex(newTab)) {
      case "UpdateItems":
        pageUpdateItems_Refresh();
        break;

      default:
        break;
    }
  }

  // Always Refresh Current Processes, even when moving back
  if (newTab == 0) {
    if (!mRecord_CurrentProcesses) pageCurrentProcesses_Refresh();
  }

  // Make Tab it
  tabWizard.SelectedTabIndex(newTab);

  // Special
  switch(tabWizard.SelectedTabId()) {
    case "CurrentProcesses":
      // Reset from recent flag
      mFromRecent = false;
      break;

    default:
      break;
  }

  // Tweak fields

  // Update Heading
  switch (tabWizard.SelectedTabId()) {
    default:
      frmMain.RefreshHeading(tabWizard.TabCaption(tabWizard.SelectedTabId()), tabWizard.TabTooltipText(tabWizard.SelectedTabId()));
      break;
  }

  // Back, Next command buttons valid?
  tabWizard_UpdateButtons();

  // Resize Wizard
  tabWizard_Resize();

  // Focus
  switch (tabWizard.SelectedTabId()) {
    default:
      tabWizard.FocusFirst();
      break;
  }
}

// ===============
// Validate Wizard
// ===============
function tabWizard_Validate(validCallback) {
  // Validate
  var Ok = tabWizard.Validate(true);

  // Other client-side validation
  if (Ok) {
    switch (tabWizard.SelectedTabId()) {
      case "General":
        // General
        break;

      case "UpdateItems":
        // Update Items
        var selectedIdentifiers = CreateFinishParameters_SelectedItems();
        if (selectedIdentifiers.length == 0) {
          Ok = false;
          widget.UI.MsgBoxAlert("You have not selected any Accounts to pay.");
        }
        break;

      default:
        // No validation
        validCallback();
        return;
    }
  }

  // Server-side validation
  if (Ok) {
    var params;

    switch (tabWizard.SelectedTabId()) {
      default:
        break;
    }

    if (params) {
      // Disable Form
      frmMain.FormDisable("Validating");

      // Extend parameters
      params.pageId = tabWizard.SelectedTabId();

      // Call WizardValidate method in Script
      widget.GetString("WizardValidate",
                       params,
                       function (data) { tabWizard_ValidatePost(validCallback, data); },
                       tabWizard_ValidateFail);
    }
    else {
      // No server-side validation
      validCallback();
    }
  }
}

function tabWizard_ValidatePost(validCallback, data) {
  // Enable form
  frmMain.FormEnable();

  // Parse Data
  var o = {};
  if (data) o = JSON.parse(data);

  if (o.FailedMessage) {
    // -----------------
    // Validation failed
    // -----------------
    var o = JSON.parse(data);
    widget.UI.MsgBoxAlert(o.FailedMessage);
    if (o.FailedControlId) $("#" + o.FailedControlId).focus();
  }
  else {
    // ---------------------
    // Validation successful
    // ---------------------
    // Validation could pass back additional information, e.g., to use in tabWizard_Refresh
    switch (tabWizard.SelectedTabId()) {
      case "General":
        // General
        if (o.Data &amp;&amp; o.Data.length != 0) {
          // Confirm warnings
          widget.UI.MsgBoxConfirmList("To continue, please approve the following:",
                                      o.Data,
                                      {
                                        heading: "Additional Confirmation",
                                        icon: "Warning",
                                      },
                                      function () { validCallback(); },
                                      null);

          // Allow callbacks to continue
          return;
        };

        break;
    }

    // Callback
    validCallback();
  }
}

function tabWizard_ValidateFail(errorMessage)
{
  widget.UI.MsgBoxAlert(errorMessage);

  // Enable form
  frmMain.FormEnable();
}

// =================
// Execute an Action
// =================
function Form_ExecuteAction(actionId) {
  switch (actionId.toUpperCase()) {
    case "FINISH":
      // Finish
      if (mComplete) {
        widget.Close();
      }
      else {
        Form_ExecuteAction_Finish();
      }
      break;

    case "RECENT":
      // Recent
      tabWizard_Refresh(0);
      break;

    default:
      window.alert(mViewName + ".Form_ExecuteAction: Unhandled action '" + actionId + "'");
      break;
  }
}

// =============
// Finish Action
// =============
function Form_ExecuteAction_Finish() {
  if (cmdFinish.text() == "Stop") {
    // Stop Process?
    widget.UI.MsgBoxConfirm("Are you sure you want to stop this process?\n\nNOTE: This may not take affect immediately.", {}, function () { Form_ExecuteAction_FinishStop(); }, null);
  }
  else {
    // Validate
    tabWizard_Validate(function () {
      // Confirmation Message
      var message = "";

      // Build Message
      message += "Are you sure you want to pay the selected Disbursement Accounts?";

      // Background Process
      message += "\n\nNOTE: You can close this form and any time and open it again to monitor the status of this process.";

      // Confirm
      widget.UI.MsgBoxConfirm(message, {}, function () { Form_ExecuteAction_FinishPost(); }, null);
    });
  }
}

function Form_ExecuteAction_FinishPost() {
  // Running new process
  mMonitoringExisting = false;

  // Clear Progress Page
  pageProgress_Refresh(true);

  // Disable Form
  widget.UI.Block("Starting Disbursement Account Payments, please wait...");

  // Create Parameters
  var params = CreateFinishParameters();

  // Finish
  widget.GetString("Finish", params,
    function (data) {
      // Parse
      data = JSON.parse(data);

      // Set Tab
      tabWizard.SelectedTabId("Progress");
      tabWizard_Refresh();

      // Save Status
      mProcessId = data.ProcessId;
      mRecord_BackgroundProcessStatus = data;

      // Update Wizard Buttons
      tabWizard_UpdateButtons();

      // Enable Form
      widget.UI.Unblock();

      // Refresh Progress
      pageProgress_Refresh();

      // Poll Background Process
      window.setTimeout(Form_ExecuteAction_GetBackgroundProcessStatus, 3500);
    },

    function (error) {
      // Show Error
      widget.UI.MsgBoxAlert(error);

      // Enable Form
      widget.UI.Unblock();
    }
  );
}

function Form_ExecuteAction_FinishStop() {
  // Continue
  widget.GetString("CancelBackgroundProcess", { processId: mProcessId },
    function (data) {
      widget.UI.MsgBoxInfo("The process has been requested to stop.");
    },

    function (error) {
      // Show Error
      widget.UI.MsgBoxAlert(error);
    }
  );
}

function Form_ExecuteAction_GetBackgroundProcessStatus() {
  // Continue
  widget.GetString("GetBackgroundProcessStatus", { processId: mProcessId, lastEventId: mLastEventId },
    function (data) {
      data = JSON.parse(data);

      // Update Status
      mRecord_BackgroundProcessStatus = data;

      // Refresh Progress
      pageProgress_Refresh();

      // Status
      var Status = mRecord_BackgroundProcessStatus.Status;

      // Handle Status
      switch(Status) {
        case "Cancelled":
          // Cancelled
          mRecord_BackgroundProcessStatus = null;

          // Update Wizard Buttons
          tabWizard_UpdateButtons();

          // Notify
          widget.UI.MsgBoxInfo("Disbursement Account Payments was successfully cancelled.");
          break;

        case "Complete":
        case "CompleteWithErrors":
        case "CompleteWithWarnings":
          // Complete
          mComplete = true;
          mRecord_BackgroundProcessStatus = null;

          // Update Wizard Buttons
          tabWizard_UpdateButtons();

          // Notify
          widget.UI.MsgBoxInfo("Disbursement Account Payments is " + widget.SplitWordsAtCapitals(Status, true, true) + ".");
          break;

        case "Failed":
          // Failed
          mRecord_BackgroundProcessStatus = null;

          // Update Wizard Buttons
          tabWizard_UpdateButtons();

          // Notify
          widget.UI.MsgBoxAlert("Disbursement Account Payments failed to complete.");
          break;

        default:
          // Continue Polling
          window.setTimeout(Form_ExecuteAction_GetBackgroundProcessStatus, 2500);

          // Prevent finPOWER Connect Cloud UI signing the User out
          widget.NotifyBusy();
      }
    },

    function (error) {
      // Show Error
      widget.UI.MsgBoxAlert(error);

      // Abort Execution
      mRecord_BackgroundProcessStatus = null;

      // Update Wizard Buttons
      tabWizard_UpdateButtons();
    }
  );
}

// ====================
// pageCurrentProcesses
// ====================
function pageCurrentProcesses_Refresh() {
  // Reset flags
  mComplete = false;

  // Block UI
  widget.UI.Block("Refreshing Recent Disbursement Account Payments, please wait...");

  // Fetch
  widget.GetString("GetCurrentProcesses", {},
    function (data) {
      // Parse
      mRecord_CurrentProcesses = JSON.parse(data);

      // Unblock UI
      widget.UI.Unblock();

      // Update Wizard Buttons
      tabWizard_UpdateButtons();

      // Refresh Grid
      gridCurrentProcesses_Refresh();
    },

    function (error) {
      // Unblock UI
      widget.UI.Unblock();

      // Show Error
      widget.UI.MsgBoxAlert(error);
    }
  );
}

// ===============
// pageUpdateItems
// ===============
function pageUpdateItems_Refresh() {
  // Hide content
  frmMain.Visible(false);

  // Block UI
  widget.UI.Block("Retrieving Disbursements, please wait...")

  // Parameters
  var params = CreateFinishParameters();

  // Retrieve Disbursements Statements
  widget.GetString("GetUpdateItems", params,
    // Success
    function(data) {
      // Parse
      mDisbursementAccountPayments = JSON.parse(data);

      // Unblock
      widget.UI.Unblock();

      // Show content
      frmMain.Visible(true);

      // Refresh Grid
      gridUpdateItems_Refresh();
    },

    // Fail
    function(errorMessage) {
      // Unblock
      widget.UI.Unblock();

      // Cancel
      tabWizard_Move(-1);

      // Show content
      frmMain.Visible(true);

      // Error
      widget.UI.MsgBoxAlert(errorMessage);
    }
  );
}

// ============
// pageProgress
// ============
function pageProgress_Refresh(clear) {
  if (clear) {    
    mLastProcessStatus = "";
    mLastEventId = "";
    mRecord_BackgroundProcessStatus = null;
    mRecord_CurrentProcesses = null;
  }
  else if (mRecord_BackgroundProcessStatus) {
    // Retrieve Last Process Status
    mLastProcessStatus = mRecord_BackgroundProcessStatus.StatusText;
  }

  // Build Progress
  mLastEventId = widget.UI.BuildBackgroundProcessProgress(C.divProgress, clear, mRecord_BackgroundProcessStatus);

  // Stop button valid?
  tabWizard_UpdateButtons()

  // Update Heading
  if (tabWizard.SelectedTabId() == "Progress") {
    if (mLastProcessStatus &amp;&amp; mLastProcessStatus.length != 0) {
      frmMain.RefreshHeading(mLastProcessStatus, "Processing progress.");
    }
    else {
      frmMain.RefreshHeading("Progress", "Processing progress.");
    }
  }
}

// ====================
// gridCurrentProcesses
// ====================
function gridCurrentProcesses_Refresh() {
  // Add Columns
  if (C.gridCurrentProcesses.ColumnCount() == 0) {
    C.gridCurrentProcesses.AddColumnDrilldown();
    C.gridCurrentProcesses.AddColumnString("StatusText", { caption: "Status" });
    C.gridCurrentProcesses.AddColumnDateTime("CreatedDate", { caption: "Started" });
  }

  // Refresh
  C.gridCurrentProcesses.VirtualDataRefresh(mRecord_CurrentProcesses);

  // Activate no rows
  C.gridCurrentProcesses.ActiveDataRowIndex(-1);
}

function gridCurrentProcesses_InitialiseRow(e) {
  var item = mRecord_CurrentProcesses[e.row.listIndex];

  // Update cells
  e.row.AutoBind(item);

  // Styles
  switch(item.Status) {
    case "Complete":
      e.row.cells.StatusText.colour = "green";
      break;

    case "CompleteWithErrors":
      e.row.cells.StatusText.colour = "darkred";
      break;

    case "CompleteWithWarnings":
      e.row.cells.StatusText.colour = "orange";
      break;

    case "Failed":
      e.row.cells.StatusText.colour = "red";
      break;

    case "Pending":
    case "InProgress":
    case "InProgressCancelRequested":
      e.row.bold = true;
      break;
  }
}

function gridCurrentProcesses_RowDrilldown(e) {
  var item = mRecord_CurrentProcesses[e.row.listIndex];

  // Switch to Progress Page
  mFromRecent = true;
  mMonitoringExisting = true;
  mProcessId = item.ProcessId;
  tabWizard_Refresh(3);
  pageProgress_Refresh(true);

  // Start monitoring
  Form_ExecuteAction_GetBackgroundProcessStatus();
}

// ===============
// gridUpdateItems
// ===============
function gridUpdateItems_Refresh() {
  var showWarnings = false;

  // Show / Hide Columns
  for (var i = 0; i &lt; mDisbursementAccountPayments.length; i++) {
    var item = mDisbursementAccountPayments[i];

    // Warnings
    if (item.Warnings) showWarnings = true;
  }

  // Add Columns
  C.gridUpdateItems.ClearColumns();
  C.gridUpdateItems.AddColumnIcon("Icon", { caption: "" });
  C.gridUpdateItems.AddColumnBoolean("Include", { caption: "Include", allowEdit: true });
  C.gridUpdateItems.AddColumnCode("AccountId", { caption: "Account" });
  C.gridUpdateItems.AddColumnString("AccountName", { caption: "Name" });
  C.gridUpdateItems.AddColumnString("ChequeReference", { caption: "Cheque Number" });
  C.gridUpdateItems.AddColumnCurrency("Outgoing", { caption: "Outgoing", blankIfZero: true, summary: "sum" });
  C.gridUpdateItems.AddColumnCurrency("Incoming", { caption: "Incoming", blankIfZero: true, summary: "sum" });
  C.gridUpdateItems.AddColumnCurrency("Fee", { caption: "Fee", summary: "sum" });
  C.gridUpdateItems.AddColumnCurrency("ValueNet", { caption: "Net Value", summary: "sum" });
  C.gridUpdateItems.AddColumnString("Warnings", { caption: "Warnings", visible: showWarnings });

  // Actions
  C.gridUpdateItems.Actions().Define([{ actionId: "Refresh", tooltipText:"Refresh", icon: "Refresh" },
                                      {},
                                      { actionId: "SelectUp", tooltipText:"Select all rows above and including the current row", icon: "Select_Up" },
                                      { actionId: "SelectDown", tooltipText:"Select all rows below and including the current row", icon: "Select_Down" },
                                      { actionId: "SelectAll", tooltipText:"Select all valid rows", icon: "Select_All" },
                                      { actionId: "SelectNone", tooltipText:"Select no rows", icon: "Select_None" },
                                      { actionId: "SelectChecked", tooltipText: "Select all rows that are checked to include", icon: "Select_Checked" },
                                      { actionId: "SelectUnchecked", tooltipText: "Select all rows that are not checked to include", icon: "Select_Unchecked" },
                                      {},
                                      { actionId: "Check", tooltipText: "Check selected row(s)", icon: "Checkbox_Checked" },
                                      { actionId: "Uncheck", tooltipText: "Uncheck selected row(s)", icon: "Checkbox_Unchecked" }
                                     ]);

  // Give collection ability to form a unique cache key and preview parameters for the Widget
  mDisbursementAccountPayments.GetCacheKey = function (index) {
    var item = mDisbursementAccountPayments[index];
    return item.Identifier;
  };
  mDisbursementAccountPayments.GetPreviewFetchParameters = function (index) {
    var item = mDisbursementAccountPayments[index];
    var o = {};

    o.accountId = item.AccountId;
    o.parametersJson = JSON.stringify(CreateFinishParameters());
    o.identifier = item.Identifier;

    return o;
  };

  // Refresh
  C.gridUpdateItems.VirtualDataRefresh(mDisbursementAccountPayments);

  // Select first row
  C.gridUpdateItems.ActivateFirstDataRow();

  // Update Totals
  divTransactionsSummary_Refresh();
}

function gridUpdateItems_Action(actionId) {
  switch (actionId.toUpperCase()) {
    case "REFRESH":
      pageUpdateItems_Refresh();
      break;

    case "SELECTUP":
    case "SELECTDOWN":
      var activeRowIndex = C.gridUpdateItems.ActiveDataRowListIndex();
      var indexes = [];

      for(var i = 0; i &lt; mDisbursementAccountPayments.length; i++) {
        if(mDisbursementAccountPayments[i].CanInclude) {
          if(actionId.toUpperCase() == "SELECTUP" &amp;&amp; i &lt;= activeRowIndex) {
            indexes.push(i);
          }
          else if(actionId.toUpperCase() == "SELECTDOWN" &amp;&amp; i &gt;= activeRowIndex) {
            indexes.push(i);
          }
        }
      }
      break;

    case "SELECTALL":
      var indexes = [];
      for(var i = 0; i &lt; mDisbursementAccountPayments.length; i++) {
        var item = mDisbursementAccountPayments[i];
        if(item.CanInclude) indexes.push(i);
      }
      break;

    case "SELECTNONE":
      var indexes = [];
      break;

    case "SELECTCHECKED":
    case "SELECTUNCHECKED":
      var indexes = [];

      for(var i = 0; i &lt; mDisbursementAccountPayments.length; i++) {
        var item = mDisbursementAccountPayments[i];

        if(item.CanInclude) {
          if(actionId.toUpperCase() == "SELECTCHECKED" &amp;&amp; item.Include) {
            indexes.push(i);
          }
          else if(actionId.toUpperCase() == "SELECTUNCHECKED" &amp;&amp; !item.Include) {
            indexes.push(i);
          }
        }
      }
      break;

    case "CHECK":
    case "UNCHECK":
      var selectedItems = C.gridUpdateItems.GetSelectedRowIndexes(true, true);

      for(var i = 0; i &lt; selectedItems.length; i++) {
        var item = mDisbursementAccountPayments[selectedItems[i]];
        if(item.CanInclude) item.Include = (actionId.toUpperCase() == "CHECK");
      }
      C.gridUpdateItems.VirtualDataRefresh(mDisbursementAccountPayments, true, { retainSelectedRows: true });
      break;

    default:
      break;
  }

  // Set Indexes
  if(indexes) {
    C.gridUpdateItems.SetSelectedRowIndexes(indexes, true);
  }

  // Update Totals
  divTransactionsSummary_Refresh();
}

function gridUpdateItems_AfterRowActivate(e) {
  // Preview
  wbUpdateItemSummary_Preview();
}

function gridUpdateItems_BeforeCellUpdate(e) {
  var item = mDisbursementAccountPayments[e.row.listIndex];

  switch(e.columnKey) {
    case "Include":
      item.Include = e.newValue;
      break;
  }

  // Update Totals
  divTransactionsSummary_Refresh();
}

function gridUpdateItems_InitialiseRow(e) {
  var item = mDisbursementAccountPayments[e.row.listIndex];

  // Update cells
  e.row.AutoBind(item);

  // Invalid rows cannot be edited
  e.row.readOnly = !item.CanInclude;
  e.row.cells.Include.readOnly = !item.CanInclude;

  // Has warning?
  if(item.Icon == "Warning" &amp;&amp; item.Warnings.length != 0) {
    e.row.cells.Warnings.colour = "red";
  }

  // Hyperlinks
  e.row.cells.AccountId.hyperlink = "app://FormShow?form=Accounts&amp;id=" + widget.UI.HtmlEncode(item.AccountId);
}

function gridUpdateItems_RowDrilldown(e) {

}

// ========
// txtRange
// ========
function txtRange_ButtonClick(sender, e) {
  if (e.id == "Lookup") {
    var caption = sender.Element().attr("lookupCaption");
    var range = sender.Element().attr("id");

    range = range.substr(8);
    if(range.startsWith("Payee")) range = "ExternalParties" + range.substr(5);
    if(range.startsWith("SourceAccounts")) range = "Accounts";

    widget.UI.Forms.ShowRangeLookupFromStandardRange(range, sender.Text(), { caption: "Lookup " + caption},
      function (newRange) {
        sender.Text(newRange);
        sender.Focus();
      }
    );
  }
}

// ========================
// Create Finish Parameters
// ========================
function CreateFinishParameters() {
  var params;

  // Parameters
  params = {
    paymentDate: C.datePaymentDate.Value(),
    includeTransactionsToDate: C.dateIncludeTransactionsToDate.Value(),

    rangeAccountManagers: C.txtRangeAccountManagers.Text(),
    rangeAccounts: C.txtRangeAccounts.Text(),
    rangeAccountTypes: C.txtRangeAccountTypes.Text(),
    rangeBranches: C.txtRangeBranches.Text(),
    rangeDepartments: C.txtRangeDepartments.Text(),
    rangeEntities: C.txtRangeEntities.Text(),
    rangeProductTypes: C.txtRangeProductTypes.Text(),
    rangeSourceAccounts: C.txtRangeSourceAccounts.Text(),

    selectedItemIdentifierList: CreateFinishParameters_SelectedItems(),
  }


  return params;
}

// ==========================================
// Get Selected Disbursement Account Payments
// ==========================================
function CreateFinishParameters_SelectedItems() {
  var records = [];

  if (mDisbursementAccountPayments) {
    for(var i = 0; i &lt; mDisbursementAccountPayments.length; i++) {
      var item = mDisbursementAccountPayments[i];

      if(item.Include &amp;&amp; item.CanInclude) {
        records.push(item.Identifier);
      }
    }
  }

  return records;
}

// ======================
// divTransactionsSummary
// ======================
function divTransactionsSummary_Refresh() {
  var total = 0;

  // Total
  for (var i = 0; i &lt; mDisbursementAccountPayments.length; i++) {
    var item = mDisbursementAccountPayments[i];

    if (item.Include &amp;&amp; item.CanInclude) {
      total += item.ValueNet;
    }
  }

  // Avoid rounding issues
  total = widget.RoundCurrency(total);

  // Message
  C.divTransactionsSummary.html("Selected: &lt;b&gt;" + widget.FormatCurrency(total, true) + "&lt;/b&gt;");
}

// =================
// Advanced handling
// =================
function AdvancedInitialise() {
  // Tweaks

  // General
  AdvancedInitialiseSection("Ranges", mRecord.ShowRangesHeading);
  AdvancedInitialiseSection("AccountManagers", mRecord.ShowAccountManagers);
  AdvancedInitialiseSection("Accounts", mRecord.ShowAccounts);
  AdvancedInitialiseSection("AccountTypes", mRecord.ShowAccountTypes);
  AdvancedInitialiseSection("Branches", mRecord.ShowBranches);
  AdvancedInitialiseSection("Departments", mRecord.ShowDepartments);
  AdvancedInitialiseSection("Entities", mRecord.ShowEntities);
  AdvancedInitialiseSection("ProductTypes", mRecord.ShowProductTypes);
  AdvancedInitialiseSection("SourceAccounts", mRecord.ShowSourceAccounts);
}

function AdvancedInitialiseSection(id, option) {
  // Get elements
  var els=$("*[advancedId='" + id + "']");

  // Update
  switch(option.toUpperCase()) {
    case "TRUE":
      // Always show, i.e., not advanced
      break;

    case "FALSE":
      // Never show
      els.hide();
      break;

    case "ADVANCED":
      // Only show in 'Advanced' mode
      els.addClass("advanced");
      break;
  }
}

function AdvancedToggle() {
  // Toggle Advanced
  mAdvancedVisible = !mAdvancedVisible;

  // Update Controls
  if (mAdvancedVisible) {
    // Showing
    $("body").addClass("advanced-visible");
    cmdAdvanced.attr("showing", true);
  }
  else {
    // Not showing
    $("body").removeClass("advanced-visible");
    cmdAdvanced.attr("showing", false);
  }

  // Other
  switch (tabWizard.SelectedTabId()) {
    default:
      break;
  }

  // Finalise
  AdvancedInitialise();

  // Force resize
  tabWizard_Resize()
}

// ===================
// wbUpdateItemSummary
// ===================
function wbUpdateItemSummary_Preview() {
  C.wbUpdateItemSummary.PreviewFromGridCollection(C.gridUpdateItems, mDisbursementAccountPayments, "GetUpdateItemPreview");
}

// ====================
// Notification Handler
// ====================
function Widget_NotificationHandler(actionId, data) {
  switch(actionId.toUpperCase()) {
    case "FORMCLOSE":
      // Closing Form
      if (mRecord &amp;&amp; mRecord.WorkflowId &amp;&amp; !mSearchResult) {
        widget.UI.MsgBoxConfirm("Closing this form without performing a Search will not action the Workflow Item.\n\nAre you sure you want to close this form?", {}, tabWizard_Cancel);
      }
      else {
        tabWizard_Cancel();
      }
      break;

    default:
      break;
  }
}
&lt;/script&gt;</TemplateText>
    <TemplateTextBookmarks />
    <TimeoutSeconds>60</TimeoutSeconds>
    <UniqueId>u4Ci2KJ+tUGDoH2xTthKiA</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption />
    <HtmlWidgetAllowInitialEventCaching>false</HtmlWidgetAllowInitialEventCaching>
    <HtmlWidgetMaxHeight>0</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>1200</HtmlWidgetMaxWidth>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceChartsApex>false</HtmlWidgetResourceChartsApex>
    <HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <HtmlWidgetSpecialEventGetFolderCount>false</HtmlWidgetSpecialEventGetFolderCount>
    <Icon />
    <RestrictedOriginsListEnabled>false</RestrictedOriginsListEnabled>
    <RunAsAdministrator>false</RunAsAdministrator>
    <WebServiceName />
    <WebServiceAllowAnonymous>false</WebServiceAllowAnonymous>
    <WebServiceSendDebugInformation>false</WebServiceSendDebugInformation>
    <ShowInMenu>None</ShowInMenu>
    <ParametersType>Custom</ParametersType>
    <Parameters>
      <ISParameterDefs version="1.00">
        <Parameters>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Form options.</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="ShowAccounts" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>true</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowAccountManagers" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>true</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowAccountTypes" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>true</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowBranches" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>true</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowDepartments" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>true</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowEntities" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>true</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowProductTypes" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>true</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowSourceAccounts" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>true</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>TESTING</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText>These are the Parameters required by this HTML Widget to function correctly.
They are listed here for testing purposes only.</TooltipText>
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="AccountId" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <List>RANGE.Accounts</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
        </Parameters>
      </ISParameterDefs>
    </Parameters>
  </finScript>