1 package FS::part_pkg::flat;
4 use vars qw(@ISA %info);
5 #use FS::Record qw(qsearch);
8 @ISA = qw(FS::part_pkg);
11 'name' => 'Flat rate (anniversary billing)',
13 'setup_fee' => { 'name' => 'Setup fee for this package',
16 'recur_fee' => { 'name' => 'Recurring fee for this package',
19 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
20 ' of service at cancellation',
24 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit' ],
25 #'setup' => 'what.setup_fee.value',
26 #'recur' => 'what.recur_fee.value',
31 my($self, $cust_pkg ) = @_;
32 $self->option('setup_fee');
37 $self->base_recur(@_);
41 my($self, $cust_pkg) = @_;
42 $self->option('recur_fee');
46 my ($self, $cust_pkg) = @_;
47 my $time = time; #should be able to pass this in for credit calculation
48 my $next_bill = $cust_pkg->getfield('bill') || 0;
49 my $last_bill = $cust_pkg->last_bill || 0;
50 return 0 if ! $self->base_recur
51 || ! $self->option('unused_credit', 1)
54 || $next_bill < $time;
57 'h' => 3600, # 60 * 60
58 'd' => 86400, # 60 * 60 * 24
59 'w' => 604800, # 60 * 60 * 24 * 7
60 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
63 $self->freq =~ /^(\d+)([hdwm]?)$/
64 or die 'unparsable frequency: '. $self->freq;
65 my $freq_sec = $1 * $sec{$2||'m'};
66 return 0 unless $freq_sec;
68 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
73 qw( setup_fee recur_fee );
77 0; #no, we're postpaid