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',
26 'seconds' => { 'name' => 'Time limit for this package',
29 'upbytes' => { 'name' => 'Upload limit for this package',
31 'format' => \&FS::UI::Web::display_bytecount,
32 'parse' => \&FS::UI::Web::parse_bytecount,
34 'downbytes' => { 'name' => 'Download limit for this package',
36 'format' => \&FS::UI::Web::display_bytecount,
37 'parse' => \&FS::UI::Web::parse_bytecount,
39 'totalbytes' => { 'name' => 'Transfer limit for this package',
41 'format' => \&FS::UI::Web::display_bytecount,
42 'parse' => \&FS::UI::Web::parse_bytecount,
44 'recharge_amount' => { 'name' => 'Cost of recharge for this package',
46 'format' => \&FS::UI::Web::display_bytecount,
47 'parse' => \&FS::UI::Web::parse_bytecount,
49 'recharge_seconds' => { 'name' => 'Recharge time for this package',
51 'format' => \&FS::UI::Web::display_bytecount,
52 'parse' => \&FS::UI::Web::parse_bytecount,
54 'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
56 'format' => \&FS::UI::Web::display_bytecount,
57 'parse' => \&FS::UI::Web::parse_bytecount,
59 'recharge_downbytes' => { 'name' => 'Recharge download for this package',
61 'format' => \&FS::UI::Web::display_bytecount,
62 'parse' => \&FS::UI::Web::parse_bytecount,
64 'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package',
66 'format' => \&FS::UI::Web::display_bytecount,
67 'parse' => \&FS::UI::Web::parse_bytecount,
70 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit',
71 'seconds', 'upbytes', 'downbytes', 'totalbytes',
72 'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
73 'recharge_downbytes', 'recharge_totalbytes',
79 my($self, $cust_pkg, $sdate, $details ) = @_;
82 my $count = $self->option( 'additional_count', 'quiet' ) || 0;
84 push @$details, $self->option( 'additional_info' . $i++ );
87 $self->option('setup_fee');
91 my($self, $cust_pkg) = @_;
92 $self->reset_usage($cust_pkg);
93 $self->base_recur($cust_pkg);
97 my($self, $cust_pkg) = @_;
98 $self->option('recur_fee');
102 my ($self, $cust_pkg) = @_;
103 my $time = time; #should be able to pass this in for credit calculation
104 my $next_bill = $cust_pkg->getfield('bill') || 0;
105 my $last_bill = $cust_pkg->last_bill || 0;
106 return 0 if ! $self->base_recur
107 || ! $self->option('unused_credit', 1)
110 || $next_bill < $time;
113 'h' => 3600, # 60 * 60
114 'd' => 86400, # 60 * 60 * 24
115 'w' => 604800, # 60 * 60 * 24 * 7
116 'm' => 2629744, # 60 * 60 * 24 * 365.2422 / 12
119 $self->freq =~ /^(\d+)([hdwm]?)$/
120 or die 'unparsable frequency: '. $self->freq;
121 my $freq_sec = $1 * $sec{$2||'m'};
122 return 0 unless $freq_sec;
124 sprintf("%.2f", $self->base_recur * ( $next_bill - $time ) / $freq_sec );
128 sub is_free_options {
129 qw( setup_fee recur_fee );
133 0; #no, we're postpaid
137 my($self, $cust_pkg) = @_;
138 my %values = map { $_, $self->option($_) }
139 grep { $self->option($_, 'hush') }
140 qw(seconds upbytes downbytes totalbytes);
141 $cust_pkg->set_usage(\%values);