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 smartcard - Smartcard number, for devices that use a smartcard
50 =item statusnum - Service status (see L<FS::hardware_status>)
52 =item note - Installation notes: location on property, physical access, etc.
62 Creates a new svc_hardware object.
66 sub table { 'svc_hardware'; }
69 my %opts = ( 'type' => 'text', 'disable_select' => 1 );
71 'name' => 'Hardware', #?
72 'name_plural' => 'Hardware',
73 'display_weight' => 59,
74 'cancel_weight' => 86,
76 'svcnum' => { label => 'Service' },
77 'typenum' => { label => 'Device type',
78 type => 'select-hardware',
82 disable_inventory => 1,
84 'serial' => { label => 'Serial number', %opts },
85 'hw_addr' => { label => 'Hardware address', %opts },
86 'ip_addr' => { label => 'IP address', %opts },
87 'smartcard' => { label => 'Smartcard #', %opts },
88 'statusnum' => { label => 'Service status',
90 select_table => 'hardware_status',
91 select_key => 'statusnum',
92 select_label => 'label',
93 disable_inventory => 1,
95 'note' => { label => 'Installation notes', %opts },
101 my ($class, $string) = @_;
104 my $ip = NetAddr::IP->new($string);
106 push @where, $class->search_sql_field('ip_addr', $ip->addr);
109 if ( $string =~ /^(\w+)$/ ) {
110 push @where, 'LOWER(svc_hardware.serial) LIKE \'%'.lc($string).'%\'';
113 if ( $string =~ /^([0-9A-Fa-f]|\W)+$/ ) {
114 my $hex = uc($string);
116 push @where, 'svc_hardware.hw_addr LIKE \'%'.$hex.'%\'';
120 '(' . join(' OR ', @where) . ')';
128 $self->serial || $self->hw_addr;
133 Adds this record to the database. If there is an error, returns the error,
134 otherwise returns false.
138 Delete this record from the database.
140 =item replace OLD_RECORD
142 Replaces the OLD_RECORD with this one in the database. If there is an error,
143 returns the error, otherwise returns false.
145 # the replace method can be inherited from FS::Record
149 Checks all fields to make sure this is a valid service. If there is
150 an error, returns the error, otherwise returns false. Called by the insert
158 my $x = $self->setfixed;
159 return $x unless ref $x;
161 my $hw_addr = $self->getfield('hw_addr');
162 $hw_addr = join('', split(/\W/, $hw_addr));
163 $self->setfield('hw_addr', $hw_addr);
166 $self->ut_numbern('svcnum')
167 || $self->ut_foreign_key('typenum', 'hardware_type', 'typenum')
168 || $self->ut_ip46n('ip_addr')
169 || $self->ut_hexn('hw_addr')
170 || $self->ut_alphan('serial')
171 || $self->ut_alphan('smartcard')
172 || $self->ut_foreign_keyn('statusnum', 'hardware_status', 'statusnum')
173 || $self->ut_anything('note')
175 return $error if $error;
177 if ( !length($self->getfield('hw_addr'))
178 and !length($self->getfield('serial')) ) {
179 return 'Serial number or hardware address required';
187 Returns the L<FS::hardware_type> object associated with this installation.
193 return qsearchs('hardware_type', { 'typenum' => $self->typenum });
198 Returns the 'label' field of the L<FS::hardware_status> object associated
199 with this installation.
205 my $status = qsearchs('hardware_status', { 'statusnum' => $self->statusnum })
215 L<FS::Record>, L<FS::svc_Common>, schema.html from the base documentation.