1 package FS::reason_type;
5 use FS::Record qw( qsearch qsearchs );
16 our %class_purpose = (
17 'C' => 'explain why a customer package was cancelled',
18 'R' => 'explain why a customer was credited',
19 'S' => 'explain why a customer package was suspended',
20 'X' => 'explain why a credit was voided',
25 FS::reason_type - Object methods for reason_type records
31 $record = new FS::reason_type \%hash;
32 $record = new FS::reason_type { 'column' => 'value' };
34 $error = $record->insert;
36 $error = $new_record->replace($old_record);
38 $error = $record->delete;
40 $error = $record->check;
44 An FS::reason_type object represents a grouping of reasons. FS::reason_type
45 inherits from FS::Record. The following fields are currently supported:
49 =item typenum - primary key
51 =item class - currently 'C', 'R', 'S' or 'X' for cancel, credit, suspend, refund or void credit
53 =item type - name of the type of reason
64 Creates a new reason_type. To add the example to the database, see L<"insert">.
66 Note that this stores the hash reference, not a distinct copy of the hash it
67 points to. You can ask the object for a copy with the I<hash> method.
71 sub table { 'reason_type'; }
75 Adds this record to the database. If there is an error, returns the error,
76 otherwise returns false.
82 Delete this record from the database.
86 =item replace OLD_RECORD
88 Replaces the OLD_RECORD with this one in the database. If there is an error,
89 returns the error, otherwise returns false.
95 Checks all fields to make sure this is a valid reason_type. If there is
96 an error, returns the error, otherwise returns false. Called by the insert
105 $self->ut_numbern('typenum')
106 || $self->ut_enum('class', [ keys %class_name ] )
107 || $self->ut_text('type')
109 return $error if $error;
116 Returns a list of all reasons associated with this type.
121 qsearch( 'reason', { 'reason_type' => shift->typenum } );
124 =item enabled_reasons
126 Returns a list of enabled reasons associated with this type.
130 sub enabled_reasons {
131 qsearch( 'reason', { 'reason_type' => shift->typenum,
136 # Used by FS::Setup to initialize a new database.
137 sub _populate_initial_data { # class method
138 my ($self, %opts) = @_;
140 my $conf = new FS::Conf;
142 foreach ( keys %class_name ) {
143 my $object = $self->new( {'class' => $_,
144 'type' => ucfirst($class_name{$_}). ' Reason',
146 my $error = $object->insert();
147 die "error inserting $self into database: $error\n"
151 my $object = qsearchs('reason_type', { 'class' => 'R' });
152 die "can't find credit reason type just inserted!\n"
155 foreach ( keys %FS::cust_credit::reasontype_map ) {
156 # my $object = $self->new( {'class' => 'R',
157 # 'type' => $FS::cust_credit::reasontype_map{$_},
159 # my $error = $object->insert();
160 # die "error inserting $self into database: $error\n"
162 $conf->set($_, $object->typenum);
169 # Used by FS::Upgrade to migrate to a new database.
170 sub _upgrade_data { # class method
171 my ($self, %opts) = @_;
173 foreach ( keys %class_name ) {
174 unless (scalar(qsearch('reason_type', { 'class' => $_ }))) {
175 my $object = $self->new( {'class' => $_,
176 'type' => ucfirst($class_name{$_}),
178 my $error = $object->insert();
179 die "error inserting $self into database: $error\n"
192 Here be termintes. Don't use on wooden computers.
196 L<FS::Record>, schema.html from the base documentation.