1 package FS::phone_avail;
4 use vars qw( @ISA $DEBUG $me );
5 use FS::Record qw( qsearch qsearchs );
9 $me = '[FS::phone_avail]';
14 FS::phone_avail - Phone number availability cache
20 $record = new FS::phone_avail \%hash;
21 $record = new FS::phone_avail { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::phone_avail object represents availability of phone service.
34 FS::phone_avail inherits from FS::Record. The following fields are currently
87 Creates a new record. To add the record to the database, see L<"insert">.
89 Note that this stores the hash reference, not a distinct copy of the hash it
90 points to. You can ask the object for a copy with the I<hash> method.
94 # the new method can be inherited from FS::Record, if a table method is defined
96 sub table { 'phone_avail'; }
100 Adds this record to the database. If there is an error, returns the error,
101 otherwise returns false.
105 # the insert method can be inherited from FS::Record
109 Delete this record from the database.
113 # the delete method can be inherited from FS::Record
115 =item replace OLD_RECORD
117 Replaces the OLD_RECORD with this one in the database. If there is an error,
118 returns the error, otherwise returns false.
122 # the replace method can be inherited from FS::Record
126 Checks all fields to make sure this is a valid record. If there is
127 an error, returns the error, otherwise returns false. Called by the insert
132 # the check method should currently be supplied - FS::Record contains some
133 # data checking routines
139 $self->ut_numbern('availnum')
140 || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum' )
141 || $self->ut_number('countrycode')
142 || $self->ut_alphan('state')
143 || $self->ut_number('npa')
144 || $self->ut_numbern('nxx')
145 || $self->ut_numbern('station')
146 || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum' )
147 || $self->ut_textn('availbatch')
149 return $error if $error;
154 sub process_batch_import {
158 my( $phone_avail, $value ) = @_;
160 $value =~ /^(\d{3})(\d{3})(\d+)$/ or die "unparsable number $value\n";
161 #( $hash->{npa}, $hash->{nxx}, $hash->{station} ) = ( $1, $2, $3 );
162 $phone_avail->npa($1);
163 $phone_avail->nxx($2);
164 $phone_avail->station($3);
167 my $opt = { 'table' => 'phone_avail',
168 'params' => [ 'availbatch', 'exportnum', 'countrycode' ],
169 'formats' => { 'default' => [ 'state', $numsub ] },
172 FS::Record::process_batch_import( $job, $opt, @_ );
176 # Used by FS::Upgrade to migrate to a new database.
178 my ($class, %opts) = @_;
180 warn "$me upgrading $class\n" if $DEBUG;
182 my $sth = dbh->prepare(
183 'UPDATE phone_avail SET svcnum = NULL
184 WHERE svcnum IS NOT NULL
185 AND 0 = ( SELECT COUNT(*) FROM svc_phone
186 WHERE phone_avail.svcnum = svc_phone.svcnum )'
187 ) or die dbh->errstr;
189 $sth->execute or die $sth->errstr;
197 Sparse documentation.
201 L<FS::Record>, schema.html from the base documentation.