communigate provisioning phase 2: add svc_domain.trailer -> communigate TrailerText...
[freeside.git] / FS / FS / phone_avail.pm
1 package FS::phone_avail;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6
7 @ISA = qw(FS::Record);
8
9 =head1 NAME
10
11 FS::phone_avail - Phone number availability cache
12
13 =head1 SYNOPSIS
14
15   use FS::phone_avail;
16
17   $record = new FS::phone_avail \%hash;
18   $record = new FS::phone_avail { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::phone_avail object represents availability of phone service.
31 FS::phone_avail inherits from FS::Record.  The following fields are currently
32 supported:
33
34 =over 4
35
36 =item availnum
37
38 primary key
39
40 =item exportnum
41
42 exportnum
43
44 =item countrycode
45
46 countrycode
47
48 =item state
49
50 state
51
52 =item npa
53
54 npa
55
56 =item nxx
57
58 nxx
59
60 =item station
61
62 station
63
64 =item name
65
66 Optional name
67
68 =item svcnum
69
70 svcnum
71
72 =item availbatch
73
74 availbatch
75
76 =back
77
78 =head1 METHODS
79
80 =over 4
81
82 =item new HASHREF
83
84 Creates a new record.  To add the record to the database, see L<"insert">.
85
86 Note that this stores the hash reference, not a distinct copy of the hash it
87 points to.  You can ask the object for a copy with the I<hash> method.
88
89 =cut
90
91 # the new method can be inherited from FS::Record, if a table method is defined
92
93 sub table { 'phone_avail'; }
94
95 =item insert
96
97 Adds this record to the database.  If there is an error, returns the error,
98 otherwise returns false.
99
100 =cut
101
102 # the insert method can be inherited from FS::Record
103
104 =item delete
105
106 Delete this record from the database.
107
108 =cut
109
110 # the delete method can be inherited from FS::Record
111
112 =item replace OLD_RECORD
113
114 Replaces the OLD_RECORD with this one in the database.  If there is an error,
115 returns the error, otherwise returns false.
116
117 =cut
118
119 # the replace method can be inherited from FS::Record
120
121 =item check
122
123 Checks all fields to make sure this is a valid record.  If there is
124 an error, returns the error, otherwise returns false.  Called by the insert
125 and replace methods.
126
127 =cut
128
129 # the check method should currently be supplied - FS::Record contains some
130 # data checking routines
131
132 sub check {
133   my $self = shift;
134
135   my $error = 
136     $self->ut_numbern('availnum')
137     || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum' )
138     || $self->ut_number('countrycode')
139     || $self->ut_alphan('state')
140     || $self->ut_number('npa')
141     || $self->ut_numbern('nxx')
142     || $self->ut_numbern('station')
143     || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum' )
144     || $self->ut_textn('availbatch')
145   ;
146   return $error if $error;
147
148   $self->SUPER::check;
149 }
150
151 sub process_batch_import {
152   my $job = shift;
153
154   my $numsub = sub {
155     my( $phone_avail, $value ) = @_;
156     $value =~ s/\D//g;
157     $value =~ /^(\d{3})(\d{3})(\d+)$/ or die "unparsable number $value\n";
158     #( $hash->{npa}, $hash->{nxx}, $hash->{station} ) = ( $1, $2, $3 );
159     $phone_avail->npa($1);
160     $phone_avail->nxx($2);
161     $phone_avail->station($3);
162   };
163
164   my $opt = { 'table'   => 'phone_avail',
165               'params'  => [ 'availbatch', 'exportnum', 'countrycode' ],
166               'formats' => { 'default' => [ 'state', $numsub ] },
167             };
168
169   FS::Record::process_batch_import( $job, $opt, @_ );
170
171 }
172
173 =back
174
175 =head1 BUGS
176
177 Sparse documentation.
178
179 =head1 SEE ALSO
180
181 L<FS::Record>, schema.html from the base documentation.
182
183 =cut
184
185 1;
186