2 use base qw( FS::svc_Common );
12 FS::svc_alarm - Object methods for svc_alarm records
18 $record = new FS::svc_alarm \%hash;
19 $record = new FS::svc_alarm { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::svc_alarm object represents an alarm service. FS::svc_alarm inherits
34 The following fields are currently supported:
38 =item svcnum - Primary key
40 =item alarmsystemnum - Alarm System Vendor (see L<FS::alarm_system>)
42 =item alarmtypenum - Alarm System Type (inputs/outputs) (see L<FS::alarm_type>)
44 =item alarmstationnum - Alarm central station (see L<FS::alarm_station>)
46 =item acctnum - Account number
48 =item _password - Password
50 =item location - Location on property
60 Creates a new svc_dish object.
64 sub table { 'svc_alarm'; }
67 my %opts = ( 'type' => 'text',
68 #'disable_select' => 1,
69 'disable_inventory' => 1,
72 tie my %fields, 'Tie::IxHash',
73 'svcnum' => { label => 'Service' },
74 'acctnum' => { label => 'Account #', %opts },
75 '_password' => { label => 'Password' , %opts },
76 'location' => { label => 'Location', %opts },
77 'cs_receiver' => { label => 'CS Receiver #'},
78 'cs_phonenum' => { label => 'CS Phone #' },
79 'serialnum' => { label => 'Alarm Serial #' },
80 'alarmsystemnum' => { label => 'Alarm System Vendor',
81 type => 'select-alarm_system',
82 disable_inventory => 1,
83 value_callback => sub {
84 shift->alarm_system->systemname
87 'alarmtypenum' => { label => 'Alarm System Type',
88 type => 'select-alarm_type',
89 disable_inventory => 1,
90 value_callback => sub {
91 shift->alarm_type->typename
94 'alarmstationnum' => { label => 'Alarm Central Station',
95 type => 'select-alarm_station',
96 disable_inventory => 1,
97 value_callback => sub {
98 shift->alarm_station->stationname
104 'name' => 'Alarm service',
105 'sorts' => 'acctnum',
106 'display_weight' => 80,
107 'cancel_weight' => 85,
108 'fields' => \%fields,
109 'addl_process_fields' => [qw( alarmsystemnum_systemname
110 alarmtypenum_inputs alarmtypenum_outputs
111 alarmstationnum_stationname
118 $self->acctnum . '@'. $self->alarm_station->stationname. #?
119 ' ('. $self->alarm_system->systemname. ' '. $self->alarm_type->typename. ')'
124 my($class, $string) = @_;
125 $class->search_sql_field('acctnum', $string);
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.
144 sub preinsert_hook_first { shift->_inline_add(@_); }
145 sub prereplace_hook_first { shift->_inline_add(@_); }
150 my $agentnum = $self->cust_svc->cust_pkg->cust_main->agentnum;
152 if ( $self->alarmsystemnum == -1 ) {
153 my $alarm_system = new FS::alarm_system {
154 'agentnum' => $agentnum,
155 'systemname' => $self->alarmsystemnum_systemname,
157 my $error = $alarm_system->insert;
158 return $error if $error;
159 $self->alarmsystemnum($alarm_system->alarmsystemnum);
162 if ( $self->alarmtypenum == -1 ) {
163 my $alarm_type = new FS::alarm_type {
164 'agentnum' => $agentnum,
165 'inputs' => $self->alarmtypenum_inputs,
166 'outputs' => $self->alarmtypenum_outputs,
168 my $error = $alarm_type->insert;
169 return $error if $error;
170 $self->alarmtypenum($alarm_type->alarmtypenum);
173 if ( $self->alarmstationnum == -1 ) {
174 my $alarm_station = new FS::alarm_station {
175 'agentnum' => $agentnum,
176 'stationname' => $self->alarmstationnum_stationname,
178 my $error = $alarm_station->insert;
179 return $error if $error;
180 $self->alarmstationnum($alarm_station->alarmstationnum)
188 Checks all fields to make sure this is a valid service. If there is
189 an error, returns the error, otherwise returns false. Called by the insert
197 my $x = $self->setfixed;
198 return $x unless ref $x;
200 my $iso3166 = $self->cust_main->ship_location->country();
203 $self->ut_numbern('svcnum')
204 || $self->ut_text('acctnum')
205 || $self->ut_alphan('_password')
206 || $self->ut_textn('location')
207 || $self->ut_numbern('cs_receiver')
208 || $self->ut_phonen('cs_phonenum', $iso3166)
209 || $self->ut_alphan('serialnum')
210 || $self->ut_foreign_key('alarmsystemnum', 'alarm_system', 'systemnum')
211 || $self->ut_foreign_key('alarmtypenum', 'alarm_type', 'typenum')
212 || $self->ut_foreign_key('alarmstationnum', 'alarm_station', 'stationnum')
214 return $error if $error;
223 L<FS::Record>, L<FS::svc_Common>, schema.html from the base documentation.