Retrieve Quote Form Report and change the associated report

Find general Jiwa support here.

Retrieve Quote Form Report and change the associated report

Postby changsen.wu » Mon Jun 01, 2015 8:54 am

Hi Mike/Scott

Can you please advise how I can determine which report is associated with a non-sales order form (such as quote) other than reading and setting the Jiwa.xml using JiwaSysProfile object and how I can change the report used on the fly? I understand how sales order form reports work through the specialised clsSalesOrderReports object. I don't see anything similar for other form based reports.

Thanks

Changsen
changsen.wu
I'm new here
I'm new here
 
Posts: 8
Joined: Wed Sep 03, 2014 10:20 am

Re: Retrieve Quote Form Report and change the associated rep

Postby Scott.Pearce » Mon Jun 01, 2015 4:43 pm

When "Print" is clicked for any given form, what normally happens is the form calls MDIParent.CreateReport (MDIParent being the main startup form in Jiwa.exe) and passes a hard coded XPath. CreateReport () then talks to the JiwaSysProfile object, again passing on the XPath, to retrieve the filename and path of the report from an in-memory copy of Jiwa.xml. CreateReport() then loads up JiwaPrintReportUI and provides it with the report filename and path it obtained from JiwaSysProfile.

Could you perhaps manipulate MDIParent.CurrentSystemProfile.XMLDoc at form load time?
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Retrieve Quote Form Report and change the associated rep

Postby changsen.wu » Mon Jun 01, 2015 4:53 pm

Hi Scott

XMLDoc property from clsSysProfile class is a read only property. Are you able to post the code that is used to call the form report so that I can replicate it in breakout. Specifically I am looking for the MDIParentObject.CreateReport method signature and ways to load the report on screen (presumably one of the parameters within the CreateReport method). BTW, any chance of getting a full list of MDIParent object's public methods and what it does?

Thanks

Changsen
changsen.wu
I'm new here
I'm new here
 
Posts: 8
Joined: Wed Sep 03, 2014 10:20 am

Re: Retrieve Quote Form Report and change the associated rep

Postby Scott.Pearce » Mon Jun 01, 2015 5:41 pm

XMLDoc is read only, but I would have thought that you would still be able to perform direct operations on it, just not "set" it.

Anyway, here is CreateReport() and GetReportDetailsFromXPath() (which it calls). Both of these are public and reside in MDIParent (internally known as WildWindFrame).

Code: Select all
Public Function CreateReport(ByVal XPath As String, Optional ByVal NumberCopies As Long = 1, Optional ByVal PrintToScreen As Boolean = True, Optional ByVal ShowRanges As Boolean = True, Optional ByVal PromptUser As Boolean = False, Optional ByVal RecordSelectionFormula As String = "", Optional ByVal PromptOnInvalidReport As Boolean = True, Optional ByVal ReportsAllowed As Integer = 2) As Object
Dim LocalExternalActiveXApp As Object
Dim ExternalMDILoadTest As Boolean
Dim lReportPathAndFile As String
Dim lReportCaption As String
Dim lPrinterDeviceName As String
Dim lPrinterDriverName As String
Dim lPrinterPort As String
Dim lLogicalPrinterName As String
   
    Set LocalExternalActiveXApp = AddNewExternalMDIObject("JiwaPrintReportUI.StdFunctions")
    If Not (LocalExternalActiveXApp Is Nothing) Then

        ExternalMDILoadTest = True
        On Error Resume Next
            ExternalMDILoadTest = LocalExternalActiveXApp.CanLoad
        On Error GoTo 0

        If ExternalMDILoadTest = True Then
       
            If GetReportDetailsFromXPath(XPath, lReportCaption, lReportPathAndFile, lPrinterDeviceName, lPrinterDriverName, lPrinterPort, lLogicalPrinterName) = True Then
           
                Set LocalExternalActiveXApp.CrystalApplicationObject = JWPrint
                LocalExternalActiveXApp.LogicalPrinterName = lLogicalPrinterName
                LocalExternalActiveXApp.ReportTitle = lReportCaption
                LocalExternalActiveXApp.ReportFile = lReportPathAndFile
                LocalExternalActiveXApp.NumberCopies = NumberCopies
                LocalExternalActiveXApp.PrintToScreen = PrintToScreen
                LocalExternalActiveXApp.OverrideRecordSelectionFormula = RecordSelectionFormula
                LocalExternalActiveXApp.ShowRangesTab = ShowRanges
                LocalExternalActiveXApp.PromptUser = PromptUser
                LocalExternalActiveXApp.ReportsAllowed = ReportsAllowed
   
                LocalExternalActiveXApp.Start
               
                If LocalExternalActiveXApp.Terminated = False Then
                    Set CreateReport = LocalExternalActiveXApp
                End If
            End If
                       
        End If
    End If
End Function


Code: Select all
Public Function GetReportDetailsFromXPath(ByVal XPath As String, ByRef ReportCaption As Variant, ByRef ReportPathAndFile As Variant, ByRef PrinterDeviceName As Variant, ByRef PrinterDriverName As Variant, ByRef PrinterPort As Variant, Optional ByRef LogicalPrinterName As String) As Boolean
Dim lLogicalPrinterName As String
Dim lReportPath As String
Dim lReportFile As String
Dim lLogicalPrinter As JiwaSysProfile.clsLogicalPrinter

    GetReportDetailsFromXPath = True
   
    On Error GoTo ErrorHandler
   
    ReportCaption = CurrentSystemProfile.GetValue(XPath & "/Caption")

    lReportFile = CurrentSystemProfile.GetValue(XPath & "/File")
    lReportPath = CurrentSystemProfile.GetValue(XPath & "/Path")
    If lReportFile = "" Or lReportPath = "" Then
        ReportPathAndFile = ""
    Else
        ReportPathAndFile = lReportPath & IIf(Right(lReportPath, 1) <> "\", "\", "") & lReportFile
    End If
   
    lLogicalPrinterName = WildWindFrame.CurrentSystemProfile.GetValue(XPath & "/LogicalPrinterName")

    Set lLogicalPrinter = CurrentSystemProfile.LogicalPrinters.GetLogicalPrinterFromName(lLogicalPrinterName)
       
    If Not lLogicalPrinter Is Nothing Then
        PrinterDeviceName = lLogicalPrinter.DeviceName
        PrinterDriverName = lLogicalPrinter.DriverName
        PrinterPort = lLogicalPrinter.Port
        LogicalPrinterName = lLogicalPrinter.LogicalPrinterName
        Set lLogicalPrinter = Nothing
    Else
        PrinterDeviceName = ""
        PrinterDriverName = ""
        PrinterPort = ""
        LogicalPrinterName = ""
    End If
   
    On Error GoTo 0
    Exit Function

ErrorHandler:
    GetReportDetailsFromXPath = False

End Function


For context, here is the what happens when Print is clicked in Quotes:

Code: Select all
Public Sub mRecordPrint_Click()

    If RunFormPrintBeforeBreakout = False Then
        'WindowTitle = "Printout of " & SalesQuotes.QuoteNo
       
        ' Save first
        If SalesQuotes.RecordMode = e_SalesQuoteInsertUpdateMode Or SalesQuotes.QuotePrinted = False Then
           
            If SalesQuotes.RecordMode = e_SalesQuoteNormalMode Then
                'SavingForPrint = True
            End If
           
            ' Save first
            SalesQuotes.QuotePrinted = True
            SaveQuote True
            DoEvents
           
            'SavingForPrint = False
        End If
       
        Call InvPrint(SalesQuotes.SystemSettings.PrintToScreen)

        RunFormPrintCompleteBreakout
    End If
   
End Sub


Code: Select all
Private Sub InvPrint(ByVal PrintToScreen As Boolean)
Dim PrintUIObject As Object
Dim IsSPBasedReport As Boolean
Dim MyLoop As Long

    If PrintToScreen = True Then
        Set PrintUIObject = MDIParent.CreateReport("/JiwaDocument/FormReports/Form[@Name='JiwaSalesQuotesUI.Quoting']/Report[@Key='QTReport']", 1, True, False, True, "")
        If Not (PrintUIObject Is Nothing) Then
                                   
            IsSPBasedReport = False
       
            For MyLoop = 1 To PrintUIObject.ExposedForm.PrintReportObject.JiwaPrintReportRanges.Count
                If UCase(PrintUIObject.ExposedForm.PrintReportObject.JiwaPrintFormulas(PrintUIObject.ExposedForm.PrintReportObject.JiwaPrintReportRanges(MyLoop).FormulaKey).Name) = UCase("{@Pass_SP_QuoteHistoryID}") Then
                    PrintUIObject.ExposedForm.PrintReportObject.JiwaPrintReportRanges(MyLoop).Value = SalesQuotes.SalesQuoteHistorys(SalesQuotes.SelectedHistoryNo).InvoiceHistoryID
                    IsSPBasedReport = True
                    Exit For
                End If
            Next MyLoop
           
            If IsSPBasedReport = False Then
                PrintUIObject.ExposedForm.PrintReportObject.OverrideRecordSelectionCriteria = PrintUIObject.ExposedForm.PrintReportObject.CrystalReportObject.RecordSelectionFormula
                PrintUIObject.ExposedForm.PrintReportObject.OverrideRecordSelectionCriteria = Replace(PrintUIObject.ExposedForm.PrintReportObject.OverrideRecordSelectionCriteria, "{@Pass_CurrentHistNo}", Database.FormatNumber(Format$(SalesQuotes.SelectedHistoryNo, "00")))
                PrintUIObject.ExposedForm.PrintReportObject.OverrideRecordSelectionCriteria = Replace(PrintUIObject.ExposedForm.PrintReportObject.OverrideRecordSelectionCriteria, "{@Pass_QuoteNo}", Database.FormatChar(SalesQuotes.QuoteNo))
            End If
           
            PrintUIObject.ExposedForm.UpdateReport
            PrintUIObject.ExposedForm.PrintReportToScreen
        End If
    Else
        MDIParent.ResetReportSelectionFormulaTokens
        MDIParent.AddReportSelectionFormulaToken "{@Pass_CurrentHistNo}", Database.FormatNumber(Format$(SalesQuotes.SelectedHistoryNo, "00"))
        MDIParent.AddReportSelectionFormulaToken "{@Pass_QuoteNo}", SalesQuotes.QuoteNo
        MDIParent.AddReportSelectionFormulaToken "{@Pass_SP_QuoteHistoryID}", SalesQuotes.SalesQuoteHistorys(SalesQuotes.SelectedHistoryNo).InvoiceHistoryID
       
        Call MDIParent.PrintReportDirectXPath("/JiwaDocument/FormReports/Form[@Name='JiwaSalesQuotesUI.Quoting']/Report[@Key='QTReport']")
    End If
   
End Sub
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Retrieve Quote Form Report and change the associated rep

Postby changsen.wu » Tue Jun 02, 2015 5:07 pm

Hi Scott

Thanks for the code snippet. I am still having trouble with exporting the report to a PDF file.

Please see the code snippet below:

Code: Select all
        With JiwaPrintReportObject
            If Not .LoadReport(QuoteReportPath) Then
                MsgBox "Error loading quote report " & QuoteReportPath & ":" & .ErrorString, vbCritical + vbInformation, "Jiwa"
                .CleanUp
                Set JiwaPrintReportObject = Nothing
                rtnCancel = True
                Exit Sub
            End If
        End With
       
        With SalesQuoteObject.Database
            SQL = "select a.invoiceno, a.currenthistoryno, b.invoicehistoryid from qo_main a inner join qo_history b on a.invoiceid=b.invoiceid and a.currenthistoryno=b.historyno where a.invoiceno between " & .FormatChar(StartingQuoteNo) & " and " & .FormatChar(EndingQuoteNo) & " order by invoiceno"
            ReadHandle = .StatementOpen(.ConnectionRead1)
           
            If .ExecuteSelect(CInt(ReadHandle), SQL, True) Then
                While .FetchRow(CInt(ReadHandle))
                    CurrentQuoteNo = .GetData(CInt(ReadHandle), 1)
                    CurrentHistoryNo = .GetData(CInt(ReadHandle), 2)
                    CurrentInvoiceHistoryID = .GetData(CInt(ReadHandle), 3)
                   
                    With JiwaPrintReportObject
                        .ResetReportSelectionFormulaTokens
                        .AddReportSelectionFormulaToken "{@Pass_CurrentHistNo}", Right("00" & CurrentHistoryNo, 2)
                        .AddReportSelectionFormulaToken "{@Pass_QuoteNo}", CurrentQuoteNo
                        .AddReportSelectionFormulaToken "{@Pass_SP_QuoteHistoryID}", CurrentInvoiceHistoryID
                        If .UpdateReport = e_PrintReportReturnCodeSuccess Then
                            With .CrystalReportObject.ExportOptions
                                .DestinationType = crEDTDiskFile
                                If FileType = "XLS" Then
                                    .FormatType = crEFTExcel97
                                Else
                                    .FormatType = crEFTPortableDocFormat
                                    .PDFExportAllPages = True
                                End If
                                .DiskFileName = QuoteFolder & CurrentQuoteNo & "." & FileType
                               
                            End With
                            .CrystalReportObject.Export False
                        Else
                            MsgBox "Unable to export quote report for " & CurrentQuoteNo & ":" & .ErrorString, vbCritical + vbInformation, "Jiwa"
                        End If
                    End With
                Wend
            Else
                MsgBox "Error retrieving quotes to print : " & .ErrorMessage, vbCritical + vbInformation, "Jiwa"
                JiwaPrintReportObject.CleanUp
                Set JiwaPrintReportObject = Nothing
                Set FSO = Nothing
                rtnCancel = True
                Exit Sub
            End If
           
            .StatementClose CInt(ReadHandle)
        End With
       


I am getting an error at UpdateReport method. The actual error message is "The string is non-numeric". As I am testing with a standard Jiwa report, I can't see what could be triggering this error. I am not sure if you have come across similar issue before or not that could explain this behaviour.

In addition, as you can see from my code, I am exporting out a set of quote reports to disk. Do I know need to call cleanup and setup on JiwaPrintReport object each time before I export, or the current way I am doing it is fine?

Thanks

Changsen
changsen.wu
I'm new here
I'm new here
 
Posts: 8
Joined: Wed Sep 03, 2014 10:20 am


Return to Core Product Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron