summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-07-06 16:50:09 -0700
committerMark Wells <mark@freeside.biz>2013-07-06 17:06:47 -0700
commit90398f046915a915f65976e33ce060ac5baabbae (patch)
treefbf7f3702eabe8fe500584c13a7de7278727945e /FS
parentd3b736c3603a980b67f7c69242c94f6ad31a12a1 (diff)
delayed package start option, #20686
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Conf.pm7
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/cust_pkg.pm11
-rw-r--r--FS/FS/part_pkg.pm31
-rw-r--r--FS/FS/part_pkg/delayed_Mixin.pm12
5 files changed, 57 insertions, 5 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 10b2b810e..7534b4133 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4183,6 +4183,13 @@ and customer address. Include units.',
},
{
+ 'key' => 'part_pkg-delay_start',
+ 'section' => '',
+ 'description' => 'Enabled "delayed start" option for packages.',
+ 'type' => 'checkbox',
+ },
+
+ {
'key' => 'mcp_svcpart',
'section' => '',
'description' => 'Master Control Program svcpart. Leave this blank.',
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index d4e35ec58..cfacbfcf5 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1730,6 +1730,7 @@ sub tables_hashref {
'no_auto', 'char', 'NULL', 1, '', '',
'recur_show_zero', 'char', 'NULL', 1, '', '',
'setup_show_zero', 'char', 'NULL', 1, '', '',
+ 'delay_start', 'int', 'NULL', '', '', '',
],
'primary_key' => 'pkgpart',
'unique' => [],
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 308db5d9c..740a56274 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -269,6 +269,7 @@ sub insert {
my $part_pkg = $self->part_pkg;
+ # if the package def says to start only on the first of the month:
if ( $part_pkg->option('start_1st', 1) && !$self->start_date ) {
my ($sec,$min,$hour,$mday,$mon,$year) = (localtime(time) )[0,1,2,3,4,5];
$mon += 1 unless $mday == 1;
@@ -276,6 +277,8 @@ sub insert {
$self->start_date( timelocal_nocheck(0,0,0,1,$mon,$year) );
}
+ # set up any automatic expire/adjourn/contract_end timers
+ # based on the start date
foreach my $action ( qw(expire adjourn contract_end) ) {
my $months = $part_pkg->option("${action}_months",1);
if($months and !$self->$action) {
@@ -284,16 +287,16 @@ sub insert {
}
}
+ # if this package has "free days" and delayed setup fee, tehn
+ # set start date that many days in the future.
+ # (this should have been set in the UI, but enforce it here)
if ( ! $options{'change'}
&& ( my $free_days = $part_pkg->option('free_days',1) )
&& $part_pkg->option('delay_setup',1)
#&& ! $self->start_date
)
{
- my ($mday,$mon,$year) = (localtime(time) )[3,4,5];
- #my $start_date = ($self->start_date || timelocal(0,0,0,$mday,$mon,$year)) + 86400 * $free_days;
- my $start_date = timelocal(0,0,0,$mday,$mon,$year) + 86400 * $free_days;
- $self->start_date($start_date);
+ $self->start_date( $part_pkg->default_start_date );
}
$self->order_date(time);
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index 5424db5c0..8db0e9902 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -4,7 +4,7 @@ use strict;
use vars qw( @ISA %plans $DEBUG $setup_hack $skip_pkg_svc_hack );
use Carp qw(carp cluck confess);
use Scalar::Util qw( blessed );
-use Time::Local qw( timelocal_nocheck );
+use Time::Local qw( timelocal timelocal_nocheck );
use Tie::IxHash;
use FS::Conf;
use FS::Record qw( qsearch qsearchs dbh dbdef );
@@ -106,6 +106,8 @@ inherits from FS::Record. The following fields are currently supported:
=item fcc_voip_class - Which column of FCC form 477 part II.B this package
belongs in.
+=item delay_start - Number of days to delay package start, by default
+
=back
=head1 METHODS
@@ -577,6 +579,7 @@ sub check {
)
|| $self->ut_numbern('fcc_ds0s')
|| $self->ut_numbern('fcc_voip_class')
+ || $self->ut_numbern('delay_start')
|| $self->SUPER::check
;
return $error if $error;
@@ -866,10 +869,36 @@ sub is_free {
}
}
+# whether the plan allows discounts to be applied to this package
sub can_discount { 0; }
+# whether the plan allows changing the start date
sub can_start_date { 1; }
+# the default start date; takes an FS::cust_main as an argument
+sub default_start_date {
+ my $self = shift;
+ my $cust_main = shift;
+ my $conf = FS::Conf->new;
+
+ if ( $self->delay_start ) {
+ my $delay = $self->delay_start;
+
+ my ($mday,$mon,$year) = (localtime(time))[3,4,5];
+ my $start_date = timelocal(0,0,0,$mday,$mon,$year) + 86400 * $delay;
+ return $start_date;
+
+ } elsif ( $conf->exists('order_pkg-no_start_date') ) {
+
+ return ''
+
+ } else {
+
+ return $cust_main->next_bill_date;
+
+ }
+}
+
sub freqs_href {
# moved to FS::Misc to make this accessible to other packages
# at initialization
diff --git a/FS/FS/part_pkg/delayed_Mixin.pm b/FS/FS/part_pkg/delayed_Mixin.pm
index ab53bda06..ae286d351 100644
--- a/FS/FS/part_pkg/delayed_Mixin.pm
+++ b/FS/FS/part_pkg/delayed_Mixin.pm
@@ -2,6 +2,7 @@ package FS::part_pkg::delayed_Mixin;
use strict;
use vars qw(%info);
+use Time::Local qw(timelocal);
use NEXT;
%info = (
@@ -52,4 +53,15 @@ sub calc_remain {
sub can_start_date { ! shift->option('delay_setup', 1) }
+sub default_start_date {
+ my $self = shift;
+ if ( $self->option('delay_setup') and $self->option('free_days') ) {
+ my $delay = $self->option('free_days');
+
+ my ($mday, $mon, $year) = (localtime(time))[3,4,5];
+ return timelocal(0,0,0,$mday,$mon,$year) + 86400 * $self->option('free_days');
+ }
+ return $self->NEXT::default_start_date(@_);
+}
+
1;