X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fsvc_acct.pm;h=fc950fafa2732c973218a467036e02601d7b2cf5;hp=be5a6d35eeeb3e03f913469836cf56e03a8efd56;hb=eb4ff7f73c5d4bdf74a3472448b5a195598ff4cd;hpb=0dd05e9ff98263d2d42b419b1e278a5a3bc594b2 diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index be5a6d35e..fc950fafa 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -24,6 +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::bytecount; use FS::svc_Common; use FS::cust_svc; use FS::part_svc; @@ -277,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', @@ -303,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, }, }, }; @@ -778,7 +779,7 @@ sub replace { } } - $error = $new->SUPER::replace($old); + $error = $new->SUPER::replace($old, @_); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error if $error; @@ -844,7 +845,7 @@ Called by the suspend method of FS::cust_pkg (see L). sub suspend { my $self = shift; return "can't suspend system account" if $self->_check_system; - $self->SUPER::suspend; + $self->SUPER::suspend(@_); } =item unsuspend @@ -866,7 +867,7 @@ sub unsuspend { return $error if $error; } - $self->SUPER::unsuspend; + $self->SUPER::unsuspend(@_); } =item cancel @@ -897,7 +898,7 @@ sub cancel { } } - $self->SUPER::cancel; + $self->SUPER::cancel(@_); } @@ -1635,9 +1636,12 @@ sub _op_usage { my $action = $op2action{$op}; - if ( &{$op2condition{$op}}($self, $column, $amount) ) { + if ( &{$op2condition{$op}}($self, $column, $amount) && + ( $action eq 'suspend' && !$self->overlimit + || $action eq 'unsuspend' && $self->overlimit ) + ) { foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { - if ($part_export->option('overlimit_groups'), 1) { + if ($part_export->option('overlimit_groups')) { my ($new,$old); my $other = new FS::svc_acct $self->hashref; my $groups = &{ $self->_fieldhandlers->{'usergroup'} } @@ -1662,7 +1666,7 @@ sub _op_usage { && &{$op2condition{$op}}($self, $column, $amount) ) { #my $error = $self->$action(); my $error = $self->cust_svc->cust_pkg->$action(); - $error ||= $self->overlimit($action); + # $error ||= $self->overlimit($action); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "Error ${action}ing: $error"; @@ -1749,7 +1753,7 @@ sub set_usage { if (scalar(keys %handyhash)) { my $sth = $dbh->prepare( $sql ) or die "Error preparing $sql: ". $dbh->errstr; - my $rv = $sth->execute((grep{$_} values %handyhash), $self->svcnum); + my $rv = $sth->execute((values %handyhash), $self->svcnum); die "Error executing $sql: ". $sth->errstr unless defined($rv); die "Can't update usage for svcnum ". $self->svcnum @@ -1757,15 +1761,18 @@ sub set_usage { } if ( $reset ) { - my $error = $self->overlimit('unsuspend'); - - foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { - if ($part_export->option('overlimit_groups'), 1) { - my $old = new FS::svc_acct $self->hashref; - my $groups = &{ $self->_fieldhandlers->{'usergroup'} } - ($self, $part_export->option('overlimit_groups')); - $old->usergroup( $groups ); - $error ||= $part_export->export_replace($self, $old); + my $error; + + if ($self->overlimit) { + $error = $self->overlimit('unsuspend'); + foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { + if ($part_export->option('overlimit_groups')) { + my $old = new FS::svc_acct $self->hashref; + my $groups = &{ $self->_fieldhandlers->{'usergroup'} } + ($self, $part_export->option('overlimit_groups')); + $old->usergroup( $groups ); + $error ||= $part_export->export_replace($self, $old); + } } } @@ -2303,7 +2310,7 @@ sub send_email { =cut sub check_and_rebuild_fuzzyfiles { - my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc; -e "$dir/svc_acct.username" or &rebuild_fuzzyfiles; } @@ -2316,7 +2323,7 @@ sub rebuild_fuzzyfiles { use Fcntl qw(:flock); - my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc; #username @@ -2342,7 +2349,7 @@ sub rebuild_fuzzyfiles { =cut sub all_username { - my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc; open(USERNAMECACHE,"<$dir/svc_acct.username") or die "can't open $dir/svc_acct.username: $!"; my @array = map { chomp; $_; } ; @@ -2361,7 +2368,7 @@ sub append_fuzzyfiles { use Fcntl qw(:flock); - my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc; open(USERNAME,">>$dir/svc_acct.username") or die "can't open $dir/svc_acct.username: $!"; @@ -2484,8 +2491,12 @@ sub reached_threshold { 'last' => $cust_main->getfield('last'), 'pkg' => $cust_pkg->part_pkg->pkg, 'column' => $opt{'column'}, - 'amount' => $svc_acct->getfield($opt{'column'}), - 'threshold' => $threshold, + 'amount' => $opt{'column'} =~/bytes/ + ? FS::UI::bytecount::display_bytecount($svc_acct->getfield($opt{'column'})) + : $svc_acct->getfield($opt{'column'}), + 'threshold' => $opt{'column'} =~/bytes/ + ? FS::UI::bytecount::display_bytecount($threshold) + : $threshold, } );