reincorporate the changes from http://www.sisd.com/cgi-bin/viewcvs.cgi/freeside/httem...
[freeside.git] / FS / FS / svc_phone.pm
1 package FS::svc_phone;
2
3 use strict;
4 use vars qw( @ISA );
5 #use FS::Record qw( qsearch qsearchs );
6 use FS::svc_Common;
7
8 @ISA = qw( FS::svc_Common );
9
10 =head1 NAME
11
12 FS::svc_phone - Object methods for svc_phone records
13
14 =head1 SYNOPSIS
15
16   use FS::svc_phone;
17
18   $record = new FS::svc_phone \%hash;
19   $record = new FS::svc_phone { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29   $error = $record->suspend;
30
31   $error = $record->unsuspend;
32
33   $error = $record->cancel;
34
35 =head1 DESCRIPTION
36
37 An FS::svc_phone object represents a phone number.  FS::svc_phone inherits
38 from FS::Record.  The following fields are currently supported:
39
40 =over 4
41
42 =item svcnum - primary key
43
44 =item countrycode - 
45
46 =item phonenum - 
47
48 =item pin - 
49
50 =back
51
52 =head1 METHODS
53
54 =over 4
55
56 =item new HASHREF
57
58 Creates a new phone number.  To add the number to the database, see L<"insert">.
59
60 Note that this stores the hash reference, not a distinct copy of the hash it
61 points to.  You can ask the object for a copy with the I<hash> method.
62
63 =cut
64
65 # the new method can be inherited from FS::Record, if a table method is defined
66 #
67 sub table_info {
68   {
69     'name' => 'Phone number',
70     'sorts' => 'phonenum',
71     'display_weight' => 60,
72     'cancel_weight'  => 80,
73     'fields' => {
74         'countrycode' => { label => 'Country code',
75                            type  => 'text',
76                            disable_inventory => 1,
77                            disable_select => 1,
78                          },
79         'phonenum'    => 'Phone number',
80         'pin'         => { label => 'Personal Identification Number',
81                            type  => 'text',
82                            disable_inventory => 1,
83                            disable_select => 1,
84                          },
85     },
86   };
87 }
88
89 sub table { 'svc_phone'; }
90
91 =item search_sql STRING
92
93 Class method which returns an SQL fragment to search for the given string.
94
95 =cut
96
97 sub search_sql {
98   my( $class, $string ) = @_;
99   $class->search_sql_field('phonenum', $string );
100 }
101
102 =item label
103
104 Returns the phone number.
105
106 =cut
107
108 sub label {
109   my $self = shift;
110   $self->phonenum; #XXX format it better
111 }
112
113 =item insert
114
115 Adds this record to the database.  If there is an error, returns the error,
116 otherwise returns false.
117
118 =cut
119
120 # the insert method can be inherited from FS::Record
121
122 =item delete
123
124 Delete this record from the database.
125
126 =cut
127
128 # the delete method can be inherited from FS::Record
129
130 =item replace OLD_RECORD
131
132 Replaces the OLD_RECORD with this one in the database.  If there is an error,
133 returns the error, otherwise returns false.
134
135 =cut
136
137 # the replace method can be inherited from FS::Record
138
139 =item suspend
140
141 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
142
143 =item unsuspend
144
145 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
146
147 =item cancel
148
149 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
150
151 =item check
152
153 Checks all fields to make sure this is a valid phone number.  If there is
154 an error, returns the error, otherwise returns false.  Called by the insert
155 and replace methods.
156
157 =cut
158
159 # the check method should currently be supplied - FS::Record contains some
160 # data checking routines
161
162 sub check {
163   my $self = shift;
164
165   my $error = 
166     $self->ut_numbern('svcnum')
167     || $self->ut_numbern('countrycode')
168     || $self->ut_number('phonenum')
169     || $self->ut_numbern('pin')
170   ;
171   return $error if $error;
172
173   $self->countrycode(1) unless $self->countrycode;
174
175   $self->SUPER::check;
176 }
177
178 =back
179
180 =head1 BUGS
181
182 =head1 SEE ALSO
183
184 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
185 L<FS::cust_pkg>, schema.html from the base documentation.
186
187 =cut
188
189 1;
190