Saturday, April 9, 2022

Print Product Group in WHMCS Invoice Item Description

PRODUCTNAME - Domain (Start Date - End Date)

e.g. Standard - abc.com (04/10/2010 - 03/10/2012)

Need to change it to the following:

PRODUCTNAME - Domain (Start Date - End Date)

PRODUCT DESCRIPTION

e.g. Shared Hosting - Standard - abc.com (04/10/2010 - 03/10/2012)

Method -1: 

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}

Now 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'];
}

Method -2: 
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.

No comments:

Post a Comment

Office 2021 Activation using command

  @echo off title Activate Microsoft Office 2021 (ALL versions) for FREE - office.com&cls&echo =====================================...