4 use base qw( FS::svc_Common );
6 use FS::Record qw( qsearchs ); # qw( qsearch qsearchs );
13 FS::svc_alarm - Object methods for svc_alarm records
19 $record = new FS::svc_alarm \%hash;
20 $record = new FS::svc_alarm { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::svc_alarm object represents an alarm service. FS::svc_alarm inherits
35 The following fields are currently supported:
39 =item svcnum - Primary key
41 =item alarmsystemnum - Alarm System Vendor (see L<FS::alarm_system>)
43 =item alarmtypenum - Alarm System Type (inputs/outputs) (see L<FS::alarm_type>)
45 =item alarmstationnum - Alarm central station (see L<FS::alarm_station>)
47 =item acctnum - Account number
49 =item _password - Password
51 =item location - Location on property
61 Creates a new svc_dish object.
65 sub table { 'svc_alarm'; }
68 my %opts = ( 'type' => 'text',
69 #'disable_select' => 1,
70 'disable_inventory' => 1,
73 tie my %fields, 'Tie::IxHash',
74 'svcnum' => { label => 'Service' },
75 'acctnum' => { label => 'Account #', %opts },
76 '_password' => { label => 'Password' , %opts },
77 'location' => { label => 'Location', %opts },
78 'cs_receiver' => { label => 'CS Receiver #'},
79 'cs_phonenum' => { label => 'CS Phone #' },
80 'serialnum' => { label => 'Alarm Serial #' },
81 'alarmsystemnum' => { label => 'Alarm System Vendor',
82 type => 'select-alarm_system',
83 disable_inventory => 1,
84 value_callback => sub {
85 shift->alarm_system->systemname
88 'alarmtypenum' => { label => 'Alarm System Type',
89 type => 'select-alarm_type',
90 disable_inventory => 1,
91 value_callback => sub {
92 shift->alarm_type->typename
95 'alarmstationnum' => { label => 'Alarm Central Station',
96 type => 'select-alarm_station',
97 disable_inventory => 1,
98 value_callback => sub {
99 shift->alarm_station->stationname
105 'name' => 'Alarm service',
106 'sorts' => 'acctnum',
107 'display_weight' => 80,
108 'cancel_weight' => 85,
109 'fields' => \%fields,
110 'addl_process_fields' => [qw( alarmsystemnum_systemname
111 alarmtypenum_inputs alarmtypenum_outputs
112 alarmstationnum_stationname
119 $self->acctnum . '@'. $self->alarm_station->stationname. #?
120 ' ('. $self->alarm_system->systemname. ' '. $self->alarm_type->typename. ')'
125 my($class, $string) = @_;
126 $class->search_sql_field('acctnum', $string);
131 Adds this record to the database. If there is an error, returns the error,
132 otherwise returns false.
136 Delete this record from the database.
138 =item replace OLD_RECORD
140 Replaces the OLD_RECORD with this one in the database. If there is an error,
141 returns the error, otherwise returns false.
145 sub preinsert_hook_first { shift->_inline_add(@_); }
146 sub prereplace_hook_first { shift->_inline_add(@_); }
151 my $agentnum = $self->cust_svc->cust_pkg->cust_main->agentnum;
153 if ( $self->alarmsystemnum == -1 ) {
154 my $alarm_system = new FS::alarm_system {
155 'agentnum' => $agentnum,
156 'systemname' => $self->alarmsystemnum_systemname,
158 my $error = $alarm_system->insert;
159 return $error if $error;
160 $self->alarmsystemnum($alarm_system->alarmsystemnum);
163 if ( $self->alarmtypenum == -1 ) {
164 my $alarm_type = new FS::alarm_type {
165 'agentnum' => $agentnum,
166 'inputs' => $self->alarmtypenum_inputs,
167 'outputs' => $self->alarmtypenum_outputs,
169 my $error = $alarm_type->insert;
170 return $error if $error;
171 $self->alarmtypenum($alarm_type->alarmtypenum);
174 if ( $self->alarmstationnum == -1 ) {
175 my $alarm_station = new FS::alarm_station {
176 'agentnum' => $agentnum,
177 'stationname' => $self->alarmstationnum_stationname,
179 my $error = $alarm_station->insert;
180 return $error if $error;
181 $self->alarmstationnum($alarm_station->alarmstationnum)
189 Checks all fields to make sure this is a valid service. If there is
190 an error, returns the error, otherwise returns false. Called by the insert
198 my $x = $self->setfixed;
199 return $x unless ref $x;
201 my $iso3166 = $self->cust_main->ship_location->country();
204 $self->ut_numbern('svcnum')
205 || $self->ut_text('acctnum')
206 || $self->ut_alphan('_password')
207 || $self->ut_textn('location')
208 || $self->ut_numbern('cs_receiver')
209 || $self->ut_phonen('cs_phonenum', $iso3166)
210 || $self->ut_alphan('serialnum')
211 || $self->ut_foreign_key('alarmsystemnum', 'alarm_system', 'systemnum')
212 || $self->ut_foreign_key('alarmtypenum', 'alarm_type', 'typenum')
213 || $self->ut_foreign_key('alarmstationnum', 'alarm_station', 'stationnum')
215 return $error if $error;
217 #really just an signed int, but to discourage storing other data (e.g. phone)
218 return 'CS Receiver must be 9 digits or less'
219 if $self->cs_receiver =~ /\d{10}/;
225 qsearchs('alarm_system', { alarmsystemnum => shift->alarmsystemnum } );
228 qsearchs('alarm_type', { alarmtypenum => shift->alarmtypenum } );
231 qsearchs('alarm_station', { alarmstationnum => shift->alarmstationnum } );
238 L<FS::Record>, L<FS::svc_Common>, schema.html from the base documentation.