svc_cable, RT#22009
[freeside.git] / FS / FS / cable_device.pm
1 package FS::cable_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_cable;
8
9 =head1 NAME
10
11 FS::cable_device - Object methods for cable_device records
12
13 =head1 SYNOPSIS
14
15   use FS::cable_device;
16
17   $record = new FS::cable_device \%hash;
18   $record = new FS::cable_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::cable_device object represents a specific customer cable modem.
31 FS::cable_device inherits from FS::Record.  The following fields are currently
32 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 =item serial
53
54 serial
55
56
57 =back
58
59 =head1 METHODS
60
61 =over 4
62
63 =item new HASHREF
64
65 Creates a new record.  To add the record to the database, see L<"insert">.
66
67 Note that this stores the hash reference, not a distinct copy of the hash it
68 points to.  You can ask the object for a copy with the I<hash> method.
69
70 =cut
71
72 sub table { 'cable_device'; }
73
74 =item insert
75
76 Adds this record to the database.  If there is an error, returns the error,
77 otherwise returns false.
78
79 =item delete
80
81 Delete this record from the database.
82
83 =item replace OLD_RECORD
84
85 Replaces the OLD_RECORD with this one in the database.  If there is an error,
86 returns the error, otherwise returns false.
87
88 =item check
89
90 Checks all fields to make sure this is a valid record.  If there is
91 an error, returns the error, otherwise returns false.  Called by the insert
92 and replace methods.
93
94 =cut
95
96 sub check {
97   my $self = shift;
98
99   my $mac = $self->mac_addr;
100   $mac =~ s/\s+//g;
101   $mac =~ s/://g;
102   $self->mac_addr($mac);
103
104   my $error = 
105     $self->ut_numbern('devicenum')
106     || $self->ut_number('devicepart')
107     || $self->ut_foreign_key('devicepart', 'part_device', 'devicepart')
108     || $self->ut_foreign_key('svcnum', 'svc_cable', 'svcnum' ) #cust_svc?
109     || $self->ut_hexn('mac_addr')
110     || $self->ut_textn('serial')
111   ;
112   return $error if $error;
113
114   $self->SUPER::check;
115 }
116
117 =item part_device
118
119 Returns the device type record (see L<FS::part_device>) associated with this
120 customer device.
121
122 =cut
123
124 sub part_device {
125   my $self = shift;
126   qsearchs( 'part_device', { 'devicepart' => $self->devicepart } );
127 }
128
129 =back
130
131 =head1 BUGS
132
133 =head1 SEE ALSO
134
135 L<FS::Record>
136
137 =cut
138
139 1;
140