stray closing /TABLE in the no-ticket case
[freeside.git] / FS / FS / svc_Tower_Mixin.pm
index 6adbc6f..d677679 100644 (file)
@@ -1,19 +1,9 @@
 package FS::svc_Tower_Mixin;
 
 use strict;
-use FS::Record qw(qsearchs); #qsearch;
-use FS::tower_sector;
 
 =item tower_sector
 
-=cut
-
-sub tower_sector {
-  my $self = shift;
-  return '' unless $self->sectornum;
-  qsearchs('tower_sector', { sectornum => $self->sectornum });
-}
-
 =item tower_sector_sql HASHREF
 
 Class method which returns a list of WHERE clause fragments to 
@@ -27,19 +17,23 @@ 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( $class, $params ) = @_;
+  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;
+      if ( grep /^none$/, @$value ) {
+        # then allow this field to be null
+        push @orwhere, "tower_sector.$field IS NULL";
+        # and if this field is the sector, also allow the default sector
+        # on the tower
+        push @orwhere, "sectorname = '_default'" if $field eq 'sectornum';
+      }
       push @where, '( '.join(' OR ', @orwhere).' )';
     }
     elsif ( $value =~ /^(\d+)$/ ) {