initial svc_pbx implementation, RT#7051
[freeside.git] / FS / FS / svc_pbx.pm
1 package FS::svc_pbx;
2
3 use strict;
4 use base qw( FS::svc_External_Common );
5 #use FS::Record qw( qsearch qsearchs );
6 use FS::cust_svc;
7
8 =head1 NAME
9
10 FS::svc_pbx - Object methods for svc_pbx records
11
12 =head1 SYNOPSIS
13
14   use FS::svc_pbx;
15
16   $record = new FS::svc_pbx \%hash;
17   $record = new FS::svc_pbx { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27   $error = $record->suspend;
28
29   $error = $record->unsuspend;
30
31   $error = $record->cancel;
32
33 =head1 DESCRIPTION
34
35 An FS::svc_pbx object represents a PBX tenant.  FS::svc_pbx inherits from
36 FS::svc_Common.  The following fields are currently supported:
37
38 =over 4
39
40 =item field - description
41
42 =back
43
44 =head1 METHODS
45
46 =over 4
47
48 =item new HASHREF
49
50 Creates a new PBX tenant.  To add the PBX tenant to the database, see
51 L<"insert">.
52
53 Note that this stores the hash reference, not a distinct copy of the hash it
54 points to.  You can ask the object for a copy with the I<hash> method.
55
56 =cut
57
58 sub table { 'svc_pbx'; }
59
60 sub table_info {
61   {
62     'name' => 'PBX',
63     'name_plural' => 'PBXs', #optional,
64     'longname_plural' => 'PBXs', #optional
65     'sorts' => 'svcnum', # optional sort field (or arrayref of sort fields, main first)
66     'display_weight' => 70,
67     'cancel_weight'  => 90,
68     'fields' => {
69       'id'    => 'Thirdlane ID',
70       'title' => 'Description',
71       'max_extensions' => 'Maximum number of User Extensions',
72 #      'field'         => 'Description',
73 #      'another_field' => { 
74 #                           'label'     => 'Description',
75 #                          'def_label' => 'Description for service definitions',
76 #                          'type'      => 'text',
77 #                          'disable_default'   => 1, #disable switches
78 #                          'disable_fixed'     => 1, #
79 #                          'disable_inventory' => 1, #
80 #                        },
81 #      'foreign_key'   => { 
82 #                           'label'        => 'Description',
83 #                          'def_label'    => 'Description for service defs',
84 #                          'type'         => 'select',
85 #                          'select_table' => 'foreign_table',
86 #                          'select_key'   => 'key_field_in_table',
87 #                          'select_label' => 'label_field_in_table',
88 #                        },
89
90     },
91   };
92 }
93
94 =item search_sql STRING
95
96 Class method which returns an SQL fragment to search for the given string.
97
98 =cut
99
100 #XXX
101 #or something more complicated if necessary
102 #sub search_sql {
103 #  my($class, $string) = @_;
104 #  $class->search_sql_field('title', $string);
105 #}
106
107 =item label
108
109 Returns a meaningful identifier for this PBX tenant.
110
111 =cut
112
113 sub label {
114   my $self = shift;
115   $self->label_field; #or something more complicated if necessary
116 }
117
118 =item insert
119
120 Adds this record to the database.  If there is an error, returns the error,
121 otherwise returns false.
122
123 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be 
124 defined.  An FS::cust_svc record will be created and inserted.
125
126 =cut
127
128 sub insert {
129   my $self = shift;
130   my $error;
131
132   $error = $self->SUPER::insert;
133   return $error if $error;
134
135   '';
136 }
137
138 =item delete
139
140 Delete this record from the database.
141
142 =cut
143
144 sub delete {
145   my $self = shift;
146   my $error;
147
148   $error = $self->SUPER::delete;
149   return $error if $error;
150
151   '';
152 }
153
154
155 =item replace OLD_RECORD
156
157 Replaces the OLD_RECORD with this one in the database.  If there is an error,
158 returns the error, otherwise returns false.
159
160 =cut
161
162 sub replace {
163   my ( $new, $old ) = ( shift, shift );
164   my $error;
165
166   $error = $new->SUPER::replace($old);
167   return $error if $error;
168
169   '';
170 }
171
172 =item suspend
173
174 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
175
176 =item unsuspend
177
178 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
179
180 =item cancel
181
182 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
183
184 =item check
185
186 Checks all fields to make sure this is a valid PBX tenant.  If there is
187 an error, returns the error, otherwise returns false.  Called by the insert
188 and repalce methods.
189
190 =cut
191
192 sub check {
193   my $self = shift;
194
195   my $x = $self->setfixed;
196   return $x unless ref($x);
197   my $part_svc = $x;
198
199
200   $self->SUPER::check;
201 }
202
203 =back
204
205 =head1 BUGS
206
207 =head1 SEE ALSO
208
209 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
210 L<FS::cust_pkg>, schema.html from the base documentation.
211
212 =cut
213
214 1;
215