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->reset_usage($cust_pkg);
47 $self->base_recur($cust_pkg);
51 my($self, $cust_pkg) = @_;
52 my $units = $cust_pkg->option('units') ? $cust_pkg->option('units') : 1 ;
53 # default to 1 if not found
55 ($self->option('recur_fee') * $units )
60 my ($self, $cust_pkg) = @_;
61 my $time = time; #should be able to pass this in for credit calculation
62 my $next_bill = $cust_pkg->getfield('bill') || 0;
63 my $last_bill = $cust_pkg->last_bill || 0;
64 return 0 if ! $self->base_recur
65 || ! $self->option('unused_credit', 1)
68 || $next_bill < $time;
71 'h' => 3600, # 60 * 60
72 'd' => 86400, # 60 * 60 * 24
73 'w' => 604800, # 60 * 60 * 24 * 7
74 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
77 $self->freq =~ /^(\d+)([hdwm]?)$/
78 or die 'unparsable frequency: '. $self->freq;
79 my $freq_sec = $1 * $sec{$2||'m'};
80 return 0 unless $freq_sec;
82 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
87 qw( setup_fee recur_fee );
91 0; #no, we're postpaid
95 my($self, $cust_pkg) = @_;
96 my %values = map { $_, $self->option($_) }
97 grep { $self->option($_, 'hush') }
98 qw(seconds upbytes downbytes totalbytes);
99 $cust_pkg->set_usage(\%values);