Sales Order printing, changing rpt on the fly
I have been given the task of writing a plugin which will change the sales order report based on the debtor.
Basically the client will be printing an invoice as per their normal workflow, but when a sales order has a specific debtor, then a delivery docket must print out instead.
They do not have the print selection popup, nor do they have print to screen turned on. This means that as soon as they click the print icon in the toolbar, the output spits out of the printer, no dialogs at all.
I can add their delivery docket into the sales order print collection, but I am finding that both the invoice and delivery docket print out automatically. I just need one or the other.
I think I have successfully swapped from the invoice to the delivery docket based on the debtor (see code below).
I am hooking into the salesOrderForm.SalesOrder.Printing event as that seems to be the only event where I can capture the debtor and change the report before printing.
I can't find a way to just get one report to print out, even though there could be multiple reports in the collection. I thought of incrementing a counter, but that didn't seem to go well, and the ClientCancelledException aborts the whole print job.
Unfortunately, the client has a deadline to get something implemented tomorrow. Yeah, I know!
This is my effort so far.
Any feedback would be appreciated.
Cheers
Danny
Basically the client will be printing an invoice as per their normal workflow, but when a sales order has a specific debtor, then a delivery docket must print out instead.
They do not have the print selection popup, nor do they have print to screen turned on. This means that as soon as they click the print icon in the toolbar, the output spits out of the printer, no dialogs at all.
I can add their delivery docket into the sales order print collection, but I am finding that both the invoice and delivery docket print out automatically. I just need one or the other.
I think I have successfully swapped from the invoice to the delivery docket based on the debtor (see code below).
I am hooking into the salesOrderForm.SalesOrder.Printing event as that seems to be the only event where I can capture the debtor and change the report before printing.
I can't find a way to just get one report to print out, even though there could be multiple reports in the collection. I thought of incrementing a counter, but that didn't seem to go well, and the ClientCancelledException aborts the whole print job.
Unfortunately, the client has a deadline to get something implemented tomorrow. Yeah, I know!
This is my effort so far.
- Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)
AddHandler salesOrderForm.SalesOrder.Printing, AddressOf SOPrinting
End Sub
Sub SOPrinting (sender As Object, e As System.eventargs, ByRef Report As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport)
msgbox(PrintedReportCounter)
If PrintedReportCounter = 0 Then ' Just print a single report no matter how many are in the print collection.
Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast( sender , JiwaSales.SalesOrder.SalesOrder)
If salesOrder.Debtor.AccountNo = "1140" Then
For Each salesOrderReport As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport In salesOrder.SalesOrderReports
If salesOrderReport.ReportDefinition.Report.FileName = "MNT30000 - My Delivery Docket.rpt" Then
Report = salesOrderReport
Exit For
End If
Next
End If
End If
PrintedReportCounter = PrintedReportCounter + 1
If PrintedReportCounter > 0 Then
Throw New JiwaApplication.Exceptions.ClientCancelledException
End If
End Sub
Any feedback would be appreciated.
Cheers
Danny