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',
23 'externalid' => { 'name' => 'Optional External ID',
27 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 'externalid' ],
32 my($self, $cust_pkg ) = @_;
33 $self->option('setup_fee');
38 $self->base_recur(@_);
42 my($self, $cust_pkg) = @_;
43 $self->option('recur_fee');
47 my ($self, $cust_pkg) = @_;
48 my $time = time; #should be able to pass this in for credit calculation
49 my $next_bill = $cust_pkg->getfield('bill') || 0;
50 my $last_bill = $cust_pkg->last_bill || 0;
51 return 0 if ! $self->base_recur
52 || ! $self->option('unused_credit', 1)
55 || $next_bill < $time;
58 'h' => 3600, # 60 * 60
59 'd' => 86400, # 60 * 60 * 24
60 'w' => 604800, # 60 * 60 * 24 * 7
61 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
64 $self->freq =~ /^(\d+)([hdwm]?)$/
65 or die 'unparsable frequency: '. $self->freq;
66 my $freq_sec = $1 * $sec{$2||'m'};
67 return 0 unless $freq_sec;
69 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
74 qw( setup_fee recur_fee );
78 0; #no, we're postpaid