fix latitude/longitude w/cust_main-require_censustract, RT#16479
[freeside.git] / httemplate / edit / cust_main / bottomfixup.js
1 function bottomfixup(what) {
2
3 %# ../cust_main.cgi
4   var layervars = new Array(
5     'payauto', 'billday',
6     'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
7     'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
8     'paystart_month', 'paystart_year', 'payissue',
9     'payip',
10     'paid'
11   );
12
13   var cf = document.CustomerForm;
14   var payby = cf.payby.options[cf.payby.selectedIndex].value;
15   for ( f=0; f < layervars.length; f++ ) {
16     var field = layervars[f];
17     copyelement( cf.elements[payby + '_' + field],
18                  cf.elements[field]
19                );
20   }
21
22   //this part does USPS address correction
23   standardize_locations();
24
25 }
26
27 <% include( '/elements/standardize_locations.js',
28             'callback', 'post_geocode();'
29           )
30 %>
31
32 function post_geocode() {
33
34 % if ( $conf->exists('cust_main-require_censustract') ) {
35
36   //alert('fetch census tract data');
37   var cf = document.CustomerForm;
38   var state_el = cf.elements['ship_state'];
39   var census_data = new Array(
40     'year',     <% $conf->config('census_year') || '2012' %>,
41     'address1', cf.elements['ship_address1'].value,
42     'city',     cf.elements['ship_city'].value,
43     'state',    state_el.options[ state_el.selectedIndex ].value,
44     'zip',      cf.elements['ship_zip'].value
45   );
46
47   censustract( census_data, update_censustract );
48
49 % }else{
50
51   document.CustomerForm.submit();
52
53 % }
54
55 }
56
57 var set_censustract;
58
59 function update_censustract(arg) {
60
61   var argsHash = eval('(' + arg + ')');
62
63   var cf = document.CustomerForm;
64
65 /*  var msacode    = argsHash['msacode'];
66   var statecode  = argsHash['statecode'];
67   var countycode = argsHash['countycode'];
68   var tractcode  = argsHash['tractcode'];
69   
70   var newcensus = 
71     new String(statecode)  +
72     new String(countycode) +
73     new String(tractcode).replace(/\s$/, '');  // JSON 1 workaround */
74   var error      = argsHash['error'];
75   var newcensus  = argsHash['censustract'];
76
77   set_censustract = function () {
78
79     cf.elements['censustract'].value = newcensus;
80     cf.submit();
81
82   }
83
84   if (error || cf.elements['censustract'].value != newcensus) {
85     // popup an entry dialog
86
87     if (error) { newcensus = error; }
88     newcensus.replace(/.*ndefined.*/, 'Not found');
89
90     var latitude = cf.elements['latitude' ].value || '<% $company_latitude %>';
91     var longitude= cf.elements['longitude'].value || '<% $company_longitude %>';
92
93     var choose_censustract =
94       '<CENTER><BR><B>Confirm censustract</B><BR>' +
95       '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
96       'census_year=<% $conf->config('census_year') || '2012' %>' +
97       '&latitude=' + latitude +
98       '&longitude=' + longitude +
99       '" target="_blank">Map service module location</A><BR>' +
100       '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
101       'census_year=<% $conf->config('census_year') || '2012' %>' +
102       '&zip_code=' + cf.elements['ship_zip'].value +
103       '" target="_blank">Map zip code center</A><BR><BR>' +
104       '<TABLE>';
105     
106     choose_censustract = choose_censustract + 
107       '<TR><TH style="width:50%">Entered census tract</TH>' +
108         '<TH style="width:50%">Calculated census tract</TH></TR>' +
109       '<TR><TD>' + cf.elements['censustract'].value +
110         '</TD><TD>' + newcensus + '</TD></TR>' +
111         '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
112
113     choose_censustract = choose_censustract +
114       '<TR><TD ALIGN="center">' +
115         '<BUTTON TYPE="button" onClick="document.CustomerForm.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract </BUTTON>' + 
116       '</TD><TD ALIGN="center">' +
117         '<BUTTON TYPE="button" onClick="set_censustract();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract </BUTTON>' + 
118       '</TD></TR>' +
119       '<TR><TD COLSPAN=2 ALIGN="center">' +
120         '<BUTTON TYPE="button" onClick="document.CustomerForm.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
121         
122       '</TABLE></CENTER>';
123
124     overlib( choose_censustract, CAPTION, 'Confirm censustract', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
125
126   } else {
127
128     cf.submit();
129
130   }
131
132 }
133
134 function copyelement(from, to) {
135   if ( from == undefined ) {
136     to.value = '';
137   } else if ( from.type == 'select-one' ) {
138     to.value = from.options[from.selectedIndex].value;
139     //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
140   } else if ( from.type == 'checkbox' ) {
141     if ( from.checked ) {
142       to.value = from.value;
143     } else {
144       to.value = '';
145     }
146   } else {
147     if ( from.value == undefined ) {
148       to.value = '';
149     } else {
150       to.value = from.value;
151     }
152   }
153   //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
154 }
155
156 <%init>
157
158 my $conf = new FS::Conf;
159
160 my $company_latitude  = $conf->config('company_latitude');
161 my $company_longitude = $conf->config('company_longitude');
162
163
164 </%init>