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)',
14 'setup_fee' => { 'name' => 'Setup fee for this package',
17 'recur_fee' => { 'name' => 'Recurring fee for this package',
20 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
21 ' of service at cancellation',
24 'externalid' => { 'name' => 'Optional External ID',
27 'seconds' => { 'name' => 'Time limit for this package',
29 'check' => sub { shift =~ /^\d*$/ },
31 'upbytes' => { 'name' => 'Upload limit for this package',
33 'check' => sub { shift =~ /^\d*$/ },
34 'format' => \&FS::UI::bytecount::display_bytecount,
35 'parse' => \&FS::UI::bytecount::parse_bytecount,
37 'downbytes' => { 'name' => 'Download limit for this package',
39 'check' => sub { shift =~ /^\d*$/ },
40 'format' => \&FS::UI::bytecount::display_bytecount,
41 'parse' => \&FS::UI::bytecount::parse_bytecount,
43 'totalbytes' => { 'name' => 'Transfer limit for this package',
45 'check' => sub { shift =~ /^\d*$/ },
46 'format' => \&FS::UI::bytecount::display_bytecount,
47 'parse' => \&FS::UI::bytecount::parse_bytecount,
49 'recharge_amount' => { 'name' => 'Cost of recharge for this package',
51 'check' => sub { shift =~ /^\d*(\.\d{2})?$/ },
53 'recharge_seconds' => { 'name' => 'Recharge time for this package',
55 'check' => sub { shift =~ /^\d*$/ },
57 'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
59 'check' => sub { shift =~ /^\d*$/ },
60 'format' => \&FS::UI::bytecount::display_bytecount,
61 'parse' => \&FS::UI::bytecount::parse_bytecount,
63 'recharge_downbytes' => { 'name' => 'Recharge download for this package',
65 'check' => sub { shift =~ /^\d*$/ },
66 'format' => \&FS::UI::bytecount::display_bytecount,
67 'parse' => \&FS::UI::bytecount::parse_bytecount,
69 'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package',
71 'check' => sub { shift =~ /^\d*$/ },
72 'format' => \&FS::UI::bytecount::display_bytecount,
73 'parse' => \&FS::UI::bytecount::parse_bytecount,
75 'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '.
76 ' over into current period',
80 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit',
81 'seconds', 'upbytes', 'downbytes', 'totalbytes',
82 'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
83 'recharge_downbytes', 'recharge_totalbytes',
84 'usage_rollover', 'externalid' ],
89 my($self, $cust_pkg, $sdate, $details ) = @_;
92 my $count = $self->option( 'additional_count', 'quiet' ) || 0;
94 push @$details, $self->option( 'additional_info' . $i++ );
97 $self->option('setup_fee');
101 my($self, $cust_pkg) = @_;
102 $self->base_recur($cust_pkg);
106 my($self, $cust_pkg) = @_;
107 $self->option('recur_fee', 1) || 0;
111 my ($self, $cust_pkg, %options) = @_;
114 if ($options{'time'}) {
115 $time = $options{'time'};
120 my $next_bill = $cust_pkg->getfield('bill') || 0;
121 my $last_bill = $cust_pkg->last_bill || 0;
122 return 0 if ! $self->base_recur
123 || ! $self->option('unused_credit', 1)
126 || $next_bill < $time;
129 'h' => 3600, # 60 * 60
130 'd' => 86400, # 60 * 60 * 24
131 'w' => 604800, # 60 * 60 * 24 * 7
132 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
135 $self->freq =~ /^(\d+)([hdwm]?)$/
136 or die 'unparsable frequency: '. $self->freq;
137 my $freq_sec = $1 * $sec{$2||'m'};
138 return 0 unless $freq_sec;
140 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
144 sub is_free_options {
145 qw( setup_fee recur_fee );
149 0; #no, we're postpaid
153 my($self, $cust_pkg) = @_;
154 my %values = map { $_, $self->option($_) }
155 grep { $self->option($_, 'hush') }
156 qw(seconds upbytes downbytes totalbytes);
157 if ($self->option('usage_rollover', 1)) {
158 $cust_pkg->recharge(\%values);
160 $cust_pkg->set_usage(\%values);