sub _upgrade_data { # class method
my ($class, %opts) = @_;
+ local $FS::payinfo_Mixin::ignore_masked_payinfo = 1;
+
$class->_upgrade_reasonnum(%opts);
my $sql = "SELECT usernum FROM access_user WHERE username = ( SELECT history_user FROM h_cust_pay_void WHERE paynum = ? AND history_action = 'insert' ORDER BY history_date LIMIT 1 ) ";
my $table = $class->table;
my $reason_class;
- if ( $table eq 'cust_bill' or $table eq 'cust_bill_pkg' ) {
+ if ( $table =~ /^cust_bill/ ) { # also includes cust_bill_pkg
$reason_class = 'I';
- } elsif ( $table eq 'cust_pay' ) {
+ } elsif ( $table =~ /^cust_pay/ ) {
$reason_class = 'P';
} elsif ( $table eq 'cust_refund' ) {
$reason_class = 'F';
- } elsif ( $table eq 'cust_credit' ) {
+ } elsif ( $table =~ /^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' ) {
+ if ( $table =~ /^cust_credit/ and $fieldname eq 'void_reason' ) {
$reason_class = 'X';
}
}
);
- if (
- scalar(
- grep { $_->getfield($fieldname) =~ /\S/ }
- @legacy_reason_records
- )
- )
- {
+ if ( @legacy_reason_records ) {
+
warn "$me Found unmigrated reasons\n" if $DEBUG;
my $reason_type =
- _upgrade_get_legacy_reason_type( $class, $table );
- my $noreason = _upgrade_get_no_reason( $class, $reason_type );
+ $class->_upgrade_get_legacy_reason_type( $reason_class );
+ # XXX "noreason" does not actually work, because we limited to
+ # "reason is not null" above. Records where the reason string
+ # is null will end up with a reasonnum of null also.
+ my $noreason = $class->_upgrade_get_no_reason( $reason_type );
foreach my $record_to_upgrade (@legacy_reason_records) {
my $reason = $record_to_upgrade->getfield($fieldname);
warn "Contemplating reason $reason\n" if $DEBUG > 1;
if ( $reason =~ /\S/ ) {
my $reason =
- _upgrade_get_reason( $class, $reason, $reason_type );
+ $class->_upgrade_get_reason( $reason, $reason_type );
$record_to_upgrade->set( $fieldname . 'num',
$reason->reasonnum );
}
}
}
+# internal methods for upgrade
+
# _upgrade_get_legacy_reason_type is class method supposed to be used only
# within the reason_Mixin class which will either find or create a reason_type
sub _upgrade_get_legacy_reason_type {
my $class = shift;
- my $table = shift;
-
- my $reason_class =
- ( $table =~ /void/ ) ? 'X' : 'F'; # see FS::reason_type (%class_name)
+ my $reason_class = shift;
my $reason_type_params = { 'class' => $reason_class, 'type' => 'Legacy' };
my $reason_type = qsearchs( 'reason_type', $reason_type_params );
unless ($reason_type) {
my $class = shift;
my $reason_type = shift;
- return _upgrade_get_reason( $class, '(none)', $reason_type );
+ return $class->_upgrade_get_reason( '(none)', $reason_type );
}
# _upgrade_get_reason is class method supposed to be used only within the
use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );
+use Tie::IxHash;
@ISA = qw(FS::Record);
-tie our %class_name, Tie::IxHash, (
+tie our %class_name, 'Tie::IxHash', (
'C' => 'cancel',
'R' => 'credit',
'S' => 'suspend',
'F' => 'refund',
- 'X' => 'void credit',
- 'I' => 'void invoice',
- 'P' => 'void payment',
+ 'X' => 'credit void',
+ 'I' => 'invoice void',
+ 'P' => 'payment void',
);
our %class_purpose = (
-<% include( 'elements/browse.html',
- 'title' => ucfirst($classname) . " Reason Types",
- 'menubar' => [ ucfirst($classname) . " reasons" =>
- $p.'browse/reason.html?class=' . $class,
- ],
- 'html_init' => $html_init,
- 'name' => $classname . " reason types",
- 'query' => { 'table' => 'reason_type',
- 'hashref' => {},
- 'extra_sql' => $where_clause .
- 'ORDER BY typenum',
- },
- 'count_query' => $count_query,
- 'header' => [ '#',
- ucfirst($classname) . ' Reason Type',
- ucfirst($classname) . ' Reasons',
- ],
- 'fields' => [ 'typenum',
- 'type',
- $reasons_sub,
- ],
- 'links' => [ $link,
- $link,
- '',
- ],
- )
-%>
+<& elements/browse.html,
+ 'title' => ucwords($classname) . " Reasons",
+ 'html_init' => $html_init,
+ 'name' => $classname . " reason types",
+ 'query' => { 'table' => 'reason_type',
+ 'hashref' => {},
+ 'extra_sql' => $where_clause .
+ 'ORDER BY typenum',
+ },
+ 'count_query' => $count_query,
+ 'header' => [ '#',
+ ucwords($classname) . ' Reason Type',
+ ucwords($classname) . ' Reasons',
+ ],
+ 'fields' => [ 'typenum',
+ 'type',
+ $reasons_sub,
+ ],
+ 'links' => [ $link,
+ $link,
+ '',
+ ],
+ 'disable_total' => 1,
+&>
<%init>
+sub ucwords {
+ join(' ', map ucfirst($_), split(/ /, shift));
+}
+
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
$cgi->param('class') =~ /^(\w)$/ or die "illegal class";
my $class=$1;
-my $classname = $FS::reason_type::class_name{$class};
+my $classname = ucfirst($FS::reason_type::class_name{$class});
+
+my $html_init = 'Reasons: ' .
+ include('/elements/menubar.html',
+ map {
+ ucfirst($FS::reason_type::class_name{$_}),
+ $p.'browse/reason_type.html?class=' . $_
+ } keys (%FS::reason_type::class_name)
+ );
-my $html_init = ucfirst($classname) .
- " reason types allow groups of $classname reasons for reporting purposes." .
- qq!<BR><BR><A HREF="${p}edit/reason_type.html?class=$class"><I>Add a ! .
- $classname . " reason type</I></A><BR><BR>";
+$html_init .= '<BR><P>' .
+ $classname . ' reasons ' .
+ $FS::reason_type::class_purpose{$class} .
+ '. Reason types allow reasons to be grouped for reporting purposes.' .
+ qq!<BR><BR><A HREF="${p}edit/reason_type.html?class=$class"><I>! .
+ ($classname =~ /^[aeiou]/i ? 'Add an ' : 'Add a ') .
+ lc($classname) . ' reason type</I></A>'.
+ '</P>';
my $reasons_sub = sub {
my $reason_type = shift;
- [ map {
+ [ ( map {
[
{
'data' => $_->reason,
},
];
}
- $reason_type->enabled_reasons,
+ $reason_type->enabled_reasons ),
+ [
+ {
+ 'data' => '(add)',
+ 'align' => 'left',
+ 'link' => $p. "edit/reason.html?class=$class",
+ 'data_style' => 'i',
+ }
+ ]
];
if $curuser->access_right('Configuration');
tie my %config_pkg_reason, 'Tie::IxHash',
- 'Cancel reasons' => [ $fsurl.'browse/reason.html?class=C', 'Cancel reasons explain why a service was cancelled.' ],
- 'Cancel reason types' => [ $fsurl.'browse/reason_type.html?class=C', 'Cancel reason types define groups of reasons.' ],
- 'Suspend reasons' => [ $fsurl.'browse/reason.html?class=S', 'Suspend reasons explain why a service was suspended.' ],
- 'Suspend reason types' => [ $fsurl.'browse/reason_type.html?class=S', 'Suspend reason types define groups of reasons.' ],
+ 'Cancel reasons' => [ $fsurl.'browse/reason_type.html?class=C', 'Cancel reasons explain why a service was cancelled.' ],
+ 'Suspend reasons' => [ $fsurl.'browse/reason_type.html?class=S', 'Suspend reasons explain why a service was suspended.' ],
;
tie my %config_pkg, 'Tie::IxHash', ();
}
$config_billing{'separator4'} = ''; #its a separator!
- $config_billing{'Credit reasons'} = [ $fsurl.'browse/reason.html?class=R', 'Credit reasons explain why a credit was issued.' ];
- $config_billing{'Credit reason types'} = [ $fsurl.'browse/reason_type.html?class=R', 'Credit reason types define groups of reasons.' ];
+ $config_billing{'Credit reasons'} = [ $fsurl.'browse/reason_type.html?class=R', 'Credit reasons explain why a credit was issued.' ];
- $config_billing{'separator5'} = ''; #its a separator!
- $config_billing{'Refund reasons'} = [ $fsurl.'browse/reason.html?class=F', 'Refund reasons explain why a refund was issued.' ];
- $config_billing{'Refund reason types'} = [ $fsurl.'browse/reason_type.html?class=F', 'Refund reason types define groups of reasons.' ];
+ $config_billing{'Refund reasons'} = [ $fsurl.'browse/reason_type.html?class=F', 'Refund reasons explain why a refund was issued.' ];
- $config_billing{'separator6'} = ''; #its a separator!
- $config_billing{'Void reasons'} = [ $fsurl.'browse/reason.html?class=X', 'Void reasons explain why a void was issued.' ];
- $config_billing{'Void reason types'} = [ $fsurl.'browse/reason_type.html?class=X', 'Void reason types define groups of reasons.' ];
+ $config_billing{'Invoice void reasons'} = [ $fsurl.'browse/reason_type.html?class=I', 'Invoice void reasons explain why an invoice was voided.' ];
+ $config_billing{'Payment void reasons'} = [ $fsurl.'browse/reason_type.html?class=P', 'Payment void reasons explain why a payment was voided.' ];
+ $config_billing{'Credit void reasons'} = [ $fsurl.'browse/reason_type.html?class=X', 'Credit void reasons explain why a credit was voided.' ];
}
#XXX also to be unified