diff options
author | Ivan Kohler <ivan@freeside.biz> | 2012-06-04 15:29:18 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2012-06-04 15:29:18 -0700 |
commit | 17b4664d50ba04809cb8b68fa0f3b6146b0c8ff3 (patch) | |
tree | 30c13e0648b51046e3eda9c8f77a615f9e254654 /httemplate/misc | |
parent | 93786ae8b97b3b11b11eff8ee5fdf78b6b53f26f (diff) |
suspend and unsuspend whole customer action, RT#17841
Diffstat (limited to 'httemplate/misc')
-rwxr-xr-x | httemplate/misc/cust_main-suspend.cgi | 75 | ||||
-rwxr-xr-x | httemplate/misc/cust_main-unsuspend.cgi | 56 | ||||
-rw-r--r-- | httemplate/misc/suspend_cust.html | 79 | ||||
-rw-r--r-- | httemplate/misc/unsuspend_cust.html | 68 |
4 files changed, 278 insertions, 0 deletions
diff --git a/httemplate/misc/cust_main-suspend.cgi b/httemplate/misc/cust_main-suspend.cgi new file mode 100755 index 0000000..6185136 --- /dev/null +++ b/httemplate/misc/cust_main-suspend.cgi @@ -0,0 +1,75 @@ +<& /elements/header-popup.html, mt("Customer suspended") &> + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + </BODY> +</HTML> +<%init> + +#false laziness w/cust_main-cancel.cgi + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Suspend customer'); + +my $custnum; +my $adjourn = ''; +if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { + $custnum = $1; + $adjourn = $cgi->param('adjourn'); +} else { + my($query) = $cgi->keywords; + $query =~ /^(\d+)$/ || die "Illegal custnum"; + $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' ) ), + }; +} + +#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')) { + $adjourn = parse_datetime($adjourn); + if($adjourn) { + #warn "setting adjourn dates on custnum#$custnum\n"; + my @pkgs = $cust_main->unsuspended_pkgs; + @errors = grep {$_} map { $_->suspend( + 'reason' => $reasonnum, + 'date' => $adjourn, + ) } @pkgs; + } + else { + @errors = ("error parsing adjourn date: ".$cgi->param('adjourn')); + } +} +else { + warn "suspending $cust_main"; + @errors = $cust_main->suspend( + 'reason' => $reasonnum, + ); +} +my $error = join(' / ', @errors) if scalar(@errors); + +if ( $error ) { + $cgi->param('error', $error); + print $cgi->redirect(popurl(1). "suspend_cust.html?". $cgi->query_string ); +} + +</%init> diff --git a/httemplate/misc/cust_main-unsuspend.cgi b/httemplate/misc/cust_main-unsuspend.cgi new file mode 100755 index 0000000..eb4a2c8 --- /dev/null +++ b/httemplate/misc/cust_main-unsuspend.cgi @@ -0,0 +1,56 @@ +<& /elements/header-popup.html, mt("Customer unsuspended") &> + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + </BODY> +</HTML> +<%init> + +#false laziness w/cust_main-cancel.cgi + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Unsuspend customer'); + +my $custnum; +my $resume = ''; +if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { + $custnum = $1; + $resume = $cgi->param('resume'); +} else { + my($query) = $cgi->keywords; + $query =~ /^(\d+)$/ || die "Illegal custnum"; + $custnum = $1; +} + +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')) { + $resume = parse_datetime($resume); + if($resume) { + #warn "setting resume dates on custnum#$custnum\n"; + my @pkgs = $cust_main->suspended_pkgs; + @errors = grep {$_} map { $_->unsuspend( + 'date' => $resume, + ) } @pkgs; + } + else { + @errors = ("error parsing adjourn date: ".$cgi->param('adjourn')); + } +} +else { + warn "unsuspending $cust_main"; + @errors = $cust_main->unsuspend; +} +my $error = join(' / ', @errors) if scalar(@errors); + +if ( $error ) { + $cgi->param('error', $error); + print $cgi->redirect(popurl(1). "unsuspend_cust.html?". $cgi->query_string ); +} + +</%init> diff --git a/httemplate/misc/suspend_cust.html b/httemplate/misc/suspend_cust.html new file mode 100644 index 0000000..b41f36f --- /dev/null +++ b/httemplate/misc/suspend_cust.html @@ -0,0 +1,79 @@ +<& /elements/header-popup.html, mt('Suspend customer') &> + +<& /elements/error.html &> + +<FORM NAME="cust_suspend_popup" ACTION="<% popurl(1) %>cust_main-suspend.cgi" METHOD=POST> +<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>"> + + <P ALIGN="center"><B><% mt('Suspend this customer?') |h %></B> + +<TABLE BORDER="0" CELLSPACING="2" +STYLE="margin-left:auto; margin-right:auto"> +<TR> + <TD ALIGN="right"> + <INPUT TYPE="radio" NAME="now_or_later" VALUE="0" onclick="toggle(false)" CHECKED /> + </TD> + <TD ALIGN="left"><% mt('Suspend now') |h %></TD> +</TR> +<TR> + <TD ALIGN="right"> + <INPUT TYPE="radio" NAME="now_or_later" VALUE="1" onclick="toggle(true)" /> + </TD> + <TD ALIGN="left"><% mt('Suspend on date: ') |h %> + <& /elements/input-date-field.html, { + 'name' => 'adjourn', + 'value' => time, + } &> + </TD> +</TR> +</TABLE> +<SCRIPT type="text/javascript"> +function toggle(val) { + document.getElementById("adjourn_text").disabled = !val; + document.getElementById("adjourn_button").style.visibility = + val ? 'visible' : 'hidden'; +} +toggle(false); +</SCRIPT> + +<TABLE BGCOLOR="#cccccc", BORDER="0" CELLSPACING="2" +STYLE="margin-left:auto; margin-right:auto"> +<& /elements/tr-select-reason.html, + 'field' => 'reasonnum', + 'reason_class' => 'C', + 'cgi' => $cgi, + 'control_button' => "document.getElementById('confirm_suspend_cust_button')", +&> + +</TABLE> + +<BR> +<P ALIGN="CENTER"> +<INPUT TYPE="submit" NAME="submit" ID="confirm_suspend_cust_button" VALUE="<% mt('Suspend customer') |h %>" DISABLED> + +<INPUT TYPE="BUTTON" VALUE="<% mt("Don't suspend") |h %>" onClick="parent.cClick();"> + +</FORM> +</BODY> +</HTML> + +<%init> + +#false laziness w/cancel_cust.html + +$cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum'; +my $custnum = $1; + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" unless $curuser->access_right('Suspend customer'); + +my $cust_main = qsearchs( { + 'table' => 'cust_main', + 'hashref' => { 'custnum' => $custnum }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, +} ); +die "No customer # $custnum" unless $cust_main; + +</%init> + diff --git a/httemplate/misc/unsuspend_cust.html b/httemplate/misc/unsuspend_cust.html new file mode 100644 index 0000000..600eb26 --- /dev/null +++ b/httemplate/misc/unsuspend_cust.html @@ -0,0 +1,68 @@ +<& /elements/header-popup.html, mt('Unsuspend customer') &> + +<& /elements/error.html &> + +<FORM NAME="cust_unsuspend_popup" ACTION="<% popurl(1) %>cust_main-unsuspend.cgi" METHOD=POST> +<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>"> + + <P ALIGN="center"><B><% mt('Unsuspend this customer?') |h %></B> + +<TABLE BORDER="0" CELLSPACING="2" +STYLE="margin-left:auto; margin-right:auto"> +<TR> + <TD ALIGN="right"> + <INPUT TYPE="radio" NAME="now_or_later" VALUE="0" onclick="toggle(false)" CHECKED /> + </TD> + <TD ALIGN="left"><% mt('Unsuspend now') |h %></TD> +</TR> +<TR> + <TD ALIGN="right"> + <INPUT TYPE="radio" NAME="now_or_later" VALUE="1" onclick="toggle(true)" /> + </TD> + <TD ALIGN="left"><% mt('Unsuspend on date: ') |h %> + <& /elements/input-date-field.html, { + 'name' => 'resume', + 'value' => time, + } &> + </TD> +</TR> +</TABLE> +<SCRIPT type="text/javascript"> +function toggle(val) { + document.getElementById("resume_text").disabled = !val; + document.getElementById("resume_button").style.visibility = + val ? 'visible' : 'hidden'; +} +toggle(false); +</SCRIPT> + +<BR> +<P ALIGN="CENTER"> +<INPUT TYPE="submit" NAME="submit" ID="confirm_unsuspend_cust_button" VALUE="<% mt('Unsuspend customer') |h %>"> + +<INPUT TYPE="BUTTON" VALUE="<% mt("Don't unsuspend") |h %>" onClick="parent.cClick();"> + +</FORM> +</BODY> +</HTML> + +<%init> + +#false laziness w/cancel_cust.html + +$cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum'; +my $custnum = $1; + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" unless $curuser->access_right('Unsuspend customer'); + +my $cust_main = qsearchs( { + 'table' => 'cust_main', + 'hashref' => { 'custnum' => $custnum }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, +} ); +die "No customer # $custnum" unless $cust_main; + +</%init> + |