alarm systems, types, central stations, RT#25994
[freeside.git] / FS / FS / svc_alarm.pm
1 package FS::svc_alarm;
2
3 use strict;
4 use base qw( FS::svc_Common );
5 use Tie::IxHash;
6 use FS::Record qw( qsearchs ); # qw( qsearch qsearchs );
7 use FS::alarm_system;
8 use FS::alarm_type;
9 use FS::alarm_station;
10
11 =head1 NAME
12
13 FS::svc_alarm - Object methods for svc_alarm records
14
15 =head1 SYNOPSIS
16
17   use FS::svc_alarm;
18
19   $record = new FS::svc_alarm \%hash;
20   $record = new FS::svc_alarm { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::svc_alarm object represents an alarm service.  FS::svc_alarm inherits
33 from FS::svc_Common.
34
35 The following fields are currently supported:
36
37 =over 4
38
39 =item svcnum - Primary key
40
41 =item alarmsystemnum - Alarm System Vendor (see L<FS::alarm_system>)
42
43 =item alarmtypenum - Alarm System Type (inputs/outputs) (see L<FS::alarm_type>)
44
45 =item alarmstationnum - Alarm central station (see L<FS::alarm_station>)
46
47 =item acctnum - Account number
48
49 =item _password - Password
50
51 =item location - Location on property
52
53 =back
54
55 =head1 METHODS
56
57 =over 4
58
59 =item new HASHREF
60
61 Creates a new svc_dish object.
62
63 =cut
64
65 sub table { 'svc_alarm'; }
66
67 sub table_info {
68   my %opts = ( 'type' => 'text', 
69                #'disable_select' => 1,
70                'disable_inventory' => 1,
71              );
72
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
83                            },
84                          },
85     'alarmtypenum'    => { label => 'Alarm System Type',
86                            type  => 'select-alarm_type',
87                            disable_inventory => 1,
88                            value_callback    => sub {
89                              shift->alarm_type->typename
90                            },
91                          },
92     'alarmstationnum' => { label => 'Alarm Central Station',
93                            type  => 'select-alarm_station',
94                            disable_inventory => 1,
95                            value_callback    => sub {
96                              shift->alarm_station->stationname
97                            },
98                          },
99   ;
100
101   {
102     'name'           => 'Alarm service',
103     'sorts'          => 'acctnum',
104     'display_weight' => 80,
105     'cancel_weight'  => 85,
106     'fields'         => \%fields,
107
108   };
109 }
110
111 sub label {
112   my $self = shift;
113   $self->acctnum . '@'. $self->alarm_station->stationname. #?
114     ' ('. $self->alarm_system->systemname. ' '. $self->alarm_type->typename. ')'
115   ;
116 }
117
118 sub search_sql {
119   my($class, $string) = @_;
120   $class->search_sql_field('acctnum', $string);
121 }
122
123 =item insert
124
125 Adds this record to the database.  If there is an error, returns the error,
126 otherwise returns false.
127
128 =item delete
129
130 Delete this record from the database.
131
132 =item replace OLD_RECORD
133
134 Replaces the OLD_RECORD with this one in the database.  If there is an error,
135 returns the error, otherwise returns false.
136
137 =item check
138
139 Checks all fields to make sure this is a valid service.  If there is
140 an error, returns the error, otherwise returns false.  Called by the insert
141 and replace methods.
142
143 =cut
144
145 sub check {
146   my $self = shift;
147
148   my $x = $self->setfixed;
149   return $x unless ref $x;
150
151   my $error = 
152     $self->ut_numbern('svcnum')
153     || $self->ut_text('acctnum')
154     || $self->ut_alphan('_password')
155     || $self->ut_textn('location')
156     || $self->ut_foreign_key('alarmsystemnum',  'alarm_system',  'systemnum')
157     || $self->ut_foreign_key('alarmtypenum',    'alarm_type',    'typenum')
158     || $self->ut_foreign_key('alarmstationnum', 'alarm_station', 'stationnum')
159   ;
160   return $error if $error;
161
162   $self->SUPER::check;
163 }
164
165 sub alarm_system  { qsearchs('alarm_system', {systemnum =>shift->systemnum } ) }
166 sub alarm_type    { qsearchs('alarm_type',   {typenum   =>shift->systemnum } ) }
167 sub alarm_station { qsearchs('alarm_station',{stationnum=>shift->stationnum} ) }
168
169 =back
170
171 =head1 SEE ALSO
172
173 L<FS::Record>, L<FS::svc_Common>, schema.html from the base documentation.
174
175 =cut
176
177 1;
178