X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fsqlradacct_hour.pm;h=79e64fbabfd0b6243498f96f25aa6219060a86fe;hb=b7cf1606a66cca95e3540f803ffa66d223f23a40;hp=a2b64c7409838ba1a9e744ab8ced7addc99cf6b7;hpb=fb4ab1073f0d15d660c6cdc4e07afebf68ef3924;p=freeside.git diff --git a/FS/FS/part_pkg/sqlradacct_hour.pm b/FS/FS/part_pkg/sqlradacct_hour.pm index a2b64c740..79e64fbab 100644 --- a/FS/FS/part_pkg/sqlradacct_hour.pm +++ b/FS/FS/part_pkg/sqlradacct_hour.pm @@ -7,8 +7,17 @@ use FS::part_pkg::flat; @ISA = qw(FS::part_pkg::flat); +# some constants to facilitate changes +# maybe we display charge per petabyte in the future? +use constant KB => 1024; +use constant MB => KB * 1024; +use constant GB => MB * 1024; +use constant BU => GB; # base unit +use constant BS => 'gigabyte'; # BU spelled out +use constant BA => 'gig'; # BU abbreviation + %info = ( - 'name' => 'Base charge plus per-hour (and for data) from an SQL RADIUS radacct table', + 'name' => 'Time and data charges from an SQL RADIUS radacct table', 'shortname' => 'Usage charges from RADIUS', 'inherit_fields' => [ 'global_Mixin' ], 'fields' => { @@ -24,11 +33,11 @@ use FS::part_pkg::flat; 'default' => 0, }, - 'recur_included_input' => { 'name' => 'Upload megabytes included', + 'recur_included_input' => { 'name' => 'Upload ' . BS . 's included', 'default' => 0, }, 'recur_input_charge' => { 'name' => - 'Additional charge per megabyte upload', + 'Additional charge per ' . BS . ' upload', 'default' => 0, }, 'recur_input_cap' => { 'name' => 'Maximum overage charge for upload'. @@ -36,11 +45,11 @@ use FS::part_pkg::flat; 'default' => 0, }, - 'recur_included_output' => { 'name' => 'Download megabytes included', + 'recur_included_output' => { 'name' => 'Download ' . BS . 's included', 'default' => 0, }, 'recur_output_charge' => { 'name' => - 'Additional charge per megabyte download', + 'Additional charge per ' . BS . ' download', 'default' => 0, }, 'recur_output_cap' => { 'name' => 'Maximum overage charge for download'. @@ -49,15 +58,15 @@ use FS::part_pkg::flat; }, 'recur_included_total' => { 'name' => - 'Total megabytes included', + 'Total ' . BS . 's included', 'default' => 0, }, 'recur_total_charge' => { 'name' => - 'Additional charge per megabyte total', + 'Additional charge per ' . BS . ' total', 'default' => 0, }, 'recur_total_cap' => { 'name' => 'Maximum overage charge for total'. - ' megabytes (0 means no cap)', + ' ' . BS . 's (0 means no cap)', 'default' => 0, }, @@ -68,14 +77,12 @@ use FS::part_pkg::flat; }, '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 )], - #'setup' => 'what.setup_fee.value', - #'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 ;\'', 'weight' => 40, ); sub price_info { my $self = shift; - my $str = $self->SUPER::price_info; + my $str = $self->SUPER::price_info(@_); $str .= " plus usage" if $str; $str; } @@ -91,12 +98,12 @@ sub calc_recur { my $input = $cust_pkg->attribute_since_sqlradacct( $last_bill, $$sdate, 'AcctInputOctets' ) - / 1048576; + / BU; my $output = $cust_pkg->attribute_since_sqlradacct( $last_bill, $$sdate, 'AcctOutputOctets' ) - / 1048576; + / BU; my $total = $input + $output - $self->option('recur_included_total'); $total = 0 if $total < 0; @@ -130,16 +137,16 @@ sub calc_recur { && $hourscharge > $self->option('recur_hourly_cap'); if ( $self->option('recur_total_charge') > 0 ) { - push @$details, "Last month's data ". - sprintf('%.1f', $total). " megs: $totalcharge"; + push @$details, + sprintf( "Last month's data %.3f %ss: %s", $total, BA, $totalcharge ); } if ( $self->option('recur_input_charge') > 0 ) { - push @$details, "Last month's download ". - sprintf('%.1f', $input). " megs: $inputcharge"; + push @$details, + sprintf( "Last month's download %.3f %ss: %s", $input, BA, $inputcharge ); } if ( $self->option('recur_output_charge') > 0 ) { - push @$details, "Last month's upload ". - sprintf('%.1f', $output). " megs: $outputcharge"; + push @$details, + sprintf( "Last month's upload %.3f %ss: %s", $output, BA, $outputcharge ); } if ( $self->option('recur_hourly_charge') > 0 ) { push @$details, "Last month\'s time ".