saadsalman Posted October 4, 2010 Share Posted October 4, 2010 Hello All, I would like to add the product group to the invoice item description in my invoices. So far our invoices look like this: PRODUCTNAME - Domain (Start Date - End Date) e.g. Standard - abc.com (04/10/2010 - 03/10/2012) I want to change it to the following: PRODUCTGROUP - PRODUCTNAME - Domain (Start Date - End Date) e.g. Shared Hosting - Standard - abc.com (04/10/2010 - 03/10/2012) I can fix it by renaming the products to include the product group as well but that's not what I would want as a permanent solution. Please let me know if there is some way of adding the product group to the invoice item description. Thanks in advance. 0 Quote Link to comment Share on other sites More sharing options...
saadsalman Posted October 19, 2010 Author Share Posted October 19, 2010 No one has the answer? 0 Quote Link to comment Share on other sites More sharing options...
m00 Posted October 19, 2010 Share Posted October 19, 2010 It's not possible to link an item on your invoice back to a product group. The description on the invoice is just plain text, not linked to a product, product group, etc. 0 Quote Link to comment Share on other sites More sharing options...
saadsalman Posted October 19, 2010 Author Share Posted October 19, 2010 It's not possible to link an item on your invoice back to a product group. The description on the invoice is just plain text, not linked to a product, product group, etc. Thanks for the reply. Then any way I could change the format of that description text? 0 Quote Link to comment Share on other sites More sharing options...
m00 Posted October 19, 2010 Share Posted October 19, 2010 Thanks for the reply. Then any way I could change the format of that description text? Let's call this a creative solution. Place the following script at the top of your /templates/<templatename>/viewinvoice.tpl: {php} foreach ($this->_tpl_vars['invoiceitems'] as $key => $value) { $result = mysql_query("SELECT (SELECT name FROM tblproductgroups WHERE gid = tblproducts.id) AS groupname FROM tblproducts WHERE name = '".sanitize(substr($value['description'], 0, strpos($value['description']." - ", " - ")))."'"); $data = mysql_fetch_array($result); if(mysql_num_rows($result) == 1) $this->_tpl_vars['invoiceitems'][$key]['description'] = $data['groupname']." - ".$value['description']; } {/php} Place the following script at the top of your /templates/<templatename>/invoicepdf.tpl: foreach ($invoiceitems as $key => $value) { $result = mysql_query("SELECT (SELECT name FROM tblproductgroups WHERE gid = tblproducts.id) AS groupname FROM tblproducts WHERE name = '".sanitize(substr($value['description'], 0, strpos($value['description']." - ", " - ")))."'"); $data = mysql_fetch_array($result); if(mysql_num_rows($result) == 1) $invoiceitems[$key]['description'] = $data['groupname']." - ".$value['description']; } 0 Quote Link to comment Share on other sites More sharing options...
m00 Posted October 19, 2010 Share Posted October 19, 2010 (edited) An easier and cleaner solution is probably an action hook. Create a new .php file called invoices_productgroup.php in your action hooks directory (/includes/hooks/), and place the following code in it: <?php add_hook("InvoiceCreationPreEmail", 1, "invoice_productgroup"); function invoice_productgroup($vars) { $result = select_query("tblinvoiceitems","id,description",array("invoiceid" => $vars['invoiceid'])); while($data = mysql_fetch_array ($result)) { $result2 = full_query("SELECT (SELECT name FROM tblproductgroups WHERE gid = tblproducts.id) AS groupname FROM tblproducts WHERE name = '".sanitize(substr($data['description'], 0, strpos($data['description']." - ", " - ")))."'"); $data2 = mysql_fetch_array($result2); if(mysql_num_rows($result2) == 1) update_query("tblinvoiceitems", array("description" => $data2['groupname']." - ".$data['description']), array("id" => $data['id'])); } } ?> This will add the product group (if applicable) in front of the description from a new invoice. Edited October 19, 2010 by m00 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted October 19, 2010 Share Posted October 19, 2010 you can go from the relid on the invoice item to the hosting product, and from there to the package, and from their to the product group 0 Quote Link to comment Share on other sites More sharing options...
m00 Posted October 20, 2010 Share Posted October 20, 2010 you can go from the relid on the invoice item to the hosting product, and from there to the package, and from their to the product group You're right! I totally forgot that. Sorry. Fixed hook: <?php add_hook("InvoiceCreationPreEmail", 1, "invoice_productgroup"); function invoice_productgroup($vars) { $result = select_query("tblinvoiceitems","id,description",array("invoiceid" => $vars['invoiceid'])); while($data = mysql_fetch_array ($result)) { $result2 = full_query("SELECT (SELECT (SELECT (SELECT tblproductgroups.name FROM tblproductgroups WHERE id = tblproducts.gid) FROM tblproducts WHERE id = tblhosting.packageid) FROM tblhosting WHERE id = tblinvoiceitems.relid) AS groupname FROM tblinvoiceitems WHERE id='".$data['id']."';"); $data2 = mysql_fetch_array($result2); if(mysql_num_rows($result2) == 1) update_query("tblinvoiceitems", array("description" => $data2['groupname']." - ".$data['description']), array("id" => $data['id'])); } } ?> 0 Quote Link to comment Share on other sites More sharing options...
saadsalman Posted October 20, 2010 Author Share Posted October 20, 2010 Thanks m00 for spending some of your precious time on my issue, much appreciated. Unfortunately I am unable to get it to wok as when I place the file in hooks folder a blank page appears. I added $display_errors=true; to the configuration.php file and the error is: Warning: Cannot modify header information - headers already sent by (output started at /home/pakserv/public_html/includes/hooks/invoices_productgroup.php:18 ) in /home/usr/public_html/includes/adminfunctions.php on line 0 Any clue why is this happening? 0 Quote Link to comment Share on other sites More sharing options...
m00 Posted October 20, 2010 Share Posted October 20, 2010 Thanks m00 for spending some of your precious time on my issue, much appreciated. Unfortunately I am unable to get it to wok as when I place the file in hooks folder a blank page appears. I added $display_errors=true; to the configuration.php file and the error is: Warning: Cannot modify header information - headers already sent by (output started at /home/pakserv/public_html/includes/hooks/invoices_productgroup.php:18 ) in /home/usr/public_html/includes/adminfunctions.php on line 0 Any clue why is this happening? Remove all spaces outside the <?php and ?> tags. Also, a little fix on the hook: <?php add_hook("InvoiceCreationPreEmail", 1, "invoice_productgroup"); function invoice_productgroup($vars) { $result = full_query("SELECT id, description, (SELECT (SELECT (SELECT tblproductgroups.name FROM tblproductgroups WHERE id = tblproducts.gid) FROM tblproducts WHERE id = tblhosting.packageid) FROM tblhosting WHERE id = tblinvoiceitems.relid) AS groupname FROM tblinvoiceitems WHERE invoiceid='".$vars['invoiceid']."' AND type='Hosting';"); while($data = mysql_fetch_array ($result)) if($data['groupname'] !== NULL) update_query("tblinvoiceitems", array("description" => $data['groupname']." - ".$data['description']), array("id" => $data['id'])); } ?> 1 Quote Link to comment Share on other sites More sharing options...
saadsalman Posted October 20, 2010 Author Share Posted October 20, 2010 That's perfect m00. Thanks a lot for your help! 0 Quote Link to comment Share on other sites More sharing options...
wwwcad Posted August 30, 2021 Share Posted August 30, 2021 <?php add_hook("InvoiceCreationPreEmail", 1, "invoice_productgroup"); function invoice_productgroup($vars) { try { $result = full_query("SELECT id, description, (SELECT (SELECT (SELECT tblproductgroups.name FROM tblproductgroups WHERE id = tblproducts.gid) FROM tblproducts WHERE id = tblhosting.packageid) FROM tblhosting WHERE id = tblinvoiceitems.relid) AS groupname FROM tblinvoiceitems WHERE invoiceid='".$vars['invoiceid']."' AND type='Hosting';"); while($data = $result->fetch()) { if($data['groupname'] !== NULL) { update_query("tblinvoiceitems", array("description" => $data['groupname']." - ".$data['description']), array("id" => $data['id'])); } } } catch(Exception $e) { logActivity('Error in Hook invoice_productgroup: '.$e->getMessage(), 0); } } ?> This is an updated version compatible with the latest WHMCS and PHP 7. 1 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.