[freeside-commits] freeside/FS/FS/Report/Table Monthly.pm, 1.17, 1.17.2.1
Ivan,,,
ivan at wavetail.420.am
Thu Dec 3 11:06:54 PST 2009
Update of /home/cvs/cvsroot/freeside/FS/FS/Report/Table
In directory wavetail.420.am:/tmp/cvs-serv22947/FS/FS/Report/Table
Modified Files:
Tag: FREESIDE_1_9_BRANCH
Monthly.pm
Log Message:
average per cust_pkg option for peter
Index: Monthly.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Report/Table/Monthly.pm,v
retrieving revision 1.17
retrieving revision 1.17.2.1
diff -u -d -r1.17 -r1.17.2.1
--- Monthly.pm 24 Aug 2009 05:09:26 -0000 1.17
+++ Monthly.pm 3 Dec 2009 19:06:52 -0000 1.17.2.1
@@ -331,11 +331,15 @@
$agentnum ||= $opt{'agentnum'};
- my $usage = cust_bill_pkg_detail(@_);
+ my $total_sql =
+ " SELECT COALESCE( SUM(cust_bill_pkg.setup + cust_bill_pkg.recur), 0 ) ";
- my $total = $self->scalar_sql("
- SELECT SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)
- FROM cust_bill_pkg
+ $total_sql .=
+ " / CASE COUNT(cust_pkg.*) WHEN 0 THEN 1 ELSE COUNT(cust_pkg.*) END "
+ if $opt{average_per_cust_pkg};
+
+ $total_sql .=
+ " FROM cust_bill_pkg
LEFT JOIN cust_bill USING ( invnum )
LEFT JOIN cust_main USING ( custnum )
LEFT JOIN cust_pkg USING ( pkgnum )
@@ -343,15 +347,16 @@
LEFT JOIN part_pkg AS override ON pkgpart_override = override.pkgpart
WHERE pkgnum != 0
AND $where
- AND ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
- );
+ AND ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum);
if ($opt{use_usage} && $opt{use_usage} eq 'recurring') {
+ my $total = $self->scalar_sql($total_sql);
+ my $usage = cust_bill_pkg_detail(@_); #$speriod, $eperiod, $agentnum, %opt
return $total-$usage;
} elsif ($opt{use_usage} && $opt{use_usage} eq 'usage') {
- return $usage;
+ return cust_bill_pkg_detail(@_); #$speriod, $eperiod, $agentnum, %opt
} else {
- return $total;
+ return $self->scalar_sql($total_sql);
}
}
@@ -391,9 +396,14 @@
my $where = join( ' AND ', @where );
- $self->scalar_sql("
- SELECT SUM(amount)
- FROM cust_bill_pkg_detail
+ my $total_sql = " SELECT SUM(amount) ";
+
+ $total_sql .=
+ " / CASE COUNT(cust_pkg.*) WHEN 0 THEN 1 ELSE COUNT(cust_pkg.*) END "
+ if $opt{average_per_cust_pkg};
+
+ $total_sql .=
+ " FROM cust_bill_pkg_detail
LEFT JOIN cust_bill_pkg USING ( billpkgnum )
LEFT JOIN cust_bill ON cust_bill_pkg.invnum = cust_bill.invnum
LEFT JOIN cust_main USING ( custnum )
@@ -401,8 +411,9 @@
LEFT JOIN part_pkg USING ( pkgpart )
LEFT JOIN part_pkg AS override ON pkgpart_override = override.pkgpart
WHERE $where
- AND ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
- );
+ AND ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum);
+
+ $self->scalar_sql($total_sql);
}
More information about the freeside-commits
mailing list