1 package FS::reason_type;
5 use FS::Record qw( qsearch qsearchs );
15 our %class_purpose = (
16 'C' => 'explain why a customer package was cancelled',
17 'R' => 'explain why a customer was credited',
18 'S' => 'explain why a customer package was suspended',
23 FS::reason_type - Object methods for reason_type records
29 $record = new FS::reason_type \%hash;
30 $record = new FS::reason_type { 'column' => 'value' };
32 $error = $record->insert;
34 $error = $new_record->replace($old_record);
36 $error = $record->delete;
38 $error = $record->check;
42 An FS::reason_type object represents a grouping of reasons. FS::reason_type
43 inherits from FS::Record. The following fields are currently supported:
47 =item typenum - primary key
49 =item class - currently 'C', 'R', or 'S' for cancel, credit, or suspend
51 =item type - name of the type of reason
62 Creates a new reason_type. To add the example to the database, see L<"insert">.
64 Note that this stores the hash reference, not a distinct copy of the hash it
65 points to. You can ask the object for a copy with the I<hash> method.
69 sub table { 'reason_type'; }
73 Adds this record to the database. If there is an error, returns the error,
74 otherwise returns false.
80 Delete this record from the database.
84 =item replace OLD_RECORD
86 Replaces the OLD_RECORD with this one in the database. If there is an error,
87 returns the error, otherwise returns false.
93 Checks all fields to make sure this is a valid reason_type. If there is
94 an error, returns the error, otherwise returns false. Called by the insert
103 $self->ut_numbern('typenum')
104 || $self->ut_enum('class', [ keys %class_name ] )
105 || $self->ut_text('type')
107 return $error if $error;
114 Returns a list of all reasons associated with this type.
119 qsearch( 'reason', { 'reason_type' => shift->typenum } );
122 =item enabled_reasons
124 Returns a list of enabled reasons associated with this type.
128 sub enabled_reasons {
129 qsearch( 'reason', { 'reason_type' => shift->typenum,
134 # _populate_initial_data
136 # Used by FS::Setup to initialize a new database.
140 sub _populate_initial_data { # class method
141 my ($self, %opts) = @_;
143 my $conf = new FS::Conf;
145 foreach ( keys %class_name ) {
146 my $object = $self->new( {'class' => $_,
147 'type' => ucfirst($class_name{$_}). ' Reason',
149 my $error = $object->insert();
150 die "error inserting $self into database: $error\n"
154 my $object = qsearchs('reason_type', { 'class' => 'R' });
155 die "can't find credit reason type just inserted!\n"
158 foreach ( keys %FS::cust_credit::reasontype_map ) {
159 # my $object = $self->new( {'class' => 'R',
160 # 'type' => $FS::cust_credit::reasontype_map{$_},
162 # my $error = $object->insert();
163 # die "error inserting $self into database: $error\n"
165 # # or clause for 1.7.x
166 $conf->set($_, $object->typenum)
167 or die "failed setting config";
176 # Used by FS::Upgrade to migrate to a new database.
180 sub _upgrade_data { # class method
181 my ($self, %opts) = @_;
183 foreach ( keys %class_name ) {
184 unless (scalar(qsearch('reason_type', { 'class' => $_ }))) {
185 my $object = $self->new( {'class' => $_,
186 'type' => ucfirst($class_name{$_}),
188 my $error = $object->insert();
189 die "error inserting $self into database: $error\n"
202 Here be termintes. Don't use on wooden computers.
206 L<FS::Record>, schema.html from the base documentation.