Sales per year report off by one month

Project:Ubercart Contributions
Component:Code
Category:
Priority:normal
Assigned:Unassigned
Status:active
Description
Project: 
Ubercart

In the latest upgrade to 1.6, there has been a bug introduced into the Sales reports, specifically the "Sales per year" report (admin/store/reports/sales/year).

When looking at the report in the default view, the number of orders is listed one month off from the month the orders were completed. Therefore the total number of November orders shows up next to the "Dec 2008" link, number of October orders shows up next to the "Nov 2008" link, etc.

This used to work correctly in Ubercart 1.4.

Version: 
Ubercart 1.6
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Sales per year report off by one month

I'll diff the source, but I don't remember any changes to those modules. I wonder if it's not actually the timing of the releases, such that Daylight Savings Time is throwing a fork in the whole operation. Thoughts?

ron_s's picture
Offline
Joined: 09/11/2008
Juice: 173
Re: Re: Sales per year report off by one month
Assigned to:Ryan» ron_s

Possibly, but I would have thought we'd only see a one hour shift, or maybe at most one day?

We're seeing all of November's orders show up in the December line total, all of October's in November, etc. Also the total for the year is coming up empty. For example, we should be seeing this:

Month / Number of Orders
Sep 2008 / 561
Oct 2008 / 831
Nov 2008 / 352
Dec 2008 / 0
Total 2008 / (total # for the year)

But instead, we're seeing this:

Month / Number of Orders
Sep 2008 / 132
Oct 2008 / 561
Nov 2008 / 831
Dec 2008 / 352
Total 2008 / 0

Doesn't make sense why the total would be 0 ... I would expect it to be the running total for the year. Also obviously we haven't even reached December yet, but have 352 orders listed on the report.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Sales per year report off by one month
Assigned to:ron_s» Ryan

Schnikes... yeah, if only Ubercart was able to plan orders for you before they ever happened. So this happened when you updated, correct? Did you update or add any other modules at the same time? Is your system time displaying the correct time? Like if you go place an order right now, will it show today's date?

I'm asking these sorts of questions, because I did a diff on the reports module and literally nothing has changed in it since the 1.4 release.

ron_s's picture
Offline
Joined: 09/11/2008
Juice: 173
Re: Re: Re: Re: Sales per year report off by one month
Assigned to:Ryan» ron_s

Yes, this happened after update from 1.4 to 1.6. Pre-1.6 did not do this. Didn't update any other modules. Yes, the system time is displayed correctly, and yes an order right now shows the right date.

The orders are fine and assigned to the right dates. This problem is *only* on the "Sales per year" report. All other reports are good. Even the links on the "Sale per year" report are technically correct. If I attempt to click on the "Dec 2008" link, it tells me no orders can be found for that time period, which is right.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Re: Re: Sales per year report off by one month
Assigned to:ron_s» Ryan

Quick non sequitur... I hate the name of that report. Seems like it should at least be "Monthly sales report" or something. Sticking out tongue

Anyways, you should see the following lines in the reports module starting at line 498:

<?php
 
// For each month of the year...
 
for ($i = 1; $i <= 12; $i++) {
   
// Calculate the start and end timestamps for the month in local time.
   
$month_start = gmmktime(0, 0, 0, $i, 1, $year) - $timezone_offset;
   
$month_end = gmmktime(23, 59, 59, $i + 1, 0, $year) - $timezone_offset;
?>

I think this still may be a DST issue, so try making the following change:

<?php
 
// For each month of the year...
 
for ($i = 1; $i <= 12; $i++) {
   
// Calculate the start and end timestamps for the month in local time.
   
$month_start = gmmktime(0, 0, 0, $i, 1, $year) - $timezone_offset - 3600;
   
$month_end = gmmktime(23, 59, 59, $i + 1, 0, $year) - $timezone_offset - 3600;
?>

Let's see where that gets us...

ron_s's picture
Offline
Joined: 09/11/2008
Juice: 173
Re: Re: Re: Re: Re: Re: Sales per year report off by one month
Assigned to:Ryan» ron_s

Gave it a try and no change ... still the same. And yes, I agree it should be something like a "monthly sales report". Smiling

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Re: Re: Re: Re: Sales per year report off by one mon
Assigned to:ron_s» Ryan

Any chance I could get ya to play around with those month start and end dates until you find one that works? Sticking out tongue

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 850
Re: Re: Re: Re: Re: Re: Re: Re: Sales per year report off by one
Assigned to:Ryan» cYu

I've seen oddities regarding reports and DST as well. Did you happen to update the default time zone at admin/settings/date-time whenever DST kicked in?

leenwebb's picture
Offline
Joined: 06/01/2008
Juice: 248
Another data point
Assigned to:cYu» leenwebb

FWIW, I was seeing this exact same thing -- orders off by one month in the Sales by Year report -- and it corrected itself when I went to Date&Time and set the timezone to be correct (EST instead of GMT) and set the "Configurable Time Zone" to disabled. Dunno why that would make a difference, but in my case it fixed the issue.

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 850
Re: Re: Re: Re: Re: Re: Re: Re: Sales per year report off by one
Assigned to:leenwebb» cYu

One thing I noticed was happening with Custom sales report parameters was that after I submitted something like December 1 2008 - December 2 2008 the page would reload with December 1 2008 - December 3 2008.

I think I tracked this down to an issue with the sales report trying to use _uc_reports_timezone_offset() which uses a site's timezone to generate a timestamp but then the date being output with format_date() which takes that timestamp and then applies the individual user's timezone to it. So if a user's timezone does not match the site's timezone you will see strange behavior.

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 850
Re: Re: Re: Re: Re: Re: Re: Re: Re: Sales per year report off by

Perhaps passing _uc_reports_timezone_offset() as the 4th parameter to format_date() would fix some things?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Patch posted
Assigned to:cYu» Lyle

There's a patch posted on drupal.org for those who are interested in trying it: http://drupal.org/node/344890.