Jump to content

Add client name to Affiliates Page


pat_ads

Recommended Posts

Hi all!

 

Our business has resellers (affiliates) who sell our software. I've been asked if the affiliates page, under "Your Referrals" could specify the client name and/or business name. This would greatly improve their efforts to follow up with clients who order our free trial.

 

I've searched for this but the only tip I found was a WHMCS comment that they do not support this for "privacy reasons" which do not apply in my case.

 

Thanks in advance.

Link to comment
Share on other sites

Go to the templates directory, then the template you are using, and edit the affiliates.tpl file. In the table that you want to show the client name, add this code...

 

in the thead, add

<th>Client</th>

 

 

in the tbody, add

<td>

{php}

$userid = $this->_tpl_vars['referral']['userid'];

$result = mysql_query("SELECT companyname, CONCAT_WS(' ', `firstname`, `lastname`) As ClientName FROM tblclients WHERE id=$userid");

$data = mysql_fetch_array($result);

$company = $data["companyname"];

if($company != '') {

echo $company;

} else {

echo $data["ClientName"];

}

{/php}

</td>

Link to comment
Share on other sites

Silverline, thanks for the tip! It looks great...is there any way to get the heading to sort? Here is what I have so far:

 

<table class="table table-striped table-framed">
   <thead>
       <tr>
           <th>Client</th>
    <th{if $orderby eq "date"} class="headerSort{$sort}"{/if}><a href="affiliates.php?orderby=date">{$LANG.affiliatessignupdate}</a></th>
           <th{if $orderby eq "product"} class="headerSort{$sort}"{/if}><a href="affiliates.php?orderby=product">{$LANG.orderproduct}</a></th>
           <th{if $orderby eq "amount"} class="headerSort{$sort}"{/if}><a href="affiliates.php?orderby=amount">{$LANG.affiliatesamount}</a></th>
           <th>{$LANG.affiliatescommission}</th>
           <th{if $orderby eq "status"} class="headerSort{$sort}"{/if}><a href="affiliates.php?orderby=status">{$LANG.affiliatesstatus}</a></th>
       </tr>
   </thead>
   <tbody>
	{foreach key=num item=referral from=$referrals}
		<tr>
			<td>
				{php}
					$userid = $this->_tpl_vars['referral']['userid'];
					$result = mysql_query("SELECT companyname, CONCAT_WS(' ', `firstname`, `lastname`) As ClientName  FROM tblclients WHERE id=$userid");
					$data = mysql_fetch_array($result);
					$company = $data["companyname"];
					if($company != '') {
					echo $company;
					} else {
					echo $data["ClientName"];
					} 
				{/php} 
			</td>
			<td>{$referral.date}</td>
			<td>{$referral.service}</td>
			<td>{$referral.amountdesc}</td>
			<td>{$referral.commission}</td>
			<td>{$referral.status}</td>
		</tr>
	{foreachelse}
		<tr>
			<td colspan="5">{$LANG.norecordsfound}</td>
		</tr>
	{/foreach}
   </tbody>
</table>

 

Wasn't sure if the 'colspan=5' needed changing so I left it alone. If I can get the Client heading to sort that would be great.

 

Thanks again

Link to comment
Share on other sites

you could probably change the colspan to 6 as there are now six columns in your setup - but unless there was a table border, it might not make much difference if you don't.

 

I should also say in passing that one of the WHMCS support guys mentioned that they intend to switch to using Smarty v3 in the next major release beta - one feature of which being that {php} is not allowed in templates - so at that point, this solution will no longer work.

 

http://forum.whmcs.com/showthread.php?90110-Using-array-key-as-loop-counter-bad-idea&p=379819#post379819

 

I don't work for WHMCS, but I would guess you'll be ok with this for the rest of this year - but sometime in 2015, you'll have to revisit this code.

Link to comment
Share on other sites

I looked into smarty v3 and you can use a plugin to remove the need for the {php} tag. This also works with the current version. I'm not a professional php developer, so I don't know if I'm doing this the best way, but here is a working solution.

 

in includes/classes/smarty/plugins, create a file named function.get_client_name.php with this code...

 

<?php

/*

* Smarty plugin

* -------------------------------------------------------------

* File: function.get_client_name.php

* Type: function

* Name: get_client_name

* Purpose: gets the client name

* -------------------------------------------------------------

*/

function smarty_function_get_client_name($params, $smarty)

{

$userid = $params['userid'];

$result = mysql_query("SELECT companyname, CONCAT_WS(' ', `firstname`, `lastname`) As ClientName FROM tblclients WHERE id=$userid");

$data = mysql_fetch_array($result);

$company = $data["companyname"];

if($company != '') {

$output = $company;

} else {

$output = $data["ClientName"];

}

return $output;

}

?>

 

 

then in your template files, replace the {php} block of code with this

 

{get_client_name userid=$referral.userid}

 

 

I don't know if the plugin file will be lost during whmcs upgrades, so you probably want to make a copy of it somewhere so you can restore it if it is lost.

Link to comment
Share on other sites

  • 1 year later...
I looked into smarty v3 and you can use a plugin to remove the need for the {php} tag. This also works with the current version. I'm not a professional php developer, so I don't know if I'm doing this the best way, but here is a working solution.

 

in includes/classes/smarty/plugins, create a file named function.get_client_name.php with this code...

 

<?php

/*

* Smarty plugin

* -------------------------------------------------------------

* File: function.get_client_name.php

* Type: function

* Name: get_client_name

* Purpose: gets the client name

* -------------------------------------------------------------

*/

function smarty_function_get_client_name($params, $smarty)

{

$userid = $params['userid'];

$result = mysql_query("SELECT companyname, CONCAT_WS(' ', `firstname`, `lastname`) As ClientName FROM tblclients WHERE id=$userid");

$data = mysql_fetch_array($result);

$company = $data["companyname"];

if($company != '') {

$output = $company;

} else {

$output = $data["ClientName"];

}

return $output;

}

?>

 

 

then in your template files, replace the {php} block of code with this

 

{get_client_name userid=$referral.userid}

 

 

I don't know if the plugin file will be lost during whmcs upgrades, so you probably want to make a copy of it somewhere so you can restore it if it is lost.

 

I used WHMCS 6.1.1 and i tried your way, i even try the previous way, but still no success in showing company-client name in the affiliate table.

Anyone can help whis this ? :)

Anyone

Link to comment
Share on other sites

I just tried the Smarty plugin method on v6.2 and it works fine... I suppose technically it would be preferable as an action hook, and would be simple enough to write, but the smarty solution definitely works.

 

one thing you may want to check though is where you uploaded the plugin - the paths were changed in v6, and so it should no longer be added to includes/classes/smarty/plugins - it should be uploaded to /vendor/smarty/smarty/libs/plugins

Link to comment
Share on other sites

I just tried the Smarty plugin method on v6.2 and it works fine... I suppose technically it would be preferable as an action hook, and would be simple enough to write, but the smarty solution definitely works.

 

one thing you may want to check though is where you uploaded the plugin - the paths were changed in v6, and so it should no longer be added to includes/classes/smarty/plugins - it should be uploaded to /vendor/smarty/smarty/libs/plugins

 

You are right, my path was wrong... it works like a charm :)

 

Btw is it possible to show more columns like: Invoice Status, Invoice date or something from Invoices (table) for clients...

 

And i got another question: http://prntscr.com/9ibvd8

i have a few services per client but some of them are 0.00$, is it possible to hide those with 0$ ?

Link to comment
Share on other sites

You are right, my path was wrong... it works like a charm :)

i'm glad you got it sorted. :idea:

 

Btw is it possible to show more columns like: Invoice Status, Invoice date or something from Invoices (table) for clients...

if you can query the database table for the values, then yes... though you only have limited reference info available to use, so you'd have to be specific with your query to ensure you are getting the correct value.

 

And i got another question: http://prntscr.com/9ibvd8

i have a few services per client but some of them are 0.00$, is it possible to hide those with 0$ ?

you could modify the template and use a Smarty while loop to hide them...

 

so change..

 

            {foreach from=$referrals item=referral}
               <tr class="text-center">
                   <td>{get_client_name userid=$referral.userid}</td>
                   <td>{$referral.date}</td>
                   <td>{$referral.service}</td>
                   <td>{$referral.amountdesc}</td>
                   <td>{$referral.commission}</td>
                   <td><span class='label status status-{$referral.status|strtolower}'>{$referral.status}</span></td>
               </tr>
           {/foreach}

to...

 

            {foreach from=$referrals item=referral}
               {while $referral.amount neq '0.00'}
               <tr class="text-center">
                   <td>{get_client_name userid=$referral.userid}</td>
                   <td>{$referral.date}</td>
                   <td>{$referral.service}</td>
                   <td>{$referral.amountdesc}</td>
                   <td>{$referral.commission}</td>
                   <td><span class='label status status-{$referral.status|strtolower}'>{$referral.status}</span></td>
               </tr>
               {/while}
           {/foreach}

Edited by brian!
Link to comment
Share on other sites

            {foreach from=$referrals item=referral}
               {while $referral.amount neq '0.00'}
               <tr class="text-center">
                   <td>{get_client_name userid=$referral.userid}</td>
                   <td>{$referral.date}</td>
                   <td>{$referral.service}</td>
                   <td>{$referral.amountdesc}</td>
                   <td>{$referral.commission}</td>
                   <td><span class='label status status-{$referral.status|strtolower}'>{$referral.status}</span></td>
               </tr>
               {/while}
           {/foreach}

 

Hey Brian, i try your code but it doesnt work... my browser keep on loading after i put it and nothing show up when i go to

https://....../affiliates.php

 

Also about invoice (im not really a php dev) but i try use the script for company name, switching some code to get invoice amount or paymentmethod from tblinvoices but no luck, i mean i get some values but they arent the right ones. So i guess i have some small problem with the code, or maybe the whole code is wrong :)

 

I tried this:

<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.get_client_invoice.php
* Type: function
* Name: get_client_invoice
* Purpose: gets the client invoice 
* -------------------------------------------------------------
*/
function smarty_function_get_client_invoice($params, $smarty)
{
$userid = $params['userid'];
$result = mysql_query("SELECT total, CONCAT_WS(' ', `total`) As InvoiceTotal FROM tblinvoices WHERE id=$userid");
$data = mysql_fetch_array($result);
$total = $data["total"];
if($amount != '') {
$output = $total;
} else {
$output = $data["InvoiceTotal"];
} 
return $output;
}
?>

 

But the result is not right :(

http://prntscr.com/9isrnb

Link to comment
Share on other sites

Hey Brian, i try your code but it doesnt work... my browser keep on loading after i put it and nothing show up when i go to

https://....../affiliates.php

I tried it on my own v6 dev first before posting - so it definitely works! :idea:

 

anything in the activity log to give a clue why it isn't working for you? perhaps for you it needs to be '0,00' ? or just try '0'

 

Also about invoice (im not really a php dev) but i try use the script for company name, switching some code to get invoice amount or paymentmethod from tblinvoices but no luck, i mean i get some values but they arent the right ones. So i guess i have some small problem with the code, or maybe the whole code is wrong :)

But the result is not right :(

http://prntscr.com/9isrnb

it will be that sql query - it night need to be more specific, but i'm not convinced it can be 100% accurate... i'll take another look tomorrow.

Link to comment
Share on other sites

I tried it on my own v6 dev first before posting - so it definitely works! :idea:

 

anything in the activity log to give a clue why it isn't working for you? perhaps for you it needs to be '0,00' ? or just try '0'

 

 

it will be that sql query - it night need to be more specific, but i'm not convinced it can be 100% accurate... i'll take another look tomorrow.

 

 

Okey :) i google a bit (2hours) and somehow after 1372893479279 try`s :) i decided to switch {while} with {if}...

 

So with {if....} {/if} its working like a charm..... btw i have v6.1.1 with "Allow Smarty PHP Tags > Enable" in system settings.

 

Anyway if you could help me a bit tomorrow with TBLInvoices SQL query :) I will be very thankful.

Link to comment
Share on other sites

Okey :) i google a bit (2hours) and somehow after 1372893479279 try`s :) i decided to switch {while} with {if}...

 

So with {if....} {/if} its working like a charm..... btw i have v6.1.1 with "Allow Smarty PHP Tags > Enable" in system settings.

{if} would work... :idea:

 

{if $referral.commission neq '£0.00'}

obviously, change the '£' and '.' to match your currency output.

 

Anyway if you could help me a bit tomorrow with TBLInvoices SQL query :) I will be very thankful.

i'll take a quick look, but don't raise your hopes that it can be done (easily). :(

 

one problem is when a user signs up, the database only stores the date - but when they make an order, it stores date and time... so it's difficult to link a signup to an invoice (if they signed up for multiple packages during the same day)... I suppose potentially you can do some cross-referencing of tables to make a very good guess at the link, but i'm not convinced it would be 100% accurate.

 

i'll take a quick look tomorrow, but i've got a lot to do, so I won't have time to spend long on it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated