Jump to content

Widget to show income between any two dates, e.g Fiscal Year, Quarter etc


brian!

Recommended Posts

Here is a simple widget that you can add to your Admin homepage to show your actual income between two specified dates - this could be your fiscal year; a quarter, week, six months, two years.. in fact, any dates that you wish! :)

 

this is how the widget will look.

 

cmOXl2z.png

 

the code for this widget, which i've called fiscal_income.php, is as follows:

 

     <?php

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

   function widget_fiscal_income() {

   $startdate = '2014-01-01';
   $enddate = '2014-12-31';
   $dateformat = 'd/m/Y';

   $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;" cellspacing="1">
   <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td>Start Date</td><td>End Date</td><td>Income</td></tr>';

       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate' AND '$enddate'");
       while ($data = @mysql_fetch_array ($result)) {
           $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate)).'</td><td>'.date($dateformat, strtotime($enddate)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
       }
       $content .= '</table>';

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

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

   ?>

create a new file in your /modules/widgets/ directory called fiscal_income.php and paste the above code into it.

 

if you are unfamiliar with adding widgets to your Admin homepage, read the documentation to learn how...

 

http://docs.whmcs.com/Widgets

 

if the widget is working correctly, by default it should output the same income amount as already shown in the top right of your admin homepage.

 

next you will need to modify three variables within the code to suit your own requirements...

 

    $startdate = '2014-01-01';
   $enddate = '2014-12-31';
   $dateformat = 'd/m/Y';

the two dates must be in YYYY-MM-DD format (as that is how they are stored in the database)... if you wanted to use your own fiscal dates, e.g 6th April 2014 - 5th April 2015, you would change the date variables to...

 

    $startdate = '2014-04-06';
   $enddate = '2015-04-05';

$dateformat can be used to change the output of the date from YYYY-MM-DD to a more familiar format - for most that will be 'd/m/Y'; for China it might be 'Y/m/d' and for USA, 'm/d/Y'.

 

in the admin area, if you currently see dates as 01/31/2014, you would modify the variable to be...

 

    $dateformat = 'm/d/Y';

I did consider querying the database to get the admin date format value currently used, but there may be circumstances where you want to use a different date format in this widget, so I decided to leave it as a variable that could be easily altered. :idea:

 

there are plenty of alternative options with regards to modifying how dates are shown, e.g using full or abbreviate month names, days etc as shown in the table below...

 

wp_date_format_2.jpg

 

if you wanted to show dates as '1 January 2014 - 31 December 2014', you would use...

 

    $dateformat = 'j F Y';

 

i've tried to keep the output flexible (and basic) enough for others to modify... currently it just uses two dates, but you could quite easily add additional date variables to show income from current and previous fiscal years, or the last few quarters - it would simply be a case of duplicating/modifying the variables and modifying the sql query.

 

e.g if you wanted to show income for both the current and previous fiscal year, you could modify the widget code by duplicating the date variables, and modifying the sql query.

 

     <?php

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

   function widget_fiscal_income() {

   $startdate = '2014-01-01';
   $enddate = '2014-12-31';
   $dateformat = 'd/m/Y';

   $startdate2 = '2013-01-01';
   $enddate2 = '2013-12-31';

   $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;" cellspacing="1">
   <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td>Start Date</td><td>End Date</td><td>Income</td></tr>';

       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate' AND '$enddate'");
       while ($data = @mysql_fetch_array ($result)) {
           $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate)).'</td><td>'.date($dateformat, strtotime($enddate)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
       }
       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate2' AND '$enddate2'");
       while ($data = @mysql_fetch_array ($result)) {
           $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate2)).'</td><td>'.date($dateformat, strtotime($enddate2)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
       }
       $content .= '</table>';

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

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

   ?>

this will now show two rows of data - the current fiscal year in the first row; the previous fiscal year in the second row.

 

I hope others will find this widget useful! :idea:

Link to comment
Share on other sites

Stunt's right with this - it's all about assigning who can use it via the admin area... it's why I added the link to the documentation! :roll:

 

Granting/Restricting Access to Widgets

 

Access to Widgets is defined on a per admin role group basis. So for example all your Sales staff might have access to the System & Orders Overview widgets, while your Support staff might not require those things.

To get started, begin by navigating to Setup > Staff Management > Administrator Roles and then click the edit icon next to the admin role group you want to change.

 

Once on the permissions page, simply scroll down to the section labelled Widgets and from there you'll be able to enable/disable the Widgets accessible to that group by checking or unchecking the boxes.

Accessing Newly Installed Widgets

 

When a new widget is first installed into the system, the first thing you will always need to do before you can see & use it is navigate to your admin role group setup area as described above and enable it. Once enabled, you can then navigate back to your homepage and the new widget will appear as the top widget on your dashboard which you can move around and adjust as desired.

Link to comment
Share on other sites

Just playing around with the second version so to add the previous fiscal year, however the date for start/end is showing as 01/01/1970 with zero figures....I have checked the date range within the code and that is correct.

I would think that the dates must have been entered incorrectly - I can reproduce the 01/01/1970 default date error by adding a 'wrong' character to one of the date variables... '2014x01-01';

 

I would suggest checking the dates again... if they're correct, then the widget would work with any number of rows.

 

I tested the second version before posting without any issues. :)

Link to comment
Share on other sites

Thanks Brian.

 

Just checked the dates and they look correct. The top row works fine (previous Fiscal year) it's just the lower row that has the 1970 blank info.

 

Here's the dates I have:

 

$startdate = '2014-07-22';

$enddate = '2015-07-21';

$dateformat = 'd/m/Y';

 

$startdate = '2013-07-22';

$enddate = '2014-07-21';

 

As you can see by the dates we have just gone into our new Fiscal year!

Link to comment
Share on other sites

aahh... you didn't copy my code correctly! :)

 

you've reused the same date variables twice, whereas I used different variables for each fiscal period - so your dates variables should look like this...

 

  $startdate = '2013-07-22';
   $enddate = '2014-07-21';
$dateformat = 'd/m/Y';

$startdate2 = '2014-07-22';
  $enddate2 = '2015-07-21';

assuming that you've copied the rest of the code correctly, the top row should now show last fiscal year's amount; second row should use the current year details.

 

let me know if using the above date changes works.

Link to comment
Share on other sites

Oh lord....and then the penny drops!

 

Thanks Brian. I now understand what happened...I first used the single row option then when testing the double row option I just copied out of the original and changed the dates...not noticing the cheeky number 2!

 

Working perfectly now, thank you. Makes a HUGE difference to us. It's great seeing at a glance the incoming figures that are now accurate to our business.

 

Yet again very much appreciated!

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

while coding another widget (http://forum.whmcs.com/showthread.php?94823-Widget-To-Display-A-Summary-Of-Fiscal-Income-For-Multiple-Periods), I have revisited this widget and improved it so that it now only requires a fiscal start day and month - it calculates the fiscal year itself and the year end date - it adjusts automatically when the new fiscal year begins.

 

as before, I will post the code for the two versions - the first shows only the income for the current fiscal year; the second now shows the income for the current year and upto 9 previous years - if income for any fiscal year is zero, it will not be shown.

 

the 1-year Fiscal Income widget...

 

    <?php

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

   function widget_fiscal_income() {

   $startday = 1;
   $startmonth = 4;
   $currentyear = date('Y');    
   $dateformat = 'd/m/Y';
   $startdate = date_create($currentyear.'-'.$startmonth.'-'.$startday);
   $today = date_create(date('Y-m-d'));
   $interval = date_diff($startdate, $today);
   $days = $interval->format('%r%a');

       if($days>=0)
       {
       $startdate = $currentyear.'-'.$startmonth.'-'.$startday;
       }
       else
       {
       $startdate = ($currentyear-1).'-'.$startmonth.'-'.$startday;
       } 

   $enddate = date('Y-m-d', strtotime('+1 year -1 day', strtotime($startdate)) );    

   $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;" cellspacing="1">
   <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="33%">Start Date</td><td width="33%">End Date</td><td width="33%">Income</td></tr>';

       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate' AND '$enddate'");
       while ($data = @mysql_fetch_array ($result)) {
       $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate)).'</td><td>'.date($dateformat, strtotime($enddate)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
       }
       $content .= '</table>';

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

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

   ?>

and the 10-year version...

 

note that you can change this number of years simply by changing the value of X in the while loop - while($x<=10)... if you change X to 1, then its output should just be the same as that created by the previous 1-year widget code.

 

if you have only used WHMCS for 3 years, it will only show three years in the table - next fiscal year, it will show four years etc.

 

    <?php

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

   function widget_fiscal_income() {

   $startday = 1;
   $startmonth = 4;
   $currentyear = date('Y');    
   $dateformat = 'd/m/Y';
   $startdate = date_create($currentyear.'-'.$startmonth.'-'.$startday);
   $today = date_create(date('Y-m-d'));
   $interval = date_diff($startdate, $today);
   $days = $interval->format('%r%a');

       $dateformat = 'd/m/Y';

       if($days>=0)
       {
       $startdate = $currentyear.'-'.$startmonth.'-'.$startday;
       }
       else
       {
       $startdate = ($currentyear-1).'-'.$startmonth.'-'.$startday;
       } 

   $enddate = date('Y-m-d', strtotime('+1 year -1 day', strtotime($startdate)) );    

   $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;" cellspacing="1">
   <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="33%">Start Date</td><td width="33%">End Date</td><td width="33%">Income</td></tr>';

   $x=1;
   while($x<=10) {
       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate' AND '$enddate'");
       while ($data = @mysql_fetch_array ($result)) {
       if ($data['SUM(amountin-fees-amountout)'] > 0)
           {
               $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate)).'</td><td>'.date($dateformat, strtotime($enddate)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
           }
       }
       $startdate = date('Y-m-d', strtotime('-1 year', strtotime($startdate)) );    
       $enddate = date('Y-m-d', strtotime('-1 year', strtotime($enddate)) );    
   $x++;
} 

   $content .= '</table>';

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

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

   ?>

Link to comment
Share on other sites

while coding another widget (http://forum.whmcs.com/showthread.php?94823-Widget-To-Display-A-Summary-Of-Fiscal-Income-For-Multiple-Periods), I have revisited this widget and improved it so that it now only requires a fiscal start day and month - it calculates the fiscal year itself and the year end date - it adjusts automatically when the new fiscal year begins.

 

as before, I will post the code for the two versions - the first shows only the income for the current fiscal year; the second now shows the income for the current year and upto 9 previous years - if income for any fiscal year is zero, it will not be shown.

 

the 1-year Fiscal Income widget...

 

    <?php

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

   function widget_fiscal_income() {

   $startday = 1;
   $startmonth = 4;
   $currentyear = date('Y');    
   $dateformat = 'd/m/Y';
   $startdate = date_create($currentyear.'-'.$startmonth.'-'.$startday);
   $today = date_create(date('Y-m-d'));
   $interval = date_diff($startdate, $today);
   $days = $interval->format('%r%a');

       if($days>=0)
       {
       $startdate = $currentyear.'-'.$startmonth.'-'.$startday;
       }
       else
       {
       $startdate = ($currentyear-1).'-'.$startmonth.'-'.$startday;
       } 

   $enddate = date('Y-m-d', strtotime('+1 year -1 day', strtotime($startdate)) );    

   $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;" cellspacing="1">
   <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="33%">Start Date</td><td width="33%">End Date</td><td width="33%">Income</td></tr>';

       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate' AND '$enddate'");
       while ($data = @mysql_fetch_array ($result)) {
       $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate)).'</td><td>'.date($dateformat, strtotime($enddate)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
       }
       $content .= '</table>';

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

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

   ?>

and the 10-year version...

 

note that you can change this number of years simply by changing the value of X in the while loop - while($x<=10)... if you change X to 1, then its output should just be the same as that created by the previous 1-year widget code.

 

if you have only used WHMCS for 3 years, it will only show three years in the table - next fiscal year, it will show four years etc.

 

    <?php

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

   function widget_fiscal_income() {

   $startday = 1;
   $startmonth = 4;
   $currentyear = date('Y');    
   $dateformat = 'd/m/Y';
   $startdate = date_create($currentyear.'-'.$startmonth.'-'.$startday);
   $today = date_create(date('Y-m-d'));
   $interval = date_diff($startdate, $today);
   $days = $interval->format('%r%a');

       $dateformat = 'd/m/Y';

       if($days>=0)
       {
       $startdate = $currentyear.'-'.$startmonth.'-'.$startday;
       }
       else
       {
       $startdate = ($currentyear-1).'-'.$startmonth.'-'.$startday;
       } 

   $enddate = date('Y-m-d', strtotime('+1 year -1 day', strtotime($startdate)) );    

   $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;" cellspacing="1">
   <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="33%">Start Date</td><td width="33%">End Date</td><td width="33%">Income</td></tr>';

   $x=1;
   while($x<=10) {
       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate' AND '$enddate'");
       while ($data = @mysql_fetch_array ($result)) {
       if ($data['SUM(amountin-fees-amountout)'] > 0)
           {
               $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate)).'</td><td>'.date($dateformat, strtotime($enddate)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
           }
       }
       $startdate = date('Y-m-d', strtotime('-1 year', strtotime($startdate)) );    
       $enddate = date('Y-m-d', strtotime('-1 year', strtotime($enddate)) );    
   $x++;
} 

   $content .= '</table>';

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

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

   ?>

 

Wow! Invaluable tool.

Awesome work. Using it now.

I now have a great easy to read summary of last 10 years income to see how I am travelling at a glance, and it auto updates!!!! too.

 

I thank you so much for this.

Should be standard in WHMCS IMO.

Thank you again for your effort.

Link to comment
Share on other sites

Wow! Invaluable tool.

Awesome work. Using it now.

I now have a great easy to read summary of last 10 years income to see how I am travelling at a glance, and it auto updates!!!! too.

 

I thank you so much for this.

Should be standard in WHMCS IMO.

Thank you again for your effort.

 

I would like to hopefully try to add 2 of these.

1. As per above and a second

With last 10 months as in

jan vs jan last yr

feb vs feb last yr

 

Etc

If this is possible it would also be extremely helpful.

Is this possible to add 2, I presume I would need to alter names?

Link to comment
Share on other sites

i'll have a look at this tomorrow afternoon - it's gone midnight here, so a little too late to get my mind to focus on this...

 

you can do this already graphically by running the Annual Income Report, and running the mouse over the bar chart - but I guess this widget would put it in an easier numerical format.

Link to comment
Share on other sites

With last 10 months as in

jan vs jan last yr

feb vs feb last yr

I think the problem with this idea is if you mean you want to show the income for months from the current year next to those from the year before, that works fine now in Oct/Nov/Dec, but when you get to January and a new year begins, it will only show one month for 2015.

 

I was originally thinking of a 3-column widget (Month Name, Income This Year, Income Last Year) with the month name starting with the current month and working backwards... but you would currently end up showing December 2013 as the final month which is not technically "This Year"... so I thought that might get a little confusing..

 

so what i've done is alter the idea and wrote a widget that displays four columns - Month Year - Income This Year - Income Last Year - Month Year - so you would end up with something like this..

 

Screenshot_13.png

 

it is written to show all 12 months, so that is currently Nov 2014 - Dec 2013 in the first column, with Nov 2013 - Dec 2012 showing in the fourth column... with the monthly income values shown next to each month... so it will display the totals from the last 24 months (if you haven't been using WHMCS for that long, then some early months will have zero income).

 

if you don't need this fourth column, then you can just remove it from the table code in the widget.

 

the current month is always shown first and adjusts automatically at the start of each new month.

 

there are no variables to manually enter into the widget - they are all generated automatically - unless you wanted to alter the number of months shown, and you can do that by reducing the value of X in the code.

 

http://forum.whmcs.com/showthread.php?94902-Widget-To-Show-Comparison-of-Monthly-Income-Totals-From-This-Year-Last-Year

Link to comment
Share on other sites

  • 5 months later...

minor update...

 

<?php

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

   function widget_fiscal_income() {

   $startday = 1;
   $startmonth = 4;
   $currentyear = date('Y');    
   $dateformat = 'd/m/Y';
   $startdate = date_create($currentyear.'-'.$startmonth.'-'.$startday);
   $today = date_create(date('Y-m-d'));
   $interval = date_diff($startdate, $today);
   $days = $interval->format('%r%a');

       $dateformat = 'd/m/Y';

       if($days>=0)
       {
       $startdate = $currentyear.'-'.$startmonth.'-'.$startday;
       }
       else
       {
       $startdate = ($currentyear-1).'-'.$startmonth.'-'.$startday;
       } 

   $enddate = date('Y-m-d', strtotime('+1 year -1 day', strtotime($startdate)) );    

   $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;" cellspacing="1">
   <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td width="33%">Start Date</td><td width="33%">End Date</td><td width="33%">Income</td></tr>';

   $x=1;
   while($x<=10) {
       $result = mysql_query("SELECT SUM((amountin-fees-amountout)/rate) FROM tblaccounts WHERE date BETWEEN '$startdate' AND '$enddate'");
       while ($data = @mysql_fetch_array ($result)) {
       if ($data['SUM((amountin-fees-amountout)/rate)'] > 0)
           {
               $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate)).'</td><td>'.date($dateformat, strtotime($enddate)).'</td><td>'.formatCurrency($data['SUM((amountin-fees-amountout)/rate)']).'</td></tr>';
           }
       }
       $startdate = date('Y-m-d', strtotime('-1 year', strtotime($startdate)) );    
       $enddate = date('Y-m-d', strtotime('-1 year', strtotime($enddate)) );    
   $x++;
} 

   $content .= '</table>';

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

   add_hook("AdminHomeWidgets",1,"widget_fiscal_income");
?>

Link to comment
Share on other sites

  • 1 month later...

another year in what sense?

 

there was a 10-year version on the previous page of this thread - or there is a widget that can show the monthly income amounts as a bar chart for a number of years...

 

http://forum.whmcs.com/showthread.php?69506-WHMCS-5-0-Style-Bar-Widgets-for-Monthly-Completed-Orders-and-Monthly-Income&p=413775#post413775

Link to comment
Share on other sites

Hi,

 

I was referring to the code above. It only shows current fiscal and previous fiscal year.

What if I need another fiscal year. Example 2015, 2014 and 2013

use the 10-year version - it will only show years that have income... so you shouldn't need to adjust it, as it should show 2013,2014 and 2015 by default.

 

http://forum.whmcs.com/showthread.php?91343-Widget-to-show-income-between-any-two-dates-e-g-Fiscal-Year-Quarter-etc&p=397934#post397934

Link to comment
Share on other sites

Hi Brian, based on

$startdate = '2012-01-01';

$enddate = '2012-12-31';

$dateformat = 'd/m/Y';

 

$startdate2 = '2013-01-01';

$enddate2 = '2013-12-31';

 

would it be possible in Start Date be 7 days ago and end date be today so that you have a rolling 7 day report

Link to comment
Share on other sites

Hi,

 

would it be possible in Start Date be 7 days ago and end date be today so that you have a rolling 7 day report

sure, to show the weekly income for the last two weeks, you just need to modify the variables...

 

    <?php

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

   function widget_fiscal_weekly_income() {

   $startdate = date("Y-m-d",strtotime("-6 days"));
   $enddate = date("Y-m-d");
   $dateformat = "d/m/Y";

   $startdate2 = date("Y-m-d",strtotime("-13 days"));
   $enddate2 = date("Y-m-d",strtotime("-1 week"));

   $content = '<table bgcolor="#cccccc" align="center" style="margin-bottom:5px;width:100%;" cellspacing="1">
   <tr bgcolor="#efefef" style="text-align:center;font-weight:bold;"><td>Start Date</td><td>End Date</td><td>Income</td></tr>';

       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate' AND '$enddate'");
       while ($data = @mysql_fetch_array ($result)) {
           $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate)).'</td><td>'.date($dateformat, strtotime($enddate)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
       }
       $result = mysql_query("SELECT SUM(amountin-fees-amountout) FROM tblaccounts WHERE date BETWEEN '$startdate2' AND '$enddate2'");
       while ($data = @mysql_fetch_array ($result)) {
           $content .= '<tr bgcolor="#ffffff" style="text-align:center;"><td>'.date($dateformat, strtotime($startdate2)).'</td><td>'.date($dateformat, strtotime($enddate2)).'</td><td>'.formatCurrency($data['SUM(amountin-fees-amountout)']).'</td></tr>';
       }
       $content .= '</table>';

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

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

   ?>

alternatively, instead of using the last seven days, you could also define what your weekly period is (e.g, Monday -> Sunday) by using the following...

 

    $startdate = date("Y-m-d",strtotime("last monday"));
   $enddate = date("Y-m-d",strtotime("today"));
   $dateformat = "d/m/Y";

   $startdate2 = date("Y-m-d",strtotime("last monday -1 week"));
   $enddate2 = date("Y-m-d",strtotime("last sunday"));

this sets the start of your week as Monday and will display the income from the current week, last Monday to today (Mon 4th May - Sat 9th May), and the previous week (Mon 27th April -> Sun 3rd May).

 

for neatness, you could change the $enddate variable to a time in the future, e.g next Sunday, so that the dates shown were consistently regular...

 

    $enddate = date("Y-m-d",strtotime("next sunday"));

these ideas could probably be added to the 10-year widget version, and modified to display the weekly income for any number of previous weeks (rather than years).

Link to comment
Share on other sites

  • 2 years later...
13 minutes ago, djpete said:

Any updates on this code. It stops widgets refreshing on latest version of WHMCS. Once disabled all works how it should. But I used to like this feature..Help

on v7.3.0 ? using Blend or v4?? which version of the widget are you using???

it's not something i'm seeing locally in the v7.3 dev (or even v7.4RC for that matter) using Blend or v4 - all the other default widgets seem to be refreshing as normal. :?:

it is my intention to rewrite all of these widgets (including some new ones!) when v7.4 gets a full release - if I could reproduce your error, I could bring that forward, but i'm not seeing what you're seeing.

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