Error Generating PDF from the Quotes Module

Good morning,

I wanted to ask if anyone has encountered this issue when generating a PDF, whether for printing (downloading) or sending it via email using the options provided by the Quotes module.

Specifically, our issue is that it only fails in the Quotes module, while it works correctly in the Invoices module.

I investigated whether it could be a permission issue with the tmp folder. Since we use Apache, I changed the user to daemon:daemon and granted write permissions, thinking that might be the problem, but it didn’t work.

We have a PDF template for quotes, but when we try to print or send the PDF from a record, instead of opening a new tab with the PDF or the email for sending it as an attachment, the same page refreshes and goes blank, with the URL remaining as: example.com.ar/index.php?entryPoint=generatePdf. Whether checking the console or Grafana, it returns a 500 error.

The strange part is that it works in one module but not in the other, and the error doesn’t provide more information.

I’d like to know if anyone has experienced the same issue and if they found the cause.

version suiteCRM: 7.14.4

Thanks in advance!

Hey

Please go to the file
modules/AOS_PDF_Templates/generatePdf.php

In the top of this file add these two lines

<?php
ini_set('display_errors',1);
ini_set('error_reporting',E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_WARNING);

Then try to download the PDF using generatePdf functionality.
It should show you the error that is occurring. Post the error here and we should be able to help you further.

After resolving the error remember to remove these two lines

Thank you very much for your prompt response. I added those two lines you mentioned, and it returned the following error on the screen:
Fatal error: Uncaught TypeError: round(): Argument #1 ($num) must be of type int|float, array given in /bitnami/suitecrm/modules/Currencies/Currency.php:412 Stack trace: #0 /bitnami/suitecrm/modules/Currencies/Currency.php(412): round() #1 /bitnami/suitecrm/modules/AOS_PDF_Templates/templateParser.php(154): format_number() #2 /bitnami/suitecrm/modules/AOS_PDF_Templates/templateParser.php(37): templateParser::parse_template_bean() #3 /bitnami/suitecrm/modules/AOS_PDF_Templates/generatePdf.php(369): templateParser::parse_template() #4 /bitnami/suitecrm/modules/AOS_PDF_Templates/generatePdf.php(277): populate_product_lines() #5 /bitnami/suitecrm/modules/AOS_PDF_Templates/generatePdf.php(147): populate_group_lines() #6 /bitnami/suitecrm/include/MVC/Controller/SugarController.php(1017): require_once(‘…’) #7 /bitnami/suitecrm/include/MVC/Controller/SugarController.php(465): SugarController->handleEntryPoint() #8 /bitnami/suitecrm/include/MVC/Controller/SugarController.php(361): SugarController->process() #9 /bitnami/suitecrm/include/MVC/SugarApplication.php(101): SugarController->execute() #10 /bitnami/suitecrm/index.php(52): SugarApplication->execute() #11 {main} thrown in /bitnami/suitecrm/modules/Currencies/Currency.php on line 412

And this in the console:
GET
https://desarrollocrm2.flexxus.com.ar/favicon.ico

Have you made any custom changes to modules/Currencies/Currency.php file ?

No, no, I haven’t made any changes to that file. But I think the error might be happening because a value is being passed incorrectly, maybe as an array instead of taking each value individually. I’m currently checking that.

Could it be that, in the case of a quote, multiple values are being passed at once, or all the product line items together, causing the error? If the quote has no product items, the PDF is generated correctly. The issue arises when there is a product list.

Probably adding some logging or a simple vardump of the variable being formatted here might help you investigate further

Thank you very much for the guidance you provided. Being able to view the errors and identify the files allowed me to determine the issue.

I reviewed both templateParser.php and Currency.php and made changes to Currency.php, adding:

php

if (is_array($amount)) {
    $amount = reset($amount);
}

inside the number formatting function. With that, the PDF was correctly generated and displayed.

1 Like

Is that a fix that could be proposed as a PR to be integrated into the core code for every one?

Hi pgr,
Yes, definitely. I have found several people in the community who have had this issue, and this would probably be a reliable solution.

1 Like

Have you ever made a PR? This could be your first one :rocket:

1 Like