1 package FS::part_pkg::flat;
4 use vars qw(@ISA %info);
5 #use FS::Record qw(qsearch);
9 @ISA = qw(FS::part_pkg);
12 'name' => 'Flat rate (anniversary billing)',
13 'shortname' => 'Anniversary',
15 'setup_fee' => { 'name' => 'Setup fee for this package',
18 'recur_fee' => { 'name' => 'Recurring fee for this package',
21 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
22 ' of service at cancellation',
25 'externalid' => { 'name' => 'Optional External ID',
28 'seconds' => { 'name' => 'Time limit for this package',
30 'check' => sub { shift =~ /^\d*$/ },
32 'upbytes' => { 'name' => 'Upload limit for this package',
34 'check' => sub { shift =~ /^\d*$/ },
35 'format' => \&FS::UI::bytecount::display_bytecount,
36 'parse' => \&FS::UI::bytecount::parse_bytecount,
38 'downbytes' => { 'name' => 'Download limit for this package',
40 'check' => sub { shift =~ /^\d*$/ },
41 'format' => \&FS::UI::bytecount::display_bytecount,
42 'parse' => \&FS::UI::bytecount::parse_bytecount,
44 'totalbytes' => { 'name' => 'Transfer limit for this package',
46 'check' => sub { shift =~ /^\d*$/ },
47 'format' => \&FS::UI::bytecount::display_bytecount,
48 'parse' => \&FS::UI::bytecount::parse_bytecount,
50 'recharge_amount' => { 'name' => 'Cost of recharge for this package',
52 'check' => sub { shift =~ /^\d*(\.\d{2})?$/ },
54 'recharge_seconds' => { 'name' => 'Recharge time for this package',
56 'check' => sub { shift =~ /^\d*$/ },
58 'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
60 'check' => sub { shift =~ /^\d*$/ },
61 'format' => \&FS::UI::bytecount::display_bytecount,
62 'parse' => \&FS::UI::bytecount::parse_bytecount,
64 'recharge_downbytes' => { 'name' => 'Recharge download for this package',
66 'check' => sub { shift =~ /^\d*$/ },
67 'format' => \&FS::UI::bytecount::display_bytecount,
68 'parse' => \&FS::UI::bytecount::parse_bytecount,
70 'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package',
72 'check' => sub { shift =~ /^\d*$/ },
73 'format' => \&FS::UI::bytecount::display_bytecount,
74 'parse' => \&FS::UI::bytecount::parse_bytecount,
76 'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '.
77 ' over into current period',
80 'recharge_reset' => { 'name' => 'Reset usage to these values on manual '.
85 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit',
86 'seconds', 'upbytes', 'downbytes', 'totalbytes',
87 'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
88 'recharge_downbytes', 'recharge_totalbytes',
89 'usage_rollover', 'recharge_reset', 'externalid' ],
94 my($self, $cust_pkg, $sdate, $details ) = @_;
97 my $count = $self->option( 'additional_count', 'quiet' ) || 0;
99 push @$details, $self->option( 'additional_info' . $i++ );
102 $self->option('setup_fee');
106 my($self, $cust_pkg) = @_;
107 $self->base_recur($cust_pkg);
111 my($self, $cust_pkg) = @_;
112 $self->option('recur_fee', 1) || 0;
116 my ($self, $cust_pkg, %options) = @_;
119 if ($options{'time'}) {
120 $time = $options{'time'};
125 my $next_bill = $cust_pkg->getfield('bill') || 0;
126 my $last_bill = $cust_pkg->last_bill || 0;
127 return 0 if ! $self->base_recur
128 || ! $self->option('unused_credit', 1)
131 || $next_bill < $time;
134 'h' => 3600, # 60 * 60
135 'd' => 86400, # 60 * 60 * 24
136 'w' => 604800, # 60 * 60 * 24 * 7
137 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
140 $self->freq =~ /^(\d+)([hdwm]?)$/
141 or die 'unparsable frequency: '. $self->freq;
142 my $freq_sec = $1 * $sec{$2||'m'};
143 return 0 unless $freq_sec;
145 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
149 sub is_free_options {
150 qw( setup_fee recur_fee );
154 0; #no, we're postpaid
158 my($self, $cust_pkg) = @_;
159 my %values = map { $_, $self->option($_) }
160 grep { $self->option($_, 'hush') }
161 qw(seconds upbytes downbytes totalbytes);
162 if ($self->option('usage_rollover', 1)) {
163 $cust_pkg->recharge(\%values);
165 $cust_pkg->set_usage(\%values);