From 2c6b7c910668dc09dff9ec34b169a240850f16c0 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 4 Dec 2007 18:19:08 +0000 Subject: change credit reasons from freetext to new reason/reason type system (#2777) --- httemplate/browse/reason.html | 10 +++----- httemplate/browse/reason_type.html | 6 +---- httemplate/edit/cust_credit.cgi | 7 ++---- httemplate/edit/elements/edit.html | 16 ++++++++++--- httemplate/edit/process/cust_credit.cgi | 38 +++++++++++++++++++++++++------ httemplate/edit/reason.html | 5 +--- httemplate/edit/reason_type.html | 6 +---- httemplate/elements/menu.html | 2 ++ httemplate/elements/tr-select-reason.html | 28 +++++++++++++++++++++-- 9 files changed, 80 insertions(+), 38 deletions(-) (limited to 'httemplate') diff --git a/httemplate/browse/reason.html b/httemplate/browse/reason.html index b017f8f58..5df94b2f3 100644 --- a/httemplate/browse/reason.html +++ b/httemplate/browse/reason.html @@ -36,14 +36,10 @@ die "access denied" $cgi->param('class') =~ /^(\w)$/ or die "illegal class"; my $class = $1; -my %classmap = ( 'C' => 'cancel', - 'S' => 'suspend', - ); +my $classname = $FS::reason_type::class_name{$class};; +my $classpurpose = $FS::reason_type::class_purpose{$class};; -my $classname = $classmap{$class}; - -my $html_init = ucfirst($classname) . -" reasons explain why we $classname a package.

". +my $html_init = ucfirst($classname). " reasons $classpurpose.

". qq!!. "Add a $classname reason

"; diff --git a/httemplate/browse/reason_type.html b/httemplate/browse/reason_type.html index 09f451c9f..6b444bad1 100644 --- a/httemplate/browse/reason_type.html +++ b/httemplate/browse/reason_type.html @@ -33,11 +33,7 @@ die "access denied" $cgi->param('class') =~ /^(\w)$/ or die "illegal class"; my $class=$1; -my %classmap = ( 'C' => 'cancel', - 'S' => 'suspend', - ); - -my $classname = $classmap{$class}; +my $classname = $FS::reason_type::class_name{$class}; my $html_init = ucfirst($classname) . " reason types allow groups of $classname reasons for reporting purposes." . diff --git a/httemplate/edit/cust_credit.cgi b/httemplate/edit/cust_credit.cgi index 13d062c74..b6924f4d9 100755 --- a/httemplate/edit/cust_credit.cgi +++ b/httemplate/edit/cust_credit.cgi @@ -5,7 +5,7 @@

% } -
+ @@ -30,10 +30,7 @@ Credit %#print qq! Also post refund!; % - - Reason - - +<% include('/elements/tr-select-reason.html', 'reasonnum', 'R', '', '', '', 'document.credit_popup.submit',) %> Auto-apply
to invoices diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 17c5ad3eb..22143a3f0 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -187,12 +187,20 @@ % } elsif ( $type eq 'select' ) { +% +% my $aref = $f->{'value'}{'values'}; +% my $vkey = $f->{'value'}{'vcolumn'}; +% my $ckey = $f->{'value'}{'ccolumn'}; +% +% if (scalar(@$aref) == 1) { + + <% @$aref[0]->$ckey %> + + +% }else{ +% } + % } else { diff --git a/httemplate/edit/process/cust_credit.cgi b/httemplate/edit/process/cust_credit.cgi index 19faca47a..9dcad7f68 100755 --- a/httemplate/edit/process/cust_credit.cgi +++ b/httemplate/edit/process/cust_credit.cgi @@ -3,16 +3,39 @@ %$cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!"; %my $custnum = $1; % -%my $new = new FS::cust_credit ( { -% map { -% $_, scalar($cgi->param($_)); -% } fields('cust_credit') -%} ); -% -%my $error = $new->insert; +%$cgi->param('reasonnum') =~ /^(-?\d+)$/ or die "Illegal reasonnum"; +%my $reasonnum = $1; +% +%my $oldAutoCommit = $FS::UID::AutoCommit; +%local $FS::UID::AutoCommit = 0; +%my $dbh = dbh; +% +%my $error = ''; +%if ($reasonnum == -1) { +% +% $error = 'Enter a new reason (or select an existing one)' +% unless $cgi->param('newreasonnum') !~ /^\s*$/; +% my $reason = new FS::reason({ 'reason_type' => $cgi->param('newreasonnumT'), +% 'reason' => $cgi->param('newreasonnum'), +% }); +% $error ||= $reason->insert; +% $cgi->param('reasonnum', $reason->reasonnum) +% unless $error; +%} +% +%unless ($error) { +% my $new = new FS::cust_credit ( { +% map { +% $_, scalar($cgi->param($_)); +% } fields('cust_credit') +% } ); +% $error = $new->insert; +%} % %if ( $error ) { +% $cgi->param('reasonnum', $reasonnum); % $cgi->param('error', $error); +% $dbh->rollback if $oldAutoCommit; % % <% $cgi->redirect(popurl(2). "cust_credit.cgi?". $cgi->query_string ) %> @@ -27,6 +50,7 @@ % } % #print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum"); % +% $dbh->commit or die $dbh->errstr if $oldAutoCommit; % <% header('Credit sucessful') %>