FCC from 477 improvements #4912
authorjeff <jeff>
Mon, 27 Jul 2009 03:26:47 +0000 (03:26 +0000)
committerjeff <jeff>
Mon, 27 Jul 2009 03:26:47 +0000 (03:26 +0000)
FS/FS/Conf.pm
FS/FS/cust_main.pm
FS/FS/cust_pkg.pm
httemplate/edit/cust_main.cgi
httemplate/edit/cust_main/bottomfixup.js
httemplate/edit/cust_main/contact.html
httemplate/elements/location.html
httemplate/misc/xmlhttp-cust_main-censustract.html
httemplate/search/cust_pkg.cgi
httemplate/view/cust_main/misc.html

index 832322f..37f5530 100644 (file)
@@ -2605,6 +2605,28 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'census_year',
+    'section'     => 'UI',
+    'description' => 'The year to use in census tract lookups',
+    'type'        => 'select',
+    'select_enum' => [ qw( 2008 2007 2006 ) ],
+  },
+
+  {
+    'key'         => 'company_latitude',
+    'section'     => 'UI',
+    'description' => 'Your company latitude (-90 through 90)',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'company_longitude',
+    'section'     => 'UI',
+    'description' => 'Your company longitude (-180 thru 180)',
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'disable_acl_changes',
     'section'     => '',
     'description' => 'Disable all ACL changes, for demos.',
index 9d41c4b..518ab4d 100644 (file)
@@ -1571,6 +1571,13 @@ sub check {
     unless ! $self->referral_custnum 
            || qsearchs( 'cust_main', { 'custnum' => $self->referral_custnum } );
 
+  if ( $self->censustract ne '' ) {
+    $self->censustract =~ /^\s*(\d{9})\.?(\d{2})\s*$/
+      or return "Illegal census tract: ". $self->censustract;
+    
+    $self->censustract("$1.$2");
+  }
+
   if ( $self->ss eq '' ) {
     $self->ss('');
   } else {
@@ -7371,6 +7378,19 @@ sub support_services {
 
 }
 
+# Return a list of latitude/longitude for one of the services (if any)
+sub service_coordinates {
+  my $self = shift;
+
+  my @svc_X = 
+    grep { $_->latitude && $_->longitude }
+    map { $_->svc_x }
+    map { $_->cust_svc }
+    $self->ncancelled_pkgs;
+
+  scalar(@svc_X) ? ( $svc_X[0]->latitude, $svc_X[0]->longitude ) : ()
+}
+
 =back
 
 =head1 CLASS METHODS
index 4d44692..00a0301 100644 (file)
@@ -2377,8 +2377,11 @@ sub search_sql {
   # parse censustract
   ###
 
-  if ( $params->{'censustract'} =~ /^([.\d]+)$/ and $1 ) {
-    push @where,  "cust_main.censustract = '". $params->{censustract}. "'";
+  if ( exists($params->{'censustract'}) ) {
+    $params->{'censustract'} =~ /^([.\d]*)$/;
+    my $censustract = "cust_main.censustract = '$1'";
+    $censustract .= ' OR cust_main.censustract is NULL' unless $1;
+    push @where,  "( $censustract )";
   }
 
   ###
index 5751314..8b1d2b5 100755 (executable)
   <% include('cust_main/birthdate.html', $cust_main) %>
 % }
 
+%# latitude and longitude
+% if ( $conf->exists('cust_main-require_censustract') ) {
+%   my ($latitude, $longitude) = $cust_main->service_coordinates;
+%   $latitude ||= $conf->config('company_latitude') || '';
+%   $longitude ||= $conf->config('company_longitude') || '';
+  <INPUT NAME="latitude" TYPE="hidden" VALUE="<% $latitude |h %>">
+  <INPUT NAME="longitude" TYPE="hidden" VALUE="<% $longitude |h %>">
+% }
+
 %# contact info
 
 %  my $same_checked = '';
index 822f98d..06e8b13 100644 (file)
@@ -242,7 +242,7 @@ function post_geocode() {
   var cf = document.CustomerForm;
   var state_el = cf.elements['ship_state'];
   var census_data = new Array(
-    'year',    '2008', // from config value?
+    'year',   <% $conf->config('census_year') || '2008' %>,
     'address', cf.elements['ship_address1'].value,
     'city',    cf.elements['ship_city'].value,
     'state',   state_el.options[ state_el.selectedIndex ].value,
@@ -296,44 +296,52 @@ function update_censustract(arg) {
   var tractcode  = argsHash['tractcode'];
   var error      = argsHash['error'];
   
+  var newcensus = 
+    new String(statecode)  +
+    new String(countycode) +
+    new String(tractcode).replace(/\s$/, '');  // JSON 1 workaround
+
   set_censustract = function () {
 
-    cf.elements['censustract'].value =
-      document.forms.popupcensustract.elements.censustract.value;
+    cf.elements['censustract'].value = newcensus
     cf.submit();
 
   }
 
-  if (error) {
+  if (error || cf.elements['censustract'].value != newcensus) {
     // popup an entry dialog
 
     var choose_censustract =
-      '<CENTER><BR><B>Enter census tract</B><BR><BR>' + 
-      '<FORM name="popupcensustract">' +
+      '<CENTER><BR><B>Confirm censustract</B><BR>' +
+      '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
+      'census_year=<% $conf->config('census_year') || '2008' %>' +
+      '&latitude=' + cf.elements['latitude'].value +
+      '&longitude=' + cf.elements['longitude'].value +
+      '" target="_blank">Map service module location</A><BR><BR>' +
       '<TABLE>';
     
     choose_censustract = choose_censustract + 
-      '<TR><TH>Census Tract: </TH>' +
-        '<TD><INPUT NAME="censustract" ID="censustract"></TD>' +
-      '</TR><TR>' +
-        '<TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
-      
-    choose_censustract = choose_censustract + 
+      '<TR><TH>Entered census tract</TH>' +
+        '<TH>Calculated census tract</TH></TR>' +
+      '<TR><TD>' + cf.elements['censustract'].value +
+        '</TD><TD>' + newcensus + '</TD></TR>' +
+        '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
+
+    choose_censustract = choose_censustract +
       '<TR><TD>' +
-        '<BUTTON TYPE="button" onClick="set_censustract();"><IMG SRC="<%$p%>images/tick.png" ALT="">Submit census tract</BUTTON>' + 
+        '<BUTTON TYPE="button" onClick="document.CustomerForm.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract </BUTTON>' + 
       '</TD><TD>' +
+        '<BUTTON TYPE="button" onClick="set_censustract();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract </BUTTON>' + 
+      '</TD></TR>' +
+      '<TR><TD COLSPAN=2 ALIGN="center">' +
         '<BUTTON TYPE="button" onClick="document.CustomerForm.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
-      '</TABLE></FORM></CENTER>';
+        
+      '</TABLE></CENTER>';
 
-      overlib( choose_censustract, CAPTION, 'Choose a census tract', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
+    overlib( choose_censustract, CAPTION, 'Confirm censustract', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
 
-      setTimeout("document.forms.popupcensustract.elements.censustract.focus()",1);
   } else {
 
-    cf.elements['censustract'].value =
-      new String(statecode)  +
-      new String(countycode) +
-      new String(tractcode);
     cf.submit();
 
   }
index 2691da6..3bed54b 100644 (file)
@@ -111,6 +111,10 @@ $cust_main->set($pre.'state', $statedefault )
 $cust_main->set('stateid_state', $cust_main->state )
   unless $pre || $cust_main->get('stateid_state');
 
+if ( $conf->exists('cust_main-require_censustract') ) {
+  $opt{censustract} ||= $cust_main->censustract;
+}
+
 #my($county_html, $state_html, $country_html) =
 #  FS::cust_main_county::regionselector( $cust_main->get($pre.'county'),
 #                                        $cust_main->get($pre.'state'),
index 1bdbf96..07aaa69 100644 (file)
@@ -87,7 +87,15 @@ Example:
 % if ( !$pre ) { 
   <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
 % } else {
-  <INPUT TYPE="hidden" NAME="censustract" VALUE="<% $opt{censustract} %>">
+%   if ( $pre eq 'ship_' && $conf->exists('cust_main-require_censustract') ) {
+      <TR><TH ALIGN="right">Census tract<BR>(automatic)</TH>
+        <TD>
+          <INPUT TYPE="text" NAME="censustract" VALUE="<% $opt{censustract} %>">
+        </TD>
+      </TR>
+%   } else {
+      <INPUT TYPE="hidden" NAME="censustract" VALUE="<% $opt{censustract} %>">
+%   } 
 % } 
 
 <%init>
index 05636d3..9d588d7 100644 (file)
@@ -86,6 +86,8 @@ if ( $sub eq 'censustract' ) {
         }
 
         $error = "No census tract found" unless $return->{tractcode};
+        $return->{tractcode} .= ' '
+          unless $error || $JSON::VERSION >= 2; #broken JSON 1 workaround
 
       } #unless ($res->code  eq '200')
 
index a2ea3c5..f6a3620 100755 (executable)
@@ -162,10 +162,14 @@ my $money_char = $conf->config('money_char') || '$';
   
   $search_hash{'query'} = $cgi->keywords;
   
-  for ( qw(agentnum magic status classnum pkgpart custom censustract) ) {
+  for ( qw(agentnum magic status classnum pkgpart custom ) ) {
     $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
   }
 
+  for my $param ( qw(censustract) ) {
+    $search_hash{$param} = $cgi->param($param) || ''
+      if ( grep { /$param/ } $cgi->param );
+  }
 
 my @report_option = $cgi->param('report_option')
   if $cgi->param('report_option');
index 91b304b..71e8d69 100644 (file)
 
 % }
 
+% if ( $conf->exists('cust_main-require_censustract') ) {
+
+  <TR>
+    <TD ALIGN="right">Census tract</TD>
+    <TD BGCOLOR="#ffffff"><% $cust_main->censustract  %></TD>
+  </TR>
+
+% }
+
 </TABLE></TD></TR></TABLE>
 <%init>