From: ivan Date: Fri, 7 Aug 2009 23:08:03 +0000 (+0000) Subject: add ability to edit signup dates (turn on cust_main-edit_signupdate config), RT#4644 X-Git-Tag: root_of_svc_elec_features~942 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=c183de0b7e942672cafdc1c14a203e389ffd2c43 add ability to edit signup dates (turn on cust_main-edit_signupdate config), RT#4644 --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index c335c0140..66f74578d 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -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 => "DEPRECATED", type => "text" }, { key => "apachemachine", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachines", section => "deprecated", description => "DEPRECATED", type => "text" }, diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 8b1d2b59c..15c9f45b2 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -56,7 +56,7 @@ % } % } -

+
Billing address <% include('cust_main/contact.html', @@ -182,6 +182,7 @@ function samechanged(what) { +%# cust_main/bottomfixup.js % foreach my $hidden ( % 'payauto', % 'payinfo', 'payinfo1', 'payinfo2', 'paytype', diff --git a/httemplate/edit/cust_main/top_misc.html b/httemplate/edit/cust_main/top_misc.html index 5aaa0b0cc..041050664 100644 --- a/httemplate/edit/cust_main/top_misc.html +++ b/httemplate/edit/cust_main/top_misc.html @@ -71,6 +71,16 @@ % } +%# 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", + }) + %> +% } diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi index 1709752fb..f72ca0a81 100755 --- a/httemplate/edit/process/cust_main.cgi +++ b/httemplate/edit/process/cust_main.cgi @@ -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') ) diff --git a/httemplate/elements/tr-input-date-field.html b/httemplate/elements/tr-input-date-field.html index 428221a5c..2a731e1e8 100644 --- a/httemplate/elements/tr-input-date-field.html +++ b/httemplate/elements/tr-input-date-field.html @@ -23,7 +23,17 @@ <%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 {