1 package FS::part_pkg::sqlradacct_hour;
4 use vars qw(@ISA %info);
5 #use FS::Record qw(qsearch qsearchs);
8 @ISA = qw(FS::part_pkg);
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 monthly charge for this package',
19 'recur_included_hours' => { 'name' => 'Hours included',
22 'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
25 'recur_included_input' => { 'name' => 'Upload megabytes included',
28 'recur_input_charge' => { 'name' =>
29 'Additional charge per megabyte upload',
32 'recur_included_output' => { 'name' => 'Download megabytes included',
35 'recur_output_charge' => { 'name' =>
36 'Additional charge per megabyte download',
39 'recur_included_total' => { 'name' =>
40 'Total megabytes included',
43 'recur_total_charge' => { 'name' =>
44 'Additional charge per megabyte total',
48 'fieldorder' => [qw( setup_fee recur_flat recur_included_hours recur_hourly_charge recur_included_input recur_input_charge recur_included_output recur_output_charge recur_included_total recur_total_charge )],
49 #'setup' => 'what.setup_fee.value',
50 #'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 ;\'',
55 my($self, $cust_pkg ) = @_;
56 $self->option('setup_fee');
60 my($self, $cust_pkg, $sdate, $details ) = @_;
62 my $last_bill = $cust_pkg->last_bill;
63 my $hours = $cust_pkg->seconds_since_sqlradacct($last_bill, $$sdate ) / 3600;
64 $hours -= $self->option('recur_included_hours');
65 $hours = 0 if $hours < 0;
67 my $input = $cust_pkg->attribute_since_sqlradacct( $last_bill,
72 my $output = $cust_pkg->attribute_since_sqlradacct( $last_bill,
77 my $total = $input + $output - $self->option('recur_included_total');
78 $total = 0 if $total < 0;
79 $input = $input - $self->option('recur_included_input');
80 $input = 0 if $input < 0;
81 $output = $output - $self->option('recur_included_output');
82 $output = 0 if $output < 0;
85 $total * sprintf('%.2f', $self->option('recur_total_charge'));
87 $input * sprintf('%.2f', $self->option('recur_input_charge'));
89 $output * sprintf('%.2f', $self->option('recur_output_charge'));
92 $hours * sprintf('%.2f', $self->option('recur_hourly_charge'));
94 if ( $self->option('recur_total_charge') > 0 ) {
95 push @$details, "Last month's data ".
96 sprintf('%.1f', $total). " megs: $totalcharge";
98 if ( $self->option('recur_input_charge') > 0 ) {
99 push @$details, "Last month's download ".
100 sprintf('%.1f', $input). " megs: $inputcharge";
102 if ( $self->option('recur_output_charge') > 0 ) {
103 push @$details, "Last month's upload ".
104 sprintf('%.1f', $output). " megs: $outputcharge";
106 if ( $self->option('recur_hourly_charge') > 0 ) {
107 push @$details, "Last month\'s time ".
108 sprintf('%.1f', $hours). " hours: $hourscharge";
111 $self->option('recur_flat')
112 + $hourscharge + $inputcharge + $outputcharge + $totalcharge;