optimize CDR rating after timed rate perf regression, RT#15739
[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') || '2011' %>,
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 choose_censustract =
91       '<CENTER><BR><B>Confirm censustract</B><BR>' +
92       '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
93       'census_year=<% $conf->config('census_year') || '2008' %>' +
94       '&latitude=' + cf.elements['latitude'].value +
95       '&longitude=' + cf.elements['longitude'].value +
96       '" target="_blank">Map service module location</A><BR>' +
97       '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
98       'census_year=<% $conf->config('census_year') || '2008' %>' +
99       '&zip_code=' + cf.elements['ship_zip'].value +
100       '" target="_blank">Map zip code center</A><BR><BR>' +
101       '<TABLE>';
102     
103     choose_censustract = choose_censustract + 
104       '<TR><TH style="width:50%">Entered census tract</TH>' +
105         '<TH style="width:50%">Calculated census tract</TH></TR>' +
106       '<TR><TD>' + cf.elements['censustract'].value +
107         '</TD><TD>' + newcensus + '</TD></TR>' +
108         '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
109
110     choose_censustract = choose_censustract +
111       '<TR><TD ALIGN="center">' +
112         '<BUTTON TYPE="button" onClick="document.CustomerForm.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract </BUTTON>' + 
113       '</TD><TD ALIGN="center">' +
114         '<BUTTON TYPE="button" onClick="set_censustract();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract </BUTTON>' + 
115       '</TD></TR>' +
116       '<TR><TD COLSPAN=2 ALIGN="center">' +
117         '<BUTTON TYPE="button" onClick="document.CustomerForm.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
118         
119       '</TABLE></CENTER>';
120
121     overlib( choose_censustract, CAPTION, 'Confirm censustract', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
122
123   } else {
124
125     cf.submit();
126
127   }
128
129 }
130
131 function copyelement(from, to) {
132   if ( from == undefined ) {
133     to.value = '';
134   } else if ( from.type == 'select-one' ) {
135     to.value = from.options[from.selectedIndex].value;
136     //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
137   } else if ( from.type == 'checkbox' ) {
138     if ( from.checked ) {
139       to.value = from.value;
140     } else {
141       to.value = '';
142     }
143   } else {
144     if ( from.value == undefined ) {
145       to.value = '';
146     } else {
147       to.value = from.value;
148     }
149   }
150   //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
151 }
152
153 <%init>
154
155 my $conf = new FS::Conf;
156
157 </%init>