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',
13 'setup_fee' => { 'name' => 'Setup fee for this package',
16 'recur_flat' => { 'name' => 'Base recurring fee for this package',
19 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
20 ' of service at cancellation',
24 'recur_included_hours' => { 'name' => 'Hours included',
27 'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
30 'recur_hourly_cap' => { 'name' => 'Maximum overage charge for hours'.
36 'recur_included_input' => { 'name' => 'Upload megabytes included',
39 'recur_input_charge' => { 'name' =>
40 'Additional charge per megabyte upload',
43 'recur_input_cap' => { 'name' => 'Maximum overage charge for upload'.
48 'recur_included_output' => { 'name' => 'Download megabytes included',
51 'recur_output_charge' => { 'name' =>
52 'Additional charge per megabyte download',
55 'recur_output_cap' => { 'name' => 'Maximum overage charge for download'.
60 'recur_included_total' => { 'name' =>
61 'Total megabytes included',
64 'recur_total_charge' => { 'name' =>
65 'Additional charge per megabyte total',
68 'recur_total_cap' => { 'name' => 'Maximum overage charge for total'.
69 ' megabytes (0 means no cap)',
73 'global_cap' => { 'name' => 'Global cap on all overage charges'.
79 'fieldorder' => [qw( setup_fee recur_flat unused_credit 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 )],
80 #'setup' => 'what.setup_fee.value',
81 #'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_flat.value + \' + $hourscharge + $inputcharge + $outputcharge + $totalcharge ;\'',
86 my($self, $cust_pkg, $sdate, $details ) = @_;
88 my $last_bill = $cust_pkg->last_bill;
89 my $hours = $cust_pkg->seconds_since_sqlradacct($last_bill, $$sdate ) / 3600;
90 $hours -= $self->option('recur_included_hours');
91 $hours = 0 if $hours < 0;
93 my $input = $cust_pkg->attribute_since_sqlradacct( $last_bill,
98 my $output = $cust_pkg->attribute_since_sqlradacct( $last_bill,
103 my $total = $input + $output - $self->option('recur_included_total');
104 $total = 0 if $total < 0;
105 $input = $input - $self->option('recur_included_input');
106 $input = 0 if $input < 0;
107 $output = $output - $self->option('recur_included_output');
108 $output = 0 if $output < 0;
111 $total * sprintf('%.2f', $self->option('recur_total_charge'));
112 $totalcharge = $self->option('recur_total_cap')
113 if $self->option('recur_total_cap')
114 && $totalcharge > $self->option('recur_total_cap');
117 $input * sprintf('%.2f', $self->option('recur_input_charge'));
118 $inputcharge = $self->option('recur_input_cap')
119 if $self->option('recur_input_cap')
120 && $inputcharge > $self->option('recur_input_cap');
123 $output * sprintf('%.2f', $self->option('recur_output_charge'));
124 $outputcharge = $self->option('recur_output_cap')
125 if $self->option('recur_output_cap')
126 && $outputcharge > $self->option('recur_output_cap');
129 $hours * sprintf('%.2f', $self->option('recur_hourly_charge'));
130 $hourscharge = $self->option('recur_hours_cap')
131 if $self->option('recur_hours_cap')
132 && $hourscharge > $self->option('recur_hours_cap');
134 if ( $self->option('recur_total_charge') > 0 ) {
135 push @$details, "Last month's data ".
136 sprintf('%.1f', $total). " megs: $totalcharge";
138 if ( $self->option('recur_input_charge') > 0 ) {
139 push @$details, "Last month's download ".
140 sprintf('%.1f', $input). " megs: $inputcharge";
142 if ( $self->option('recur_output_charge') > 0 ) {
143 push @$details, "Last month's upload ".
144 sprintf('%.1f', $output). " megs: $outputcharge";
146 if ( $self->option('recur_hourly_charge') > 0 ) {
147 push @$details, "Last month\'s time ".
148 sprintf('%.1f', $hours). " hours: $hourscharge";
151 my $charges = $hourscharge + $inputcharge + $outputcharge + $totalcharge;
152 if ( $self->option('global_cap') && $charges > $self->option('global_cap') ) {
153 $charges = $self->option('global_cap');
154 push @$details, "Usage charges capped at: $charges";
157 $self->option('recur_flat') + $charges;
160 sub is_free_options {
161 qw( setup_fee recur_flat recur_hourly_charge
162 recur_input_charge recur_output_charge recur_total_charge );
166 my($self, $cust_pkg) = @_;
167 $self->option('recur_flat');