X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fmisc%2Fcust_main-cancel.cgi;h=fcae671943d1dc3f11a78014f4773f084d9190a3;hp=d29e4f5fc0091a61bf39c93aeb76e75469445b46;hb=HEAD;hpb=c8cccb4a92adceb943c635fe62dad0d034462ce0 diff --git a/httemplate/misc/cust_main-cancel.cgi b/httemplate/misc/cust_main-cancel.cgi index d29e4f5fc..fcae67194 100755 --- a/httemplate/misc/cust_main-cancel.cgi +++ b/httemplate/misc/cust_main-cancel.cgi @@ -1,23 +1,64 @@ -% -% -%my $custnum; -%my $ban = ''; -%if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { -% $custnum = $1; -% $ban = $cgi->param('ban'); -%} else { -% my($query) = $cgi->keywords; -% $query =~ /^(\d+)$/ || die "Illegal custnum"; -% $custnum = $1; -%} -% -%my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ); -% -%my @errors = $cust_main->cancel( 'ban' => $ban ); -%eidiot(join(' / ', @errors)) if scalar(@errors); -% -%#print $cgi->redirect($p. "view/cust_main.cgi?". $cust_main->custnum); -%print $cgi->redirect($p); -% -% +<& /elements/popup-topreload.html, mt("Customer cancelled") &> +<%init> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Cancel customer'); + +my $custnum; +my $ban = ''; +my $expire = ''; +if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { + $custnum = $1; + $ban = $cgi->param('ban'); + $expire = $cgi->param('expire'); +} else { + my($query) = $cgi->keywords; + $query =~ /^(\d+)$/ || die "Illegal custnum"; + $custnum = $1; +} + + +#untaint reasonnum / create new reason +my ($reasonnum, $error) = $m->comp('process/elements/reason'); +if (!$reasonnum) { + $error ||= 'Reason required' +} + +my $cust_main = qsearchs( { + 'table' => 'cust_main', + 'hashref' => { 'custnum' => $custnum }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, +} ); + +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; + my @errors = grep {$_} map { $_->cancel( + 'reason' => $reasonnum, + 'date' => $expire, + ) } @pkgs; + $error = join(' / ', @errors); + } + else { + $error = ("error parsing expire date: ".$cgi->param('expire')); + } +} +else { + warn "cancelling $cust_main"; + my @error = $cust_main->cancel( #returns list of errors + 'ban' => $ban, + 'reason' => $reasonnum, + ); + $error = join(', ',@error); +} + +if ( $error ) { + $cgi->param('error', $error); + print $cgi->redirect(popurl(1). "cancel_cust.html?". $cgi->query_string ); +} + +