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 my $quantity = $cust_pkg->quantity || 1;
104 sprintf("%.2f", $quantity * $self->unit_setup($cust_pkg, $sdate, $details) );
108 my($self, $cust_pkg, $sdate, $details ) = @_;
110 $self->option('setup_fee');
114 my($self, $cust_pkg) = @_;
115 $self->base_recur($cust_pkg);
119 my($self, $cust_pkg) = @_;
120 $self->option('recur_fee', 1) || 0;
124 my ($self, $cust_pkg, %options) = @_;
127 if ($options{'time'}) {
128 $time = $options{'time'};
133 my $next_bill = $cust_pkg->getfield('bill') || 0;
134 my $last_bill = $cust_pkg->last_bill || 0;
135 return 0 if ! $self->base_recur
136 || ! $self->option('unused_credit', 1)
139 || $next_bill < $time;
142 'h' => 3600, # 60 * 60
143 'd' => 86400, # 60 * 60 * 24
144 'w' => 604800, # 60 * 60 * 24 * 7
145 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
148 $self->freq =~ /^(\d+)([hdwm]?)$/
149 or die 'unparsable frequency: '. $self->freq;
150 my $freq_sec = $1 * $sec{$2||'m'};
151 return 0 unless $freq_sec;
153 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
157 sub is_free_options {
158 qw( setup_fee recur_fee );
162 0; #no, we're postpaid
166 my($self, $cust_pkg, %opt) = @_;
167 warn " resetting usage counters" if $opt{debug} > 1;
168 my %values = map { $_, $self->option($_) }
169 grep { $self->option($_, 'hush') }
170 qw(seconds upbytes downbytes totalbytes);
171 if ($self->option('usage_rollover', 1)) {
172 $cust_pkg->recharge(\%values);
174 $cust_pkg->set_usage(\%values);