1 package FS::part_pkg::base_rate;
4 use vars qw(@ISA %info);
5 #use FS::Record qw(qsearch);
8 @ISA = qw(FS::part_pkg);
11 'name' => 'Base rate (anniversary billing, Times units ordered)',
13 'setup_fee' => { 'name' => 'Setup fee for this package',
16 'recur_fee' => { 'name' => 'Recurring Base fee for this package',
19 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
20 ' of service at cancellation',
23 'externalid' => { 'name' => 'Optional External ID',
27 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit',
33 my($self, $cust_pkg, $sdate, $details ) = @_;
36 my $count = $self->option( 'additional_count', 'quiet' ) || 0;
38 push @$details, $self->option( 'additional_info' . $i++ );
41 $self->option('setup_fee');
45 my($self, $cust_pkg) = @_;
46 $self->base_recur($cust_pkg);
50 my($self, $cust_pkg) = @_;
51 my $units = $cust_pkg->option('units') ? $cust_pkg->option('units') : 1 ;
52 # default to 1 if not found
54 ($self->option('recur_fee') * $units )
59 my ($self, $cust_pkg) = @_;
60 my $time = time; #should be able to pass this in for credit calculation
61 my $next_bill = $cust_pkg->getfield('bill') || 0;
62 my $last_bill = $cust_pkg->last_bill || 0;
63 return 0 if ! $self->base_recur
64 || ! $self->option('unused_credit', 1)
67 || $next_bill < $time;
70 'h' => 3600, # 60 * 60
71 'd' => 86400, # 60 * 60 * 24
72 'w' => 604800, # 60 * 60 * 24 * 7
73 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
76 $self->freq =~ /^(\d+)([hdwm]?)$/
77 or die 'unparsable frequency: '. $self->freq;
78 my $freq_sec = $1 * $sec{$2||'m'};
79 return 0 unless $freq_sec;
81 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
86 qw( setup_fee recur_fee );
90 0; #no, we're postpaid