Mas-J Posted July 3, 2019 Share Posted July 3, 2019 Hello Everyone, I activate the proforma invoice feature for invoice. I want rename the PDF being sent to client if the invoice status is Unpaid become "Proforma Invoice-1900001" instead of the standard name "Invoice-1900001" So, it will make a differenciation between Unpaid invoice and Paid invoice PDF when client recieved it. Do you know what file and script should I edit to make it possible ? 0 Quote Link to comment Share on other sites More sharing options...
smart-mouse Posted June 17, 2020 Share Posted June 17, 2020 Same problem here, please. Did you resolve this? Thank you 0 Quote Link to comment Share on other sites More sharing options...
anoopk40 Posted June 18, 2020 Share Posted June 18, 2020 same here. Waiting for the update. 0 Quote Link to comment Share on other sites More sharing options...
Maison Posted August 1, 2020 Share Posted August 1, 2020 Changing/Translating Filename The default filename for invoices is Invoice-xxx. For quotes, this is Quote-xxx. For both, xxx is the ID of the invoice or quote. It may be desirable to change the filenames the clients see or translate into other languages. Achieve this in the same way as any text within WHMCS, by using the Language Files. Look for these strings: $_LANG['invoicefilename'] = "Invoice-"; $_LANG['quotefilename'] = "Quote-"; 0 Quote Link to comment Share on other sites More sharing options...
Mas-J Posted August 3, 2020 Author Share Posted August 3, 2020 On 8/1/2020 at 7:17 PM, zimbahost said: Changing/Translating Filename The default filename for invoices is Invoice-xxx. For quotes, this is Quote-xxx. For both, xxx is the ID of the invoice or quote. It may be desirable to change the filenames the clients see or translate into other languages. Achieve this in the same way as any text within WHMCS, by using the Language Files. Look for these strings: $_LANG['invoicefilename'] = "Invoice-"; $_LANG['quotefilename'] = "Quote-"; Thanks for the suggestion, but this is not the solution for my question actually 🙂 0 Quote Link to comment Share on other sites More sharing options...
Maison Posted August 3, 2020 Share Posted August 3, 2020 Sorry I got it wrong, you need two names in the files, one name when the invoice is open and one when the invoice is paid. Cool this idea also had thinking about it before. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 3, 2020 Share Posted August 3, 2020 2 hours ago, zimbahost said: Sorry I got it wrong, you need two names in the files, one name when the invoice is open and one when the invoice is paid. this would be so easy for WHMCS to do. themselves. 2 hours ago, zimbahost said: Cool this idea also had thinking about it before. I assume the feature request below was from Mas-J ? https://requests.whmcs.com/topic/change-proforma-file-name-without-eu-vat-addon I can think of one potential way to do it with a hook (untested - so it's only theoretical) - but doesn't Kian's Billing Extension rename the filename ?? if so, he'll know how to do this. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 3, 2020 Share Posted August 3, 2020 (edited) There's no way to do that with standard WHMCS. The first solution that comes to mind is boring but should work. Use EmailPreSend to detect invoice-related emails and abort sending (you can't handle attachments via API) Re-create the same email directly including phpMailer class Download the invoice from dl.php file (Admin authentication required) and store it in a PHP variable (eg. $output = curl_exec($ch);) Query db to retreive invoice status and anything you want Name the PDF as you wish like for example "I am Sexy 2020 this invoice is Unpaid You are client ID 120 with USD currency.pdf") bold words come from database echo $output in that file setting haders (application/pdf) Attach the newly generated file in th email and send it As I said it is boring. Edited August 3, 2020 by Kian 0 Quote Link to comment Share on other sites More sharing options...
Mas-J Posted August 4, 2020 Author Share Posted August 4, 2020 14 hours ago, zimbahost said: Sorry I got it wrong, you need two names in the files, one name when the invoice is open and one when the invoice is paid. Cool this idea also had thinking about it before. No problem, hehe.. 10 hours ago, brian! said: this would be so easy for WHMCS to do. themselves. I assume the feature request below was from Mas-J ? https://requests.whmcs.com/topic/change-proforma-file-name-without-eu-vat-addon I can think of one potential way to do it with a hook (untested - so it's only theoretical) - but doesn't Kian's Billing Extension rename the filename ?? if so, he'll know how to do this. It's not me, but I've vote for it but I think WHMCS didn't consider it since 2 years ago LoL 9 hours ago, Kian said: There's no way to do that with standard WHMCS. The first solution that comes to mind is boring but should work. Use EmailPreSend to detect invoice-related emails and abort sending (you can't handle attachments via API) Re-create the same email directly including phpMailer class Download the invoice from dl.php file (Admin authentication required) and store it in a PHP variable (eg. $output = curl_exec($ch);) Query db to retreive invoice status and anything you want Name the PDF as you wish like for example "I am Sexy 2020 this invoice is Unpaid You are client ID 120 with USD currency.pdf") bold words come from database echo $output in that file setting haders (application/pdf) Attach the newly generated file in th email and send it As I said it is boring. Cool ! Thanks for the insight, however I can't create the script but I'll give this clue to our dev on other custom modules. 0 Quote Link to comment Share on other sites More sharing options...
mariathomson2 Posted April 28 Share Posted April 28 To implement the renaming of the PDF based on the invoice status in WHMCS, you would need to customize the process by using a hook and some custom PHP code. Here's a summary of the steps you can follow based on the suggestions shared in the community: Use the EmailPreSend Hook: This hook can be used to detect email-related events before the email is sent. You can check the invoice status in this hook. Abort Sending the Default Email: You'll need to stop the default email from being sent (as attachments can't be handled via the API). Recreate the Email with phpMailer: After stopping the default email, create a new email using the phpMailer class, which allows you to control email content and attachments. Download the Invoice Using dl.php: Use dl.php (with admin authentication) to fetch the invoice PDF. This step requires using cURL to download the invoice content and store it in a PHP variable. Query the Database to Retrieve Invoice Status: You'll need to query the database to check the status of the invoice (whether it’s paid or unpaid) and extract other necessary details (such as client ID, currency, etc.). Rename the PDF Based on the Invoice Status: After downloading the invoice, rename it based on the status. For example, if the status is "Unpaid," rename the file to "Proforma Invoice-1900001" instead of "Invoice-1900001." Set Appropriate Headers: Set headers to indicate the content type as application/pdf and ensure the email contains the newly generated PDF with the custom filename. Send the Custom Email: Attach the renamed PDF to the email and send it to the client. Example Code Outline (Theoretical): php Copy Edit function customRenameInvoicePDF($vars) { $invoice_id = $vars['invoiceid']; $invoice_status = getInvoiceStatus($invoice_id); // Fetch the invoice status $client_id = getClientId($invoice_id); // Fetch the client ID $filename = "Invoice-" . $invoice_id; if ($invoice_status == "Unpaid") { $filename = "Proforma Invoice-" . $invoice_id; } // Download the invoice using cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "path/to/dl.php?invoiceid=$invoice_id"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); // Send the email with phpMailer and the renamed file sendCustomEmail($client_id, $filename, $output); } function sendCustomEmail($client_id, $filename, $pdf_content) { // Set up phpMailer and send the email $mail = new PHPMailer(true); $mail->setFrom('your-email@example.com'); $mail->addAddress(getClientEmail($client_id)); $mail->Subject = "Your Invoice: $filename"; $mail->Body = "Please find your invoice attached."; // Attach the renamed PDF $mail->addStringAttachment($pdf_content, $filename . ".pdf", 'base64', 'application/pdf'); // Send the email $mail->send(); } add_hook('EmailPreSend', 1, 'customRenameInvoicePDF'); Notes: This solution is theoretical and may require customization based on your WHMCS setup. You'll need to have a developer implement this solution or modify the code as per your system requirements. Make sure you have permission to use cURL and phpMailer in your WHMCS environment. This approach should allow you to differentiate between unpaid and paid invoices by renaming the PDFs appropriately when sending them to clients. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.