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();',
70 'main_prefix' => 'bill_',
76 function fetch_censustract() {
78 //alert('fetch census tract data');
79 prefix = document.getElementById('same').checked ? 'bill_' : 'ship_';
80 var cf = document.CustomerForm;
81 var state_el = cf.elements[prefix + 'state'];
82 var census_data = new Array(
83 'year', <% $conf->config('census_year') || '2012' %>,
84 'address1', cf.elements[prefix + 'address1'].value,
85 'city', cf.elements[prefix + 'city'].value,
86 'state', state_el.options[ state_el.selectedIndex ].value,
87 'zip', cf.elements[prefix + 'zip'].value
90 censustract( census_data, update_censustract );
96 function update_censustract(arg) {
98 var argsHash = eval('(' + arg + ')');
100 var cf = document.CustomerForm;
102 /* var msacode = argsHash['msacode'];
103 var statecode = argsHash['statecode'];
104 var countycode = argsHash['countycode'];
105 var tractcode = argsHash['tractcode'];
108 new String(statecode) +
109 new String(countycode) +
110 new String(tractcode).replace(/\s$/, ''); // JSON 1 workaround */
111 var error = argsHash['error'];
112 var newcensus = argsHash['censustract'];
114 set_censustract = function () {
116 cf.elements[prefix + 'censustract'].value = newcensus;
121 if (error || cf.elements[prefix + 'censustract'].value != newcensus) {
122 // popup an entry dialog
124 if (error) { newcensus = error; }
125 newcensus.replace(/.*ndefined.*/, 'Not found');
127 var latitude = cf.elements[prefix + 'latitude'].value
128 || '<% $company_latitude %>';
129 var longitude= cf.elements[prefix + 'longitude'].value
130 || '<% $company_longitude %>';
132 var choose_censustract =
133 '<CENTER><BR><B>Confirm censustract</B><BR>' +
134 '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
135 'census_year=<% $conf->config('census_year') || '2012' %>' +
136 '&latitude=' + latitude +
137 '&longitude=' + longitude +
138 '" target="_blank">Map service module location</A><BR>' +
139 '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
140 'census_year=<% $conf->config('census_year') || '2012' %>' +
141 '&zip_code=' + cf.elements[prefix + 'zip'].value +
142 '" target="_blank">Map zip code center</A><BR><BR>' +
145 choose_censustract = choose_censustract +
146 '<TR><TH style="width:50%">Entered census tract</TH>' +
147 '<TH style="width:50%">Calculated census tract</TH></TR>' +
148 '<TR><TD>' + cf.elements[prefix + 'censustract'].value +
149 '</TD><TD>' + newcensus + '</TD></TR>' +
150 '<TR><TD> </TD><TD> </TD></TR>';
152 choose_censustract = choose_censustract +
153 '<TR><TD ALIGN="center">' +
154 '<BUTTON TYPE="button" onClick="submit_continue();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract </BUTTON>' +
155 '</TD><TD ALIGN="center">' +
156 '<BUTTON TYPE="button" onClick="set_censustract();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract </BUTTON>' +
158 '<TR><TD COLSPAN=2 ALIGN="center">' +
159 '<BUTTON TYPE="button" onClick="submit_abort();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
163 overlib( choose_censustract, CAPTION, 'Confirm censustract', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
173 function copyelement(from, to) {
174 if ( from == undefined ) {
176 } else if ( from.type == 'select-one' ) {
177 to.value = from.options[from.selectedIndex].value;
178 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
179 } else if ( from.type == 'checkbox' ) {
180 if ( from.checked ) {
181 to.value = from.value;
186 if ( from.value == undefined ) {
189 to.value = from.value;
192 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
195 function check_unique() {
196 var search_hash = new Object;
197 % foreach ($conf->config('cust_main-check_unique')) {
198 search_hash['<% $_ %>'] = document.CustomerForm.elements['<% $_ %>'].value;
201 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
202 duplicates_form(JSON.stringify(search_hash), confirm_unique);
205 function confirm_unique(arg) {
206 if ( arg.match(/\S/) ) {
207 %# arg contains a complete form to choose an existing customer, or not
208 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
209 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
210 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
211 } else { // no duplicates