set expire date for customer packages, RT#9697
authormark <mark>
Sat, 4 Sep 2010 02:19:03 +0000 (02:19 +0000)
committermark <mark>
Sat, 4 Sep 2010 02:19:03 +0000 (02:19 +0000)
httemplate/elements/input-date-field.html [new file with mode: 0644]
httemplate/misc/cancel_cust.html
httemplate/misc/cust_main-cancel.cgi
httemplate/view/cust_main.cgi

diff --git a/httemplate/elements/input-date-field.html b/httemplate/elements/input-date-field.html
new file mode 100644 (file)
index 0000000..0ea4be7
--- /dev/null
@@ -0,0 +1,48 @@
+
+<LINK REL="stylesheet" TYPE="text/css" HREF="<%$fsurl%>elements/calendar-win2k-2.css" TITLE="win2k-2">
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar_stripped.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-en.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-setup.js"></SCRIPT>
+
+<INPUT TYPE="text" NAME="<% $name %>" ID="<% $name %>_text" VALUE="<% $value %>">
+<IMG SRC="<%$fsurl%>images/calendar.png" ID="<% $name  %>_button" STYLE="cursor: pointer" TITLE="Select date">
+
+<SCRIPT TYPE="text/javascript">
+  Calendar.setup({
+    inputField: "<% $name %>_text",
+    ifFormat:   "<% $format %>",
+    button:     "<% $name %>_button",
+    align:      "BR"
+  });
+</SCRIPT>
+
+<%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 = '';
+}
+
+</%init>
+
index 12c37eb..b7ecccd 100644 (file)
@@ -2,18 +2,46 @@
 
 <% include('/elements/error.html') %>
 
+
 <FORM NAME="cust_cancel_popup" ACTION="<% popurl(1) %>cust_main-cancel.cgi" METHOD=POST>
 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
 
 
  <P ALIGN="center"><B>Permanently delete all services and cancel this customer?</B>
 
- <% $ban %>
-<BR><BR>
-
-<% ntable("#cccccc", 2) %>
+<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">Cancel now</TD>
+</TR>
+<TR>
+  <TD ALIGN="right">
+    <INPUT TYPE="radio" NAME="now_or_later" VALUE="1" onclick="toggle(true)" />
+  </TD>
+  <TD ALIGN="left">Cancel on date:&nbsp;
+  <% include('/elements/input-date-field.html', {
+              'name'    => 'expire',
+              'value'   => time,
+    } ) %>
+  </TD>
+</TR>
+</TABLE>
+<SCRIPT type="text/javascript">
+function toggle(val) {
+  document.getElementById("expire_text").disabled = !val;
+  document.getElementById("ban").disabled = val;
+  document.getElementById("expire_button").style.visibility = 
+    val ? 'visible' : 'hidden';
+}
+toggle(false);
+</SCRIPT> 
+<% $ban %>
 
+<TABLE BGCOLOR="#cccccc", BORDER="0" CELLSPACING="2"
+STYLE="margin-left:auto; margin-right:auto">
 <% 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 = '<BR><P ALIGN="center">'.
-         '<INPUT TYPE="checkbox" NAME="ban" VALUE="1"> Ban this customer\'s ';
+  $ban = '<P ALIGN="center">'.
+         '<INPUT TYPE="checkbox" NAME="ban" ID="ban" VALUE="1"> Ban this customer\'s ';
   if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
     $ban .= 'credit card';
   } elsif (  $cust_main->payby =~ /^(CHEK|DCHK)$/ ) {
index 009a7d4..44be20c 100755 (executable)
@@ -1,4 +1,4 @@
-<% header("Customer cancelled") %>
+<% include('/elements/header.html', "Customer cancelled") %>
   <SCRIPT TYPE="text/javascript">
     window.top.location.reload();
   </SCRIPT>
@@ -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 ) {
index cb325e2..b4a6170 100755 (executable)
@@ -57,6 +57,7 @@ function areyousure(href, message) {
                 'color'       => '#ff0000',
                 'cust_main'   => $cust_main,
                 'width'       => 616, #make room for reasons
+                'height'      => 366,
               }
             )
   %> |