break _bytecount subroutines out of FS::UI::Web
authorjeff <jeff>
Thu, 19 Apr 2007 23:30:41 +0000 (23:30 +0000)
committerjeff <jeff>
Thu, 19 Apr 2007 23:30:41 +0000 (23:30 +0000)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/UI/Web.pm
FS/FS/UI/bytecount.pm [new file with mode: 0644]
FS/FS/part_pkg/flat.pm
FS/FS/svc_acct.pm
htetc/handler.pl
httemplate/edit/process/prepay_credit.cgi
httemplate/edit/process/svc_acct.cgi
httemplate/search/prepay_credit.html

index bade103..ad73aaf 100644 (file)
@@ -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),
          };
 
 }
index 43c4935..682dc31 100644 (file)
@@ -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 (file)
index 0000000..233082b
--- /dev/null
@@ -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;
+
index f2b51c7..9f5e784 100644 (file)
@@ -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', 
index 53aa4e7..1e34ff0 100644 (file)
@@ -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,
                                  },
     },
   };
index d467425..755e664 100644 (file)
@@ -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;
index 6bf46bf..518f79d 100644 (file)
@@ -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>
 % } 
 
index 65ac5c1..a4a6c00 100755 (executable)
@@ -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 : ();
index ab6490d..43fc6a9 100644 (file)
                        },
                    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;