From f3717767d19f9da888e190f87a04dfa245d658b4 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 27 Jul 2009 03:26:47 +0000 Subject: [PATCH] FCC from 477 improvements #4912 --- FS/FS/Conf.pm | 22 ++++++++++ FS/FS/cust_main.pm | 20 +++++++++ FS/FS/cust_pkg.pm | 7 +++- httemplate/edit/cust_main.cgi | 9 ++++ httemplate/edit/cust_main/bottomfixup.js | 48 +++++++++++++--------- httemplate/edit/cust_main/contact.html | 4 ++ httemplate/elements/location.html | 10 ++++- httemplate/misc/xmlhttp-cust_main-censustract.html | 2 + httemplate/search/cust_pkg.cgi | 6 ++- httemplate/view/cust_main/misc.html | 9 ++++ 10 files changed, 113 insertions(+), 24 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 832322faf..37f55306a 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -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.', diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 9d41c4bdf..518ab4d98 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -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 diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 4d44692b3..00a030117 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -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 )"; } ### diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 575131424..8b1d2b59c 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -32,6 +32,15 @@ <% 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') || ''; + + +% } + %# contact info % my $same_checked = ''; diff --git a/httemplate/edit/cust_main/bottomfixup.js b/httemplate/edit/cust_main/bottomfixup.js index 822f98d39..06e8b13b6 100644 --- a/httemplate/edit/cust_main/bottomfixup.js +++ b/httemplate/edit/cust_main/bottomfixup.js @@ -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 = - '

Enter census tract

' + - '
' + + '

Confirm censustract
' + + 'Map service module location

' + ''; choose_censustract = choose_censustract + - '' + - '' + - '' + - ''; - - choose_censustract = choose_censustract + + '' + + '' + + '' + + ''; + + choose_censustract = choose_censustract + '' + + '' + - '
Census Tract:
  
Entered census tractCalculated census tract
' + cf.elements['censustract'].value + + '' + newcensus + '
  
' + - '' + + '' + '' + + '' + + '
' + '
'; + + '
'; - 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(); } diff --git a/httemplate/edit/cust_main/contact.html b/httemplate/edit/cust_main/contact.html index 2691da652..3bed54b85 100644 --- a/httemplate/edit/cust_main/contact.html +++ b/httemplate/edit/cust_main/contact.html @@ -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'), diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html index 1bdbf9604..07aaa69f0 100644 --- a/httemplate/elements/location.html +++ b/httemplate/elements/location.html @@ -87,7 +87,15 @@ Example: % if ( !$pre ) { % } else { - +% if ( $pre eq 'ship_' && $conf->exists('cust_main-require_censustract') ) { + Census tract
(automatic) + + + + +% } else { + +% } % } <%init> diff --git a/httemplate/misc/xmlhttp-cust_main-censustract.html b/httemplate/misc/xmlhttp-cust_main-censustract.html index 05636d3fb..9d588d712 100644 --- a/httemplate/misc/xmlhttp-cust_main-censustract.html +++ b/httemplate/misc/xmlhttp-cust_main-censustract.html @@ -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') diff --git a/httemplate/search/cust_pkg.cgi b/httemplate/search/cust_pkg.cgi index a2ea3c582..f6a3620d3 100755 --- a/httemplate/search/cust_pkg.cgi +++ b/httemplate/search/cust_pkg.cgi @@ -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'); diff --git a/httemplate/view/cust_main/misc.html b/httemplate/view/cust_main/misc.html index 91b304b5d..71e8d6973 100644 --- a/httemplate/view/cust_main/misc.html +++ b/httemplate/view/cust_main/misc.html @@ -98,6 +98,15 @@ % } +% if ( $conf->exists('cust_main-require_censustract') ) { + + + Census tract + <% $cust_main->censustract %> + + +% } + <%init> -- 2.11.0