X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_acct.pm;h=be5a6d35eeeb3e03f913469836cf56e03a8efd56;hb=0dd05e9ff98263d2d42b419b1e278a5a3bc594b2;hp=a06f4d797eadd0aea698356c845e7fb6de11769f;hpb=fbfffdabe931d704aae420984058e61dc4196b01;p=freeside.git diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index a06f4d797..be5a6d35e 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -83,6 +83,7 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $smtpmachine = $conf->config('smtpmachine'); $radius_password = $conf->config('radius-password') || 'Password'; $radius_ip = $conf->config('radius-ip') || 'Framed-IP-Address'; + @pw_set = ( 'A'..'Z' ) if $conf->exists('password-generated-allcaps'); }; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @@ -272,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, + }, }, }; } @@ -608,6 +656,12 @@ sub delete { } } + my $error = $self->SUPER::delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + foreach my $radius_usergroup ( qsearch('radius_usergroup', { 'svcnum' => $self->svcnum } ) ) { @@ -618,12 +672,6 @@ sub delete { } } - my $error = $self->SUPER::delete; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; - } - $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; } @@ -1589,7 +1637,7 @@ sub _op_usage { if ( &{$op2condition{$op}}($self, $column, $amount) ) { foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { - if ($part_export->option('overlimit_groups')) { + if ($part_export->option('overlimit_groups'), 1) { my ($new,$old); my $other = new FS::svc_acct $self->hashref; my $groups = &{ $self->_fieldhandlers->{'usergroup'} } @@ -1601,6 +1649,7 @@ sub _op_usage { $new = $self; $old = $other; } my $error = $part_export->export_replace($new, $old); + $error ||= $self->overlimit($action); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "Error replacing radius groups in export, ${op}: $error"; @@ -1613,6 +1662,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); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "Error ${action}ing: $error"; @@ -1671,6 +1721,7 @@ sub set_usage { my $dbh = dbh; my $reset = 0; + my %handyhash = (); foreach my $field (keys %$valueref){ $reset = 1 if $valueref->{$field}; $self->setfield($field, $valueref->{$field}); @@ -1682,12 +1733,45 @@ sub set_usage { ) ) ); + $handyhash{$field} = $self->getfield($field); + $handyhash{$field.'_threshold'} = $self->getfield($field.'_threshold'); } - my $error = $self->replace; - die $error if $error; + #my $error = $self->replace; #NO! we avoid the call to ->check for + #die $error if $error; #services not explicity changed via the UI - if ( $conf->exists("svc_acct-usage_unsuspend") && $reset ) { - my $error = $self->cust_svc->cust_pkg->unsuspend; + my $sql = "UPDATE svc_acct SET " . + join (',', map { "$_ = ?" } (keys %handyhash) ). + " WHERE svcnum = ?"; + + warn "$me $sql\n" + if $DEBUG; + + 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); + die "Error executing $sql: ". $sth->errstr + unless defined($rv); + die "Can't update usage for svcnum ". $self->svcnum + if $rv == 0; + } + + 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); + } + } + + if ( $conf->exists("svc_acct-usage_unsuspend")) { + $error ||= $self->cust_svc->cust_pkg->unsuspend; + } if ( $error ) { $dbh->rollback if $oldAutoCommit; return "Error unsuspending: $error"; @@ -2386,7 +2470,6 @@ sub reached_threshold { my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list, - $svc_acct->email, ($opt{'to'} ? $opt{'to'} : ()) );