Jump to content

[Ask] How to Show Next Invoice Date on Product/Services Tab with Hooks ?


Mas-J

Recommended Posts

Dear All,

I want to show the Next Invoice Date under Next Due Date when admin access Page Client Details on Product/Services Tab.

But, I've no idea how to show it, I just know to get the Next Invoice Date value related from tblhosting

Anyone can help me to show it ? Thank you.

<?php

use WHMCS\Database\Capsule;

add_hook('AdminClientServicesTabFields', 1, function($vars) {

	$PID = $vars['id'];
	$nextinvoicedate = Capsule::table('tblhosting')->where('id', $PID)->pluck('nextinvoicedate');
	
	$result = array();
	$result['nextinvoicedate'] = $nextinvoicedate;
	return $result
	
});


 

NextInvoiceDate.png

Link to comment
Share on other sites

3 hours ago, Mas-J said:

But, I've no idea how to show it, I just know to get the Next Invoice Date value related from tblhosting

it would be value rather than pluck in recent versions.

3 hours ago, Mas-J said:

Anyone can help me to show it ?

well it would be an AdminAreaHeaderOutput hook that uses JS to insert the relevant content.

WXoKEJZ.png

personally, i'd forget about outputting it in a new table cell - that could be an absolute pain to code in a hardcoded table... just return the value after the NDD.

I would suspect you're probably looking at 20-30 lines of code here... e.g getting the ID value from the URL (or querying it if that value doesn't exist, e.g first product), handling addons, handling one-time products (which won't have NDD or NID values), handling terminated products (which will have NID but it will be irrelevant) etc.

it's all doable - the output side of things is simple enough and roughly demonstrated in the hook below posted by Kian (you won't need everything he's doing in that hook)...

just work through it logically.... the real pain is that i'll think you'll have to use $_ GET and so pasting the code here wouldn't work.

Link to comment
Share on other sites

10 hours ago, brian! said:

it would be value rather than pluck in recent versions.

Oh thank you for the correction @brian!

 

10 hours ago, brian! said:

well it would be an AdminAreaHeaderOutput hook that uses JS to insert the relevant content.

How to determine the related service that page that admin open ?
I think if using AdminClientServicesTabFields Hooks it can detect value of service ID. Can I use two Hooks in one file ?
AdminClientServicesTabFields for related service ID
AdminAreaHeaderOutput for the output in the page

 

10 hours ago, brian! said:

just work through it logically.... the real pain is that i'll think you'll have to use $_ GET and so pasting the code here wouldn't work.

I got the logic, how can I know the parameter that can be used as variable like vars=['filename'] or $_Get ?
Can you give me the reference link or document from WHMCS maybe ? I didn't know the keyword to find it.

Link to comment
Share on other sites

8 hours ago, Mas-J said:

How to determine the related service that page that admin open ?

the way I did it above was to take the "productselect" value from the URL - if it exists, then that's the PID number... once you have that, then the world is your oyster and off to go to query the db via any number of methods... if it doesn't exist, then it's the first product - at which point, you just do a simple query that returns the first product of that client.

8 hours ago, Mas-J said:

I think if using AdminClientServicesTabFields Hooks it can detect value of service ID. Can I use two Hooks in one file ?
AdminClientServicesTabFields for related service ID
AdminAreaHeaderOutput for the output in the page

you can use multiple hooks in the same file - you can even use hooks within hooks if you have to (i've posted examples - but whether that is actually necessary in this case, I doubt).

8 hours ago, Mas-J said:

I got the logic, how can I know the parameter that can be used as variable like vars=['filename'] or $_Get ?

below is a screenshot of the quick test hook I wrote for the above screenshot - it will only get you so far and needs to be thoroughly worked through as I outlined previously.

iY4ykuO.png

8 hours ago, Mas-J said:

Can you give me the reference link or document from WHMCS maybe ? I didn't know the keyword to find it.

i'm not sure there is a relevant reference that I can give you - it's more a case of knowing what needs to be done and then working out the best way to do it.... so if it's using capsule (as per your example), the WHMCS doc would be here - though frankly you'd be better off reading the laravel documentation.

the first change you'd likely have to make is to the second if statement - you're going to have to check if the $PID value is a number - if so, then it's a service... if it starts with 'a', then it's a product addon and you'd then have to query the tblhostingaddons table instead of tblhosting for the NID.

actually, what you're probably going to have to do is instead of using value to just get the NID date, you might have to get the entire table row and then use the values in the array to work out it's status (terminated etc), it's billing cycle (one time or recurring) as they would al have an impact on whether NID exists or is of any practical use.

Link to comment
Share on other sites

Actually before your post I've write some code from Kian reference that you gave me but I can't submit it to community to ask you, the page say 403 forbidden I think it because the JS script.

18 hours ago, brian! said:

below is a screenshot of the quick test hook I wrote for the above screenshot - it will only get you so far and needs to be thoroughly worked through as I outlined previously.

I've write your code (and double check) but the NID didn't appear, have you test it in your whmcs ? 


My code still not perfect like Kian said, when refresh page or change the services it will show 1970-01-01
After see your code and give a little modification I can show the NID value, thanks
script_nid.thumb.png.df56fe83f1cafcfa57fb9f48dbd9b82c.png

 

17 hours ago, brian! said:

i'm not sure there is a relevant reference that I can give you - it's more a case of knowing what needs to be done and then working out the best way to do it.... so if it's using capsule (as per your example), the WHMCS doc would be here - though frankly you'd be better off reading the laravel documentation.

Thank you ! How about to know what value we can use for variable ? example variable $vars['filename'] with value 'clientsservices'
Where I can know the list value like 'clientsservices' ?
I want to know others value from some variables in WHMCS 🙂

Link to comment
Share on other sites

5 hours ago, Mas-J said:

I've write your code (and double check) but the NID didn't appear, have you test it in your whmcs ? 

I always do before posting (that screenshot wasn't Photoshopped!) - the hook returns the correct value for me on every client/service I tried... though as I said those values would be meaningless for terminated/one-time products etc.

5 hours ago, Mas-J said:

My code still not perfect like Kian said, when refresh page or change the services it will show 1970-01-01

not for me.

5 hours ago, Mas-J said:

After see your code and give a little modification I can show the NID value, thanks

da-dahhhh! magicien.gif

5 hours ago, Mas-J said:

Thank you ! How about to know what value we can use for variable ? example variable $vars['filename'] with value 'clientsservices'

some, but not all, of the variables available to a hook point are shown on the dev pages....

https://developers.whmcs.com/hooks-reference/output/#adminareaheaderoutput

Runs on every admin area page load. All template variables defined at the time the hook is invoked are made availble to this hook point. This can vary by page. The list below is not an exhaustive list.
Parameters
Variable 	Type 	Notes
charset 	string 	System charset setting eg. UTF-8
template 	string 	The admin template being used
pagetemplate 	string 	The template for the current page (if applicable)
adminid 	int 	The currently logged in admin user ID
admin_username 	string 	The username of the current admin user
admin_notes 	string 	The private notes for the current admin user
admin_perms 	array 	The permissions of the current admin user
addon_modules 	array 	A list of add-on modules the current admin user has access to
filename 	string 	The name of the file being called
pagetitle 	string 	The title of the current page
helplink 	string 	The documentation url for the current page
sidebar 	string 	The sidebar output
minsidebar 	bool 	Returns true if the sidebar is minimised
jquerycode 	string 	jQuery code for the current page
jscode 	string 	Javascript code for the current page
datepickerformat 	string 	The format defined for dates in the admin area
adminsonline 	string 	A list of currently online admin users
Response

Accepts HTML to be output within the body tag of the admin area output
5 hours ago, Mas-J said:

Where I can know the list value like 'clientsservices' ?

that's just the filename of the page in the admin area, e.g clientsservices.php

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