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',
30 'upbytes' => { 'name' => 'Upload limit for this package',
32 'format' => \&FS::UI::Web::display_bytecount,
33 'parse' => \&FS::UI::Web::parse_bytecount,
35 'downbytes' => { 'name' => 'Download limit for this package',
37 'format' => \&FS::UI::Web::display_bytecount,
38 'parse' => \&FS::UI::Web::parse_bytecount,
40 'totalbytes' => { 'name' => 'Transfer limit for this package',
42 'format' => \&FS::UI::Web::display_bytecount,
43 'parse' => \&FS::UI::Web::parse_bytecount,
45 'recharge_amount' => { 'name' => 'Cost of recharge for this package',
47 'format' => \&FS::UI::Web::display_bytecount,
48 'parse' => \&FS::UI::Web::parse_bytecount,
50 'recharge_seconds' => { 'name' => 'Recharge time for this package',
52 'format' => \&FS::UI::Web::display_bytecount,
53 'parse' => \&FS::UI::Web::parse_bytecount,
55 'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
57 'format' => \&FS::UI::Web::display_bytecount,
58 'parse' => \&FS::UI::Web::parse_bytecount,
60 'recharge_downbytes' => { 'name' => 'Recharge download for this package',
62 'format' => \&FS::UI::Web::display_bytecount,
63 'parse' => \&FS::UI::Web::parse_bytecount,
65 'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package',
67 'format' => \&FS::UI::Web::display_bytecount,
68 'parse' => \&FS::UI::Web::parse_bytecount,
71 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit',
72 'seconds', 'upbytes', 'downbytes', 'totalbytes',
73 'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
74 'recharge_downbytes', 'recharge_totalbytes',
80 my($self, $cust_pkg, $sdate, $details ) = @_;
83 my $count = $self->option( 'additional_count', 'quiet' ) || 0;
85 push @$details, $self->option( 'additional_info' . $i++ );
88 $self->option('setup_fee');
92 my($self, $cust_pkg) = @_;
93 $self->reset_usage($cust_pkg);
94 $self->base_recur($cust_pkg);
98 my($self, $cust_pkg) = @_;
99 $self->option('recur_fee');
103 my ($self, $cust_pkg) = @_;
104 my $time = time; #should be able to pass this in for credit calculation
105 my $next_bill = $cust_pkg->getfield('bill') || 0;
106 my $last_bill = $cust_pkg->last_bill || 0;
107 return 0 if ! $self->base_recur
108 || ! $self->option('unused_credit', 1)
111 || $next_bill < $time;
114 'h' => 3600, # 60 * 60
115 'd' => 86400, # 60 * 60 * 24
116 'w' => 604800, # 60 * 60 * 24 * 7
117 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
120 $self->freq =~ /^(\d+)([hdwm]?)$/
121 or die 'unparsable frequency: '. $self->freq;
122 my $freq_sec = $1 * $sec{$2||'m'};
123 return 0 unless $freq_sec;
125 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
129 sub is_free_options {
130 qw( setup_fee recur_fee );
134 0; #no, we're postpaid
138 my($self, $cust_pkg) = @_;
139 my %values = map { $_, $self->option($_) }
140 grep { $self->option($_, 'hush') }
141 qw(seconds upbytes downbytes totalbytes);
142 $cust_pkg->set_usage(\%values);