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::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 monthly charge for this package',
19 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
20 ' of service at cancellation',
23 'recur_included_hours' => { 'name' => 'Hours included',
26 'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
29 'recur_included_input' => { 'name' => 'Upload megabytes included',
32 'recur_input_charge' => { 'name' =>
33 'Additional charge per megabyte upload',
36 'recur_included_output' => { 'name' => 'Download megabytes included',
39 'recur_output_charge' => { 'name' =>
40 'Additional charge per megabyte download',
43 'recur_included_total' => { 'name' =>
44 'Total megabytes included',
47 'recur_total_charge' => { 'name' =>
48 'Additional charge per megabyte total',
52 'fieldorder' => [qw( setup_fee recur_flat unused_credit recur_included_hours recur_hourly_charge recur_included_input recur_input_charge recur_included_output recur_output_charge recur_included_total recur_total_charge )],
53 #'setup' => 'what.setup_fee.value',
54 #'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 ;\'',
59 my($self, $cust_pkg, $sdate, $details ) = @_;
61 my $last_bill = $cust_pkg->last_bill;
62 my $hours = $cust_pkg->seconds_since_sqlradacct($last_bill, $$sdate ) / 3600;
63 $hours -= $self->option('recur_included_hours');
64 $hours = 0 if $hours < 0;
66 my $input = $cust_pkg->attribute_since_sqlradacct( $last_bill,
71 my $output = $cust_pkg->attribute_since_sqlradacct( $last_bill,
76 my $total = $input + $output - $self->option('recur_included_total');
77 $total = 0 if $total < 0;
78 $input = $input - $self->option('recur_included_input');
79 $input = 0 if $input < 0;
80 $output = $output - $self->option('recur_included_output');
81 $output = 0 if $output < 0;
84 $total * sprintf('%.2f', $self->option('recur_total_charge'));
86 $input * sprintf('%.2f', $self->option('recur_input_charge'));
88 $output * sprintf('%.2f', $self->option('recur_output_charge'));
91 $hours * sprintf('%.2f', $self->option('recur_hourly_charge'));
93 if ( $self->option('recur_total_charge') > 0 ) {
94 push @$details, "Last month's data ".
95 sprintf('%.1f', $total). " megs: $totalcharge";
97 if ( $self->option('recur_input_charge') > 0 ) {
98 push @$details, "Last month's download ".
99 sprintf('%.1f', $input). " megs: $inputcharge";
101 if ( $self->option('recur_output_charge') > 0 ) {
102 push @$details, "Last month's upload ".
103 sprintf('%.1f', $output). " megs: $outputcharge";
105 if ( $self->option('recur_hourly_charge') > 0 ) {
106 push @$details, "Last month\'s time ".
107 sprintf('%.1f', $hours). " hours: $hourscharge";
110 $self->option('recur_flat')
111 + $hourscharge + $inputcharge + $outputcharge + $totalcharge;
114 sub is_free_options {
115 qw( setup_fee recur_flat recur_hourly_charge
116 recur_input_charge recur_output_charge recur_total_charge );
120 my($self, $cust_pkg) = @_;
121 $self->option('recur_flat');