1 package FS::svc_hardware;
4 use base qw( FS::svc_Common );
5 use FS::Record qw( qsearch qsearchs );
7 use FS::hardware_status;
11 FS::svc_hardware - Object methods for svc_hardware records
17 $record = new FS::svc_hardware \%hash;
18 $record = new FS::svc_hardware { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::svc_hardware object represents an equipment installation, such as
31 a wireless broadband receiver, satellite antenna, or DVR. FS::svc_hardware
32 inherits from FS::svc_Common.
34 The following fields are currently supported:
38 =item svcnum - Primary key
40 =item typenum - Device type number (see L<FS::hardware_type>)
42 =item ip_addr - IP address
44 =item hw_addr - Hardware address
46 =item serial - Serial number
48 =item statusnum - Service status (see L<FS::hardware_status>)
50 =item note - Installation notes: location on property, physical access, etc.
60 Creates a new svc_hardware object.
64 sub table { 'svc_hardware'; }
67 my %opts = ( 'type' => 'text', 'disable_select' => 1 );
69 'name' => 'Hardware', #?
70 'name_plural' => 'Hardware',
71 'display_weight' => 59,
72 'cancel_weight' => 86,
74 'svcnum' => { label => 'Service' },
75 'typenum' => { label => 'Device type',
76 type => 'select-hardware',
80 disable_inventory => 1,
82 'serial' => { label => 'Serial number', %opts },
83 'hw_addr' => { label => 'Hardware address', %opts },
84 'ip_addr' => { label => 'IP address', %opts },
85 'statusnum' => { label => 'Service status',
87 select_table => 'hardware_status',
88 select_key => 'statusnum',
89 select_label => 'label',
90 disable_inventory => 1,
92 'note' => { label => 'Installation notes', %opts },
98 my ($class, $string) = @_;
101 my $ip = NetAddr::IP->new($string);
103 push @where, $class->search_sql_field('ip_addr', $ip->addr);
106 if ( $string =~ /^(\w+)$/ ) {
107 push @where, 'LOWER(svc_hardware.serial) LIKE \'%'.lc($string).'%\'';
110 if ( $string =~ /^([0-9A-Fa-f]|\W)+$/ ) {
111 my $hex = uc($string);
113 push @where, 'svc_hardware.hw_addr LIKE \'%'.$hex.'%\'';
117 '(' . join(' OR ', @where) . ')';
125 $self->serial || $self->hw_addr;
130 Adds this record to the database. If there is an error, returns the error,
131 otherwise returns false.
135 Delete this record from the database.
137 =item replace OLD_RECORD
139 Replaces the OLD_RECORD with this one in the database. If there is an error,
140 returns the error, otherwise returns false.
142 # the replace method can be inherited from FS::Record
146 Checks all fields to make sure this is a valid service. If there is
147 an error, returns the error, otherwise returns false. Called by the insert
155 my $x = $self->setfixed;
156 return $x unless ref $x;
158 my $hw_addr = $self->getfield('hw_addr');
159 $hw_addr = join('', split(/\W/, $hw_addr));
160 $self->setfield('hw_addr', $hw_addr);
163 $self->ut_numbern('svcnum')
164 || $self->ut_foreign_key('typenum', 'hardware_type', 'typenum')
165 || $self->ut_ip46n('ip_addr')
166 || $self->ut_hexn('hw_addr')
167 || $self->ut_alphan('serial')
168 || $self->ut_foreign_keyn('statusnum', 'hardware_status', 'statusnum')
169 || $self->ut_textn('note')
171 return $error if $error;
173 if ( !length($self->getfield('hw_addr'))
174 and !length($self->getfield('serial')) ) {
175 return 'Serial number or hardware address required';
183 Returns the L<FS::hardware_type> object associated with this installation.
189 return qsearchs('hardware_type', { 'typenum' => $self->typenum });
194 Returns the 'label' field of the L<FS::hardware_status> object associated
195 with this installation.
201 my $status = qsearchs('hardware_status', { 'statusnum' => $self->statusnum })
211 L<FS::Record>, L<FS::svc_Common>, schema.html from the base documentation.