use vars qw( %plans $DEBUG $setup_hack $skip_pkg_svc_hack );
use Carp qw(carp cluck confess);
use Scalar::Util qw( blessed );
-use Time::Local qw( timelocal timelocal_nocheck );
+use DateTime;
+use Time::Local qw( timelocal timelocal_nocheck ); # eventually replace with DateTime
use Tie::IxHash;
use FS::Conf;
use FS::Record qw( qsearch qsearchs dbh dbdef );
If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
values, the appropriate FS::pkg_svc records will be replaced. I<hidden_svc>
can be set to a hashref of svcparts and flag values ('Y' or '') to set the
-'hidden' field in these records.
+'hidden' field in these records. I<bulk_skip> can be set to a hashref of
+svcparts and flag values ('Y' or '') to set the 'bulk_skip' field in those
+records.
If I<primary_svc> is set to the svcpart of the primary service, the appropriate
FS::pkg_svc record will be updated.
warn " replacing pkg_svc records" if $DEBUG;
my $pkg_svc = $options->{'pkg_svc'};
my $hidden_svc = $options->{'hidden_svc'} || {};
+ my $bulk_skip = $options->{'bulk_skip'} || {};
if ( $pkg_svc ) { # if it wasn't passed, don't change existing pkg_svcs
foreach my $part_svc ( qsearch('part_svc', {} ) ) {
- my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
- my $hidden = $hidden_svc->{$part_svc->svcpart} || '';
+ my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
+ my $hidden = $hidden_svc->{$part_svc->svcpart} || '';
+ my $bulk_skip = $bulk_skip->{$part_svc->svcpart} || '';
my $primary_svc =
( defined($options->{'primary_svc'}) && $options->{'primary_svc'}
&& $options->{'primary_svc'} == $part_svc->svcpart
my $old_quantity = 0;
my $old_primary_svc = '';
my $old_hidden = '';
+ my $old_bulk_skip = '';
if ( $old_pkg_svc ) {
$old_quantity = $old_pkg_svc->quantity;
$old_primary_svc = $old_pkg_svc->primary_svc
if $old_pkg_svc->dbdef_table->column('primary_svc'); # is this needed?
$old_hidden = $old_pkg_svc->hidden;
+ $old_bulk_skip = $old_pkg_svc->old_bulk_skip;
}
- next unless $old_quantity != $quantity ||
- $old_primary_svc ne $primary_svc ||
- $old_hidden ne $hidden;
+ next unless $old_quantity != $quantity
+ || $old_primary_svc ne $primary_svc
+ || $old_hidden ne $hidden
+ || $old_bulk_skip ne $bulk_skip;
my $new_pkg_svc = new FS::pkg_svc( {
'pkgsvcnum' => ( $old_pkg_svc ? $old_pkg_svc->pkgsvcnum : '' ),
'quantity' => $quantity,
'primary_svc' => $primary_svc,
'hidden' => $hidden,
+ 'bulk_skip' => $bulk_skip,
} );
my $error = $old_pkg_svc
? $new_pkg_svc->replace($old_pkg_svc)
# 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 {
+# the delay start date if present
+sub delay_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 '';
+ my $delay = $self->delay_start or return '';
- } elsif ( $cust_main ) {
-
- return $cust_main->next_bill_date;
-
- } else {
-
- return '';
-
- }
+ # avoid timelocal silliness
+ my $dt = DateTime->today(time_zone => 'local');
+ $dt->add(days => $delay);
+ $dt->epoch;
}
sub can_currency_exchange { 0; }
$cust_bill_pkg->recur;
}
+=item unit_setup CUST_PKG
+
+Returns the setup fee for one unit of the package.
+
+=cut
+
+sub unit_setup {
+ my ($self, $cust_pkg) = @_;
+ $self->option('setup_fee') || 0;
+}
+
=item format OPTION DATA
Returns data formatted according to the function 'format' described