This commit was generated by cvs2svn to compensate for changes in r9232,
[freeside.git] / FS / FS / part_pkg / flat_introrate.pm
1 package FS::part_pkg::flat_introrate;
2
3 use strict;
4 use vars qw(@ISA %info $DEBUG $me);
5 #use FS::Record qw(qsearch qsearchs);
6 use FS::part_pkg::flat;
7
8 use Date::Manip qw(DateCalc UnixDate ParseDate);
9
10 @ISA = qw(FS::part_pkg::flat);
11 $me = '[' . __PACKAGE__ . ']';
12 $DEBUG = 0;
13
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',
21                      'default' => 0,
22          };
23 $info{fields}{intro_duration} =
24          { 'name' => 'Duration of the introductory period, in number of months',
25            'default' => 0,
26          };
27 $info{fieldorder} = [ @{ $info{fieldorder} } ];
28 splice @{$info{fieldorder}}, 1, 0, qw( intro_duration intro_fee );
29 $info{weight} = 14;
30
31 sub base_recur {
32   my($self, $cust_pkg, $time ) = @_;
33
34   my $now = $time ? $$time : time;
35
36   my ($duration) = ($self->option('intro_duration') =~ /^(\d+)$/);
37   unless ($duration) {
38     die "Invalid intro_duration: " . $self->option('intro_duration');
39   }
40
41   my $setup = &ParseDate('epoch ' . $cust_pkg->getfield('setup'));
42   my $intro_end = &DateCalc($setup, "+${duration} month");
43   my $recur;
44
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;
48
49   if ($now < &UnixDate($intro_end, '%s')) {
50     $recur = $self->option('intro_fee');
51   } else {
52     $recur = $self->option('recur_fee');
53   }
54
55   $recur;
56
57 }
58
59
60 1;