service refactor!
[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                          },
78         'phonenum'    => 'Phone number',
79         'pin'         => { label => 'Personal Identification Number',
80                            type  => 'text',
81                            disable_inventory => 1,
82                          },
83     },
84   };
85 }
86
87 sub table { 'svc_phone'; }
88
89 =item search_sql STRING
90
91 Class method which returns an SQL fragment to search for the given string.
92
93 =cut
94
95 sub search_sql {
96   my( $class, $string ) = @_;
97   $class->search_sql_field('phonenum', $string );
98 }
99
100 =item label
101
102 Returns the phone number.
103
104 =cut
105
106 sub label {
107   my $self = shift;
108   $self->phonenum; #XXX format it better
109 }
110
111 =item insert
112
113 Adds this record to the database.  If there is an error, returns the error,
114 otherwise returns false.
115
116 =cut
117
118 # the insert method can be inherited from FS::Record
119
120 =item delete
121
122 Delete this record from the database.
123
124 =cut
125
126 # the delete method can be inherited from FS::Record
127
128 =item replace OLD_RECORD
129
130 Replaces the OLD_RECORD with this one in the database.  If there is an error,
131 returns the error, otherwise returns false.
132
133 =cut
134
135 # the replace method can be inherited from FS::Record
136
137 =item suspend
138
139 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
140
141 =item unsuspend
142
143 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
144
145 =item cancel
146
147 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
148
149 =item check
150
151 Checks all fields to make sure this is a valid phone number.  If there is
152 an error, returns the error, otherwise returns false.  Called by the insert
153 and replace methods.
154
155 =cut
156
157 # the check method should currently be supplied - FS::Record contains some
158 # data checking routines
159
160 sub check {
161   my $self = shift;
162
163   my $error = 
164     $self->ut_numbern('svcnum')
165     || $self->ut_numbern('countrycode')
166     || $self->ut_number('phonenum')
167     || $self->ut_numbern('pin')
168   ;
169   return $error if $error;
170
171   $self->countrycode(1) unless $self->countrycode;
172
173   $self->SUPER::check;
174 }
175
176 =back
177
178 =head1 BUGS
179
180 =head1 SEE ALSO
181
182 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
183 L<FS::cust_pkg>, schema.html from the base documentation.
184
185 =cut
186
187 1;
188