[freeside-commits] freeside/FS/FS/Report/Table Monthly.pm, 1.25, 1.26
Mark Wells
mark at wavetail.420.am
Sat Jan 7 15:04:05 PST 2012
Update of /home/cvs/cvsroot/freeside/FS/FS/Report/Table
In directory wavetail.420.am:/tmp/cvs-serv4642/FS/FS/Report/Table
Modified Files:
Monthly.pm
Log Message:
projected sales report, #15393
Index: Monthly.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Report/Table/Monthly.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -w -d -r1.25 -r1.26
--- Monthly.pm 26 Dec 2011 20:24:17 -0000 1.25
+++ Monthly.pm 7 Jan 2012 23:04:03 -0000 1.26
@@ -2,6 +2,7 @@
use strict;
use vars qw( @ISA );
+use FS::UID qw(dbh);
use FS::Report::Table;
use Time::Local qw( timelocal );
@@ -41,17 +42,55 @@
=cut
sub data {
+ local $FS::UID::AutoCommit = 0;
my $self = shift;
my $smonth = $self->{'start_month'};
my $syear = $self->{'start_year'};
my $emonth = $self->{'end_month'};
my $eyear = $self->{'end_year'};
+ # how far to extrapolate into the future
+ my $pmonth = $self->{'project_month'};
+ my $pyear = $self->{'project_year'};
+
+ # sanity checks
+ if ( $eyear < $syear or
+ ($eyear == $syear and $emonth < $smonth) ) {
+ return { error => 'Start month must be before end month' };
+ }
+
my $agentnum = $self->{'agentnum'};
+ if ( $pyear > $eyear or
+ ($pyear == $eyear and $pmonth > $emonth) ) {
+
+ # create the entire projection set first to avoid timing problems
+
+ $self->init_projection if $pmonth;
+
+ my $thisyear = $eyear;
+ my $thismonth = $emonth;
+ while ( $thisyear < $pyear ||
+ ( $thisyear == $pyear and $thismonth <= $pmonth )
+ ) {
+ my $speriod = timelocal(0,0,0,1,$thismonth-1,$thisyear);
+ $thismonth++;
+ if ( $thismonth == 13 ) { $thisyear++; $thismonth = 1; }
+ my $eperiod = timelocal(0,0,0,1,$thismonth-1,$thisyear);
+
+ $self->extend_projection($speriod, $eperiod);
+ }
+ }
+
my %data;
- while ( $syear < $eyear || ( $syear == $eyear && $smonth < $emonth+1 ) ) {
+ my $max_year = $pyear || $eyear;
+ my $max_month = $pmonth || $emonth;
+
+ my $projecting = 0; # are we currently projecting?
+
+ while ( $syear < $max_year
+ || ( $syear == $max_year && $smonth < $max_month+1 ) ) {
if ( $self->{'doublemonths'} ) {
my($firstLabel,$secondLabel) = @{$self->{'doublemonths'}};
@@ -62,6 +101,11 @@
push @{$data{label}}, "$smonth/$syear";
}
+ if ( $syear > $eyear || ( $syear == $eyear && $smonth >= $emonth + 1 ) ) {
+ # start getting data from the projection
+ $projecting = 1;
+ }
+
my $speriod = timelocal(0,0,0,1,$smonth-1,$syear);
push @{$data{speriod}}, $speriod;
if ( ++$smonth == 13 ) { $syear++; $smonth=1; }
@@ -71,20 +115,24 @@
my $col = 0;
my @items = @{$self->{'items'}};
my $i;
+
for ( $i = 0; $i < scalar(@items); $i++ ) {
if ( $self->{'doublemonths'} ) {
my $item = $items[$i];
my @param = $self->{'params'} ? @{ $self->{'params'}[$i] }: ();
+ push @param, 'project', $projecting;
my $value = $self->$item($speriod, $eperiod, $agentnum, @param);
push @{$data{data}->[$col]}, $value;
$item = $items[$i+1];
@param = $self->{'params'} ? @{ $self->{'params'}[++$i] }: ();
+ push @param, 'project', $projecting;
$value = $self->$item($speriod, $eperiod, $agentnum, @param);
push @{$data{data}->[$col++]}, $value;
}
else {
my $item = $items[$i];
my @param = $self->{'params'} ? @{ $self->{'params'}[$col] }: ();
+ push @param, 'project', $projecting;
my $value = $self->$item($speriod, $eperiod, $agentnum, @param);
push @{$data{data}->[$col++]}, $value;
}
@@ -132,6 +180,10 @@
$data{'indices'} = \@indices;
}
+ # clean up after ourselves
+ dbh->rollback;
+ # may be useful for debugging
+ #dbh->commit;
\%data;
}
More information about the freeside-commits
mailing list