From 3cda3a85eb0daa5b8b9f4d30cd0896da6ccf4a9b Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 25 Nov 2014 19:39:23 -0800 Subject: option to credit unused time on suspension as part of suspend reason, #31702 --- httemplate/misc/cancel_cust.html | 2 +- httemplate/misc/cancel_pkg.html | 6 +++--- httemplate/misc/cust_main-cancel.cgi | 30 ++++++++++---------------- httemplate/misc/cust_main-suspend.cgi | 37 ++++++++++++--------------------- httemplate/misc/process/cancel_pkg.html | 19 +++++++---------- httemplate/misc/process/elements/reason | 17 +++++++++++++++ httemplate/misc/suspend_cust.html | 2 +- 7 files changed, 53 insertions(+), 60 deletions(-) create mode 100644 httemplate/misc/process/elements/reason (limited to 'httemplate/misc') diff --git a/httemplate/misc/cancel_cust.html b/httemplate/misc/cancel_cust.html index 3259a03f6..e4bfdba76 100644 --- a/httemplate/misc/cancel_cust.html +++ b/httemplate/misc/cancel_cust.html @@ -50,7 +50,7 @@ STYLE="margin-left:auto; margin-right:auto"> 'field' => 'reasonnum', 'reason_class' => 'C', 'cgi' => $cgi, - 'control_button' => "document.getElementById('confirm_cancel_cust_button')", + 'control_button' => 'confirm_cancel_cust_button', &> diff --git a/httemplate/misc/cancel_pkg.html b/httemplate/misc/cancel_pkg.html index e2734e97d..c80b2b278 100755 --- a/httemplate/misc/cancel_pkg.html +++ b/httemplate/misc/cancel_pkg.html @@ -6,9 +6,9 @@ -

+
<% emt(ucfirst($method)." [_1]", $part_pkg->pkg_comment(cust_pkg=>$cust_pkg) ) %> -<% ntable("#cccccc", 2) %> + % my $date_init = 0; % if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') { @@ -58,7 +58,7 @@ field => 'reasonnum', reason_class => $class, curr_value => $reasonnum, - control_button => "document.getElementById('confirm_cancel_pkg_button')", + control_button => "confirm_cancel_pkg_button", &> % } diff --git a/httemplate/misc/cust_main-cancel.cgi b/httemplate/misc/cust_main-cancel.cgi index 2ae9f1021..a78a8b3dc 100755 --- a/httemplate/misc/cust_main-cancel.cgi +++ b/httemplate/misc/cust_main-cancel.cgi @@ -22,51 +22,43 @@ if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { $custnum = $1; } -#false laziness w/process/cancel_pkg.html -#untaint reasonnum -my $reasonnum = $cgi->param('reasonnum'); -$reasonnum =~ /^(-?\d+)$/ || die "Illegal reasonnum"; -$reasonnum = $1; - -if ($reasonnum == -1) { - $reasonnum = { - 'typenum' => scalar( $cgi->param('newreasonnumT') ), - 'reason' => scalar( $cgi->param('newreasonnum' ) ), - }; +#untaint reasonnum / create new reason +my ($reasonnum, $error) = $m->comp('process/elements/reason'); +if (!$reasonnum) { + $error ||= 'Reason required' } -#eslaf - my $cust_main = qsearchs( { 'table' => 'cust_main', 'hashref' => { 'custnum' => $custnum }, 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, } ); -my @errors; -if($cgi->param('now_or_later')) { +if ( $error ) { + # do nothing +} elsif ( $cgi->param('now_or_later') ) { $expire = parse_datetime($expire); if($expire) { #warn "setting expire dates on custnum#$custnum\n"; my @pkgs = $cust_main->ncancelled_pkgs; - @errors = grep {$_} map { $_->cancel( + my @errors = grep {$_} map { $_->cancel( 'reason' => $reasonnum, 'date' => $expire, ) } @pkgs; + $error = join(' / ', @errors); } else { - @errors = ("error parsing expire date: ".$cgi->param('expire')); + $error = ("error parsing expire date: ".$cgi->param('expire')); } } else { warn "cancelling $cust_main"; - @errors = $cust_main->cancel( + $error = $cust_main->cancel( 'ban' => $ban, 'reason' => $reasonnum, ); } -my $error = join(' / ', @errors) if scalar(@errors); if ( $error ) { $cgi->param('error', $error); diff --git a/httemplate/misc/cust_main-suspend.cgi b/httemplate/misc/cust_main-suspend.cgi index 61851364e..7a501d61a 100755 --- a/httemplate/misc/cust_main-suspend.cgi +++ b/httemplate/misc/cust_main-suspend.cgi @@ -22,50 +22,39 @@ if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { $custnum = $1; } -#false laziness w/process/cancel_pkg.html - -#untaint reasonnum -my $reasonnum = $cgi->param('reasonnum'); -$reasonnum =~ /^(-?\d+)$/ || die "Illegal reasonnum"; -$reasonnum = $1; - -if ($reasonnum == -1) { - $reasonnum = { - 'typenum' => scalar( $cgi->param('newreasonnumT') ), - 'reason' => scalar( $cgi->param('newreasonnum' ) ), - }; +#untaint reasonnum / create new reason +my ($reasonnum, $error) = $m->comp('process/elements/reason'); +if (!$reasonnum) { + $error ||= 'Reason required'; } -#eslaf - my $cust_main = qsearchs( { 'table' => 'cust_main', 'hashref' => { 'custnum' => $custnum }, 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, } ); -my @errors; -if($cgi->param('now_or_later')) { +if ( $error ) { + # do nothing +} elsif ( $cgi->param('now_or_later') ) { $adjourn = parse_datetime($adjourn); if($adjourn) { #warn "setting adjourn dates on custnum#$custnum\n"; my @pkgs = $cust_main->unsuspended_pkgs; - @errors = grep {$_} map { $_->suspend( + my @errors = grep {$_} map { $_->suspend( 'reason' => $reasonnum, 'date' => $adjourn, ) } @pkgs; + $error = join(' / ', @errors); + } else { + $error = ("error parsing adjourn date: ".$cgi->param('adjourn')); } - else { - @errors = ("error parsing adjourn date: ".$cgi->param('adjourn')); - } -} -else { +} else { warn "suspending $cust_main"; - @errors = $cust_main->suspend( + $error = $cust_main->suspend( 'reason' => $reasonnum, ); } -my $error = join(' / ', @errors) if scalar(@errors); if ( $error ) { $cgi->param('error', $error); diff --git a/httemplate/misc/process/cancel_pkg.html b/httemplate/misc/process/cancel_pkg.html index a106b845a..47ceca23b 100755 --- a/httemplate/misc/process/cancel_pkg.html +++ b/httemplate/misc/process/cancel_pkg.html @@ -65,17 +65,12 @@ if ( $method eq 'suspend' ) { #or 'adjourn' my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} ); -#untaint reasonnum -my $reasonnum = $cgi->param('reasonnum'); -if ( $method !~ /^(unsuspend|uncancel)$/ ) { - $reasonnum =~ /^(-?\d+)$/ or die "Illegal reasonnum"; - $reasonnum = $1; - - if ($reasonnum == -1) { - $reasonnum = { - 'typenum' => scalar( $cgi->param('newreasonnumT') ), - 'reason' => scalar( $cgi->param('newreasonnum' ) ), - }; +#untaint reasonnum, and set up new reason if appropriate +my ($reasonnum, $error); +if ($method ne 'resume' and $method ne 'uncancel') { + ($reasonnum, $error) = $m->comp('elements/reason'); + if (!$reasonnum) { + $error ||= 'Reason required'; } } @@ -87,7 +82,7 @@ my $bill = my $svc_fatal = ( $cgi->param('svc_not_fatal') ne 'Y' ); -my $error = $cust_pkg->$method( 'reason' => $reasonnum, +$error ||= $cust_pkg->$method( 'reason' => $reasonnum, 'date' => $date, 'resume_date' => $resume_date, 'last_bill' => $last_bill, diff --git a/httemplate/misc/process/elements/reason b/httemplate/misc/process/elements/reason new file mode 100644 index 000000000..ae92a7528 --- /dev/null +++ b/httemplate/misc/process/elements/reason @@ -0,0 +1,17 @@ +<%init> +#untaint reasonnum, and set up new reason if appropriate +my $reasonnum = $cgi->param('reasonnum'); +$reasonnum =~ /^(-?\d+)$/ or die "Illegal reasonnum"; +$reasonnum = $1; + +my $error; +if ($reasonnum == -1) { + my $new_reason = FS::reason->new({ + map { $_ => scalar( $cgi->param("reasonnum_new_$_") ) } + qw( reason_type reason unsuspend_pkgpart unsuspend_hold unused_credit ) + }); # not sanitizing them here, but check() will do it + $error = $new_reason->insert; + $reasonnum = $new_reason->reasonnum; +} +return ($reasonnum, $error); + diff --git a/httemplate/misc/suspend_cust.html b/httemplate/misc/suspend_cust.html index e0d17f30b..3a49e136d 100644 --- a/httemplate/misc/suspend_cust.html +++ b/httemplate/misc/suspend_cust.html @@ -42,7 +42,7 @@ STYLE="margin-left:auto; margin-right:auto"> 'field' => 'reasonnum', 'reason_class' => 'S', 'cgi' => $cgi, - 'control_button' => "document.getElementById('confirm_suspend_cust_button')", + 'control_button' => 'confirm_suspend_cust_button', &>
-- cgit v1.2.1