2 my %opt = @_; # custnum
3 my $conf = new FS::Conf;
5 my $company_latitude = $conf->config('company_latitude');
6 my $company_longitude = $conf->config('company_longitude');
8 my @fixups = ('copy_payby_fields', 'standardize_locations');
10 push @fixups, 'fetch_censustract'
11 if $conf->exists('cust_main-require_censustract');
13 push @fixups, 'check_unique'
14 if $conf->exists('cust_main-check_unique') and !$opt{'custnum'};
16 push @fixups, 'do_submit'; # always last
19 var fixups = <% encode_json(\@fixups) %>;
22 %# state machine to deal with all the asynchronous stuff we're doing
23 %# call this after each fixup on success:
24 function submit_continue() {
25 window[ fixups[fixup_position++] ].call();
29 function submit_abort() {
31 document.CustomerForm.submitButton.disabled = false;
35 function bottomfixup(what) {
37 document.CustomerForm.submitButton.disabled = true;
41 function do_submit() {
42 document.CustomerForm.submit();
45 function copy_payby_fields() {
46 var layervars = new Array(
48 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
49 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
50 'paystart_month', 'paystart_year', 'payissue',
55 var cf = document.CustomerForm;
56 var payby = cf.payby.options[cf.payby.selectedIndex].value;
57 for ( f=0; f < layervars.length; f++ ) {
58 var field = layervars[f];
59 copyelement( cf.elements[payby + '_' + field],
66 %# call submit_continue() on completion...
67 %# otherwise not touching standardize_locations for now
68 <% include( '/elements/standardize_locations.js',
69 'callback' => 'submit_continue();'
73 function fetch_censustract() {
75 //alert('fetch census tract data');
76 var cf = document.CustomerForm;
77 var state_el = cf.elements['ship_state'];
78 var census_data = new Array(
79 'year', <% $conf->config('census_year') || '2012' %>,
80 'address1', cf.elements['ship_address1'].value,
81 'city', cf.elements['ship_city'].value,
82 'state', state_el.options[ state_el.selectedIndex ].value,
83 'zip', cf.elements['ship_zip'].value
86 censustract( census_data, update_censustract );
92 function update_censustract(arg) {
94 var argsHash = eval('(' + arg + ')');
96 var cf = document.CustomerForm;
98 /* var msacode = argsHash['msacode'];
99 var statecode = argsHash['statecode'];
100 var countycode = argsHash['countycode'];
101 var tractcode = argsHash['tractcode'];
104 new String(statecode) +
105 new String(countycode) +
106 new String(tractcode).replace(/\s$/, ''); // JSON 1 workaround */
107 var error = argsHash['error'];
108 var newcensus = argsHash['censustract'];
110 set_censustract = function () {
112 cf.elements['censustract'].value = newcensus;
117 if (error || cf.elements['censustract'].value != newcensus) {
118 // popup an entry dialog
120 if (error) { newcensus = error; }
121 newcensus.replace(/.*ndefined.*/, 'Not found');
123 var latitude = cf.elements['latitude' ].value || '<% $company_latitude %>';
124 var longitude= cf.elements['longitude'].value || '<% $company_longitude %>';
126 var choose_censustract =
127 '<CENTER><BR><B>Confirm censustract</B><BR>' +
128 '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
129 'census_year=<% $conf->config('census_year') || '2012' %>' +
130 '&latitude=' + latitude +
131 '&longitude=' + longitude +
132 '" target="_blank">Map service module location</A><BR>' +
133 '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
134 'census_year=<% $conf->config('census_year') || '2012' %>' +
135 '&zip_code=' + cf.elements['ship_zip'].value +
136 '" target="_blank">Map zip code center</A><BR><BR>' +
139 choose_censustract = choose_censustract +
140 '<TR><TH style="width:50%">Entered census tract</TH>' +
141 '<TH style="width:50%">Calculated census tract</TH></TR>' +
142 '<TR><TD>' + cf.elements['censustract'].value +
143 '</TD><TD>' + newcensus + '</TD></TR>' +
144 '<TR><TD> </TD><TD> </TD></TR>';
146 choose_censustract = choose_censustract +
147 '<TR><TD ALIGN="center">' +
148 '<BUTTON TYPE="button" onClick="submit_continue();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract </BUTTON>' +
149 '</TD><TD ALIGN="center">' +
150 '<BUTTON TYPE="button" onClick="set_censustract();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract </BUTTON>' +
152 '<TR><TD COLSPAN=2 ALIGN="center">' +
153 '<BUTTON TYPE="button" onClick="submit_abort();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
157 overlib( choose_censustract, CAPTION, 'Confirm censustract', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
167 function copyelement(from, to) {
168 if ( from == undefined ) {
170 } else if ( from.type == 'select-one' ) {
171 to.value = from.options[from.selectedIndex].value;
172 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
173 } else if ( from.type == 'checkbox' ) {
174 if ( from.checked ) {
175 to.value = from.value;
180 if ( from.value == undefined ) {
183 to.value = from.value;
186 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
189 function check_unique() {
190 var search_hash = new Object;
191 % foreach ($conf->config('cust_main-check_unique')) {
192 search_hash['<% $_ %>'] = document.CustomerForm.elements['<% $_ %>'].value;
195 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
196 duplicates_form(JSON.stringify(search_hash), confirm_unique);
199 function confirm_unique(arg) {
200 if ( arg.match(/\S/) ) {
201 %# arg contains a complete form to choose an existing customer, or not
202 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
203 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
204 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
205 } else { // no duplicates