<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2023-07-20T23:31:51.0000000">
    <CreatedUserId>ADMIN</CreatedUserId>
    <CreatedUtcDate>2021-07-05T04:40:56.5800000</CreatedUtcDate>
    <UpdatedUserId>ADMIN</UpdatedUserId>
    <UpdatedUtcDate>2023-07-20T23:31:26.9670000</UpdatedUtcDate>
    <ScriptId>ATV</ScriptId>
    <Description>Account Transaction View</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Bookmarks />
    <Category />
    <Code>' HtmlWidget_AccountTransactionView
Option Explicit On
Option Strict On

' #################################################################
' Account Transaction View form HTML Widget
'
' Version: 1.05 (21/07/2023)
'
' Usage: System-defined HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.04  14/09/2021  ISS      J027393   Permission checks
'    1.05  21/07/2023  ISS      J031617   Supplied Account Transaction row will be selected by default
' #################################################################

' Constants
Private Const FORM_KEY As String = "AccountTransactionView"

' Common Parameters
Private mAccountTransactionPk As Integer

' 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
    mAccountTransactionPk = .GetInteger("AccountTransactionPk")
    If mAccountTransactionPk = 0 Then mAccountTransactionPk = .GetInteger("id") ' Compatibility with Summary Pages such as Account Key Details, Events block
  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 "GetInitialisationInfo"
      ' Get Initialisation Information required for this form
      Main = GetInitialisationInfo(returnValue)

    Case "GetTransactionPreview"
      ' Get Transaction Preview
      Main = GetTransactionPreview(returnValue)

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

End Function

''' &lt;summary&gt;
'''  Get Initialisation Information required for this form.
''' &lt;/summary&gt;
Public Function GetInitialisationInfo(ByRef response As String) As Boolean

  Dim BatchView As finBatchView
  Dim BatchViewTransaction As finBatchViewTransaction
  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate
  If mAccountTransactionPk = 0 Then
    Success = False
    finBL.Error.ErrorBegin("Transaction Pk not specified.")
  ElseIf Not finBL.CurrentUser.Permissions.Allow("Account.Form.Page.Transactions") Then
    Success = False
    finBL.Error.ErrorBegin("You do not have permission to view Account Transactions.")
  End If

  ' Load Batch View
  If Success Then
    BatchView = finBL.CreateBatchView()
    Success = BatchView.LoadByAccountTransactionPk(mAccountTransactionPk)
  End If

  ' Get Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' General
      If BatchView.BatchHeaderPk = 0 Then
        .Heading = "Transaction Details"
      Else
        .Heading = "Batch: " &amp; BatchView.BatchId
      End If
      .Summary = String.Format("Entered via {0} by {1} on {2}", BatchView.SourceText, BatchView.CreatedUserId, finBL.FormatDateTimeLong(BatchView.CreatedDate))

      ' Batch Properties
      If BatchView.BatchHeaderPk &lt;&gt; 0 Then
        .BatchId = BatchView.BatchId
        .TransactionTypeId = BatchView.TransactionTypeId
        .TransactionTypeDescription = BatchView.TransactionTypeDescription
        .Notes = BatchView.Notes
      End If

      ' Transactions
      .DefaultIndex = BatchView.Transactions.GetItemIndexFromPk(mAccountTransactionPk)
      For Each BatchViewTransaction In BatchView.Transactions
        .Transactions.Add(New TransactionDetails(finBL, BatchViewTransaction))
      Next

      ' Configuration
    End With
  End If

  ' Response
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(FormInitialisationInfo, response)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Transaction Preview.
''' &lt;/summary&gt;
Public Function GetTransactionPreview(ByRef returnValue As String) As Boolean

  Dim AccountId As String
  Dim Pk As Integer
  Dim Success As Boolean

  ' NOTE: This preview is performed without the overhead of loading the Bank Batch and does not use the SummaryPage2_BatchBank_TransactionSummary Script

  ' Assume Success
  Success = True

  ' Parameters
  With mCombinedParameters
    AccountId = .GetString("AccountId")
    Pk = .GetInteger("Pk")
  End With

  ' Validate
  If Not finBL.CurrentUser.Permissions.Allow("Account.Form.Page.Transactions") Then
    Success = False
    finBL.Error.ErrorBegin("You do not have permission to view Account Transactions.")
  End If

  ' Get Preview
  If Success Then
    returnValue = finBL.SummaryPageFunctions.AccountTransactionSummaryByTransactionPk(False, AccountId, Pk, finBL.HtmlWidgetUtilities.CreateScriptContextData(ScriptInfo, FORM_KEY))
  Else
    returnValue = finBL.GetHtmlErrorMessage(finBL.Error.Message)
  End If

  Return Success

End Function

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

  ' General
  Public Heading As String
  Public Summary As String

  ' Batch Properties
  Public BatchId As String
  Public TransactionTypeId As String
  Public TransactionTypeDescription As String
  Public Notes As String

  ' Transactions
  Public DefaultIndex As Integer
  Public Transactions As New List(Of TransactionDetails)

  ' Configuration

End Class


Public Class TransactionDetails

  Public AccountId As String
  Public AccountName As String
  Public Credit As Decimal?
  Public [Date] As Date
  Public Debit As Decimal?
  Public ElementId As String
  Public Notes As String
  Public Pk As Integer
  Public Reference As String

  Public Sub New(finBL As ISfinSupport,
                 batchViewTransaction As finBatchViewTransaction)

    With batchViewTransaction
      Me.AccountId = .AccountId
      Me.AccountName = .AccountName
      Me.Date = finBL.HtmlWidgetUtilities.GetJsonUtcDateFromDatabaseDate(.Date)
      Me.ElementId = .ElementId
      Me.Notes = .Notes
      Me.Pk = .Pk
      Me.Reference = .Reference

      ' Value
      If .Value &lt; 0 Then
        Me.Debit = Nothing
        Me.Credit = -.Value
      ElseIf .Value &gt; 0 Then
        Me.Debit = .Value
        Me.Credit = Nothing
      ElseIf .ElementType = isefinElementType.Interest OrElse .ElementType = isefinElementType.InterestDefault Then
        Me.Debit = 0
        Me.Credit = Nothing
      Else
        Me.Debit = Nothing
        Me.Credit = Nothing
      End If
    End With

  End Sub

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

Used as a finPOWER Connect Cloud compatible version of the form "AccountTransactionView".</Notes>
    <PermissionKeyExecute />
    <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="tabDetails" class="is-tabs"&gt;
      &lt;ul&gt;
        &lt;li tabId="General"&gt;Details&lt;/li&gt;
      &lt;ul&gt;
    &lt;/div&gt;
  &lt;/header&gt;

  &lt;!-- Pages --&gt;
  &lt;div class="is-widget-form-body"&gt;
    &lt;!-- General --&gt;
    &lt;div id="pageGeneral"&gt;
      &lt;div style="display:flex; flex-direction:column; position:absolute; top:4px; left:4px; right:4px; bottom:4px"&gt;
        &lt;div style="flex-grow:0"&gt;
          &lt;table class="is-form"&gt;
            &lt;colgroup&gt;
              &lt;col style="width:6em" /&gt;
              &lt;col /&gt;
            &lt;/colgroup&gt;

            &lt;tbody id="tbBatchDetails"&gt;
              &lt;tr&gt;&lt;th colspan="2"&gt;&lt;label id="lblBatchDetails"&gt;Batch Details&lt;/label&gt;&lt;/th&gt;&lt;/tr&gt;
              &lt;tr&gt;
                &lt;th&gt;&lt;label for="txtBatchId"&gt;Batch:&lt;/label&gt;&lt;/th&gt;
                &lt;td&gt;&lt;input id="txtBatchId" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                &lt;th&gt;&lt;label for="cboTransactionType"&gt;Type:&lt;/label&gt;&lt;/th&gt;
                &lt;td&gt;&lt;input id="cboTransactionType" /&gt;&lt;/td&gt;
              &lt;/tr&gt;

              &lt;tr&gt;&lt;th colspan="2"&gt;&lt;label id="lblNotes"&gt;Notes&lt;/label&gt;&lt;/th&gt;&lt;/tr&gt;
              &lt;tr&gt;
                &lt;th&gt;&lt;label for="txtNotes"&gt;Notes:&lt;/label&gt;&lt;/th&gt;
                &lt;td&gt;&lt;input id="txtNotes" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
            &lt;/tbody&gt;

            &lt;tbody id="tbTransactions"&gt;
              &lt;tr&gt;&lt;th colspan="2"&gt;&lt;label id="lblTransactions"&gt;Transactions&lt;/label&gt;&lt;/th&gt;&lt;/tr&gt;
            &lt;/tbody&gt;
          &lt;/table&gt;
        &lt;/div&gt;
        &lt;div style="flex-grow:1; position:relative"&gt;

          &lt;div class="is-dock-fill is-split-container split5050"&gt;
            &lt;div class="panel"&gt;
              &lt;div id="gridTransactions"&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="panel"&gt;
              &lt;div id="wbTransactions" class="is-dock-fill"&gt;&lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;

        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

  &lt;/div&gt;

&lt;/div&gt;



&lt;script&gt;
// Properties
var mRecord;
var mRecord_Transactions;

// Controls
var C = {
  // General
  tbBatchDetails: null,
  lblBatchDetails: null,
  txtBatchId: null,
  cboTransactionType: null,

  lblNotes: null,
  txtNotes: null,

  tbTransactions: null,
  lblTransactions: null,

  gridTransactions: null,
  wbTransactions: null,
}

// Form
var frmMain;
var tabDetails;

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

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

  // --------
  // Controls
  // --------
  //   General
  C.tbBatchDetails = $("#tbBatchDetails");
  C.lblBatchDetails = widget.UI.Label("lblBatchDetails", {});
  C.txtBatchId = widget.UI.TextBox("txtBatchId", {
    autoReadOnly: false,
    readOnly: true,
    width: widget.UI.FIELD_WIDTH_CODE_20
  });
  C.cboTransactionType = widget.UI.DBCombo("cboTransactionType", {
    autoReadOnly: false,
    readOnly: true,
    showDropdown: false,
    width: widget.UI.FIELD_WIDTH_CODE_10
  });

  C.lblNotes = widget.UI.Label("lblNotes", {});
  C.txtNotes = widget.UI.TextBox("txtNotes", {
    autoReadOnly: false,
    readOnly: true,
    multiLine: true,
    rows: 3,
  });

  C.tbTransactions = $("#tbTransactions");
  C.lblTransactions = widget.UI.Label("lblTransactions", {});
  C.wbTransactions = widget.UI.PreviewPane("wbTransactions", {});

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

    onAfterRowActivate: gridTransactions_AfterRowActivate,
    onInitialiseRow: gridTransactions_InitialiseRow,
  });

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

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

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

  // Reset
  Form_Reset();
});

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

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

  // Resize
  Form_Resize();

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

// ===========
// Load Record
// ===========
function Record_Load() {
  // Initialise
  mRecord = null;
  mRecord_Transactions = 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_Transactions = mRecord.Transactions;

      Fields_Load();
    },

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

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // General
    C.txtBatchId.Text(mRecord.BatchId);
    C.cboTransactionType.RefreshUnbound(mRecord.TransactionTypeId, mRecord.TransactionTypeDescription);

    C.txtNotes.Text(mRecord.Notes);

    gridTransactions_Refresh();
  }

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

  // Update Controls

  // Update fields
  Fields_Update();

  // Refresh Tab
  tabDetails_Refresh(0);
}

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // Not used by this wizard since there is no concept of updating an object behind the wizard
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Form Heading
  if (mRecord) {
    frmMain.RefreshHeading(mRecord.Heading, mRecord.Summary);
  }

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

  // Controls
  if (mRecord) {
    if (mRecord.BatchId) {
      if (!mRecord.Notes) {
        C.lblNotes.VisibleRow(false);
        C.txtNotes.VisibleRow(false);
      }
    }
    else {
      C.tbBatchDetails.hide();
    }
  }

  // Show Summary
//  if (mRecord &amp;&amp; mRecord.ShowSummary) {
//    Form_ExecuteAction("Summary");
//  }

  // Resize Tab
  tabDetails_Resize();
}

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

  // Tab
  tabDetails_Resize();
}

// ==========
// Resize Tab
// ==========
function tabDetails_Resize() {
  switch (tabDetails.SelectedTabId()) {
    case "General":
      C.txtNotes.WidthResizeFromParent();
      break;

    default:
      break;
  }
}

// ===========
// Refresh Tab
// ===========
function tabDetails_Refresh(newTab) {
  // Moving forward onto tab, so Load information
  if (newTab &gt;= tabDetails.SelectedTabIndex()) {
    switch (tabDetails.GetTabIdByIndex(newTab)) {
      default:
        break;
    }
  }

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

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

// ================
// gridTransactions
// ================
function gridTransactions_Refresh() {
  // Add Columns
  C.gridTransactions.ClearColumns();
  C.gridTransactions.AddColumnCode("AccountId", { caption: "Account", width: widget.UI.FIELD_WIDTH_CODE_10 });
  C.gridTransactions.AddColumnCode("AccountName", { caption: "Name", width: "30%" });
  C.gridTransactions.AddColumnDate("Date", { caption: "Date" });
  C.gridTransactions.AddColumnString("Reference", { caption: "Reference", width: "6em" });
  C.gridTransactions.AddColumnString("ElementId", { caption: "Element", width: "6em" });
  C.gridTransactions.AddColumnCurrency("Debit", { caption: "Debit", summary: "sum" });
  C.gridTransactions.AddColumnCurrency("Credit", { caption: "Credit", summary: "sum" });
  C.gridTransactions.AddColumnString("Notes", { caption: "Notes", width: "30%" });

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

    o.accountId = item.AccountId;
    o.pk = item.Pk;

    o.target = "WebInternal";
    o.highDpi = widget.IsHighDpi();
    return o;
  };

  // Refresh
  C.gridTransactions.VirtualDataRefresh(mRecord_Transactions);

  // Activate First Row  
  if (mRecord.DefaultIndex) {
    C.gridTransactions.ActiveDataRowListIndex(mRecord.DefaultIndex);
  }
  else {
    C.gridTransactions.ActivateFirstDataRow();
  }  
}

function gridTransactions_InitialiseRow(e) {
  var item = mRecord_Transactions[e.row.listIndex];

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

  // Cell Styles
  e.row.cells.AccountName.small = true;
  e.row.cells.Notes.small = true;

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

function gridTransactions_AfterRowActivate(e) {
  // Preview
  wbTransactions_Preview();
}

// ==============
// wbTransactions
// ==============
function wbTransactions_Preview() {
  C.wbTransactions.PreviewFromGridCollection(C.gridTransactions, mRecord_Transactions, "GetTransactionPreview");
}

&lt;/script&gt;</TemplateText>
    <TemplateTextBookmarks />
    <TimeoutSeconds>60</TimeoutSeconds>
    <UniqueId>I19qKpWAC0G+WDNzeV5ESA</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption>Transaction View</Caption>
    <HtmlWidgetAllowInitialEventCaching>false</HtmlWidgetAllowInitialEventCaching>
    <HtmlWidgetMaxHeight>1200</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>1024</HtmlWidgetMaxWidth>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceChartsApex>false</HtmlWidgetResourceChartsApex>
    <HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <HtmlWidgetSpecialEventGetFolderCount>false</HtmlWidgetSpecialEventGetFolderCount>
    <Icon>Transaction_Entry</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>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="AccountTransactionPk" type="Number">
            <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>
            <DecimalPlaces>0</DecimalPlaces>
            <GroupDigits>true</GroupDigits>
            <MaxValue />
            <MinValue />
            <NumberSpecialType>None</NumberSpecialType>
            <SpinChange>1</SpinChange>
          </Parameter>
        </Parameters>
      </ISParameterDefs>
    </Parameters>
  </finScript>