Download Quote PDF without QO_Main being modified  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Download Quote PDF without QO_Main being modified

Postby Joe.Thorpe » Mon Mar 25, 2024 5:45 pm

Hi,

I've got a requirement to save Quote PDFs so that Sales can provide a link to customers with their quote.

We have some code which listens to QO_Main being modified through a DB trigger, and syncs that Quote over to our CRM system. I added some logic to that which downloads the Quote PDF from the JIWA API and saves it somewhere.

Unfortunately, whenever a Quote is printed, the InvoicePrinted/QuotePrinted field is set to true, and the LastSavedDateTime is modified. This triggers that DB trigger, resulting in a loop (Quote modified => DB Trigger => Sync => Print PDF => Quote Modified => DB Trigger =>...).

Is there a way to print a Quote without triggering the JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote.Printed event, (or whatever is causing the above behaviour)?

If not, is there another way to solve this problem?

I'm looking into switching to a workflow where the PDF is downloaded from the API upon the user's request, but it currently takes about 4-7 seconds to get a response (have to lookup the report by name, then lookup the Quote by the InvoiceNo, then download the PDF...), but that's too slow.

Saving the Quote PDF on a recurring basis (e.g. every 30 minutes) isn't viable - Sales need to be able to send the quote immediately after creating the quote.

Thanks,
Joe
Joe.Thorpe
Occasional Contributor
Occasional Contributor
 
Posts: 19
Joined: Fri Jun 11, 2021 1:57 pm

Re: Download Quote PDF without QO_Main being modified  Topic is solved

Postby SBarnes » Tue Mar 26, 2024 5:58 am

Hi Joe,

The reason the quote is modified is if it works the same as the sales order is beacause the print log is being updated which triggers the save, the short answer is to print the quote which is a crystal report in another way and the answer is there is a reporting route on the api to do it.

If you look at the plugin on this post viewtopic.php?f=26&t=1254&p=5102&hilit=csv#p5102 you can see the guts of what you need to do but basically the code to do it is shown below. Alternatively if you want to see code to print a report in the rest api plugin do a search for the ReportsServices class and it will show you the code of what to do. The down side is you won't get an entry in the print log saying it was printed unless you execute an SQL statement to add this.

Code: Select all
               using (ReportsServices rs = base.ResolveService<ReportsServices>())
               {
                  ReportsPDFGETRequest pdfreq = new ReportsPDFGETRequest();
                  pdfreq.ReportID = RESTAPIPlugin.InvoiceReportID;
                  pdfreq.ReportParameters = new List<ReportParameter>();
                  pdfreq.AsAttachment = true;
                  pdfreq.ReportParameters.Add(new ReportParameter(){Name = "Pass_SP_InvoiceHistoryID", Value = HistoryID});
                  return  rs.Get(pdfreq);               
               }         
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Download Quote PDF without QO_Main being modified

Postby Mike.Sheen » Tue Mar 26, 2024 3:04 pm

Joe.Thorpe wrote:Hi,

I've got a requirement to save Quote PDFs so that Sales can provide a link to customers with their quote.

We have some code which listens to QO_Main being modified through a DB trigger, and syncs that Quote over to our CRM system. I added some logic to that which downloads the Quote PDF from the JIWA API and saves it somewhere.

Unfortunately, whenever a Quote is printed, the InvoicePrinted/QuotePrinted field is set to true, and the LastSavedDateTime is modified. This triggers that DB trigger, resulting in a loop (Quote modified => DB Trigger => Sync => Print PDF => Quote Modified => DB Trigger =>...).

Is there a way to print a Quote without triggering the JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote.Printed event, (or whatever is causing the above behaviour)?

If not, is there another way to solve this problem?

I'm looking into switching to a workflow where the PDF is downloaded from the API upon the user's request, but it currently takes about 4-7 seconds to get a response (have to lookup the report by name, then lookup the Quote by the InvoiceNo, then download the PDF...), but that's too slow.

Saving the Quote PDF on a recurring basis (e.g. every 30 minutes) isn't viable - Sales need to be able to send the quote immediately after creating the quote.

Thanks,
Joe


Are you using a database trigger on QO_Main to perform a push sync of data into another system?
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Download Quote PDF without QO_Main being modified

Postby Joe.Thorpe » Tue Mar 26, 2024 3:13 pm

Mike.Sheen wrote:
Joe.Thorpe wrote:Hi,

I've got a requirement to save Quote PDFs so that Sales can provide a link to customers with their quote.

We have some code which listens to QO_Main being modified through a DB trigger, and syncs that Quote over to our CRM system. I added some logic to that which downloads the Quote PDF from the JIWA API and saves it somewhere.

Unfortunately, whenever a Quote is printed, the InvoicePrinted/QuotePrinted field is set to true, and the LastSavedDateTime is modified. This triggers that DB trigger, resulting in a loop (Quote modified => DB Trigger => Sync => Print PDF => Quote Modified => DB Trigger =>...).

Is there a way to print a Quote without triggering the JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote.Printed event, (or whatever is causing the above behaviour)?

If not, is there another way to solve this problem?

I'm looking into switching to a workflow where the PDF is downloaded from the API upon the user's request, but it currently takes about 4-7 seconds to get a response (have to lookup the report by name, then lookup the Quote by the InvoiceNo, then download the PDF...), but that's too slow.

Saving the Quote PDF on a recurring basis (e.g. every 30 minutes) isn't viable - Sales need to be able to send the quote immediately after creating the quote.

Thanks,
Joe


Are you using a database trigger on QO_Main to perform a push sync of data into another system?


Yeah correct (through https://github.com/IsNemoEqualTrue/moni ... dependency).

Turns out printing the PDF through the API wasn't causing the loop. A very old and forgotten service was.
Joe.Thorpe
Occasional Contributor
Occasional Contributor
 
Posts: 19
Joined: Fri Jun 11, 2021 1:57 pm

Re: Download Quote PDF without QO_Main being modified

Postby Mike.Sheen » Tue Mar 26, 2024 3:17 pm

Joe.Thorpe wrote:Yeah correct (through https://github.com/IsNemoEqualTrue/moni ... dependency).

Turns out printing the PDF through the API wasn't causing the loop. A very old and forgotten service was.


I'm confused now - is this still an issue for you?
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Download Quote PDF without QO_Main being modified

Postby Joe.Thorpe » Tue Mar 26, 2024 3:18 pm

Mike.Sheen wrote:
Joe.Thorpe wrote:Yeah correct (through https://github.com/IsNemoEqualTrue/moni ... dependency).

Turns out printing the PDF through the API wasn't causing the loop. A very old and forgotten service was.


I'm confused now - is this still an issue for you?


Apologies for the confusion - no it's resolved now.
Joe.Thorpe
Occasional Contributor
Occasional Contributor
 
Posts: 19
Joined: Fri Jun 11, 2021 1:57 pm


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 16 guests

cron