1 package FS::part_export::internal_diddb;
3 use vars qw(@ISA %info);
5 use FS::Record qw(qsearch qsearchs);
9 @ISA = qw(FS::part_export);
13 'desc' => 'Provision phone numbers from the internal DID database',
14 'notes' => 'After adding the export, DIDs may be imported under Tools -> Importing -> Import phone numbers (DIDs)',
17 sub rebless { shift; }
21 my %opt = ref($_[0]) ? %{$_[0]} : @_;
23 my %hash = ( 'countrycode' => 1, #XXX make an option or something
24 'exportnum' => $self->exportnum,
28 if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers
30 $hash{npa} = $opt{areacode};
31 $hash{nxx} = $opt{exchange};
33 return [ map { $_->npa. '-'. $_->nxx. '-'. $_->station }
34 qsearch({ 'table' => 'phone_avail',
36 'order_by' => 'ORDER BY station',
40 } elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX)
42 $hash{npa} = $opt{areacode};
44 return [ map { '('. $_->npa. '-'. $_->nxx. '-XXXX)' }
45 qsearch({ 'select' => 'DISTINCT npa, nxx',
46 'table' => 'phone_avail',
48 'order_by' => 'ORDER BY nxx',
52 } elsif ( $opt{'state'} ) { #return aracodes
54 $hash{state} = $opt{state};
56 return [ map { $_->npa }
57 qsearch({ 'select' => 'DISTINCT npa',
58 'table' => 'phone_avail',
60 'order_by' => 'ORDER BY npa',
65 die "FS::part_export::internal_diddb::get_dids called without options\n";
70 sub _export_insert { #link phone_avail to svcnum
71 my( $self, $svc_phone ) = (shift, shift);
73 $svc_phone =~ /^(\d{3})(\d{3})(\d+)$/
74 or return "unparsable phone number: ". $svc_phone->phonenum;
75 my( $npa, $nxx, $station ) = ($1, $2, $3);
77 my $phone_avail = qsearchs('phone_avail', {
78 'countrycode' => 1, #XXX make an option or something
79 'exportnum' => $self->exportnum,
83 'station' => $station,
86 return "number not available: ". $svc_phone->phonenum
89 $phone_avail->svcnum($svc_phone->svcnum);
91 $phone_avail->replace;
95 sub _export_delete { #unlink phone_avail from svcnum
96 my( $self, $svc_phone ) = (shift, shift);
98 $svc_phone =~ /^(\d{3})(\d{3})(\d+)$/
99 or return "unparsable phone number: ". $svc_phone->phonenum;
100 my( $npa, $nxx, $station ) = ($1, $2, $3);
102 my $phone_avail = qsearchs('phone_avail', {
103 'countrycode' => 1, #XXX make an option or something
104 'exportnum' => $self->exportnum,
105 'svcnum' => $svc_phone->svcnum,
109 'station' => $station,
112 return "can't find number to return to availability: ". $svc_phone->phonenum
115 $phone_avail->svcnum('');
117 $phone_avail->replace;
121 sub _export_replace { ''; }
122 sub _export_suspend { ''; }
123 sub _export_unsuspend { ''; }