X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Finternal_diddb.pm;fp=FS%2FFS%2Fpart_export%2Finternal_diddb.pm;h=5e14873673e76de548c14ebbb039bbc046b52cc2;hb=dcc553538ede04c0783bc92d3942c905c29131c1;hp=0000000000000000000000000000000000000000;hpb=f9befdcb5ce8cf5dc5b9cacb6fe04ce29ed3cb80;p=freeside.git diff --git a/FS/FS/part_export/internal_diddb.pm b/FS/FS/part_export/internal_diddb.pm new file mode 100644 index 000000000..5e1487367 --- /dev/null +++ b/FS/FS/part_export/internal_diddb.pm @@ -0,0 +1,126 @@ +package FS::part_export::internal_diddb; + +use vars qw(@ISA %info); +#use Tie::IxHash; +use FS::Record qw(qsearch qsearchs); +use FS::part_export; +use FS::phone_avail; + +@ISA = qw(FS::part_export); + +%info = ( + 'svc' => 'svc_phone', + '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)', +); + +sub rebless { shift; } + +sub get_dids { + my $self = shift; + my %opt = ref($_[0]) ? %{$_[0]} : @_; + + my %hash = ( 'countrycode' => 1, #XXX make an option or something + 'exportnum' => $self->exportnum, + 'svcnum' => '', + ); + + if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers + + $hash{npa} = $opt{areacode}; + $hash{nxx} = $opt{exchange}; + + return [ map { $_->npa. '-'. $_->nxx. '-'. $_->station } + qsearch({ 'table' => 'phone_avail', + 'hashref' => \%hash, + 'order_by' => 'ORDER BY station', + }) + ]; + + } elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX) + + $hash{npa} = $opt{areacode}; + + return [ map { '('. $_->npa. '-'. $_->nxx. '-XXXX)' } + qsearch({ 'select' => 'DISTINCT npa, nxx', + 'table' => 'phone_avail', + 'hashref' => \%hash, + 'order_by' => 'ORDER BY nxx', + }) + ]; + + } elsif ( $opt{'state'} ) { #return aracodes + + $hash{state} = $opt{state}; + + return [ map { $_->npa } + qsearch({ 'select' => 'DISTINCT npa', + 'table' => 'phone_avail', + 'hashref' => \%hash, + 'order_by' => 'ORDER BY npa', + }) + ]; + + } else { + die "FS::part_export::internal_diddb::get_dids called without options\n"; + } + +} + +sub _export_insert { #link phone_avail to svcnum + my( $self, $svc_phone ) = (shift, shift); + + $svc_phone =~ /^(\d{3})(\d{3})(\d+)$/ + or return "unparsable phone number: ". $svc_phone->phonenum; + my( $npa, $nxx, $station ) = ($1, $2, $3); + + my $phone_avail = qsearchs('phone_avail', { + 'countrycode' => 1, #XXX make an option or something + 'exportnum' => $self->exportnum, + 'svcnum' => '', + 'npa' => $npa, + 'nxx' => $nxx, + 'station' => $station, + }); + + return "number not available: ". $svc_phone->phonenum + unless $phone_avail; + + $phone_avail->svcnum($svc_phone->svcnum); + + $phone_avail->replace; + +} + +sub _export_delete { #unlink phone_avail from svcnum + my( $self, $svc_phone ) = (shift, shift); + + $svc_phone =~ /^(\d{3})(\d{3})(\d+)$/ + or return "unparsable phone number: ". $svc_phone->phonenum; + my( $npa, $nxx, $station ) = ($1, $2, $3); + + my $phone_avail = qsearchs('phone_avail', { + 'countrycode' => 1, #XXX make an option or something + 'exportnum' => $self->exportnum, + 'svcnum' => $svc_phone->svcnum, + #these too? + 'npa' => $npa, + 'nxx' => $nxx, + 'station' => $station, + }); + + return "can't find number to return to availability: ". $svc_phone->phonenum + unless $phone_avail; + + $phone_avail->svcnum(''); + + $phone_avail->replace; + +} + +sub _export_replace { ''; } +sub _export_suspend { ''; } +sub _export_unsuspend { ''; } + +1; +