﻿<?xml version="1.0" encoding="utf-16"?>
<JiwaDocument xmlns:jiwa="http://www.jiwa.com.au/xml/schemas" Type="JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin">
  <RecID>07873cd2-2918-4c5b-ba61-1cdbd7c1c9a1</RecID>
  <Name>Franklin - Unlock sales order user defined fields</Name>
  <Description>Unlocks user defined fields on the sales order to allow user input.</Description>
  <IsEnabled>true</IsEnabled>
  <IsIsolatedToOwnAppDomain>false</IsIsolatedToOwnAppDomain>
  <ExecutionOrder>0</ExecutionOrder>
  <Author>Jiwa Financials</Author>
  <Version>7.0.149.0</Version>
  <Code>Imports JiwaFinancials.Jiwa
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Diagnostics
Imports System.Drawing
Imports System.Data
Imports System.IO
Imports System.Net.Mail
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates

Public Class FormPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaFormPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function
	
	Dim globalForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = Nothing

    Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
		If TypeOf JiwaForm Is JiwaSalesUI.SalesOrder.SalesOrderEntryForm Then
			
			Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(jiwaform, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
			
			AddHandler salesOrderForm.UltraToolbarsManager1.ToolClick, AddressOf SalesOrder_UltraToolbarsManager1_ToolClick
			
		End If
    End Sub
	
	Private Sub SalesOrder_UltraToolbarsManager1_ToolClick(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs)
	    If e.Tool.Key.ToString() = "ID_RecordProcess" Then
			Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(sender, Infragistics.Win.UltraWinToolbars.UltraToolbarsManager).DockWithinContainer
			
			Dim salesOrder As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder = salesOrderForm.SalesOrder
			
			Dim backOrder As Boolean = False
			
			For Each item As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine In salesOrder.SalesOrderLines
				
				If item.QuantityBackOrdered &gt; 0 Then
					backOrder = True
				End If
				
			Next
			
			If backOrder Then
				If MsgBox("There are items in back order. Do want to process anyway?", MsgBoxStyle.YesNo, "Sales Order - Items in Back Order") = MsgBoxResult.No Then
					Throw New JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException
				End If
			End If
			
		End If
		
	End Sub
	
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
		If TypeOf JiwaForm Is JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm Then			
			Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
			' Store a reference to this sales order form in the business logic
			Dim formReference As New JiwaApplication.BusinessLogic.GenericObjectItem 
			formReference.RecID = "SalesOrderForm"
			formReference.Object = salesOrderForm
			salesOrderForm.SalesOrder.GenericObjectCollection.Add(formReference)
			
			globalForm = salesOrderForm
			
			For Each form As JiwaApplication.IJiwaForm In salesOrderForm.OwnedForms
				MessageBox.Show(form.Form.Name)
			Next
			
			' Add a handler for the read end and create end
			AddHandler salesOrderForm.Load, AddressOf SalesOrder_Load
			AddHandler salesOrderForm.SalesOrder.ReadEnd, AddressOf SalesOrder_ReadEnd
			AddHandler salesOrderForm.SalesOrder.ProcessingStart, AddressOf SalesOrder_ProcessingStart
			AddHandler salesOrderForm.SalesOrder.ProcessingEnd, AddressOf SalesOrder_ProcessingEnd
			AddHandler salesOrderForm.SalesOrder.SaveStart, AddressOf SalesOrder_SaveStart
			AddHandler salesOrderForm.SalesOrder.SaveEnding, AddressOf SalesOrder_SaveEnd
			AddHandler salesOrderForm.SalesOrder.SalesOrderLineRemoved, AddressOf SalesOrder_SalesOrderLineRemoved
			AddHandler salesOrderForm.SalesOrder.SalesOrderLineAdding, AddressOf SalesOrder_SalesOrderLineAdding
			AddHandler salesOrderForm.SalesOrder.Printed, AddressOf SalesOrder_Printed
			AddHandler salesOrderForm.SalesOrder.CustomFieldValues.Changed, AddressOf SalesOrder_CustomFieldValuesChanged
			AddHandler salesOrderForm.SalesOrder.CreateEnd, AddressOf SalesOrder_Created
		End If
    End Sub
	
	Private Sub SalesOrderHistory_PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs)
		
		Dim salesOrderHistory As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderHistory = sender
		
		If e.PropertyName = "DatePosted" Then
			
			Dim overrideInvoiceDate As Boolean = False
					
			' Look for the OverrideInvoiceDate Custom Field and sets its value
			For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In globalForm.SalesOrder.CustomFieldValues	
				If customFieldValue.CustomField.PluginCustomField.Name = "OverrideInvoiceDate" Then
					If customFieldValue.Contents = "True" Then
						overrideInvoiceDate = True
					End If
					
					Exit For
				End If
			Next
			
			If overrideInvoiceDate = True Then
			
				For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In globalForm.SalesOrder.CustomFieldValues	
					If customFieldValue.CustomField.PluginCustomField.Name = "DefaultInitiatedDate" Then
							
						If customFieldValue.Contents IsNot Nothing AndAlso customFieldValue.Contents.Length &gt; 0 Then
						
							Dim SQLParam As SqlClient.SqlParameter = Nothing
							Dim SQL As String = "UPDATE SO_History SET DatePosted = @DatePosted, RecordDate = @RecordDate WHERE InvoiceHistoryID = @InvoiceHistoryID"
														
							Using SQLCmd As SqlCommand = New SqlCommand(SQL, JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.SQLConnection, JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.SQLTransaction)
								SQLParam = New SqlParameter("@DatePosted", System.Data.SqlDbType.DateTime)
					        	SQLParam.Value = System.Convert.ToDateTime(customFieldValue.Contents)
					        	SQLCmd.Parameters.Add(SQLParam)
								
								SQLParam = New SqlParameter("@RecordDate", System.Data.SqlDbType.DateTime)
					        	SQLParam.Value = System.Convert.ToDateTime(customFieldValue.Contents)
					        	SQLCmd.Parameters.Add(SQLParam)
								
								SQLParam = New SqlParameter("@InvoiceHistoryID", System.Data.SqlDbType.Char)
					        	SQLParam.Value = salesOrderHistory.RecID
					        	SQLCmd.Parameters.Add(SQLParam)
								
								SQLCmd.ExecuteNonQuery()
								
								SQLCmd.Dispose()
								
							End Using
							
						End If
						
						Exit For
						
					End If
				Next
			
			End If
			
		End If
		
	End Sub
	
	Private Sub SalesOrder_ProcessingStart(ByVal sender As Object, ByVal e As System.EventArgs)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = sender
		
		Dim salesOrderHistory As JiwaSales.SalesOrder.SalesOrderHistory = salesOrder.SalesOrderHistorys(salesOrder.SelectedHistoryNo)
		
		Dim overrideInvoiceDate As Boolean = False
					
		For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In salesOrder.CustomFieldValues	
			If customFieldValue.CustomField.PluginCustomField.Name = "OverrideInvoiceDate" Then
				If customFieldValue.Contents = "True" Then
					overrideInvoiceDate = True
				End If
				
				Exit For
			End If
		Next
		
		If overrideInvoiceDate = True Then
		
			For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In salesOrder.CustomFieldValues	
				If customFieldValue.CustomField.PluginCustomField.Name = "DefaultInitiatedDate" Then
						
					If customFieldValue.Contents IsNot Nothing AndAlso customFieldValue.Contents.Length &gt; 0 Then
					
						salesOrderHistory.RecordDate = System.Convert.ToDateTime(customFieldValue.Contents)
						salesOrderHistory.DatePosted = System.Convert.ToDateTime(customFieldValue.Contents)
						salesOrderHistory.SaveRecord()
						
					Else
						
						salesOrderHistory.RecordDate = System.DateTime.Now
						salesOrderHistory.DatePosted = System.DateTime.Now
						salesOrderHistory.SaveRecord()
						
					End If
					
					Exit For
				End If
			Next
		
		Else 
			
			salesOrderHistory.RecordDate = System.DateTime.Now
			salesOrderHistory.DatePosted = System.DateTime.Now
			salesOrderHistory.SaveRecord()
			
		End If
		
	End Sub
	
	Private Sub SalesOrder_ProcessingEnd(ByVal sender As Object, ByVal e As System.EventArgs)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = sender
		Dim overrideInvoiceDate As Boolean = False
					
		For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In salesOrder.CustomFieldValues	
			If customFieldValue.CustomField.PluginCustomField.Name = "OverrideInvoiceDate" Then
				If customFieldValue.Contents = "True" Then
					overrideInvoiceDate = True
				End If
				
				Exit For
			End If
		Next
		
		If overrideInvoiceDate = True Then
		
			For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In salesOrder.CustomFieldValues	
				If customFieldValue.CustomField.PluginCustomField.Name = "DefaultInitiatedDate" Then
						
					If customFieldValue.Contents IsNot Nothing AndAlso customFieldValue.Contents.Length &gt; 0 Then
					
						Dim salesOrderHistory As JiwaSales.SalesOrder.SalesOrderHistory = salesOrder.SalesOrderHistorys(salesorder.SelectedHistoryNo)
						
						Dim SQLParam As SqlClient.SqlParameter = Nothing
						Dim SQL As String = "UPDATE DB_Trans SET TranDate = @TranDate WHERE TransID = @TransID "
													
						Using SQLCmd As SqlCommand = New SqlCommand(SQL, JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.SQLConnection, JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.SQLTransaction)
							SQLParam = New SqlParameter("@TransID", System.Data.SqlDbType.Char)
				        	SQLParam.Value = salesOrderHistory.DBTransID
				        	SQLCmd.Parameters.Add(SQLParam)
							
							SQLParam = New SqlParameter("@TranDate", System.Data.SqlDbType.DateTime)
				        	SQLParam.Value = System.Convert.ToDateTime(customFieldValue.Contents)
				        	SQLCmd.Parameters.Add(SQLParam)
							
							SQLCmd.ExecuteNonQuery()
							
							SQLCmd.Dispose()
							
						End Using
					
					End If
					
					Exit For
				End If
			Next
		
		Else
					
			Dim salesOrderHistory As JiwaSales.SalesOrder.SalesOrderHistory = salesOrder.SalesOrderHistorys(salesorder.SelectedHistoryNo)
				
			Dim SQLParam As SqlClient.SqlParameter = Nothing
			Dim SQL As String = "UPDATE DB_Trans SET TranDate = @TranDate WHERE TransID = @TransID "
										
			Using SQLCmd As SqlCommand = New SqlCommand(SQL, JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.SQLConnection, JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.SQLTransaction)
				SQLParam = New SqlParameter("@TransID", System.Data.SqlDbType.Char)
	        	SQLParam.Value = salesOrderHistory.DBTransID
	        	SQLCmd.Parameters.Add(SQLParam)
				
				SQLParam = New SqlParameter("@TranDate", System.Data.SqlDbType.DateTime)
	        	SQLParam.Value = System.DateTime.Now
	        	SQLCmd.Parameters.Add(SQLParam)
				
				SQLCmd.ExecuteNonQuery()
				
				SQLCmd.Dispose()
				
			End Using
			
		End If
	End Sub
	
	Private Sub SalesOrder_Created(ByVal sender As Object, ByVal e As System.EventArgs)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrder.GenericObjectCollection("SalesOrderForm").Object, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
		
		If salesOrder.Debtor.Name.Length &gt; 0 Then
			
			Dim debtor As JiwaSales.SalesOrder.Debtor = New JiwaSales.SalesOrder.Debtor
			
			debtor.ReadRecord(salesOrder.Debtor.RecID)
			
			If Not IsNothing(debtor) And debtor.Name.Length &gt; 0 Then
				
				If debtor.Classification.RecID &lt;&gt; "73668026d47f4f14a177" Then
					
					For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In salesOrder.CustomFieldValues
					
						If customFieldValue.CustomField.PluginCustomField.Name = "PrintInUSD" Then
							
							customFieldValue.Contents = "True"
							Exit For
							
						End If
						
					Next					
					
				End If
				
			End If
			
			
		End If
		
		If JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.Description = "Karratha" Then
			salesOrder.Branch.ReadRecord("571d4f70967944f4b8c7")
			salesOrder.PriceScheme.Read("618f8685f41f4945ada2")
		Else If JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.Description = "Darwin" Then
			salesOrder.Branch.ReadRecord("270e29af0d8a450a971e")
			salesOrder.PriceScheme.Read("fa6cc19d4c5d4bdbb6b7")
		Else
			salesOrder.Branch.ReadRecord("ZZZZZZZZZZ0000000000")
			salesOrder.PriceScheme.Read("6799bc053a4e4d7b8f96")
		End If
		
	End Sub
	
	Private Sub SalesOrder_CustomFieldValuesChanged(item As JiwaApplication.CustomFields.CustomFieldValue, e As System.EventArgs)
		
		If globalForm IsNot Nothing AndAlso item.Contents IsNot Nothing AndAlso item.Contents.Length &gt; 0 Then
			
			If item.CustomField.PluginCustomField.Name = "PrintInUSD" Then
				
				If item.Contents IsNot Nothing AndAlso item.Contents.Length &gt; 0 Then
				
					For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In globalForm.SalesOrder.CustomFieldValues
						
						If customFieldValue.CustomField.PluginCustomField.Name = "USDExchangeRate" Then
							
							If System.Convert.ToBoolean(item.Contents) = True AndAlso globalForm.SalesOrder.Debtor.RecID.Length &gt; 0 Then
								
								Dim debtor As JiwaSales.SalesOrder.Debtor = New JiwaSales.SalesOrder.Debtor
			
								debtor.ReadRecord(globalForm.SalesOrder.Debtor.RecID)
			
								Dim SQLParam As SqlClient.SqlParameter = Nothing
								Dim SQLReader As SqlDataReader = Nothing
								Dim SQL As String = ""
								
								With JiwaApplication.Manager.Instance.Database 
									Try
										SQL = "usp_Franklin_SalesOrder_GetCurrentExchangeRate"
											
										Using SQLCmd As SqlCommand = New SqlCommand(SQL, .SQLConnection, .SQLTransaction)
											SQLParam = New SqlParameter("@ActualDate", System.Data.SqlDbType.DateTime)
						                	SQLParam.Value = System.DateTime.Today.ToString("yyyy-MM-dd")
						                	SQLCmd.Parameters.Add(SQLParam)
											
											SQLParam = New SqlParameter("@ShortName", System.Data.SqlDbType.VarChar)
						                	SQLParam.Value = debtor.Classification.Description.Split(" ")(0)
						                	SQLCmd.Parameters.Add(SQLParam)
											
											SQLCmd.CommandType = CommandType.StoredProcedure
											
											SQLReader = SQLCmd.ExecuteReader()
											
											While SQLReader.Read
												If Not IsNothing(.Sanitise(SQLReader, "TransactionRate")) And .Sanitise(SQLReader, "TransactionRate").ToString().Length &gt; 0 Then
													customFieldValue.Contents = .Sanitise(SQLReader, "TransactionRate")
												End If
											End While
										End Using
											
										SQLReader.Close()
									Finally
										If Not SQLReader Is Nothing Then
											SQLReader.Close()
										End If
									End Try
								End With
								
							Else
								customFieldValue.Contents = ""
							End If
							
							Exit For
							
						End If
						
					Next
				
				End If
				
			Else If item.CustomField.PluginCustomField.Name = "OverrideInvoiceDate" Then
				
				If globalForm.SalesOrder.InvoiceNo.Length &gt; 0 Then
				
					Dim salesOrderHistory As JiwaSales.SalesOrder.SalesOrderHistory = globalForm.SalesOrder.SalesOrderHistorys(globalForm.SalesOrder.SelectedHistoryNo)
					
					For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In globalForm.SalesOrder.CustomFieldValues
					
					If customFieldValue.CustomField.PluginCustomField.Name = "DefaultInitiatedDate" Then
						
						If System.Convert.ToBoolean(item.Contents) = True Then
					
							If customFieldValue.Contents IsNot Nothing Then
								customFieldValue.Contents = System.DateTime.Today.ToString("dd/MM/yyyy")
								salesOrderHistory.DatePosted = System.DateTime.Today.ToString("dd/MM/yyyy")
							End If
							
						Else
							
							customFieldValue.Contents = ""
							salesOrderHistory.DatePosted = System.DateTime.Today.ToString("dd/MM/yyyy")
							
						End If
						
						Exit For
						
					End If
						
					Next
				
				End If
				
			Else If item.CustomField.PluginCustomField.Name = "DefaultInitiatedDate" Then
				
				If globalForm.SalesOrder.InvoiceNo.Length &gt; 0 Then
				
					Dim salesOrderHistory As JiwaSales.SalesOrder.SalesOrderHistory = globalForm.SalesOrder.SalesOrderHistorys(globalForm.SalesOrder.SelectedHistoryNo)
					
					If item.Contents IsNot Nothing AndAlso item.Contents.Length &gt; 0 Then
						salesOrderHistory.DatePosted = System.Convert.ToDateTime(item.Contents)
					Else
						salesOrderHistory.DatePosted = System.DateTime.Today.ToString("dd/MM/yyyy")
					End If
				
				End If
				
			End If
			
		End If
	End Sub
	
	Private Sub SalesOrder_Load(sender As Object, e As System.EventArgs)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = sender
		
		Dim printJobSheetButton As New Infragistics.Win.Misc.UltraButton
		With printJobSheetButton
			.Location = New System.Drawing.Point(salesOrderForm.grdCartage.Size.Width + salesOrderForm.grdCartage.Location.X + 150, salesOrderForm.grdCartage.Location.Y + 10)
			.Dock = System.Windows.Forms.DockStyle.None
			.Name = "PrintJobSheetButton"
			.Text = "Print Job Sheet Workshop with all documents (*)"
			.Size = New Size(300,50)
			.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
		End With
		
		Dim printJobSheetLabel As New Infragistics.Win.Misc.UltraLabel
		With printJobSheetLabel
			.Location = New System.Drawing.Point(printJobSheetButton.Location.X + 20, printJobSheetButton.Location.Y + 52)
			.Appearance = salesOrderForm.txtDebtorFax.Appearance
			.Dock = System.Windows.Forms.DockStyle.None
			.Name = "PrintJobSheetLabel"
			.Size = New Size(300,50)
			.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
			.Text = "(*) This action will also send an email to the Workshop"
		End With
		
		Dim printAllReportsButton As New Infragistics.Win.Misc.UltraButton
		With printAllReportsButton
			.Location = New System.Drawing.Point(printJobSheetButton.Size.Width + printJobSheetButton.Location.X + 100, printJobSheetButton.Location.Y)
			.Dock = System.Windows.Forms.DockStyle.None
			.Name = "PrintAllReportsButton"
			.Text = "Print All Reports"
			.Size = New Size(300,50)
			.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
		End With
		
		Dim printAllReportsLabel As New Infragistics.Win.Misc.UltraLabel
		With printAllReportsLabel
			.Location = New System.Drawing.Point(printAllReportsButton.Location.X - 30, printAllReportsButton.Location.Y + 52)
			.Appearance = salesOrderForm.txtDebtorFax.Appearance
			.Dock = System.Windows.Forms.DockStyle.None
			.Name = "PrintAllReportsLabel"
			.Size = New Size(400,50)
			.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
			.Text = "(*) This action will print the Invoice, Delivery Docket and Packing Slip Reports"
		End With
		
		If JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.Description &lt;&gt; "Darwin" And JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.Description &lt;&gt; "Karratha" Then
			salesOrderForm.grdCartage.Parent.Controls.Add(printJobSheetButton)
			salesOrderForm.grdCartage.Parent.Controls.Add(printJobSheetLabel)
			salesOrderForm.grdCartage.Parent.Controls.Add(printAllReportsButton)
			salesOrderForm.grdCartage.Parent.Controls.Add(printAllReportsLabel)
		End If
		
		AddHandler printJobSheetButton.Click, AddressOf printJobSheetButton_Click
		AddHandler printAllReportsButton.Click, AddressOf printAllReportsButton_Click
		
	End Sub
	
	Private Sub printAllReportsButton_Click(sender As Object, e As System.EventArgs)
		Dim printAllReportsButton As Infragistics.Win.Misc.UltraButton = DirectCast(sender, Infragistics.Win.Misc.UltraButton)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = printAllReportsButton.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = salesOrderForm.SalesOrder
		
		Dim invoicePrinted As Boolean = False
		Dim deliveryPrinted As Boolean = False
		Dim packingPrinted As Boolean = False
		
		If MsgBox("Are you sure that you want to print all reports?", vbYesNo + vbQuestion, "Confirm Sales Order - Invoice, Delivery Docket and Packing Slip Reports") = vbYes Then
			For Each salesOrderReport As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport In salesOrder.SalesOrderReports
				
				If salesOrderReport.ReportDefinition.Report.FileName.Contains("FOS") Then
				
				Dim candidateReportsToPrint As New JiwaApplication.JiwaCollection(Of JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport)
                ' override the logical printer
                candidateReportsToPrint.Add(salesOrderReport)
					
				If salesOrderReport.ReportDefinition.Report.Title.Contains("Invoice") And invoicePrinted = False Then
					
                    ' Print the report
					salesOrder.Print(candidateReportsToPrint, False)
					invoicePrinted = True
					
				Else If salesOrderReport.ReportDefinition.Report.Title.Contains("Delivery Docket") And deliveryPrinted = False Then
					
					' Print the report
					salesOrder.Print(candidateReportsToPrint, False)
					deliveryPrinted = True
					
				Else If salesOrderReport.ReportDefinition.Report.Title.Contains("Packing Slip") And packingPrinted = False Then
					
					' Print the report
					salesOrder.Print(candidateReportsToPrint, False)
					packingPrinted = True
					
				End If
				
				End If
			Next
		End If
		
	End Sub
	
	Private Sub printJobSheetButton_Click(sender As Object, e As System.EventArgs)
		Dim printJobSheetButton As Infragistics.Win.Misc.UltraButton = DirectCast(sender, Infragistics.Win.Misc.UltraButton)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = printJobSheetButton.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = salesOrderForm.SalesOrder
		
		If MsgBox("Are you sure that you want to print this Job Sheet to the Workshop?", vbYesNo + vbQuestion, "Confirm Sales Order - Job Sheet Workshop") = vbYes Then
		
		'IsFileOpen
		Dim openFile As String
		
		For Each document As JiwaFinancials.Jiwa.JiwaApplication.Documents.Document In salesOrder.Documents
			If Trim(document.DocumentType.Description) = "Document to be printed with JobSheet" Or Trim(document.DocumentType.Description) = "Document to be emailed and printed w/ JobSheet" Then
				Dim fpath As String = "C:\Temp\JIWA\Documents\"
				Dim file As FileInfo = New FileInfo(fpath + document.PhysicalFileName)
				
				If IsFileOpen(file) Then
					openFile = document.PhysicalFileName
					
					Exit For
				End If
			End If
		Next
		
		
		If Len(openFile) &gt; 0 Then
			MessageBox.Show("All attached documents must to be closed to perform this action. Please close all attached documents and try again." &amp; System.Environment.NewLine &amp; System.Environment.NewLine &amp; "File:" &amp; System.Environment.NewLine &amp; openFile, "Sales Order Documents", MessageBoxButtons.OK, MessageBoxIcon.Warning)
		Else
			For Each logicalPrinter As JiwaApplication.PrintGroup.Maintenance.LogicalPrinter In JiwaApplication.Manager.Instance.Staff.PrintGroup.LogicalPrinters
	            If logicalPrinter.Name = "Workshop - Job Sheets" Then
	                ' Find a sales order report named "test report.rpt".
	                For Each salesOrderReport As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport In salesOrder.SalesOrderReports
	                    If salesOrderReport.ReportDefinition.Report.FileName = "FOS - Job SheetWS.rpt" Then
	                        Dim candidateReportsToPrint As New JiwaApplication.JiwaCollection(Of JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport)
	                        ' override the logical printer
	                        salesOrderReport.ReportDefinition.LogicalPrinter = logicalPrinter
	                        candidateReportsToPrint.Add(salesOrderReport)
	                        ' Print the report
							
							salesOrder.Print(candidateReportsToPrint, False)
							
							Dim currentStaff As New JiwaApplication.Entities.Staff.Staff
							currentStaff.ReadRecord(JiwaApplication.Manager.Instance.Staff.RecID)
							
							Dim lastHistory As New JiwaApplication.Entities.Sales.SalesOrderHistory
							lastHistory.ReadRecord(salesOrder.InvoiceID, salesOrder.CurrentHistoryNo)
							
							Dim printLog As New JiwaSales.SalesOrder.PrintLog
							printLog.PrintDateTime = JiwaApplication.Manager.Instance.SysDateTime 
							printLog.Staff = currentStaff
							printLog.ReportType = salesOrderReport.DocumentType
							printLog.HistoryID = lastHistory.InvoiceHistoryID
							printLog.Description = salesOrderReport.ReportDefinition.Report.Title + " printed to the Workshop by " + currentStaff.FullName
							printLog.RecID = ""
							
							salesOrder.PrintLogCollection.Add(printLog)
							salesOrder.Save()
							
							Exit For
						End If
					Next
				Else If logicalPrinter.Name = "Workshop - Other Documents" Then
					
                    Dim nDocuments As Integer = 0
					
					Dim myProcess As System.Diagnostics.Process
					
					' Print documents
					For Each document As JiwaFinancials.Jiwa.JiwaApplication.Documents.Document In salesOrder.Documents
		
						If Trim(document.DocumentType.Description) = "Document to be printed with JobSheet" Or Trim(document.DocumentType.Description) = "Document to be emailed and printed w/ JobSheet" Then
							
							nDocuments = nDocuments + 1
							
							Dim fpath As String = "C:\Temp\JIWA\Documents\"
							
							If Not Directory.Exists(fpath) Then
								Directory.CreateDirectory(fpath)
							End If
							
							Dim file As String = fpath + document.PhysicalFileName
					
							If System.IO.File.Exists(file) Then
								System.IO.File.Delete(file)
							End If
					
							Dim fs As System.IO.FileStream = System.IO.File.Create(file)
							fs.Close()
					
							Dim documentClone As JiwaApplication.Documents.Document = document.Clone()
							
							System.IO.File.WriteAllBytes(file, documentClone.FileBinary)
							
							Dim psi As New System.Diagnostics.ProcessStartInfo()
							psi.UseShellExecute = True
							psi.Verb = "PrintTo"
							psi.WindowStyle = ProcessWindowStyle.Hidden
							psi.Arguments = """" + logicalPrinter.PhysicalPrinterName + """"
							psi.FileName = file
							psi.CreateNoWindow = True
							
							
							myProcess = System.Diagnostics.Process.Start(psi)  
							myProcess.WaitForInputIdle()
							myProcess.CloseMainWindow()
							myProcess.Close()
							
						End If
					
					Next
					
	            End If
	        Next
			
			' Send email
			Try
				Dim mailSmtpServer As New System.Net.Mail.SmtpClient()
				Dim mail As New System.Net.Mail.MailMessage()
				
				mailSmtpServer.UseDefaultCredentials = False
				mailSmtpServer.Credentials = New System.Net.NetworkCredential("hr3","Fos#2015!")
				mailSmtpServer.EnableSsl = True
				mailSmtpServer.Port = 25
				mailSmtpServer.Host = "10.148.202.15"
				
				mail.From = New MailAddress("hr3@franklinoffshore.com.au", "Job Management System")
				mail.To.Add("workshop@franklinoffshore.com.au")
				mail.Subject = "New Job Sheet Created [" + salesOrder.InvoiceNo + "] by " + salesOrder.Staff.FirstName
				mail.Body = "Workshop, please check printer for following new WorkSheet: " &amp; System.Environment.NewLine _
					&amp; System.Environment.NewLine _
					&amp; "Company:" &amp; Chr(9) &amp; salesOrder.Debtor.Name &amp; System.Environment.NewLine _
					&amp; "Raised By:" &amp; Chr(9) &amp; salesOrder.Staff.DisplayName &amp; System.Environment.NewLine _
					&amp; "Delivery Due:" &amp; Chr(9) &amp; salesOrder.ExpectedDeliveryDate.ToShortDateString() &amp; System.Environment.NewLine
				
				System.Net.ServicePointManager.ServerCertificateValidationCallback = _
				New System.Net.Security.RemoteCertificateValidationCallback(AddressOf customCertValidation)
				
				mailSmtpServer.Send(mail)
			Catch ex As System.Exception
				MessageBox.Show("An error occurred while sending the email to the Workshop")
			End Try
		End If
		End If
	End Sub
	
	Private Function IsFileOpen(ByVal file As FileInfo) As Boolean
		Dim isOpen As Boolean = False
		
	    Dim stream As FileStream = Nothing
	    Try
	        stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None)
	        stream.Close()
	    Catch ex As System.Exception

	        If TypeOf ex Is IOException AndAlso IsFileLocked(ex) Then
	            isOpen = True
	        End If
	    End Try
		
		Return isOpen
	End Function

	Private Shared Function IsFileLocked(exception As System.Exception) As Boolean
	    Dim errorCode As Integer = System.Runtime.InteropServices.Marshal.GetHRForException(exception) And ((1 &lt;&lt; 16) - 1)
	    Return errorCode = 32 OrElse errorCode = 33
	End Function
	
	Private Sub SalesOrder_Printed(sender As Object, e As System.EventArgs, report As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport)
    	Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrder.GenericObjectCollection("SalesOrderForm").Object, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
	
		ButtonsVisibility(salesOrderForm)
    End Sub   
	
	Private Shared Function customCertValidation(ByVal sender As Object, _
                                                ByVal cert As X509Certificate, _
                                                ByVal chain As X509Chain, _
                                                ByVal errors As SslPolicyErrors) As Boolean

        Return True

    End Function
	
	Private Sub SendEmail(salesOrder As JiwaSales.SalesOrder.SalesOrder, salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
		
		Dim candidateReports As JiwaApplication.JiwaCollection(Of JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport) = salesOrderForm.SalesOrder.GetCandidateReportsToEmail()
		
		If candidateReports.Count = 0 Then
	    	Throw New System.Exception("There are no reports that are applicable to this particular invoice.")
		End If

	    ' load print selection dialog        
		Dim emailReportDialog As JiwaSalesUI.SalesOrder.EmailReport = JiwaApplication.Manager.Instance.DialogFactory.CreateDialog(Of JiwaSalesUI.SalesOrder.EmailReport)(New Object() {candidateReports}, SalesOrderForm, "Sales Order Entry")
	    emailReportDialog.NameToGiveAttachment = salesOrderForm.SalesOrder.InvoiceNo &amp; "-" &amp; salesOrderForm.SalesOrder.SelectedHistoryNo
	    
		emailReportDialog.EmailTo = salesOrder.Debtor.EmailAddress 'salesOrderForm.SalesOrder.Debtor.Email
		emailReportDialog.From = JiwaApplication.Manager.Instance.Staff.EmailAddress ' Microsoft.VisualBasic.Strings.Chr(34) &amp; Microsoft.VisualBasic.Strings.Replace(JiwaApplication.Manager.Instance.Staff.EmailDisplayName, "@", " ") &amp; Microsoft.VisualBasic.Strings.Chr(34) &amp; " &lt;" &amp; JiwaApplication.Manager.Instance.Staff.EmailAddress &amp; "&gt;"
	    emailReportDialog.Subject = salesOrderForm.SalesOrder.InvoiceNo
	    emailReportDialog.SelectedReport = candidateReports(1)

		If salesOrderForm.SalesOrder.Debtor.ContactName &lt;&gt; "" And salesOrderForm.SalesOrder.Debtor.ContactName &lt;&gt; " " Then 		
			emailReportDialog.Message = "Dear " &amp; salesOrderForm.SalesOrder.Debtor.ContactName &amp; "," &amp; System.Environment.NewLine &amp; System.Environment.NewLine
		Else
			emailReportDialog.Message = ""
		End If
	
		emailReportDialog.Message = emailReportDialog.Message &amp; "Please find the documents of the Sales Order " &amp; salesOrderForm.SalesOrder.InvoiceNo &amp; " attached." &amp; System.Environment.NewLine _
								&amp; System.Environment.NewLine _
								&amp; "Best Regards, " &amp; System.Environment.NewLine _
								&amp; JiwaApplication.Manager.Instance.Staff.EmailDisplayName &amp; System.Environment.NewLine _
								&amp; "Franklin Offshore Australia Pty Ltd" &amp; System.Environment.NewLine _
								&amp; "7 Possner Way Henderson WA 6166" &amp; System.Environment.NewLine _
								&amp; "Phn: +61 8 9410 6000   Fax: +61 8 9410 6001" &amp; System.Environment.NewLine _
								&amp; "Email: " &amp; JiwaApplication.Manager.Instance.Staff.EmailAddress &amp; System.Environment.NewLine _
								&amp; "Web: www.franklinoffshore.com.au"

	    If emailReportDialog.ShowDialog(salesOrderForm) = System.Windows.Forms.DialogResult.OK Then
	    	'salesOrderForm.SalesOrder.Email(emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, ExportFormatType)
			
			' Generate the report to file then add as an attachment		
			Dim PrintReportObject As New JiwaApplication.JiwaPrintReport.JiwaPrintReport
		    PrintReportObject.Setup()

		    PrintReportObject.LoadReport(emailReportDialog.SelectedReport.ReportDefinition.Report)
		    PrintReportObject.OverrideRecordSelectionCriteria = ""
				
			For Each jiwaReportRange As JiwaApplication.JiwaPrintReport.JiwaReportRange In PrintReportObject.JiwaReportRangeCollection
	        	If PrintReportObject.JiwaPrintFormulaCollection(jiwaReportRange.FormulaKey).Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() = "{@Pass_SP_InvoiceHistoryID}".Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() Then
	            	jiwaReportRange.Value = salesOrderForm.SalesOrder.SalesOrderHistorys(salesOrderForm.SalesOrder.SelectedHistoryNo).RecID
				ElseIf PrintReportObject.JiwaPrintFormulaCollection(jiwaReportRange.FormulaKey).Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() = "{@Pass_InvoiceNo}".Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() Then
	            	jiwaReportRange.Value = salesOrderForm.SalesOrder.InvoiceNo
				ElseIf PrintReportObject.JiwaPrintFormulaCollection(jiwaReportRange.FormulaKey).Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() = "{@Pass_CurrentHistNo}".Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() Then
	            	jiwaReportRange.Value = JiwaApplication.Manager.Instance.Database.FormatNumber(Format(salesOrderForm.SalesOrder.SelectedHistoryNo, "00"))
	            End If
	        Next

			PrintReportObject.UpdateReport()
				
			' Export Report to PDF
			Dim exOption As CrystalDecisions.Shared.ExportOptions
			exOption = PrintReportObject.CrystalReportObject.ExportOptions
			exOption.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat			
	        exOption.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
			
			Dim tempFolderPath As String = My.Computer.FileSystem.SpecialDirectories.Temp
	        If tempFolderPath.Trim.Length = 0 Then
	            Throw New System.Exception("Unable to get temporary folder")
	        End If

	        If emailReportDialog.NameToGiveAttachment.Trim.Length = 0 Then
	            Throw New System.Exception("Attachment name is invalid.")
	        End If

	        If Not emailReportDialog.NameToGiveAttachment.EndsWith(".pdf") Then
	            emailReportDialog.NameToGiveAttachment = emailReportDialog.NameToGiveAttachment &amp; ".pdf"
	        End If
			
			emailReportDialog.NameToGiveAttachment = JiwaApplication.Manager.MakeSafeFileName(emailReportDialog.NameToGiveAttachment)

			Dim ExportFormatType As CrystalDecisions.Shared.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
	        PrintReportObject.CrystalReportObject.ExportToDisk(ExportFormatType, My.Computer.FileSystem.CombinePath(tempFolderPath, emailReportDialog.NameToGiveAttachment))
				
			' Create Email message			
			Dim emailForm As JiwaApplication.JiwaEmailUI.MainForm = JiwaApplication.Manager.Instance.FormFactory.CreateForm(Of JiwaApplication.JiwaEmailUI.MainForm)
			' Show the email form
			emailForm.Start()
			emailForm.EmailObject.CreateNew
			
			emailForm.EmailObject.EmailFrom = emailReportDialog.From
			emailForm.EmailObject.EmailTo = emailReportDialog.EmailTo
			emailForm.EmailObject.EmailCC = emailReportDialog.CC 
			emailForm.EmailObject.EmailBCC = emailReportDialog.BCC 
			emailForm.EmailObject.EmailSubject = emailReportDialog.Subject 
			emailForm.EmailObject.EmailBody = emailReportDialog.Message 
			
			Dim reportAttachment As New JiwaApplication.Documents.Document 
			reportAttachment.Description = "Generated Sales Order Report"
			reportAttachment.PhysicalFileName = emailReportDialog.NameToGiveAttachment
			reportAttachment.FileBinary = My.Computer.FileSystem.ReadAllBytes(My.Computer.FileSystem.CombinePath(tempFolderPath, emailReportDialog.NameToGiveAttachment))
			emailForm.EmailObject.Attachments.Add(reportAttachment)
				
			' Add the sales order documents to the email
			For Each document As JiwaApplication.Documents.Document In salesOrderForm.SalesOrder.Documents
				If Trim(document.DocumentType.Description) = "Document to be emailed" Then
					Dim emailDocument As New JiwaApplication.Documents.Document 
					emailDocument.Description = document.Description
					emailDocument.PhysicalFileName = document.PhysicalFileName 
					emailDocument.FileBinary = document.FileBinary
					emailForm.EmailObject.Attachments.Add(emailDocument)
				End If
			Next
			
			' Add to email log.
		    Dim emailLog As New JiwaSales.SalesOrder.EmailLog 
		    emailLog.ReportType = emailReportDialog.SelectedReport.DocumentType
		    emailLog.EM_Main_RecID = emailForm.EmailObject.RecID 
		    emailLog.BCC = emailForm.EmailObject.EmailBCC
		    emailLog.Body = emailForm.EmailObject.EmailBody
		    emailLog.CC = emailForm.EmailObject.EmailCC
		    emailLog.EmailDateTime = Now
		    emailLog.EmailTo = emailForm.EmailObject.EmailTo
		    emailLog.From = emailForm.EmailObject.EmailFrom
		    emailLog.InvoiceHistoryID = salesOrderForm.SalesOrder.SalesOrderHistorys(salesOrderForm.SalesOrder.SelectedHistoryNo).RecID
		    emailLog.InvoiceID = salesOrderForm.SalesOrder.InvoiceID
		    emailLog.RequestReadReceipt = emailForm.EmailObject.RequestReadReceipt 
		    emailLog.Subject = emailForm.EmailObject.EmailSubject 
		    emailLog.Staff = salesOrderForm.SalesOrder.Staff
		    emailLog.Attachments = emailReportDialog.NameToGiveAttachment

		    salesOrderForm.SalesOrder.EmailLogCollection.Add(emailLog)
				
			' Store a reference to the sales order form in the email business logic, so we can access that in the save_end handler
			Dim genericObject As New JiwaApplication.BusinessLogic.GenericObjectItem 
			genericObject.RecID = "SalesOrderForm"
			genericObject.Object = salesOrderForm
			emailForm.EmailObject.GenericObjectCollection.Add(genericObject)
				
			genericObject = New JiwaApplication.BusinessLogic.GenericObjectItem 
			genericObject.RecID = "EmailForm"
			genericObject.Object = emailForm
			emailForm.EmailObject.GenericObjectCollection.Add(genericObject)
			
			' Add a handler to the save event of the email message
			' We'll need to save the sales order and close the email in there
			AddHandler emailForm.EmailObject.SaveEnd, AddressOf SalesOrderEmailMessage_SaveEnd
		End If
	End Sub
	
	Private Sub SalesOrderEmailMessage_SaveEnd(sender As Object, e As System.EventArgs)
		Dim emailMessage As JiwaApplication.JiwaEmail.EmailMessage = sender
		
		' Remove our handler so we don't get save notifications for the email anymore
		RemoveHandler emailMessage.ReadEnd, AddressOf SalesOrderEmailMessage_SaveEnd
				
		Dim genericObject As JiwaApplication.BusinessLogic.GenericObjectItem = emailMessage.GenericObjectCollection("SalesOrderForm")
		If genericObject IsNot Nothing Then
			Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(genericObject.Object, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
			salesOrderForm.SalesOrder.Save
			
			genericObject = emailMessage.GenericObjectCollection("EmailForm")
			If genericObject IsNot Nothing Then
				Dim emailForm As JiwaApplication.JiwaEmailUI.MainForm = DirectCast(genericObject.Object, JiwaApplication.JiwaEmailUI.MainForm)
				emailform.Close 
			End If
		End If
	End Sub
	
	Public Sub SalesOrder_SalesOrderLineAdding(sender As Object, e As System.EventArgs, salesItem As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrder.GenericObjectCollection("SalesOrderForm").Object, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
		
		If salesItem.HistoryID.Length = 0
			
			Dim itemPickPack As Boolean = False
			Dim itemSingleItem As Boolean = False
			Dim itemManufactured As Boolean = False
			
			If salesItem.PartNo.ToUpper() = "LABOUR" Or salesItem.PartNo.ToUpper() = "LABOUR TESTING" Or salesItem.PartNo.ToUpper() = "T"
				itemSingleItem = True
			Else
				If salesItem.PartNo.ToUpper() = "M"
					itemManufactured = True
				Else
					itemPickPack = True
				End If
			End If
			
			
			For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In salesItem.CustomFieldValues
			
				If customFieldValue.CustomField.PluginCustomField.Name = "PickPack" Then
					customFieldValue.Contents = itemPickPack.ToString()
				Else
					If customFieldValue.CustomField.PluginCustomField.Name = "SingleItem" Then
						customFieldValue.Contents = itemSingleItem.ToString()
					Else
						If customFieldValue.CustomField.PluginCustomField.Name = "Manufactured" Then
							customFieldValue.Contents = itemManufactured.ToString()
						End If
					End If
				End If
				
			Next
			
		End If
		
		
	End Sub
	
	Public Sub SalesOrder_SalesOrderLineRemoved(sender As Object, e As System.EventArgs, salesItem As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrder.GenericObjectCollection("SalesOrderForm").Object, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
		
		SetItemNumber(salesOrder, salesOrderForm)
	End Sub
	
	Public Sub SalesOrder_SaveEnd(sender As Object, e As System.EventArgs)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
		Dim salesOrderHistory As JiwaSales.SalesOrder.SalesOrderHistory = salesOrder.SalesOrderHistorys(salesOrder.SelectedHistoryNo)
		
		Dim overrideInvoiceDate As Boolean = False
					
		For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In globalForm.SalesOrder.CustomFieldValues	
			If customFieldValue.CustomField.PluginCustomField.Name = "OverrideInvoiceDate" Then
				If customFieldValue.Contents IsNot Nothing AndAlso customFieldValue.Contents.Length &gt; 0 Then
					overrideInvoiceDate = System.Convert.ToBoolean(customFieldValue.Contents)
				End If
				
				Exit For
			End If
		Next
		
		For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In globalForm.SalesOrder.CustomFieldValues	
			If customFieldValue.CustomField.PluginCustomField.Name = "DefaultInitiatedDate" Then
					
				If overrideInvoiceDate = True Then
					
					If customFieldValue.Contents IsNot Nothing AndAlso customFieldValue.Contents.Length &gt; 0 Then
					
						salesOrderHistory.DatePosted = System.Convert.ToDateTime(customFieldValue.Contents)
						
					Else
						salesOrderHistory.DatePosted = System.DateTime.Now
						
					End If
					
				End If
				
				Exit For
			End If
		Next
		
	End Sub
	
	Public Sub SalesOrder_SaveStart(sender As Object, e As System.EventArgs)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrder.GenericObjectCollection("SalesOrderForm").Object, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
		Dim salesOrderHistory As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderHistory = salesOrderForm.SalesOrder.SalesOrderHistorys(salesOrderForm.SalesOrder.CurrentHistoryNo)
				
		AddHandler salesOrderHistory.PropertyChanged, AddressOf SalesOrderHistory_PropertyChanged
					
		SetItemNumber(salesOrder, salesOrderForm)
		
		Dim gridSheet As JiwaFinancials.Jiwa.JiwaApplication.Controls.Sheet = DirectCast(salesOrderForm.grdLines.ActiveSheet, JiwaFinancials.Jiwa.JiwaApplication.Controls.Sheet)
		
		For row As Integer = 0 To gridSheet.Rows.Count - 1
			
			If Not IsNothing(gridSheet.GetValue(row, 0)) Then
				
				For Each line As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine In salesOrder.SalesOrderLines
					
					If gridSheet.GetValue(row, 0).ToString() = line.RecID Then
						
						line.FixSellPrice = True
						
						Exit For
						
					End If
					
				Next
			
			End If
			
		Next
		
		
		
	End Sub
	
	Public Function ButtonsVisibility(salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = salesOrderForm.SalesOrder
		
		If JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.Description &lt;&gt; "Darwin" And JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.Description &lt;&gt; "Karratha" Then
			
			Dim SQLParam As SqlClient.SqlParameter = Nothing
			Dim SQLReader As SqlDataReader = Nothing
			Dim SQL As String = ""
			
			salesOrderForm.lblPrinted.Visible = False
			
			With JiwaApplication.Manager.Instance.Database 
				Try
					SQL = "SELECT COUNT(1) as Qtd FROM SO_PrintLog WHERE InvoiceID = @InvoiceID AND Description LIKE '%to the Workshop%'"
						
					Using SQLCmd As SqlCommand = New SqlCommand(SQL, .SQLConnection, .SQLTransaction)
						SQLParam = New SqlParameter("@InvoiceID", System.Data.SqlDbType.Char)
	                	SQLParam.Value = salesOrder.InvoiceID
	                	SQLCmd.Parameters.Add(SQLParam)
						
						SQLReader = SQLCmd.ExecuteReader()
						
						While SQLReader.Read
							If .Sanitise(SQLReader, "Qtd").ToString() &lt;&gt; "0" Then
								salesOrderForm.lblPrinted.Visible = True
							End If
						End While
					End Using
						
					SQLReader.Close()
				Finally
					If Not SQLReader Is Nothing Then
						SQLReader.Close()
					End If
				End Try
			End With
			
		End If
	End Function
	
	Public Function SetItemNumber(salesOrder As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder, salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
		Dim itemNumber As Integer
		
		For Each line As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine In salesOrder.SalesOrderLines
			
			If ((line.KitLineType.ToString() = "e_SalesOrderNormalLine") Or (line.KitLineType.ToString() = "e_SalesOrderKitHeader")) And (line.CommentLine = False) And (line.TypeKitRounding = False) Then
				
				Dim itemShouldBeCounted As Boolean
				
				itemShouldBeCounted = False
				
				For Each customFieldValue As JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue In line.CustomFieldValues
					
					If ((customFieldValue.CustomField.PluginCustomField.Name = "PickPack") Or (customFieldValue.CustomField.PluginCustomField.Name = "SingleItem") Or (customFieldValue.CustomField.PluginCustomField.Name = "Manufactured")) Then
						
						If (customFieldValue.Contents.ToString() = "True") Then
							itemShouldBeCounted = True
						End If
					End If
					
				Next
				
				If itemShouldBeCounted Then
					itemNumber += 1
				
					line.UserDefinedFloat1 = itemNumber
				Else
					line.UserDefinedFloat1 = 0
				End If
				
			Else 
				
				line.UserDefinedFloat1 = 0
				
			End If
			
			salesOrderForm.grdLines.LockColumn(True, "UserDefinedFloat1", line.ItemNo - 1)
			
		Next
		
		salesOrderForm.grdLines.LockColumn(True, "UserDefinedFloat1", -1)
	End Function
	
	Public Sub SalesOrder_ReadEnd(sender As Object, e As System.EventArgs)
		Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
		Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrder.GenericObjectCollection("SalesOrderForm").Object, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
			
		For Each line As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine In salesOrder.SalesOrderLines
			
			salesOrderForm.grdLines.LockColumn(True, "UserDefinedFloat1", line.ItemNo - 1)
			
		Next
		
		salesOrderForm.grdLines.LockColumn(True, "UserDefinedFloat1", -1)
		
		If salesOrder.SalesOrderStatus = JiwaApplication.Entities.Sales.SalesOrder.SalesOrderStatuses.e_SalesOrderProcessed Or salesOrder.SalesOrderStatus = JiwaApplication.Entities.Sales.SalesOrder.SalesOrderStatuses.e_SalesOrderClosed Then
			For Each customFieldLine As JiwaApplication.CustomFields.CustomField In salesOrder.CustomSettings
				salesOrderForm.grdCustomFields.LockColumn(True, "Contents", customFieldLine.ItemNo - 1)
			Next
		End If
		
		ButtonsVisibility(salesOrderForm)
		
	End Sub
		
End Class

Public Class BusinessLogicPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaBusinessLogicPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub Setup(ByVal JiwaBusinessLogic As JiwaApplication.IJiwaBusinessLogic, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaBusinessLogicPlugin.Setup
	End Sub
	

End Class

Public Class ApplicationManagerPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaApplicationManagerPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub Setup(ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaApplicationManagerPlugin.Setup
    End Sub

End Class

Public Class CustomFieldPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaCustomFieldPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub FormatCell(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Col As Integer, ByVal Row As Integer, ByVal HostObject As JiwaApplication.IJiwaCustomFieldValues, ByVal CustomField As JiwaApplication.CustomFields.CustomField, ByVal CustomFieldValue As JiwaApplication.CustomFields.CustomFieldValue) Implements JiwaApplication.IJiwaCustomFieldPlugin.FormatCell
    End Sub

    Public Sub ReadData(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Row As Integer, ByVal HostObject As JiwaApplication.IJiwaCustomFieldValues, ByVal CustomField As JiwaApplication.CustomFields.CustomField, ByVal CustomFieldValue As JiwaApplication.CustomFields.CustomFieldValue) Implements JiwaApplication.IJiwaCustomFieldPlugin.ReadData
    End Sub

    Public Sub ButtonClicked(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Col As Integer, ByVal Row As Integer, ByVal HostObject As JiwaApplication.IJiwaCustomFieldValues, ByVal CustomField As JiwaApplication.CustomFields.CustomField, ByVal CustomFieldValue As JiwaApplication.CustomFields.CustomFieldValue) Implements JiwaApplication.IJiwaCustomFieldPlugin.ButtonClicked
    End Sub

End Class

Public Class LineCustomFieldPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaLineCustomFieldPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub FormatCell(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Col As Integer, ByVal Row As Integer, ByVal HostItem As JiwaApplication.IJiwaLineCustomFieldValues, ByVal CustomField As JiwaApplication.CustomFields.CustomField, ByVal CustomFieldValue As JiwaApplication.CustomFields.CustomFieldValue) Implements JiwaApplication.IJiwaLineCustomFieldPlugin.FormatCell
    End Sub

    Public Sub ReadData(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Row As Integer, ByVal HostItem As JiwaApplication.IJiwaLineCustomFieldValues, ByVal CustomField As JiwaApplication.CustomFields.CustomField, ByVal CustomFieldValue As JiwaApplication.CustomFields.CustomFieldValue) Implements JiwaApplication.IJiwaLineCustomFieldPlugin.ReadData
    End Sub

    Public Sub ButtonClicked(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Col As Integer, ByVal Row As Integer, ByVal HostItem As JiwaApplication.IJiwaLineCustomFieldValues, ByVal CustomField As JiwaApplication.CustomFields.CustomField, ByVal CustomFieldValue As JiwaApplication.CustomFields.CustomFieldValue) Implements JiwaApplication.IJiwaLineCustomFieldPlugin.ButtonClicked
    End Sub

End Class

Public Class SystemSettingPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaSystemSettingPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub FormatCell(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Col As Integer, ByVal Row As Integer, ByVal SystemSetting As JiwaApplication.SystemSettings.Setting) Implements JiwaApplication.IJiwaSystemSettingPlugin.FormatCell
    End Sub

    Public Sub ReadData(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Row As Integer, ByVal SystemSetting As JiwaApplication.SystemSettings.Setting) Implements JiwaApplication.IJiwaSystemSettingPlugin.ReadData
    End Sub

    Public Sub ButtonClicked(ByVal BusinessLogicHost As JiwaApplication.IJiwaBusinessLogic, ByVal GridObject As JiwaApplication.Controls.JiwaGrid, ByVal FormObject As JiwaApplication.IJiwaForm, ByVal Col As Integer, ByVal Row As Integer, ByVal SystemSetting As JiwaApplication.SystemSettings.Setting) Implements JiwaApplication.IJiwaSystemSettingPlugin.ButtonClicked
    End Sub

End Class

Public Class ScheduledExecutionPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaScheduledExecutionPlugin

    Public Sub Execute(ByVal Plugin As JiwaApplication.Plugin.Plugin, ByVal Schedule As JiwaApplication.Schedule.Schedule) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.Execute

    End Sub

    Public Sub OnServiceStart(ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.OnServiceStart

    End Sub

    Public Sub OnServiceStopping(ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaScheduledExecutionPlugin.OnServiceStopping

    End Sub
End Class
</Code>
  <ExceptionPolicy>Report</ExceptionPolicy>
  <Language>VisualBasic</Language>
  <PluginFormCollection>
    <PluginForm>
      <RecID>37cf9244-6949-42c2-a76e-f0e39312bf2c</RecID>
      <Description>Sales Orders</Description>
      <ClassName>JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm</ClassName>
    </PluginForm>
  </PluginFormCollection>
  <ReferenceCollection>
    <Reference>
      <RecID>c3d7d790-18dd-4469-825c-46873c726f52</RecID>
      <AssemblyFullName>JiwaApplication, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaApplication.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaApplication.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>5147027d-bf3d-4d04-8627-73c2c2ece19f</RecID>
      <AssemblyFullName>mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>mscorlib.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>ffffd59a-180d-4125-9849-124629e89508</RecID>
      <AssemblyFullName>Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>Microsoft.VisualBasic.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>3a2bc569-3b2e-46b7-9278-7d452d1f1d73</RecID>
      <AssemblyFullName>System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>9dd54fe3-8d2e-4ab3-93ea-e929a04d5f94</RecID>
      <AssemblyFullName>System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Windows.Forms.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>9bee2e6e-078d-4ff1-8dce-790a66041565</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinToolbars.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinToolbars.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinToolbars.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>2c172ec4-4755-4b1b-ace5-3dd0e369fe17</RecID>
      <AssemblyFullName>Infragistics4.Win.Misc.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.Misc.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.Misc.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>f1b4ab3d-7fd4-4b8c-baa7-fe50c21cd0fc</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinStatusBar.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinStatusBar.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinStatusBar.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>d72df741-893d-45a5-a8d6-55217245daae</RecID>
      <AssemblyFullName>Infragistics4.Win.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>5c7310f2-0a8e-41bf-a777-94519baaf2d9</RecID>
      <AssemblyFullName>FarPoint.Win.Spread, Version=7.35.20132.1, Culture=neutral, PublicKeyToken=327c3516b1b18457</AssemblyFullName>
      <AssemblyName>FarPoint.Win.Spread.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\FarPoint.Win.Spread.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>34860186-7463-4adc-a0ad-5cd90daa49c0</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinTabControl.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinTabControl.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinTabControl.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>9741ad4d-f608-4bc6-878c-96de4a7f97db</RecID>
      <AssemblyFullName>System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>System.Drawing.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>a63f2e85-1e9e-43ff-81d6-a2945f68f080</RecID>
      <AssemblyFullName>Microsoft.SqlServer.Smo, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91</AssemblyFullName>
      <AssemblyName>Microsoft.SqlServer.Smo.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Smo\12.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Smo.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>6b9c9b30-e817-45b7-844f-12e5925cbc8a</RecID>
      <AssemblyFullName>System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Data.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>c6371d3d-c763-4009-b275-71a7ab4cc4d9</RecID>
      <AssemblyFullName>JiwaODBC, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaODBC.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaODBC.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>34c2e005-d792-4845-928b-21aa5eacc2f3</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinEditors.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinEditors.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinEditors.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>12668c1a-d5b5-438b-b978-eff6a2350055</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinExplorerBar.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinExplorerBar.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinExplorerBar.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>5ce07b57-b447-409c-877b-4b4c5c27e40a</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinTree.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinTree.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinTree.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>9020852f-ee0d-4093-848e-f6114e86e042</RecID>
      <AssemblyFullName>System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Xml.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>10a118b4-839b-451f-a70b-70f0f18cf8a8</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinListView.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinListView.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinListView.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>79002ac7-4e8c-49db-8173-32b734ee9ade</RecID>
      <AssemblyFullName>ActiproSoftware.SyntaxEditor.WinForms, Version=12.1.304.0, Culture=neutral, PublicKeyToken=c27e062d3c1a4763</AssemblyFullName>
      <AssemblyName>ActiproSoftware.SyntaxEditor.WinForms.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\ActiproSoftware.SyntaxEditor.WinForms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>b8d1e8fa-eed4-4184-8326-18c43338cf45</RecID>
      <AssemblyFullName>ZetaHtmlEditControl, Version=1.1.0.3, Culture=neutral, PublicKeyToken=2e2e5ba5da72b6c0</AssemblyFullName>
      <AssemblyName>ZetaHtmlEditControl.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\ZetaHtmlEditControl.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>2c845762-bfcb-4887-b1da-187340d5776c</RecID>
      <AssemblyFullName>ActiproSoftware.SyntaxEditor.Addons.DotNet.WinForms, Version=12.1.304.0, Culture=neutral, PublicKeyToken=c27e062d3c1a4763</AssemblyFullName>
      <AssemblyName>ActiproSoftware.SyntaxEditor.Addons.DotNet.WinForms.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\ActiproSoftware.SyntaxEditor.Addons.DotNet.WinForms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>850f5c39-1ac7-43c0-8d94-bc53f58b492e</RecID>
      <AssemblyFullName>CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.CrystalReports.Engine.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.CrystalReports.Engine\13.0.2000.0__692fbea5521e1304\CrystalDecisions.CrystalReports.Engine.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>2c7c66fb-c93b-493f-97bf-452fa85e37cd</RecID>
      <AssemblyFullName>CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.Shared.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.Shared\13.0.2000.0__692fbea5521e1304\CrystalDecisions.Shared.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>4a9f3416-8726-41a4-a809-45bce61c5cf4</RecID>
      <AssemblyFullName>CrystalDecisions.Windows.Forms, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.Windows.Forms.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.Windows.Forms\13.0.2000.0__692fbea5521e1304\CrystalDecisions.Windows.Forms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>21c4c4f7-42d0-4e29-b23b-671ee59ce422</RecID>
      <AssemblyFullName>Infragistics4.Win.AppStylistSupport.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.AppStylistSupport.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.AppStylistSupport.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>f922e4a0-a587-4e98-88b4-f634c118abe1</RecID>
      <AssemblyFullName>JiwaLib, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaLib.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaLib.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>4c19a5f1-7bc6-4ff9-aab6-a8b21a517522</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinSchedule.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinSchedule.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinSchedule.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>4a7d09c3-e876-4392-a8c8-0966fffe89fc</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinGrid.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinGrid.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Win.UltraWinGrid.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>ce0892b5-6eec-4da8-b0a1-a09feb82d37e</RecID>
      <AssemblyFullName>System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Runtime.Serialization.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>00cf7fd8-0b97-461a-93a5-dc9e0645aaeb</RecID>
      <AssemblyFullName>Infragistics4.Shared.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Shared.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Infragistics4.Shared.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>fb9546db-350f-45ea-b4fc-6f4a69a8c422</RecID>
      <AssemblyFullName>Microsoft.SqlServer.ConnectionInfo, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91</AssemblyFullName>
      <AssemblyName>Microsoft.SqlServer.ConnectionInfo.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ConnectionInfo\12.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.ConnectionInfo.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>0a6f596b-9154-4a3d-9293-1adb2f76c3c6</RecID>
      <AssemblyFullName>mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>mscorlib.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>2050e573-711f-4ac8-b57f-a2ef75f7dcf9</RecID>
      <AssemblyFullName>System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Data.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>d84293ac-abf8-4a87-86fe-018a5ed31b47</RecID>
      <AssemblyFullName>System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Windows.Forms.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>41373ca8-01bc-455e-a590-cf428a824498</RecID>
      <AssemblyFullName>System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>System.Drawing.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>48627de9-0d5e-41b6-bd82-40b3ee2f6d92</RecID>
      <AssemblyFullName>System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>9ac24dd2-0612-4a64-bfbf-c40c59cee5f6</RecID>
      <AssemblyFullName>System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Core.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>a1e17970-2c23-4f26-bc84-0999321a449d</RecID>
      <AssemblyFullName>Microsoft.SqlServer.Dac, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>Microsoft.SqlServer.Dac.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\Microsoft.SqlServer.Dac.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>07b182d1-4872-462f-a018-70a134b17acb</RecID>
      <AssemblyFullName>JiwaEncryption, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaEncryption.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaEncryption.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>c5c1e66f-1176-4dcd-9a9f-7e785b10a98f</RecID>
      <AssemblyFullName>JiwaSendEmail, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaSendEmail.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaSendEmail.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>f44a484a-1445-46a4-b2f8-6aa2c1da5ff8</RecID>
      <AssemblyFullName>CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.ReportAppServer.ClientDoc.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.ReportAppServer.ClientDoc\13.0.2000.0__692fbea5521e1304\CrystalDecisions.ReportAppServer.ClientDoc.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>82b40937-7a5a-4cee-90a1-29c0aa80f4c0</RecID>
      <AssemblyFullName>CrystalDecisions.ReportAppServer.Controllers, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.ReportAppServer.Controllers.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.ReportAppServer.Controllers\13.0.2000.0__692fbea5521e1304\CrystalDecisions.ReportAppServer.Controllers.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>c0887307-9d69-4f62-bc4b-bd243b1b8227</RecID>
      <AssemblyFullName>CrystalDecisions.ReportAppServer.ReportDefModel, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.ReportAppServer.ReportDefModel.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.ReportAppServer.ReportDefModel\13.0.2000.0__692fbea5521e1304\CrystalDecisions.ReportAppServer.ReportDefModel.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>62342534-e27a-4f3e-943e-2f21d4c13c88</RecID>
      <AssemblyFullName>FarPoint.Win, Version=7.35.20132.1, Culture=neutral, PublicKeyToken=327c3516b1b18457</AssemblyFullName>
      <AssemblyName>FarPoint.Win.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\FarPoint.Win.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>e56d287c-b639-4c59-a59f-da7dd96acbe6</RecID>
      <AssemblyFullName>ActiproSoftware.Shared.WinForms, Version=12.1.304.0, Culture=neutral, PublicKeyToken=c27e062d3c1a4763</AssemblyFullName>
      <AssemblyName>ActiproSoftware.Shared.WinForms.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\ActiproSoftware.Shared.WinForms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>57bc9524-0ba5-4647-9e72-4a4488117171</RecID>
      <AssemblyFullName>System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>System.Security.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Security\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Security.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>a87296db-8c36-4d73-ad65-0dd69232a0f6</RecID>
      <AssemblyFullName>JiwaSalesUI, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaSalesUI.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaSalesUI.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>7bfdd7eb-596d-4fc0-838a-1faab36990b7</RecID>
      <AssemblyFullName>JiwaSales, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaSales.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaSales.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>ea057aae-847e-419c-99d7-3b9aff3dfe5e</RecID>
      <AssemblyFullName>JiwaJobCosting, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaJobCosting.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaJobCosting.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>164a0434-9720-4a9d-abe6-eb3db5c9ec29</RecID>
      <AssemblyFullName>JiwaPriceSchemes, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaPriceSchemes.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaPriceSchemes.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>5559ce64-d02d-4fc0-ae62-00f9d0b3f080</RecID>
      <AssemblyFullName>JiwaSerialNumbersUI, Version=7.0.129.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaSerialNumbersUI.dll</AssemblyName>
      <AssemblyLocation>C:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaSerialNumbersUI.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>bb7c5c5b-9fdf-41da-9d29-3d34088c6e4b</RecID>
      <AssemblyFullName>System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Xml.Linq.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll</AssemblyLocation>
    </Reference>
  </ReferenceCollection>
</JiwaDocument>