X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling.pm;h=f65d495cfdffbb3820d5816f2d8f2528ad1d3607;hp=f4c30ce63ba511e28215cc7af066aa0473ca7983;hb=7516e3da0f17eeecba27219ef96a8b5f46af2083;hpb=439d00a59c67a7d9d53b5d89c14ab332be16e38b diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm index f4c30ce63..f65d495cf 100644 --- a/FS/FS/cust_main/Billing.pm +++ b/FS/FS/cust_main/Billing.pm @@ -23,6 +23,7 @@ use FS::part_event_condition; use FS::pkg_category; use FS::cust_event_fee; use FS::Log; +use FS::TaxEngine; # 1 is mostly method/subroutine entry and options # 2 traces progress of some operations @@ -106,8 +107,9 @@ options of those methods are also available. sub bill_and_collect { my( $self, %options ) = @_; - my $log = FS::Log->new('bill_and_collect'); - $log->debug('start', object => $self, agentnum => $self->agentnum); + my $log = FS::Log->new('FS::cust_main::Billing::bill_and_collect'); + my %logopt = (object => $self); + $log->debug('start', %logopt); my $error; @@ -123,6 +125,7 @@ sub bill_and_collect { ); $job->update_statustext('0,cleaning expired packages') if $job; + $log->debug('canceling expired packages', %logopt); $error = $self->cancel_expired_pkgs( $actual_time ); if ( $error ) { $error = "Error expiring custnum ". $self->custnum. ": $error"; @@ -131,6 +134,7 @@ sub bill_and_collect { else { warn $error; } } + $log->debug('suspending adjourned packages', %logopt); $error = $self->suspend_adjourned_pkgs( $actual_time ); if ( $error ) { $error = "Error adjourning custnum ". $self->custnum. ": $error"; @@ -139,6 +143,7 @@ sub bill_and_collect { else { warn $error; } } + $log->debug('unsuspending resumed packages', %logopt); $error = $self->unsuspend_resumed_pkgs( $actual_time ); if ( $error ) { $error = "Error resuming custnum ".$self->custnum. ": $error"; @@ -148,6 +153,7 @@ sub bill_and_collect { } $job->update_statustext('20,billing packages') if $job; + $log->debug('billing packages', %logopt); $error = $self->bill( %options ); if ( $error ) { $error = "Error billing custnum ". $self->custnum. ": $error"; @@ -157,6 +163,7 @@ sub bill_and_collect { } $job->update_statustext('50,applying payments and credits') if $job; + $log->debug('applying payments and credits', %logopt); $error = $self->apply_payments_and_credits; if ( $error ) { $error = "Error applying custnum ". $self->custnum. ": $error"; @@ -165,10 +172,24 @@ sub bill_and_collect { else { warn $error; } } - $job->update_statustext('70,running collection events') if $job; - unless ( $conf->exists('cancelled_cust-noevents') - && ! $self->num_ncancelled_pkgs - ) { + # 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' }) + ) + { + warn "skipped collection for custnum ".$self->custnum. + " due to pending invoices\n" if $DEBUG; + } elsif ( $conf->exists('cancelled_cust-noevents') + && ! $self->num_ncancelled_pkgs ) + { + warn "skipped collection for custnum ".$self->custnum. + " because they have no active packages\n" if $DEBUG; + } else { + # run collection normally + $job->update_statustext('70,running collection events') if $job; + $log->debug('running collection events', %logopt); $error = $self->collect( %options ); if ( $error ) { $error = "Error collecting custnum ". $self->custnum. ": $error"; @@ -177,8 +198,9 @@ sub bill_and_collect { else { warn $error; } } } + $job->update_statustext('100,finished') if $job; - $log->debug('finish', object => $self, agentnum => $self->agentnum); + $log->debug('finish', %logopt); ''; @@ -329,6 +351,10 @@ An array ref of specific packages (objects) to attempt billing, instead trying a A hashref of pkgparts to exclude from this billing run (can also be specified as a comma-separated scalar). +=item no_prepaid + +Do not bill prepaid packages. Used by freeside-daily. + =item invoice_time Used in conjunction with the I