1 package FS::part_pkg::flat_introrate;
4 use vars qw(@ISA %info $DEBUG $DEBUG_PRE);
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);
12 $DEBUG_PRE = '[' . __PACKAGE__ . ']: ';
15 'name' => 'Introductory price for X months, then flat rate,'.
16 'relative to setup date (anniversary billing)',
18 'setup_fee' => { 'name' => 'Setup fee for this package',
21 'intro_fee' => { 'name' => 'Introductory recurring free for this package',
24 'intro_duration' => { 'name' => 'Duration of the introductory period, ' .
25 'in number of months',
28 'recur_fee' => { 'name' => 'Recurring fee for this package',
31 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
32 ' of service at cancellation',
36 'fieldorder' => [ 'setup_fee', 'intro_duration', 'intro_fee', 'recur_fee', 'unused_credit' ],
41 my($self, $cust_pkg, $time ) = @_;
43 my ($duration) = ($self->option('intro_duration') =~ /^(\d+)$/);
45 die "Invalid intro_duration: " . $self->option('intro_duration');
48 my $setup = &ParseDate('epoch ' . $cust_pkg->getfield('setup'));
49 my $intro_end = &DateCalc($setup, "+${duration} month");
52 warn $DEBUG_PRE . "\$duration = ${duration}" if $DEBUG;
53 warn $DEBUG_PRE . "\$intro_end = ${intro_end}" if $DEBUG;
54 warn $DEBUG_PRE . "$$time < " . &UnixDate($intro_end, '%s') if $DEBUG;
56 if ($$time < &UnixDate($intro_end, '%s')) {
57 $recur = $self->option('intro_fee');
59 $recur = $self->option('recur_fee');