X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Finternal_diddb.pm;h=8771ae88327203173c7ebee37506772ef6a6f787;hp=a330cb0a6fb17e414022f044faa4fc49576618b6;hb=5372897f367498972c96f5494e142e6e11b29eb8;hpb=63a268637b2d51a8766412617724b9436439deb6 diff --git a/FS/FS/part_export/internal_diddb.pm b/FS/FS/part_export/internal_diddb.pm index a330cb0a6..8771ae883 100644 --- a/FS/FS/part_export/internal_diddb.pm +++ b/FS/FS/part_export/internal_diddb.pm @@ -17,10 +17,13 @@ tie my %options, 'Tie::IxHash', 'desc' => 'Provision phone numbers from the internal DID database', 'notes' => 'After adding the export, DIDs may be imported under Tools -> Importing -> Import phone numbers (DIDs)', 'options' => \%options, + 'no_machine' => 1, ); sub rebless { shift; } +sub can_get_dids { 1; } + sub get_dids { my $self = shift; my %opt = ref($_[0]) ? %{$_[0]} : @_; @@ -30,7 +33,20 @@ sub get_dids { 'svcnum' => '', ); - if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers + if ( $opt{'ratecenter'} && $opt{'state'} ) { + my $rc = $opt{ratecenter}; + $rc =~ s/, [A-Z][A-Z]$//g; + $hash{name} = $rc; + $hash{state} = $opt{state}; + + return [ map { $_->npa. '-'. $_->nxx. '-'. $_->station } + qsearch({ 'table' => 'phone_avail', + 'hashref' => \%hash, + 'order_by' => 'ORDER BY station', + }) + ]; + } + elsif ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers $hash{npa} = $opt{areacode}; $hash{nxx} = $opt{exchange}; @@ -42,11 +58,22 @@ sub get_dids { }) ]; - } elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX) + } elsif ( $opt{'areacode'} ) { $hash{npa} = $opt{areacode}; - return [ map { '('. $_->npa. '-'. $_->nxx. '-XXXX)' } + my @rc = qsearch({ 'select' => 'DISTINCT name, state', + 'table' => 'phone_avail', + 'hashref' => \%hash, + }); + + if(scalar(@rc)) { + my $first_phone_avail = $rc[0]; + return [ map { $_->get('name').", ".$_->state } @rc ] + if $first_phone_avail->get('name'); + } + + return [ map { '('. $_->npa. '-'. $_->nxx. '-XXXX)' } qsearch({ 'select' => 'DISTINCT npa, nxx', 'table' => 'phone_avail', 'hashref' => \%hash, @@ -54,7 +81,7 @@ sub get_dids { }) ]; - } elsif ( $opt{'state'} ) { #return aracodes + } elsif ( $opt{'state'} ) { #return areacodes $hash{state} = $opt{state}; @@ -67,7 +94,15 @@ sub get_dids { ]; } else { - die "FS::part_export::internal_diddb::get_dids called without options\n"; + + #die "FS::part_export::internal_diddb::get_dids called without options\n"; + return [ map { $_->npa. '-'. $_->nxx. '-'. $_->station } + qsearch({ 'table' => 'phone_avail', + 'hashref' => \%hash, + 'order_by' => 'ORDER BY station', + }) + ]; + } }