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