Jump to content

Bulk Auto Recalculate Client Domains & Products/Services


Kian

Recommended Posts

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
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
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?

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

 

 

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

Link to comment
Share on other sites

  • 5 months later...
  • 4 months later...
On 3/6/2021 at 2:04 PM, persis said:

Hi @Kian

Many thanks for this useful hook.

I test it with whmcs 8.1.3 and work great.

could you please add this features to this hook?

- work for all customers at once.

-work automatic with whmcs cron.

thank you in advance

<?php

use WHMCS\Database\Capsule;

add_hook('AfterCronJob', 1, function($vars)
{
    $adminUsername = ''; // Optional for WHMCS 7.2 and later
    
    foreach(Capsule::table('tblhosting')->pluck('id') as $v)
    {
        localAPI('UpdateClientProduct', array('serviceid' => $v, 'autorecalc' => true), $adminUsername);
    }

    foreach (Capsule::table('tbldomains')->pluck('id') as $v)
    {
        localAPI('UpdateClientDomain', array('domainid' => $v, 'autorecalc' => true), $adminUsername);
    }

});

Link to comment
Share on other sites

  • 6 months later...
On 7/10/2021 at 7:06 PM, persis said:

<?php

use WHMCS\Database\Capsule;

add_hook('AfterCronJob', 1, function($vars)
{
    $adminUsername = ''; // Optional for WHMCS 7.2 and later
    
    foreach(Capsule::table('tblhosting')->pluck('id') as $v)
    {
        localAPI('UpdateClientProduct', array('serviceid' => $v, 'autorecalc' => true), $adminUsername);
    }

    foreach (Capsule::table('tbldomains')->pluck('id') as $v)
    {
        localAPI('UpdateClientDomain', array('domainid' => $v, 'autorecalc' => true), $adminUsername);
    }

});

Thanks, but it doesn't work as expected. Does it need any modification for whmcs 8.3.2 ? or I missed something 😞

Edited by Ardeshir
Link to comment
Share on other sites

  • 1 year later...

It seems the feature request shows a 404 now, not even a feature request for this now?
The inflation is growing everywhere, but imagine living in Argentina where it's always 2 digits yearly.

This module worked fine but not yet for PHP 8, hopefully there is a native feature for this, to mass update the pricing of all services to match the price configured at the product.

Link to comment
Share on other sites

It shows a 404 because they deleted it leaving no trace 😄 Btw stop waiting and do it yourself. Sadly there's no other option.

I recently managed to auto-update domains in line with changes in Registrars costs. Next week I'll add monthly updates for all prices based on inflation rate retreived from official statistical offices like Eurostat, Istat etc. It is well worth the effort since at the end of the day it lets you cover unnecessary financial loss.

It puzzles me how this is still not part of WHMCS but it is what it is. After 10 years we are still waiting. The lesson here is: hire someone that can code it or do it youself 😐

Link to comment
Share on other sites

  • 6 months later...

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