summaryrefslogtreecommitdiff
path: root/FS/FS/cust_bill_pkg.pm
diff options
context:
space:
mode:
authorivan <ivan>2011-11-14 20:36:00 +0000
committerivan <ivan>2011-11-14 20:36:00 +0000
commit2df6bb6be0b1acc2e5cc7271df62d81e2cd4b01e (patch)
tree07b9c267585938394992de61efaa6d20a84005cf /FS/FS/cust_bill_pkg.pm
parent3db061f538c06804bd0a52b9ef8be3dc6b6db82e (diff)
optimize invoice rendering with lots of CDRs, RT#15155
Diffstat (limited to 'FS/FS/cust_bill_pkg.pm')
-rw-r--r--FS/FS/cust_bill_pkg.pm25
1 files changed, 15 insertions, 10 deletions
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index adc09d7a7..9cc6e7cab 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -826,11 +826,10 @@ usage.
sub usage {
my( $self, $classnum ) = @_;
my $sum = 0;
- my @values = ();
if ( $self->get('details') ) {
- @values =
+ foreach my $value (
map { ref($_) eq 'HASH'
? $_->{'amount'}
: $_->[2]
@@ -843,20 +842,26 @@ sub usage {
: 1
)
}
- @{ $self->get('details') };
+ @{ $self->get('details') }
+ ) {
+ $sum += $value if $value;
+ }
+
+ return $sum;
} else {
- my $hashref = { 'billpkgnum' => $self->billpkgnum };
- $hashref->{ 'classnum' } = $classnum if defined($classnum);
- @values = map { $_->amount } qsearch('cust_bill_pkg_detail', $hashref);
+ my $sql = 'SELECT SUM(COALESCE(amount,0)) FROM cust_bill_pkg_detail '.
+ ' WHERE billpkgnum = '. $self->billpkgnum;
+ $sql .= " AND classnum = $classnum" if defined($classnum);
- }
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+
+ return $sth->fetchrow_arrayref->[0];
- foreach ( @values ) {
- $sum += $_ if $_;
}
- $sum;
+
}
=item usage_classes