RT#42393: Verification cust_pay_pending handling in history & report
[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                            'disable_select'    => 1, #
77                          },
78       'foreign_key'   => { 
79                            'label'        => 'Description',
80                            'def_label'    => 'Description for service defs',
81                            'type'         => 'select',
82                            'select_table' => 'foreign_table',
83                            'select_key'   => 'key_field_in_table',
84                            'select_label' => 'label_field_in_table',
85                          },
86
87     },
88   };
89 }
90
91 =item search_sql STRING
92
93 Class method which returns an SQL fragment to search for the given string.
94
95 =cut
96
97 #or something more complicated if necessary
98 sub search_sql {
99   my($class, $string) = @_;
100   $class->search_sql_field('search_field', $string);
101 }
102
103 =item label
104
105 Returns a meaningful identifier for this example
106
107 =cut
108
109 sub label {
110   my $self = shift;
111   $self->label_field; #or something more complicated if necessary
112 }
113
114 =item insert
115
116 Adds this record to the database.  If there is an error, returns the error,
117 otherwise returns false.
118
119 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be 
120 defined.  An FS::cust_svc record will be created and inserted.
121
122 =cut
123
124 sub insert {
125   my $self = shift;
126   my $error;
127
128   $error = $self->SUPER::insert;
129   return $error if $error;
130
131   '';
132 }
133
134 =item delete
135
136 Delete this record from the database.
137
138 =cut
139
140 sub delete {
141   my $self = shift;
142   my $error;
143
144   $error = $self->SUPER::delete;
145   return $error if $error;
146
147   '';
148 }
149
150
151 =item replace OLD_RECORD
152
153 Replaces the OLD_RECORD with this one in the database.  If there is an error,
154 returns the error, otherwise returns false.
155
156 =cut
157
158 sub replace {
159   my ( $new, $old ) = ( shift, shift );
160   my $error;
161
162   $error = $new->SUPER::replace($old);
163   return $error if $error;
164
165   '';
166 }
167
168 =item suspend
169
170 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
171
172 =item unsuspend
173
174 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
175
176 =item cancel
177
178 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
179
180 =item check
181
182 Checks all fields to make sure this is a valid example.  If there is
183 an error, returns the error, otherwise returns false.  Called by the insert
184 and repalce methods.
185
186 =cut
187
188 sub check {
189   my $self = shift;
190
191   my $x = $self->setfixed;
192   return $x unless ref($x);
193   my $part_svc = $x;
194
195
196   $self->SUPER::check;
197 }
198
199 =back
200
201 =head1 BUGS
202
203 The author forgot to customize this manpage.
204
205 =head1 SEE ALSO
206
207 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
208 L<FS::cust_pkg>, schema.html from the base documentation.
209
210 =cut
211
212 1;
213