Jump to content
Kian

Bulk Auto Recalculate Client Domains & Products/Services

Recommended Posts

Posted (edited)

I've seen there's a feature request submitted 7 years ago about bulk auto recalculate. I know you can do that from phpMyAdmin or with a script but enough is enough.

whmcs-bulk-auto-recalculate-customer.png.c70b86e753454dee952995aee6b324c2.png

whmcs-bulk-auto-recalculate-customer-domain-product.png.d4378ab3f748d230563ae523d8b863c5.png

<?

/**
 * Bulk Auto Recalculate Client Domain & Products/Services
 *
 * @writtenby   Kian
 *
 */

use WHMCS\Database\Capsule;

add_hook('AdminAreaHeaderOutput', 1, function($vars)
{
    if ($vars['filename'] == 'clientssummary' AND $_GET['userid'] AND in_array($_GET['kata'], array('bulkAutoRecalculateP', 'bulkAutoRecalculateD')))
    {
        $adminUsername = ''; // Optional for WHMCS 7.2 and later

        if ($_GET['kata'] == 'bulkAutoRecalculateP')
        {
            foreach(Capsule::table('tblhosting')->where('userid', '=', $_GET['userid'])->pluck('id') as $v)
            {
                localAPI('UpdateClientProduct', array('serviceid' => $v, 'autorecalc' => true), $adminUsername);
            }

            header('Location: clientssummary.php?userid=' . $_GET['userid']);
            die();
        }
        elseif ($_GET['kata'] == 'bulkAutoRecalculateD')
        {
            foreach (Capsule::table('tbldomains')->where('userid', '=', $_GET['userid'])->pluck('id') as $v)
            {
                localAPI('UpdateClientDomain', array('domainid' => $v, 'autorecalc' => true), $adminUsername);
            }

            header('Location: clientssummary.php?userid=' . $_GET['userid']);
            die();
        }
    }

    return <<<HTML
<script>
$(document).ready(function(){
	$('[href*="affiliates.php?action=edit&id="], [href*="clientssummary.php?userid="][href*="&activateaffiliate=true&token="]').closest('li').after(('<li><a href="#" id="kata_BulkAutoRecalculate"><i class="fas fa-fw fa-sliders-h" style="width:16px;text-align:center;"></i> Bulk Auto Recalculate</a></li>'));
		$('#kata_BulkAutoRecalculate').on('click', function(e){
			e.preventDefault();
			$('#modalAjaxTitle').html('Bulk Auto Recalculate');
			$('#modalAjaxBody').html('<div class="container col-md-12"><div class="row"><div class="col-md-6 text-center"><div class="panel panel-default"><div class="panel-body"><p><i class="fas fa-box fa-5x"></i></p><p><small>Auto Recalculate Customer\'s <strong>Products/Services</strong></small></p><p><a href="clientssummary.php?userid={$_GET['userid']}&kata=bulkAutoRecalculateP" class="btn btn-info btn-block">Recalculate Now »</a></p></div></div></div><div class="col-md-6 text-center"><div class="panel panel-default"><div class="panel-body"><p><i class="fas fa-globe fa-5x"></i></p><p><small>Auto Recalculate Customer\'s <strong>Domains</strong></small></p><p><a href="clientssummary.php?userid={$_GET['userid']}&kata=bulkAutoRecalculateD" class="btn btn-info btn-block">Recalculate Now »</a></p></div></div></div></div></div>');
			$('#modalAjax .modal-submit').addClass('hidden');
			$('#modalAjaxLoader').hide();
			$('#modalAjax .modal-dialog').addClass('modal-lg');
			$('#modalAjax').modal('show');
		})
	})
</script>
HTML;

});

 

Edited by Kian

Share this post


Link to post
Share on other sites

Hi there

May I ask what is updated by this? I'm trying to simplify the process of updating due dates, invoices etc, and this sounds interesting.

Share this post


Link to post
Share on other sites
1 minute ago, PatInt said:

May I ask what is updated by this?

Recurring amount.

1 minute ago, PatInt said:

I'm trying to simplify the process of updating due dates, invoices etc, and this sounds interesting.

Are you talking about overriding "Next Due Date" in bulk?

Share this post


Link to post
Share on other sites
Just now, Kian said:

Recurring amount.

Are you talking about overriding "Next Due Date" in bulk?

Yes...I realise this is restricted to the current user though.

Also the generate due invoices seems to miss anything over 1 month old, so just fishing around for solutions and handy tools as I'm new to WHMCS.

 

 

Share this post


Link to post
Share on other sites

Technically, it didn't miss anything over 1 month old. If it doesn't generate the invoice(s), it means it's already been generated unless you deleted them manually.

If that's not the case, try settings the next due date to a different date, save, and change it to the original expiry date, save again. Try generate due invoice again and see if that fixes the issue.

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.


  • 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