SuiteCRM PDF Template - Custom Field generation

Hi,
We are generating invoices using PDF templates in SuiteCRM. One of our requirement is to print the total amount in words. We have added a placeholder in the template file as %%total_amount_in_words%%. Then in …\modules\AOS_PDF_Templates\generatePdf.php file, we have added the following lines of code.

$number = "\$"."aos_invoices" . "_total_amount";
$newValueTemp = str_replace(',','',$number);
$amountInWords = convertNumberToWords($newValueTemp);
$text = str_replace("%%total_amount_in_words%%", $amountInWords , $text);

The values from $aos_invoices_total_amount is 10,000.00 (with comma as per the formatting). We would like to get this removed as we want to pass this to another php function to get the number in words. With the above code, the conversion fails when we call the function as the ‘,’ (Comma) is not removed.

Just to make sure we are doing it right, we have tried replacing even one of the digits. Its still fails to replace it. Looks like we are not able to manipulate anything on the string.

Any help and advice is highly appreciated.

What exactly is the content of $number before the first str_replace?

And what exactly is the content of NewValueTemp after that str_replace?

$number shows 10,000.00 and $newValueTemp also shows the same

How are you “showing” those values? I wonder if their value is actually just 10000 and the commas just get added again when it’s displayed. You could determine this better if you were looking at the values in a debugger.

Maybe a different approach could work better: https://stackoverflow.com/a/11026779/1189711

No luck. Tried this. The problem seems to be different actually. Var_dump prints nothing at all.

Just to solve the issue, is there a way to add total amount in words in a pdf template?

No, there is no way to do that unless you write the function yourself.

What you’re facing here is just some weird PHP behavior. It really should work, and once you understand what’s happening, which data types are being used, which functions are changing the display, etc., it should be pretty easy to solve. I just can’t help much from a distance - you need to be able to debug the code and test different things to figure out what is wrong… good luck.