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 'alarmsystemnum' => { label => 'Alarm System Vendor',
78 type => 'select-alarm_system',
79 disable_inventory => 1,
80 value_callback => sub {
81 shift->alarm_system->systemname
84 'alarmtypenum' => { label => 'Alarm System Type',
85 type => 'select-alarm_type',
86 disable_inventory => 1,
87 value_callback => sub {
88 shift->alarm_type->typename
91 'alarmstationnum' => { label => 'Alarm Central Station',
92 type => 'select-alarm_station',
93 disable_inventory => 1,
94 value_callback => sub {
95 shift->alarm_station->stationname
101 'name' => 'Alarm service',
102 'sorts' => 'acctnum',
103 'display_weight' => 80,
104 'cancel_weight' => 85,
105 'fields' => \%fields,
106 'addl_process_fields' => [qw( alarmsystemnum_systemname
107 alarmtypenum_inputs alarmtypenum_outputs
108 alarmstationnum_stationname
115 $self->acctnum . '@'. $self->alarm_station->stationname. #?
116 ' ('. $self->alarm_system->systemname. ' '. $self->alarm_type->typename. ')'
121 my($class, $string) = @_;
122 $class->search_sql_field('acctnum', $string);
127 Adds this record to the database. If there is an error, returns the error,
128 otherwise returns false.
132 Delete this record from the database.
134 =item replace OLD_RECORD
136 Replaces the OLD_RECORD with this one in the database. If there is an error,
137 returns the error, otherwise returns false.
141 sub preinsert_hook_first { shift->_inline_add(@_); }
142 sub prereplace_hook_first { shift->_inline_add(@_); }
147 my $agentnum = $self->cust_svc->cust_pkg->cust_main->agentnum;
149 if ( $self->alarmsystemnum == -1 ) {
150 my $alarm_system = new FS::alarm_system {
151 'agentnum' => $agentnum,
152 'systemname' => $self->alarmsystemnum_systemname,
154 my $error = $alarm_system->insert;
155 return $error if $error;
156 $self->alarmsystemnum($alarm_system->alarmsystemnum);
159 if ( $self->alarmtypenum == -1 ) {
160 my $alarm_type = new FS::alarm_type {
161 'agentnum' => $agentnum,
162 'inputs' => $self->alarmtypenum_inputs,
163 'outputs' => $self->alarmtypenum_outputs,
165 my $error = $alarm_type->insert;
166 return $error if $error;
167 $self->alarmtypenum($alarm_type->alarmtypenum);
170 if ( $self->alarmstationnum == -1 ) {
171 my $alarm_station = new FS::alarm_station {
172 'agentnum' => $agentnum,
173 'stationname' => $self->alarmstationnum_stationname,
175 my $error = $alarm_station->insert;
176 return $error if $error;
177 $self->alarmstationnum($alarm_station->alarmstationnum)
185 Checks all fields to make sure this is a valid service. If there is
186 an error, returns the error, otherwise returns false. Called by the insert
194 my $x = $self->setfixed;
195 return $x unless ref $x;
198 $self->ut_numbern('svcnum')
199 || $self->ut_text('acctnum')
200 || $self->ut_alphan('_password')
201 || $self->ut_textn('location')
202 || $self->ut_foreign_key('alarmsystemnum', 'alarm_system', 'systemnum')
203 || $self->ut_foreign_key('alarmtypenum', 'alarm_type', 'typenum')
204 || $self->ut_foreign_key('alarmstationnum', 'alarm_station', 'stationnum')
206 return $error if $error;
215 L<FS::Record>, L<FS::svc_Common>, schema.html from the base documentation.