Hi Stuart,
My apologies for the delayed reply - things got away from me the last week.
Below is a code snippet you should put in the ScheduledExecutionPlugin class of your plugin. You will need to add a reference to JiwaJournalSets.dll if your plugin does not already have that reference.
The example is not tested, but should serve as a guide on how to connect to the wages database from within the plugin, query the wages tables, construct a pending journal and send a todo notification. If you have any further questions or issues, please don't hesitate to ask.
Mike
- Code: Select all
Public Sub Execute(ByVal Plugin As JiwaApplication.Plugin.Plugin, ByVal Schedule As JiwaApplication.Schedule.Schedule) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.Execute
Dim WagesSQLConnection As SqlClient.SqlConnection
Try
' Create a connection to the Wages SQL database
Dim connStringBuilder As New SqlConnectionStringBuilder()
With connStringBuilder
.DataSource = "SQLServerName" ' Can also use JiwaApplication.Manager.Instance.Database.ServerName if it is always the same server as the where the jiwa db resides
.InitialCatalog = "WagesDB"
.UserID = "SQLUser"
.Password = "password"
.MultipleActiveResultSets = True
.ApplicationName = "Jiwa Financials"
.ApplicationIntent = ApplicationIntent.ReadWrite
End With
WagesSQLConnection = New System.Data.SqlClient.SqlConnection(connStringBuilder.ToString)
WagesSQLConnection.Open
Dim WagesSQL As String = "SELECT ?" ' This is the query to get the data from the wages database.
Using WagesSQLCmd As SqlCommand = New SqlCommand(WagesSQL, WagesSQLConnection)
Dim WagesSQLReader As SqlDataReader = WagesSQLCmd.ExecuteReader()
Do While WagesSQLReader.Read = True
' Use WagesSQLReader(0) to get first field from the query results, WagesSQLReader(1) to get the second, etc
Dim journalSet As JiwaJournalSets.JournalSet = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaJournalSets.JournalSet)(Nothing)
journalSet.CreateNew
journalSet.SetType = JiwaJournalSets.JournalSet.SetTypes.Pending
journalSet.PostedDate = Now
journalSet.Description = "Test wages journal set 123"
Dim journalLine As JiwaJournalSets.Line
journalLine = New JiwaJournalSets.Line
journalLine.GLAccount.ReadRecordFromAccountNo("4140-200-00") ' Wages NSW
journalLine.DebitAmount = 100
journalLine.Reference = "123"
journalLine.Remark = "Wages"
journalSet.Lines.Add(journalLine)
journalLine = New JiwaJournalSets.Line
journalLine.GLAccount.ReadRecordFromAccountNo("4140-200-00") ' Superannuation NSW
journalLine.DebitAmount = 115
journalLine.Reference = "123"
journalLine.Remark = "Superannuation"
journalSet.Lines.Add(journalLine)
journalLine = New JiwaJournalSets.Line
journalLine.GLAccount.ReadRecordFromAccountNo("6000-200-00") ' Cash On Hand NSW
journalLine.CreditAmount = 215
journalLine.Reference = "123"
journalLine.Remark = "Cash on Hand"
journalSet.Lines.Add(journalLine)
journalSet.Save()
Dim toDo As JiwaApplication.JiwaToDos.ToDo = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaApplication.JiwaToDos.ToDo)(Nothing)
toDo.CreateNew
toDo.AssignedTo.ReadRecordByUsername("mikes")
toDo.Body = String.Format("Wages Journal Set {0} created.", journalSet.SetNo)
toDo.ReminderPredefinedSetting = JiwaApplication.JiwaToDos.ToDo.ReminderPredefinedSettingType.WhenDue
toDo.ReminderSpecificDateTime = Now
toDo.ReminderEnabled = True
toDo.Save()
Loop
If Not WagesSQLReader Is Nothing Then
WagesSQLReader.Close()
WagesSQLReader = Nothing
End If
End Using
Finally
If Not (WagesSQLConnection Is Nothing) Then
If WagesSQLConnection.State <> System.Data.ConnectionState.Closed Then
WagesSQLConnection.Close()
End If
End If
End Try
End Sub