Jump to content

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


Recommended Posts

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);
        };

	}

});

 

Link to comment
Share on other sites

  • 3 years later...
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?

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