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