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)',
17 'shortname' => 'Anniversary, with intro price',
19 'setup_fee' => { 'name' => 'Setup fee for this package',
22 'intro_fee' => { 'name' => 'Introductory recurring free for this package',
25 'intro_duration' => { 'name' => 'Duration of the introductory period, ' .
26 'in number of months',
29 'recur_fee' => { 'name' => 'Recurring fee for this package',
32 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
33 ' of service at cancellation',
37 'fieldorder' => [ 'setup_fee', 'intro_duration', 'intro_fee', 'recur_fee', 'unused_credit' ],
42 my($self, $cust_pkg, $time ) = @_;
44 my ($duration) = ($self->option('intro_duration') =~ /^(\d+)$/);
46 die "Invalid intro_duration: " . $self->option('intro_duration');
49 my $setup = &ParseDate('epoch ' . $cust_pkg->getfield('setup'));
50 my $intro_end = &DateCalc($setup, "+${duration} month");
53 warn $DEBUG_PRE . "\$duration = ${duration}" if $DEBUG;
54 warn $DEBUG_PRE . "\$intro_end = ${intro_end}" if $DEBUG;
55 warn $DEBUG_PRE . "$$time < " . &UnixDate($intro_end, '%s') if $DEBUG;
57 if ($$time < &UnixDate($intro_end, '%s')) {
58 $recur = $self->option('intro_fee');
60 $recur = $self->option('recur_fee');