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