A number of months back Mike kindly wrote me a breakout which automatically prints or emails depending on if the email information field is populated.
This script has always just printed the invoice, just wanting an option in the breakout where i can specify the invoice that is printed.
I have looked around and found another breakout Mike had written which had the option to do this in it, but was unable to get it working on my own.
- Code: Select all
PrintingOptions = 0 ' bitwise field 1 = print invoice, 2 = print print invoice Office, 3 = print picking slip
Was hoping I could get some assistance in getting this option in this breakout
Kind Regards
Robin
- Code: Select all
Public Function ProcessSalesOrder(FormObject, SalesOrderObject)
Dim SOProcObject
Dim lErrorString
Dim lErrorModule
ProcessSalesOrder = True
If ProcessSalesOrder = True Then
Set SOProcObject = CreateObject("JiwaProcessSO.clsSalesOrderProcess")
Set SOProcObject.Database = SalesOrderObject.Database
Set SOProcObject.CommonLib = SalesOrderObject.JiwaCommLib
Set SOProcObject.JLib = SalesOrderObject.JLib
Set SOProcObject.MDIParent = FormObject.MDIParent
Set SOProcObject.SystemProfile = SalesOrderObject.SystemProfile
End If
If ProcessSalesOrder = True Then
If SOProcObject.Setup = 0 Then
ProcessSalesOrder = False
lErrorString = SOProcObject.ErrorString
lErrorModule = SOProcObject.ErrorModule
End If
End If
If ProcessSalesOrder = True Then
If SOProcObject.ProcessSalesOrder(SalesOrderObject.InvoiceID) = 0 Then
ProcessSalesOrder = False
lErrorString = SOProcObject.ErrorString
lErrorModule = SOProcObject.ErrorModule
End If
End If
If Not (SOProcObject Is Nothing) Then
SOProcObject.CleanUp
Set SOProcObject = Nothing
End If
If ProcessSalesOrder = False Then
MsgBox "Error occurred whilst processing : " & lErrorString & vbCrLf & "Module : " & lErrorModule
End If
End Function
Public Function EmailReportDirect(MDIParentObject, SalesOrderObject, ReportFileName, From, EmailTo, Subject, CC, BCC, Message, NameToGiveAttachment, EM_Main_RecID, SourceID, SourceType, SourceDisplayNo, SourceDrillDownIndex, rtnErrorModule, rtnErrorString)
Dim PrintReportObject
Dim m_JiwaReportRange
Dim MyLoop
Dim OldCriticalSectionFlag
EmailReportDirect = True
EM_Main_RecID = ""
If EmailReportDirect = True Then
InternetMailControlLicenseKey = "IPELLICSJMMBMVTC"
Set InternetMailControl = CreateObject("SocketTools.InternetMail")
' Initialize the control with the license key
nError = InternetMailControl.Initialize(InternetMailControlLicenseKey)
If nError > 0 Then
rtnErrorModule = "InternetMailControl.Initialize"
rtnErrorString = "Unable to initialize control:" & vbCrLf & InternetMailControl.LastErrorString
EmailReportDirect = False
End If
End If
If EmailReportDirect = True Then
Set PrintReportObject = CreateObject("JiwaPrintReport.clsJiwaPrintReport")
Set PrintReportObject.Database = SalesOrderObject.Database
Set PrintReportObject.JiwaCommLib = SalesOrderObject.JiwaCommLib
Set PrintReportObject.JLib = SalesOrderObject.JLib
Set PrintReportObject.CrystalApplicationObject = MDIParentObject.GetJWPrintObject
Set PrintReportObject.SystemProfile = SalesOrderObject.SystemProfile
Set PrintReportObject.InternetMailControl = InternetMailControl
End If
If EmailReportDirect = True Then
PrintReportObject.ClearError
PrintReportObject.SetUp
End If
If EmailReportDirect = True Then
If PrintReportObject.ErrorString <> "" Then
rtnErrorString = PrintReportObject.ErrorString
rtnErrorModule = PrintReportObject.ErrorModule
EmailReportDirect = False
End If
End If
If EmailReportDirect = True Then
If PrintReportObject.LoadReport(ReportFileName) = 0 Then
rtnErrorString = PrintReportObject.ErrorString
rtnErrorModule = PrintReportObject.ErrorModule
EmailReportDirect = False
End If
End If
If EmailReportDirect = True Then
'PrintReportObject.OverrideRecordSelectionCriteria = RecordSelectionFormula
For Each m_JiwaReportRange In PrintReportObject.JiwaPrintReportRanges
Select Case UCase(Trim(PrintReportObject.JiwaPrintFormulas(m_JiwaReportRange.FormulaKey).Name))
Case UCase("{@Pass_CurrentHistNo}")
m_JiwaReportRange.Value = SalesOrderObject.SelectedHistoryNo
Case UCase("{@Pass_InvoiceNo}")
m_JiwaReportRange.Value = SalesOrderObject.InvoiceNo
Case UCase("{@Pass_SP_InvoiceHistoryID}")
m_JiwaReportRange.Value = SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).InvoiceHistoryID
End Select
Next
End If
If EmailReportDirect = True Then
If PrintReportObject.UpdateReport = 0 Then
rtnErrorString = PrintReportObject.ErrorString
rtnErrorModule = PrintReportObject.ErrorModule
EmailReportDirect = False
End If
End If
If EmailReportDirect = True Then
If PrintReportObject.EmailReport(From, EmailTo, Subject, CC, BCC, Message, NameToGiveAttachment, EM_Main_RecID, False, SourceID, SourceType, SourceDisplayNo, SourceDrillDownIndex) = 0 Then
rtnErrorString = PrintReportObject.ErrorString
rtnErrorModule = PrintReportObject.ErrorModule
EmailReportDirect = False
End If
End If
If Not (PrintReportObject Is Nothing) Then
PrintReportObject.CleanUp
Set PrintReportObject = Nothing
End If
End Function
Public Function GetReportDetails(SalesOrderObject, rtnReportFileName, rtnReportDescription, rtnLogicalPrinterDeviceName, rtnLogicalPrinterDriverName, rtnLogicalPrinterPort, rtnNumberCopies, rtnErrorString, rtnErrorModule)
GetReportDetails = True
Set PrintSetupObject = CreateObject("JiwaSOPrintSetup.clsSalesOrderReports")
Set PrintSetupObject.SystemProfile = SalesOrderObject.SystemProfile
If PrintSetupObject.ReadRecords = False Then
rtnErrorString = PrintSetupObject.ErrorString
rtnErrorModule = PrintSetupObject.ErrorModule
GetReportDetails = False
Else
For Each lReport In PrintSetupObject
If lReport.ReportType = 0 Then
rtnReportFileName = lReport.ReportPath & "\" & lReport.ReportFileName
rtnReportDescription = lReport.ReportDescription
Set LogicalPrinter = SalesOrderObject.SystemProfile.LogicalPrinters.GetLogicalPrinterFromName(lReport.Printer)
rtnLogicalPrinterDeviceName = LogicalPrinter.DeviceName
rtnLogicalPrinterDriverName = LogicalPrinter.DriverName
rtnLogicalPrinterPort = LogicalPrinter.Port
rtnNumberCopies = lReport.NumberOfCopies
Exit For
End If
Next
End If
End Function
Public Sub ProcessAndEmailOrPrintInvoice(SalesOrderObject, FormObject, MDIParentObject)
NumberCopies = 1
If GetReportDetails(SalesOrderObject, ReportFileName, ReportDescription, LogicalPrinterDeviceName, LogicalPrinterDriverName, LogicalPrinterPort, NumberCopies, ErrorString, ErrorModule) = 0 Then
MsgBox ErrorString
Else
If Trim(ReportFileName) = "" Then
MsgBox "No report has been defined."
Else
If ProcessSalesOrder(FormObject, SalesOrderObject) = True Then
FormObject.ReadRecord 0
If Trim(SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).EmailAddress) <> "" Then
From = "[email protected]"
EmailTo = SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).EmailAddress
Subject = "Invoice for goods supplied" & SalesOrderObject.InvoiceNo
CC = ""
BCC = ""
Message = "Attached is your invoice for your recent order." & vbcrlf & vbcrlf & "Thank you"
NameToGiveAttachment = SalesOrderObject.InvoiceNo & ".pdf"
SourceID = SalesOrderObject.InvoiceID
SourceType = "Sales Order"
SourceDisplayNo = SalesOrderObject.InvoiceNo
If EmailReportDirect(MDIParentObject, SalesOrderObject, ReportFileName, From, EmailTo, Subject, CC, BCC, Message, NameToGiveAttachment, EM_Main_RecID, SourceID, SourceType, SourceDisplayNo, 3, ErrorModule, ErrorString) = 0 Then
MsgBox ErrorString
End If
SalesOrderObject.AddEmailLog Subject, EmailTo, From, CC, BCC, NameToGiveAttachment, "", Message, EM_Main_RecID, False, 0
If SalesOrderObject.SaveOrder(, True) = 0 Then
MsgBox SalesOrderObject.ErrorString
End If
Else
MDIParentObject.ResetReportSelectionFormulaTokens
MDIParentObject.AddReportSelectionFormulaToken "{@Pass_CurrentHistNo}", SalesOrderObject.SelectedHistoryNo
MDIParentObject.AddReportSelectionFormulaToken "{@Pass_InvoiceNo}", SalesOrderObject.InvoiceNo
MDIParentObject.AddReportSelectionFormulaToken "{@Pass_SP_InvoiceHistoryID}", SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).InvoiceHistoryID
MDIParentObject.PrintReportDirect ReportFileName, LogicalPrinterDeviceName, LogicalPrinterDriverName, LogicalPrinterPort, NumberCopies, False, ""
SalesOrderObject.AddPrintLog SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).Ref & " - " & ReportDescription & " (Printed By " & SalesOrderObject.Database.JiwaLoginUserName & ")", 0
If SalesOrderObject.SaveOrder(, True) = 0 Then
MsgBox SalesOrderObject.ErrorString
End If
End If
FormObject.ReadRecord 0
End If
End If
End If
End Sub