angelettif Posted April 13, 2020 Share Posted April 13, 2020 This hook runs after all the automations and set the invoices to "Cancelled" it the services have been terminated or cancelled. This feature has been long requested to WHMCS but it was never implemented. All you need to do to install and activate the hook is to upload the file into the /includes/hooks of you WHMCS installation. It will day after the cron runs it will set all the invoices to "Cancelled" if the related product is Terminated or Cancelled. It will also create an entry in the client log to have a record or the cancelled invoice. The same log will appear also in the System Activity Log. <?php if (!defined("WHMCS"))die("This file cannot be accessed directly"); use Illuminate\Database\Capsule\Manager as Capsule; function hooks_cancel_invoices($vars) { $query = "SELECT a.id,a.userid FROM tblinvoices a, tblinvoiceitems b WHERE b.invoiceid=a.id and b.type='Hosting' and a.status='Unpaid' AND b.relid IN (SELECT id from tblhosting where domainstatus='Terminated' OR domainstatus='Cancelled')"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $query2 = "UPDATE `tblinvoices` SET `status` = 'Cancelled' WHERE `id` = '".$row['id']."'"; logactivity("Hooks Cancelled Invoice - Invoice ID: ".$row['id'], $row['userid']); $result2 = mysql_query($query2); if($result2==FALSE)logactivity('Hooks Cancelled Invoice FAIL: '.mysql_error()); } } add_hook('DailyCronJob', 100,'hooks_cancel_invoices'); /includes/hooks 0 Quote Link to comment Share on other sites More sharing options...
angelettif Posted April 13, 2020 Author Share Posted April 13, 2020 The next change can be using SQL helper functions: https://docs.whmcs.com/SQL_Helper_Functions 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.