Page 1 of 1

Download Quote PDF without QO_Main being modified

PostPosted: Mon Mar 25, 2024 5:45 pm
by Joe.Thorpe
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

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

PostPosted: Tue Mar 26, 2024 5:58 am
by SBarnes
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);               
               }         

Re: Download Quote PDF without QO_Main being modified

PostPosted: Tue Mar 26, 2024 3:04 pm
by Mike.Sheen
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?

Re: Download Quote PDF without QO_Main being modified

PostPosted: Tue Mar 26, 2024 3:13 pm
by Joe.Thorpe
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.

Re: Download Quote PDF without QO_Main being modified

PostPosted: Tue Mar 26, 2024 3:17 pm
by Mike.Sheen
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?

Re: Download Quote PDF without QO_Main being modified

PostPosted: Tue Mar 26, 2024 3:18 pm
by Joe.Thorpe
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.