1 package FS::part_pkg::flat_introrate;
4 use vars qw(@ISA %info $DEBUG $me);
5 #use FS::Record qw(qsearch qsearchs);
6 use FS::part_pkg::flat;
8 use Date::Manip qw(DateCalc UnixDate ParseDate);
10 @ISA = qw(FS::part_pkg::flat);
11 $me = '[' . __PACKAGE__ . ']';
14 (%info) = (%FS::part_pkg::flat::info);
15 $info{name} = 'Introductory price for X months, then flat rate,'.
16 'relative to setup date (anniversary billing)';
17 $info{shortname} = 'Anniversary, with intro price';
18 $info{fields} = { %{$info{fields}} };
19 $info{fields}{intro_fee} =
20 { 'name' => 'Introductory recurring fee for this package',
23 $info{fields}{intro_duration} =
24 { 'name' => 'Duration of the introductory period, in number of months',
27 $info{fieldorder} = [ @{ $info{fieldorder} } ];
28 splice @{$info{fieldorder}}, 1, 0, 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');