1 package FS::part_pkg::flat_introrate;
4 use vars qw(@ISA %info $DEBUG $me);
5 use FS::part_pkg::flat;
7 use Date::Manip qw(DateCalc UnixDate ParseDate);
9 @ISA = qw(FS::part_pkg::flat);
10 $me = '[' . __PACKAGE__ . ']';
14 'name' => 'Introductory price for X months, then flat rate,'.
15 'relative to setup date (anniversary billing)',
16 'shortname' => 'Anniversary, with intro price',
17 'inherit_fields' => [ 'flat', 'usage_Mixin', 'global_Mixin' ],
19 'intro_fee' => { 'name' => 'Introductory recurring fee for this package',
23 { 'name' => 'Duration of the introductory period, in number of months',
27 'fieldorder' => [ qw(intro_duration intro_fee) ],
32 my($self, $cust_pkg, $time ) = @_;
34 my $now = $time ? $$time : time;
36 my ($duration) = ($self->option('intro_duration') =~ /^(\d+)$/);
38 die "Invalid intro_duration: " . $self->option('intro_duration');
41 my $setup = &ParseDate('epoch ' . $cust_pkg->getfield('setup'));
42 my $intro_end = &DateCalc($setup, "+${duration} month");
45 warn "$me: \$duration = ${duration}" if $DEBUG;
46 warn "$me: \$intro_end = ${intro_end}" if $DEBUG;
47 warn "$me: $now < " . &UnixDate($intro_end, '%s') if $DEBUG;
49 if ($now < &UnixDate($intro_end, '%s')) {
50 $recur = $self->option('intro_fee');
52 $recur = $self->option('recur_fee');