summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/ClientAPI/MyAccount.pm7
-rw-r--r--FS/FS/UI/Web.pm36
-rw-r--r--FS/FS/UI/bytecount.pm94
-rw-r--r--FS/FS/part_pkg/flat.pm34
-rw-r--r--FS/FS/svc_acct.pm26
-rw-r--r--htetc/handler.pl1
-rw-r--r--httemplate/edit/process/prepay_credit.cgi6
-rwxr-xr-xhttemplate/edit/process/svc_acct.cgi2
-rw-r--r--httemplate/search/prepay_credit.html6
9 files changed, 136 insertions, 76 deletions
diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index bade103f2..ad73aaf55 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -9,6 +9,7 @@ use Business::CreditCard;
use Time::Duration;
use FS::CGI qw(small_custview); #doh
use FS::UI::Web;
+use FS::UI::bytecount;
use FS::Conf;
use FS::Record qw(qsearch qsearchs);
use FS::Msgcat qw(gettext);
@@ -402,11 +403,11 @@ sub process_prepay {
'seconds' => $seconds,
'duration' => duration_exact($seconds),
'upbytes' => $upbytes,
- 'upload' => FS::UI::Web::bytecount_unexact($upbytes),
+ 'upload' => FS::UI::bytecount::bytecount_unexact($upbytes),
'downbytes' => $downbytes,
- 'download' => FS::UI::Web::bytecount_unexact($downbytes),
+ 'download' => FS::UI::bytecount::bytecount_unexact($downbytes),
'totalbytes'=> $totalbytes,
- 'totalload' => FS::UI::Web::bytecount_unexact($totalbytes),
+ 'totalload' => FS::UI::bytecount::bytecount_unexact($totalbytes),
};
}
diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm
index 43c49354e..682dc31c5 100644
--- a/FS/FS/UI/Web.pm
+++ b/FS/FS/UI/Web.pm
@@ -181,42 +181,6 @@ sub parse_lt_gt {
}
-sub bytecount_unexact {
- my $bc = shift;
- return("$bc bytes")
- if ($bc < 1000);
- return(sprintf("%.2f Kbytes", $bc/1000))
- if ($bc < 1000000);
- return(sprintf("%.2f Mbytes", $bc/1000000))
- if ($bc < 1000000000);
- return(sprintf("%.2f Gbytes", $bc/1000000000));
-}
-
-sub parse_bytecount {
- my $bc = shift;
- return $bc if (($bc =~ tr/.//) > 1);
- $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
- my $base = $1;
- return $bc unless length $base;
- my $exponent = index ' kmgt', lc($2);
- return $bc if ($exponent < 0 && $2);
- $exponent = 0 if ($exponent < 0);
- return $base * 1024 ** $exponent;
-}
-
-sub display_bytecount {
- my $bc = shift;
- return $bc unless ($bc =~ /^(\d+)$/);
- my $conf = new FS::Conf;
- my $f = new Number::Format;
- my $precision = $conf->exists('datavolume-significantdigits')
- ? $conf->config('datavolume-significantdigits')
- : 3;
- my $unit = $conf->exists('datavolume-forcemegabytes') ? 'M' : 'A';
-
- return $f->format_bytes($bc, precision => $precision, unit => $unit);
-}
-
###
# cust_main report subroutines
###
diff --git a/FS/FS/UI/bytecount.pm b/FS/FS/UI/bytecount.pm
new file mode 100644
index 000000000..233082b08
--- /dev/null
+++ b/FS/FS/UI/bytecount.pm
@@ -0,0 +1,94 @@
+package FS::UI::bytecount;
+
+use strict;
+use vars qw($DEBUG $me);
+use FS::Conf;
+use Number::Format;
+
+$DEBUG = 0;
+$me = '[FS::UID::bytecount]';
+
+=head1 NAME
+
+FS::UI::bytecount - Subroutines for parsing and displaying byte counters
+
+=head1 SYNOPSIS
+
+ use FS::UI::bytecount;
+
+=head1 SUBROUTINES
+
+=over 4
+
+=item bytecount_unexact COUNT
+
+Returns a two decimal place value for COUNT followed by bytes, Kbytes, Mbytes,
+or GBytes as appropriate.
+
+=cut
+
+sub bytecount_unexact {
+ my $bc = shift;
+ return("$bc bytes")
+ if ($bc < 1000);
+ return(sprintf("%.2f Kbytes", $bc/1000))
+ if ($bc < 1000000);
+ return(sprintf("%.2f Mbytes", $bc/1000000))
+ if ($bc < 1000000000);
+ return(sprintf("%.2f Gbytes", $bc/1000000000));
+}
+
+=item parse_bytecount AMOUNT
+
+Accepts a number (digits and a decimal point) possibly followed by k, m, g, or
+t (and an optional 'b') in either case. Returns a pure number representing
+the input or the input itself if unparsable.
+
+=cut
+
+sub parse_bytecount {
+ my $bc = shift;
+ return $bc if (($bc =~ tr/.//) > 1);
+ $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
+ my $base = $1;
+ return $bc unless length $base;
+ my $exponent = index ' kmgt', lc($2);
+ return $bc if ($exponent < 0 && $2);
+ $exponent = 0 if ($exponent < 0);
+ return $base * 1024 ** $exponent;
+}
+
+=item display_bytecount AMOUNT
+
+Converts a pure number to a value followed possibly followed by k, m, g, or
+t via Number::Format
+
+=cut
+
+sub display_bytecount {
+ my $bc = shift;
+ return $bc unless ($bc =~ /^(\d+)$/);
+ my $conf = new FS::Conf;
+ my $f = new Number::Format;
+ my $precision = $conf->exists('datavolume-significantdigits')
+ ? $conf->config('datavolume-significantdigits')
+ : 3;
+ my $unit = $conf->exists('datavolume-forcemegabytes') ? 'M' : 'A';
+
+ return $f->format_bytes($bc, precision => $precision, unit => $unit);
+}
+
+=back
+
+=head1 BUGS
+
+Fly
+
+=head1 SEE ALSO
+
+L<Number::Format>
+
+=cut
+
+1;
+
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index f2b51c782..9f5e78446 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -3,7 +3,7 @@ package FS::part_pkg::flat;
use strict;
use vars qw(@ISA %info);
#use FS::Record qw(qsearch);
-use FS::UI::Web;
+use FS::UI::bytecount;
use FS::part_pkg;
@ISA = qw(FS::part_pkg);
@@ -29,43 +29,43 @@ use FS::part_pkg;
},
'upbytes' => { 'name' => 'Upload limit for this package',
'default' => '',
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes' => { 'name' => 'Download limit for this package',
'default' => '',
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes' => { 'name' => 'Transfer limit for this package',
'default' => '',
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_amount' => { 'name' => 'Cost of recharge for this package',
'default' => '',
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_seconds' => { 'name' => 'Recharge time for this package',
'default' => '',
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_upbytes' => { 'name' => 'Recharge upload for this package',
'default' => '',
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_downbytes' => { 'name' => 'Recharge download for this package',
'default' => '',
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package',
'default' => '',
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
},
'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit',
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index 53aa4e7e6..1e34ff03c 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -24,7 +24,7 @@ use FS::UID qw( datasrc );
use FS::Conf;
use FS::Record qw( qsearch qsearchs fields dbh dbdef );
use FS::Msgcat qw(gettext);
-use FS::UI::Web; #for {display,parse}_bytecount... perhaps not the best place?
+use FS::UI::bytecount;
use FS::svc_Common;
use FS::cust_svc;
use FS::part_svc;
@@ -278,22 +278,22 @@ sub table_info {
type => 'text',
disable_inventory => 1,
disable_select => 1,
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes' => { label => 'Download',
type => 'text',
disable_inventory => 1,
disable_select => 1,
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes'=> { label => 'Total up and download',
type => 'text',
disable_inventory => 1,
disable_select => 1,
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'seconds_threshold' => { label => 'Seconds',
type => 'text',
@@ -304,22 +304,22 @@ sub table_info {
type => 'text',
disable_inventory => 1,
disable_select => 1,
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'downbytes_threshold' => { label => 'Download',
type => 'text',
disable_inventory => 1,
disable_select => 1,
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
'totalbytes_threshold'=> { label => 'Total up and download',
type => 'text',
disable_inventory => 1,
disable_select => 1,
- 'format' => \&FS::UI::Web::display_bytecount,
- 'parse' => \&FS::UI::Web::parse_bytecount,
+ 'format' => \&FS::UI::bytecount::display_bytecount,
+ 'parse' => \&FS::UI::bytecount::parse_bytecount,
},
},
};
diff --git a/htetc/handler.pl b/htetc/handler.pl
index d46742544..755e664b9 100644
--- a/htetc/handler.pl
+++ b/htetc/handler.pl
@@ -128,6 +128,7 @@ sub handler
use FS::CGI qw(header menubar popurl rooturl table itable ntable idiot
eidiot small_custview myexit http_header);
use FS::UI::Web qw(svc_url);
+ use FS::UI::bytecount;
use FS::Msgcat qw(gettext geterror);
use FS::Misc qw( send_email send_fax states_hash counties state_label );
use FS::Report::Table::Monthly;
diff --git a/httemplate/edit/process/prepay_credit.cgi b/httemplate/edit/process/prepay_credit.cgi
index 6bf46bf7c..518f79d86 100644
--- a/httemplate/edit/process/prepay_credit.cgi
+++ b/httemplate/edit/process/prepay_credit.cgi
@@ -49,9 +49,9 @@
<% $hashref->{amount} ? sprintf('$%.2f', $hashref->{amount} ) : '' %>
<% $hashref->{amount} && $hashref->{seconds} ? 'and' : '' %>
<% $hashref->{seconds} ? duration_exact($hashref->{seconds}) : '' %>
- <% $hashref->{upbytes} ? FS::UI::Web::bytecount_unexact($hashref->{upbytes}) : '' %>
- <% $hashref->{downbytes} ? FS::UI::Web::bytecount_unexact($hashref->{downbytes}) : '' %>
- <% $hashref->{totalbytes} ? FS::UI::Web::bytecount_unexact($hashref->{totalbytes}) : '' %>
+ <% $hashref->{upbytes} ? FS::UI::bytecount::bytecount_unexact($hashref->{upbytes}) : '' %>
+ <% $hashref->{downbytes} ? FS::UI::bytecount::bytecount_unexact($hashref->{downbytes}) : '' %>
+ <% $hashref->{totalbytes} ? FS::UI::bytecount::bytecount_unexact($hashref->{totalbytes}) : '' %>
<br>
% }
diff --git a/httemplate/edit/process/svc_acct.cgi b/httemplate/edit/process/svc_acct.cgi
index 65ac5c176..a4a6c0015 100755
--- a/httemplate/edit/process/svc_acct.cgi
+++ b/httemplate/edit/process/svc_acct.cgi
@@ -25,7 +25,7 @@
%
%#unmunge bytecounts
%foreach (map { $_,$_."_threshold" } qw( upbytes downbytes totalbytes )) {
-% $cgi->param($_, FS::UI::Web::parse_bytecount($cgi->param($_)) );
+% $cgi->param($_, FS::UI::bytecount::parse_bytecount($cgi->param($_)) );
%}
%
%my %hash = $svcnum ? $old->hash : ();
diff --git a/httemplate/search/prepay_credit.html b/httemplate/search/prepay_credit.html
index ab6490d33..43fc6a96c 100644
--- a/httemplate/search/prepay_credit.html
+++ b/httemplate/search/prepay_credit.html
@@ -20,17 +20,17 @@
},
sub { my $c = shift;
$c->upbytes
- ? FS::UI::Web::bytecount_unexact($c->upbytes)
+ ? FS::UI::bytecount::bytecount_unexact($c->upbytes)
: ''
},
sub { my $c = shift;
$c->downbytes
- ? FS::UI::Web::bytecount_unexact($c->downbytes)
+ ? FS::UI::bytecount::bytecount_unexact($c->downbytes)
: ''
},
sub { my $c = shift;
$c->totalbytes
- ? FS::UI::Web::bytecount_unexact($c->totalbytes)
+ ? FS::UI::bytecount::bytecount_unexact($c->totalbytes)
: ''
},
sub { my $agent = shift->agent;