X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Finternal_diddb.pm;h=a94e43e2824723569012fcc43fc98e38e192231d;hb=09df4e8790fe3ed8e233d2c198ea524465c0096e;hp=c30d858ac555007f544b2c5a4b65b8602ac0071c;hpb=e3c53b20ac5a7e120562bbd259a19707e9c11cb5;p=freeside.git diff --git a/FS/FS/part_export/internal_diddb.pm b/FS/FS/part_export/internal_diddb.pm index c30d858ac..a94e43e28 100644 --- a/FS/FS/part_export/internal_diddb.pm +++ b/FS/FS/part_export/internal_diddb.pm @@ -30,7 +30,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 +55,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, @@ -100,7 +124,7 @@ sub _export_insert { #link phone_avail to svcnum sub _export_delete { #unlink phone_avail from svcnum my( $self, $svc_phone ) = (shift, shift); - $svc_phone =~ /^(\d{3})(\d{3})(\d+)$/ + $svc_phone->phonenum =~ /^(\d{3})(\d{3})(\d+)$/ or return "unparsable phone number: ". $svc_phone->phonenum; my( $npa, $nxx, $station ) = ($1, $2, $3);