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)',
12 # XXX it multiplies recurring fee by cust_pkg option "units", how to
14 'shortname' => 'Bulk (manual from "units" option)',
16 'setup_fee' => { 'name' => 'Setup fee for this package',
19 'recur_fee' => { 'name' => 'Recurring Base fee for this package',
22 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
23 ' of service at cancellation',
26 'externalid' => { 'name' => 'Optional External ID',
30 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit',
36 my($self, $cust_pkg, $sdate, $details ) = @_;
39 my $count = $self->option( 'additional_count', 'quiet' ) || 0;
41 push @$details, $self->option( 'additional_info' . $i++ );
44 $self->option('setup_fee');
48 my($self, $cust_pkg) = @_;
49 $self->base_recur($cust_pkg);
53 my($self, $cust_pkg) = @_;
54 my $units = $cust_pkg->option('units') ? $cust_pkg->option('units') : 1 ;
55 # default to 1 if not found
57 ($self->option('recur_fee') * $units )
62 my ($self, $cust_pkg) = @_;
63 my $time = time; #should be able to pass this in for credit calculation
64 my $next_bill = $cust_pkg->getfield('bill') || 0;
65 my $last_bill = $cust_pkg->last_bill || 0;
66 return 0 if ! $self->base_recur
67 || ! $self->option('unused_credit', 1)
70 || $next_bill < $time;
73 'h' => 3600, # 60 * 60
74 'd' => 86400, # 60 * 60 * 24
75 'w' => 604800, # 60 * 60 * 24 * 7
76 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
79 $self->freq =~ /^(\d+)([hdwm]?)$/
80 or die 'unparsable frequency: '. $self->freq;
81 my $freq_sec = $1 * $sec{$2||'m'};
82 return 0 unless $freq_sec;
84 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
89 qw( setup_fee recur_fee );
93 0; #no, we're postpaid