diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-08-09 19:38:07 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-08-09 19:38:07 -0700 |
commit | a8121357fa4c5215c19b17e2ed79ced4a7d9fa0b (patch) | |
tree | ad6fe7e1320c4738071d3c9992e37f46bf742d15 /FS/FS/cust_main.pm | |
parent | 66c62dfc4734fa278e7e28c5fda5c4061778dc14 (diff) |
optimize billing for customers with lots of existing packages and invoices, RT#30238
Diffstat (limited to 'FS/FS/cust_main.pm')
-rw-r--r-- | FS/FS/cust_main.pm | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 7d3185a22..cbf95f549 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -3777,9 +3777,17 @@ Returns all the payments (see L<FS::cust_pay>) for this customer. sub cust_pay { my $self = shift; - return $self->num_cust_pay unless wantarray; - sort { $a->_date <=> $b->_date } - qsearch( 'cust_pay', { 'custnum' => $self->custnum } ) + my $opt = ref($_[0]) ? shift : { @_ }; + + return $self->num_cust_pay unless wantarray || keys %$opt; + + $opt->{'table'} = 'cust_pay'; + $opt->{'hashref'}{'custnum'} = $self->custnum; + + map { $_ } #behavior of sort undefined in scalar context + sort { $a->_date <=> $b->_date } + qsearch($opt); + } =item num_cust_pay @@ -3797,6 +3805,22 @@ sub num_cust_pay { $sth->fetchrow_arrayref->[0]; } +=item unapplied_cust_pay + +Returns all the unapplied payments (see L<FS::cust_pay>) for this customer. + +=cut + +sub unapplied_cust_pay { + my $self = shift; + + $self->cust_pay( + 'extra_sql' => ' AND '. FS::cust_pay->unapplied_sql. ' > 0', + #@_ + ); + +} + =item cust_pay_pkgnum Returns all the payments (see L<FS::cust_pay>) for this customer's specific |