phone devices (for netsapiens integration), RT#5226
[freeside.git] / FS / FS / phone_device.pm
1 package FS::phone_device;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearchs ); # qsearch );
6 use FS::part_device;
7 use FS::svc_phone;
8
9 =head1 NAME
10
11 FS::phone_device - Object methods for phone_device records
12
13 =head1 SYNOPSIS
14
15   use FS::phone_device;
16
17   $record = new FS::phone_device \%hash;
18   $record = new FS::phone_device { '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_device object represents a specific customer phone device, such as
31 a SIP phone or ATA.  FS::phone_device inherits from FS::Record.  The following
32 fields are currently supported:
33
34 =over 4
35
36 =item devicenum
37
38 primary key
39
40 =item devicepart
41
42 devicepart
43
44 =item svcnum
45
46 svcnum
47
48 =item mac_addr
49
50 mac_addr
51
52
53 =back
54
55 =head1 METHODS
56
57 =over 4
58
59 =item new HASHREF
60
61 Creates a new record.  To add the record to the database, see L<"insert">.
62
63 Note that this stores the hash reference, not a distinct copy of the hash it
64 points to.  You can ask the object for a copy with the I<hash> method.
65
66 =cut
67
68 # the new method can be inherited from FS::Record, if a table method is defined
69
70 sub table { 'phone_device'; }
71
72 =item insert
73
74 Adds this record to the database.  If there is an error, returns the error,
75 otherwise returns false.
76
77 =cut
78
79 # the insert method can be inherited from FS::Record
80
81 =item delete
82
83 Delete this record from the database.
84
85 =cut
86
87 # the delete method can be inherited from FS::Record
88
89 =item replace OLD_RECORD
90
91 Replaces the OLD_RECORD with this one in the database.  If there is an error,
92 returns the error, otherwise returns false.
93
94 =cut
95
96 # the replace method can be inherited from FS::Record
97
98 =item check
99
100 Checks all fields to make sure this is a valid record.  If there is
101 an error, returns the error, otherwise returns false.  Called by the insert
102 and replace methods.
103
104 =cut
105
106 # the check method should currently be supplied - FS::Record contains some
107 # data checking routines
108
109 sub check {
110   my $self = shift;
111
112   my $mac = $self->mac_addr;
113   $mac =~ s/\s+//g;
114   $mac =~ s/://g;
115   $self->mac_addr($mac);
116
117   my $error = 
118     $self->ut_numbern('devicenum')
119     || $self->ut_foreign_key('devicepart', 'part_device', 'devicepart')
120     || $self->ut_foreign_key('svcnum', 'svc_phone', 'svcnum' ) #cust_svc?
121     || $self->ut_hexn('mac_addr')
122   ;
123   return $error if $error;
124
125   $self->SUPER::check;
126 }
127
128 =item part_device
129
130 Returns the device type record (see L<FS::part_device>) associated with this
131 customer device.
132
133 =cut
134
135 sub part_device {
136   my $self = shift;
137   qsearchs( 'part_device', { 'devicepart' => $self->devicepart } );
138 }
139
140 =back
141
142 =head1 BUGS
143
144 =head1 SEE ALSO
145
146 L<FS::Record>, schema.html from the base documentation.
147
148 =cut
149
150 1;
151