To consume Financial Transaction service, the software developers need to consume 4 entities; FinancialHeader, FinancialLine, FinancialBankStatement, FinancialPaymentTerms. All 4 entities make up the Financial Transaction service.
This document provides a step-by-step guide to do this using Microsoft Visual Studio 2008 as an example.
Not applicable.
Open Microsoft Visual Studio 2008.
Create a new project with the following information:
Add a service reference to the FinancialHeader service:
FinancialLine
Open the Form1 class in the Designer window.
Open the Form1 class in the Code Editor window and add the following code:
Private headerClient As New EntityFinancialHeader.FinancialHeaderClient
Private lineClient As New EntityFinancialLine.FinancialLineClient
Private bankClient As New EntityFinancialBankStatement.FinancialBankStatementClient
Private termClient As New EntityFinancialPaymentTerm.FinancialPaymentTermClient
Private headerData As EntityFinancialHeader.FinancialHeaderData
Private lineData As EntityFinancialLine.FinancialLineData
Private bankData As EntityFinancialBankStatement.FinancialBankStatementData
Private termData As EntityFinancialPaymentTerm.FinancialPaymentTermData
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
headerClient.ClientCredentials.Windows.AllowedImpersonationLevel = Security.Principal.TokenImpersonationLevel.Impersonation
lineClient.ClientCredentials.Windows.AllowedImpersonationLevel = Security.Principal.TokenImpersonationLevel.Impersonation
bankClient.ClientCredentials.Windows.AllowedImpersonationLevel = Security.Principal.TokenImpersonationLevel.Impersonation
termClient.ClientCredentials.Windows.AllowedImpersonationLevel = Security.Principal.TokenImpersonationLevel.Impersonation
End Sub
headerClient.ChannelFactory.Credentials.Windows.ClientCredential = New System.Net.NetworkCredential("username", "password", "exact-software")
lineClient.ChannelFactory.Credentials.Windows.ClientCredential = New System.Net.NetworkCredential("username", "password", "exact-software")
bankClient.ChannelFactory.Credentials.Windows.ClientCredential = New System.Net.NetworkCredential("username", "password", "exact-software")
Private Sub CreateEntity(Optional ByVal UseSave As Boolean = False)
Dim transKey As Guid
Dim entryNo As String = ""
Dim isProcessed As Boolean = rdProcessed.Checked
'lineData 1
lineData = New EntityFinancialLine.FinancialLineData()
With lineData
.IsProcessed = New EntityFinancialLine.EntityBoolean With {.Value = isProcessed, .IsDirty = True}
.CompanyCode = New EntityFinancialLine.EntityString With {.Value = "001", .IsDirty = True}
.TransactionType = New EntityFinancialLine.EntityInteger With {.Value = 6, .IsDirty = True}
.ProcessLine = New EntityFinancialLine.EntityString With {.Value = " 1", .IsDirty = True}
.TransType = New EntityFinancialLine.EntityString With {.Value = "N", .IsDirty = True}
.TransactionSubType = New EntityFinancialLine.EntityString With {.Value = "Y", .IsDirty = True}
.ProcessLineCode = New EntityFinancialLine.EntityString With {.Value = "A", .IsDirty = True}
.TransactionDate = New EntityFinancialLine.EntityDateTime With {.Value = dtTransDate.Value, .IsDirty = True}
.Creditor = New EntityFinancialLine.EntityString With {.Value = "10004", .IsDirty = True}
.CompanyAccountCode = New EntityFinancialLine.EntityString With {.Value = "1100", .IsDirty = True}
.CurrencyCode = New EntityFinancialLine.EntityString With {.Value = "EUR", .IsDirty = True}
.ForeignCurrencyDebitAmount = New EntityFinancialLine.EntityInteger With {.Value = 0, .IsDirty = True}
.ForeignCurrencyCreditAmount = New EntityFinancialLine.EntityInteger With {.Value = 3800, .IsDirty = True}
.Rate = New EntityFinancialLine.EntityInteger With {.Value = 1, .IsDirty = True}
.OriginOfTransaction = New EntityFinancialLine.EntityString With {.Value = "A", .IsDirty = True}
.OriginOfEntry = New EntityFinancialLine.EntityString With {.Value = "N", .IsDirty = True}
.PaymentMethod = New EntityFinancialLine.EntityString With {.Value = "B", .IsDirty = True}
.ProcessNumber = New EntityFinancialLine.EntityInteger With {.Value = 1, .IsDirty = True}
.JournalPostingNumber = New EntityFinancialLine.EntityInteger With {.Value = 1, .IsDirty = True}
End With
Try
If UseSave Then
lineData = lineClient.Save(lineData)
Else
lineData = lineClient.Create(lineData)
End If
Catch ex As Exception
MessageBox.Show("Financial lineData Entity - Create failed: " & ex.Message)
End Try
transKey = lineData.TransactionKey.Value
'lineData 2
.TransactionKey = New EntityFinancialLine.EntityGuid With {.Value = transKey, .IsDirty = True}
.TransactionSubType = New EntityFinancialLine.EntityString With {.Value = "T", .IsDirty = True}
.ProcessLineCode = New EntityFinancialLine.EntityString With {.Value = "B", .IsDirty = True}
.CompanyAccountCode = New EntityFinancialLine.EntityString With {.Value = "7000", .IsDirty = True}
.ForeignCurrencyDebitAmount = New EntityFinancialLine.EntityInteger With {.Value = 3800, .IsDirty = True}
.ForeignCurrencyCreditAmount = New EntityFinancialLine.EntityInteger With {.Value = 0, .IsDirty = True}
'Create header
headerData = New EntityFinancialHeader.FinancialHeaderData
With headerData
.TransactionKey = New EntityFinancialHeader.EntityGuid With {.Value = transKey, .IsDirty = True}
.IsProcessed = New EntityFinancialHeader.EntityBoolean With {.Value = isProcessed, .IsDirty = True}
headerData = headerClient.Save(headerData)
headerData = headerClient.Create(headerData)
Private Sub btnCreatePend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreatePend.Click
If CreateEntity() Then
SetMessage("Financial Transaction Created")
SetMessage("Financial Transaction Create: Failed", False)
If CreateEntity(True) Then
SetMessage("Financial Transaction Save: Success")
SetMessage("Financial Transaction Save: Failed", False)
Private Sub btnUpdatePend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdatePend.Click
Dim transKey As Guid = Guid.NewGuid
btnRetrievePend_Click(sender, e)
For Each line As EntityFinancialLine.FinancialLineData In lineDataArray
line.Description = New EntityFinancialLine.EntityString With {.Value = "update", .IsDirty = True}
line.TransactionKey = New EntityFinancialLine.EntityGuid With {.Value = transKey, .IsDirty = True}
line.EntryNumber = New EntityFinancialLine.EntityString With {.Value = txtEntryNumber.Text, .IsDirty = True}
line.FinancialYear = New EntityFinancialLine.EntityInteger With {.Value = CInt(txtFinYear.Text), .IsDirty = True}
line.FinancialPeriod = New EntityFinancialLine.EntityString With {.Value = txtFinPeriod.Text, .IsDirty = True}
lineClient.Update(line)
Next
.EntryNumber = New EntityFinancialHeader.EntityString With {.Value = txtEntryNumber.Text, .IsDirty = True}
.FinancialYear = New EntityFinancialHeader.EntityInteger With {.Value = CInt(txtFinYear.Text), .IsDirty = True}
.FinancialPeriod = New EntityFinancialHeader.EntityString With {.Value = txtFinPeriod.Text, .IsDirty = True}
headerClient.Update(headerData)
MessageBox.Show("Update Failed: " & ex.Message)
Return
SetMessage("Update Successfull", False)
Private Sub btnRetrievePend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetrievePend.Click
Dim statusText As StringBuilder
If (Len(txtEntryNumber.Text) = 0) OrElse (Len(txtFinPeriod.Text) = 0) OrElse (Len(txtFinYear.Text) = 0) Then
SetMessage("EntryNumber, FinancialYear and FinancialPeriod are Mandatory", False)
.IsProcessed = New EntityFinancialHeader.EntityBoolean With {.Value = rdProcessed.Checked, .IsDirty = True}
headerData = headerClient.Retrieve(headerData)
MessageBox.Show("Financial header Data Entity - Retrieve failed: " & ex.Message)
SetMessage("Unable to find data", False)
statusText = New StringBuilder
statusText.AppendLine("FinancialTransaction Entity Retrieved:-")
If (Not headerData.LineIDs.IsNothing) AndAlso (Len(headerData.LineIDs.Value) > 0) Then
Dim IDs() As String = headerData.LineIDs.Value.Split(",")
lineDataArray = New List(Of EntityFinancialLine.FinancialLineData)
For i As Integer = 0 To UBound(IDs)
lineDataArray.Add(New EntityFinancialLine.FinancialLineData)
lineDataArray(i).ID = New EntityFinancialLine.EntityInteger With {.Value = CInt(IDs(i)), .IsDirty = True}
lineDataArray(i).IsProcessed = New EntityFinancialLine.EntityBoolean With {.Value = rdProcessed.Checked, .IsDirty = True}
lineDataArray(i) = lineClient.Retrieve(lineDataArray(i))
MessageBox.Show("Financial Line Entity - Retrieve failed: " & ex.Message)
statusText.AppendLine("Financial Line, ID: " & IDs(i))
If (Not headerData.BankIDs.IsNothing) AndAlso (Len(headerData.BankIDs.Value) > 0) Then
Dim IDs() As String = headerData.BankIDs.Value.Split(",")
bankData = New EntityFinancialBankStatement.FinancialBankStatementData
bankData.ID = New EntityFinancialBankStatement.EntityInteger With {.Value = CInt(IDs(i)), .IsDirty = True}
bankData = bankClient.Retrieve(bankData)
statusText.AppendLine("Bank Statement, ID: " & bankData.ID.Value.ToString)
If (Not headerData.PaymentIDs.IsNothing) AndAlso (Len(headerData.PaymentIDs.Value) > 0) Then
Dim IDs() As String = headerData.PaymentIDs.Value.Split(",")
termData = New EntityFinancialPaymentTerm.FinancialPaymentTermData
termData.ID = New EntityFinancialPaymentTerm.EntityInteger With {.Value = CInt(IDs(i)), .IsDirty = True}
termData = termClient.Retrieve(termData)
statusText.AppendLine("Financial Line, EntryGuid: " & termData.ID.Value.ToString)
SetMessage(statusText.ToString)
Private Sub btnDeletePend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeletePend.Click
headerClient.Delete(headerData)
MessageBox.Show("Delete Failed: " & ex.Message)
SetMessage("Entity Deleted", False)
Private Sub btnOpenNewPend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenNewPend.Click
Dim statusText As New StringBuilder
lineData = New EntityFinancialLine.FinancialLineData
headerData = headerClient.OpenNew(headerData)
MessageBox.Show("OpenNew Failed: " & ex.Message)
statusText.AppendLine("Default values retrieved for FinancialHeader Entity.")
lineData = lineClient.OpenNew(lineData)
statusText.AppendLine("Default values retrieved for FinancialLine Entity.")
bankData = bankClient.OpenNew(bankData)
statusText.AppendLine("Default values retrieved for FinancialBankStatement Entity.")
termData = termClient.OpenNew(termData)
statusText.AppendLine("Default values retrieved for FinancialPaymentTerm Entity.")
Private Sub btnValidatePend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidatePend.Click
line = lineClient.Validate(line)
MessageBox.Show("Validation Failed: " & ex.Message)
SetMessage("Validation Passed")
You can also add a Try-Catch statement to catch the fault exception during the CRUDOVS operations.
Exception:
MessageBox.Show("Error Occurred :" & ex.Message, "Entity Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Fault Exception:
In order to use fault exception, you need to import <System.ServiceModel> by adding the following line at the beginning of your code: Imports System.ServiceModel
Create a standard fault exception handling function using the code as below:
Private Sub ShowError(ByVal exc As Object)
Dim fe As Object
Select Case True
Case InStr(exc.GetType.ToString, "EntityBinary")
fe = DirectCast(exc, FaultException(Of EntityBinary.EntityFault))
Case InStr(exc.GetType.ToString, "EntityDocumentAttachment")
fe = DirectCast(exc, FaultException(Of EntityDocumentAttachment.EntityFault))
End Select
Dim sb As New System.Text.StringBuilder
sb.AppendLine("An error has occured!")
sb.AppendLine("")
sb.AppendFormat("{0}: [{1}]" & vbCrLf, "Exception Type", fe.Code.Name)
sb.AppendFormat("{0}: [{1}]" & vbCrLf, "Exception Message", fe.Message)
If Not IsNothing(fe.Detail.Exceptions) AndAlso UBound(fe.Detail.Exceptions) > -1 Then
For Each info In fe.Detail.Exceptions
With sb
.AppendFormat("{0}: [{1}]" & vbCrLf, "Property", info.PropertyName)
.AppendFormat("{0}: [{1}]" & vbCrLf, "Message", info.Message)
.AppendLine("")
MessageBox.Show(sb.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch fe As FaultException
ShowError(fe)
: