summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authormark <mark>2010-09-09 00:35:29 +0000
committermark <mark>2010-09-09 00:35:29 +0000
commit972250d54b5a8b3b071c878de27d2bc87e3222f1 (patch)
tree0ae7a1d925214345bd4b4cd861764699d2591f8b /FS/FS
parent532f8a5a544cb61b84828ca5a1b9043ca962dc6a (diff)
auto-adjourn option in flat packages, RT#9516
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/cust_pkg.pm17
-rw-r--r--FS/FS/part_pkg.pm24
-rw-r--r--FS/FS/part_pkg/flat.pm5
3 files changed, 23 insertions, 23 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index c27d458..e93476d 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 f278d5e..21ab975 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 d539e8d..18388d4 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,