add ability to edit signup dates (turn on cust_main-edit_signupdate config), RT#4644
authorivan <ivan>
Fri, 7 Aug 2009 23:08:03 +0000 (23:08 +0000)
committerivan <ivan>
Fri, 7 Aug 2009 23:08:03 +0000 (23:08 +0000)
FS/FS/Conf.pm
httemplate/edit/cust_main.cgi
httemplate/edit/cust_main/top_misc.html
httemplate/edit/process/cust_main.cgi
httemplate/elements/tr-input-date-field.html

index c335c01..66f7457 100644 (file)
@@ -3016,6 +3016,13 @@ worry that config_items is freeside-specific and icky.
     'type'        => 'checkbox',
   },
 
+  {
+    'key'         => 'cust_main-edit_signupdate',
+    'section'     => 'UI',
+    'descritpion' => 'Enable manual editing of the signup date.',
+    'type'        => 'checkbox',
+  },
+
   { key => "apacheroot", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachine", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachines", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
index 8b1d2b5..15c9f45 100755 (executable)
@@ -56,7 +56,7 @@
 %    }
 %  }
 
-<BR><BR>
+<BR>
 <FONT SIZE="+1"><B>Billing address</B></FONT>
 
 <% include('cust_main/contact.html',
@@ -182,6 +182,7 @@ function samechanged(what) {
 
 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
 
+%# cust_main/bottomfixup.js
 % foreach my $hidden (
 %    'payauto',
 %    'payinfo', 'payinfo1', 'payinfo2', 'paytype',
index 5aaa0b0..0410506 100644 (file)
   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
 % } 
 
+%# signup date
+% if ( $conf->exists('cust_main-edit_signupdate') ) {
+    <% include('/elements/tr-input-date-field.html', {
+                  'name'        => 'signupdate',
+                  'value'       => $cust_main->signupdate,
+                  'label'       => 'Signup date',
+                  'format'      => $conf->config('date_format') || "%m/%d/%Y",
+              })
+    %>
+% }
 
 </TABLE>
 
index 1709752..f72ca0a 100755 (executable)
@@ -73,20 +73,41 @@ if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) {
   );
 }
 
-if ( $cgi->param('birthdate') && $cgi->param('birthdate') =~ /^([ 0-9\-\/]{0,10})$/) {
-  my $format = $conf->config('date_format') || "%m/%d/%Y";
-  my $parser = DateTime::Format::Strptime->new(pattern => $format,
-                                               time_zone => 'floating',
-                                              );
-  my $dt =  $parser->parse_datetime($1);
-  if ($dt) {
-    $new->setfield('birthdate', $dt->epoch);
-    $cgi->param('birthdate', $dt->epoch);
-  } else {
-#    $error ||= $cgi->param('birthdate') . " is an invalid birthdate:" . $parser->errmsg;
-    $error ||= "Invalid birthdate: " . $cgi->param('birthdate') . ".";
-    $cgi->param('birthdate', '');
+my %usedatetime = ( 'birthdate' => 1 );
+
+foreach my $dfield (qw( birthdate signupdate )) {
+
+  if ( $cgi->param($dfield) && $cgi->param($dfield) =~ /^([ 0-9\-\/]{0,10})$/) {
+
+    my $value = $1;
+    my $parsed = '';
+
+    if ( exists $usedatetime{$dfield} && $usedatetime{$dfield} ) {
+
+      my $format = $conf->config('date_format') || "%m/%d/%Y";
+      my $parser = DateTime::Format::Strptime->new( pattern   => $format,
+                                                    time_zone => 'floating',
+                                                  );
+      my $dt = $parser->parse_datetime($value);
+      if ( $dt ) {
+        $parsed = $dt->epoch;
+      } else {
+    #    $error ||= $cgi->param('birthdate') . " is an invalid birthdate:" . $parser->errmsg;
+        $error ||= "Invalid $dfield: $value";
+      }
+
+    } else {
+
+      $parsed = str2time($value)
+        or $error ||= "Invalid $dfield: $value";
+
+    }
+
+    $new->setfield( $dfield, $parsed );
+    $cgi->param(    $dfield, $parsed );
+
   }
+
 }
 
 $new->setfield('paid', $cgi->param('paid') )
index 428221a..2a731e1 100644 (file)
 
 
 <%init>
-my($name, $value, $label, $format, $usedatetime) = @_;
+my($name, $value, $label, $format, $usedatetime);
+if ( ref($_[0]) ) {
+  my $opt = shift;
+  $name        = $opt->{'name'};
+  $value       = $opt->{'value'};
+  $label       = $opt->{'label'};
+  $format      = $opt->{'format'};
+  $usedatetime = $opt->{'usedatetime'};
+} else {
+  ($name, $value, $label, $format, $usedatetime) = @_;
+}
 
 $format = "%m/%d/%Y" unless $format;
 $label = $name unless $label;
@@ -32,7 +42,7 @@ if ( $value =~ /\S/ ) {
   if ( $usedatetime ) {
     my $dt = DateTime->from_epoch(epoch => $value, time_zone => 'floating');
     $value = $dt->strftime($format);
-  } else {
+  } elsif ( $value =~ /^\d+$/ ) {
     $value = time2str($format, $value);
   }
 } else {