summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Jackson <mitch@freeside.biz>2018-08-09 14:55:44 -0400
committerMitch Jackson <mitch@freeside.biz>2018-08-14 20:27:37 -0400
commitf81eebbe27a6acc0ae4284fa04b5525a41ae4570 (patch)
treecf34bc5793ca7bc4a32007c8278fc0d772a78c24
parent4c5f25435ed32c15a6c8078109b62654ff96797b (diff)
RT# 78547 bill_and_collect() small optimization
-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 3bffa3a59..ea524dae4 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -5414,6 +5414,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 9cf9b56c6..71d5c9b81 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')