RT#30820: Report not working
[freeside.git] / FS / FS / part_pkg / flat_introrate.pm
1 package FS::part_pkg::flat_introrate;
2 use base qw( FS::part_pkg::flat );
3
4 use strict;
5 use vars qw( %info );
6
7 use FS::Log;
8
9 %info = (
10   'name' => 'Introductory price for X months, then flat rate,'.
11             'relative to setup date (anniversary billing)',
12   'shortname' => 'Anniversary, with intro price',
13   'inherit_fields' => [ 'flat', 'usage_Mixin', 'global_Mixin' ],
14   'fields' => {
15     'intro_fee' => { 'name' => 'Introductory recurring fee for this package',
16                      'default' => 0,
17                    },
18     'intro_duration' =>
19          { 'name' => 'Duration of the introductory period, in number of months',
20            'default' => 0,
21          },
22   },
23   'fieldorder' => [ qw(intro_duration intro_fee) ],
24   'weight' => 14,
25 );
26
27 sub base_recur {
28   my($self, $cust_pkg, $time ) = @_;
29
30   warn "flat_introrate base_recur requires date!" if !$time;
31   my $now = $time ? $$time : time;
32
33   my ($duration) = ($self->option('intro_duration') =~ /^\s*(\d+)\s*$/);
34   unless (length($duration)) {
35     my $log = FS::Log->new('FS::part_pkg');
36     $log->warning("Invalid intro_duration '".$self->option('intro_duration')."' on pkgpart ".$self->pkgpart
37                 .", defaulting to 0, check package definition");
38     $duration = 0;
39   }
40   my $intro_end = $self->add_freq($cust_pkg->setup, $duration);
41
42   if ($now < $intro_end) {
43     return $self->option('intro_fee');
44   } else {
45     return $self->option('recur_fee');
46   }
47
48 }
49
50
51 1;