Jump to content
MikeDVB

WHMCS 5.0 Style Bar Widgets for Monthly Completed Orders and Monthly Income

Recommended Posts

I finally figured out a way to remove the validation and make use of the $totalyears variable - makes the code much neater too. :idea:

 

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

function income_overview_bars($vars) {
   global $_ADMINLANG,$chart;

   $title = 'Income Overview for '.date("Y");
   $args = array();
   $args['colors'] = '#3070CF,#F9D88C,#779500,#E8C2D4,#CBEAAD';
   $args['chartarea'] = '80,40,85%,70%';
   $args['xlabel'] = 'Month of Year';
   $args['ylabel'] = 'Default Currency';
   $content = $chart->drawChart('Column',chartdata_annual_overview_bars(),$args,'300px');

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

function chartdata_annual_overview_bars() {

   $totalyears = 4;

   for($i = 0; $i <= $totalyears-1; $i++) {
   $chartyear[$i] = date("Y",strtotime("-$i year"));
   }

   $chartdata = array();
   $chartdata['cols'][] = array('label'=>'Days Range','type'=>'string');

   for($i = $totalyears-1; $i >=0 ; $i--) {
   $chartdata['cols'][] = array('label'=>$chartyear[$i],'type'=>'number');
   }

   $months = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

   for ( $counter = 1; $counter <= 12; $counter += 1) {
       $month = $months[$counter-1];
       $counter = str_pad($counter, 2, "0", STR_PAD_LEFT);
           for($i = $totalyears-1; $i >=0 ; $i--) {
           $monthbal[$i] = get_query_val("tblaccounts","SUM((amountin-fees-amountout)/rate)","date LIKE '".$chartyear[$i]."-$counter-%'");
           }
       $chartdata['rows'][] = array('c'=>array(array('v'=>$month),array('v'=>$monthbal[$totalyears-1],'f'=>formatCurrency($monthbal[$totalyears-1])),array('v'=>$monthbal[$totalyears-2],'f'=>formatCurrency($monthbal[$totalyears-2])),array('v'=>$monthbal[$totalyears-3],'f'=>formatCurrency($monthbal[$totalyears-3])),array('v'=>$monthbal[$totalyears-4],'f'=>formatCurrency($monthbal[$totalyears-4])),array('v'=>$monthbal[$totalyears-5],'f'=>formatCurrency($monthbal[$totalyears-5]))));
   }
   return $chartdata;
}

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

?> 

 

Any idea why do not work with version 6.2?

Share this post


Link to post
Share on other sites
Any idea why do not work with version 6.2?

they work fine on my v6 dev using v6.2 :idea:

Share this post


Link to post
Share on other sites

Still working fine on v7.2.3 :1311_thumbsup_tone2:

Just the mouse over effect showing the amounts is not working. :/

Share this post


Link to post
Share on other sites
21 minutes ago, Patty said:

Just the mouse over effect showing the amounts is not working.

the reverse version seems to be working fine if the widget is only using 1 year, but fails if using more than that... 9_9

the normal version seems to display fine for multiple years. :smile2:

if @MikeDVB can figure out the issue, so much the better - if not, i'll take a look at the weekend and rewrite the widget for v7.

 

  • Like 1

Share this post


Link to post
Share on other sites
On 4/1/2015 at 7:22 PM, brian! said:

I finally figured out a way to remove the validation and make use of the $totalyears variable - makes the code much neater too. :idea:

 

 


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

function income_overview_bars($vars) {
   global $_ADMINLANG,$chart;

   $title = 'Income Overview for '.date("Y");
   $args = array();
   $args['colors'] = '#3070CF,#F9D88C,#779500,#E8C2D4,#CBEAAD';
   $args['chartarea'] = '80,40,85%,70%';
   $args['xlabel'] = 'Month of Year';
   $args['ylabel'] = 'Default Currency';
   $content = $chart->drawChart('Column',chartdata_annual_overview_bars(),$args,'300px');

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

function chartdata_annual_overview_bars() {

   $totalyears = 4;

   for($i = 0; $i <= $totalyears-1; $i++) {
   $chartyear[$i] = date("Y",strtotime("-$i year"));
   }

   $chartdata = array();
   $chartdata['cols'][] = array('label'=>'Days Range','type'=>'string');

   for($i = $totalyears-1; $i >=0 ; $i--) {
   $chartdata['cols'][] = array('label'=>$chartyear[$i],'type'=>'number');
   }

   $months = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

   for ( $counter = 1; $counter <= 12; $counter += 1) {
       $month = $months[$counter-1];
       $counter = str_pad($counter, 2, "0", STR_PAD_LEFT);
           for($i = $totalyears-1; $i >=0 ; $i--) {
           $monthbal[$i] = get_query_val("tblaccounts","SUM((amountin-fees-amountout)/rate)","date LIKE '".$chartyear[$i]."-$counter-%'");
           }
       $chartdata['rows'][] = array('c'=>array(array('v'=>$month),array('v'=>$monthbal[$totalyears-1],'f'=>formatCurrency($monthbal[$totalyears-1])),array('v'=>$monthbal[$totalyears-2],'f'=>formatCurrency($monthbal[$totalyears-2])),array('v'=>$monthbal[$totalyears-3],'f'=>formatCurrency($monthbal[$totalyears-3])),array('v'=>$monthbal[$totalyears-4],'f'=>formatCurrency($monthbal[$totalyears-4])),array('v'=>$monthbal[$totalyears-5],'f'=>formatCurrency($monthbal[$totalyears-5]))));
   }
   return $chartdata;
}

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

?> 
 

 

Hello how are you?

Did you even test these widgets in the latest stable release?

Share this post


Link to post
Share on other sites
13 hours ago, edvancombr said:

Did you even test these widgets in the latest stable release? 

they wouldn't work in v7.6+ and would have to be rewritten - give me a poke when v7.7 comes out and i'll take a closer look.

Share this post


Link to post
Share on other sites
21 hours ago, brian! said:

they wouldn't work in v7.6+ and would have to be rewritten - give me a poke when v7.7 comes out and i'll take a closer look.

Thank you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines