Jump to content
Sign in to follow this  
Web Host Pro

Is there a way to remove old invoices of terminated accounts?

Recommended Posts

It looks like WHMCS is terminated accounts that are the set past due but it's not removing the invoices. Is there a way for WHMCS to see if the account is terminated or cancelled and remove the invoice if it is?

Share this post


Link to post
Share on other sites

It can also be done using a hook.

<?php

$daysBeforeCancel = '60'; //Change this to how many days you want to wait for the system to cancel an invoice after the due date

use WHMCS\Database\Capsule;
add_hook('DailyCronJobPreEmail', 1, function($vars) {
	$command = 'GetInvoices';
	$postData = array(
		'status' => 'Overdue',
		'limitnum' => '700', 
	);
	$results = localAPI($command, $postData);
		
	foreach ($results['invoices']['invoice'] as $cancelInvoice){
		if(strtotime($cancelInvoice['duedate']) < strtotime($daysBeforeCancel)) {
			$command = 'UpdateInvoice';
			$postData = array(
				'invoiceid' => $cancelInvoice['id'],
				'status' => 'Cancelled',
				);
			$results = localAPI($command, $postData);
        };

	}

});

 

Share this post


Link to post
Share on other sites
On 1/3/2019 at 12:02 AM, DennisHermannsen said:

It can also be done using a hook.


<?php

$daysBeforeCancel = '60'; //Change this to how many days you want to wait for the system to cancel an invoice after the due date

use WHMCS\Database\Capsule;
add_hook('DailyCronJobPreEmail', 1, function($vars) {
	$command = 'GetInvoices';
	$postData = array(
		'status' => 'Overdue',
		'limitnum' => '700', 
	);
	$results = localAPI($command, $postData);
		
	foreach ($results['invoices']['invoice'] as $cancelInvoice){
		if(strtotime($cancelInvoice['duedate']) < strtotime($daysBeforeCancel)) {
			$command = 'UpdateInvoice';
			$postData = array(
				'invoiceid' => $cancelInvoice['id'],
				'status' => 'Cancelled',
				);
			$results = localAPI($command, $postData);
        };

	}

});

 

Hello! Thank you for sharing the code but unfortunately it is not working for me. Do you think this code is outdated?

Share this post


Link to post
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.

Sign in to follow this  

  • 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