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, 'confirm_censustract_bill', 'confirm_censustract_ship'
11 if $conf->exists('cust_main-require_censustract');
13 my $uniqueness = $conf->config('cust_main-check_unique');
14 push @fixups, 'check_unique'
15 if $uniqueness and !$opt{'custnum'};
17 push @fixups, 'do_submit'; # always last
19 var fixups = <% encode_json(\@fixups) %>;
23 <&| /elements/onload.js &>
27 %# state machine to deal with all the asynchronous stuff we're doing
28 %# call this after each fixup on success:
29 function submit_continue() {
31 window[ fixups[fixup_position++] ].call();
36 function submit_abort() {
39 document.CustomerForm.submitButton.disabled = false;
43 function bottomfixup(what) {
45 document.CustomerForm.submitButton.disabled = true;
50 function do_submit() {
51 document.CustomerForm.submit();
54 function copy_payby_fields() {
55 var layervars = new Array(
57 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
58 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
59 'paystart_month', 'paystart_year', 'payissue',
64 var cf = document.CustomerForm;
65 var payby = cf.payby.options[cf.payby.selectedIndex].value;
66 for ( f=0; f < layervars.length; f++ ) {
67 var field = layervars[f];
68 copyelement( cf.elements[payby + '_' + field],
75 <& /elements/standardize_locations.js,
76 'callback' => 'submit_continue();',
78 'with_census' => 1, # no with_firm, apparently
81 function copyelement(from, to) {
82 if ( from == undefined ) {
84 } else if ( from.type == 'select-one' ) {
85 to.value = from.options[from.selectedIndex].value;
86 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
87 } else if ( from.type == 'checkbox' ) {
89 to.value = from.value;
94 if ( from.value == undefined ) {
97 to.value = from.value;
100 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
103 % # the value in pre+'censustract' is the confirmed censustract; if it's set,
104 % # and the user hasn't changed it manually, skip this
105 function confirm_censustract(pre) {
106 var cf = document.CustomerForm;
107 if ( cf.elements[pre+'censustract'].value == '' ||
108 cf.elements[pre+'enter_censustract'].value !=
109 cf.elements[pre+'censustract'].value )
111 var address_info = form_address_info();
112 address_info[pre+'latitude'] = cf.elements[pre+'latitude'].value;
113 address_info[pre+'longitude'] = cf.elements[pre+'longitude'].value;
114 address_info['prefix'] = pre;
116 '<%$p%>/misc/confirm-censustract.html',
117 'q=' + encodeURIComponent(JSON.stringify(address_info)),
119 if ( OLresponseAJAX ) {
120 overlib( OLresponseAJAX, CAPTION, 'Confirm censustract', STICKY,
121 AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH,
122 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399',
128 } else submit_continue();
130 function confirm_censustract_bill() {
131 confirm_censustract('bill_');
134 function confirm_censustract_ship() {
135 var cf = document.CustomerForm;
136 if ( cf.elements['same'].checked ) {
139 confirm_censustract('ship_');
143 %# called from confirm-censustract.html
144 function set_censustract(tract, year, pre) {
145 var cf = document.CustomerForm;
146 cf.elements[pre + 'censustract'].value = tract;
147 cf.elements[pre + 'censusyear'].value = year;
151 function check_unique() {
152 var search_hash = {};
153 % if ($uniqueness eq 'address') {
154 search_hash['address'] = [
155 document.CustomerForm.elements['bill_address1'].value,
156 document.CustomerForm.elements['ship_address1'].value
159 %# no other options yet
161 %# supported in IE8+, Firefox 3.5+, WebKit, Opera 10.5+
162 duplicates_form(JSON.stringify(search_hash), confirm_unique);
165 function confirm_unique(arg) {
166 if ( arg.match(/\S/) ) {
167 %# arg contains a complete form to choose an existing customer, or not
168 overlib( arg, CAPTION, 'Duplicate customer', STICKY, AUTOSTATUSCAP,
169 CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT,
170 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
171 } else { // no duplicates