summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2010-03-09 02:43:36 +0000
committerivan <ivan>2010-03-09 02:43:36 +0000
commit2b33f138c2a795a4e49967b2f4bcc13c56531087 (patch)
treeb09ee934b36e73fcc749fa32fa362543f09155e9
parente2d1089dbafcd25b58119a36a0c2a1dc9e609357 (diff)
a package that starts on the 1st and expires after N months, RT#7738
Notes
Notes: actually looks to be RT#7347
-rw-r--r--FS/FS/cust_pkg.pm21
-rw-r--r--FS/FS/part_pkg/flat.pm21
2 files changed, 37 insertions, 5 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index e47edde8c..609194dc7 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -6,6 +6,7 @@ use Carp qw(cluck);
use Scalar::Util qw( blessed );
use List::Util qw(max);
use Tie::IxHash;
+use Time::Local qw( timelocal_nocheck );
use MIME::Entity;
use FS::UID qw( getotaker dbh );
use FS::Misc qw( send_email );
@@ -543,6 +544,26 @@ sub check {
}
+ if ( $self->part_pkg->option('start_1st') && !$self->start_date ) {
+ my ($sec,$min,$hour,$mday,$mon,$year) = (localtime(time) )[0,1,2,3,4,5];
+ $mon += 1 unless $mday == 1;
+ until ( $mon < 12 ) { $mon -= 12; $year++; }
+ $self->start_date( timelocal_nocheck(0,0,0,1,$mon,$year) );
+ }
+
+ my $expire_months = $self->part_pkg->option('expire_months');
+ 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) );
+ }
+
$self->otaker(getotaker) unless $self->otaker;
$self->otaker =~ /^(\w{1,32})$/ or return "Illegal otaker";
$self->otaker($1);
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index b825dded6..e25c28c72 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -107,19 +107,30 @@ tie my %temporalities, 'Tie::IxHash',
'type' => 'select',
'select_options' => \%temporalities,
},
-
- %usage_fields,
- %usage_recharge_fields,
-
'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
' of service at cancellation',
'type' => 'checkbox',
},
+
+ #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',
+ },
+ #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',
+ },
+
+ %usage_fields,
+ %usage_recharge_fields,
+
'externalid' => { 'name' => 'Optional External ID',
'default' => '',
},
},
- 'fieldorder' => [ qw( setup_fee recur_fee recur_temporality unused_credit ),
+ 'fieldorder' => [ qw( setup_fee recur_fee
+ recur_temporality unused_credit
+ expire_months start_1st
+ ),
@usage_fieldorder, @usage_recharge_fieldorder,
qw( externalid ),
],