As Jiwa 7 is a .NET product, there's a lot of scope for automating tasks in Jiwa using powershell.
As an example, here is a powershell script to import sales orders from a csv file, and send an email at the conclusion of the import.
- Code: Select all
## Script will import sales orders from a CSV file
## And at the conclusion will email a notification
## that the import completed.
## Load assemblies
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaApplication.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaLib.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaODBC.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaEncryption.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaJrnlPost.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaPriceSchemes.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaJobCosting.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaLock.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaSales.dll")
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaSendEmail.dll")
## Create new JiwaApplication Manager, and login
$appman = [JiwaFinancials.Jiwa.JiwaApplication.Manager]::Instance
$appman.Logon("JiwaMike", "JiwaDemo", 1, "Admin", "password")
## Get the business logic factory, which we will need later to create business logic objects
$factory = $appman.BusinessLogicFactory
$method = [JiwaFinancials.Jiwa.JiwaApplication.BusinessLogicFactory].GetMethod("CreateBusinessLogic")
## Load a sales order
## Using the business logic factory is not very intuitive in powershell as it uses a generic, and poweshell makes you jump through a few hoops
$closedMethod = $method.MakeGenericMethod([JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder])
$salesorder = $closedMethod.Invoke($factory, $null)
## $salesorder.Find(4, "SO_Main.InvoiceNo", "", "")
## Sample CSV
##OrderNo,OrderDate,DebtorAccountNo,PartNo,QuantityOrdered,PriceExGST
##000100,2006-05-30,1001,1170,5,15.45
##000100,2006-05-30,1001,1171,5,15.45
##000100,2006-05-30,1001,1172,5,15.45
##000100,2006-05-30,1001,1173,5,15.45
##000101,2006-06-01,1002,1170,5,15.45
##000101,2006-06-01,1002,1171,5,15.45
##000101,2006-06-01,1002,1172,5,15.45
##000102,2006-06-02,1003,1173,5,15.45
$csv = Import-Csv "C:\users\mikes\documents\sample.txt"
$previousOrderNo = ""
$newKey = ""
$InvoiceNos = @()
foreach ($line in $csv) {
if ($previousOrderNo -ne $line.OrderNo) {
#if the order no. has changed, then we've finished adding to this order - save and move on.
If ($salesorder.InsertFlag) {
$salesorder.Save()
$InvoiceNos += $salesorder.InvoiceNo
}
#$salesorder.CreateNew(0, $line.DebtorAccountNo, 1, "", "", "", "")
$salesorder.CreateNew(0, $line.DebtorAccountNo, $null, $null, $null, $null, $null)
$salesorder.OrderNo = $line.OrderNo
$salesorder.InitiatedDate = $line.OrderDate
}
$salesOrder.SalesOrderLines.AddInventoryItem($line.PartNo, 1, [ref]$newKey, $null, 0)
$salesOrderLine = $salesOrder.SalesOrderLines[$newKey]
$salesOrderLine.QuantityOrdered = $line.QuantityOrdered
$salesOrderLine.DiscountedPrice = $line.PriceExGST
$previousOrderNo = $line.OrderNo
}
If ($salesorder.InsertFlag) {
$salesorder.Save()
$InvoiceNos += $salesorder.InvoiceNo
}
#send an email
$closedMethod = $method.MakeGenericMethod([JiwaFinancials.Jiwa.JiwaApplication.JiwaEmail.EmailMessage])
$mail = $closedMethod.Invoke($factory, $null)
$mail.CreateNew()
$mail.EmailTo = "[email protected]"
$mail.EmailSubject = "Sales Order Import Completed"
$body = "The following sales orders were imported:"
$body += $InvoiceNos | out-string
$mail.EmailBody = $body
#By default the mail status is "sent" so that when you save the email, it will attempt to send it.
#You can opt to set the status to "ready to send", and have another process send it - if desired.
#Note that the transport mechanism is controlled by the Jiwa system settings - You can opt to send directly (not recommended), via relay server (recommended) or by using a locally installed Outlook instance.
$mail.Save()