Invoice PDF file names

Hi there,

Two questions for the coding community:

  1. How do I change the default file names for Invoices exported from SuiteCRM?
  2. Is it possible to add some logic code that alters the file name according to the customer/account name or a custom field?

I have had a poke at the code, but I can’t find the relevant section.

Thanks in advance,

Ben

Hi Ben,

The filename is generated around line 122 of modules/AOS_PDF_Templates/generatePdf.php (https://github.com/salesagility/SuiteCRM/blob/hotfix-7.2.3/modules/AOS_PDF_Templates/generatePdf.php#L122).

You can change the static string at the start by changing the LBL_PDF_NAME label in the appropriate module (i.e. in invoices).

It’s possible to change the naming but would require some customisation. Making the changes in the above file isn’t upgrade safe so it’s better to create a copy of this file and place it into ‘custom/modules/AOS_PDF_Templates/generatePdf.php’ and make the changes you need there. This file isn’t automatically picked up unfortunately. This means you’ll also need to edit the $entry_point_registry to point to the new version of generatePdf (have a look in ‘custom/Extension/application/Ext/EntryPointRegistry/*’ for examples of how to change this).

Hope this helps,
Jim

2 Likes

Thanks Jim, that’s great. I’ll try and set some time aside this weekend and have a stab at making the required changes.

hey blloyd, any luck? I’d be interested in this as well!

I added a little if-statement so that the pdf-file-name uses custom-field data, but only when the respective module is being used ( in this case the invoices module).

if ($module_type=="AOS_Invoices") { 

        // custom naming scheme for Invoices module
	$file_name = "RG_".substr($module->invoice_date, -2).substr($module->invoice_date, 3, 2).substr($module->invoice_date, 0, 2)."_".$module->kostenstelle_c."_".$module->kontierung_c."_".$module->number."_".str_replace(" ","_",$module->name_anschrift_c).".pdf"; 
			
} else {
			
	$file_name = $mod_strings['LBL_PDF_NAME']."_".str_replace(" ","_",$module->name).".pdf";  // original naming scheme
				
} 

I’d appreciate some more pointers as to how to make this be picked up in the custom folder to make it upgrade-safe (I could use this also for changes we had to make to the phpmailer class…)

Hello,

I have used your tip on my previous 7.6.3 version and was able to customise pdf file name ( note : this could be a “standard” feature accessible directly from admin/global settings).

I have upgraded to 7.7.5, made exact same changes to the file modules/AOS_PDF_Templates/generatePdf.php but unfortunately it didn’t work, and I am not a programmer so I do not understand my mistake. Maybe someone could help me understand :

I would like the following :
-> for quotes module, pdf name should be formated as : quote_[billing_account_name]_[quote_number].pdf
I have the following code :


if ($module_type=="AOS_Invoices") { 
		// custom naming scheme for Invoices module
		$file_name = "Facture_".str_replace(" ","_",$module->billing_account)."_".$module->number."_".substr($module->invoice_date, 0, 2).substr($module->invoice_date, 3, 2).substr($module->invoice_date, -2).".pdf";
		} elseif ($module_type=="AOS_Quotes") {
		// custom naming scheme for Quotes module
		$file_name = "Devis_".str_replace(" ","_",$module->billing_account)."_".$module->number.".pdf";
		} else {			
		$file_name = $mod_strings['LBL_PDF_NAME']."_".str_replace(" ","_",$module->name).".pdf";  // original naming scheme				
	}	

I only get : ‘Devis_.pdf’ as pdf filename … [billing_account_name and quote_number do not appear.

Note : I have the same issue with invoices, the pdf name is : Facture_.pdf

It worked for version 7.6.3 but doesn’t for 7.7.5 … Could anyone help me understand why ?

Thank you

1 Like

Hello,

I have corrected my mistake and the code works for 7.7.5 :

(around line 138 in file modules/AOS_PDF_Templates/generatePdf.php )


if ($bean->module_dir=="AOS_Invoices") { 
		// custom naming scheme for Invoices module
		$file_name = "Facture_".str_replace(" ","_",$bean->billing_account)."_".$bean->number."_".substr($bean->invoice_date, 0, 2).substr($bean->invoice_date, 3, 2).substr($bean->invoice_date, -2).".pdf";
		} elseif ($bean->module_dir=="AOS_Quotes") {
		// custom naming scheme for Quotes module
		$file_name = "Devis_".str_replace(" ","_",$bean->billing_account)."_".$bean->number.".pdf";
		} else {			
		$file_name = $mod_strings['LBL_PDF_NAME'] . "_" . str_replace(" ", "_", $bean->name) . ".pdf"; 	// original naming scheme			
	}	

Miroslav

1 Like