=item reason
Returns the text of the associated reason (see L<FS::reason>) for this credit /
-voided payment / voided invoice.
+voided payment / voided invoice. This can no longer be used to set the
+(deprecated) free-text "reason" field; see L<FS::reason/new_or_existing>.
=cut
return $reason_text;
}
-# it was a mistake to allow setting the reason this way; use
-# FS::reason->new_or_existing
-
# Used by FS::Upgrade to migrate reason text fields to reasonnum.
+# Note that any new tables that get reasonnum fields do NOT need to be
+# added here unless they have previously had a free-text "reason" field.
+
sub _upgrade_reasonnum { # class method
my $class = shift;
my $table = $class->table;
+ my $reason_class;
+ if ( $table eq 'cust_bill' or $table eq 'cust_bill_pkg' ) {
+ $reason_class = 'I';
+ } elsif ( $table eq 'cust_pay' ) {
+ $reason_class = 'P';
+ } elsif ( $table eq 'cust_refund' ) {
+ $reason_class = 'F';
+ } elsif ( $table eq 'cust_credit' ) {
+ $reason_class = 'R';
+ } else {
+ die "don't know the reason class to use for upgrading $table";
+ }
+
for my $fieldname (qw(reason void_reason)) {
+
+ if ( $table eq 'cust_credit' and $fieldname eq 'void_reason' ) {
+ $reason_class = 'X';
+ }
+
if ( defined dbdef->table($table)->column($fieldname)
&& defined dbdef->table($table)->column( $fieldname . 'num' ) )
{
@ISA = qw(FS::Record);
-our %class_name = (
+tie our %class_name, Tie::IxHash, (
'C' => 'cancel',
'R' => 'credit',
'S' => 'suspend',
'F' => 'refund',
- 'X' => 'void', # credit/invoice/payment
+ 'X' => 'void credit',
+ 'I' => 'void invoice',
+ 'P' => 'void payment',
);
our %class_purpose = (
'R' => 'explain why a customer was credited',
'S' => 'explain why a customer package was suspended',
'F' => 'explain why a customer was refunded',
- 'X' => 'explain why a transaction was voided',
+ 'X' => 'explain why a credit was voided',
+ 'I' => 'explain why an invoice was voided',
+ 'P' => 'explain why a payment was voided',
+);
+
+our %class_add_access_right = (
+ 'C' => 'Add on-the-fly cancel reason',
+ 'R' => 'Add on-the-fly credit reason',
+ 'S' => 'Add on-the-fly suspend reason',
+ 'F' => 'Add on-the-fly refund reason',
+ 'X' => 'Add on-the-fly void reason',
+ 'I' => 'Add on-the-fly void reason',
+ 'P' => 'Add on-the-fly void reason',
);
=head1 NAME
=item typenum - primary key
-=item class - currently 'C', 'R', 'S', 'F' or 'X' for cancel, credit, suspend, refund or void credit
+=item class - one of the keys of %class_name
=item type - name of the type of reason
#required
'field' => 'reasonnum',
- 'reason_class' => 'C', # currently 'C', 'R', 'F', 'S' or 'X'
- # for cancel, credit, refund, suspend or void credit
+ 'reason_class' => 'C', # one of those in %FS::reason_type::class_name
#recommended
'cgi' => $cgi, #easiest way for things to be properly "sticky" on errors
my $id = $opt{'id'} || $name;
$id =~ s/\./_/g; # for edit/part_event
-my $add_access_right;
-if ($class eq 'C') {
- $add_access_right = 'Add on-the-fly cancel reason';
-} elsif ($class eq 'S') {
- $add_access_right = 'Add on-the-fly suspend reason';
-} elsif ($class eq 'R') {
- $add_access_right = 'Add on-the-fly credit reason';
-} elsif ($class eq 'F') {
- $add_access_right = 'Add on-the-fly refund reason';
-} elsif ($class eq 'X') {
- $add_access_right = 'Add on-the-fly void reason';
-} else {
- die "illegal class: $class";
-}
+my $add_access_right = $FS::reason_type::class_add_access_right{$class}
+ or die "unknown class: $class";
my @reasons = qsearch({
'table' => 'reason',
<% ntable("#cccccc", 2) %>
<& /elements/tr-select-reason.html,
'field' => 'reasonnum',
- 'reason_class' => 'X',
+ 'reason_class' => 'I',
'cgi' => $cgi
&>
<TABLE BGCOLOR="#cccccc" BORDER="0" CELLSPACING="2" STYLE="margin-left:auto; margin-right:auto">
<& /elements/tr-select-reason.html,
'field' => 'reasonnum',
- 'reason_class' => 'X',
+ 'reason_class' => 'P',
'cgi' => $cgi
&>
</TABLE>