Jump to content

Hook to cancell orders terminated cancelled invoice


Recommended Posts

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

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