Jump to content

Report/widget for estimated income?


zomex

Recommended Posts

  • 1 year later...
On 12/6/2023 at 6:08 AM, zomex said:

Hello,

A few years ago WHMCS used to have a admin homepage widget that would display the estimated income broken down by month, year etc.

Does anyone know what happened to this? Why was it removed and is there a new version/replacement?

Thanks

I still have a copy of it and use it.  Do you need it?

Link to comment
Share on other sites

Sorry for the delay, here you go:

<?php

if (!defined("WHMCS"))
    die("This file cannot be accessed directly");

function widget_income_forecast_avg($vars) {
    global $whmcs,$_ADMINLANG,$currency,$currencytotal,$data;

    $title = "Income Forecast Avg";

function ah_formatstat1($billingcycle,$stat) {
    global $data,$currency,$currencytotal;
    $value = array_key_exists($billingcycle,$data) ? $data[$billingcycle][$stat] : '';
    if (!$value) $value = 0;
    if ($stat=="sum") {
        if ($billingcycle=="Monthly") {
            $currencytotal += $value*12;
        } elseif ($billingcycle=="Quarterly") {
            $currencytotal += $value*4;
        } elseif ($billingcycle=="Semi-Annually") {
            $currencytotal += $value*2;
        } elseif ($billingcycle=="Annually") {
            $currencytotal += $value;
        } elseif ($billingcycle=="Biennially") {
            $currencytotal += $value/2;
        } elseif ($billingcycle=="Triennially") {
            $currencytotal += $value/3;
        }
        $value = formatCurrency($value);
    }
    return $value;
}
$incomestats = array();
$result = select_query("tblhosting,tblclients", "currency,billingcycle,COUNT(*),SUM(amount)", "tblclients.id = tblhosting.userid AND (domainstatus = 'Active' OR domainstatus = 'Suspended') GROUP BY currency, billingcycle");
while ($data = mysql_fetch_array($result)) {
    $incomestats[$data['currency']][$data['billingcycle']]["count"] = $data[2];
    $incomestats[$data['currency']][$data['billingcycle']]["sum"] = $data[3];
}
$result = select_query("tblhostingaddons,tblhosting,tblclients", "currency,tblhostingaddons.billingcycle,COUNT(*),SUM(recurring)", "tblhostingaddons.hostingid=tblhosting.id AND tblclients.id=tblhosting.userid AND (tblhostingaddons.status='Active' OR tblhostingaddons.status='Suspended') GROUP BY currency, tblhostingaddons.billingcycle");
while ($data = mysql_fetch_array($result)) {
    if (isset($incomestats[$data['currency']][$data['billingcycle']]["count"])) $incomestats[$data['currency']][$data['billingcycle']]["count"] += $data[2];
    else $incomestats[$data['currency']][$data['billingcycle']]["count"] = $data[2];
    if (isset($incomestats[$data['currency']][$data['billingcycle']]["sum"])) $incomestats[$data['currency']][$data['billingcycle']]["sum"] += $data[3];
    else $incomestats[$data['currency']][$data['billingcycle']]["sum"] = $data[3];
}
$result = select_query("tbldomains,tblclients", "currency,COUNT(*),SUM(recurringamount/registrationperiod)", "tblclients.id=tbldomains.userid AND tbldomains.status='Active' GROUP BY currency");
while ($data = mysql_fetch_array($result)) {
    if (isset($incomestats[$data['currency']]["Annually"]["count"])) $incomestats[$data['currency']]["Annually"]["count"] += $data[1];
    else $incomestats[$data['currency']]["Annually"]["count"] = $data[1];
    if (isset($incomestats[$data['currency']]["Annually"]["sum"])) $incomestats[$data['currency']]["Annually"]["sum"] += $data[2];
    else $incomestats[$data['currency']]["Annually"]["sum"] = $data[2];
}

$content = '';
if (count($incomestats)) {
    $content = '<div class="row">';
    foreach ($incomestats AS $currency=>$data) {
        $currency = getCurrency("",$currency);
        $currencytotal = 0;
        $content .= '<div class="' . ((count($incomestats) > 1) ? 'col-md-6' : '') . ' text-center">'
            . "<span class=\"textred\"><b>{$currency['code']} ".$_ADMINLANG['currencies']['currency']."</b></span><br />
    ".$_ADMINLANG['billingcycles']['monthly'].": ".ah_formatstat1('Monthly','sum')." (".ah_formatstat1('Monthly','count').")<br />
    ".$_ADMINLANG['billingcycles']['quarterly'].": ".ah_formatstat1('Quarterly','sum')." (".ah_formatstat1('Quarterly','count').")<br />
    ".$_ADMINLANG['billingcycles']['semiannually'].": ".ah_formatstat1('Semi-Annually','sum')." (".ah_formatstat1('Semi-Annually','count').")<br />
    ".$_ADMINLANG['billingcycles']['annually'].": ".ah_formatstat1('Annually','sum')." (".ah_formatstat1('Annually','count').")<br />
    ".$_ADMINLANG['billingcycles']['biennially'].": ".ah_formatstat1('Biennially','sum')." (".ah_formatstat1('Biennially','count').")<br />
    ".$_ADMINLANG['billingcycles']['triennially'].": ".ah_formatstat1('Triennially','sum')." (".ah_formatstat1('Triennially','count').")<br />
    <span class=\"textgreen\"><b>".$_ADMINLANG['billing']['annualestimate'].": ".formatCurrency($currencytotal)." (".formatCurrency($currencytotal/12).")</b></span></div>";
    }
    $content .= '</div>';
} else {
    $content = '<div align="center">No Active or Suspended Products/Services Found to build Forecast</div>';
}

    $content = '<div id="incomeforecastavg">'.$content.'</div>';

    return array('title'=>$title,'content'=>$content);

}

add_hook("AdminHomeWidgets",1,"widget_income_forecast_avg");

 

Edited by blakeh
Link to comment
Share on other sites

Here is another widget I got back at the same time from these forums that does a year over year monthly compare.

 

<?php

    if (!defined("WHMCS"))
        die("This file cannot be accessed directly");

    function widget_monthly_compare() {
    
    $startmonth = date('Y-m');
    $previousyear = date('Y-m', strtotime('-1 year', strtotime($startmonth)) );    
    
    $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;font-size:14px;" cellspacing="1">
    <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="25%">Month</td><td width="25%">Income</td><td width="25%">Income</td><td width="25%">Month</td></tr>';

    $x=1;
    while($x<=12) {
        $result = mysql_query("SELECT SUM((amountin-fees-amountout)/rate) FROM tblaccounts WHERE date LIKE '".$startmonth."-%'");
        while ($data = @mysql_fetch_array ($result)) {
           $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date('F Y', strtotime($startmonth)).'</td><td>'.formatCurrency($data['SUM((amountin-fees-amountout)/rate)']).'</td>';
        }    
        $result = mysql_query("SELECT SUM((amountin-fees-amountout)/rate) FROM tblaccounts WHERE date LIKE '".$previousyear."-%'");
        while ($data = @mysql_fetch_array ($result)) {
           $content .= '<td>'.formatCurrency($data['SUM((amountin-fees-amountout)/rate)']).'</td><td>'.date('F Y', strtotime($previousyear)).'</td></tr>';
        }    
        $startmonth = date('Y-m', strtotime('-1 month', strtotime($startmonth)) );    
        $previousyear = date('Y-m', strtotime('-1 month', strtotime($previousyear)) );    
    $x++;
    } 
    $content .= '</table>';
        return array( 'title' => 'Monthly Income Comparison', 'content' => $content );
    }
    add_hook("AdminHomeWidgets",1,"widget_monthly_compare");
?>

 

Link to comment
Share on other sites

1 minute ago, zomex said:

Thanks for sharing the code.

Not having any luck getting these to display. Tried /modules/widgets/ and includes/hooks/

You put them in widgets. Then you have to go into admin roles and enable display for them, checkboxes at the bottom.

Link to comment
Share on other sites

21 minutes ago, blakeh said:

You put them in widgets. Then you have to go into admin roles and enable display for them, checkboxes at the bottom.

Thanks 🙂

Now displaying well. Shame multicurrency isn't working properly but beggars can't be choosers it's nice to have this feature back.

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