From 48e3f879908a13cb87786e32e158ff8a8bf18fbb Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 4 Sep 2010 02:19:03 +0000 Subject: [PATCH] set expire date for customer packages, RT#9697 --- httemplate/elements/input-date-field.html | 48 +++++++++++++++++++++++++++++++ httemplate/misc/cancel_cust.html | 42 ++++++++++++++++++++++----- httemplate/misc/cust_main-cancel.cgi | 31 ++++++++++++++++---- httemplate/view/cust_main.cgi | 1 + 4 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 httemplate/elements/input-date-field.html diff --git a/httemplate/elements/input-date-field.html b/httemplate/elements/input-date-field.html new file mode 100644 index 000000000..0ea4be70a --- /dev/null +++ b/httemplate/elements/input-date-field.html @@ -0,0 +1,48 @@ + + + + + + + + + + + +<%init> + +my($name, $value, $format, $usedatetime); +if ( ref($_[0]) ) { + my $opt = shift; + $name = $opt->{'name'}; + $value = $opt->{'value'}; + $format = $opt->{'format'}; + $usedatetime = $opt->{'usedatetime'}; +} else { + ($name, $value, $format, $usedatetime) = @_; +} + +my $conf = new FS::Conf; + +$format ||= $conf->config('date_format') || '%m/%d/%Y'; + +if ( $value =~ /\S/ ) { + if ( $usedatetime ) { + my $dt = DateTime->from_epoch(epoch => $value, time_zone => 'floating'); + $value = $dt->strftime($format); + } elsif ( $value =~ /^\d+$/ ) { + $value = time2str($format, $value); + } +} else { + $value = ''; +} + + + diff --git a/httemplate/misc/cancel_cust.html b/httemplate/misc/cancel_cust.html index 12c37ebe2..b7ecccd7e 100644 --- a/httemplate/misc/cancel_cust.html +++ b/httemplate/misc/cancel_cust.html @@ -2,18 +2,46 @@ <% include('/elements/error.html') %> +

Permanently delete all services and cancel this customer? - <% $ban %> - -

- -<% ntable("#cccccc", 2) %> + + + + + + + + + +
+ + Cancel now
+ + Cancel on date:  + <% include('/elements/input-date-field.html', { + 'name' => 'expire', + 'value' => time, + } ) %> +
+ +<% $ban %> + <% include('/elements/tr-select-reason.html', 'field' => 'reasonnum', 'reason_class' => 'C', @@ -50,8 +78,8 @@ die "No customer # $custnum" unless $cust_main; my $ban = ''; if ( $cust_main->payby =~ /^(CARD|DCRD|CHEK|DCHK)$/ ) { - $ban = '

'. - ' Ban this customer\'s '; + $ban = '

'. + ' Ban this customer\'s '; if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) { $ban .= 'credit card'; } elsif ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) { diff --git a/httemplate/misc/cust_main-cancel.cgi b/httemplate/misc/cust_main-cancel.cgi index 009a7d41b..44be20c8a 100755 --- a/httemplate/misc/cust_main-cancel.cgi +++ b/httemplate/misc/cust_main-cancel.cgi @@ -1,4 +1,4 @@ -<% header("Customer cancelled") %> +<% include('/elements/header.html', "Customer cancelled") %> @@ -11,9 +11,11 @@ die "access denied" 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"; @@ -42,11 +44,28 @@ my $cust_main = qsearchs( { 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, } ); -warn "cancelling $cust_main"; -my @errors = $cust_main->cancel( - 'ban' => $ban, - 'reason' => $reasonnum, -); +my @errors; +if($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( + 'reason' => $reasonnum, + 'date' => $expire, + ) } @pkgs; + } + else { + @errors = ("error parsing expire date: ".$cgi->param('expire')); + } +} +else { + warn "cancelling $cust_main"; + @errors = $cust_main->cancel( + 'ban' => $ban, + 'reason' => $reasonnum, + ); +} my $error = join(' / ', @errors) if scalar(@errors); if ( $error ) { diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi index cb325e21d..b4a6170c5 100755 --- a/httemplate/view/cust_main.cgi +++ b/httemplate/view/cust_main.cgi @@ -57,6 +57,7 @@ function areyousure(href, message) { 'color' => '#ff0000', 'cust_main' => $cust_main, 'width' => 616, #make room for reasons + 'height' => 366, } ) %> | -- 2.11.0