Jump to content

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


MikeDVB

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...
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?

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 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