From: mark Date: Thu, 9 Sep 2010 00:35:29 +0000 (+0000) Subject: auto-adjourn option in flat packages, RT#9516 X-Git-Tag: TORRUS_1_0_9~323 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=972250d54b5a8b3b071c878de27d2bc87e3222f1 auto-adjourn option in flat packages, RT#9516 --- diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index c27d4587d..e93476dce 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -259,17 +259,12 @@ sub insert { $self->start_date( timelocal_nocheck(0,0,0,1,$mon,$year) ); } - my $expire_months = $self->part_pkg->option('expire_months', 1); - if ( $expire_months && !$self->expire ) { - my $start = $self->start_date || $self->setup || time; - - #false laziness w/part_pkg::add_freq - my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($start) )[0,1,2,3,4,5]; - $mon += $expire_months; - until ( $mon < 12 ) { $mon -= 12; $year++; } - - #$self->expire( timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year) ); - $self->expire( timelocal_nocheck(0,0,0,$mday,$mon,$year) ); + foreach my $action ( qw(expire adjourn) ) { + my $months = $self->part_pkg->option("${action}_months",1); + if($months and !$self->$action) { + my $start = $self->start_date || $self->setup || time; + $self->$action( $self->part_pkg->add_freq($start, $months) ); + } } local $SIG{HUP} = 'IGNORE'; diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index f278d5ebd..21ab97568 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -809,32 +809,34 @@ sub freq_pretty { } } -=item add_freq TIMESTAMP +=item add_freq TIMESTAMP [ FREQ ] -Adds the frequency of this package to the provided timestamp and returns -the resulting timestamp, or -1 if the frequency of this package could not be -parsed (shouldn't happen). +Adds a billing period of some frequency to the provided timestamp and +returns the resulting timestamp, or -1 if the frequency could not be +parsed (shouldn't happen). By default, the frequency of this package +will be used; to override this, pass a different frequency as a second +argument. =cut sub add_freq { - my( $self, $date ) = @_; - my $freq = $self->freq; + my( $self, $date, $freq ) = @_; + $freq = $self->freq if !defined($freq); #change this bit to use Date::Manip? CAREFUL with timezones (see # mailing list archive) my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($date) )[0,1,2,3,4,5]; - if ( $self->freq =~ /^\d+$/ ) { - $mon += $self->freq; + if ( $freq =~ /^\d+$/ ) { + $mon += $freq; until ( $mon < 12 ) { $mon -= 12; $year++; } - } elsif ( $self->freq =~ /^(\d+)w$/ ) { + } elsif ( $freq =~ /^(\d+)w$/ ) { my $weeks = $1; $mday += $weeks * 7; - } elsif ( $self->freq =~ /^(\d+)d$/ ) { + } elsif ( $freq =~ /^(\d+)d$/ ) { my $days = $1; $mday += $days; - } elsif ( $self->freq =~ /^(\d+)h$/ ) { + } elsif ( $freq =~ /^(\d+)h$/ ) { my $hours = $1; $hour += $hours; } else { diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index d539e8d1e..18388d4c8 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -115,6 +115,8 @@ tie my %temporalities, 'Tie::IxHash', #used in cust_pkg.pm so could add to any price plan 'expire_months' => { 'name' => 'Auto-add an expiration date this number of months out', }, + 'adjourn_months'=> { 'name' => 'Auto-add a suspension date this number of months out', + }, #used in cust_pkg.pm so could add to any price plan where it made sense 'start_1st' => { 'name' => 'Auto-add a start date to the 1st, ignoring the current month.', 'type' => 'checkbox', @@ -138,7 +140,8 @@ tie my %temporalities, 'Tie::IxHash', }, 'fieldorder' => [ qw( setup_fee recur_fee recur_temporality unused_credit - expire_months start_1st sync_bill_date + expire_months adjourn_months + start_1st sync_bill_date unsuspend_adjust_bill ), @usage_fieldorder, @usage_recharge_fieldorder,