1 package FS::part_pkg::sqlradacct_hour;
4 use vars qw(@ISA %info);
5 #use FS::Record qw(qsearch qsearchs);
6 use FS::part_pkg::flat;
8 @ISA = qw(FS::part_pkg::flat);
11 'name' => 'Base charge plus per-hour (and for data) from an SQL RADIUS radacct table',
12 'shortname' => 'Usage charges from RADIUS',
13 'inherit_fields' => [ 'global_Mixin' ],
15 'recur_included_hours' => { 'name' => 'Hours included',
18 'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
21 'recur_hourly_cap' => { 'name' => 'Maximum overage charge for hours'.
27 'recur_included_input' => { 'name' => 'Upload megabytes included',
30 'recur_input_charge' => { 'name' =>
31 'Additional charge per megabyte upload',
34 'recur_input_cap' => { 'name' => 'Maximum overage charge for upload'.
39 'recur_included_output' => { 'name' => 'Download megabytes included',
42 'recur_output_charge' => { 'name' =>
43 'Additional charge per megabyte download',
46 'recur_output_cap' => { 'name' => 'Maximum overage charge for download'.
51 'recur_included_total' => { 'name' =>
52 'Total megabytes included',
55 'recur_total_charge' => { 'name' =>
56 'Additional charge per megabyte total',
59 'recur_total_cap' => { 'name' => 'Maximum overage charge for total'.
60 ' megabytes (0 means no cap)',
64 'global_cap' => { 'name' => 'Global cap on all overage charges'.
70 'fieldorder' => [qw( recur_included_hours recur_hourly_charge recur_hourly_cap recur_included_input recur_input_charge recur_input_cap recur_included_output recur_output_charge recur_output_cap recur_included_total recur_total_charge recur_total_cap global_cap )],
71 #'setup' => 'what.setup_fee.value',
72 #'recur' => '\'my $last_bill = $cust_pkg->last_bill; my $hours = $cust_pkg->seconds_since_sqlradacct($last_bill, $sdate ) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; my $input = $cust_pkg->attribute_since_sqlradacct($last_bill, $sdate, \"AcctInputOctets\" ) / 1048576; my $output = $cust_pkg->attribute_since_sqlradacct($last_bill, $sdate, \"AcctOutputOctets\" ) / 1048576; my $total = $input + $output - \' + what.recur_included_total.value + \'; $total = 0 if $total < 0; my $input = $input - \' + what.recur_included_input.value + \'; $input = 0 if $input < 0; my $output = $output - \' + what.recur_included_output.value + \'; $output = 0 if $output < 0; my $totalcharge = sprintf(\"%.2f\", \' + what.recur_total_charge.value + \' * $total); my $inputcharge = sprintf(\"%.2f\", \' + what.recur_input_charge.value + \' * $input); my $outputcharge = sprintf(\"%.2f\", \' + what.recur_output_charge.value + \' * $output); my $hourscharge = sprintf(\"%.2f\", \' + what.recur_hourly_charge.value + \' * $hours); if ( \' + what.recur_total_charge.value + \' > 0 ) { push @details, \"Last month\\\'s data \". sprintf(\"%.1f\", $total). \" megs: \\\$$totalcharge\" } if ( \' + what.recur_input_charge.value + \' > 0 ) { push @details, \"Last month\\\'s download \". sprintf(\"%.1f\", $input). \" megs: \\\$$inputcharge\" } if ( \' + what.recur_output_charge.value + \' > 0 ) { push @details, \"Last month\\\'s upload \". sprintf(\"%.1f\", $output). \" megs: \\\$$outputcharge\" } if ( \' + what.recur_hourly_charge.value + \' > 0 ) { push @details, \"Last month\\\'s time \". sprintf(\"%.1f\", $hours). \" hours: \\\$$hourscharge\"; } \' + what.recur_fee.value + \' + $hourscharge + $inputcharge + $outputcharge + $totalcharge ;\'',
78 my $str = $self->SUPER::price_info;
79 $str .= " plus usage" if $str;
84 my($self, $cust_pkg, $sdate, $details ) = @_;
86 my $last_bill = $cust_pkg->last_bill;
87 my $hours = $cust_pkg->seconds_since_sqlradacct($last_bill, $$sdate ) / 3600;
88 $hours -= $self->option('recur_included_hours');
89 $hours = 0 if $hours < 0;
91 my $input = $cust_pkg->attribute_since_sqlradacct( $last_bill,
96 my $output = $cust_pkg->attribute_since_sqlradacct( $last_bill,
101 my $total = $input + $output - $self->option('recur_included_total');
102 $total = 0 if $total < 0;
103 $input = $input - $self->option('recur_included_input');
104 $input = 0 if $input < 0;
105 $output = $output - $self->option('recur_included_output');
106 $output = 0 if $output < 0;
109 sprintf('%.2f', $total * $self->option('recur_total_charge'));
110 $totalcharge = $self->option('recur_total_cap')
111 if $self->option('recur_total_cap')
112 && $totalcharge > $self->option('recur_total_cap');
115 sprintf('%.2f', $input * $self->option('recur_input_charge'));
116 $inputcharge = $self->option('recur_input_cap')
117 if $self->option('recur_input_cap')
118 && $inputcharge > $self->option('recur_input_cap');
121 sprintf('%.2f', $output * $self->option('recur_output_charge'));
122 $outputcharge = $self->option('recur_output_cap')
123 if $self->option('recur_output_cap')
124 && $outputcharge > $self->option('recur_output_cap');
127 sprintf('%.2f', $hours * $self->option('recur_hourly_charge'));
128 $hourscharge = $self->option('recur_hourly_cap')
129 if $self->option('recur_hourly_cap')
130 && $hourscharge > $self->option('recur_hourly_cap');
132 if ( $self->option('recur_total_charge') > 0 ) {
133 push @$details, "Last month's data ".
134 sprintf('%.1f', $total). " megs: $totalcharge";
136 if ( $self->option('recur_input_charge') > 0 ) {
137 push @$details, "Last month's download ".
138 sprintf('%.1f', $input). " megs: $inputcharge";
140 if ( $self->option('recur_output_charge') > 0 ) {
141 push @$details, "Last month's upload ".
142 sprintf('%.1f', $output). " megs: $outputcharge";
144 if ( $self->option('recur_hourly_charge') > 0 ) {
145 push @$details, "Last month\'s time ".
146 sprintf('%.1f', $hours). " hours: $hourscharge";
149 my $charges = $hourscharge + $inputcharge + $outputcharge + $totalcharge;
150 if ( $self->option('global_cap') && $charges > $self->option('global_cap') ) {
151 $charges = $self->option('global_cap');
152 push @$details, "Usage charges capped at: $charges";
155 $self->option('recur_fee') + $charges;
158 sub can_discount { 0; }
160 sub is_free_options {
161 qw( setup_fee recur_fee recur_hourly_charge
162 recur_input_charge recur_output_charge recur_total_charge );
166 my($self, $cust_pkg) = @_;
167 $self->option('recur_fee');