1 package FS::part_pkg::flat_introrate;
2 use base qw( FS::part_pkg::flat );
9 # mostly false laziness with FS::part_pkg::global_Mixin::validate_moneyn,
10 # except for blank string handling...
12 my ($option, $valref) = @_;
13 if ( $$valref eq '' ) {
15 } elsif ( $$valref =~ /^\s*(\d*)(\.\d{1})\s*$/ ) {
16 #handle one decimal place without barfing out
17 $$valref = ( ($1||''). ($2.'0') ) || 0;
18 } elsif ( $$valref =~ /^\s*(\d*)(\.\d{2})?\s*$/ ) {
19 $$valref = ( ($1||''). ($2||'') ) || 0;
21 return "Illegal (money) $option: ". $$valref;
27 my ($option, $valref) = @_;
28 $$valref = 0 unless $$valref;
29 return "Invalid $option"
30 unless ($$valref) = ($$valref =~ /^\s*(\d+)\s*$/);
35 'name' => 'Introductory price for X months, then flat rate,'.
36 'relative to setup date (anniversary billing)',
37 'shortname' => 'Anniversary, with intro price',
38 'inherit_fields' => [ 'flat', 'usage_Mixin', 'global_Mixin' ],
40 'intro_fee' => { 'name' => 'Introductory recurring fee for this package',
42 'validate' => \&validate_money,
45 { 'name' => 'Duration of the introductory period, in number of months',
47 'validate' => \&validate_number,
50 'fieldorder' => [ qw(intro_duration intro_fee) ],
55 my($self, $cust_pkg, $time ) = @_;
57 warn "flat_introrate base_recur requires date!" if !$time;
58 my $now = $time ? $$time : time;
60 my ($duration) = ($self->option('intro_duration') =~ /^\s*(\d+)\s*$/);
61 unless (length($duration)) {
62 my $log = FS::Log->new('FS::part_pkg');
63 $log->warning("Invalid intro_duration '".$self->option('intro_duration')."' on pkgpart ".$self->pkgpart
64 .", defaulting to 0, check package definition");
67 my $intro_end = $self->add_freq($cust_pkg->setup, $duration);
69 if ($now < $intro_end) {
70 return $self->option('intro_fee');
72 return $self->option('recur_fee');