diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Conf.pm | 14 | ||||
-rw-r--r-- | FS/FS/UI/Web.pm | 26 | ||||
-rw-r--r-- | FS/FS/part_pkg.pm | 33 | ||||
-rw-r--r-- | FS/FS/part_pkg/flat.pm | 16 | ||||
-rw-r--r-- | FS/FS/part_svc.pm | 8 | ||||
-rw-r--r-- | FS/FS/svc_acct.pm | 47 | ||||
-rw-r--r-- | FS/bin/freeside-queued | 1 |
7 files changed, 143 insertions, 2 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 374b583..8bff460 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1755,6 +1755,20 @@ httemplate/docs/config.html 'type' => 'checkbox', }, + { + 'key' => 'datavolume-forcemegabytes', + 'section' => 'UI', + 'description' => 'All data volumes are expressed in megabytes', + 'type' => 'checkbox', + }, + + { + 'key' => 'datavolume-significantdigits', + 'section' => 'UI', + 'description' => 'number of significant digits to use to represent data volumes', + 'type' => 'text', + }, + ); 1; diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm index 9ddcf14..a05a667 100644 --- a/FS/FS/UI/Web.pm +++ b/FS/FS/UI/Web.pm @@ -4,6 +4,7 @@ use strict; use vars qw($DEBUG $me); use FS::Conf; use FS::Record qw(dbdef); +use Number::Format; #use vars qw(@ISA); #use FS::UI @@ -186,6 +187,31 @@ sub bytecount_unexact { 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/part_pkg.pm b/FS/FS/part_pkg.pm index 03222fa..3110c1c 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -817,6 +817,39 @@ sub plan_info { \%plans; } +=item format OPTION DATA + +Returns data formatted according to the function 'format' described +in the plan info. Returns DATA if no such function exists. + +=cut + +sub format { + my ($self, $option, $data) = (shift, shift, shift); + if (exists($plans{$self->plan}->{fields}->{$option}{format})) { + &{$plans{$self->plan}->{fields}->{$option}{format}}($data); + }else{ + $data; + } +} + +=item prase OPTION DATA + +Returns data parsed according to the function 'parse' described +in the plan info. Returns DATA if no such function exists. + +=cut + +sub parse { + my ($self, $option, $data) = (shift, shift, shift); + if (exists($plans{$self->plan}->{fields}->{$option}{parse})) { + &{$plans{$self->plan}->{fields}->{$option}{parse}}($data); + }else{ + $data; + } +} + + =back =head1 NEW PLAN CLASSES diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index 94b7d99..c0fbb5a 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -28,27 +28,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, }, 'downbytes' => { 'name' => 'Download limit for this package', 'default' => '', + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::parse_bytecount, }, 'totalbytes' => { 'name' => 'Transfer limit for this package', 'default' => '', + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::parse_bytecount, }, 'recharge_amount' => { 'name' => 'Cost of recharge for this package', 'default' => '', + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::parse_bytecount, }, 'recharge_seconds' => { 'name' => 'Recharge time for this package', 'default' => '', + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::parse_bytecount, }, 'recharge_upbytes' => { 'name' => 'Recharge upload for this package', 'default' => '', + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::parse_bytecount, }, 'recharge_downbytes' => { 'name' => 'Recharge download for this package', 'default' => '', + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::parse_bytecount, }, 'recharge_totalbytes' => { 'name' => 'Recharge transfer for this package', 'default' => '', + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::parse_bytecount, }, }, 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm index 5b4e54c..4fae457 100644 --- a/FS/FS/part_svc.pm +++ b/FS/FS/part_svc.pm @@ -145,9 +145,11 @@ sub insert { my $flag = $self->getfield($svcdb.'__'.$field.'_flag'); #if ( uc($flag) =~ /^([DFMAX])$/ ) { if ( uc($flag) =~ /^([A-Z])$/ ) { #part_svc_column will test it + my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse} + || sub { shift }; $part_svc_column->setfield('columnflag', $1); $part_svc_column->setfield('columnvalue', - $self->getfield($svcdb.'__'.$field) + &$parser($self->getfield($svcdb.'__'.$field)) ); if ( $previous ) { $error = $part_svc_column->replace($previous); @@ -264,9 +266,11 @@ sub replace { my $flag = $new->getfield($svcdb.'__'.$field.'_flag'); #if ( uc($flag) =~ /^([DFMAX])$/ ) { if ( uc($flag) =~ /^([A-Z])$/ ) { #part_svc_column will test it + my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse} + || sub { shift }; $part_svc_column->setfield('columnflag', $1); $part_svc_column->setfield('columnvalue', - $new->getfield($svcdb.'__'.$field) + &$parser($new->getfield($svcdb.'__'.$field)) ); if ( $previous ) { $error = $part_svc_column->replace($previous); diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 1ef2119..be5a6d3 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -273,6 +273,53 @@ sub table_info { disable_inventory => 1, disable_select => 1, }, + 'upbytes' => { label => 'Upload', + type => 'text', + disable_inventory => 1, + disable_select => 1, + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::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, + }, + '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, + }, + 'seconds_threshold' => { label => 'Seconds', + type => 'text', + disable_inventory => 1, + disable_select => 1, + }, + 'upbytes_threshold' => { label => 'Upload', + type => 'text', + disable_inventory => 1, + disable_select => 1, + 'format' => \&FS::UI::Web::display_bytecount, + 'parse' => \&FS::UI::Web::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, + }, + '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, + }, }, }; } diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 93d735d..b3128f0 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -9,6 +9,7 @@ use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm); use FS::Record qw(qsearch qsearchs); use FS::queue; use FS::queue_depend; +use FS::UI::Web; # no autoloading for non-FS classes... use Net::SSH 0.07; |