bell west CDR format, RT#4403
[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 svcnum
65
66 svcnum
67
68 =item availbatch
69
70 availbatch
71
72 =back
73
74 =head1 METHODS
75
76 =over 4
77
78 =item new HASHREF
79
80 Creates a new record.  To add the record to the database, see L<"insert">.
81
82 Note that this stores the hash reference, not a distinct copy of the hash it
83 points to.  You can ask the object for a copy with the I<hash> method.
84
85 =cut
86
87 # the new method can be inherited from FS::Record, if a table method is defined
88
89 sub table { 'phone_avail'; }
90
91 =item insert
92
93 Adds this record to the database.  If there is an error, returns the error,
94 otherwise returns false.
95
96 =cut
97
98 # the insert method can be inherited from FS::Record
99
100 =item delete
101
102 Delete this record from the database.
103
104 =cut
105
106 # the delete method can be inherited from FS::Record
107
108 =item replace OLD_RECORD
109
110 Replaces the OLD_RECORD with this one in the database.  If there is an error,
111 returns the error, otherwise returns false.
112
113 =cut
114
115 # the replace method can be inherited from FS::Record
116
117 =item check
118
119 Checks all fields to make sure this is a valid record.  If there is
120 an error, returns the error, otherwise returns false.  Called by the insert
121 and replace methods.
122
123 =cut
124
125 # the check method should currently be supplied - FS::Record contains some
126 # data checking routines
127
128 sub check {
129   my $self = shift;
130
131   my $error = 
132     $self->ut_numbern('availnum')
133     || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum' )
134     || $self->ut_number('countrycode')
135     || $self->ut_alphan('state')
136     || $self->ut_number('npa')
137     || $self->ut_numbern('nxx')
138     || $self->ut_numbern('station')
139     || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum' )
140     || $self->ut_textn('availbatch')
141   ;
142   return $error if $error;
143
144   $self->SUPER::check;
145 }
146
147 sub process_batch_import {
148   my $job = shift;
149
150   my $numsub = sub {
151     my( $phone_avail, $value ) = @_;
152     $value =~ s/\D//g;
153     $value =~ /^(\d{3})(\d{3})(\d+)$/ or die "unparsable number $value\n";
154     #( $hash->{npa}, $hash->{nxx}, $hash->{station} ) = ( $1, $2, $3 );
155     $phone_avail->npa($1);
156     $phone_avail->nxx($2);
157     $phone_avail->station($3);
158   };
159
160   my $opt = { 'table'   => 'phone_avail',
161               'params'  => [ 'availbatch', 'exportnum', 'countrycode' ],
162               'formats' => { 'default' => [ 'state', $numsub ] },
163             };
164
165   FS::Record::process_batch_import( $job, $opt, @_ );
166
167 }
168
169 =back
170
171 =head1 BUGS
172
173 Sparse documentation.
174
175 =head1 SEE ALSO
176
177 L<FS::Record>, schema.html from the base documentation.
178
179 =cut
180
181 1;
182