Sales Order printing, changing rpt on the fly  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Sales Order printing, changing rpt on the fly

Postby DannyC » Thu May 19, 2016 4:54 pm

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.
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
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Sales Order printing, changing rpt on the fly  Topic is solved

Postby Mike.Sheen » Mon May 23, 2016 8:30 pm

You probably want to hook into the PrintingMany event, instead of the Printing event.

In there you can examine all the reports in the ReportCollection passed in as a parameter to that event, and remove the reports you don't want to print.

Just remember that removing items in a collection whilst inside a for each loop will product unexpected results, so use a For Next loop instead - starting from the Count back to 1, with a Step -1.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Sales Order printing, changing rpt on the fly

Postby DannyC » Thu May 26, 2016 12:24 pm

Thx Mike.
Have sorted out this one using your suggestion re PrintingMany.

Cheers.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests