diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Record.pm | 16 | ||||
-rw-r--r-- | FS/FS/svc_Tower_Mixin.pm | 39 | ||||
-rw-r--r-- | FS/FS/svc_acct.pm | 8 | ||||
-rwxr-xr-x | FS/FS/svc_broadband.pm | 13 |
4 files changed, 74 insertions, 2 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index a9d15cb25..d6c964278 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -3040,6 +3040,22 @@ sub scalar_sql { defined($scalar) ? $scalar : ''; } +=item count [ WHERE ] + +Convenience method for the common case of "SELECT COUNT(*) FROM table", +with optional WHERE. Must be called as method on a class with an +associated table. + +=cut + +sub count { + my($self, $where) = (shift, shift); + my $table = $self->table or die 'count called on object of class '.ref($self); + my $sql = "SELECT COUNT(*) FROM $table"; + $sql .= " WHERE $where" if $where; + $self->scalar_sql($sql); +} + =back =head1 SUBROUTINES diff --git a/FS/FS/svc_Tower_Mixin.pm b/FS/FS/svc_Tower_Mixin.pm index 8caef6dc8..0b5588466 100644 --- a/FS/FS/svc_Tower_Mixin.pm +++ b/FS/FS/svc_Tower_Mixin.pm @@ -14,4 +14,43 @@ sub tower_sector { qsearchs('tower_sector', { sectornum => $self->sectornum }); } +=item tower_sector_sql HASHREF + +Class method which returns a list of WHERE clause fragments to +search for services with tower/sector given by HASHREF. Can +contain 'towernum' and 'sectornum' keys, either of which can be +an arrayref or a single value. To use this, the search needs to +join to tower_sector. + +towernum or sectornum can also contain 'none' to allow null values. + +=cut + +sub tower_sector_sql { + my $class = shift; + my $params = shift; + return '' unless keys %$params; + my $where = ''; + + my @where; + for my $field (qw(towernum sectornum)) { + my $value = $params->{$field} or next; + if ( ref $value and grep { $_ } @$value ) { + my $in = join(',', map { /^(\d+)$/ ? $1 : () } @$value); + my @orwhere; + push @orwhere, "tower_sector.$field IN ($in)" if $in; + push @orwhere, "tower_sector.$field IS NULL" if grep /^none$/, @$value; + push @where, '( '.join(' OR ', @orwhere).' )'; + } + elsif ( $value =~ /^(\d+)$/ ) { + push @where, "tower_sector.$field = $1"; + } + elsif ( $value eq 'none' ) { + push @where, "tower_sector.$field IS NULL"; + } + } + @where; +} + + 1; diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 50553c5c7..201e8818e 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1462,7 +1462,7 @@ sub set_password { if ( !$encoding ) { # set encoding to system default ($encoding, $encryption) = - split(/-/, lc($conf->config('default-password-encoding'))); + split(/-/, lc($conf->config('default-password-encoding') || '')); $encoding ||= 'legacy'; $self->_password_encoding($encoding); } @@ -2846,6 +2846,9 @@ sub search { push @where, "svcpart = $1"; } + # sector and tower + my @where_sector = $class->tower_sector_sql($params); + push @where, @where_sector if @where_sector; # here is the agent virtualization #if ($params->{CurrentUser}) { @@ -2873,6 +2876,9 @@ sub search { ' LEFT JOIN cust_pkg USING ( pkgnum ) '. ' LEFT JOIN cust_main USING ( custnum ) '; + $addl_from .= ' LEFT JOIN tower_sector USING ( sectornum )' + if @where_sector; + my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql"; #if ( keys %svc_acct ) { # $count_query .= ' WHERE '. diff --git a/FS/FS/svc_broadband.pm b/FS/FS/svc_broadband.pm index a85fc5cb0..18514af19 100755 --- a/FS/FS/svc_broadband.pm +++ b/FS/FS/svc_broadband.pm @@ -4,7 +4,7 @@ use strict; use vars qw(@ISA $conf); use base qw(FS::svc_Radius_Mixin FS::svc_Tower_Mixin FS::svc_Common); -use NetAddr::IP; +{ no warnings 'redefine'; use NetAddr::IP; } use FS::Record qw( qsearchs qsearch dbh ); use FS::svc_Common; use FS::cust_svc; @@ -158,6 +158,10 @@ Parameters: =item routernum - arrayref +=item sectornum - arrayref + +=item towernum - arrayref + =item order_by =back @@ -214,6 +218,13 @@ sub search { push @where, "addr_block.routernum = $1"; } } + + #sector and tower, as above + my @where_sector = $class->tower_sector_sql($params); + if ( @where_sector ) { + push @where, @where_sector; + push @from, 'LEFT JOIN tower_sector USING ( sectornum )'; + } #svcnum if ( $params->{'svcnum'} =~ /^(\d+)$/ ) { |