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 'alarmsystemnum' => { label => 'Alarm System Vendor',
79 type => 'select-alarm_system',
80 disable_inventory => 1,
81 value_callback => sub {
82 shift->alarm_system->systemname
85 'alarmtypenum' => { label => 'Alarm System Type',
86 type => 'select-alarm_type',
87 disable_inventory => 1,
88 value_callback => sub {
89 shift->alarm_type->typename
92 'alarmstationnum' => { label => 'Alarm Central Station',
93 type => 'select-alarm_station',
94 disable_inventory => 1,
95 value_callback => sub {
96 shift->alarm_station->stationname
102 'name' => 'Alarm service',
103 'sorts' => 'acctnum',
104 'display_weight' => 80,
105 'cancel_weight' => 85,
106 'fields' => \%fields,
107 'addl_process_fields' => [qw( alarmsystemnum_systemname
108 alarmtypenum_inputs alarmtypenum_outputs
109 alarmstationnum_stationname
116 $self->acctnum . '@'. $self->alarm_station->stationname. #?
117 ' ('. $self->alarm_system->systemname. ' '. $self->alarm_type->typename. ')'
122 my($class, $string) = @_;
123 $class->search_sql_field('acctnum', $string);
128 Adds this record to the database. If there is an error, returns the error,
129 otherwise returns false.
133 Delete this record from the database.
135 =item replace OLD_RECORD
137 Replaces the OLD_RECORD with this one in the database. If there is an error,
138 returns the error, otherwise returns false.
142 sub preinsert_hook_first { shift->_inline_add(@_); }
143 sub prereplace_hook_first { shift->_inline_add(@_); }
148 my $agentnum = $self->cust_svc->cust_pkg->cust_main->agentnum;
150 if ( $self->alarmsystemnum == -1 ) {
151 my $alarm_system = new FS::alarm_system {
152 'agentnum' => $agentnum,
153 'systemname' => $self->alarmsystemnum_systemname,
155 my $error = $alarm_system->insert;
156 return $error if $error;
157 $self->alarmsystemnum($alarm_system->alarmsystemnum);
160 if ( $self->alarmtypenum == -1 ) {
161 my $alarm_type = new FS::alarm_type {
162 'agentnum' => $agentnum,
163 'inputs' => $self->alarmtypenum_inputs,
164 'outputs' => $self->alarmtypenum_outputs,
166 my $error = $alarm_type->insert;
167 return $error if $error;
168 $self->alarmtypenum($alarm_type->alarmtypenum);
171 if ( $self->alarmstationnum == -1 ) {
172 my $alarm_station = new FS::alarm_station {
173 'agentnum' => $agentnum,
174 'stationname' => $self->alarmstationnum_stationname,
176 my $error = $alarm_station->insert;
177 return $error if $error;
178 $self->alarmstationnum($alarm_station->alarmstationnum)
186 Checks all fields to make sure this is a valid service. If there is
187 an error, returns the error, otherwise returns false. Called by the insert
195 my $x = $self->setfixed;
196 return $x unless ref $x;
199 $self->ut_numbern('svcnum')
200 || $self->ut_text('acctnum')
201 || $self->ut_alphan('_password')
202 || $self->ut_textn('location')
203 || $self->ut_foreign_key('alarmsystemnum', 'alarm_system', 'systemnum')
204 || $self->ut_foreign_key('alarmtypenum', 'alarm_type', 'typenum')
205 || $self->ut_foreign_key('alarmstationnum', 'alarm_station', 'stationnum')
207 return $error if $error;
213 qsearchs('alarm_system', { alarmsystemnum => shift->alarmsystemnum } );
216 qsearchs('alarm_type', { alarmtypenum => shift->alarmtypenum } );
219 qsearchs('alarm_station', { alarmstationnum => shift->alarmstationnum } );
226 L<FS::Record>, L<FS::svc_Common>, schema.html from the base documentation.