1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 %# CONTRIBUTION SUBMISSION POLICY:
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
45 %# END BPS TAGGED BLOCK }}}
48 $weekends => $Statistics::PerDayWeekends;
65 my $now = new RT::Date($session{CurrentUser});
69 if (!defined $Queue) {
70 $Queue = $Statistics::PerDayQueue;
73 if ($sDay > $Statistics::monthsMaxDay{$sMonth}) {
74 $sDay = $Statistics::monthsMaxDay{$sMonth};
77 if ($eDay > $Statistics::monthsMaxDay{$eMonth}) {
78 $eDay = $Statistics::monthsMaxDay{$eMonth};
82 $sEpoch = timelocal(0, 0, 0, $sDay, $sMonth, $sYear-1900);
85 Statistics::DebugLog("eMonth = " . $eMonth . "\n");
86 $eEpoch = timelocal(0, 0, 0, $eDay, $eMonth, $eYear-1900);
88 # This case happens when the page is first loaded
89 my @local = localtime(time);
90 ($eDay, $eMonth, $eYear) = ($local[3], $local[4], $local[5]);
92 $eEpoch = timelocal(0, 0, 0, $local[3], $local[4], $local[5], $local[6], $local[7], $local[8]);
93 Statistics::DebugLog("Setting eEpoch=$eEpoch from current time.\n");
96 if (($eEpoch < $sEpoch) || ($sEpoch == 0)) {
97 # We have an end, but not a start, or, overlapping.
99 # if $currentMonth is set, just set the day to 1
101 # set start vars from end, but with day set to 1
102 (undef, undef, undef, $sDay, $sMonth, $sYear) = localtime($eEpoch);
104 $sEpoch = timelocal(0, 0, 0, $sDay, $sMonth, $sYear);
106 # If the user has specified how many days back to go, use that,
107 # If not, set start to configured default period before end
109 $sEpoch = $eEpoch - ($days * $Statistics::secsPerDay);
111 $sEpoch = $eEpoch - ($Statistics::PerDayPeriod * $Statistics::secsPerDay);
113 (undef, undef, undef, $sDay, $sMonth, $sYear) = localtime($sEpoch);
119 $r->content_type('application/vnd.ms-excel');
121 # Put out some data about the generation of this file
122 $m->out("Tickets per day for Queue:\t" . $Queue . "\tGenerated at:\t" . Statistics::FormatDate("%x %X", $now). "\n\n");
125 # Compute days to chart.
126 # The +1 is because we need to generate one more date. If the user
127 # selected a 10 day range, we need to generate 11 days.
128 my $diff = int(($eEpoch - $sEpoch + $Statistics::secsPerDay - 1) / $Statistics::secsPerDay)+1;
130 # Build array of dates
131 my $endRange = $eEpoch + $Statistics::secsPerDay;
132 my $QueueObj = new RT::Queue($session{'CurrentUser'});
133 $QueueObj->Load($Queue);
134 until ($#dates == $diff) {
135 my $date = new RT::Date($session{CurrentUser});
136 $date->Set(Value=>$endRange - $n, Format => 'unix');
137 # Note: we used to adjust the time to local midnight, but
138 # none of the other date entry fields in RT seem to adjust, so we've stopped.
139 #Statistics::DebugLog("Before adjust to midnight date " . Statistics::FormatDate("%c", $date) . "\n");
140 $n+= $Statistics::secsPerDay;
141 # If we aren't showing weekends and this is one, decrement the number
142 # of days to show and skip to the next date.
143 if(!$weekends and Statistics::RTDateIsWeekend($date)) {$diff--; next;}
144 unshift @dates, $date;
148 $m->out("Date\tcreate\tresolved\tdeleted\n");
151 LINE: for my $d (0..$#dates) {
156 # Output the date for this row
157 $m->out(Statistics::FormatDate($Statistics::PerDayDateFormat, $dates[$d]));
159 # output the 3 columns for this row
160 for my $status (qw(created resolved deleted)) {
161 my $tix = new RT::Tickets($session{'CurrentUser'});
162 if ($status eq "created") {
163 $tix->LimitCreated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
165 $tix->LimitCreated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
167 } elsif ($status eq "resolved") {
168 $tix->LimitStatus(VALUE => $status);
169 $tix->LimitResolved(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
171 $tix->LimitResolved(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
173 } elsif ($status eq "deleted") {
174 $tix->LimitStatus(VALUE => $status);
175 $tix->LimitLastUpdated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
177 $tix->LimitLastUpdated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
180 $tix->LimitQueue (VALUE => $Queue);
181 $m->out( "\t" . $tix->Count );
182 $Totals{$status} += $tix->Count;
188 $m->out("Totals\t$Totals{created}\t$Totals{resolved}\t$Totals{deleted}\n");