summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorMitch Jackson <mitch@freeside.biz>2018-08-09 14:55:44 -0400
committerMitch Jackson <mitch@freeside.biz>2018-09-19 00:42:00 -0400
commitd1dfa92834944079595def7f1ba2d62b2f30243b (patch)
treeb12fd28c5f037f931227a41691e580c1c57a350d /FS/FS
parent7b326a5bd5550034f98086ef7df1884c9cf72bb7 (diff)
RT# 78547 bill_and_collect() small optimization
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/cust_main.pm10
-rw-r--r--FS/FS/cust_main/Billing.pm8
2 files changed, 13 insertions, 5 deletions
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 22d0dcc..64b002b 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -5694,6 +5694,16 @@ sub process_bill_and_collect {
$cust_main->bill_and_collect( %$param );
}
+=item pending_invoice_count
+
+Return number of cust_bill with pending=Y for this customer
+
+=cut
+
+sub pending_invoice_count {
+ FS::cust_bill->count( 'custnum = '.shift->custnum."AND pending = 'Y'" );
+}
+
#starting to take quite a while for big dbs
# (JRNL: journaled so it only happens once per database)
# - seq scan of h_cust_main (yuck), but not going to index paycvv, so
diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm
index 9cf9b56..71d5c9b 100644
--- a/FS/FS/cust_main/Billing.pm
+++ b/FS/FS/cust_main/Billing.pm
@@ -1,6 +1,7 @@
package FS::cust_main::Billing;
use strict;
+use feature 'state';
use vars qw( $conf $DEBUG $me );
use Carp;
use Data::Dumper;
@@ -170,11 +171,8 @@ sub bill_and_collect {
# In a batch tax environment, do not run collection if any pending
# invoices were created. Collection will run after the next tax batch.
- my $tax = FS::TaxEngine->new;
- if ( $tax->info->{batch} and
- qsearch('cust_bill', { custnum => $self->custnum, pending => 'Y' })
- )
- {
+ state $is_batch_tax = FS::TaxEngine->new->info->{batch} ? 1 : 0;
+ if ( $is_batch_tax && $self->pending_invoice_count ) {
warn "skipped collection for custnum ".$self->custnum.
" due to pending invoices\n" if $DEBUG;
} elsif ( $conf->exists('cancelled_cust-noevents')