summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorjeff <jeff>2007-04-19 23:30:41 +0000
committerjeff <jeff>2007-04-19 23:30:41 +0000
commit1748e50c012a65ecb729f15e09169f5d8122a3b1 (patch)
treeaedfbaafc7f921298a3065909cf7597ea245d18a /FS
parentdb4034e2019cb6c7f455640b89e8d5fedeb28932 (diff)
break _bytecount subroutines out of FS::UI::Web
Diffstat (limited to 'FS')
-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
5 files changed, 128 insertions, 69 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,
},
},
};