Jump to content

Block access to client area if client has overdue invoice(s)


wdele

Recommended Posts

"The page are not correctly routed."

 

That is an issue with your own install, not this hook, and you'll have to work with your developers to fully implement this.

From the looks of things, you're using some other sort of CMS that handles routing, and you need to address that there.

The hook is quite simplistic, really. If you can't get it to work, hand it off to your developers to see why it's not working

It works, I've tested it, others have as well, and verified. If it doesn't, you need to take the time and figure out why, because you're doing something different than WHMCS expects.

Link to comment
Share on other sites

Yet another fun update for this (sorry, don't mean to keep hijacking your thread, wdele, I'll probably create a thread specifically for this, after this:

Addition #1: specific grace period. So, your clients won't be immediately redirected. Change $graceperiod = "" to $graceperiod ="number" where number is the number of days to utilize it :), added by request

 

Addition #2: WHMCS System (and system ssl) URLs. was hoping to avoid this, as these actually throw two new queries into the mix, but since some don't handle redirects properly, this will help that (hopefully).

 

<?php

//redirect clients to invoice page if they are overdue. Nothing else.
//provided by https://www.whmcs.guru
use Illuminate\Database\Capsule\Manager as Capsule;

function check_client_access($vars)
{
// give the client a grace period? Numeric only, as in 10, for 10 days
$graceperiod = "";

//what time is it?
$time = time();
//are we logged in? If not, then return
$uid  = $_SESSION['uid'];
if (empty($uid))
{
	return;
}

//get the WHMCS system url for those systems that can't handle simple redirects
$systemurl = Capsule::table('tblconfiguration')->where('setting', '=', 'SystemURL')->pluck('value');
$systemsslurl = Capsule::table('tblconfiguration')->where('setting', '=', 'SystemSSLURL')->pluck('value');
if (is_array($systemurl))
{
	$systemurl = $systemurl['0'];
	$systemsslurl = $systemsslurl['0'];
}
if (!empty($systemsslurl))
{
	$systemurl = $systemsslurl;
}

$filename = $vars['filename'];
$displayTitle = $vars['displayTitle'];
//do we have any unpaid invoices?
$rows = Capsule::table('tblinvoices')->select('id') ->WHERE ('userid', '<=', $uid) ->where('status', '=', 'Unpaid') ->count();

if (empty($rows))
{

	//we have no unpaid invoices. Do not proceed any further
	return;
}

if (!empty($rows))
{
	//we have unpaid invoices. Are they overdue?

	foreach (Capsule::table('tblinvoices')->select('duedate') ->WHERE ('userid', '=', $uid) ->where('status', '=', 'Unpaid')->get() as $unpaidinvoice) {

		$invdue = $unpaidinvoice->duedate;
		$invdue = strtotime($invdue);
		if (!empty($graceperiod))
		{
			//get the corrected date
			$graceperiod = $graceperiod  * 24 * 60 * 60;
			$invdue = $invdue + $graceperiod;

						}
		if ($invdue < $time) {

			//let's make sure they're not viewing, or attempting to pay their invoice, ok?
			if ($filename !="viewinvoice" && $displayTitle != "My Invoices" && $filename !="creditcard")
			{
				//all those checks, we're finally where we need to be
				header('Location: clientarea.php?action=invoices');

			}

		}

	}

}





}
add_hook('ClientAreaPage', 1, "check_client_access");

Link to comment
Share on other sites

Yet another fun update for this (sorry, don't mean to keep hijacking your thread, wdele, I'll probably create a thread specifically for this, after this:

Addition #1: specific grace period. So, your clients won't be immediately redirected. Change $graceperiod = "" to $graceperiod ="number" where number is the number of days to utilize it :), added by request

 

Addition #2: WHMCS System (and system ssl) URLs. was hoping to avoid this, as these actually throw two new queries into the mix, but since some don't handle redirects properly, this will help that (hopefully).

 

<?php

//redirect clients to invoice page if they are overdue. Nothing else.
//provided by https://www.whmcs.guru
use Illuminate\Database\Capsule\Manager as Capsule;

function check_client_access($vars)
{
// give the client a grace period? Numeric only, as in 10, for 10 days
$graceperiod = "";

//what time is it?
$time = time();
//are we logged in? If not, then return
$uid  = $_SESSION['uid'];
if (empty($uid))
{
	return;
}

//get the WHMCS system url for those systems that can't handle simple redirects
$systemurl = Capsule::table('tblconfiguration')->where('setting', '=', 'SystemURL')->pluck('value');
$systemsslurl = Capsule::table('tblconfiguration')->where('setting', '=', 'SystemSSLURL')->pluck('value');
if (is_array($systemurl))
{
	$systemurl = $systemurl['0'];
	$systemsslurl = $systemsslurl['0'];
}
if (!empty($systemsslurl))
{
	$systemurl = $systemsslurl;
}

$filename = $vars['filename'];
$displayTitle = $vars['displayTitle'];
//do we have any unpaid invoices?
$rows = Capsule::table('tblinvoices')->select('id') ->WHERE ('userid', '<=', $uid) ->where('status', '=', 'Unpaid') ->count();

if (empty($rows))
{

	//we have no unpaid invoices. Do not proceed any further
	return;
}

if (!empty($rows))
{
	//we have unpaid invoices. Are they overdue?

	foreach (Capsule::table('tblinvoices')->select('duedate') ->WHERE ('userid', '=', $uid) ->where('status', '=', 'Unpaid')->get() as $unpaidinvoice) {

		$invdue = $unpaidinvoice->duedate;
		$invdue = strtotime($invdue);
		if (!empty($graceperiod))
		{
			//get the corrected date
			$graceperiod = $graceperiod  * 24 * 60 * 60;
			$invdue = $invdue + $graceperiod;

						}
		if ($invdue < $time) {

			//let's make sure they're not viewing, or attempting to pay their invoice, ok?
			if ($filename !="viewinvoice" && $displayTitle != "My Invoices" && $filename !="creditcard")
			{
				//all those checks, we're finally where we need to be
				header('Location: clientarea.php?action=invoices');

			}

		}

	}

}





}
add_hook('ClientAreaPage', 1, "check_client_access");

 

Unfortunately we were unable to salvage somehow.

We tried many different whmcs system.

I don't know what I can do about this

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