Jump to content

Client Area: Show clients credit management logs (or show them credit log)


wulfric

Recommended Posts

latest WHMCS using stock six template

 

Is something like this already baked-into WHMCS? Where can client see activity log for credits?

 

WHMCS Admin Dashboard > Client Profile > Invoices/Billing > Manage Credits

 

How can I display the table data that I see as an admin, to my client? So perhaps, when the client receives a credit, they can see why, when and how much.

Link to comment
Share on other sites

latest WHMCS using stock six template

Is something like this already baked-into WHMCS? Where can client see activity log for credits?

they currently can't - the credit log is primarily for admin eyes only...

 

WHMCS Admin Dashboard > Client Profile > Invoices/Billing > Manage Credits

How can I display the table data that I see as an admin, to my client? So perhaps, when the client receives a credit, they can see why, when and how much.

you'd need to get that information from the database, so the easiest way would be an action hook - something along the lines of...

 

<?php

# Credit Logs For Client Area
# Written by brian!

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_client_credit_logs($vars)

{
   $client = Menu::context('client'); 
   $creditlogs = Capsule::table('tblcredit')
               ->where('clientid', $client->id)
               ->get();

   $encodedata = json_encode($creditlogs);
   $decodedata = json_decode($encodedata, true);

   return array("creditlogs" => $decodedata);
}
add_hook("ClientAreaPage", 1, "hook_client_credit_logs");
?>

that will give you a $creditlogs array when the client is logged in - then it's just a case of outputting that array via a foreach loop in a table, panel or however you want to in the template or hook.

 

where/how you want to output will determine the method - e.g if it's a panel, then you can do it all in a hook (though not via CAP, but a panel hook); if it's only to be used on one specific page, then you can use a specific hook for that page, or modify CAP for use on only that template page...

 

for example, if you threw it into a table, it would look something like...

 

Nrt1EMY.png

 

what would be missing from the above basic hook is any form of date/currency formatting - so you either have to add that to the hook code or the Smarty template.

Link to comment
Share on other sites

Thanks for the generous response, very helpful!

 

When you say action hook, does that mean hook inside the /includes/hooks?

 

I'll wait for your reply while I reading the docs right here: https://developers.whmcs.com/hooks/

 

---

 

1.) I created new file called credit-log.php and copy / pasted your above snippet then uploaded to /includes/hooks

2.) I open and edit clientareahome.tpl and paste {$creditlogs}

3.) I refresh page in private browser tab and do not see any results?

 

Also, I went into Setup > General > Other > Display PHP Errors but do not see anything. I check Hooks Debug Mode to see if something else might pop up but I get nothing.

Link to comment
Share on other sites

Thanks for the generous response, very helpful!

When you say action hook, does that mean hook inside the /includes/hooks?

I'll wait for your reply while I reading the docs right here: https://developers.whmcs.com/hooks/

1.) I created new file called credit-log.php and copy / pasted your above snippet then uploaded to /includes/hooks

2.) I open and edit clientareahome.tpl and paste {$creditlogs}

3.) I refresh page in private browser tab and do not see any results?

Also, I went into Setup > General > Other > Display PHP Errors but do not see anything. I check Hooks Debug Mode to see if something else might pop up but I get nothing.

when I add {$creditlogs} to the template, I see this...

 

covY1nR.png

the fact I see "Array" tells me there is a Smarty array available containing data - if you're seeing nothing, then i'd assume the clientlog is empty for the client that you've chosen. :?:

 

How did you throw the output code in a table?

in the same way WHMCS adds the output code to a table on any other page. :)

 

if it helps, I quickly used this on the homepage - ideally you should really use language strings for the table headings, but it was only a throwaway demo!

 

{include file="$template/includes/tablelist.tpl" tableName="CreditsLog"} 
<div class="table-container clearfix"> 
   <table id="tableCreditsLog" class="table table-list"> 
       <thead> 
           <tr> 
               <th>Date</th> 
               <th>Description</th> 
               <th>Amount</th> 
               <th>Status</th> 
           </tr> 
       </thead> 
       <tbody> 
           {foreach from=$creditlogs item=creditlog} 
               <tr> 
                   <td align="center">{$creditlog.date}</td> 
                   <td align="center">{$creditlog.description}</td> 
                   <td align="center">{$creditlog.amount}</td> 
                   <td align="center">{if $creditlog.amount gt 0}Credit{else}Debit{/if}</td> 
               </tr> 
           {/foreach} 
       </tbody> 
   </table> 

</div>

Also I search the hook index, and do not see anything for credit, I think this is incomplete docs... o well, I can dig around on the forums the more!

that doesn't really matter - you can use ClientAreaPage to pass the array to any page in the client area, or if you only want to use it on the Invoices page, you could use ClientAreaPageInvoices - basically, you're just querying the database and passing the info back to the template... the above custom hook will do that - IF the information exists! :idea:

Link to comment
Share on other sites

Friggin' awesome... Everything you just shared helped me get the results I was looking for! I never knew how to use the {include file="$template/includes/tablelist.tpl" tableName="CreditsLog"} stuff and WILL DEFINITELY be using it more in the future.

 

:evil:

 

You were right, I launched up the debug and could see the credit log data being displayed.

 

---

 

Might you be able to recommend a way to customize tabletlist.tpl output?

 

For example, default select "view all" and remove the filter and info?

 

#tableCreditsLog_filter, #tableCreditsLog_info { display: none;}

 

sU76vO4.png

 

I was going to add a javascript snippet to select all

 

T6fOIx8.png

 

Thanks, big help!

Edited by wulfric
forgot picture
Link to comment
Share on other sites

Might you be able to recommend a way to customize tabletlist.tpl output?

For example, default select "view all" and remove the filter and info?

you could use the following in the include statement to remove pagination (the show x entries dropdown) and the search box...

 

{include file="$template/includes/tablelist.tpl" tableName="CreditsLog" noPagination=true noSearch=true}

 

QS940sk.png

if you don't want the info box either, you just add noInfo to that line...

 

{include file="$template/includes/tablelist.tpl" tableName="CreditsLog" noPagination=true noSearch=true noInfo=true}

 

r26m5H1.png

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.

×
×
  • 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